[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm loncreateuser.pm londropadd.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 26 Aug 2007 21:09:43 -0000


This is a MIME encoded message

--raeburn1188162583
Content-Type: text/plain

raeburn		Sun Aug 26 17:09:43 2007 EDT

  Modified files:              
    /loncom/interface	londropadd.pm loncreateuser.pm loncommon.pm 
  Log:
  "Enroll a single student" in Enrollment Manager now uses the same user search interface as "Set Individual User Roles" in Create Users, Change User Privileges.
  
  loncommon.pm
  - &user_picker() takes an additional argument ($caller) to indicate the name of the form which will contain the user search - either: document.crtuser for CUSR or document.studentform for ENRL.
  - javascript function: validateEntry() now takes an argument - callingForm, which similarly contains the name of the form (document.crtuser or document.studentform.
  
  loncreateuser.pm
  - &print_user_selection_page() takes two additional arguments: $context,$srcharray.
    - $context is 'createuser' or 'enrollstudent', depending on caller of form.   - $srcharray is a reference to an array of search items - ('srchterm','srchby','srchin','srchtype','srchdomain').
    - The call to lonhtmlcommon::echo_form_input() in print_user_selection_page() is replaced with printing of form input for elements in @{$srcharray} because of the possibility that this page could be reached coming back from the user modification page.
    - form element: 'state' renamed 'currstate' to avoid collision with 'state' which is already used in ENRL.
    - entry for studentform added to &crumb_utilities() so setFormElements() works for ENRL usage.      
  
  londropadd.pm
  - &single_user_entry_form() added to display user search in "Enroll a single student" interface.
  - user information fields filled in for new username is data available in institutional search.
  - breadcrumbs code allows return to intermediate steps in multi-screen single student enrollment.
  
  
  
--raeburn1188162583
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070826170943.txt"

Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.165 loncom/interface/londropadd.pm:1.166
--- loncom/interface/londropadd.pm:1.165	Thu Jul 26 19:56:35 2007
+++ loncom/interface/londropadd.pm	Sun Aug 26 17:09:42 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to drop and add students in courses 
 #
-# $Id: londropadd.pm,v 1.165 2007/07/26 23:56:35 albertel Exp $
+# $Id: londropadd.pm,v 1.166 2007/08/26 21:09:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -45,7 +45,13 @@
 ###############################################################
 ###############################################################
 sub header {
-    my $start_page=&Apache::loncommon::start_page('Enrollment Manager');
+    my ($jscript,$loaditems) = @_;
+    my $start_page;
+    if (ref($loaditems) eq 'HASH') {
+        $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript,{'add_entries' => $loaditems,});
+    } else {
+        $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript);
+    }
     return(<<ENDHEAD);
 $start_page
 <form method="post" enctype="multipart/form-data"  
@@ -738,7 +744,7 @@
 ###############################################################
 ###############################################################
 sub enroll_single_student {
-    my $r=shift;
+    my ($r,$srcharray) = @_; 
     # Remove non alphanumeric values from section
     $env{'form.csec'}=~s/\W//g;
     #
@@ -823,6 +829,21 @@
         $r->print(&mt('Invalid username or domain'));
     }    
     $r->print("<p><a href='/adm/dropadd?action=enrollstudent'>".&mt("Enroll another student")."</a></p>");
+    if (ref($srcharray) eq 'ARRAY') {
+        foreach my $item (@{$srcharray},'ccuname','ccdomain') {
+            $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
+        }
+    }
+    foreach my $item ('sortby','seluname','seludom') {
+        if (exists($env{'form.'.$item})) {
+            $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
+        }
+    }
+    $r->print('<input type="hidden" name="phase" value="get_user_info" />'."\n".
+              '<input type="hidden" name="currstate" value="" />'."\n".
+              '<input type="hidden" name="prevphase" value="" />'."\n".
+              '<input type="hidden" name="action" value="enrollstudent" />'."\n".
+              '<input type="hidden" name="state" value="gotusername" />');
 }
 
 sub setup_date_selectors {
@@ -936,9 +957,23 @@
 ## Single student enrollment routines (some of them)
 ##
 sub get_student_username_domain_form {
-    my $r = shift;
-    my $domform = &Apache::loncommon::select_dom_form
-        ($env{'course.'.$env{'request.course.id'}.'.domain'},'cudomain',0);
+    my ($r,$elements,$response,$srch,$forcenewuser) =  @_;
+    my $loaditems = {
+            'onload' => "javascript:setFormElements(document.studentform)",
+                     };
+    $r->print(&header(undef,$loaditems));
+    &Apache::lonhtmlcommon::add_breadcrumb
+        ({href=>"javascript:backPage(document.studentform,'','')",
+          text=>"Single user search"});
+    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
+                                                  'Course_Add_Student'));
+    my $defdom=$env{'request.role.domain'};
+
+    my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+        '<script type="text/javascript">'."\n".
+        &Apache::lonhtmlcommon::set_form_elements($elements->{'studentform'}).
+        '</script>'."\n";
+
     my %lt=&Apache::lonlocal::texthash(
 		    'eos'  => "Enroll One Student",
 		    'usr'  => "Username",
@@ -946,34 +981,48 @@
                     'been' => "Begin Enrollment",
 				       );
     $r->print(<<END);
