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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 14 Jul 2003 15:25:59 -0000


This is a MIME encoded message

--matthew1058196359
Content-Type: text/plain

matthew		Mon Jul 14 11:25:59 2003 EDT

  Modified files:              
    /loncom/interface	londropadd.pm 
  Log:
  Bug 1475
  Added &get_student_username_domain_form which, when enrolling a single student,
  uses a seperate page to get the username & domain.  If the user exists the
  enrollment page is simplified and pre-filled out.  If not, the enrollment
  page is pretty much as before (minor cosmetic changes).
  Added &javascript_validiations_without_auth
  Reworked much of &print_enroll_single_student_form()
  
  
--matthew1058196359
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20030714112559.txt"

Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.73 loncom/interface/londropadd.pm:1.74
--- loncom/interface/londropadd.pm:1.73	Sat Jul  5 06:07:11 2003
+++ loncom/interface/londropadd.pm	Mon Jul 14 11:25:59 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to drop and add students in courses 
 #
-# $Id: londropadd.pm,v 1.73 2003/07/05 10:07:11 www Exp $
+# $Id: londropadd.pm,v 1.74 2003/07/14 15:25:59 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -275,6 +275,36 @@
 
 }
 
+sub javascript_validations_without_auth {
+    my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+    return (<<ENDPICK);
+function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
+    var foundatype=0;
+    var message='';
+    if (founduname==0) {
+	alert('You need to specify the username field');
+        return;
+    }
+    if (foundname==0) { message='name fields'; }
+    if (foundid==0) { if (message!='') { message+=', '; } message+='student number field'; }
+    if (foundsec==0) {  if (message!='') { message+=', '; } message+='section or group field'; }
+    if (foundemail==0) {  if (message!='') { message+=', '; } message+='email address field'; }
+    if (message!='') {
+       message='Not specified (optional): '+message+'.  Continue enrollment?';
+       if (confirm(message)) {
+          vf.state.value='enrolling';
+	  vf.submit();
+       }
+    } else {
+      vf.state.value='enrolling';
+      vf.submit();
+    }
+}
+
+ENDPICK
+
+}
+
 ###############################################################
 ###############################################################
 sub upload_manager_javascript_forward_associate {
@@ -678,32 +708,132 @@
     return $result;
 }
 
