File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.80: download - view: text, annotated - select for diffs
Fri Mar 5 02:14:34 2004 UTC (20 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #2785: fix co-author display and get back the start and end date links.

    1: # The LearningOnline Network with CAPA
    2: # Create a user
    3: #
    4: # $Id: loncreateuser.pm,v 1.80 2004/03/05 02:14:34 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::loncreateuser;
   31: 
   32: =pod
   33: 
   34: =head1 NAME
   35: 
   36: Apache::loncreateuser - handler to create users and custom roles
   37: 
   38: =head1 SYNOPSIS
   39: 
   40: Apache::loncreateuser provides an Apache handler for creating users,
   41:     editing their login parameters, roles, and removing roles, and
   42:     also creating and assigning custom roles.
   43: 
   44: =head1 OVERVIEW
   45: 
   46: =head2 Custom Roles
   47: 
   48: In LON-CAPA, roles are actually collections of privileges. "Teaching
   49: Assistant", "Course Coordinator", and other such roles are really just
   50: collection of privileges that are useful in many circumstances.
   51: 
   52: Creating custom roles can be done by the Domain Coordinator through
   53: the Create User functionality. That screen will show all privileges
   54: that can be assigned to users. For a complete list of privileges,
   55: please see C</home/httpd/lonTabs/rolesplain.tab>.
   56: 
   57: Custom role definitions are stored in the C<roles.db> file of the role
   58: author.
   59: 
   60: =cut
   61: 
   62: use strict;
   63: use Apache::Constants qw(:common :http);
   64: use Apache::lonnet;
   65: use Apache::loncommon;
   66: use Apache::lonlocal;
   67: 
   68: my $loginscript; # piece of javascript used in two separate instances
   69: my $generalrule;
   70: my $authformnop;
   71: my $authformkrb;
   72: my $authformint;
   73: my $authformfsys;
   74: my $authformloc;
   75: 
   76: BEGIN {
   77:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
   78:     my $krbdefdom=$1;
   79:     $krbdefdom=~tr/a-z/A-Z/;
   80:     my %param = ( formname => 'document.cu',
   81:                   kerb_def_dom => $krbdefdom 
   82:                   );
   83: # no longer static due to configurable kerberos defaults
   84: #    $loginscript  = &Apache::loncommon::authform_header(%param);
   85:     $generalrule  = &Apache::loncommon::authform_authorwarning(%param);
   86:     $authformnop  = &Apache::loncommon::authform_nochange(%param);
   87: # no longer static due to configurable kerberos defaults
   88: #    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
   89:     $authformint  = &Apache::loncommon::authform_internal(%param);
   90:     $authformfsys = &Apache::loncommon::authform_filesystem(%param);
   91:     $authformloc  = &Apache::loncommon::authform_local(%param);
   92: }
   93: 
   94: 
   95: # ======================================================= Existing Custom Roles
   96: 
   97: sub my_custom_roles {
   98:     my %returnhash=();
   99:     my %rolehash=&Apache::lonnet::dump('roles');
  100:     foreach (keys %rolehash) {
  101: 	if ($_=~/^rolesdef\_(\w+)$/) {
  102: 	    $returnhash{$1}=$1;
  103: 	}
  104:     }
  105:     return %returnhash;
  106: }
  107: 
  108: # ==================================================== Figure out author access
  109: 
  110: sub authorpriv {
  111:     my ($auname,$audom)=@_;
  112:     if (($auname ne $ENV{'user.name'}) ||
  113:         (($audom ne $ENV{'user.domain'}) &&
  114:          ($audom ne $ENV{'request.role.domain'}))) { return ''; }
  115:     unless (&Apache::lonnet::allowed('cca',$audom)) { return ''; }
  116:     return 1;
  117: }
  118: 
  119: # =================================================================== Phase one
  120: 
  121: sub print_username_entry_form {
  122:     my $r=shift;
  123:     my $defdom=$ENV{'request.role.domain'};
  124:     my @domains = &Apache::loncommon::get_domains();
  125:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  126:     my $bodytag =&Apache::loncommon::bodytag(
  127:                                   'Create Users, Change User Privileges').
  128: 		  &Apache::loncommon::help_open_faq(282).
  129: 		  &Apache::loncommon::help_open_bug('Instructor Interface');
  130:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
  131:     my $sellink=&Apache::loncommon::selectstudent_link
  132:                                         ('crtuser','ccuname','ccdomain');
  133:     my %existingroles=&my_custom_roles();
  134:     my $choice=&Apache::loncommon::select_form('make new role','rolename',
  135: 		('make new role' => 'Generate new role ...',%existingroles));
  136:     my %lt=&Apache::lonlocal::texthash(
  137: 		    'siur'   => "Set Individual User Roles",
  138: 		    'usr'  => "Username",
  139:                     'dom'  => "Domain",
  140:                     'usrr' => "User Roles",
  141:                     'ecrp' => "Edit Custom Role Privileges",
  142:                     'nr'   => "Name of Role",
  143:                     'cre'  => "Custom Role Editor"
  144: 				       );
  145:     my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
  146:     my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
  147:     $r->print(<<"ENDDOCUMENT");
  148: <html>
  149: <head>
  150: <title>The LearningOnline Network with CAPA</title>
  151: $selscript
  152: </head>
  153: $bodytag
  154: <form action="/adm/createuser" method="post" name="crtuser">
  155: <input type="hidden" name="phase" value="get_user_info">
  156: <h2>$lt{siur}$helpsiur</h2>
  157: <table>
  158: <tr><td>$lt{usr}:</td><td><input type="text" size="15" name="ccuname">
  159: </td><td rowspan="2">$sellink</td></tr><tr><td>
  160: $lt{'dom'}:</td><td>$domform</td></tr>
  161: </table>
  162: <input name="userrole" type="submit" value="$lt{usrr}" />
  163: </form>
  164: <form action="/adm/createuser" method="post" name="docustom">
  165: <input type="hidden" name="phase" value="selected_custom_edit">
  166: <h2>$lt{'ecrp'}$helpecpr</h2>
  167: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
  168: <input name="customeditor" type="submit" value="$lt{'cre'}" />
  169: </body>
  170: </html>
  171: ENDDOCUMENT
  172: }
  173: 
  174: # =================================================================== Phase two
  175: sub print_user_modification_page {
  176:     my $r=shift;
  177:     my $ccuname=$ENV{'form.ccuname'};
  178:     my $ccdomain=$ENV{'form.ccdomain'};
  179: 
  180:     $ccuname=~s/\W//gs;
  181:     $ccdomain=~s/\W//gs;
  182: 
  183:     unless (($ccuname) && ($ccdomain)) {
  184: 	&print_username_entry_form($r);
  185:         return;
  186:     }
  187: 
  188:     my $defdom=$ENV{'request.role.domain'};
  189: 
  190:     my ($krbdef,$krbdefdom) =
  191:        &Apache::loncommon::get_kerberos_defaults($defdom);
  192: 
  193:     my %param = ( formname => 'document.cu',
  194:                   kerb_def_dom => $krbdefdom,
  195:                   kerb_def_auth => $krbdef
  196:                   );
  197:     $loginscript  = &Apache::loncommon::authform_header(%param);
  198:     $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
  199: 
  200:     $ccuname=~s/\W//g;
  201:     $ccdomain=~s/\W//g;
  202:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  203:     my $dochead =<<"ENDDOCHEAD";
  204: <html>
  205: <head>
  206: <title>The LearningOnline Network with CAPA</title>
  207: <script type="text/javascript" language="Javascript">
  208: 
  209:     function pclose() {
  210:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  211:                  "height=350,width=350,scrollbars=no,menubar=no");
  212:         parmwin.close();
  213:     }
  214: 
  215:     $pjump_def
  216: 
  217:     function dateset() {
  218:         eval("document.cu."+document.cu.pres_marker.value+
  219:             ".value=document.cu.pres_value.value");
  220:         pclose();
  221:     }
  222: 
  223: </script>
  224: </head>
  225: ENDDOCHEAD
  226:     $r->print(&Apache::loncommon::bodytag(
  227:                                      'Create Users, Change User Privileges'));
  228:     my $forminfo =<<"ENDFORMINFO";
  229: <form action="/adm/createuser" method="post" name="cu">
  230: <input type="hidden" name="phase"       value="update_user_data">
  231: <input type="hidden" name="ccuname"     value="$ccuname">
  232: <input type="hidden" name="ccdomain"    value="$ccdomain">
  233: <input type="hidden" name="pres_value"  value="" >
  234: <input type="hidden" name="pres_type"   value="" >
  235: <input type="hidden" name="pres_marker" value="" >
  236: ENDFORMINFO
  237:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
  238:     my %incdomains; 
  239:     my %inccourses;
  240:     foreach (values(%Apache::lonnet::hostdom)) {
  241:        $incdomains{$_}=1;
  242:     }
  243:     foreach (keys(%ENV)) {
  244: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
  245: 	    $inccourses{$1.'_'.$2}=1;
  246:         }
  247:     }
  248:     if ($uhome eq 'no_host') {
  249:         my $home_server_list=
  250:             '<option value="default" selected>default</option>'."\n".
  251:                 &Apache::loncommon::home_server_option_list($ccdomain);
  252:         
  253: 	my %lt=&Apache::lonlocal::texthash(
  254:                     'cnu'  => "Create New User",
  255:                     'nu'   => "New User",
  256:                     'id'   => "in domain",
  257:                     'pd'   => "Personal Data",
  258:                     'fn'   => "First Name",
  259:                     'mn'   => "Middle Name",
  260:                     'ln'   => "Last Name",
  261:                     'gen'  => "Generation",
  262:                     'idsn' => "ID/Student Number",
  263:                     'hs'   => "Home Server",
  264:                     'lg'   => "Login Data"
  265: 				       );
  266: 	my $genhelp=&Apache::loncommon::help_open_topic('Generation');
  267: 	$r->print(<<ENDNEWUSER);
  268: $dochead
  269: <h1>$lt{'cnu'}</h1>
  270: $forminfo
  271: <h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
  272: <script type="text/javascript" language="Javascript">
  273: $loginscript
  274: </script>
  275: <input type='hidden' name='makeuser' value='1' />
  276: <h3>$lt{'pd'}</h3>
  277: <p>
  278: <table>
  279: <tr><td>$lt{'fn'}  </td>
  280:     <td><input type='text' name='cfirst'  size='15' /></td></tr>
  281: <tr><td>$lt{'mn'} </td> 
  282:     <td><input type='text' name='cmiddle' size='15' /></td></tr>
  283: <tr><td>$lt{'ln'}   </td>
  284:     <td><input type='text' name='clast'   size='15' /></td></tr>
  285: <tr><td>$lt{'gen'}$genhelp</td>
  286:     <td><input type='text' name='cgen'    size='5'  /></td></tr>
  287: </table>
  288: $lt{'idsn'} <input type='text' name='cstid'   size='15' /></p>
  289: $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
  290: <hr />
  291: <h3>$lt{'lg'}</h3>
  292: <p>$generalrule </p>
  293: <p>$authformkrb </p>
  294: <p>$authformint </p>
  295: <p>$authformfsys</p>
  296: <p>$authformloc </p>
  297: ENDNEWUSER
  298:     } else { # user already exists
  299: 	my %lt=&Apache::lonlocal::texthash(
  300:                     'cup'  => "Change User Privileges",
  301:                     'usr'  => "User",                    
  302:                     'id'   => "in domain",
  303:                     'fn'   => "first name",
  304:                     'mn'   => "middle name",
  305:                     'ln'   => "last name",
  306:                     'gen'  => "generation"
  307: 				       );
  308: 	$r->print(<<ENDCHANGEUSER);
  309: $dochead
  310: <h1>$lt{'cup'}</h1>
  311: $forminfo
  312: <h2>$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
  313: ENDCHANGEUSER
  314:         # Get the users information
  315:         my %userenv = &Apache::lonnet::get('environment',
  316:                           ['firstname','middlename','lastname','generation'],
  317:                           $ccdomain,$ccuname);
  318:         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
  319:         $r->print(<<END);
  320: <hr />
  321: <table border="2">
  322: <tr>
  323: <th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th>
  324: </tr>
  325: <tr>
  326: END
  327:         foreach ('firstname','middlename','lastname','generation') {
  328:            if (&Apache::lonnet::allowed('mau',$ccdomain)) {
  329:               $r->print(<<"END");            
  330: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
  331: END
  332:            } else {
  333:                $r->print('<td>'.$userenv{$_}.'</td>');
  334:            }
  335:         }
  336:       $r->print(<<END);
  337: </tr>
  338: </table>
  339: END
  340:         # Build up table of user roles to allow revocation of a role.
  341:         my ($tmp) = keys(%rolesdump);
  342:         unless ($tmp =~ /^(con_lost|error)/i) {
  343:            my $now=time;
  344: 	   my %lt=&Apache::lonlocal::texthash(
  345: 		    'rer'  => "Revoke Existing Roles",
  346:                     'rev'  => "Revoke",                    
  347:                     'del'  => "Delete",
  348:                     'rol'  => "Role",
  349:                     'ext'  => "Extent",
  350:                     'sta'  => "Start",
  351:                     'end'  => "End"
  352: 				       );
  353:            $r->print(<<END);
  354: <hr />
  355: <h3>$lt{'rer'}</h3>
  356: <table>
  357: <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>
  358: END
  359:            my (%roletext,%sortrole,%roleclass);
  360: 	   foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
  361: 				    my $b1=join('_',(split('_',$b))[1,0]);
  362: 				    return $a1 cmp $b1;
  363: 				} keys(%rolesdump)) {
  364:                next if ($area =~ /^rolesdef/);
  365: 	       my $envkey=$area;
  366:                my $role = $rolesdump{$area};
  367:                my $thisrole=$area;
  368:                $area =~ s/\_\w\w$//;
  369:                my ($role_code,$role_end_time,$role_start_time) = 
  370:                    split(/_/,$role);
  371: # Is this a custom role? Get role owner and title.
  372: 	       my ($croleudom,$croleuname,$croletitle)=
  373: 	           ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
  374:                my $bgcol='ffffff';
  375:                my $allowed=0;
  376:                my $delallowed=0;
  377: 	       my $sortkey=$role_code;
  378: 	       my $class='Unknown';
  379:                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
  380: 		   $class='Course';
  381:                    my ($coursedom,$coursedir) = ($1,$2);
  382: 		   $sortkey.="\0$1";
  383:                    # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
  384:                    my %coursedata=
  385:                        &Apache::lonnet::coursedescription($1.'_'.$2);
  386: 		   my $carea;
  387: 		   if (defined($coursedata{'description'})) {
  388: 		       $carea=$coursedata{'description'}.
  389:                            '<br />'.&mt('Domain').': '.$coursedom.('&nbsp;'x8).
  390:      &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
  391: 		       $sortkey.="\0".$coursedata{'description'};
  392: 		   } else {
  393: 		       $carea=&mt('Unavailable course').': '.$area;
  394: 		       $sortkey.="\0".&mt('Unavailable course');
  395: 		   }
  396:                    $inccourses{$1.'_'.$2}=1;
  397:                    if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
  398:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
  399:                        $allowed=1;
  400:                    }
  401:                    if ((&Apache::lonnet::allowed('dro',$1)) ||
  402:                        (&Apache::lonnet::allowed('dro',$ccdomain))) {
  403:                        $delallowed=1;
  404:                    }
  405: # - custom role. Needs more info, too
  406: 		   if ($croletitle) {
  407: 		       if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
  408: 			   $allowed=1;
  409: 			   $thisrole.='.'.$role_code;
  410: 		       }
  411: 		   }
  412:                    # Compute the background color based on $area
  413:                    $bgcol=$1.'_'.$2;
  414:                    $bgcol=~s/[^7-9a-e]//g;
  415:                    $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
  416:                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
  417:                        $carea.='<br>Section/Group: '.$3;
  418:                    }
  419:                    $area=$carea;
  420:                } else {
  421: 		   $sortkey.="\0".$area;
  422:                    # Determine if current user is able to revoke privileges
  423:                    if ($area=~ /^\/(\w+)\//) {
  424:                        if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
  425:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
  426:                            $allowed=1;
  427:                        }
  428:                        if (((&Apache::lonnet::allowed('dro',$1))  ||
  429:                             (&Apache::lonnet::allowed('dro',$ccdomain))) &&
  430:                            ($role_code ne 'dc')) {
  431:                            $delallowed=1;
  432:                        }
  433:                    } else {
  434:                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
  435:                            $allowed=1;
  436:                        }
  437:                    }
  438: 		   if ($role_code eq 'ca' || $role_code eq 'au') {
  439: 		       $class='Construction Space';
  440: 		   } elsif ($role_code eq 'su') {
  441: 		       $class='System';
  442: 		   } else {
  443: 		       $class='Domain';
  444: 		   }
  445:                }
  446:                if ($role_code eq 'ca') {
  447:                    $area=~/\/(\w+)\/(\w+)/;
  448: 		   if (&authorpriv($2,$1)) {
  449: 		       $allowed=1;
  450:                    } else {
  451:                        $allowed=0;
  452:                    }
  453:                }
  454: 	       $bgcol='77FF77';
  455:                my $row = '';
  456:                $row.='<tr bgcolor="#'.$bgcol.'"><td>';
  457:                my $active=1;
  458:                $active=0 if (($role_end_time) && ($now>$role_end_time));
  459:                if (($active) && ($allowed)) {
  460:                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
  461:                } else {
  462:                    if ($active) {
  463:                       $row.='&nbsp;';
  464: 		   } else {
  465:                       $row.=&mt('expired or revoked');
  466: 		   }
  467:                }
  468: 	       $row.='</td><td>';
  469:                if ($delallowed) {
  470:                    $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
  471:                } else {
  472:                    $row.='&nbsp;';
  473:                }
  474: 	       my $plaintext='';
  475: 	       unless ($croletitle) {
  476: 		   $plaintext=&Apache::lonnet::plaintext($role_code);
  477: 	       } else {
  478: 	           $plaintext=
  479: 		"Customrole '$croletitle' defined by $croleuname\@$croleudom";
  480: 	       }
  481:                $row.= '</td><td>'.$plaintext.
  482:                       '</td><td>'.$area.
  483:                       '</td><td>'.($role_start_time?localtime($role_start_time)
  484:                                                    : '&nbsp;' ).
  485:                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
  486:                                                    : '&nbsp;' )
  487:                       ."</td></tr>\n";
  488: 	       $sortrole{$sortkey}=$envkey;
  489: 	       $roletext{$envkey}=$row;
  490: 	       $roleclass{$envkey}=$class;
  491:                #$r->print($row);
  492:            } # end of foreach        (table building loop)
  493: 	   foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
  494: 	       my $output;
  495: 	       foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  496: 		   if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
  497: 		       $output.=$roletext{$sortrole{$which}};
  498: 		   }
  499: 	       }
  500: 	       if (defined($output)) {
  501: 		   $r->print("<tr bgcolor='#BBffBB'>".
  502: 			     "<td align='center' colspan='7'>".&mt($type)."</td>");
  503: 	       }
  504: 	       $r->print($output);
  505: 	   }
  506: 	   $r->print('</table>');
  507:         }  # End of unless
  508: 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
  509: 	if ($currentauth=~/^krb(4|5):/) {
  510: 	    $currentauth=~/^krb(4|5):(.*)/;
  511: 	    my $krbdefdom=$1;
  512:             my %param = ( formname => 'document.cu',
  513:                           kerb_def_dom => $krbdefdom 
  514:                           );
  515:             $loginscript  = &Apache::loncommon::authform_header(%param);
  516: 	}
  517: 	# Check for a bad authentication type
  518:         unless ($currentauth=~/^krb(4|5):/ or
  519: 		$currentauth=~/^unix:/ or
  520: 		$currentauth=~/^internal:/ or
  521: 		$currentauth=~/^localauth:/
  522: 		) { # bad authentication scheme
  523: 	    if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  524: 		my %lt=&Apache::lonlocal::texthash(
  525:                                'err'   => "ERROR",
  526: 			       'uuas'  => "This user has an unrecognized authentication scheme",
  527:                                'sldb'  => "Please specify login data below",
  528:                                'ld'    => "Login Data"
  529: 						   );
  530: 		$r->print(<<ENDBADAUTH);
  531: <hr />
  532: <script type="text/javascript" language="Javascript">
  533: $loginscript
  534: </script>
  535: <font color='#ff0000'>$lt{'err'}:</font>
  536: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
  537: <h3>$lt{'ld'}</h3>
  538: <p>$generalrule</p>
  539: <p>$authformkrb</p>
  540: <p>$authformint</p>
  541: <p>$authformfsys</p>
  542: <p>$authformloc</p>
  543: ENDBADAUTH
  544:             } else { 
  545:                 # This user is not allowed to modify the users 
  546:                 # authentication scheme, so just notify them of the problem
  547: 		my %lt=&Apache::lonlocal::texthash(
  548:                                'err'   => "ERROR",
  549: 			       'uuas'  => "This user has an unrecognized authentication scheme",
  550:                                'adcs'  => "Please alert a domain coordinator of this situation"
  551: 						   );
  552: 		$r->print(<<ENDBADAUTH);
  553: <hr />
  554: <script type="text/javascript" language="Javascript">
  555: $loginscript
  556: </script>
  557: <font color="#ff0000"> $lt{'err'}: </font>
  558: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
  559: <hr />
  560: ENDBADAUTH
  561:             }
  562:         } else { # Authentication type is valid
  563: 	    my $authformcurrent='';
  564: 	    my $authform_other='';
  565: 	    if ($currentauth=~/^krb(4|5):/) {
  566: 		$authformcurrent=$authformkrb;
  567: 		$authform_other="<p>$authformint</p>\n".
  568:                     "<p>$authformfsys</p><p>$authformloc</p>";
  569: 	    }
  570: 	    elsif ($currentauth=~/^internal:/) {
  571: 		$authformcurrent=$authformint;
  572: 		$authform_other="<p>$authformkrb</p>".
  573:                     "<p>$authformfsys</p><p>$authformloc</p>";
  574: 	    }
  575: 	    elsif ($currentauth=~/^unix:/) {
  576: 		$authformcurrent=$authformfsys;
  577: 		$authform_other="<p>$authformkrb</p>".
  578:                     "<p>$authformint</p><p>$authformloc;</p>";
  579: 	    }
  580: 	    elsif ($currentauth=~/^localauth:/) {
  581: 		$authformcurrent=$authformloc;
  582: 		$authform_other="<p>$authformkrb</p>".
  583:                     "<p>$authformint</p><p>$authformfsys</p>";
  584: 	    }
  585:             $authformcurrent.=' <i>(will override current values)</i><br />';
  586:             if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  587: 		# Current user has login modification privileges
  588: 		my %lt=&Apache::lonlocal::texthash(
  589:                                'ccld'  => "Change Current Login Data",
  590: 			       'enld'  => "Enter New Login Data"
  591: 						   );
  592: 		$r->print(<<ENDOTHERAUTHS);
  593: <hr />
  594: <script type="text/javascript" language="Javascript">
  595: $loginscript
  596: </script>
  597: <h3>$lt{'ccld'}</h3>
  598: <p>$generalrule</p>
  599: <p>$authformnop</p>
  600: <p>$authformcurrent</p>
  601: <h3>$lt{'enld'}</h3>
  602: $authform_other
  603: ENDOTHERAUTHS
  604:             }
  605:         }  ## End of "check for bad authentication type" logic
  606:     } ## End of new user/old user logic
  607:     $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
  608: #
  609: # Co-Author
  610: # 
  611:     if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
  612:         ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
  613:         # No sense in assigning co-author role to yourself
  614: 	my $cuname=$ENV{'user.name'};
  615:         my $cudom=$ENV{'request.role.domain'};
  616: 	   my %lt=&Apache::lonlocal::texthash(
  617: 		    'cs'   => "Construction Space",
  618:                     'act'  => "Activate",                    
  619:                     'rol'  => "Role",
  620:                     'ext'  => "Extent",
  621:                     'sta'  => "Start",
  622:                     'end'  => "End",
  623:                     'cau'  => "Co-Author",
  624:                     'ssd'  => "Set Start Date",
  625:                     'sed'  => "Set End Date"
  626: 				       );
  627:        $r->print(<<ENDCOAUTH);
  628: <h4>$lt{'cs'}</h4>
  629: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
  630: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
  631: <tr>
  632: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
  633: <td>$lt{'cau'}</td>
  634: <td>$cudom\_$cuname</td>
  635: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
  636: <a href=
  637: "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>
  638: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
  639: <a href=
  640: "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>
  641: </tr>
  642: </table>
  643: ENDCOAUTH
  644:     }
  645: #
  646: # Domain level
  647: #
  648:     $r->print('<h4>'.&mt('Domain Level').'</h4>'.
  649:     '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
  650:     '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>');
  651:     foreach ( sort( keys(%incdomains))) {
  652: 	my $thisdomain=$_;
  653:         foreach ('dc','li','dg','au','sc') {
  654:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
  655:                my $plrole=&Apache::lonnet::plaintext($_);
  656: 	       my %lt=&Apache::lonlocal::texthash(
  657:                     'ssd'  => "Set Start Date",
  658:                     'sed'  => "Set End Date"
  659: 				       );
  660:                $r->print(<<ENDDROW);
  661: <tr>
  662: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
  663: <td>$plrole</td>
  664: <td>$thisdomain</td>
  665: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
  666: <a href=
  667: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
  668: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
  669: <a href=
  670: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
  671: </tr>
  672: ENDDROW
  673:             }
  674:         } 
  675:     }
  676:     $r->print('</table>');
  677: #
  678: # Course level
  679: #
  680:     $r->print(&course_level_table(%inccourses));
  681:     $r->print("<hr /><input type=submit value=\"".&mt('Modify User')."\">\n");
  682:     $r->print("</form></body></html>");
  683: }
  684: 
  685: # ================================================================= Phase Three
  686: sub update_user_data {
  687:     my $r=shift;
  688:     my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
  689:                                           $ENV{'form.ccdomain'});
  690:     # Error messages
  691:     my $error     = '<font color="#ff0000">'.&mt('Error').':</font>';
  692:     my $end       = '</body></html>';
  693:     # Print header
  694:     $r->print(<<ENDTHREEHEAD);
  695: <html>
  696: <head>
  697: <title>The LearningOnline Network with CAPA</title>
  698: </head>
  699: ENDTHREEHEAD
  700:     my $title;
  701:     if (exists($ENV{'form.makeuser'})) {
  702: 	$title='Set Privileges for New User';
  703:     } else {
  704:         $title='Modify User Privileges';
  705:     }
  706:     $r->print(&Apache::loncommon::bodytag($title));
  707:     # Check Inputs
  708:     if (! $ENV{'form.ccuname'} ) {
  709: 	$r->print($error.&mt('No login name specified').'.'.$end);
  710: 	return;
  711:     }
  712:     if (  $ENV{'form.ccuname'}  =~/\W/) {
  713: 	$r->print($error.&mt('Invalid login name').'.  '.
  714: 		  &mt('Only letters, numbers, and underscores are valid').'.'.
  715: 		  $end);
  716: 	return;
  717:     }
  718:     if (! $ENV{'form.ccdomain'}       ) {
  719: 	$r->print($error.&mt('No domain specified').'.'.$end);
  720: 	return;
  721:     }
  722:     if (  $ENV{'form.ccdomain'} =~/\W/) {
  723: 	$r->print($error.&mt ('Invalid domain name').'.  '.
  724: 		  &mt('Only letters, numbers, and underscores are valid').'.'.
  725: 		  $end);
  726: 	return;
  727:     }
  728:     if (! exists($ENV{'form.makeuser'})) {
  729:         # Modifying an existing user, so check the validity of the name
  730:         if ($uhome eq 'no_host') {
  731:             $r->print($error.&mt('Unable to determine home server for ').
  732:                       $ENV{'form.ccuname'}.&mt(' in domain ').
  733:                       $ENV{'form.ccdomain'}.'.');
  734:             return;
  735:         }
  736:     }
  737:     # Determine authentication method and password for the user being modified
  738:     my $amode='';
  739:     my $genpwd='';
  740:     if ($ENV{'form.login'} eq 'krb') {
  741: 	$amode='krb';
  742: 	$amode.=$ENV{'form.krbver'};
  743: 	$genpwd=$ENV{'form.krbarg'};
  744:     } elsif ($ENV{'form.login'} eq 'int') {
  745: 	$amode='internal';
  746: 	$genpwd=$ENV{'form.intarg'};
  747:     } elsif ($ENV{'form.login'} eq 'fsys') {
  748: 	$amode='unix';
  749: 	$genpwd=$ENV{'form.fsysarg'};
  750:     } elsif ($ENV{'form.login'} eq 'loc') {
  751: 	$amode='localauth';
  752: 	$genpwd=$ENV{'form.locarg'};
  753: 	$genpwd=" " if (!$genpwd);
  754:     } elsif (($ENV{'form.login'} eq 'nochange') ||
  755:              ($ENV{'form.login'} eq ''        )) { 
  756:         # There is no need to tell the user we did not change what they
  757:         # did not ask us to change.
  758:         # If they are creating a new user but have not specified login
  759:         # information this will be caught below.
  760:     } else {
  761: 	    $r->print($error.&mt('Invalid login mode or password').$end);    
  762: 	    return;
  763:     }
  764:     if ($ENV{'form.makeuser'}) {
  765:         # Create a new user
  766: 	my %lt=&Apache::lonlocal::texthash(
  767:                     'cru'  => "Creating user",                    
  768:                     'id'   => "in domain"
  769: 					   );
  770: 	$r->print(<<ENDNEWUSERHEAD);
  771: <h3>$lt{'cru'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h3>
  772: ENDNEWUSERHEAD
  773:         # Check for the authentication mode and password
  774:         if (! $amode || ! $genpwd) {
  775: 	    $r->print($error.&mt('Invalid login mode or password').$end);    
  776: 	    return;
  777: 	}
  778:         # Determine desired host
  779:         my $desiredhost = $ENV{'form.hserver'};
  780:         if (lc($desiredhost) eq 'default') {
  781:             $desiredhost = undef;
  782:         } else {
  783:             my %home_servers = &Apache::loncommon::get_library_servers
  784:                 ($ENV{'form.ccdomain'});  
  785:             if (! exists($home_servers{$desiredhost})) {
  786:                 $r->print($error.&mt('Invalid home server specified'));
  787:                 return;
  788:             }
  789:         }
  790: 	# Call modifyuser
  791: 	my $result = &Apache::lonnet::modifyuser
  792: 	    ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
  793:              $amode,$genpwd,$ENV{'form.cfirst'},
  794:              $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
  795:              undef,$desiredhost
  796: 	     );
  797: 	$r->print(&mt('Generating user').': '.$result);
  798:         my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
  799:                                                $ENV{'form.ccdomain'});
  800:         $r->print('<br />'.&mt('Home server').': '.$home.' '.
  801:                   $Apache::lonnet::libserv{$home});
  802:     } elsif (($ENV{'form.login'} ne 'nochange') &&
  803:              ($ENV{'form.login'} ne ''        )) {
  804: 	# Modify user privileges
  805:     my %lt=&Apache::lonlocal::texthash(
  806:                     'usr'  => "User",                    
  807:                     'id'   => "in domain"
  808: 				       );
  809: 	$r->print(<<ENDMODIFYUSERHEAD);
  810: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
  811: ENDMODIFYUSERHEAD
  812:         if (! $amode || ! $genpwd) {
  813: 	    $r->print($error.'Invalid login mode or password'.$end);    
  814: 	    return;
  815: 	}
  816: 	# Only allow authentification modification if the person has authority
  817: 	if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
  818: 	    $r->print('Modifying authentication: '.
  819:                       &Apache::lonnet::modifyuserauth(
  820: 		       $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  821:                        $amode,$genpwd));
  822:             $r->print('<br>'.&mt('Home server').': '.&Apache::lonnet::homeserver
  823: 		  ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
  824: 	} else {
  825: 	    # Okay, this is a non-fatal error.
  826: 	    $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');    
  827: 	}
  828:     }
  829:     ##
  830:     if (! $ENV{'form.makeuser'} ) {
  831:         # Check for need to change
  832:         my %userenv = &Apache::lonnet::get
  833:             ('environment',['firstname','middlename','lastname','generation'],
  834:              $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  835:         my ($tmp) = keys(%userenv);
  836:         if ($tmp =~ /^(con_lost|error)/i) { 
  837:             %userenv = ();
  838:         }
  839:         # Check to see if we need to change user information
  840:         foreach ('firstname','middlename','lastname','generation') {
  841:             # Strip leading and trailing whitespace
  842:             $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
  843:         }
  844:         if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) && 
  845:             ($ENV{'form.cfirstname'}  ne $userenv{'firstname'}  ||
  846:              $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
  847:              $ENV{'form.clastname'}   ne $userenv{'lastname'}   ||
  848:              $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
  849:             # Make the change
  850:             my %changeHash;
  851:             $changeHash{'firstname'}  = $ENV{'form.cfirstname'};
  852:             $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
  853:             $changeHash{'lastname'}   = $ENV{'form.clastname'};
  854:             $changeHash{'generation'} = $ENV{'form.cgeneration'};
  855:             my $putresult = &Apache::lonnet::put
  856:                 ('environment',\%changeHash,
  857:                  $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  858:             if ($putresult eq 'ok') {
  859:             # Tell the user we changed the name
  860: 		my %lt=&Apache::lonlocal::texthash(
  861:                              'uic'  => "User Information Changed",             
  862:                              'frst' => "first",
  863:                              'mddl' => "middle",
  864:                              'lst'  => "last",
  865: 			     'gen'  => "generation",
  866:                              'prvs' => "Previous",
  867:                              'chto' => "Changed To"
  868: 						   );
  869:                 $r->print(<<"END");
  870: <table border="2">
  871: <caption>$lt{'uic'}</caption>
  872: <tr><th>&nbsp;</th>
  873:     <th>$lt{'frst'}</th>
  874:     <th>$lt{'mddl'}</th>
  875:     <th>$lt{'lst'}</th>
  876:     <th>$lt{'gen'}</th></tr>
  877: <tr><td>$lt{'prvs'}</td>
  878:     <td>$userenv{'firstname'}  </td>
  879:     <td>$userenv{'middlename'} </td>
  880:     <td>$userenv{'lastname'}   </td>
  881:     <td>$userenv{'generation'} </td></tr>
  882: <tr><td>$lt{'chto'}</td>
  883:     <td>$ENV{'form.cfirstname'}  </td>
  884:     <td>$ENV{'form.cmiddlename'} </td>
  885:     <td>$ENV{'form.clastname'}   </td>
  886:     <td>$ENV{'form.cgeneration'} </td></tr>
  887: </table>
  888: END
  889:             } else { # error occurred
  890:                 $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
  891:                       $ENV{'form.ccuname'}." ".&mt('in domain')." ".
  892:                       $ENV{'form.ccdomain'}."</h2>");
  893:             }
  894:         }  else { # End of if ($ENV ... ) logic
  895:             # They did not want to change the users name but we can
  896:             # still tell them what the name is
  897: 	    my %lt=&Apache::lonlocal::texthash(
  898:                            'usr'  => "User",                    
  899:                            'id'   => "in domain",
  900:                            'gen'  => "Generation"
  901: 					       );
  902:                 $r->print(<<"END");
  903: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
  904: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
  905: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
  906: END
  907:         }
  908:     }
  909:     ##
  910:     my $now=time;
  911:     $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
  912:     foreach (keys (%ENV)) {
  913: 	next if (! $ENV{$_});
  914: 	# Revoke roles
  915: 	if ($_=~/^form\.rev/) {
  916: 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
  917: # Revoke standard role
  918: 	        $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
  919:                      &Apache::lonnet::revokerole($ENV{'form.ccdomain'},
  920:                      $ENV{'form.ccuname'},$1,$2).'</b><br>');
  921: 		if ($2 eq 'st') {
  922: 		    $1=~/^\/(\w+)\/(\w+)/;
  923: 		    my $cid=$1.'_'.$2;
  924: 		    $r->print(&mt('Drop from classlist').': <b>'.
  925: 			 &Apache::lonnet::critical('put:'.
  926:                              $ENV{'course.'.$cid.'.domain'}.':'.
  927: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  928:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  929:                              $ENV{'form.ccdomain'}).'='.
  930:                          &Apache::lonnet::escape($now.':'),
  931: 	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
  932: 		}
  933: 	    } 
  934: 	    if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
  935: # Revoke custom role
  936: 		$r->print(&mt('Revoking custom role').
  937:                       ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
  938:                       &Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'},
  939: 				  $ENV{'form.ccuname'},$1,$2,$3,$4).
  940: 		'</b><br>');
  941: 	    }
  942: 	} elsif ($_=~/^form\.del/) {
  943: 	    if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
  944: 	        $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
  945:                      &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
  946:                      $ENV{'form.ccuname'},$1,$2,$now,0,1).'<br>');
  947: 		if ($2 eq 'st') {
  948: 		    $1=~/^\/(\w+)\/(\w+)/;
  949: 		    my $cid=$1.'_'.$2;
  950: 		    $r->print(&mt('Drop from classlist').': <b>'.
  951: 			 &Apache::lonnet::critical('put:'.
  952:                              $ENV{'course.'.$cid.'.domain'}.':'.
  953: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  954:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  955:                              $ENV{'form.ccdomain'}).'='.
  956:                          &Apache::lonnet::escape($now.':'),
  957: 	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
  958: 		}
  959: 	    } 
  960: 	} elsif ($_=~/^form\.act/) {
  961: 	    if 
  962: ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
  963:                 # Activate a custom role
  964: 		my $url='/'.$1.'/'.$2;
  965: 		my $full=$1.'_'.$2.'_cr_cr_'.$3.'_'.$4.'_'.$5;
  966: 		if ($ENV{'form.sec_'.$full}) {
  967: 		    $url.='/'.$ENV{'form.sec_'.$full};
  968: 		}
  969: 
  970: 		my $start = ( $ENV{'form.start_'.$full} ? 
  971: 			      $ENV{'form.start_'.$full} : 
  972: 			      $now );
  973: 		my $end   = ( $ENV{'form.end_'.$full} ? 
  974: 			      $ENV{'form.end_'.$full} :
  975: 			      0 );
  976: 
  977:     $r->print(&mt('Assigning custom role').' "'.$5.'" by '.$4.'@'.$3.' in '.$url.
  978:                          ($start?', '.&mt('starting').' '.localtime($start):'').
  979:                          ($end?', ending '.localtime($end):'').': <b>'.
  980: 	      &Apache::lonnet::assigncustomrole(
  981: 	$ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$3,$4,$5,$end,$start).
  982: 	      '</b><br>');
  983: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
  984: 		# Activate roles for sections with 3 id numbers
  985: 		# set start, end times, and the url for the class
  986: 
  987: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2.'_'.$3} ? 
  988: 			      $ENV{'form.start_'.$1.'_'.$2.'_'.$3} : 
  989: 			      $now );
  990: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2.'_'.$3} ? 
  991: 			      $ENV{'form.end_'.$1.'_'.$2.'_'.$3} :
  992: 			      0 );
  993: 		my $url='/'.$1.'/'.$2;
  994: 		if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
  995: 		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
  996: 		}
  997: 		# Assign the role and report it
  998: 		$r->print(&mt('Assigning').' '.$3.' in '.$url.
  999:                          ($start?', '.&mt('starting').' '.localtime($start):'').
 1000:                          ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
 1001:                           &Apache::lonnet::assignrole(
 1002:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
 1003:                               $url,$3,$end,$start).
 1004: 			  '</b><br>');
 1005: 		# Handle students differently
 1006: 		if ($3 eq 'st') {
 1007: 		    $url=~/^\/(\w+)\/(\w+)/;
 1008: 		    my $cid=$1.'_'.$2;
 1009: 		    $r->print(&mt('Add to classlist').': <b>'.
 1010: 			      &Apache::lonnet::critical(
 1011: 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
 1012: 	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
 1013:                                    &Apache::lonnet::escape(
 1014:                                        $ENV{'form.ccuname'}.':'.
 1015:                                        $ENV{'form.ccdomain'} ).'='.
 1016:                                    &Apache::lonnet::escape($end.':'.$start),
 1017: 				       $ENV{'course.'.$cid.'.home'})
 1018: 			      .'</b><br>');
 1019: 		}
 1020: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
 1021: 		# Activate roles for sections with two id numbers
 1022: 		# set start, end times, and the url for the class
 1023: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
 1024: 			      $ENV{'form.start_'.$1.'_'.$2} : 
 1025: 			      $now );
 1026: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
 1027: 			      $ENV{'form.end_'.$1.'_'.$2} :
 1028: 			      0 );
 1029: 		my $url='/'.$1.'/';
 1030: 		# Assign the role and report it.
 1031: 		$r->print(&mt('Assigning').' '.$2.' in '.$url.': '.
 1032:                          ($start?', '.&mt('starting').' '.localtime($start):'').
 1033:                          ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
 1034:                           &Apache::lonnet::assignrole(
 1035:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
 1036:                               $url,$2,$end,$start)
 1037: 			  .'</b><br>');
 1038: 	    } else {
 1039: 		$r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br>');
 1040:             }
 1041: 	} 
 1042:     } # End of foreach (keys(%ENV))
 1043: # Flush the course logs so reverse user roles immediately updated
 1044:     &Apache::lonnet::flushcourselogs();
 1045:     $r->print('</body></html>');
 1046: }
 1047: 
 1048: # ========================================================== Custom Role Editor
 1049: 
 1050: sub custom_role_editor {
 1051:     my $r=shift;
 1052:     my $rolename=$ENV{'form.rolename'};
 1053: 
 1054:     if ($rolename eq 'make new role') {
 1055: 	$rolename=$ENV{'form.newrolename'};
 1056:     }
 1057: 
 1058:     $rolename=~s/[^A-Za-z0-9]//gs;
 1059: 
 1060:     unless ($rolename) {
 1061: 	&print_username_entry_form($r);
 1062:         return;
 1063:     }
 1064: 
 1065:     $r->print(&Apache::loncommon::bodytag(
 1066:                      'Create Users, Change User Privileges').'<h2>');
 1067:     my $syspriv='';
 1068:     my $dompriv='';
 1069:     my $coursepriv='';
 1070:     my ($rdummy,$roledef)=
 1071: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
 1072: # ------------------------------------------------------- Does this role exist?
 1073:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
 1074: 	$r->print(&mt('Existing Role').' "');
 1075: # ------------------------------------------------- Get current role privileges
 1076: 	($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
 1077:     } else {
 1078: 	$r->print(&mt('New Role').' "');
 1079: 	$roledef='';
 1080:     }
 1081:     $r->print($rolename.'"</h2>');
 1082: # ------------------------------------------------------- What can be assigned?
 1083:     my %full=();
 1084:     my %courselevel=();
 1085:     my %courselevelcurrent=();
 1086:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
 1087: 	my ($priv,$restrict)=split(/\&/,$_);
 1088:         unless ($restrict) { $restrict='F'; }
 1089:         $courselevel{$priv}=$restrict;
 1090:         if ($coursepriv=~/\:$priv/) {
 1091: 	    $courselevelcurrent{$priv}=1;
 1092: 	}
 1093: 	$full{$priv}=1;
 1094:     }
 1095:     my %domainlevel=();
 1096:     my %domainlevelcurrent=();
 1097:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
 1098: 	my ($priv,$restrict)=split(/\&/,$_);
 1099:         unless ($restrict) { $restrict='F'; }
 1100:         $domainlevel{$priv}=$restrict;
 1101:         if ($dompriv=~/\:$priv/) {
 1102: 	    $domainlevelcurrent{$priv}=1;
 1103: 	}
 1104: 	$full{$priv}=1;
 1105:     }
 1106:     my %systemlevel=();
 1107:     my %systemlevelcurrent=();
 1108:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
 1109: 	my ($priv,$restrict)=split(/\&/,$_);
 1110:         unless ($restrict) { $restrict='F'; }
 1111:         $systemlevel{$priv}=$restrict;
 1112:         if ($syspriv=~/\:$priv/) {
 1113: 	    $systemlevelcurrent{$priv}=1;
 1114: 	}
 1115: 	$full{$priv}=1;
 1116:     }
 1117:     my %lt=&Apache::lonlocal::texthash(
 1118: 		    'prv'  => "Privilege",
 1119: 		    'crl'  => "Course Level",
 1120:                     'dml'  => "Domain Level",
 1121:                     'ssl'  => "System Level"
 1122: 				       );
 1123:     $r->print(<<ENDCCF);
 1124: <form method="post">
 1125: <input type="hidden" name="phase" value="set_custom_roles" />
 1126: <input type="hidden" name="rolename" value="$rolename" />
 1127: <table border="2">
 1128: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
 1129: <th>$lt{'ssl'}</th></tr>
 1130: ENDCCF
 1131:     foreach (sort keys %full) {
 1132: 	$r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
 1133:     ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
 1134:     ($courselevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
 1135:     '</td><td>'.
 1136:     ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
 1137:     ($domainlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
 1138:     '</td><td>'.
 1139:     ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
 1140:     ($systemlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
 1141:     '</td></tr>');
 1142:     }
 1143:     $r->print(
 1144:    '<table><input type="submit" value="'.&mt('Define Role').'" /></form></body></html>');
 1145: }
 1146: 
 1147: # ---------------------------------------------------------- Call to definerole
 1148: sub set_custom_role {
 1149:     my $r=shift;
 1150: 
 1151:     my $rolename=$ENV{'form.rolename'};
 1152: 
 1153:     $rolename=~s/[^A-Za-z0-9]//gs;
 1154: 
 1155:     unless ($rolename) {
 1156: 	&print_username_entry_form($r);
 1157:         return;
 1158:     }
 1159: 
 1160:     $r->print(&Apache::loncommon::bodytag(
 1161:                      'Create Users, Change User Privileges').'<h2>');
 1162:     my ($rdummy,$roledef)=
 1163: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
 1164: # ------------------------------------------------------- Does this role exist?
 1165:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
 1166: 	$r->print(&mt('Existing Role').' "');
 1167:     } else {
 1168: 	$r->print(&mt('New Role').' "');
 1169: 	$roledef='';
 1170:     }
 1171:     $r->print($rolename.'"</h2>');
 1172: # ------------------------------------------------------- What can be assigned?
 1173:     my $sysrole='';
 1174:     my $domrole='';
 1175:     my $courole='';
 1176: 
 1177:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
 1178: 	my ($priv,$restrict)=split(/\&/,$_);
 1179:         unless ($restrict) { $restrict=''; }
 1180:         if ($ENV{'form.'.$priv.':c'}) {
 1181: 	    $courole.=':'.$_;
 1182: 	}
 1183:     }
 1184: 
 1185:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
 1186: 	my ($priv,$restrict)=split(/\&/,$_);
 1187:         unless ($restrict) { $restrict=''; }
 1188:         if ($ENV{'form.'.$priv.':d'}) {
 1189: 	    $domrole.=':'.$_;
 1190: 	}
 1191:     }
 1192: 
 1193:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
 1194: 	my ($priv,$restrict)=split(/\&/,$_);
 1195:         unless ($restrict) { $restrict=''; }
 1196:         if ($ENV{'form.'.$priv.':s'}) {
 1197: 	    $sysrole.=':'.$_;
 1198: 	}
 1199:     }
 1200:     $r->print('<br />Defining Role: '.
 1201: 	   &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
 1202:     if ($ENV{'request.course.id'}) {
 1203:         my $url='/'.$ENV{'request.course.id'};
 1204:         $url=~s/\_/\//g;
 1205: 	$r->print('<br />'.&mt('Assigning Role to Self').': '.
 1206: 	      &Apache::lonnet::assigncustomrole($ENV{'user.domain'},
 1207: 						$ENV{'user.name'},
 1208: 						$url,
 1209: 						$ENV{'user.domain'},
 1210: 						$ENV{'user.name'},
 1211: 						$rolename));
 1212:     }
 1213:     $r->print('</body></html>');
 1214: }
 1215: 
 1216: # ================================================================ Main Handler
 1217: sub handler {
 1218:     my $r = shift;
 1219: 
 1220:     if ($r->header_only) {
 1221:        &Apache::loncommon::content_type($r,'text/html');
 1222:        $r->send_http_header;
 1223:        return OK;
 1224:     }
 1225: 
 1226:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
 1227:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
 1228:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
 1229:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
 1230:         (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
 1231:         (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
 1232:        &Apache::loncommon::content_type($r,'text/html');
 1233:        $r->send_http_header;
 1234:        unless ($ENV{'form.phase'}) {
 1235: 	   &print_username_entry_form($r);
 1236:        }
 1237:        if ($ENV{'form.phase'} eq 'get_user_info') {
 1238:            &print_user_modification_page($r);
 1239:        } elsif ($ENV{'form.phase'} eq 'update_user_data') {
 1240:            &update_user_data($r);
 1241:        } elsif ($ENV{'form.phase'} eq 'selected_custom_edit') {
 1242:            &custom_role_editor($r);
 1243:        } elsif ($ENV{'form.phase'} eq 'set_custom_roles') {
 1244: 	   &set_custom_role($r);
 1245:        }
 1246:    } else {
 1247:       $ENV{'user.error.msg'}=
 1248:         "/adm/createuser:mau:0:0:Cannot modify user data";
 1249:       return HTTP_NOT_ACCEPTABLE; 
 1250:    }
 1251:    return OK;
 1252: } 
 1253: 
 1254: #-------------------------------------------------- functions for &phase_two
 1255: sub course_level_table {
 1256:     my %inccourses = @_;
 1257:     my $table = '';
 1258: # Custom Roles?
 1259: 
 1260:     my %customroles=&my_custom_roles();
 1261: 
 1262:     foreach (sort( keys(%inccourses))) {
 1263: 	my $thiscourse=$_;
 1264: 	my $protectedcourse=$_;
 1265: 	$thiscourse=~s:_:/:g;
 1266: 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
 1267: 	my $area=$coursedata{'description'};
 1268: 	if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
 1269: 	my $bgcol=$thiscourse;
 1270: 	$bgcol=~s/[^7-9a-e]//g;
 1271: 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
 1272: 	foreach  ('st','ta','ep','ad','in','cc') {
 1273: 	    if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
 1274: 		my $plrole=&Apache::lonnet::plaintext($_);
 1275: 		$table .= <<ENDEXTENT;
 1276: <tr bgcolor="#$bgcol">
 1277: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
 1278: <td>$plrole</td>
 1279: <td>$area</td>
 1280: ENDEXTENT
 1281: 	        if ($_ ne 'cc') {
 1282: 		    $table .= <<ENDSECTION;
 1283: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
 1284: ENDSECTION
 1285:                 } else { 
 1286: 		    $table .= <<ENDSECTION;
 1287: <td>&nbsp</td> 
 1288: ENDSECTION
 1289:                 }
 1290: 		my %lt=&Apache::lonlocal::texthash(
 1291:                                'ssd'  => "Set Start Date",
 1292:                                'sed'  => "Set End Date"
 1293: 						   );
 1294: 		$table .= <<ENDTIMEENTRY;
 1295: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
 1296: <a href=
 1297: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
 1298: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
 1299: <a href=
 1300: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
 1301: ENDTIMEENTRY
 1302:                 $table.= "</tr>\n";
 1303:             }
 1304:         }
 1305:         foreach (sort keys %customroles) {
 1306: 	    if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
 1307: 		my $plrole=$_;
 1308:                 my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}.
 1309: 		    '_'.$ENV{'user.name'}.'_'.$plrole;
 1310: 		my %lt=&Apache::lonlocal::texthash(
 1311:                                'ssd'  => "Set Start Date",
 1312:                                'sed'  => "Set End Date"
 1313: 						   );
 1314: 		$table .= <<ENDENTRY;
 1315: <tr bgcolor="#$bgcol">
 1316: <td><input type="checkbox" name="act_$customrole"></td>
 1317: <td>$plrole</td>
 1318: <td>$area</td>
 1319: <td><input type="text" size="5" name="sec_$customrole"></td>
 1320: <td><input type=hidden name="start_$customrole" value=''>
 1321: <a href=
 1322: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
 1323: <td><input type=hidden name="end_$customrole" value=''>
 1324: <a href=
 1325: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td></tr>
 1326: ENDENTRY
 1327:            }
 1328: 	}
 1329:     }
 1330:     return '' if ($table eq ''); # return nothing if there is nothing 
 1331:                                  # in the table
 1332:     my %lt=&Apache::lonlocal::texthash(
 1333: 		    'crl'  => "Course Level",
 1334:                     'act'  => "Activate",
 1335:                     'rol'  => "Role",
 1336:                     'ext'  => "Extent",
 1337:                     'grs'  => "Group/Section",
 1338:                     'sta'  => "Start",
 1339:                     'end'  => "End"
 1340: 				       );
 1341:     my $result = <<ENDTABLE;
 1342: <h4>$lt{'crl'}</h4>
 1343: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
 1344: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
 1345: $table
 1346: </table>
 1347: ENDTABLE
 1348:     return $result;
 1349: }
 1350: #---------------------------------------------- end functions for &phase_two
 1351: 
 1352: #--------------------------------- functions for &phase_two and &phase_three
 1353: 
 1354: #--------------------------end of functions for &phase_two and &phase_three
 1355: 
 1356: 1;
 1357: __END__
 1358: 
 1359: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>