-<input type="hidden" name="action" value="enrollstudent" />
-<input type="hidden" name="state"  value="gotusername" />
+$jscript
 <h3>$lt{'eos'}</h3>
-<table>
-<tr><td class="LC_dropadd_labeltext"><label for="cuname">$lt{'usr'}</label>:</td>
-    <td><input type="text" name="cuname"  size="15" /></td></tr>
-<tr><td class="LC_dropadd_labeltext"><label for="cudomain">$lt{'dom'}</label>:</td>
-    <td>$domform</td></tr>
-<tr><td>&nbsp;</td>
-    <td>
-    <input type="submit" name="Begin Enrollment" value="$lt{'been'}" />
-    </td></tr>
-</table>
-<script type="text/javascript">
-// the if prevents the script error if the browser can not handle this
-if ( document.studentform.cuname ) { document.studentform.cuname.focus(); }
-</script>
 END
+    $r->print(&single_user_entry_form($defdom,$srch,$forcenewuser));
     return;
 }
 
+sub single_user_entry_form {
+    my ($dom,$srch,$forcenewuser) = @_;
+    my $userpicker =
+       &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+                                       'document.studentform');
+    my $srchbutton = &mt('Search');
+    my $output = <<"ENDDOCUMENT";
+<input type="hidden" name="action" value="enrollstudent" />
+<input type="hidden" name="state" value="gotusername" />
+<input type="hidden" name="phase" value="get_user_info" />
+$userpicker
+<input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.studentform)" />
+ENDDOCUMENT
+    return $output;
+}
+
 sub print_enroll_single_student_form {
-    my $r=shift;
+    my ($r,$jscript,$ccuname,$ccdomain,$srch) = @_;
+    $r->print(&header($jscript));
+    &Apache::lonhtmlcommon::add_breadcrumb
+        ({href=>"javascript:backPage(document.studentform,'','')",
+          text=>"Single user search"});
+    if ($env{'form.phase'} eq 'userpicked') {
+        &Apache::lonhtmlcommon::add_breadcrumb
+     ({href=>"javascript:backPage(document.studentform,'get_user_info','select')",
+       text=>"Select user",});
+    }
+    &Apache::lonhtmlcommon::add_breadcrumb
+      ({href=>"javascript:backPage(document.studentform,'$env{'form.phase'}','modify')",
+        text=>"Set enrollment",});
+    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
+                                                  'Course_Add_Student'));
     $r->print("<h3>".&mt('Enroll One Student')."</h3>");
     #
