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

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 22 Mar 2002 22:23:23 -0000


This is a MIME encoded message

--matthew1016835803
Content-Type: text/plain

matthew		Fri Mar 22 17:23:23 2002 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  Changed a lonnet::reply to lonnet::dump, added ability to change user
  name and display of name if the current user does not have MAU authorization.
  
  
--matthew1016835803
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020322172323.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.27 loncom/interface/loncreateuser.pm:1.28
--- loncom/interface/loncreateuser.pm:1.27	Tue Feb 12 16:42:18 2002
+++ loncom/interface/loncreateuser.pm	Fri Mar 22 17:23:23 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.27 2002/02/12 21:42:18 matthew Exp $
+# $Id: loncreateuser.pm,v 1.28 2002/03/22 22:23:23 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,7 +47,7 @@
 # 11/12,11/13,11/15 Scott Harrison
 # 02/11/02 Matthew Hall
 #
-# $Id: loncreateuser.pm,v 1.27 2002/02/12 21:42:18 matthew Exp $
+# $Id: loncreateuser.pm,v 1.28 2002/03/22 22:23:23 matthew Exp $
 ###
 
 package Apache::loncreateuser;
@@ -295,9 +295,7 @@
     <td><input type='text' name='cgen'    size='5'  /></td></tr>
 </table>
 ID/Student Number <input type='text' name='cstid'   size='15' /></p>
-
 <hr />
-
 <h3>Login Data</h3>
 $generalrule
 $authformkrb
@@ -312,71 +310,98 @@
 $forminfo
 <h2>User "$ccuname" in domain $ccdomain </h2>
 ENDCHANGEUSER
-        my $rolesdump=&Apache::lonnet::reply(
-                                  "dump:$ccdomain:$ccuname:roles",$uhome);
+        # Get the users information
+        my %userenv = &Apache::lonnet::get('environment',
+                          ['firstname','middlename','lastname','generation'],
+                          $ccdomain,$ccuname);
+        my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
+        $r->print(<<END);
+<hr />
+<table border="2">
+<tr>
+<th>first name</th><th>middle name</th><th>last name</th><th>generation</th>
+</tr>
+<tr>
+END
+        foreach ('firstname','middlename','lastname','generation') {
+           if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+              $r->print(<<"END");            
+<td><input type="text" name="c$_" value="$userenv{$_}" size="15"/></td>
+END
+           } else {
+               $r->print('<td>'.$userenv{$_}.'</td>');
+           }
+        }
+        $r->print(<<END);
+</tr>
+</table>
+END
         # Build up table of user roles to allow revocation of a role.
-        unless ($rolesdump eq 'con_lost' || $rolesdump =~ m/^error/i) { 
+        my ($tmp) = keys(%rolesdump);
+        unless ($tmp =~ /^(con_lost|error)/i) {
            my $now=time;
            $r->print('<hr /><h3>Revoke Existing Roles</h3>'.
              '<table border=2><tr><th>Revoke</th><th>Role</th><th>Extent</th>'.
 	     '<th>Start</th><th>End</th>');
-	   foreach (split(/&/,$rolesdump)) {
-             if ($_!~/^rolesdef\&/) {
-              my ($area,$role)=split(/=/,$_);
-              my $thisrole=$area;
-              $area=~s/\_\w\w$//;
-              my ($role_code,$role_end_time,$role_start_time)=split(/_/,$role);
-              my $bgcol='ffffff';
-              my $allows=0;
-              if ($area=~/^\/(\w+)\/(\d\w+)/) {
-                 my %coursedata=&Apache::lonnet::coursedescription($1.'_'.$2);
-                 my $carea='Course: '.$coursedata{'description'};
-                 $inccourses{$1.'_'.$2}=1;
-                 if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) {
-		     $allows=1;
-                 }
-		 # Compute the background color based on $area
-                 $bgcol=$1.'_'.$2;
-                 $bgcol=~s/[^8-9b-e]//g;
-                 $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
-                 if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
-                     $carea.='<br>Section/Group: '.$3;
-		 }
-                 $area=$carea;
-	      } else {
-		 # Determine if current user is able to revoke privileges
-                 if ($area=~/^\/(\w+)\//) {
-                     if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
-			 $allows=1;
-                     }
+	   foreach my $area (keys(%rolesdump)) {
+              if ($area!~/^rolesdef/) {
+                 my $role = $rolesdump{$area};
+                 my $thisrole=$area;
+                 $area=~s/\_\w\w$//;
+                 my ($role_code,$role_end_time,$role_start_time) =
+                     split(/_/,$role);
+                 my $bgcol='ffffff';
+                 my $allows=0;
+                 if ($area=~/^\/(\w+)\/(\d\w+)/) {
+                    my %coursedata=
+                        &Apache::lonnet::coursedescription($1.'_'.$2);
+                    my $carea='Course: '.$coursedata{'description'};
+                    $inccourses{$1.'_'.$2}=1;
+                    if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) {
+                        $allows=1;
+                    }
+                    # Compute the background color based on $area
+                    $bgcol=$1.'_'.$2;
+                    $bgcol=~s/[^8-9b-e]//g;
+                    $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
+                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
+                       $carea.='<br>Section/Group: '.$3;
+                    }
+                    $area=$carea;
                  } else {
-                     if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
-			 $allows=1;
+                     # Determine if current user is able to revoke privileges
+                     if ($area=~/^\/(\w+)\//) {
+                        if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
+                           $allows=1;
+                        }
+                     } else {
+                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
+                           $allows=1;
+                        }
                      }
                  }
-	      }
-
-              $r->print('<tr bgcolor=#"'.$bgcol.'"><td>');
-              my $active=1;
-              if (($role_end_time) && ($now>$role_end_time)) { $active=0; }
-              if (($active) && ($allows)) {
-		  $r->print('<input type="checkbox" name="rev:'
-			    .$thisrole.'">');
-              } else {
-                  $r->print('&nbsp;');
+                 $r->print('<tr bgcolor=#"'.$bgcol.'"><td>');
+                 my $active=1;
+                 $active=0 if (($role_end_time) && ($now>$role_end_time));
+                 if (($active) && ($allows)) {
+                    $r->print('<input type="checkbox" name="rev:'
+                              .$thisrole.'">');
+                 } else {
+                    $r->print('&nbsp;');
+                 }
+                 $r->print('</td><td>'.
+                           &Apache::lonnet::plaintext($role_code).
+                           '</td><td>'.$area.'</td><td>'.
+                           ($role_start_time ? localtime($role_start_time)
+                                             : '&nbsp;' )
+                           .'</td><td>'.
+                           ($role_end_time   ? localtime($role_end_time)
+                                             : '&nbsp;' )
+                           ."</td></tr>\n");
               }
