--- loncom/interface/loncreateuser.pm	2004/02/01 20:42:01	1.78
+++ loncom/interface/loncreateuser.pm	2004/08/24 23:50:15	1.86
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.78 2004/02/01 20:42:01 www Exp $
+# $Id: loncreateuser.pm,v 1.86 2004/08/24 23:50:15 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -123,10 +123,7 @@ sub print_username_entry_form {
     my $defdom=$ENV{'request.role.domain'};
     my @domains = &Apache::loncommon::get_domains();
     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
-    my $bodytag =&Apache::loncommon::bodytag(
-                                  'Create Users, Change User Privileges').
-		  &Apache::loncommon::help_open_faq(282).
-		  &Apache::loncommon::help_open_bug('Instructor Interface');
+    my $bodytag =&Apache::loncommon::bodytag('Create Users, Change User Privileges').&Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
     my $selscript=&Apache::loncommon::studentbrowser_javascript();
     my $sellink=&Apache::loncommon::selectstudent_link
                                         ('crtuser','ccuname','ccdomain');
@@ -177,8 +174,8 @@ sub print_user_modification_page {
     my $ccuname=$ENV{'form.ccuname'};
     my $ccdomain=$ENV{'form.ccdomain'};
 
-    $ccuname=~s/\W//gs;
-    $ccdomain=~s/\W//gs;
+    $ccuname=~s/[\W|_]//gs;
+    $ccdomain=~s/[\W|_]//gs;
 
     unless (($ccuname) && ($ccdomain)) {
 	&print_username_entry_form($r);
@@ -250,7 +247,7 @@ ENDFORMINFO
             '<option value="default" selected>default</option>'."\n".
                 &Apache::loncommon::home_server_option_list($ccdomain);
         
-    my %lt=&Apache::lonlocal::texthash(
+	my %lt=&Apache::lonlocal::texthash(
                     'cnu'  => "Create New User",
                     'nu'   => "New User",
                     'id'   => "in domain",
@@ -296,7 +293,7 @@ $lt{'hs'}: <select name="hserver" size="
 <p>$authformloc </p>
 ENDNEWUSER
     } else { # user already exists
-    my %lt=&Apache::lonlocal::texthash(
+	my %lt=&Apache::lonlocal::texthash(
                     'cup'  => "Change User Privileges",
                     'usr'  => "User",                    
                     'id'   => "in domain",
@@ -345,6 +342,7 @@ END
 		    'rer'  => "Revoke Existing Roles",
                     'rev'  => "Revoke",                    
                     'del'  => "Delete",
+		    'ren'  => "Re-Enable",
                     'rol'  => "Role",
                     'ext'  => "Extent",
                     'sta'  => "Start",
@@ -353,14 +351,16 @@ END
            $r->print(<<END);
 <hr />
 <h3>$lt{'rer'}</h3>
-<table border=2>
-<tr><th>$lt{'rev'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
+<table>
+<tr><th>$lt{'rev'}</th><th>$lt{'ren'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
 END
+           my (%roletext,%sortrole,%roleclass);
 	   foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
 				    my $b1=join('_',(split('_',$b))[1,0]);
 				    return $a1 cmp $b1;
 				} keys(%rolesdump)) {
                next if ($area =~ /^rolesdef/);
+	       my $envkey=$area;
                my $role = $rolesdump{$area};
                my $thisrole=$area;
                $area =~ s/\_\w\w$//;
@@ -372,18 +372,24 @@ END
                my $bgcol='ffffff';
                my $allowed=0;
                my $delallowed=0;
+	       my $sortkey=$role_code;
+	       my $class='Unknown';
                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
+		   $class='Course';
                    my ($coursedom,$coursedir) = ($1,$2);
+		   $sortkey.="\0$1";
                    # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
                    my %coursedata=
                        &Apache::lonnet::coursedescription($1.'_'.$2);
 		   my $carea;
 		   if (defined($coursedata{'description'})) {
-		       $carea=&mt('Course').': '.$coursedata{'description'}.
+		       $carea=$coursedata{'description'}.
                            '<br />'.&mt('Domain').': '.$coursedom.('&nbsp;'x8).
      &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
+		       $sortkey.="\0".$coursedata{'description'};
 		   } else {
 		       $carea=&mt('Unavailable course').': '.$area;
+		       $sortkey.="\0".&mt('Unavailable course').': '.$area;
 		   }
                    $inccourses{$1.'_'.$2}=1;
                    if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
@@ -410,6 +416,7 @@ END
                    }
                    $area=$carea;
                } else {
+		   $sortkey.="\0".$area;
                    # Determine if current user is able to revoke privileges
                    if ($area=~ /^\/(\w+)\//) {
                        if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
@@ -426,6 +433,13 @@ END
                            $allowed=1;
                        }
                    }
+		   if ($role_code eq 'ca' || $role_code eq 'au') {
+		       $class='Construction Space';
+		   } elsif ($role_code eq 'su') {
+		       $class='System';
+		   } else {
+		       $class='Domain';
+		   }
                }
                if ($role_code eq 'ca') {
                    $area=~/\/(\w+)\/(\w+)/;
@@ -435,6 +449,7 @@ END
                        $allowed=0;
                    }
                }
+	       $bgcol='77FF77';
                my $row = '';
                $row.='<tr bgcolor="#'.$bgcol.'"><td>';
                my $active=1;
@@ -449,6 +464,12 @@ END
 		   }
                }
 	       $row.='</td><td>';
+               if ($allowed && !$active) {
+                   $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
+               } else {
+                   $row.='&nbsp;';
+               }
+	       $row.='</td><td>';
                if ($delallowed) {
                    $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
                } else {
@@ -468,8 +489,24 @@ END
                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
                                                    : '&nbsp;' )
                       ."</td></tr>\n";
-               $r->print($row);
+	       $sortrole{$sortkey}=$envkey;
+	       $roletext{$envkey}=$row;
+	       $roleclass{$envkey}=$class;
+               #$r->print($row);
            } # end of foreach        (table building loop)
