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

goltermann goltermann at source.lon-capa.org
Fri Nov 30 10:09:17 EST 2012


goltermann		Fri Nov 30 15:09:17 2012 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  improved style:
  - added confirm_success for role changes
  - table of modified user info now only shows changed values
  - added actionbox after user modification
  - replaced "please be patient" with progressbar
  
  valid xhtml code (form action, closure)
  
  
  
-------------- next part --------------
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.366 loncom/interface/loncreateuser.pm:1.367
--- loncom/interface/loncreateuser.pm:1.366	Tue Oct  2 18:08:12 2012
+++ loncom/interface/loncreateuser.pm	Fri Nov 30 15:09:17 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.366 2012/10/02 18:08:12 bisitz Exp $
+# $Id: loncreateuser.pm,v 1.367 2012/11/30 15:09:17 goltermann Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2432,13 +2432,14 @@
         # If they are creating a new user but have not specified login
         # information this will be caught below.
     } else {
-	    $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);    
-	    return;
+            $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
+            return;
     }
 
     $r->print('<h3>'.&mt('User [_1] in domain [_2]',
-			 $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
-    $r->print('<p class="LC_info">'.&mt('Please be patient').'</p>');
+                        $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
+                        $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
+    my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
 
     my (%alerts,%rulematch,%inst_results,%curr_rules);
     my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
@@ -2499,6 +2500,7 @@
                 }
             }
         }
+        &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
 	# Call modifyuser
 	my $result = &Apache::lonnet::modifyuser
 	    ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
@@ -2588,9 +2590,8 @@
 	    $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);    
 	}
     }
-
     $r->rflush(); # Finish display of header before time consuming actions start
-
+    &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
     ##
     my (@userroles,%userupdate,$cnum,$cdom,%namechanged);
     if ($context eq 'course') {
@@ -2902,7 +2903,8 @@
                                         $changeHash{'tools.'.$key};
                                 } else {
                                     $newenvhash{'environment.availabletools.'.$key} =
-          &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},                                            $key,'reload','tools');
+          &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
+          $key,'reload','tools');
                                 }
                             }
                         }
@@ -3005,6 +3007,7 @@
                   .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
                   .'</span>');
     }
+    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
     if ($env{'form.action'} eq 'singlestudent') {
         &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
         $r->print('<p><a href="javascript:backPage(document.userupdate)">');
@@ -3036,10 +3039,9 @@
         if ($env{'form.popup'}) {
             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
         } else {
-            $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
-                     .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
-                     .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
-                     .&mt('Create/Modify Another User').'</a></p>');
+            $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
+                     .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
+                     '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
         }
     }
 }