-    my $username = &LONCAPA::clean_username($env{'form.cuname'});
-    my $domain   = &LONCAPA::clean_domain($env{'form.cudomain'});
-    my $home = &Apache::lonnet::homeserver($username,$domain);
+    my $home = &Apache::lonnet::homeserver($ccuname,$ccdomain);
     # $new_user flags whether we are creating a new user or using an old one
     my $new_user = 1;
     if ($home ne 'no_host') {
@@ -983,10 +1032,31 @@
     my $user_data_html = '';
     my $javascript_validations = '';
     if ($new_user) {
+        my $usertoadd;
+        my $instsrch = {
+                         srchin => 'instd',
+                         srchby => 'uname',
+                         srchtype => 'exact',
+                         srchterm => $ccuname,
+                         srchdomain => $ccdomain,
+                       };
+        if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
+            $usertoadd = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
+        }
+        my (%dirsrch_results,%inst_results);
+        if ($usertoadd) {
+            if (&Apache::loncreateuser::directorysrch_check($instsrch) eq 'ok') {
+                %dirsrch_results = &Apache::lonnet::inst_directory_query($instsrch);
+                if (ref($dirsrch_results{$usertoadd}) eq 'HASH') {
+                    %inst_results = %{$dirsrch_results{$usertoadd}};
+                }
+            }
+        }
+
         my $defdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
         # Set up authentication forms
         my ($krbdef,$krbdefdom) =
-            &Apache::loncommon::get_kerberos_defaults($domain);
+            &Apache::loncommon::get_kerberos_defaults($ccdomain);
         $javascript_validations=&javascript_validations('auth',$krbdefdom);
         my %param = ( formname => 'document.studentform',
                       kerb_def_dom => $krbdefdom,
@@ -998,7 +1068,7 @@
         #
         # Set up domain selection form
         my $homeserver_form = '';
-        my %servers = &Apache::lonnet::get_servers($domain,'library');
+        my %servers = &Apache::lonnet::get_servers($ccdomain,'library');
         $homeserver_form = '<select name="lcserver" size="1">'."\n".
             '<option value="default" selected>default</option>'."\n";
         while (my ($servername,$serverdescription) = each (%servers)) {
@@ -1021,20 +1091,20 @@
 					   );
 	my $authhelp=&Apache::loncommon::help_open_topic('Auth_Options');
         $user_data_html = <<END;
-<h3>$lt{'udf'} $username:$domain</h3>
+<h3>$lt{'udf'} $ccuname:$ccdomain</h3>
 <table>
 <tr><td class="LC_dropadd_labeltext"><label for="cfirst">$lt{'fn'}</label>:</td>
-    <td><input type="text" name="cfirst"  size="15" /></td></tr>
+    <td><input type="text" name="cfirst" size="15" value="$inst_results{'firstname'}" /></td></tr>
 <tr><td class="LC_dropadd_labeltext"><label for="cmiddle">$lt{'mn'}</label>:</td>
-    <td><input type="text" name="cmiddle" size="15" /></td></tr>
+    <td><input type="text" name="cmiddle" size="15" value="$inst_results{'middlename'}" /></td></tr>
 <tr><td class="LC_dropadd_labeltext"><label for="clast">$lt{'ln'}</label>:</td>
-    <td><input type="text" name="clast"   size="15" /></td></tr>
+    <td><input type="text" name="clast" size="15" value="$inst_results{'lastname'}" /></td></tr>
 <tr><td class="LC_dropadd_labeltext"><label for="cgen">$lt{'gen'}</label>:</td>
-    <td><input type="text" name="cgen"    size="5"  /> </td></tr>
+    <td><input type="text" name="cgen" size="5" value="$inst_results{'generation'}" /> </td></tr>
 <tr><td class="LC_dropadd_labeltext"><label for="lcserver">$lt{'hs'}</label>:</td>
     <td>$homeserver_form</td></tr>
 <tr><td class="LC_dropadd_labeltext"><label for="emailaddress">$lt{'mail'}</label>:</td>
-    <td><input type="text" name="emailaddress" size="20" /></td></tr>
+    <td><input type="text" name="emailaddress" size="20" value="$inst_results{'permanentemail'}" /></td></tr>
 </table>
 <h3>$lt{'pswd'}</h3>
 $lt{'psam'}$authhelp
@@ -1049,7 +1119,7 @@
 END
     } else {
         # User already exists.  Do not worry about authentication
-        my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
+        my %uenv = &Apache::lonnet::dump('environment',$ccdomain,$ccuname);
         $javascript_validations = &javascript_validations('noauth');
 	my %lt=&Apache::lonlocal::texthash(
 		       'udf'  => "User Data for",
@@ -1060,7 +1130,7 @@
                        'mail' => "Email Address",
 					   );
         $user_data_html = <<END;
-<h3>$lt{'udf'} $username:$domain</h3>
+<h3>$lt{'udf'} $ccuname:$ccdomain</h3>
 <input type="hidden" name="lcserver" value="default" />
 <table>
 <tr><td class="LC_dropadd_labeltext"><label for="cfirst">$lt{'fn'}</label>:</td>
@@ -1087,9 +1157,9 @@
 				       );
     $r->print(<<END);
 <input type="hidden" name="action" value="enrollstudent" />
-<input type="hidden" name="state"  value="done" />
-<input type="hidden" name="cuname" value="$username" />
-<input type="hidden" name="lcdomain" value="$domain" />
+<input type="hidden" name="state"  value="gotusername" />
+<input type="hidden" name="cuname" value="$ccuname" />
+<input type="hidden" name="lcdomain" value="$ccdomain" />
 <script type="text/javascript" language="Javascript">
 function verify(vf,sec_caller) {
     var founduname=0;
@@ -1149,6 +1219,19 @@
 <input type="button" onClick="verify(this.form,this.form.csec)" value="$lt{'eas'}" />
 </p>
 END
+    $r->print('<input type="hidden" name="currstate" value="" />'."\n".
+              '<input type="hidden" name="phase" value="" />'."\n".
+              '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />'."\n");
+    if (ref($srch) eq 'HASH') {
+        foreach my $item (sort(keys(%{$srch}))) {
+            $r->print('<input type="hidden" name="'.$item.'" value="'.$srch->{$item}.'" />'."\n");
+        }
+    }
+    foreach my $item ('sortby','seluname','seludom') {
+        if (exists($env{'form.'.$item})) {
+            $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
+        }
+    }
     return;
 }
 
@@ -2529,13 +2612,14 @@
     # Start page
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
-    $r->print(&header());
     #
     # Main switch on form.action and form.state, as appropriate
     if (! exists($env{'form.action'})) {
+        $r->print(&header());
         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment Manager'));
         my $action = &print_main_menu($r,$permission);
     } elsif ($env{'form.action'} eq 'upload' && $permission->{'enrl'}) {
+        $r->print(&header());
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>'/adm/dropadd?action=upload&state=',
               text=>"Upload Classlist"});