+	   foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
+	       my $output;
+	       foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
+		   if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
+		       $output.=$roletext{$sortrole{$which}};
+		   }
+	       }
+	       if (defined($output)) {
+		   $r->print("<tr bgcolor='#BBffBB'>".
+			     "<td align='center' colspan='7'>".&mt($type)."</td>");
+	       }
+	       $r->print($output);
+	   }
 	   $r->print('</table>');
         }  # End of unless
 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
@@ -586,7 +623,7 @@ ENDOTHERAUTHS
                     'rol'  => "Role",
                     'ext'  => "Extent",
                     'sta'  => "Start",
-                    'end'  => "End".
+                    'end'  => "End",
                     'cau'  => "Co-Author",
                     'ssd'  => "Set Start Date",
                     'sed'  => "Set End Date"
@@ -596,13 +633,13 @@ ENDOTHERAUTHS
 <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
 <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
 <tr>
-<td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
+<td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
 <td>$lt{'cau'}</td>
 <td>$cudom\_$cuname</td>
-<td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
+<td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
 <a href=
 "javascript:pjump('date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'ssd'}</a></td>
-<td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
+<td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
 <a href=
 "javascript:pjump('date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'sed'}</a></td>
 </tr>
@@ -924,12 +961,34 @@ END
 	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
 		}
 	    } 
