[LON-CAPA-cvs] cvs: loncom /interface lonpickuser.pm

raeburn raeburn@source.lon-capa.org
Thu, 06 Aug 2009 20:46:43 -0000


raeburn		Thu Aug  6 20:46:43 2009 EDT

  Modified files:              
    /loncom/interface	lonpickuser.pm 
  Log:
  - Course requestors can have rights to define new users in the domain of the course when generating a course request.
  - Provide a form in the "pick user" pop-up so the requestor can provide first name, last name and e-mail address for the new user (if an exact search by username in the course domain finds no matches, and the requestor has the required rights).
  - User information is passed back to the main course request window.
  
  
Index: loncom/interface/lonpickuser.pm
diff -u loncom/interface/lonpickuser.pm:1.1 loncom/interface/lonpickuser.pm:1.2
--- loncom/interface/lonpickuser.pm:1.1	Tue Aug  4 20:08:34 2009
+++ loncom/interface/lonpickuser.pm	Thu Aug  6 20:46:42 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Search for a user
 #
-# $Id: lonpickuser.pm,v 1.1 2009/08/04 20:08:34 raeburn Exp $
+# $Id: lonpickuser.pm,v 1.2 2009/08/06 20:46:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -71,15 +71,36 @@
     # Get parameters from query string
     &Apache::loncommon::get_unprocessed_cgi
         ($ENV{'QUERY_STRING'},['srchdom','form','udomelement','unameelement','ulastelement',
-                               'ufirstelement','uemailelement','hideudomelement']);
+                               'ufirstelement','uemailelement','hideudomelement','coursedom']);
     my $js;
 
-    if ($env{'form.phase'} eq 'get_user_info') {
+    if (($env{'form.phase'} eq 'get_user_info') || 
+        ($env{'form.phase'} eq 'store_newuser')) {
         $js = &gochoose_javascript();
+    } elsif ($env{'form.phase'} eq 'define_newuser') {
+        $js = <<"ENDSP";
+<script type="text/javascript">
+// <![CDATA[
+function setphase(caller) {
+    document.newuserinfo.phase.value = caller;
+    document.newuserinfo.submit();
+    return;
+}
+// ]]>
+</script>
+ENDSP
     }
-
-    $r->print(&Apache::loncommon::start_page('Selecting course personnel',$js,
-                                             {'no_nav_bar'  => 1, }));
+    my $startargs = {'no_nav_bar'  => 1, };
+    if ($env{'form.phase'} eq 'store_newuser') {
+        my $uname = $env{'form.srchterm'};
+        my $udom = $env{'form.srchdomain'};
+        my $newfirst = $env{'form.newfirst'};
+        my $newlast = $env{'form.newlast'};
+        my $newemail = $env{'form.newemail'};
+        $startargs->{'add_entries'} = { onload => 'javascript:gochoose('."'$uname','$udom','$newfirst','$newlast','$newemail'".');' };
+    }
+    $r->print(&Apache::loncommon::start_page('Selecting course personnel',
+                                             $js,$startargs));
     my %toset = (
                   uname   => 'unameelement',
                   udom    => 'udomelement',
@@ -108,7 +129,7 @@
                                                           $srch{'srchterm'},$rules);
     }
 
-    my $dom = $env{'form.srchdom'};
+    my $dom = $env{'form.coursedom'};
 
     my $cancreate =
         &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
@@ -118,22 +139,26 @@
     my $srchbutton = &mt('Search');
 
     my $headertext = &mt('Search for a user to add to course personnel');  
-    my $opener_elems;
+    my $opener_elems = '<input type="hidden" name="form" value="'.
+                       $env{'form.form'}.'" />'."\n".
+                       '<input type="hidden" name="coursedom" value="'.
+                       $env{'form.coursedom'}.'" />'."\n";
     foreach my $item (keys(%toset)) {
         if (exists($env{'form.'.$toset{$item}})) {
             $opener_elems .= '<input type="hidden" name="'.$toset{$item}.'" value="'.$env{'form.'.$toset{$item}}.'" />'."\n";
         }
-    } 
-    $r->print(<<"ENDBLOCK");
+    }
+    unless ($env{'form.phase'} eq 'define_newuser') { 
+        $r->print(<<"ENDBLOCK");
 <h3>$headertext</h3>
 <form action="/adm/pickuser" method="post" name="userpicker">
 $opener_elems
 <input type="hidden" name="phase" value="get_user_info" />
-<input type="hidden" name="form" value="$env{'form.form'}" />
 $userpicker
 <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.userpicker)" />
 </form>
 ENDBLOCK