-              $r->print('</td><td>'.&Apache::lonnet::plaintext($role_code).
-                        '</td><td>'.$area.'</td><td>'.
-                        ($role_start_time ? localtime($role_start_time)
-                                          : '&nbsp;' )
-			.'</td><td>'.
-                        ($role_end_time   ? localtime($role_end_time)
-                                          : '&nbsp;' )
-			."</td></tr>\n");
-	     }
-	   } 
+           } # end of foreach        (table building loop)
 	   $r->print('</table>');
-         }   
+        }  # End of unless
 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
 	if ($currentauth=~/^krb4:/) {
 	    $currentauth=~/^krb4:(.*)/;
@@ -639,6 +664,72 @@
 	    $r->print($error.'You do not have the authority to modify '.
 		      'this users authentification information.');    
 	}
+    }
+    ##
+    if (! $ENV{'form.makeuser'} ) {
+        # Check for need to change
+        my %userenv = &Apache::lonnet::get
+            ('environment',['firstname','middlename','lastname','generation'],
+             $ENV{'form.cdomain'},$ENV{'form.cuname'});
+        my ($tmp) = keys(%userenv);
+        if ($tmp =~ /^(con_lost|error)/i) { 
+            %userenv = ();
+        }
+        # Check to see if we need to change user information
+        foreach ('firstname','middlename','lastname','generation') {
+            # Strip leading and trailing whitespace
+            $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
+        }
+        if (&Apache::lonnet::allowed('mau',$ENV{'form.cdomain'}) && 
+            ($ENV{'form.cfirstname'}  ne $userenv{'firstname'}  ||
+             $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
+             $ENV{'form.clastname'}   ne $userenv{'lastname'}   ||
+             $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
+            # Make the change
+            my %changeHash;
+            $changeHash{'firstname'}  = $ENV{'form.cfirstname'};
+            $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
+            $changeHash{'lastname'}   = $ENV{'form.clastname'};
+            $changeHash{'generation'} = $ENV{'form.cgeneration'};
+            my $putresult = &Apache::lonnet::put
+                ('environment',\%changeHash,
+                 $ENV{'form.cdomain'},$ENV{'form.cuname'});
+            if ($putresult eq 'ok') {
+            # Tell the user we changed the name
+                $r->print(<<"END");
+<table border="2">
+<caption>User Information Changed</caption>
+<tr><th>&nbsp;</th>
+    <th>first</th>
+    <th>middle</th>
+    <th>last</th>
+    <th>generation</th></tr>
+<tr><td>Previous</td>
+    <td>$userenv{'firstname'}  </td>
+    <td>$userenv{'middlename'} </td>
+    <td>$userenv{'lastname'}   </td>
+    <td>$userenv{'generation'} </td></tr>
+<tr><td>Changed To</td>
+    <td>$ENV{'form.cfirstname'}  </td>
+    <td>$ENV{'form.cmiddlename'} </td>
+    <td>$ENV{'form.clastname'}   </td>
+    <td>$ENV{'form.cgeneration'} </td></tr>
+</table>
+END
+            } else { # error occurred
+                $r->print("<h2>Unable to successfully change environment for ".
+                      $ENV{'form.cuname'}." in domain ".
+                      $ENV{'form.cdomain'}."</h2>");
+            }
+        }  else { # End of if ($ENV ... ) logic
+            # They did not want to change the users name but we can
+            # still tell them what the name is
+                $r->print(<<"END");
+<h2>User "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"</h2>
+<h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
+<h4>Generation: $userenv{'generation'}</h4>
+END
+        }
     }
     ##
     my $now=time;

--matthew1016835803--