-# ======================================================= Menu Phase Two Enroll
+##
+## Single student enrollment routines (some of them)
+##
+sub get_student_username_domain_form {
+    my $r = shift;
+    my $domform = &Apache::loncommon::select_dom_form
+        ($r->dir_config('lonDefDomain'),'cudomain',0);
+    $r->print(<<END);
+<input type="hidden" name="action" value="enrollstudent" />
+<input type="hidden" name="state"  value="gotusername" />
+<h3>Enroll One Student</h3>
+<table>
+<tr><th>Username:</th>
+    <td><input type="text" name="cuname"  size="15" /></td></tr>
+<tr><th>Domain:</th>
+    <td>$domform</td></tr>
+<tr><th>&nbsp;</th>
+    <td>
+    <input type="submit" name="Begin Enrollment" value="Begin Enrollment" />
+    </td></tr>
+</table>
+END
+    return;
+}
+
 sub print_enroll_single_student_form {
     my $r=shift;
     $r->print("<h3>Enroll One Student</h3>");
-    my $today    = time;
-    my $halfyear = $today+15552000;
-    my $defdom=$r->dir_config('lonDefDomain');
-    # Set up authentication forms
-    my ($krbdef,$krbdefdom) =
-        &Apache::loncommon::get_kerberos_defaults($defdom);
-    my $javascript_validations=&javascript_validations($krbdefdom);
-    my %param = ( formname => 'document.studentform',
-                  kerb_def_dom => $krbdefdom,
-                  kerb_def_auth => $krbdef
-                  );
-    my $krbform = &Apache::loncommon::authform_kerberos(%param);
-    my $intform = &Apache::loncommon::authform_internal(%param);
-    my $locform = &Apache::loncommon::authform_local(%param);
-    # Set up domain selection form
-    my $domform = &domain_form($defdom);
+    #
+    my $username = $ENV{'form.cuname'};
+    my $domain   = $ENV{'form.cudomain'};
+    my $home = &Apache::lonnet::homeserver($username,$domain);
+    # $new_user flags whether we are creating a new user or using an old one
+    my $new_user = 1;
+    if ($home ne 'no_host') {
+        $new_user = 0;
+    }
+    &Apache::lonnet::logthis('home = '.$home);
+    #
+    my $user_data_html = '';
+    my $javascript_validations = '';
+    if ($new_user) {
+        my $defdom=$r->dir_config('lonDefDomain');
+        # Set up authentication forms
+        my ($krbdef,$krbdefdom) =
+            &Apache::loncommon::get_kerberos_defaults($defdom);
+        $javascript_validations=&javascript_validations($krbdefdom);
+        my %param = ( formname => 'document.studentform',
+                      kerb_def_dom => $krbdefdom,
+                      kerb_def_auth => $krbdef
+                      );
+        my $krbform = &Apache::loncommon::authform_kerberos(%param);
+        my $intform = &Apache::loncommon::authform_internal(%param);
+        my $locform = &Apache::loncommon::authform_local(%param);
+        #
+        # Set up domain selection form
+        my $homeserver_form = '';
+        my %servers = &Apache::loncommon::get_library_servers($domain);
+        $homeserver_form = '<select name="lcserver" size="1">'."\n".
+            '<option value="default" selected>default</option>'."\n";
+        while (my ($servername,$serverdescription) = each (%servers)) {
+            $homeserver_form .= '<option value="'.$servername.'">'.
+                $serverdescription."</option>\n";
+        }
+        $homeserver_form .= "</select>\n";
+        #
+        #
+        $user_data_html = <<END;
+<h3>User Data for $username\@$domain</h3>
+<table>
+<tr><th>First Name:</th>
+    <td><input type="text" name="cfirst"  size="15"></td></tr>
+<tr><th>Middle Name:</th>
+    <td><input type="text" name="cmiddle" size="15"></td></tr>
+<tr><th>Last Name:</th>
+    <td><input type="text" name="clast"   size="15"></td></tr>
+<tr><th>Generation:</th>
+    <td><input type="text" name="cgen"    size="5"> </td></tr>
+<tr><th>Home Server:</th>
+    <td>$homeserver_form</td></tr>
+</table>
+<h3>Password</h3>
+Please select an authentication mechanism
+<table>
+<p>
+$krbform
+</p><p>
+$intform
+</p><p>
+$locform
+</p>
+END
+    } else {
+        # User already exists.  Do not worry about authentication
+        my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
+        $javascript_validations = &javascript_validations_without_auth();
+        $user_data_html = <<END;
+<h3>User Data for $username\@$domain</h3>
+<input type="hidden" name="lcserver" value="default" />
+<table>
+<tr><th>First Name:</th>
+    <td>
+    <input type="text" name="cfirst" value="$uenv{'firstname'}" size="15" />
+    </td></tr>
+<tr><th>Middle Name:</th>
+    <td>
+    <input type="text" name="cmiddle" value="$uenv{'middlename'}" size="15" />
+    </td></tr>
+<tr><th>Last Name:</th>
+    <td>
+    <input type="text" name="clast"value="$uenv{'lastname'}" size="15" />
+    </td></tr>
+<tr><th>Generation:</th>
+    <td>
+    <input type="text" name="cgen" value="$uenv{'generation'}" size="5" />
+    </td></tr>
+</table>
+END
+    }
     my $date_table = &date_setting_table();
-    # Print it all out
+        # Print it all out
     $r->print(<<END);
-<input type="hidden" name="action" value="enrollstudent">
-<input type="hidden" name="state"  value="done">
-
+<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" />
 <script type="text/javascript" language="Javascript">
 function verify(vf) {
     var founduname=0;
@@ -740,25 +870,8 @@
 }
 
 </script>
-<h3>Personal Data</h3>
-<table>
-<tr><td>First Name:</td><td> <input type="text" name="cfirst"  size="15"></td></tr>
-<tr><td>Middle Name:</td><td> <input type="text" name="cmiddle" size="15"></td></tr>
-<tr><td>Last Name: </td><td><input type="text" name="clast"   size="15"></td></tr>
-<tr><td>Generation: </td><td><input type="text" name="cgen"    size="5"> </td></tr>
-</table>
 
-<h3>Login Data</h3>
-<p>Username: <input type="text" name="cuname"  size="15"></p>
-<p>Domain:   $domform</p>
-<p>Note: login settings below  will not take effect if the user already exists
-</p><p>
-$krbform
-</p><p>
-$intform
-</p><p>
-$locform
-</p><p>
+$user_data_html
 
 <h3>Course Data</h3>
 
@@ -1648,7 +1761,8 @@
  upload           enrolling      enroll students based on upload
  drop             undefined      print the classlist ready to drop
  drop             done           drop the selected students
- enrollstudent    undefined      print single student enroll menu
+ enrollstudent    undefined      print student username domain form
+ enrollstudent    gotusername    print single student enroll menu
  enrollstudent    enrolling      enroll student
  classlist        undefined      print html classlist
  classlist        csv            print csv classlist
@@ -1716,11 +1830,13 @@
         }
     } elsif ($ENV{'form.action'} eq 'enrollstudent') {
         if (! exists($ENV{'form.state'})) {
+            &get_student_username_domain_form($r);
+        } elsif ($ENV{'form.state'} eq 'gotusername') {
             &print_enroll_single_student_form($r);
         } elsif ($ENV{'form.state'} eq 'enrolling') {
             &enroll_single_student($r);
         } else {
-            &print_enroll_single_student_form($r);
+            &get_student_username_domain_form($r);
         }
     } elsif ($ENV{'form.action'} eq 'classlist') {
         if (! exists($ENV{'form.state'})) {

--matthew1058196359--