@@ -2555,6 +2639,7 @@
             &print_first_courselist_upload_form($r);            
         }
     } elsif ($env{'form.action'} eq 'drop' && $permission->{'enrl'}) {
+        $r->print(&header());
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>'/adm/dropadd?action=drop',
               text=>"Drop Students"});
@@ -2568,19 +2653,83 @@
             &print_drop_menu($r);
         }
     } elsif ($env{'form.action'} eq 'enrollstudent' && $permission->{'enrl'}) {
-        &Apache::lonhtmlcommon::add_breadcrumb
-            ({href=>'/adm/dropadd?action=enrollstudent',
-              text=>"Enroll Student"});
-        $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
-						      'Course_Add_Student'));
-        if (! exists($env{'form.state'})) {
-            &get_student_username_domain_form($r);
-        } elsif ($env{'form.state'} eq 'gotusername') {
-            &print_enroll_single_student_form($r);
+        my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
+        my ($jsback,$elements) = &Apache::loncreateuser::crumb_utilities();
+        my $jscript = '<script type="text/javascript">'.$jsback.'</script>';
+        if ($env{'form.state'} eq 'gotusername') {
+            my $srch;
+            foreach my $item (@search) {
+                $srch->{$item} = $env{'form.'.$item};
+            }
+            print STDERR "phase = $env{'form.phase'}\n";
+            if ($env{'form.phase'} eq 'get_user_info') {
+                my ($currstate,$response,$forcenewuser,$results) =
+                    &Apache::loncreateuser::user_search_result($srch);
+                if ($currstate eq 'select') {
+                    $r->print(&header());
+                    &Apache::lonhtmlcommon::add_breadcrumb
+                        ({href=>"javascript:backPage(document.usersrchform,'','')",
+                          text=>"Single user search"},
+                         {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
+                          text=>"Select User",});
+                    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
+                                                                  'Course_Add_Student'));
+                    &Apache::loncreateuser::print_user_selection_page($r,
+                        $response,$srch,$results,'enrollstudent',\@search);
+                } elsif ($currstate eq 'modify') {
+                    my ($ccuname,$ccdomain);
+                    if (($srch->{'srchby'} eq 'uname') &&
+                        ($srch->{'srchtype'} eq 'exact')) {
+                        $ccuname = $srch->{'srchterm'};
+                        $ccdomain= $srch->{'srchdomain'};
+                    } else {
+                        my @matchedunames = keys(%{$results});
+                        ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
+                    }
+                    $ccuname =&LONCAPA::clean_username($ccuname);
+                    $ccdomain=&LONCAPA::clean_domain($ccdomain);
+                    &print_enroll_single_student_form($r,$jscript,$ccuname,
+                                                      $ccdomain,$srch,$response);
+                } elsif ($currstate eq 'query') {
+                    $r->print(&header($jscript));
+                    &Apache::lonhtmlcommon::add_breadcrumb
+                        ({href=>"javascript:backPage(document.studentform,'','')",
+                          text=>"Single user search"});
+                    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
+                                                      'Course_Add_Student'));
+                    &Apache::loncreateuser::print_user_query_page($r,'enrollstudent');
+                } else {
+                    &get_student_username_domain_form($r,$elements,$response,
+                                                      $srch,$forcenewuser);
+                }
+            } elsif ($env{'form.phase'} eq 'userpicked') {
+                my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
+                my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
+                &print_enroll_single_student_form($r,$jscript,$ccuname,
+                                                  $ccdomain,$srch);
+            } else {
+                &get_student_username_domain_form($r,$elements);
+            }
         } elsif ($env{'form.state'} eq 'enrolling') {
-            &enroll_single_student($r);
+            $r->print(&header($jscript));
+            &Apache::lonhtmlcommon::add_breadcrumb
+                ({href=>"javascript:backPage(document.studentform,'','')",
+                  text=>"Single user search"});
+            if ($env{'form.prevphase'} eq 'userpicked') {
+               &Apache::lonhtmlcommon::add_breadcrumb
+               ({href=>"javascript:backPage(document.studentform,'get_user_info','select')",
+                 text=>"Select user",});
+            }
+            &Apache::lonhtmlcommon::add_breadcrumb
+                ({href=>"javascript:backPage(document.studentform,'$env{'form.prevphase'}','modify')",
+                  text=>"Set enrollment",},
+                 {href=>"javascript:backPage(document.studentform,$env{'form.phase'},'')",
+                 text=>"Result",});
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
+                                                      'Course_Add_Student'));
+            &enroll_single_student($r,\@search);
         } else {
-            &get_student_username_domain_form($r);
+            &get_student_username_domain_form($r,$elements);
         }
     } elsif ($env{'form.action'} eq 'classlist' && $permission->{'view'}) {
         &Apache::lonhtmlcommon::add_breadcrumb
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.178 loncom/interface/loncreateuser.pm:1.179
--- loncom/interface/loncreateuser.pm:1.178	Sun Aug 26 11:31:03 2007
+++ loncom/interface/loncreateuser.pm	Sun Aug 26 17:09:43 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.178 2007/08/26 15:31:03 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.179 2007/08/26 21:09:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -264,13 +264,14 @@
 sub entry_form {
     my ($dom,$srch,$forcenewuser) = @_;
     my $userpicker = 
-       &Apache::loncommon::user_picker($dom,$srch,$forcenewuser);
+       &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+                                       'document.crtuser');
     my $srchbutton = &mt('Search');
     my $output = <<"ENDDOCUMENT";
 <form action="/adm/createuser" method="post" name="crtuser">
 <input type="hidden" name="phase" value="get_user_info" />
 $userpicker
-<input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry()" />
+<input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
 </form>
 ENDDOCUMENT
     return $output;
@@ -305,7 +306,7 @@
 
 # =================================================================== Phase two
 sub print_user_selection_page {
-    my ($r,$response,$srch,$srch_results) = @_;
+    my ($r,$response,$srch,$srch_results,$context,$srcharray) = @_;
     my @fields = ('username','domain','lastname','firstname','permanentemail');
     my $sortby = $env{'form.sortby'};
 
@@ -329,25 +330,34 @@
 ENDSCRIPT
 
     my %lt=&Apache::lonlocal::texthash(
-                                       'srch'           => "User Search to add/modify roles",
+                                       'usrch'          => "User Search to add/modify roles",
+                                       'stusrch'        => "User Search to enroll student",
+                                       'usel'           => "Select a user to add/modify roles",
+                                       'stusel'         => "Select a user to enroll as a student", 
                                        'username'       => "username",
                                        'domain'         => "domain",
                                        'lastname'       => "last name",
                                        'firstname'      => "first name",
                                        'permanentemail' => "permanent e-mail",
                                       );
-    $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript));
-    &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>"javascript:backPage(document.usersrchform,'','')",
-          text=>"User modify/custom role edit",
-          faq=>282,bug=>'Instructor Interface',},
-         {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
-          text=>"Select User",
-          faq=>282,bug=>'Instructor Interface',});
-    $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
-    $r->print("<b>$lt{'srch'}</b><br />");
-    $r->print(&entry_form($srch->{'srchdomain'},$srch));
-    $r->print('<h3>'.&mt('Select a user to add/modify roles').'</h3>');
+    if ($context eq 'createuser') {
+        $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript));
+        &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>"javascript:backPage(document.usersrchform,'','')",
+              text=>"User modify/custom role edit",
+              faq=>282,bug=>'Instructor Interface',},
+             {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
+              text=>"Select User",
+              faq=>282,bug=>'Instructor Interface',});
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+        $r->print("<b>$lt{'usrch'}</b><br />");
+        $r->print(&entry_form($srch->{'srchdomain'},$srch));
+        $r->print('<h3>'.$lt{'usel'}.'</h3>');
+    } else {
+        $r->print($jscript."<b>$lt{'stusrch'}</b><br />");
+        $r->print(&Apache::londropadd::single_user_entry_form($srch->{'srchdomain'},$srch));
+        $r->print('</form><h3>'.$lt{'stusel'}.'</h3>');
+    }
     $r->print('<form name="usersrchform" method="post">'.
               &Apache::loncommon::start_data_table()."\n".
               &Apache::loncommon::start_data_table_header_row()."\n".
@@ -381,19 +391,27 @@
         $r->print(&Apache::loncommon::end_data_table_row());
     }
     $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
