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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 12 Sep 2007 23:42:37 -0000


This is a MIME encoded message

--raeburn1189640557
Content-Type: text/plain

raeburn		Wed Sep 12 19:42:37 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - some style changes
  - simplify population of instsrch hash
  - homeserver check occurs earlier when modifying user
  
  When adding a new user ...
  - do username rule check, and early out if format matched but no instiutional user.
  - when adding a new user for whom there is institutional data, only provide textboxes for fields without data.
  - css for data entry table
  - authentication method/arg set automatically for usernames matching rules
  
  
--raeburn1189640557
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070912194237.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.184 loncom/interface/loncreateuser.pm:1.185
--- loncom/interface/loncreateuser.pm:1.184	Wed Sep 12 19:26:25 2007
+++ loncom/interface/loncreateuser.pm	Wed Sep 12 19:42:37 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.184 2007/09/12 23:26:25 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.185 2007/09/12 23:42:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -420,10 +420,29 @@
 
 sub print_user_modification_page {
     my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
-    unless (($ccuname) && ($ccdomain)) {
-	&print_username_entry_form($r);
+    if (($ccuname eq '') || ($ccdomain eq '')) {
+        my $usermsg = &mt('No username and/or domain provided.'); 
+	&print_username_entry_form($r,$usermsg);
         return;
     }
+    my ($instsrch,$rulematch,$rules,%inst_results);
+    my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
+    if ($uhome eq 'no_host') {
+        $instsrch =
+                      {
+                         srchin => 'instd',
+                         srchby => 'uname',
+                         srchtype => 'exact',
+                         srchterm => $ccuname,
+                         srchdomain => $ccdomain,
+                       };
+        (my $usercheckmsg,$rulematch,$rules,%inst_results) = 
+            &Apache::loncommon::username_rule_check($instsrch,'new');
+        if ($usercheckmsg) {
+            &print_username_entry_form($r,$usercheckmsg);
+            return;
+        }
+    }
     if ($response) {
         $response = '<br />'.$response
     }
@@ -675,7 +694,6 @@
 <input type="hidden" name="pres_type"   value="" />
 <input type="hidden" name="pres_marker" value="" />
 ENDFORMINFO
-    my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
     my %inccourses;
     foreach my $key (keys(%env)) {
 	if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
@@ -683,51 +701,41 @@
         }
     }
     if ($uhome eq 'no_host') {
-        my $newuser;
-        my $instsrch = {
-                         srchin => 'instd',
-                         srchby => 'uname',
-                         srchtype => 'exact',
-                       };
-        if ($env{'form.phase'} eq 'userpicked') {
-            $instsrch->{'srchterm'} = $env{'form.seluname'};
-            $instsrch->{'srchdomain'} = $env{'form.seludom'};
-        } else {
-            $instsrch->{'srchterm'} = $ccuname;
-            $instsrch->{'srchdomain'} = $ccdomain,
-        }
-        if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
-            $newuser = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
-        }
-        my (%dirsrch_results,%inst_results,$dirsrchres);
-        if ($newuser) {
-            if (&directorysrch_check($instsrch) eq 'ok') {
-                ($dirsrchres,%dirsrch_results) = &Apache::lonnet::inst_directory_query($instsrch);
-                if ($dirsrchres eq 'ok') {
-                    if (ref($dirsrch_results{$newuser}) eq 'HASH') { 
-                        %inst_results = %{$dirsrch_results{$newuser}};
-                    }
-                }
-            }
-        }
         my $home_server_list=
             '<option value="default" selected>default</option>'."\n".
                 &Apache::loncommon::home_server_option_list($ccdomain);
         
 	my %lt=&Apache::lonlocal::texthash(
-                    'cnu'  => "Create New User",
-                    'nu'   => "New User",
-                    'id'   => "in domain",
-                    'pd'   => "Personal Data",
-                    'fn'   => "First Name",
-                    'mn'   => "Middle Name",
-                    'ln'   => "Last Name",
-                    'gen'  => "Generation",
-                    'mail' => "Permanent e-mail address",
-                    'idsn' => "ID/Student Number",
-                    'hs'   => "Home Server",
-                    'lg'   => "Login Data"
+                    'cnu'            => "Create New User",
+                    'nu'             => "New User",
+                    'ind'            => "in domain",
+                    'pd'             => "Personal Data",
+                    'firstname'      => "First Name",
+                    'middlename'     => "Middle Name",
+                    'lastname'       => "Last Name",
+                    'generation'     => "Generation",
+                    'permanentemail' => "Permanent e-mail address",
+                    'id'             => "ID/Student Number",
+                    'hs'             => "Home Server",
+                    'lg'             => "Login Data"
 				       );
+        my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
+        my %textboxsize = (
+                           firstname      => '15',
+                           middlename     => '15',
+                           lastname       => '15',
+                           generation     => '5',
+                           permanentemail => '25',
+                           id             => '15',
+                          );
+        my %element   = (
+                           firstname      => 'cfirst', 
+                           middlename     => 'cmiddle',
+                           lastname       => 'clast',
+                           generation     => 'cgen',
+                           permanentemail => 'cemail',
+                           id             => 'cstid',
+                          );
         my $portfolioform;
         if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
             # Current user has quota modification privileges
@@ -735,43 +743,91 @@
         }
 	my $genhelp=&Apache::loncommon::help_open_topic('Generation');
         &initialize_authen_forms();
