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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 07 Dec 2007 23:09:31 -0000


This is a MIME encoded message

--raeburn1197068971
Content-Type: text/plain

raeburn		Fri Dec  7 18:09:31 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - Use &Apache::lonnet::modifyuser() to update user's environment.db file instead of a direct call to lonnet::put() so MySQL allusers table is updated
  - Display default indicator for user's portfolio quota, for both prior quota and new quota.
  - If quota is changed, store new value in all cases (including when other user information remains unchanged).
  - Display fullname, e-mail and quota on separate lines in cases where only changes are to roles and/or authentication method.  
  
  
--raeburn1197068971
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071207180931.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.203 loncom/interface/loncreateuser.pm:1.204
--- loncom/interface/loncreateuser.pm:1.203	Wed Dec  5 23:03:35 2007
+++ loncom/interface/loncreateuser.pm	Fri Dec  7 18:09:30 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.203 2007/12/06 04:03:35 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.204 2007/12/07 23:09:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1623,10 +1623,12 @@
             }
         }
         my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
-            $inststatus,$isdefault,$defquotatext);
+            $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
+            $newdefquotatext);
         my ($defquota,$settingstatus) = 
             &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
         my %changeHash;
+        $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
         if ($userenv{'portfolioquota'} ne '') {
             $oldportfolioquota = $userenv{'portfolioquota'};
             if ($env{'form.customquota'} == 1) {
@@ -1636,15 +1638,16 @@
                     $newportfolioquota = $env{'form.portfolioquota'};
                     $newportfolioquota =~ s/[^\d\.]//g;
                 }
-                if ($newportfolioquota != $userenv{'portfolioquota'}) {
+                if ($newportfolioquota != $oldportfolioquota) {
                     $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
                 }
             } else {
                 $quotachanged = &quota_admin('',\%changeHash);
                 $newportfolioquota = $defquota;
-                $isdefault = 1; 
+                $newisdefault = 1; 
             }
         } else {
+            $oldisdefault = 1;
             $oldportfolioquota = $defquota;
             if ($env{'form.customquota'} == 1) {
                 if ($env{'form.portfolioquota'} eq '') {
@@ -1656,21 +1659,14 @@
                 $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
             } else {
                 $newportfolioquota = $defquota;
-                $isdefault = 1;
+                $newisdefault = 1;
             }
         }
-        if ($isdefault) {
-            if ($settingstatus eq '') {
-                $defquotatext = &mt('(default)');
-            } else {
-                my ($usertypes,$order) = 
-                    &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
-                if ($usertypes->{$settingstatus} eq '') {
-                    $defquotatext = &mt('(default)');
-                } else { 
-                    $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
-                }
-            }
+        if ($oldisdefault) {
+            $olddefquotatext = &get_defaultquota_text($settingstatus);
+        }
+        if ($newisdefault) {
+            $newdefquotatext = &get_defaultquota_text($settingstatus);
         }
         if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) && 
             ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
@@ -1681,18 +1677,30 @@
              $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
             $namechanged = 1;
         }