-    $r->print(&Apache::lonhtmlcommon::echo_form_input(['sortby','seluname','seludom','state','phase']));
+    if (ref($srcharray) eq 'ARRAY') {
+        foreach my $item (@{$srcharray}) {
+            $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
+        }
+    }
     $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
               ' <input type="hidden" name="seluname" value="" />'."\n".
               ' <input type="hidden" name="seludom" value="" />'."\n".
-              ' <input type="hidden" name="state" value="select" />'."\n".
-              ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
-              '</form>');
+              ' <input type="hidden" name="currstate" value="select" />'."\n".
+              ' <input type="hidden" name="phase" value="get_user_info" />'."\n");
     $r->print($response);
-    $r->print(&Apache::loncommon::end_page());
+    if ($context eq 'createuser') {
+        $r->print('</form>'.&Apache::loncommon::end_page());
+    } else {
+        $r->print('<input type="hidden" name="action" value="enrollstudent" />'."\n".
+                  '<input type="hidden" name="state" value="gotusername" />'."\n");
+    }
 }
 
 sub print_user_query_page {
-    my ($r) = @_;
+    my ($r,$caller) = @_;
 # FIXME - this is for a network-wide name search (similar to catalog search)
 # To use frames with similar behavior to catalog/portfolio search.
 # To be implemented. 
@@ -1204,8 +1222,8 @@
         $r->print(&course_level_table(%inccourses));
         $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()" />'."\n");
     }