@@ -3084,70 +3086,36 @@
     my $title = $lt{'ui'}; 
     if ($changed) {
         $title = $lt{'uic'};
-    }
-    $r->print('<h4>'.$title.'</h4>'.
-              &Apache::loncommon::start_data_table().
-              &Apache::loncommon::start_data_table_header_row());
-    if ($changed) {
+        $r->print('<h4>'.$title.'</h4>'.
+                &Apache::loncommon::start_data_table().
+                &Apache::loncommon::start_data_table_header_row());
         $r->print("<th> </th>\n");
-    }
-    my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
-    foreach my $item (@userinfo) {
-        $r->print("<th>$lt{$item}</th>\n");
-    }
-    foreach my $entry (@{$order}) {
-        if ($canshow->{$entry}) {
-            if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
-                foreach my $item (@{$requestcourses}) {
-                    $r->print("<th>$lt{$item}</th>\n");
-                }
-            } elsif ($entry eq 'tools') {
-                foreach my $item (@{$usertools}) {
-                    $r->print("<th>$lt{$item}</th>\n");
-                }
-            } else {
-                $r->print("<th>$lt{$entry}</th>\n");
-            }
-        }
-    }
-    $r->print(&Apache::loncommon::end_data_table_header_row().
-             &Apache::loncommon::start_data_table_row());
-    if ($changed) {
-        $r->print('<td><b>'.$lt{'prvs'}.'</b></td>'."\n");
-    }
-    foreach my $item (@userinfo) {
-        $r->print('<td>'.$userenv->{$item}.' </td>'."\n");
-    }
-    foreach my $entry (@{$order}) {
-        if ($canshow->{$entry}) {
-            if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
-                foreach my $item (@{$requestcourses}) {
-                    $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
-                }
-            } elsif ($entry eq 'tools') {
-                foreach my $item (@{$usertools}) {
-                    $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
-                }
-            } else {
-                $r->print("<td>$oldsetting->{$entry} $oldsettingtext->{$entry} </td>\n");
-            }
-        }
-    }
-    $r->print(&Apache::loncommon::end_data_table_row());
-    if ($changed) {
-        $r->print(&Apache::loncommon::start_data_table_row().
-                  '<td><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></td>'."\n");
+        $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
+        $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
+        $r->print(&Apache::loncommon::end_data_table_header_row());
+        my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
+        
+
         foreach my $item (@userinfo) {
             my $value = $env{'form.c'.$item};
-            if ($namechangedhash->{$item}) {
-                $value = '<span class="LC_cusr_emph">'.$value.'</span>';
+            #show changes only:
+            unless($value eq $userenv->{$item}){
+                $r->print(&Apache::loncommon::start_data_table_row());
+
+                $r->print("<td>$lt{$item}</td>\n");
+                $r->print('<td>'.$userenv->{$item}.' </td>');
+                $r->print("<td>$value </td>\n");
+
+                $r->print(&Apache::loncommon::end_data_table_row());
             }
-            $r->print("<td>$value </td>\n");
         }
         foreach my $entry (@{$order}) {
-            if ($canshow->{$entry}) {
+            if ($canshow->{$entry} && ($newsetting->{$entry} ne $newsetting->{$entry})) {
+                $r->print(&Apache::loncommon::start_data_table_row());
                 if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
                     foreach my $item (@{$requestcourses}) {
+                        $r->print("<td>$lt{$item}</td>\n");
+                        $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
                         my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
                         if ($changedhash->{$item}) {
                             $value = '<span class="LC_cusr_emph">'.$value.'</span>';
@@ -3156,6 +3124,8 @@
                     }
                 } elsif ($entry eq 'tools') {
                     foreach my $item (@{$usertools}) {
+                        $r->print("<td>$lt{$item}</td>\n");
+                        $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
                         my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
                         if ($changedhash->{$item}) {
                             $value = '<span class="LC_cusr_emph">'.$value.'</span>';
@@ -3163,17 +3133,19 @@
                         $r->print("<td>$value </td>\n");
                     }
                 } else {
+                    $r->print("<td>$lt{$entry}</td>\n");
+                    $r->print("<td>$oldsetting->{$entry} $oldsettingtext->{$entry} </td>\n");
                     my $value = $newsetting->{$entry}.' '.$newsettingtext->{$entry};
                     if ($changedhash->{$entry}) {
                         $value = '<span class="LC_cusr_emph">'.$value.'</span>';
                     }
                     $r->print("<td>$value </td>\n");
                 }
+                $r->print(&Apache::loncommon::end_data_table_row());
             }
         }
-        $r->print(&Apache::loncommon::end_data_table_row());
+        $r->print(&Apache::loncommon::end_data_table().'<br />');
     }
-    $r->print(&Apache::loncommon::end_data_table().'<br />');
     return;
 }
 
@@ -3370,14 +3342,15 @@
 		    &Apache::lonnet::revokerole($env{'form.ccdomain'},
 						$env{'form.ccuname'},
 						$scope,$role,'','',$context);
-	        $r->print(&mt('Revoking [_1] in [_2]: [_3]',
-			      $role,$scope,'<b>'.$result.'</b>').'<br />');
+                $r->print(&Apache::lonhtmlcommon::confirm_success(
+                            &mt('Revoking [_1] in [_2]', &Apache::lonnet::plaintext($role), '"'.&cid_to_cname($scope).'"<br />'),
+                            $result ne "ok"));
 		if ($role eq 'st') {
 		    my $result = 
                         &Apache::lonuserutils::classlist_drop($scope,
                             $env{'form.ccuname'},$env{'form.ccdomain'},
 			    $now);
-		    $r->print($result);
+                    $r->print(&Apache::lonhtmlcommon::confirm_success($result));
 		}
                 if (!grep(/^\Q$role\E$/, at rolechanges)) {
                     push(@rolechanges,$role);
@@ -3385,11 +3358,10 @@
 	    }
 	    if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
 # Revoke custom role
-		$r->print(&mt('Revoking custom role:').
-                      ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
-                      &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
-				  $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
-		'</b><br />');
+                $r->print(&Apache::lonhtmlcommon::confirm_success(
+                            &mt('Revoking custom role [_1] by [_2]:[_3] in [_4]',$4,$3,$2,'"'.&cid_to_cname($1).'"<br />'),
+                            &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context) ne 'ok'));
+
                 if (!grep(/^cr$/, at rolechanges)) {
                     push(@rolechanges,'cr');
                 }
@@ -3403,8 +3375,10 @@
 						$env{'form.ccuname'},
 						$scope,$role,$now,0,1,'',
                                                 $context);
