File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.77: download - view: text, annotated - select for diffs
Sat Jan 17 18:12:05 2004 UTC (20 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Missing "." generated garbage screen output.

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

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