-    $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','state']));
-    $r->print('<input type="hidden" name="state" value="" />');
+    $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate']));
+    $r->print('<input type="hidden" name="currstate" value="" />');
     $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
     $r->print("</form>".&Apache::loncommon::end_page());
 }
@@ -1750,7 +1768,7 @@
         }
     }
     $r->print('<input type="hidden" name="phase" value="" />'."\n".
-              '<input type ="hidden" name="state" value="" />'."\n".
+              '<input type ="hidden" name="currstate" value="" />'."\n".
               '</form>');
     $r->print(&Apache::loncommon::end_page());
 }
@@ -1949,7 +1967,7 @@
     }
     $r->print(&Apache::loncommon::end_data_table().
    '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
-   '" />'."\n".'<input type="hidden" name="state" value="" />'."\n".   
+   '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".   
    '<input type="reset" value="'.&mt("Reset").'" />'."\n".
    '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
 	      &Apache::loncommon::end_page());
@@ -2142,11 +2160,11 @@
                $srch->{$item} = $env{'form.'.$item};
            }
            if ($env{'form.phase'} eq 'get_user_info') {
-               my ($state,$response,$forcenewuser,$results) = 
+               my ($currstate,$response,$forcenewuser,$results) = 
                    &user_search_result($srch);
-               if ($state eq 'select') {
-                   &print_user_selection_page($r,$response,$srch,$results);
-               } elsif ($state eq 'modify') {
+               if ($currstate eq 'select') {
+                   &print_user_selection_page($r,$response,$srch,$results,'createuser',\@search);
+               } elsif ($currstate eq 'modify') {
                    my ($ccuname,$ccdomain);
                    if (($srch->{'srchby'} eq 'uname') && 
                        ($srch->{'srchtype'} eq 'exact')) {
@@ -2160,8 +2178,8 @@
                    $ccdomain=&LONCAPA::clean_domain($ccdomain);
                    &print_user_modification_page($r,$ccuname,$ccdomain,$srch,
                                                  $response);
-               } elsif ($state eq 'query') {
-                   &print_user_query_page($r);
+               } elsif ($currstate eq 'query') {
+                   &print_user_query_page($r,'createuser');
                } else {
                    &print_username_entry_form($r,$response,$srch,$forcenewuser);
                }
@@ -2193,7 +2211,7 @@
     my %allhomes;
     my %inst_matches;
     my %srch_results;
-    my ($response,$state,$forcenewuser);
+    my ($response,$currstate,$forcenewuser);
     $srch->{'srchterm'} =~ s/^\s+//;
     $srch->{'srchterm'} =~ s/\s+$//;
 
@@ -2230,7 +2248,7 @@
         }
     }
     if ($response ne '') {
-        return ($state,'<span class="LC_warning">'.$response.'</span>');
+        return ($currstate,'<span class="LC_warning">'.$response.'</span>');
     }
     if ($srch->{'srchby'} eq 'uname') {
         if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
@@ -2241,33 +2259,33 @@
                         my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
                         $response = &mt('New users can only be created in the domain to which you current role belongs - [_1].',$env{'request.role.domain'}.' ('.$domdesc.')');
                     } else {
-                        $state = 'modify';
+                        $currstate = 'modify';
                     }
                 } else {
-                    $state = 'modify';
+                    $currstate = 'modify';
                 }
             } else {
                 if ($srch->{'srchin'} eq 'dom') {
                     if ($srch->{'srchtype'} eq 'exact') {
                         my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
                         if ($uhome eq 'no_host') {
-                            ($state,$response,$forcenewuser) =
+                            ($currstate,$response,$forcenewuser) =
                                 &build_search_response($srch,%srch_results);
                         } else {
-                            $state = 'modify';
+                            $currstate = 'modify';
                         }
                     } else {
                         %srch_results = &Apache::lonnet::usersearch($srch);
-                        ($state,$response,$forcenewuser) =
+                        ($currstate,$response,$forcenewuser) =
                             &build_search_response($srch,%srch_results);
                     }
                 } else {
                     my $courseusers = &get_courseusers();
                     if ($srch->{'srchtype'} eq 'exact') {
                         if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
-                            $state = 'modify';
+                            $currstate = 'modify';
                         } else {
-                            ($state,$response,$forcenewuser) =
+                            ($currstate,$response,$forcenewuser) =
                                 &build_search_response($srch,%srch_results);
                         }
                     } else {
@@ -2293,22 +2311,22 @@
                                 }
                             }
                         }