-	        $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
-			      '<b>'.$result.'</b>').'<br />');
+                $r->print(&Apache::lonhtmlcommon::confirm_success(
+                            &mt('Deleting [_1] in [_2]',
+                            &Apache::lonnet::plaintext($role),'"'.&cid_to_cname($scope).'"<br />'),$result ne 'ok'));
+
 		if ($role eq 'st') {
 		    my $result = 
                         &Apache::lonuserutils::classlist_drop($scope,
@@ -3419,11 +3393,12 @@
 	    if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
                 my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
 # Delete custom role
-                $r->print(&mt('Deleting custom role [_1] by [_2] in [_3]',
-                      $rolename,$rnam.':'.$rdom,$url).': <b>'.
+                $r->print(&confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
+                      $rolename,$rnam.':'.$rdom,'"'.&cid_to_cname($1).'"').'<br />'));
                       &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
                          $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
-                         0,1,$context).'</b><br />');
+                         0,1,$context);
+
                 if (!grep(/^cr$/, at rolechanges)) {
                     push(@rolechanges,'cr');
                 }
@@ -3447,18 +3422,16 @@
                                 $output = "Error: $result\n";
                             }
                         } else {
-                            $output = &mt('Assigning').' '.$role.' in '.$url.
-                                      &mt('starting').' '.localtime($now).
-                                      ': <br />'.$logmsg.'<br />'.
-                                      &mt('Add to classlist').': <b>ok</b><br />';
+                            $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',&Apache::lonnet::plaintext($role),
+                                        '"'.&cid_to_cname($url).'"',&Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
                         }
                     }
                 } else {
 		    my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
                                $env{'form.ccuname'},$url,$role,0,$now,'','',
                                $context);
-		    $output = &mt('Re-enabling [_1] in [_2]: [_3]',
-			      $role,$url,'<b>'.$result.'</b>').'<br />';
+                        $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
+                                        &Apache::lonnet::plaintext($role),'"'.&cid_to_cname($url).'"').'<br />',$result ne "ok");
 		}
                 $r->print($output);
                 if (!grep(/^\Q$role\E$/, at rolechanges)) {
@@ -3471,8 +3444,8 @@
                 my $result = &Apache::lonnet::assigncustomrole(
                                $env{'form.ccdomain'}, $env{'form.ccuname'},
                                $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
-                $r->print(&mt('Re-enabling custom role [_1] by [_2] in [_3]: [_4]',
-                          $rolename,$rnam.':'.$rdom,$url,'<b>'.$result.'</b>').'<br />');
+                $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling custom role [_1] by [_2] in [_3]',
+                        $rolename,$rnam.':'.$rdom,'"'.&cid_to_cname($1).'"').'<br />'),$result ne "ok");
                 if (!grep(/^cr$/, at rolechanges)) {
                     push(@rolechanges,'cr');
                 }
@@ -3692,7 +3665,7 @@
 sub update_result_form {
     my ($uhome) = @_;
     my $outcome = 
-    '<form name="userupdate" method="post" />'."\n";
+    '<form name="userupdate" method="post" action="">'."\n";
     foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
         $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
     }
@@ -6972,7 +6945,12 @@
 #--------------------------------- functions for &phase_two and &phase_three
 
 #--------------------------end of functions for &phase_two and &phase_three
-
+sub cid_to_cname(){
+    my $courseid = shift;
+    $courseid =~ s/^\///;
+    $courseid =~ s/\//_/;
+    return $env{'course.'.$courseid.'.description'};
+}
 1;
 __END__
 


More information about the LON-CAPA-cvs mailing list