+    }
     if ($env{'form.phase'} eq 'get_user_info') {
         $r->print('<hr /><div>'.&mt('Searching ...').'</div>');
         $r->rflush();
@@ -144,7 +169,68 @@
                                                               \@search,$context,$opener_elems);
         } else {
             $r->print('<div>'.$response.'</div>');
+            if ($forcenewuser) {
+                if ($srch{'srchby'} eq 'uname' && 
+                    $srch{'srchtype'} eq 'exact' && 
+                    $srch{'srchin'} eq 'dom' && 
+                    $srch{'srchdomain'} eq $env{'form.coursedom'}) {
+                    if ($cancreate) {
+                        $r->print("\n".'<div><form name="newuser" '.
+                                  'method="post" action="/adm/pickuser">');
+                        foreach my $item (keys(%srch)) {
+                            $r->print('<input type="hidden" name="'.$item.'"'.
+                                      ' value="'.$srch{$item}.'" />'."\n");
+                        }
+                        $r->print('
+<input type="hidden" name="phase" value="define_newuser">
+<input type="submit" name="forcenew" value="'.
+&HTML::Entities::encode(&mt('Make new user "[_1]"',$srch{'srchterm'}),'<>&"').'" />'."\n".
+$opener_elems.'
+</form></div>');
+                    } else {
+                        my $helplink = 'javascript:helpMenu('."'display'".')';
+                        my %usertypetext = (
+                            official   => 'institutional',
+                            unofficial => 'non-institutional',
+                        );
+                        $r->print('<div class="LC_warning">'.
+                                  &mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.
+                                  &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="'.$helplink.'">','</a>').'</div>');
+
+                    }
+                }
+            }
+        }
+    }
+    if ($env{'form.phase'} eq 'define_newuser') {
+        $r->print('<h3>'.&mt('Define new user').' '.$srch{'srchterm'}.':'.
+                  $srch{'srchdomain'}.'</h3>'."\n".'<div>'.
+                  '<form name="newuserinfo" method="post" action="/adm/pickuser">'."\n".
+                  '<input type="hidden" name="phase" value="" />'."\n".
+                  $opener_elems.
+                  &Apache::lonhtmlcommon::start_pick_box()."\n".
+                  &Apache::lonhtmlcommon::row_title(&mt('First Name')).
+                  '<input type="text" name="newfirst" value="" size="15" />'.
+                  &Apache::lonhtmlcommon::row_closure()."\n".
+                  &Apache::lonhtmlcommon::row_title(&mt('Last Name')).
+                  '<input type="text" name="newlast" value="" size="25" />'
+.
+                  &Apache::lonhtmlcommon::row_closure()."\n".
+                  &Apache::lonhtmlcommon::row_title(&mt('E-mail Address')).
+                  '<input type="text" name="newemail" value="" size="25" />'
+.
+                  &Apache::lonhtmlcommon::row_closure(1)."\n".
+                  &Apache::lonhtmlcommon::end_pick_box());
+        foreach my $item (keys(%srch)) {
+            $r->print('<input type="hidden" name="'.$item.'"'.
+                      ' value="'.$srch{$item}.'" />'."\n");
         }
+        $r->print('<br /><input type="button" name="cancelnew" value="'.
+                  &mt('Cancel').'" onclick="javascript:setphase('.
+                  "'get_user_info'".');" />'."\n".
+                  '<input type="button" name="definenew" value="'.
+                  &mt('Save').'" onclick="javascript:setphase('.
+                  "'store_newuser'".');" /></form></div>');
     }
     $r->print(&Apache::loncommon::end_page());
     return OK;
@@ -153,6 +239,7 @@
 sub gochoose_javascript {
     return <<"ENDGC"; 
 <script type="text/javascript">
+// <![CDATA[
 function gochoose(uname,udom,ufirst,ulast,uemail) {
     opener.document.$env{'form.form'}.$env{'form.unameelement'}.value=uname;
     opener.document.$env{'form.form'}.$env{'form.ufirstelement'}.value=ufirst;
@@ -172,6 +259,7 @@
     opener.document.$env{'form.form'}.$env{'form.hideudomelement'}.value=udom;
     self.close();
 }
+// ]]>
 </script>
 
 ENDGC