-        if ($namechanged) {
-            # Make the change
+        if ($namechanged || $quotachanged) {
             $changeHash{'firstname'}  = $env{'form.cfirstname'};
             $changeHash{'middlename'} = $env{'form.cmiddlename'};
             $changeHash{'lastname'}   = $env{'form.clastname'};
             $changeHash{'generation'} = $env{'form.cgeneration'};
             $changeHash{'id'}         = $env{'form.cid'};
             $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
-            my $putresult = &Apache::lonnet::put
-                ('environment',\%changeHash,
-                 $env{'form.ccdomain'},$env{'form.ccuname'});
-            if ($putresult eq 'ok') {
+            my ($quotachgresult,$namechgresult);
+            if ($quotachanged) {
+                $quotachgresult = 
+                    &Apache::lonnet::put('environment',\%changeHash,
+                                  $env{'form.ccdomain'},$env{'form.ccuname'});
+            }
+            if ($namechanged) {
+            # Make the change
+                $namechgresult =
+                    &Apache::lonnet::modifyuser($env{'form.ccdomain'},
+                        $env{'form.ccuname'},$changeHash{'id'},undef,undef,
+                        $changeHash{'firstname'},$changeHash{'middlename'},
+                        $changeHash{'lastname'},$changeHash{'generation'},
+                        $changeHash{'id'},undef,$changeHash{'permanentemail'});
+            }
+            if (($namechanged && $namechgresult eq 'ok') || 
+                ($quotachanged && $quotachgresult eq 'ok')) {
             # Tell the user we changed the name
 		my %lt=&Apache::lonlocal::texthash(
                              'uic'  => "User Information Changed",             
@@ -1729,7 +1737,7 @@
     <td>$userenv{'generation'} </td>
     <td>$userenv{'id'}</td>
     <td>$userenv{'permanentemail'} </td>
-    <td>$oldportfolioquota Mb</td>
+    <td>$oldportfolioquota Mb $olddefquotatext </td>
 END
                 $r->print(&Apache::loncommon::end_data_table_row().
                           &Apache::loncommon::start_data_table_row());
@@ -1741,7 +1749,7 @@
     <td>$env{'form.cgeneration'} </td>
     <td>$env{'form.cid'} </td>
     <td>$env{'form.cpermanentemail'} </td>
-    <td>$newportfolioquota Mb $defquotatext </td>
+    <td>$newportfolioquota Mb $newdefquotatext </td>
 END
                 $r->print(&Apache::loncommon::end_data_table_row().
                           &Apache::loncommon::end_data_table());
@@ -1778,14 +1786,8 @@
                       $env{'form.ccdomain'}.'</span>');
             }
         }  else { # End of if ($env ... ) logic
-            my $putresult;
-            if ($quotachanged) {
-                $putresult = &Apache::lonnet::put
-                                 ('environment',\%changeHash,
-                                  $env{'form.ccdomain'},$env{'form.ccuname'});
-            }
-            # They did not want to change the users name but we can
-            # still tell them what the name is
+            # They did not want to change the users name or quota but we can
+            # still tell them what the name and quota are 
 	    my %lt=&Apache::lonlocal::texthash(
                            'id'   => "ID/Student number",
                            'mail' => "Permanent e-mail",
@@ -1794,19 +1796,12 @@
             $r->print(<<"END");
 <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
 END
-            if ($userenv{'permanentemail'} eq '') {
-                $r->print('</h4>');
-            } else {
-                $r->print('&nbsp;&nbsp;('.$lt{'mail'}.': '.
-                          $userenv{'permanentemail'}.')</h4>');
-            }
-            if ($putresult eq 'ok') {
-                if ($oldportfolioquota != $newportfolioquota) {
-                    $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '. 
-                              $defquotatext.'</h4>');
-                    &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
-                }
+            if ($userenv{'permanentemail'} ne '') {
+                $r->print('<br />['.$lt{'mail'}.': '.
+                          $userenv{'permanentemail'}.']');
             }
+            $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. 
+                 $olddefquotatext.']</h4>');
         }
     }
     ##
@@ -2035,6 +2030,23 @@
     $r->print(&Apache::loncommon::end_page());
 }
 
+sub get_defaultquota_text {
+    my ($settingstatus) = @_;
+    my $defquotatext; 
+    if ($settingstatus eq '') {
+        $defquotatext = &mt('(default)');
+    } else {
+        my ($usertypes,$order) =
+            &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
+        if ($usertypes->{$settingstatus} eq '') {
+            $defquotatext = &mt('(default)');
+        } else {
+            $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
+        }
+    }
+    return $defquotatext;
+}
+
 sub update_result_form {
     my ($uhome) = @_;
     my $outcome = 

--raeburn1197068971--