+	} elsif ($_=~/^form\.ren/) {
+	    if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
+		my $result=&Apache::lonnet::assignrole($ENV{'form.ccdomain'},
+					 $ENV{'form.ccuname'},$1,$2,0,$now);
+		$r->print(&mt('Re-Enabling [_1] in [_2]: [_3]',
+			      $2,$1,$result).'<br />');
+		if ($2 eq 'st') {
+		    $1=~/^\/(\w+)\/(\w+)/;
+		    my $cid=$1.'_'.$2;
+		    $r->print(&mt('Add to classlist').': <b>'.
+			      &Apache::lonnet::critical(
+				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
+	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
+                                   &Apache::lonnet::escape(
+                                       $ENV{'form.ccuname'}.':'.
+                                       $ENV{'form.ccdomain'} ).'='.
+                                   &Apache::lonnet::escape(':'.$now),
+				       $ENV{'course.'.$cid.'.home'})
+			      .'</b><br>');
+		}
+	    } 
 	} elsif ($_=~/^form\.act/) {
-	    if 
-($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
+	    if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
                 # Activate a custom role
-		my $url='/'.$1.'/'.$2;
-		my $full=$1.'_'.$2.'_cr_cr_'.$3.'_'.$4.'_'.$5;
+		my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
+		my $url='/'.$one.'/'.$two;
+		my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
+		$ENV{'form.sec_'.$full}=~s/\W//g;
 		if ($ENV{'form.sec_'.$full}) {
 		    $url.='/'.$ENV{'form.sec_'.$full};
 		}
@@ -941,38 +1000,39 @@ END
 			      $ENV{'form.end_'.$full} :
 			      0 );
 
-    $r->print(&mt('Assigning custom role').' "'.$5.'" by '.$4.'@'.$3.' in '.$url.
+    $r->print(&mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
                          ($start?', '.&mt('starting').' '.localtime($start):'').
                          ($end?', ending '.localtime($end):'').': <b>'.
 	      &Apache::lonnet::assigncustomrole(
-	$ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$3,$4,$5,$end,$start).
+	$ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start).
 	      '</b><br>');
 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
 		# Activate roles for sections with 3 id numbers
 		# set start, end times, and the url for the class
-
-		my $start = ( $ENV{'form.start_'.$1.'_'.$2.'_'.$3} ? 
-			      $ENV{'form.start_'.$1.'_'.$2.'_'.$3} : 
+		my ($one,$two,$three)=($1,$2,$3);
+		my $start = ( $ENV{'form.start_'.$one.'_'.$two.'_'.$three} ? 
+			      $ENV{'form.start_'.$one.'_'.$two.'_'.$three} : 
 			      $now );
-		my $end   = ( $ENV{'form.end_'.$1.'_'.$2.'_'.$3} ? 
-			      $ENV{'form.end_'.$1.'_'.$2.'_'.$3} :
+		my $end   = ( $ENV{'form.end_'.$one.'_'.$two.'_'.$three} ? 
+			      $ENV{'form.end_'.$one.'_'.$two.'_'.$three} :
 			      0 );
-		my $url='/'.$1.'/'.$2;
-		if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
-		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
+		my $url='/'.$one.'/'.$two;
+		$ENV{'form.sec_'.$one.'_'.$two.'_'.$three}=~s/\W//g;
+		if ($ENV{'form.sec_'.$one.'_'.$two.'_'.$three}) {
+		    $url.='/'.$ENV{'form.sec_'.$one.'_'.$two.'_'.$three};
 		}
 		# Assign the role and report it
-		$r->print(&mt('Assigning').' '.$3.' in '.$url.
+		$r->print(&mt('Assigning').' '.$three.' in '.$url.
                          ($start?', '.&mt('starting').' '.localtime($start):'').
                          ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
                           &Apache::lonnet::assignrole(
                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
-                              $url,$3,$end,$start).
+                              $url,$three,$end,$start).
 			  '</b><br>');
 		# Handle students differently
-		if ($3 eq 'st') {
+		if ($three eq 'st') {
 		    $url=~/^\/(\w+)\/(\w+)/;
-		    my $cid=$1.'_'.$2;
+		    my $cid=$one.'_'.$two;
 		    $r->print(&mt('Add to classlist').': <b>'.
 			      &Apache::lonnet::critical(
 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
@@ -1236,6 +1296,7 @@ sub course_level_table {
 	my $bgcol=$thiscourse;
 	$bgcol=~s/[^7-9a-e]//g;
 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
+	my ($domain)=split(/\//,$thiscourse);
 	foreach  ('st','ta','ep','ad','in','cc') {
 	    if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
 		my $plrole=&Apache::lonnet::plaintext($_);
@@ -1243,7 +1304,7 @@ sub course_level_table {
 <tr bgcolor="#$bgcol">
 <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
 <td>$plrole</td>
-<td>$area</td>
+<td>$area<br />Domain: $domain</td>
 ENDEXTENT
 	        if ($_ ne 'cc') {
 		    $table .= <<ENDSECTION;