File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.81: download - view: text, annotated - select for diffs
Thu Apr 15 22:35:51 2004 UTC (20 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#2550, Re-Enable check box on CUSR form

    1: # The LearningOnline Network with CAPA
    2: # Create a user
    3: #
    4: # $Id: loncreateuser.pm,v 1.81 2004/04/15 22:35:51 albertel 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: 		    'ren'  => "Re-Enable",
  349:                     'rol'  => "Role",
  350:                     'ext'  => "Extent",
  351:                     'sta'  => "Start",
  352:                     'end'  => "End"
  353: 				       );
  354:            $r->print(<<END);
  355: <hr />
  356: <h3>$lt{'rer'}</h3>
  357: <table>
  358: <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>
  359: END
  360:            my (%roletext,%sortrole,%roleclass);
  361: 	   foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
  362: 				    my $b1=join('_',(split('_',$b))[1,0]);
  363: 				    return $a1 cmp $b1;
  364: 				} keys(%rolesdump)) {
  365:                next if ($area =~ /^rolesdef/);
  366: 	       my $envkey=$area;
  367:                my $role = $rolesdump{$area};
  368:                my $thisrole=$area;
  369:                $area =~ s/\_\w\w$//;
  370:                my ($role_code,$role_end_time,$role_start_time) = 
  371:                    split(/_/,$role);
  372: # Is this a custom role? Get role owner and title.
  373: 	       my ($croleudom,$croleuname,$croletitle)=
  374: 	           ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
  375:                my $bgcol='ffffff';
  376:                my $allowed=0;
  377:                my $delallowed=0;
  378: 	       my $sortkey=$role_code;
  379: 	       my $class='Unknown';
  380:                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
  381: 		   $class='Course';
  382:                    my ($coursedom,$coursedir) = ($1,$2);
  383: 		   $sortkey.="\0$1";
  384:                    # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
  385:                    my %coursedata=
  386:                        &Apache::lonnet::coursedescription($1.'_'.$2);
  387: 		   my $carea;
  388: 		   if (defined($coursedata{'description'})) {
  389: 		       $carea=$coursedata{'description'}.
  390:                            '<br />'.&mt('Domain').': '.$coursedom.('&nbsp;'x8).
  391:      &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
  392: 		       $sortkey.="\0".$coursedata{'description'};
  393: 		   } else {
  394: 		       $carea=&mt('Unavailable course').': '.$area;
  395: 		       $sortkey.="\0".&mt('Unavailable course');
  396: 		   }
  397:                    $inccourses{$1.'_'.$2}=1;
  398:                    if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
  399:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
  400:                        $allowed=1;
  401:                    }
  402:                    if ((&Apache::lonnet::allowed('dro',$1)) ||
  403:                        (&Apache::lonnet::allowed('dro',$ccdomain))) {
  404:                        $delallowed=1;
  405:                    }
  406: # - custom role. Needs more info, too
  407: 		   if ($croletitle) {
  408: 		       if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
  409: 			   $allowed=1;
  410: 			   $thisrole.='.'.$role_code;
  411: 		       }
  412: 		   }
  413:                    # Compute the background color based on $area
  414:                    $bgcol=$1.'_'.$2;
  415:                    $bgcol=~s/[^7-9a-e]//g;
  416:                    $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
  417:                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
  418:                        $carea.='<br>Section/Group: '.$3;
  419:                    }
  420:                    $area=$carea;
  421:                } else {
  422: 		   $sortkey.="\0".$area;
  423:                    # Determine if current user is able to revoke privileges
  424:                    if ($area=~ /^\/(\w+)\//) {
  425:                        if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
  426:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
  427:                            $allowed=1;
  428:                        }
  429:                        if (((&Apache::lonnet::allowed('dro',$1))  ||
  430:                             (&Apache::lonnet::allowed('dro',$ccdomain))) &&
  431:                            ($role_code ne 'dc')) {
  432:                            $delallowed=1;
  433:                        }
  434:                    } else {
  435:                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
  436:                            $allowed=1;
  437:                        }
  438:                    }
  439: 		   if ($role_code eq 'ca' || $role_code eq 'au') {
  440: 		       $class='Construction Space';
  441: 		   } elsif ($role_code eq 'su') {
  442: 		       $class='System';
  443: 		   } else {
  444: 		       $class='Domain';
  445: 		   }
  446:                }
  447:                if ($role_code eq 'ca') {
  448:                    $area=~/\/(\w+)\/(\w+)/;
  449: 		   if (&authorpriv($2,$1)) {
  450: 		       $allowed=1;
  451:                    } else {
  452:                        $allowed=0;
  453:                    }
  454:                }
  455: 	       $bgcol='77FF77';
  456:                my $row = '';
  457:                $row.='<tr bgcolor="#'.$bgcol.'"><td>';
  458:                my $active=1;
  459:                $active=0 if (($role_end_time) && ($now>$role_end_time));
  460:                if (($active) && ($allowed)) {
  461:                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
  462:                } else {
  463:                    if ($active) {
  464:                       $row.='&nbsp;';
  465: 		   } else {
  466:                       $row.=&mt('expired or revoked');
  467: 		   }
  468:                }
  469: 	       $row.='</td><td>';
  470:                if ($allowed && !$active) {
  471:                    $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
  472:                } else {
  473:                    $row.='&nbsp;';
  474:                }
  475: 	       $row.='</td><td>';
  476:                if ($delallowed) {
  477:                    $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
  478:                } else {
  479:                    $row.='&nbsp;';
  480:                }
  481: 	       my $plaintext='';
  482: 	       unless ($croletitle) {
  483: 		   $plaintext=&Apache::lonnet::plaintext($role_code);
  484: 	       } else {
  485: 	           $plaintext=
  486: 		"Customrole '$croletitle' defined by $croleuname\@$croleudom";
  487: 	       }
  488:                $row.= '</td><td>'.$plaintext.
  489:                       '</td><td>'.$area.
  490:                       '</td><td>'.($role_start_time?localtime($role_start_time)
  491:                                                    : '&nbsp;' ).
  492:                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
  493:                                                    : '&nbsp;' )
  494:                       ."</td></tr>\n";
  495: 	       $sortrole{$sortkey}=$envkey;
  496: 	       $roletext{$envkey}=$row;
  497: 	       $roleclass{$envkey}=$class;
  498:                #$r->print($row);
  499:            } # end of foreach        (table building loop)
  500: 	   foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
  501: 	       my $output;
  502: 	       foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
  503: 		   if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { 
  504: 		       $output.=$roletext{$sortrole{$which}};
  505: 		   }
  506: 	       }
  507: 	       if (defined($output)) {
  508: 		   $r->print("<tr bgcolor='#BBffBB'>".
  509: 			     "<td align='center' colspan='7'>".&mt($type)."</td>");
  510: 	       }
  511: 	       $r->print($output);
  512: 	   }
  513: 	   $r->print('</table>');
  514:         }  # End of unless
  515: 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
  516: 	if ($currentauth=~/^krb(4|5):/) {
  517: 	    $currentauth=~/^krb(4|5):(.*)/;
  518: 	    my $krbdefdom=$1;
  519:             my %param = ( formname => 'document.cu',
  520:                           kerb_def_dom => $krbdefdom 
  521:                           );
  522:             $loginscript  = &Apache::loncommon::authform_header(%param);
  523: 	}
  524: 	# Check for a bad authentication type
  525:         unless ($currentauth=~/^krb(4|5):/ or
  526: 		$currentauth=~/^unix:/ or
  527: 		$currentauth=~/^internal:/ or
  528: 		$currentauth=~/^localauth:/
  529: 		) { # bad authentication scheme
  530: 	    if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  531: 		my %lt=&Apache::lonlocal::texthash(
  532:                                'err'   => "ERROR",
  533: 			       'uuas'  => "This user has an unrecognized authentication scheme",
  534:                                'sldb'  => "Please specify login data below",
  535:                                'ld'    => "Login Data"
  536: 						   );
  537: 		$r->print(<<ENDBADAUTH);
  538: <hr />
  539: <script type="text/javascript" language="Javascript">
  540: $loginscript
  541: </script>
  542: <font color='#ff0000'>$lt{'err'}:</font>
  543: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
  544: <h3>$lt{'ld'}</h3>
  545: <p>$generalrule</p>
  546: <p>$authformkrb</p>
  547: <p>$authformint</p>
  548: <p>$authformfsys</p>
  549: <p>$authformloc</p>
  550: ENDBADAUTH
  551:             } else { 
  552:                 # This user is not allowed to modify the users 
  553:                 # authentication scheme, so just notify them of the problem
  554: 		my %lt=&Apache::lonlocal::texthash(
  555:                                'err'   => "ERROR",
  556: 			       'uuas'  => "This user has an unrecognized authentication scheme",
  557:                                'adcs'  => "Please alert a domain coordinator of this situation"
  558: 						   );
  559: 		$r->print(<<ENDBADAUTH);
  560: <hr />
  561: <script type="text/javascript" language="Javascript">
  562: $loginscript
  563: </script>
  564: <font color="#ff0000"> $lt{'err'}: </font>
  565: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
  566: <hr />
  567: ENDBADAUTH
  568:             }
  569:         } else { # Authentication type is valid
  570: 	    my $authformcurrent='';
  571: 	    my $authform_other='';
  572: 	    if ($currentauth=~/^krb(4|5):/) {
  573: 		$authformcurrent=$authformkrb;
  574: 		$authform_other="<p>$authformint</p>\n".
  575:                     "<p>$authformfsys</p><p>$authformloc</p>";
  576: 	    }
  577: 	    elsif ($currentauth=~/^internal:/) {
  578: 		$authformcurrent=$authformint;
  579: 		$authform_other="<p>$authformkrb</p>".
  580:                     "<p>$authformfsys</p><p>$authformloc</p>";
  581: 	    }
  582: 	    elsif ($currentauth=~/^unix:/) {
  583: 		$authformcurrent=$authformfsys;
  584: 		$authform_other="<p>$authformkrb</p>".
  585:                     "<p>$authformint</p><p>$authformloc;</p>";
  586: 	    }
  587: 	    elsif ($currentauth=~/^localauth:/) {
  588: 		$authformcurrent=$authformloc;
  589: 		$authform_other="<p>$authformkrb</p>".
  590:                     "<p>$authformint</p><p>$authformfsys</p>";
  591: 	    }
  592:             $authformcurrent.=' <i>(will override current values)</i><br />';
  593:             if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  594: 		# Current user has login modification privileges
  595: 		my %lt=&Apache::lonlocal::texthash(
  596:                                'ccld'  => "Change Current Login Data",
  597: 			       'enld'  => "Enter New Login Data"
  598: 						   );
  599: 		$r->print(<<ENDOTHERAUTHS);
  600: <hr />
  601: <script type="text/javascript" language="Javascript">
  602: $loginscript
  603: </script>
  604: <h3>$lt{'ccld'}</h3>
  605: <p>$generalrule</p>
  606: <p>$authformnop</p>
  607: <p>$authformcurrent</p>
  608: <h3>$lt{'enld'}</h3>
  609: $authform_other
  610: ENDOTHERAUTHS
  611:             }
  612:         }  ## End of "check for bad authentication type" logic
  613:     } ## End of new user/old user logic
  614:     $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
  615: #
  616: # Co-Author
  617: # 
  618:     if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
  619:         ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
  620:         # No sense in assigning co-author role to yourself
  621: 	my $cuname=$ENV{'user.name'};
  622:         my $cudom=$ENV{'request.role.domain'};
  623: 	   my %lt=&Apache::lonlocal::texthash(
  624: 		    'cs'   => "Construction Space",
  625:                     'act'  => "Activate",                    
  626:                     'rol'  => "Role",
  627:                     'ext'  => "Extent",
  628:                     'sta'  => "Start",
  629:                     'end'  => "End",
  630:                     'cau'  => "Co-Author",
  631:                     'ssd'  => "Set Start Date",
  632:                     'sed'  => "Set End Date"
  633: 				       );
  634:        $r->print(<<ENDCOAUTH);
  635: <h4>$lt{'cs'}</h4>
  636: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
  637: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
  638: <tr>
  639: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
  640: <td>$lt{'cau'}</td>
  641: <td>$cudom\_$cuname</td>
  642: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
  643: <a href=
  644: "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>
  645: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
  646: <a href=
  647: "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>
  648: </tr>
  649: </table>
  650: ENDCOAUTH
  651:     }
  652: #
  653: # Domain level
  654: #
  655:     $r->print('<h4>'.&mt('Domain Level').'</h4>'.
  656:     '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
  657:     '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>');
  658:     foreach ( sort( keys(%incdomains))) {
  659: 	my $thisdomain=$_;
  660:         foreach ('dc','li','dg','au','sc') {
  661:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
  662:                my $plrole=&Apache::lonnet::plaintext($_);
  663: 	       my %lt=&Apache::lonlocal::texthash(
  664:                     'ssd'  => "Set Start Date",
  665:                     'sed'  => "Set End Date"
  666: 				       );
  667:                $r->print(<<ENDDROW);
  668: <tr>
  669: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
  670: <td>$plrole</td>
  671: <td>$thisdomain</td>
  672: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
  673: <a href=
  674: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
  675: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
  676: <a href=
  677: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
  678: </tr>
  679: ENDDROW
  680:             }
  681:         } 
  682:     }
  683:     $r->print('</table>');
  684: #
  685: # Course level
  686: #
  687:     $r->print(&course_level_table(%inccourses));
  688:     $r->print("<hr /><input type=submit value=\"".&mt('Modify User')."\">\n");
  689:     $r->print("</form></body></html>");
  690: }
  691: 
  692: # ================================================================= Phase Three
  693: sub update_user_data {
  694:     my $r=shift;
  695:     my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
  696:                                           $ENV{'form.ccdomain'});
  697:     # Error messages
  698:     my $error     = '<font color="#ff0000">'.&mt('Error').':</font>';
  699:     my $end       = '</body></html>';
  700:     # Print header
  701:     $r->print(<<ENDTHREEHEAD);
  702: <html>
  703: <head>
  704: <title>The LearningOnline Network with CAPA</title>
  705: </head>
  706: ENDTHREEHEAD
  707:     my $title;
  708:     if (exists($ENV{'form.makeuser'})) {
  709: 	$title='Set Privileges for New User';
  710:     } else {
  711:         $title='Modify User Privileges';
  712:     }
  713:     $r->print(&Apache::loncommon::bodytag($title));
  714:     # Check Inputs
  715:     if (! $ENV{'form.ccuname'} ) {
  716: 	$r->print($error.&mt('No login name specified').'.'.$end);
  717: 	return;
  718:     }
  719:     if (  $ENV{'form.ccuname'}  =~/\W/) {
  720: 	$r->print($error.&mt('Invalid login name').'.  '.
  721: 		  &mt('Only letters, numbers, and underscores are valid').'.'.
  722: 		  $end);
  723: 	return;
  724:     }
  725:     if (! $ENV{'form.ccdomain'}       ) {
  726: 	$r->print($error.&mt('No domain specified').'.'.$end);
  727: 	return;
  728:     }
  729:     if (  $ENV{'form.ccdomain'} =~/\W/) {
  730: 	$r->print($error.&mt ('Invalid domain name').'.  '.
  731: 		  &mt('Only letters, numbers, and underscores are valid').'.'.
  732: 		  $end);
  733: 	return;
  734:     }
  735:     if (! exists($ENV{'form.makeuser'})) {
  736:         # Modifying an existing user, so check the validity of the name
  737:         if ($uhome eq 'no_host') {
  738:             $r->print($error.&mt('Unable to determine home server for ').
  739:                       $ENV{'form.ccuname'}.&mt(' in domain ').
  740:                       $ENV{'form.ccdomain'}.'.');
  741:             return;
  742:         }
  743:     }
  744:     # Determine authentication method and password for the user being modified
  745:     my $amode='';
  746:     my $genpwd='';
  747:     if ($ENV{'form.login'} eq 'krb') {
  748: 	$amode='krb';
  749: 	$amode.=$ENV{'form.krbver'};
  750: 	$genpwd=$ENV{'form.krbarg'};
  751:     } elsif ($ENV{'form.login'} eq 'int') {
  752: 	$amode='internal';
  753: 	$genpwd=$ENV{'form.intarg'};
  754:     } elsif ($ENV{'form.login'} eq 'fsys') {
  755: 	$amode='unix';
  756: 	$genpwd=$ENV{'form.fsysarg'};
  757:     } elsif ($ENV{'form.login'} eq 'loc') {
  758: 	$amode='localauth';
  759: 	$genpwd=$ENV{'form.locarg'};
  760: 	$genpwd=" " if (!$genpwd);
  761:     } elsif (($ENV{'form.login'} eq 'nochange') ||
  762:              ($ENV{'form.login'} eq ''        )) { 
  763:         # There is no need to tell the user we did not change what they
  764:         # did not ask us to change.
  765:         # If they are creating a new user but have not specified login
  766:         # information this will be caught below.
  767:     } else {
  768: 	    $r->print($error.&mt('Invalid login mode or password').$end);    
  769: 	    return;
  770:     }
  771:     if ($ENV{'form.makeuser'}) {
  772:         # Create a new user
  773: 	my %lt=&Apache::lonlocal::texthash(
  774:                     'cru'  => "Creating user",                    
  775:                     'id'   => "in domain"
  776: 					   );
  777: 	$r->print(<<ENDNEWUSERHEAD);
  778: <h3>$lt{'cru'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h3>
  779: ENDNEWUSERHEAD
  780:         # Check for the authentication mode and password
  781:         if (! $amode || ! $genpwd) {
  782: 	    $r->print($error.&mt('Invalid login mode or password').$end);    
  783: 	    return;
  784: 	}
  785:         # Determine desired host
  786:         my $desiredhost = $ENV{'form.hserver'};
  787:         if (lc($desiredhost) eq 'default') {
  788:             $desiredhost = undef;
  789:         } else {
  790:             my %home_servers = &Apache::loncommon::get_library_servers
  791:                 ($ENV{'form.ccdomain'});  
  792:             if (! exists($home_servers{$desiredhost})) {
  793:                 $r->print($error.&mt('Invalid home server specified'));
  794:                 return;
  795:             }
  796:         }
  797: 	# Call modifyuser
  798: 	my $result = &Apache::lonnet::modifyuser
  799: 	    ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
  800:              $amode,$genpwd,$ENV{'form.cfirst'},
  801:              $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
  802:              undef,$desiredhost
  803: 	     );
  804: 	$r->print(&mt('Generating user').': '.$result);
  805:         my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
  806:                                                $ENV{'form.ccdomain'});
  807:         $r->print('<br />'.&mt('Home server').': '.$home.' '.
  808:                   $Apache::lonnet::libserv{$home});
  809:     } elsif (($ENV{'form.login'} ne 'nochange') &&
  810:              ($ENV{'form.login'} ne ''        )) {
  811: 	# Modify user privileges
  812:     my %lt=&Apache::lonlocal::texthash(
  813:                     'usr'  => "User",                    
  814:                     'id'   => "in domain"
  815: 				       );
  816: 	$r->print(<<ENDMODIFYUSERHEAD);
  817: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
  818: ENDMODIFYUSERHEAD
  819:         if (! $amode || ! $genpwd) {
  820: 	    $r->print($error.'Invalid login mode or password'.$end);    
  821: 	    return;
  822: 	}
  823: 	# Only allow authentification modification if the person has authority
  824: 	if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
  825: 	    $r->print('Modifying authentication: '.
  826:                       &Apache::lonnet::modifyuserauth(
  827: 		       $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  828:                        $amode,$genpwd));
  829:             $r->print('<br>'.&mt('Home server').': '.&Apache::lonnet::homeserver
  830: 		  ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
  831: 	} else {
  832: 	    # Okay, this is a non-fatal error.
  833: 	    $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');    
  834: 	}
  835:     }
  836:     ##
  837:     if (! $ENV{'form.makeuser'} ) {
  838:         # Check for need to change
  839:         my %userenv = &Apache::lonnet::get
  840:             ('environment',['firstname','middlename','lastname','generation'],
  841:              $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  842:         my ($tmp) = keys(%userenv);
  843:         if ($tmp =~ /^(con_lost|error)/i) { 
  844:             %userenv = ();
  845:         }
  846:         # Check to see if we need to change user information
  847:         foreach ('firstname','middlename','lastname','generation') {
  848:             # Strip leading and trailing whitespace
  849:             $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
  850:         }
  851:         if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) && 
  852:             ($ENV{'form.cfirstname'}  ne $userenv{'firstname'}  ||
  853:              $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
  854:              $ENV{'form.clastname'}   ne $userenv{'lastname'}   ||
  855:              $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
  856:             # Make the change
  857:             my %changeHash;
  858:             $changeHash{'firstname'}  = $ENV{'form.cfirstname'};
  859:             $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
  860:             $changeHash{'lastname'}   = $ENV{'form.clastname'};
  861:             $changeHash{'generation'} = $ENV{'form.cgeneration'};
  862:             my $putresult = &Apache::lonnet::put
  863:                 ('environment',\%changeHash,
  864:                  $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  865:             if ($putresult eq 'ok') {
  866:             # Tell the user we changed the name
  867: 		my %lt=&Apache::lonlocal::texthash(
  868:                              'uic'  => "User Information Changed",             
  869:                              'frst' => "first",
  870:                              'mddl' => "middle",
  871:                              'lst'  => "last",
  872: 			     'gen'  => "generation",
  873:                              'prvs' => "Previous",
  874:                              'chto' => "Changed To"
  875: 						   );
  876:                 $r->print(<<"END");
  877: <table border="2">
  878: <caption>$lt{'uic'}</caption>
  879: <tr><th>&nbsp;</th>
  880:     <th>$lt{'frst'}</th>
  881:     <th>$lt{'mddl'}</th>
  882:     <th>$lt{'lst'}</th>
  883:     <th>$lt{'gen'}</th></tr>
  884: <tr><td>$lt{'prvs'}</td>
  885:     <td>$userenv{'firstname'}  </td>
  886:     <td>$userenv{'middlename'} </td>
  887:     <td>$userenv{'lastname'}   </td>
  888:     <td>$userenv{'generation'} </td></tr>
  889: <tr><td>$lt{'chto'}</td>
  890:     <td>$ENV{'form.cfirstname'}  </td>
  891:     <td>$ENV{'form.cmiddlename'} </td>
  892:     <td>$ENV{'form.clastname'}   </td>
  893:     <td>$ENV{'form.cgeneration'} </td></tr>
  894: </table>
  895: END
  896:             } else { # error occurred
  897:                 $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
  898:                       $ENV{'form.ccuname'}." ".&mt('in domain')." ".
  899:                       $ENV{'form.ccdomain'}."</h2>");
  900:             }
  901:         }  else { # End of if ($ENV ... ) logic
  902:             # They did not want to change the users name but we can
  903:             # still tell them what the name is
  904: 	    my %lt=&Apache::lonlocal::texthash(
  905:                            'usr'  => "User",                    
  906:                            'id'   => "in domain",
  907:                            'gen'  => "Generation"
  908: 					       );
  909:                 $r->print(<<"END");
  910: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
  911: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
  912: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
  913: END
  914:         }
  915:     }
  916:     ##
  917:     my $now=time;
  918:     $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
  919:     foreach (keys (%ENV)) {
  920: 	next if (! $ENV{$_});
  921: 	# Revoke roles
  922: 	if ($_=~/^form\.rev/) {
  923: 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
  924: # Revoke standard role
  925: 	        $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
  926:                      &Apache::lonnet::revokerole($ENV{'form.ccdomain'},
  927:                      $ENV{'form.ccuname'},$1,$2).'</b><br>');
  928: 		if ($2 eq 'st') {
  929: 		    $1=~/^\/(\w+)\/(\w+)/;
  930: 		    my $cid=$1.'_'.$2;
  931: 		    $r->print(&mt('Drop from classlist').': <b>'.
  932: 			 &Apache::lonnet::critical('put:'.
  933:                              $ENV{'course.'.$cid.'.domain'}.':'.
  934: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  935:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  936:                              $ENV{'form.ccdomain'}).'='.
  937:                          &Apache::lonnet::escape($now.':'),
  938: 	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
  939: 		}
  940: 	    } 
  941: 	    if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
  942: # Revoke custom role
  943: 		$r->print(&mt('Revoking custom role').
  944:                       ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
  945:                       &Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'},
  946: 				  $ENV{'form.ccuname'},$1,$2,$3,$4).
  947: 		'</b><br>');
  948: 	    }
  949: 	} elsif ($_=~/^form\.del/) {
  950: 	    if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
  951: 	        $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
  952:                      &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
  953:                      $ENV{'form.ccuname'},$1,$2,$now,0,1).'<br>');
  954: 		if ($2 eq 'st') {
  955: 		    $1=~/^\/(\w+)\/(\w+)/;
  956: 		    my $cid=$1.'_'.$2;
  957: 		    $r->print(&mt('Drop from classlist').': <b>'.
  958: 			 &Apache::lonnet::critical('put:'.
  959:                              $ENV{'course.'.$cid.'.domain'}.':'.
  960: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  961:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  962:                              $ENV{'form.ccdomain'}).'='.
  963:                          &Apache::lonnet::escape($now.':'),
  964: 	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
  965: 		}
  966: 	    } 
  967: 	} elsif ($_=~/^form\.ren/) {
  968: 	    if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
  969: 		my $result=&Apache::lonnet::assignrole($ENV{'form.ccdomain'},
  970: 					 $ENV{'form.ccuname'},$1,$2,0,$now);
  971: 		$r->print(&mt('Re-Enabling [_1] in [_2]: [_3]',
  972: 			      $2,$1,$result).'<br />');
  973: 		if ($2 eq 'st') {
  974: 		    $1=~/^\/(\w+)\/(\w+)/;
  975: 		    my $cid=$1.'_'.$2;
  976: 		    $r->print(&mt('Add to classlist').': <b>'.
  977: 			      &Apache::lonnet::critical(
  978: 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
  979: 	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
  980:                                    &Apache::lonnet::escape(
  981:                                        $ENV{'form.ccuname'}.':'.
  982:                                        $ENV{'form.ccdomain'} ).'='.
  983:                                    &Apache::lonnet::escape(':'.$now),
  984: 				       $ENV{'course.'.$cid.'.home'})
  985: 			      .'</b><br>');
  986: 		}
  987: 	    } 
  988: 	} elsif ($_=~/^form\.act/) {
  989: 	    if 
  990: ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
  991:                 # Activate a custom role
  992: 		my $url='/'.$1.'/'.$2;
  993: 		my $full=$1.'_'.$2.'_cr_cr_'.$3.'_'.$4.'_'.$5;
  994: 		if ($ENV{'form.sec_'.$full}) {
  995: 		    $url.='/'.$ENV{'form.sec_'.$full};
  996: 		}
  997: 
  998: 		my $start = ( $ENV{'form.start_'.$full} ? 
  999: 			      $ENV{'form.start_'.$full} : 
 1000: 			      $now );
 1001: 		my $end   = ( $ENV{'form.end_'.$full} ? 
 1002: 			      $ENV{'form.end_'.$full} :
 1003: 			      0 );
 1004: 
 1005:     $r->print(&mt('Assigning custom role').' "'.$5.'" by '.$4.'@'.$3.' in '.$url.
 1006:                          ($start?', '.&mt('starting').' '.localtime($start):'').
 1007:                          ($end?', ending '.localtime($end):'').': <b>'.
 1008: 	      &Apache::lonnet::assigncustomrole(
 1009: 	$ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$3,$4,$5,$end,$start).
 1010: 	      '</b><br>');
 1011: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
 1012: 		# Activate roles for sections with 3 id numbers
 1013: 		# set start, end times, and the url for the class
 1014: 
 1015: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2.'_'.$3} ? 
 1016: 			      $ENV{'form.start_'.$1.'_'.$2.'_'.$3} : 
 1017: 			      $now );
 1018: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2.'_'.$3} ? 
 1019: 			      $ENV{'form.end_'.$1.'_'.$2.'_'.$3} :
 1020: 			      0 );
 1021: 		my $url='/'.$1.'/'.$2;
 1022: 		if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
 1023: 		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
 1024: 		}
 1025: 		# Assign the role and report it
 1026: 		$r->print(&mt('Assigning').' '.$3.' in '.$url.
 1027:                          ($start?', '.&mt('starting').' '.localtime($start):'').
 1028:                          ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
 1029:                           &Apache::lonnet::assignrole(
 1030:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
 1031:                               $url,$3,$end,$start).
 1032: 			  '</b><br>');
 1033: 		# Handle students differently
 1034: 		if ($3 eq 'st') {
 1035: 		    $url=~/^\/(\w+)\/(\w+)/;
 1036: 		    my $cid=$1.'_'.$2;
 1037: 		    $r->print(&mt('Add to classlist').': <b>'.
 1038: 			      &Apache::lonnet::critical(
 1039: 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
 1040: 	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
 1041:                                    &Apache::lonnet::escape(
 1042:                                        $ENV{'form.ccuname'}.':'.
 1043:                                        $ENV{'form.ccdomain'} ).'='.
 1044:                                    &Apache::lonnet::escape($end.':'.$start),
 1045: 				       $ENV{'course.'.$cid.'.home'})
 1046: 			      .'</b><br>');
 1047: 		}
 1048: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
 1049: 		# Activate roles for sections with two id numbers
 1050: 		# set start, end times, and the url for the class
 1051: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
 1052: 			      $ENV{'form.start_'.$1.'_'.$2} : 
 1053: 			      $now );
 1054: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
 1055: 			      $ENV{'form.end_'.$1.'_'.$2} :
 1056: 			      0 );
 1057: 		my $url='/'.$1.'/';
 1058: 		# Assign the role and report it.
 1059: 		$r->print(&mt('Assigning').' '.$2.' in '.$url.': '.
 1060:                          ($start?', '.&mt('starting').' '.localtime($start):'').
 1061:                          ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
 1062:                           &Apache::lonnet::assignrole(
 1063:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
 1064:                               $url,$2,$end,$start)
 1065: 			  .'</b><br>');
 1066: 	    } else {
 1067: 		$r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br>');
 1068:             }
 1069: 	} 
 1070:     } # End of foreach (keys(%ENV))
 1071: # Flush the course logs so reverse user roles immediately updated
 1072:     &Apache::lonnet::flushcourselogs();
 1073:     $r->print('</body></html>');
 1074: }
 1075: 
 1076: # ========================================================== Custom Role Editor
 1077: 
 1078: sub custom_role_editor {
 1079:     my $r=shift;
 1080:     my $rolename=$ENV{'form.rolename'};
 1081: 
 1082:     if ($rolename eq 'make new role') {
 1083: 	$rolename=$ENV{'form.newrolename'};
 1084:     }
 1085: 
 1086:     $rolename=~s/[^A-Za-z0-9]//gs;
 1087: 
 1088:     unless ($rolename) {
 1089: 	&print_username_entry_form($r);
 1090:         return;
 1091:     }
 1092: 
 1093:     $r->print(&Apache::loncommon::bodytag(
 1094:                      'Create Users, Change User Privileges').'<h2>');
 1095:     my $syspriv='';
 1096:     my $dompriv='';
 1097:     my $coursepriv='';
 1098:     my ($rdummy,$roledef)=
 1099: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
 1100: # ------------------------------------------------------- Does this role exist?
 1101:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
 1102: 	$r->print(&mt('Existing Role').' "');
 1103: # ------------------------------------------------- Get current role privileges
 1104: 	($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
 1105:     } else {
 1106: 	$r->print(&mt('New Role').' "');
 1107: 	$roledef='';
 1108:     }
 1109:     $r->print($rolename.'"</h2>');
 1110: # ------------------------------------------------------- What can be assigned?
 1111:     my %full=();
 1112:     my %courselevel=();
 1113:     my %courselevelcurrent=();
 1114:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
 1115: 	my ($priv,$restrict)=split(/\&/,$_);
 1116:         unless ($restrict) { $restrict='F'; }
 1117:         $courselevel{$priv}=$restrict;
 1118:         if ($coursepriv=~/\:$priv/) {
 1119: 	    $courselevelcurrent{$priv}=1;
 1120: 	}
 1121: 	$full{$priv}=1;
 1122:     }
 1123:     my %domainlevel=();
 1124:     my %domainlevelcurrent=();
 1125:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
 1126: 	my ($priv,$restrict)=split(/\&/,$_);
 1127:         unless ($restrict) { $restrict='F'; }
 1128:         $domainlevel{$priv}=$restrict;
 1129:         if ($dompriv=~/\:$priv/) {
 1130: 	    $domainlevelcurrent{$priv}=1;
 1131: 	}
 1132: 	$full{$priv}=1;
 1133:     }
 1134:     my %systemlevel=();
 1135:     my %systemlevelcurrent=();
 1136:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
 1137: 	my ($priv,$restrict)=split(/\&/,$_);
 1138:         unless ($restrict) { $restrict='F'; }
 1139:         $systemlevel{$priv}=$restrict;
 1140:         if ($syspriv=~/\:$priv/) {
 1141: 	    $systemlevelcurrent{$priv}=1;
 1142: 	}
 1143: 	$full{$priv}=1;
 1144:     }
 1145:     my %lt=&Apache::lonlocal::texthash(
 1146: 		    'prv'  => "Privilege",
 1147: 		    'crl'  => "Course Level",
 1148:                     'dml'  => "Domain Level",
 1149:                     'ssl'  => "System Level"
 1150: 				       );
 1151:     $r->print(<<ENDCCF);
 1152: <form method="post">
 1153: <input type="hidden" name="phase" value="set_custom_roles" />
 1154: <input type="hidden" name="rolename" value="$rolename" />
 1155: <table border="2">
 1156: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
 1157: <th>$lt{'ssl'}</th></tr>
 1158: ENDCCF
 1159:     foreach (sort keys %full) {
 1160: 	$r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
 1161:     ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
 1162:     ($courselevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
 1163:     '</td><td>'.
 1164:     ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
 1165:     ($domainlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
 1166:     '</td><td>'.
 1167:     ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
 1168:     ($systemlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
 1169:     '</td></tr>');
 1170:     }
 1171:     $r->print(
 1172:    '<table><input type="submit" value="'.&mt('Define Role').'" /></form></body></html>');
 1173: }
 1174: 
 1175: # ---------------------------------------------------------- Call to definerole
 1176: sub set_custom_role {
 1177:     my $r=shift;
 1178: 
 1179:     my $rolename=$ENV{'form.rolename'};
 1180: 
 1181:     $rolename=~s/[^A-Za-z0-9]//gs;
 1182: 
 1183:     unless ($rolename) {
 1184: 	&print_username_entry_form($r);
 1185:         return;
 1186:     }
 1187: 
 1188:     $r->print(&Apache::loncommon::bodytag(
 1189:                      'Create Users, Change User Privileges').'<h2>');
 1190:     my ($rdummy,$roledef)=
 1191: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
 1192: # ------------------------------------------------------- Does this role exist?
 1193:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
 1194: 	$r->print(&mt('Existing Role').' "');
 1195:     } else {
 1196: 	$r->print(&mt('New Role').' "');
 1197: 	$roledef='';
 1198:     }
 1199:     $r->print($rolename.'"</h2>');
 1200: # ------------------------------------------------------- What can be assigned?
 1201:     my $sysrole='';
 1202:     my $domrole='';
 1203:     my $courole='';
 1204: 
 1205:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
 1206: 	my ($priv,$restrict)=split(/\&/,$_);
 1207:         unless ($restrict) { $restrict=''; }
 1208:         if ($ENV{'form.'.$priv.':c'}) {
 1209: 	    $courole.=':'.$_;
 1210: 	}
 1211:     }
 1212: 
 1213:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
 1214: 	my ($priv,$restrict)=split(/\&/,$_);
 1215:         unless ($restrict) { $restrict=''; }
 1216:         if ($ENV{'form.'.$priv.':d'}) {
 1217: 	    $domrole.=':'.$_;
 1218: 	}
 1219:     }
 1220: 
 1221:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
 1222: 	my ($priv,$restrict)=split(/\&/,$_);
 1223:         unless ($restrict) { $restrict=''; }
 1224:         if ($ENV{'form.'.$priv.':s'}) {
 1225: 	    $sysrole.=':'.$_;
 1226: 	}
 1227:     }
 1228:     $r->print('<br />Defining Role: '.
 1229: 	   &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
 1230:     if ($ENV{'request.course.id'}) {
 1231:         my $url='/'.$ENV{'request.course.id'};
 1232:         $url=~s/\_/\//g;
 1233: 	$r->print('<br />'.&mt('Assigning Role to Self').': '.
 1234: 	      &Apache::lonnet::assigncustomrole($ENV{'user.domain'},
 1235: 						$ENV{'user.name'},
 1236: 						$url,
 1237: 						$ENV{'user.domain'},
 1238: 						$ENV{'user.name'},
 1239: 						$rolename));
 1240:     }
 1241:     $r->print('</body></html>');
 1242: }
 1243: 
 1244: # ================================================================ Main Handler
 1245: sub handler {
 1246:     my $r = shift;
 1247: 
 1248:     if ($r->header_only) {
 1249:        &Apache::loncommon::content_type($r,'text/html');
 1250:        $r->send_http_header;
 1251:        return OK;
 1252:     }
 1253: 
 1254:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
 1255:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
 1256:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
 1257:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
 1258:         (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
 1259:         (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
 1260:        &Apache::loncommon::content_type($r,'text/html');
 1261:        $r->send_http_header;
 1262:        unless ($ENV{'form.phase'}) {
 1263: 	   &print_username_entry_form($r);
 1264:        }
 1265:        if ($ENV{'form.phase'} eq 'get_user_info') {
 1266:            &print_user_modification_page($r);
 1267:        } elsif ($ENV{'form.phase'} eq 'update_user_data') {
 1268:            &update_user_data($r);
 1269:        } elsif ($ENV{'form.phase'} eq 'selected_custom_edit') {
 1270:            &custom_role_editor($r);
 1271:        } elsif ($ENV{'form.phase'} eq 'set_custom_roles') {
 1272: 	   &set_custom_role($r);
 1273:        }
 1274:    } else {
 1275:       $ENV{'user.error.msg'}=
 1276:         "/adm/createuser:mau:0:0:Cannot modify user data";
 1277:       return HTTP_NOT_ACCEPTABLE; 
 1278:    }
 1279:    return OK;
 1280: } 
 1281: 
 1282: #-------------------------------------------------- functions for &phase_two
 1283: sub course_level_table {
 1284:     my %inccourses = @_;
 1285:     my $table = '';
 1286: # Custom Roles?
 1287: 
 1288:     my %customroles=&my_custom_roles();
 1289: 
 1290:     foreach (sort( keys(%inccourses))) {
 1291: 	my $thiscourse=$_;
 1292: 	my $protectedcourse=$_;
 1293: 	$thiscourse=~s:_:/:g;
 1294: 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
 1295: 	my $area=$coursedata{'description'};
 1296: 	if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
 1297: 	my $bgcol=$thiscourse;
 1298: 	$bgcol=~s/[^7-9a-e]//g;
 1299: 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
 1300: 	foreach  ('st','ta','ep','ad','in','cc') {
 1301: 	    if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
 1302: 		my $plrole=&Apache::lonnet::plaintext($_);
 1303: 		$table .= <<ENDEXTENT;
 1304: <tr bgcolor="#$bgcol">
 1305: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
 1306: <td>$plrole</td>
 1307: <td>$area</td>
 1308: ENDEXTENT
 1309: 	        if ($_ ne 'cc') {
 1310: 		    $table .= <<ENDSECTION;
 1311: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
 1312: ENDSECTION
 1313:                 } else { 
 1314: 		    $table .= <<ENDSECTION;
 1315: <td>&nbsp</td> 
 1316: ENDSECTION
 1317:                 }
 1318: 		my %lt=&Apache::lonlocal::texthash(
 1319:                                'ssd'  => "Set Start Date",
 1320:                                'sed'  => "Set End Date"
 1321: 						   );
 1322: 		$table .= <<ENDTIMEENTRY;
 1323: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
 1324: <a href=
 1325: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
 1326: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
 1327: <a href=
 1328: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
 1329: ENDTIMEENTRY
 1330:                 $table.= "</tr>\n";
 1331:             }
 1332:         }
 1333:         foreach (sort keys %customroles) {
 1334: 	    if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
 1335: 		my $plrole=$_;
 1336:                 my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}.
 1337: 		    '_'.$ENV{'user.name'}.'_'.$plrole;
 1338: 		my %lt=&Apache::lonlocal::texthash(
 1339:                                'ssd'  => "Set Start Date",
 1340:                                'sed'  => "Set End Date"
 1341: 						   );
 1342: 		$table .= <<ENDENTRY;
 1343: <tr bgcolor="#$bgcol">
 1344: <td><input type="checkbox" name="act_$customrole"></td>
 1345: <td>$plrole</td>
 1346: <td>$area</td>
 1347: <td><input type="text" size="5" name="sec_$customrole"></td>
 1348: <td><input type=hidden name="start_$customrole" value=''>
 1349: <a href=
 1350: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
 1351: <td><input type=hidden name="end_$customrole" value=''>
 1352: <a href=
 1353: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td></tr>
 1354: ENDENTRY
 1355:            }
 1356: 	}
 1357:     }
 1358:     return '' if ($table eq ''); # return nothing if there is nothing 
 1359:                                  # in the table
 1360:     my %lt=&Apache::lonlocal::texthash(
 1361: 		    'crl'  => "Course Level",
 1362:                     'act'  => "Activate",
 1363:                     'rol'  => "Role",
 1364:                     'ext'  => "Extent",
 1365:                     'grs'  => "Group/Section",
 1366:                     'sta'  => "Start",
 1367:                     'end'  => "End"
 1368: 				       );
 1369:     my $result = <<ENDTABLE;
 1370: <h4>$lt{'crl'}</h4>
 1371: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
 1372: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
 1373: $table
 1374: </table>
 1375: ENDTABLE
 1376:     return $result;
 1377: }
 1378: #---------------------------------------------- end functions for &phase_two
 1379: 
 1380: #--------------------------------- functions for &phase_two and &phase_three
 1381: 
 1382: #--------------------------end of functions for &phase_two and &phase_three
 1383: 
 1384: 1;
 1385: __END__
 1386: 
 1387: 

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