File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.84: download - view: text, annotated - select for diffs
Sat Jul 3 20:45:23 2004 UTC (19 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, HEAD
- updating help links
- add ability to not have FAQ link

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