-                        ($state,$response,$forcenewuser) =
+                        ($currstate,$response,$forcenewuser) =
                             &build_search_response($srch,%srch_results);
                     }
                 }
             }
         } elsif ($srch->{'srchin'} eq 'alc') {
-            $state = 'query';
+            $currstate = 'query';
         } elsif ($srch->{'srchin'} eq 'instd') {
             %srch_results = &Apache::lonnet::inst_directory_query($srch);
-            ($state,$response,$forcenewuser) = 
+            ($currstate,$response,$forcenewuser) = 
                 &build_search_response($srch,%srch_results); 
         }
     } else {
         if ($srch->{'srchin'} eq 'dom') {
             %srch_results = &Apache::lonnet::usersearch($srch);
-            ($state,$response,$forcenewuser) = 
+            ($currstate,$response,$forcenewuser) = 
                 &build_search_response($srch,%srch_results); 
         } elsif ($srch->{'srchin'} eq 'crs') {
             my $courseusers = &get_courseusers(); 
@@ -2360,17 +2378,17 @@
                     }
                 }
             }
-            ($state,$response,$forcenewuser) = 
+            ($currstate,$response,$forcenewuser) = 
                 &build_search_response($srch,%srch_results); 
         } elsif ($srch->{'srchin'} eq 'alc') {
-            $state = 'query';
+            $currstate = 'query';
         } elsif ($srch->{'srchin'} eq 'instd') {
             %srch_results = &Apache::lonnet::inst_directory_query($srch); 
-            ($state,$response,$forcenewuser) = 
+            ($currstate,$response,$forcenewuser) = 
                 &build_search_response($srch,%srch_results);
         }
     }
-    return ($state,$response,$forcenewuser,\%srch_results);
+    return ($currstate,$response,$forcenewuser,\%srch_results);
 }
 
 sub directorysrch_check {
@@ -2467,7 +2485,7 @@
 
 sub build_search_response {
     my ($srch,%srch_results) = @_;
-    my ($state,$response,$forcenewuser);
+    my ($currstate,$response,$forcenewuser);
     my %names = (
           'uname' => 'username',
           'lastname' => 'last name',
@@ -2486,10 +2504,10 @@
                    exact => 'No exact match',
                   );
     if (keys(%srch_results) > 1) {
-        $state = 'select';
+        $currstate = 'select';
     } else {
         if (keys(%srch_results) == 1) {
-            $state = 'modify';
+            $currstate = 'modify';
             $response = &mt("$single{$srch->{'srchtype'}} was found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
         } else {
             $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}).'</span>';
@@ -2517,7 +2535,7 @@
             }
         }
     }
-    return ($state,$response,$forcenewuser);
+    return ($currstate,$response,$forcenewuser);
 }
 
 sub crumb_utilities {
@@ -2533,12 +2551,19 @@
            rolename => 'selectbox',
            newrolename => 'textbox',
        },