-	$r->print(<<ENDNEWUSER);
+	$r->print(<<ENDTITLE);
 $start_page
 $crumbs
 <h1>$lt{'cnu'}</h1>
 $response
 $forminfo
-<h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
+<h2>$lt{'nu'} "$ccuname" $lt{'ind'} $ccdomain</h2>
 <script type="text/javascript" language="Javascript">
 $loginscript
 </script>
 <input type='hidden' name='makeuser' value='1' />
 <h3>$lt{'pd'}</h3>
 <p>
-<table>
-<tr><td>$lt{'fn'}  </td>
-    <td><input type="text" name="cfirst" size="15" value="$inst_results{'firstname'}" /></td></tr>
-<tr><td>$lt{'mn'} </td> 
-    <td><input type="text" name="cmiddle" size="15" value="$inst_results{'middlename'}" /></td></tr>
-<tr><td>$lt{'ln'}   </td>
-    <td><input type="text" name="clast" size="15" value="$inst_results{'lastname'}" /></td></tr>
-<tr><td>$lt{'gen'}$genhelp</td>
-    <td><input type="text" name="cgen" size="5" value="$inst_results{'generation'}" /></td></tr>
-<tr><td>$lt{'mail'}</td>
-    <td><input type="text" name="cemail" size="20" value="$inst_results{'permanentemail'}" /></td></tr>
-</table>
-$lt{'idsn'} <input type="text" name="cstid" size="15" value="$inst_results{'id'}" /></p>
+ENDTITLE
+        $r->print(&Apache::lonhtmlcommon::start_pick_box());
+        foreach my $item (@userinfo) {
+            my $rowtitle = $lt{$item};
+            if ($item eq 'generation') {
+                $rowtitle = $genhelp.$rowtitle;
+            }
+            $r->print(&Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n");
+            if ($inst_results{$item} ne '') {
+                $r->print('<input type="hidden" name="'.$element{$item}.'" value="'.$inst_results{$item}.'" />'.$inst_results{$item});
+            } else {
+                $r->print('<input type="text" name="'.$element{$item}.'" size="'.$textboxsize{$item}.'" value="" />');
+            }
+            $r->print(&Apache::lonhtmlcommon::row_closure(1));
+        }
+        $r->print(&Apache::lonhtmlcommon::end_pick_box());
+        $r->print(<<ENDNEWUSER);
+<br />
 $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
+<br />
 <hr />
 <h3>$lt{'lg'}</h3>
-<p>$generalrule </p>
-<p>$authformkrb </p>
-<p>$authformint </p>
-<p>$authformfsys</p>
-<p>$authformloc </p>
+ENDNEWUSER
+        my ($fixedauth,$varauth,$authmsg); 
+        if ($rulematch) {
+            if (ref($rules) eq 'HASH') {
+                if (ref($rules->{$rulematch}) eq 'HASH') {
+                    my $authtype = $rules->{$rulematch}{'authtype'};
+                    if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
+                        $r->print(&set_login());
+                    } else { 
+                        my $authparm = $rules->{$rulematch}{'authparm'};
+                        if ($authtype =~ /^krb(4|5)$/) {
+                            my $ver = $1;
+                            if ($authparm ne '') {
+                                $fixedauth = <<"KERB"; 
+<input type="hidden" name="login" value="krb" />
+<input type="hidden" name="krbver" value="$ver" />
+<input type="hidden" name="krbarg" value="$authparm" />
+KERB
+                                $authmsg = $rules->{$rulematch}{'authmsg'};    
+                            }
+                        } else {
+                            $fixedauth = 
+'<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
+                            if ($rules->{$rulematch}{'authparmfixed'}) {
+                                $fixedauth .=    
+'<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
+                            } else {
+                                $varauth =  
+'<input type="text" name="'.$authtype.'arg" value="" />'."\n";
+                            }
+                        }
+                    }
+                } else {
+                    $r->print(&set_login());
+                }
+            }
+            if ($authmsg) {
+                $r->print(<<ENDAUTH);
+$fixedauth
+$authmsg
+$varauth
+ENDAUTH
+            }
+        } else {
+            $r->print(&set_login()); 
+         }
+         $r->print(<<ENDPORT);
 <hr />
 $portfolioform
-ENDNEWUSER
+ENDPORT
     } else { # user already exists
 	my %lt=&Apache::lonlocal::texthash(
                     'cup'  => "Change User Privileges",
@@ -1230,6 +1286,17 @@
     $r->print("</form>".&Apache::loncommon::end_page());
 }
 
+sub set_login {
+    my $response = (<<ENDAUTH);
+<p>$generalrule </p>
+<p>$authformkrb </p>
+<p>$authformint </p>
+<p>$authformfsys</p>
+<p>$authformloc </p>
+ENDAUTH
+    return $response;
+}
+
 # ================================================================= Phase Three
 sub update_user_data {
     my ($r) = @_; 
@@ -2494,7 +2561,6 @@
     }
 }
 
-
 sub get_courseusers {
     my %advhash;
     my $classlist = &Apache::loncoursedata::get_classlist();

--raeburn1189640557--