File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.74: download - view: text, annotated - select for diffs
Tue Dec 16 14:15:12 2003 UTC (20 years, 5 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Bug 2505 fixed. I made a stupid typo in a few places.

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

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