+       studentform => {
+           srchterm => 'text',
+           srchin => 'selectbox',
+           srchby => 'selectbox',
+           srchtype => 'selectbox',
+           srchdomain => 'selectbox',
+       },
     );
 
     my $jsback .= qq|
 function backPage(formname,prevphase,prevstate) {
     formname.phase.value = prevphase;
-    formname.state.value = prevstate;
+    formname.currstate.value = prevstate;
     formname.submit();
 }
 |;
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.569 loncom/interface/loncommon.pm:1.570
--- loncom/interface/loncommon.pm:1.569	Sat Aug 25 15:52:29 2007
+++ loncom/interface/loncommon.pm	Sun Aug 26 17:09:43 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.569 2007/08/25 19:52:29 raeburn Exp $
+# $Id: loncommon.pm,v 1.570 2007/08/26 21:09:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5609,7 +5609,7 @@
 }
 
 sub user_picker {
-    my ($dom,$srch,$forcenewuser) = @_;
+    my ($dom,$srch,$forcenewuser,$caller) = @_;
     my $currdom = $dom;
     my %curr_selected = (
                         srchin => 'dom',
@@ -5692,29 +5692,29 @@
     my ($newuserscript,$new_user_create);
 
     if ($forcenewuser) {
-	$new_user_create = '<p> <input type="submit" name="forcenew" value="'.&HTML::Entities::encode(&mt('Make new user "[_1]"',$srchterm),'<>&"').'" onclick="javascript:setSearch(\'1\');" /> </p>';
+	$new_user_create = '<p> <input type="submit" name="forcenew" value="'.&HTML::Entities::encode(&mt('Make new user "[_1]"',$srchterm),'<>&"').'" onclick="javascript:setSearch(\'1\','.$caller.');" /> </p>';
         $newuserscript = <<"ENDSCRIPT";
 
-function setSearch(createnew) {
+function setSearch(createnew,callingForm) {
     if (createnew == 1) {
-        for (var i=0; i<document.crtuser.srchby.length; i++) {
-            if (document.crtuser.srchby.options[i].value == 'uname') {
-                document.crtuser.srchby.selectedIndex = i;
+        for (var i=0; i<callingForm.srchby.length; i++) {
+            if (callingForm.srchby.options[i].value == 'uname') {
+                callingForm.srchby.selectedIndex = i;
             }
         }
-        for (var i=0; i<document.crtuser.srchin.length; i++) {
-            if ( document.crtuser.srchin.options[i].value == 'dom') {
-		document.crtuser.srchin.selectedIndex = i;
+        for (var i=0; i<callingForm.srchin.length; i++) {
+            if ( callingForm.srchin.options[i].value == 'dom') {
+		callingForm.srchin.selectedIndex = i;
             }
         }
-        for (var i=0; i<document.crtuser.srchtype.length; i++) {
-            if (document.crtuser.srchtype.options[i].value == 'exact') {
-                document.crtuser.srchtype.selectedIndex = i;
+        for (var i=0; i<callingForm.srchtype.length; i++) {
+            if (callingForm.srchtype.options[i].value == 'exact') {
+                callingForm.srchtype.selectedIndex = i;
             }
         }
-        for (var i=0; i<document.crtuser.srchdomain.length; i++) {
-            if (document.crtuser.srchdomain.options[i].value == '$env{'request.role.domain'}') {
-                document.crtuser.srchdomain.selectedIndex = i;
+        for (var i=0; i<callingForm.srchdomain.length; i++) {
+            if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
+                callingForm.srchdomain.selectedIndex = i;
             }
         }
     }
@@ -5725,21 +5725,21 @@
 
     my $output = <<"END_BLOCK";
 <script type="text/javascript">
-function validateEntry() {
+function validateEntry(callingForm) {
 
     var checkok = 1;
     var srchin;
-    for (var i=0; i<document.crtuser.srchin.length; i++) {
-	if ( document.crtuser.srchin[i].checked ) {
-	    srchin = document.crtuser.srchin[i].value;
+    for (var i=0; i<callingForm.srchin.length; i++) {
+	if ( callingForm.srchin[i].checked ) {
+	    srchin = callingForm.srchin[i].value;
 	}
     }
 
-    var srchtype = document.crtuser.srchtype.options[document.crtuser.srchtype.selectedIndex].value;
-    var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;
-    var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;
-    var srchterm =  document.crtuser.srchterm.value;
-    var srchin = document.crtuser.srchin.options[document.crtuser.srchin.selectedIndex].value;
+    var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
+    var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
+    var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
+    var srchterm =  callingForm.srchterm.value;
+    var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
     var msg = "";
 
     if (srchterm == "") {
@@ -5787,7 +5787,7 @@
         return;
     }
     if (checkok == 1) {
-        document.crtuser.submit();
+        callingForm.submit();
     }
 }
 

--raeburn1188162583--