--- loncom/interface/loncreateuser.pm	2002/11/25 18:44:33	1.45
+++ loncom/interface/loncreateuser.pm	2003/06/20 14:37:26	1.56
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.45 2002/11/25 18:44:33 matthew Exp $
+# $Id: loncreateuser.pm,v 1.56 2003/06/20 14:37:26 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -44,10 +44,9 @@
 # 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17,3/24,04/12 Gerd Kortemeyer
 # April Guy Albertelli
 # 05/10,10/16 Gerd Kortemeyer 
-# 11/12,11/13,11/15 Scott Harrison
 # 02/11/02 Matthew Hall
 #
-# $Id: loncreateuser.pm,v 1.45 2002/11/25 18:44:33 matthew Exp $
+# $Id: loncreateuser.pm,v 1.56 2003/06/20 14:37:26 www Exp $
 ###
 
 package Apache::loncreateuser;
@@ -55,6 +54,7 @@ package Apache::loncreateuser;
 use strict;
 use Apache::Constants qw(:common :http);
 use Apache::lonnet;
+use Apache::loncommon;
 
 my $loginscript; # piece of javascript used in two separate instances
 my $generalrule;
@@ -71,10 +71,12 @@ BEGIN {
     my %param = ( formname => 'document.cu',
                   kerb_def_dom => $krbdefdom 
                   );
-    $loginscript  = &Apache::loncommon::authform_header(%param);
+# no longer static due to configurable kerberos defaults
+#    $loginscript  = &Apache::loncommon::authform_header(%param);
     $generalrule  = &Apache::loncommon::authform_authorwarning(%param);
     $authformnop  = &Apache::loncommon::authform_nochange(%param);
-    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
+# no longer static due to configurable kerberos defaults
+#    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
     $authformint  = &Apache::loncommon::authform_internal(%param);
     $authformfsys = &Apache::loncommon::authform_filesystem(%param);
     $authformloc  = &Apache::loncommon::authform_local(%param);
@@ -102,18 +104,22 @@ sub print_username_entry_form {
     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
     my $bodytag =&Apache::loncommon::bodytag(
                                   'Create Users, Change User Privileges');
+    my $selscript=&Apache::loncommon::studentbrowser_javascript();
+    my $sellink=&Apache::loncommon::selectstudent_link
+                                        ('crtuser','ccuname','ccdomain');
     $r->print(<<"ENDDOCUMENT");
 <html>
 <head>
 <title>The LearningOnline Network with CAPA</title>
+$selscript
 </head>
 $bodytag
-<form action="/adm/createuser" method="post">
+<form action="/adm/createuser" method="post" name="crtuser">
 <input type="hidden" name="phase" value="get_user_info">
 <p>
 <table>
 <tr><td>Username:</td><td><input type="text" size="15" name="ccuname">
-</td></tr><tr><td>
+</td><td rowspan="2">$sellink</td></tr><tr><td>
 Domain:</td><td>$domform</td></tr>
 </table> 
 </p>
@@ -130,18 +136,21 @@ sub print_user_modification_page {
     my $ccuname=$ENV{'form.ccuname'};
     my $ccdomain=$ENV{'form.ccdomain'};
 
-    $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
-    my $krbdefdom=$1;
-    $krbdefdom=~tr/a-z/A-Z/;
+    my $defdom=$ENV{'request.role.domain'};
+
+    my ($krbdef,$krbdefdom) =
+       &Apache::loncommon::get_kerberos_defaults($defdom);
+
     my %param = ( formname => 'document.cu',
-                  kerb_def_dom => $krbdefdom 
+                  kerb_def_dom => $krbdefdom,
+                  kerb_def_auth => $krbdef
                   );
     $loginscript  = &Apache::loncommon::authform_header(%param);
-
-    my $defdom=$ENV{'request.role.domain'};
+    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
 
     $ccuname=~s/\W//g;
     $ccdomain=~s/\W//g;
+    my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
     my $dochead =<<"ENDDOCHEAD";
 <html>
 <head>
@@ -154,14 +163,7 @@ sub print_user_modification_page {
         parmwin.close();
     }
 
-    function pjump(type,dis,value,marker,ret,call) {
-        parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
-                 +"&value="+escape(value)+"&marker="+escape(marker)
-                 +"&return="+escape(ret)
-                 +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
-                 "height=350,width=350,scrollbars=no,menubar=no");
-
-    }
+    $pjump_def
 
     function dateset() {
         eval("document.cu."+document.cu.pres_marker.value+
@@ -186,7 +188,7 @@ ENDFORMINFO
     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
     my %incdomains; 
     my %inccourses;
-    foreach (%Apache::lonnet::hostdom) {
+    foreach (values(%Apache::lonnet::hostdom)) {
        $incdomains{$_}=1;
     }
     foreach (keys(%ENV)) {
@@ -253,7 +255,7 @@ 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>
+<td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
 END
            } else {
                $r->print('<td>'.$userenv{$_}.'</td>');
@@ -271,7 +273,7 @@ END
 <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>
+<tr><th>Revoke</th><th>Delete</th><th>Role</th><th>Extent</th><th>Start</th><th>End</th>
 END
 	   foreach my $area (keys(%rolesdump)) {
                next if ($area =~ /^rolesdef/);
@@ -282,14 +284,26 @@ END
                    split(/_/,$role);
                my $bgcol='ffffff';
                my $allowed=0;
+               my $delallowed=0;
                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
                    my %coursedata=
                        &Apache::lonnet::coursedescription($1.'_'.$2);
-                   my $carea='Course: '.$coursedata{'description'};
+		   my $carea;
+		   if (defined($coursedata{'description'})) {
+		       $carea='Course: '.$coursedata{'description'}.
+                              '<br />Domain: '.$1;
+		   } else {
+		       $carea='Unavailable course: '.$area;
+		   }
                    $inccourses{$1.'_'.$2}=1;
-                   if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) {
+                   if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
+                       (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
                        $allowed=1;
                    }
+                   if ((&Apache::lonnet::allowed('dro',$1)) ||
+                       (&Apache::lonnet::allowed('dro',$ccdomain))) {
+                       $delallowed=1;
+                   }
                    # Compute the background color based on $area
                    $bgcol=$1.'_'.$2;
                    $bgcol=~s/[^8-9b-e]//g;
@@ -301,9 +315,15 @@ END
                } else {
                    # Determine if current user is able to revoke privileges
                    if ($area=~ /^\/(\w+)\//) {
-                       if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
+                       if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
+                       (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
                            $allowed=1;
                        }
+                       if (((&Apache::lonnet::allowed('dro',$1))  ||
+                            (&Apache::lonnet::allowed('dro',$ccdomain))) &&
+                           ($role_code ne 'dc')) {
+                           $delallowed=1;
+                       }
                    } else {
                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
                            $allowed=1;
@@ -325,6 +345,16 @@ END
                if (($active) && ($allowed)) {
                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
                } else {
+                   if ($active) {
+                      $row.='&nbsp;';
+		   } else {
+                      $row.='expired or revoked';
+		   }
+               }
+	       $row.='</td><td>';
+               if ($delallowed) {
+                   $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
+               } else {
                    $row.='&nbsp;';
                }
                $row.= '</td><td>'.&Apache::lonnet::plaintext($role_code).
@@ -406,16 +436,7 @@ ENDBADAUTH
 		$authform_other="<p>$authformkrb</p>".
                     "<p>$authformint</p><p>$authformfsys</p>";
 	    }
-	    $authformcurrent=<<ENDCURRENTAUTH;
-<table border='1'>
-<tr>
-<td><font color='#ff0000'>* * * WARNING * * *</font></td>
-<td><font color='#ff0000'>* * * WARNING * * *</font></td>
-</tr>
-<tr><td bgcolor='#cbbcbb'>$authformcurrent</td>
-<td bgcolor='#cbbcbb'>Changing this value will overwrite existing authentication for the user; you should notify the user of this change.</td></tr>
-</table>
-ENDCURRENTAUTH
+            $authformcurrent.=' <i>(will override current values)</i><br />';
             if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
 		# Current user has login modification privileges
 		$r->print(<<ENDOTHERAUTHS);
@@ -707,47 +728,68 @@ END
 	# Revoke roles
 	if ($_=~/^form\.rev/) {
 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) {
-	        $r->print('Revoking '.$2.' in '.$1.': '.
+	        $r->print('Revoking '.$2.' in '.$1.': <b>'.
                      &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
-                     $ENV{'form.ccuname'},$1,$2,$now).'<br>');
+                     $ENV{'form.ccuname'},$1,$2,$now).'</b><br>');
 		if ($2 eq 'st') {
 		    $1=~/^\/(\w+)\/(\w+)/;
 		    my $cid=$1.'_'.$2;
-		    $r->print('Drop from classlist: '.
+		    $r->print('Drop from 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'}).'<br>');
+	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
+		}
+	    } 
+	} elsif ($_=~/^form\.del/) {
+	    if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
+	        $r->print('Deleting '.$2.' in '.$1.': '.
+                     &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
+                     $ENV{'form.ccuname'},$1,$2,$now,0,1).'<br>');
+		if ($2 eq 'st') {
+		    $1=~/^\/(\w+)\/(\w+)/;
+		    my $cid=$1.'_'.$2;
+		    $r->print('Drop from 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\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
 		# 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} ? 
-			      $ENV{'form.start_'.$1.'_'.$2} : 
+
+		my $start = ( $ENV{'form.start_'.$1.'_'.$2.'_'.$3} ? 
+			      $ENV{'form.start_'.$1.'_'.$2.'_'.$3} : 
 			      $now );
-		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
-			      $ENV{'form.end_'.$1.'_'.$2} :
+		my $end   = ( $ENV{'form.end_'.$1.'_'.$2.'_'.$3} ? 
+			      $ENV{'form.end_'.$1.'_'.$2.'_'.$3} :
 			      0 );
 		my $url='/'.$1.'/'.$2;
 		if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
 		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
 		}
 		# Assign the role and report it
-		$r->print('Assigning: '.$3.' in '.$url.': '.
+		$r->print('Assigning: '.$3.' in '.$url.
+                         ($start?', starting '.localtime($start):'').
+                         ($end?', ending '.localtime($end):'').': <b>'.
                           &Apache::lonnet::assignrole(
                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
                               $url,$3,$end,$start).
-			  '<br>');
+			  '</b><br>');
 		# Handle students differently
 		if ($3 eq 'st') {
 		    $url=~/^\/(\w+)\/(\w+)/;
 		    my $cid=$1.'_'.$2;
-		    $r->print('Add to classlist: '.
+		    $r->print('Add to classlist: <b>'.
 			      &Apache::lonnet::critical(
 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
 	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
@@ -756,7 +798,7 @@ END
                                        $ENV{'form.ccdomain'} ).'='.
                                    &Apache::lonnet::escape($end.':'.$start),
 				       $ENV{'course.'.$cid.'.home'})
-			      .'<br>');
+			      .'</b><br>');
 		}
 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
 		# Activate roles for sections with two id numbers
@@ -770,10 +812,12 @@ END
 		my $url='/'.$1.'/';
 		# Assign the role and report it.
 		$r->print('Assigning: '.$2.' in '.$url.': '.
+                         ($start?', starting '.localtime($start):'').
+                         ($end?', ending '.localtime($end):'').': <b>'.
                           &Apache::lonnet::assignrole(
                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
                               $url,$2,$end,$start)
-			  .'<br>');
+			  .'</b><br>');
 	    }
 	} 
     } # End of foreach (keys(%ENV))
@@ -824,6 +868,7 @@ sub course_level_table {
 	$thiscourse=~s:_:/:g;
 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
 	my $area=$coursedata{'description'};
+	if (!defined($area)) { $area='Unavailable course: '.$_; }
 	my $bgcol=$thiscourse;
 	$bgcol=~s/[^8-9b-e]//g;
 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);