File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.43: download - view: text, annotated - select for diffs
Thu Oct 3 14:56:48 2002 UTC (21 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #599

    1: # The LearningOnline Network with CAPA
    2: # Create a user
    3: #
    4: # $Id: loncreateuser.pm,v 1.43 2002/10/03 14:56:48 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: # (Create a course
   29: # (My Desk
   30: #
   31: # (Internal Server Error Handler
   32: #
   33: # (Login Screen
   34: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
   35: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
   36: #
   37: # YEAR=2001
   38: # 3/1/1 Gerd Kortemeyer)
   39: #
   40: # 3/1 Gerd Kortemeyer)
   41: #
   42: # 2/14 Gerd Kortemeyer)
   43: #
   44: # 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17,3/24,04/12 Gerd Kortemeyer
   45: # April Guy Albertelli
   46: # 05/10,10/16 Gerd Kortemeyer 
   47: # 11/12,11/13,11/15 Scott Harrison
   48: # 02/11/02 Matthew Hall
   49: #
   50: # $Id: loncreateuser.pm,v 1.43 2002/10/03 14:56:48 www Exp $
   51: ###
   52: 
   53: package Apache::loncreateuser;
   54: 
   55: use strict;
   56: use Apache::Constants qw(:common :http);
   57: use Apache::lonnet;
   58: 
   59: my $loginscript; # piece of javascript used in two separate instances
   60: my $generalrule;
   61: my $authformnop;
   62: my $authformkrb;
   63: my $authformint;
   64: my $authformfsys;
   65: my $authformloc;
   66: 
   67: BEGIN {
   68:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
   69:     my $krbdefdom=$1;
   70:     $krbdefdom=~tr/a-z/A-Z/;
   71:     my %param = ( formname => 'document.cu',
   72:                   kerb_def_dom => $krbdefdom 
   73:                   );
   74:     $loginscript  = &Apache::loncommon::authform_header(%param);
   75:     $generalrule  = &Apache::loncommon::authform_authorwarning(%param);
   76:     $authformnop  = &Apache::loncommon::authform_nochange(%param);
   77:     $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
   78:     $authformint  = &Apache::loncommon::authform_internal(%param);
   79:     $authformfsys = &Apache::loncommon::authform_filesystem(%param);
   80:     $authformloc  = &Apache::loncommon::authform_local(%param);
   81: }
   82: 
   83: 
   84: 
   85: # ==================================================== Figure out author access
   86: 
   87: sub authorpriv {
   88:     my ($auname,$audom)=@_;
   89:     if (($auname ne $ENV{'user.name'}) ||
   90:         (($audom ne $ENV{'user.domain'}) &&
   91:          ($audom ne $ENV{'request.role.domain'}))) { return ''; }
   92:     unless (&Apache::lonnet::allowed('cca',$audom)) { return ''; }
   93:     return 1;
   94: }
   95: 
   96: # =================================================================== Phase one
   97: 
   98: sub print_username_entry_form {
   99:     my $r=shift;
  100:     my $defdom=$ENV{'request.role.domain'};
  101:     my @domains = &Apache::loncommon::get_domains();
  102:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  103:     my $bodytag =&Apache::loncommon::bodytag(
  104:                                   'Create Users, Change User Privileges');
  105:     $r->print(<<"ENDDOCUMENT");
  106: <html>
  107: <head>
  108: <title>The LearningOnline Network with CAPA</title>
  109: </head>
  110: $bodytag
  111: <form action="/adm/createuser" method="post">
  112: <input type="hidden" name="phase" value="get_user_info">
  113: <p>
  114: <table>
  115: <tr><td>Username:</td><td><input type="text" size="15" name="ccuname">
  116: </td></tr><tr><td>
  117: Domain:</td><td>$domform</td></tr>
  118: </table> 
  119: </p>
  120: <input type="submit" value="Continue">
  121: </form>
  122: </body>
  123: </html>
  124: ENDDOCUMENT
  125: }
  126: 
  127: # =================================================================== Phase two
  128: sub print_user_modification_page {
  129:     my $r=shift;
  130:     my $ccuname=$ENV{'form.ccuname'};
  131:     my $ccdomain=$ENV{'form.ccdomain'};
  132: 
  133:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
  134:     my $krbdefdom=$1;
  135:     $krbdefdom=~tr/a-z/A-Z/;
  136:     my %param = ( formname => 'document.cu',
  137:                   kerb_def_dom => $krbdefdom 
  138:                   );
  139:     $loginscript  = &Apache::loncommon::authform_header(%param);
  140: 
  141:     my $defdom=$ENV{'request.role.domain'};
  142: 
  143:     $ccuname=~s/\W//g;
  144:     $ccdomain=~s/\W//g;
  145:     my $dochead =<<"ENDDOCHEAD";
  146: <html>
  147: <head>
  148: <title>The LearningOnline Network with CAPA</title>
  149: <script type="text/javascript" language="Javascript">
  150: 
  151:     function pclose() {
  152:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  153:                  "height=350,width=350,scrollbars=no,menubar=no");
  154:         parmwin.close();
  155:     }
  156: 
  157:     function pjump(type,dis,value,marker,ret,call) {
  158:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  159:                  +"&value="+escape(value)+"&marker="+escape(marker)
  160:                  +"&return="+escape(ret)
  161:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
  162:                  "height=350,width=350,scrollbars=no,menubar=no");
  163: 
  164:     }
  165: 
  166:     function dateset() {
  167:         eval("document.cu."+document.cu.pres_marker.value+
  168:             ".value=document.cu.pres_value.value");
  169:         pclose();
  170:     }
  171: 
  172: </script>
  173: </head>
  174: ENDDOCHEAD
  175:     $r->print(&Apache::loncommon::bodytag(
  176:                                      'Create Users, Change User Privileges'));
  177:     my $forminfo =<<"ENDFORMINFO";
  178: <form action="/adm/createuser" method="post" name="cu">
  179: <input type="hidden" name="phase"       value="update_user_data">
  180: <input type="hidden" name="ccuname"     value="$ccuname">
  181: <input type="hidden" name="ccdomain"    value="$ccdomain">
  182: <input type="hidden" name="pres_value"  value="" >
  183: <input type="hidden" name="pres_type"   value="" >
  184: <input type="hidden" name="pres_marker" value="" >
  185: ENDFORMINFO
  186:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
  187:     my %incdomains; 
  188:     my %inccourses;
  189:     foreach (%Apache::lonnet::hostdom) {
  190:        $incdomains{$_}=1;
  191:     }
  192:     foreach (keys(%ENV)) {
  193: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
  194: 	    $inccourses{$1.'_'.$2}=1;
  195:         }
  196:     }
  197:     if ($uhome eq 'no_host') {
  198:         my $home_server_list=
  199:             '<option value="default" selected>default</option>'."\n".
  200:                 &Apache::loncommon::home_server_option_list($ccdomain);
  201:         
  202: 	$r->print(<<ENDNEWUSER);
  203: $dochead
  204: <h1>Create New User</h1>
  205: $forminfo
  206: <h2>New user "$ccuname" in domain $ccdomain</h2>
  207: <script type="text/javascript" language="Javascript">
  208: $loginscript
  209: </script>
  210: <input type='hidden' name='makeuser' value='1' />
  211: <h3>Personal Data</h3>
  212: <p>
  213: <table>
  214: <tr><td>First Name  </td>
  215:     <td><input type='text' name='cfirst'  size='15' /></td></tr>
  216: <tr><td>Middle Name </td> 
  217:     <td><input type='text' name='cmiddle' size='15' /></td></tr>
  218: <tr><td>Last Name   </td>
  219:     <td><input type='text' name='clast'   size='15' /></td></tr>
  220: <tr><td>Generation  </td>
  221:     <td><input type='text' name='cgen'    size='5'  /></td></tr>
  222: </table>
  223: ID/Student Number <input type='text' name='cstid'   size='15' /></p>
  224: Home Server: <select name="hserver" size="1"> $home_server_list </select>
  225: <hr />
  226: <h3>Login Data</h3>
  227: <p>$generalrule </p>
  228: <p>$authformkrb </p>
  229: <p>$authformint </p>
  230: <p>$authformfsys</p>
  231: <p>$authformloc </p>
  232: ENDNEWUSER
  233:     } else { # user already exists
  234: 	$r->print(<<ENDCHANGEUSER);
  235: $dochead
  236: <h1>Change User Privileges</h1>
  237: $forminfo
  238: <h2>User "$ccuname" in domain $ccdomain </h2>
  239: ENDCHANGEUSER
  240:         # Get the users information
  241:         my %userenv = &Apache::lonnet::get('environment',
  242:                           ['firstname','middlename','lastname','generation'],
  243:                           $ccdomain,$ccuname);
  244:         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
  245:         $r->print(<<END);
  246: <hr />
  247: <table border="2">
  248: <tr>
  249: <th>first name</th><th>middle name</th><th>last name</th><th>generation</th>
  250: </tr>
  251: <tr>
  252: END
  253:         foreach ('firstname','middlename','lastname','generation') {
  254:            if (&Apache::lonnet::allowed('mau',$ccdomain)) {
  255:               $r->print(<<"END");            
  256: <td><input type="text" name="c$_" value="$userenv{$_}" size="15"/></td>
  257: END
  258:            } else {
  259:                $r->print('<td>'.$userenv{$_}.'</td>');
  260:            }
  261:         }
  262:         $r->print(<<END);
  263: </tr>
  264: </table>
  265: END
  266:         # Build up table of user roles to allow revocation of a role.
  267:         my ($tmp) = keys(%rolesdump);
  268:         unless ($tmp =~ /^(con_lost|error)/i) {
  269:            my $now=time;
  270:            $r->print(<<END);
  271: <hr />
  272: <h3>Revoke Existing Roles</h3>
  273: <table border=2>
  274: <tr><th>Revoke</th><th>Role</th><th>Extent</th><th>Start</th><th>End</th>
  275: END
  276: 	   foreach my $area (keys(%rolesdump)) {
  277:                next if ($area =~ /^rolesdef/);
  278:                my $role = $rolesdump{$area};
  279:                my $thisrole=$area;
  280:                $area =~ s/\_\w\w$//;
  281:                my ($role_code,$role_end_time,$role_start_time) = 
  282:                    split(/_/,$role);
  283:                my $bgcol='ffffff';
  284:                my $allowed=0;
  285:                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
  286:                    my %coursedata=
  287:                        &Apache::lonnet::coursedescription($1.'_'.$2);
  288:                    my $carea='Course: '.$coursedata{'description'};
  289:                    $inccourses{$1.'_'.$2}=1;
  290:                    if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) {
  291:                        $allowed=1;
  292:                    }
  293:                    # Compute the background color based on $area
  294:                    $bgcol=$1.'_'.$2;
  295:                    $bgcol=~s/[^8-9b-e]//g;
  296:                    $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
  297:                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
  298:                        $carea.='<br>Section/Group: '.$3;
  299:                    }
  300:                    $area=$carea;
  301:                } else {
  302:                    # Determine if current user is able to revoke privileges
  303:                    if ($area=~ /^\/(\w+)\//) {
  304:                        if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
  305:                            $allowed=1;
  306:                        }
  307:                    } else {
  308:                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
  309:                            $allowed=1;
  310:                        }
  311:                    }
  312:                }
  313:                if ($role_code eq 'ca') {
  314:                    $area=~/\/(\w+)\/(\w+)/;
  315: 		   if (&authorpriv($2,$1)) {
  316: 		       $allowed=1;
  317:                    } else {
  318:                        $allowed=0;
  319:                    }
  320:                }
  321:                my $row = '';
  322:                $row.='<tr bgcolor=#"'.$bgcol.'"><td>';
  323:                my $active=1;
  324:                $active=0 if (($role_end_time) && ($now>$role_end_time));
  325:                if (($active) && ($allowed)) {
  326:                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
  327:                } else {
  328:                    $row.='&nbsp;';
  329:                }
  330:                $row.= '</td><td>'.&Apache::lonnet::plaintext($role_code).
  331:                       '</td><td>'.$area.
  332:                       '</td><td>'.($role_start_time?localtime($role_start_time)
  333:                                                    : '&nbsp;' ).
  334:                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
  335:                                                    : '&nbsp;' )
  336:                       ."</td></tr>\n";
  337:                $r->print($row);
  338:            } # end of foreach        (table building loop)
  339: 	   $r->print('</table>');
  340:         }  # End of unless
  341: 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
  342: 	if ($currentauth=~/^krb(4|5):/) {
  343: 	    $currentauth=~/^krb(4|5):(.*)/;
  344: 	    my $krbdefdom2=$1;
  345:             my %param = ( formname => 'document.cu',
  346:                           kerb_def_dom => $krbdefdom 
  347:                           );
  348:             $loginscript  = &Apache::loncommon::authform_header(%param);
  349: 	}
  350: 	# Check for a bad authentication type
  351:         unless ($currentauth=~/^krb(4|5):/ or
  352: 		$currentauth=~/^unix:/ or
  353: 		$currentauth=~/^internal:/ or
  354: 		$currentauth=~/^localauth:/
  355: 		) { # bad authentication scheme
  356: 	    if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  357: 		$r->print(<<ENDBADAUTH);
  358: <hr />
  359: <script type="text/javascript" language="Javascript">
  360: $loginscript
  361: </script>
  362: <font color='#ff0000'>ERROR:</font>
  363: This user has an unrecognized authentication scheme ($currentauth).
  364: Please specify login data below.
  365: <h3>Login Data</h3>
  366: <p>$generalrule</p>
  367: <p>$authformkrb</p>
  368: <p>$authformint</p>
  369: <p>$authformfsys</p>
  370: <p>$authformloc</p>
  371: ENDBADAUTH
  372:             } else { 
  373:                 # This user is not allowed to modify the users 
  374:                 # authentication scheme, so just notify them of the problem
  375: 		$r->print(<<ENDBADAUTH);
  376: <hr />
  377: <script type="text/javascript" language="Javascript">
  378: $loginscript
  379: </script>
  380: <font color="#ff0000"> ERROR: </font>
  381: This user has an unrecognized authentication scheme ($currentauth).
  382: Please alert a domain coordinator of this situation.
  383: <hr />
  384: ENDBADAUTH
  385:             }
  386:         } else { # Authentication type is valid
  387: 	    my $authformcurrent='';
  388: 	    my $authform_other='';
  389: 	    if ($currentauth=~/^krb(4|5):/) {
  390: 		$authformcurrent=$authformkrb;
  391: 		$authform_other="<p>$authformint</p>\n".
  392:                     "<p>$authformfsys</p><p>$authformloc</p>";
  393: 	    }
  394: 	    elsif ($currentauth=~/^internal:/) {
  395: 		$authformcurrent=$authformint;
  396: 		$authform_other="<p>$authformkrb</p>".
  397:                     "<p>$authformfsys</p><p>$authformloc</p>";
  398: 	    }
  399: 	    elsif ($currentauth=~/^unix:/) {
  400: 		$authformcurrent=$authformfsys;
  401: 		$authform_other="<p>$authformkrb</p>".
  402:                     "<p>$authformint</p><p>$authformloc;</p>";
  403: 	    }
  404: 	    elsif ($currentauth=~/^localauth:/) {
  405: 		$authformcurrent=$authformloc;
  406: 		$authform_other="<p>$authformkrb</p>".
  407:                     "<p>$authformint</p><p>$authformfsys</p>";
  408: 	    }
  409: 	    $authformcurrent=<<ENDCURRENTAUTH;
  410: <table border='1'>
  411: <tr>
  412: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
  413: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
  414: </tr>
  415: <tr><td bgcolor='#cbbcbb'>$authformcurrent</td>
  416: <td bgcolor='#cbbcbb'>Changing this value will overwrite existing authentication for the user; you should notify the user of this change.</td></tr>
  417: </table>
  418: ENDCURRENTAUTH
  419:             if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  420: 		# Current user has login modification privileges
  421: 		$r->print(<<ENDOTHERAUTHS);
  422: <hr />
  423: <script type="text/javascript" language="Javascript">
  424: $loginscript
  425: </script>
  426: <h3>Change Current Login Data</h3>
  427: <p>$generalrule</p>
  428: <p>$authformnop</p>
  429: <p>$authformcurrent</p>
  430: <h3>Enter New Login Data</h3>
  431: $authform_other
  432: ENDOTHERAUTHS
  433:             }
  434:         }  ## End of "check for bad authentication type" logic
  435:     } ## End of new user/old user logic
  436:     $r->print('<hr /><h3>Add Roles</h3>');
  437: #
  438: # Co-Author
  439: # 
  440:     if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'})) {
  441: 	my $cuname=$ENV{'user.name'};
  442:         my $cudom=$ENV{'request.role.domain'};
  443:        $r->print(<<ENDCOAUTH);
  444: <h4>Construction Space</h4>
  445: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
  446: <th>Start</th><th>End</th></tr>
  447: <tr>
  448: <td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
  449: <td>Co-Author</td>
  450: <td>$cudom\_$cuname</td>
  451: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
  452: <a href=
  453: "javascript:pjump('date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset')">Set Start Date</a></td>
  454: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
  455: <a href=
  456: "javascript:pjump('date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset')">Set End Date</a></td>
  457: </tr>
  458: </table>
  459: ENDCOAUTH
  460:     }
  461: #
  462: # Domain level
  463: #
  464:     $r->print('<h4>Domain Level</h4>'.
  465:     '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
  466:     '<th>Start</th><th>End</th></tr>');
  467:     foreach ( sort( keys(%incdomains))) {
  468: 	my $thisdomain=$_;
  469:         foreach ('dc','li','dg','au') {
  470:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
  471:                my $plrole=&Apache::lonnet::plaintext($_);
  472:                $r->print(<<ENDDROW);
  473: <tr>
  474: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
  475: <td>$plrole</td>
  476: <td>$thisdomain</td>
  477: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
  478: <a href=
  479: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">Set Start Date</a></td>
  480: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
  481: <a href=
  482: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">Set End Date</a></td>
  483: </tr>
  484: ENDDROW
  485:             }
  486:         } 
  487:     }
  488:     $r->print('</table>');
  489: #
  490: # Course level
  491: #
  492:     $r->print(&course_level_table(%inccourses));
  493:     $r->print("<hr /><input type=submit value=\"Modify User\">\n");
  494:     $r->print("</form></body></html>");
  495: }
  496: 
  497: # ================================================================= Phase Three
  498: sub update_user_data {
  499:     my $r=shift;
  500:     my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
  501:                                           $ENV{'form.ccdomain'});
  502:     # Error messages
  503:     my $error     = '<font color="#ff0000">Error:</font>';
  504:     my $end       = '</body></html>';
  505:     # Print header
  506:     $r->print(<<ENDTHREEHEAD);
  507: <html>
  508: <head>
  509: <title>The LearningOnline Network with CAPA</title>
  510: </head>
  511: ENDTHREEHEAD
  512:     my $title;
  513:     if (exists($ENV{'form.makeuser'})) {
  514: 	$title='Set Privileges for New User';
  515:     } else {
  516:         $title='Modify User Privileges';
  517:     }
  518:     $r->print(&Apache::loncommon::bodytag($title));
  519:     # Check Inputs
  520:     if (! $ENV{'form.ccuname'} ) {
  521: 	$r->print($error.'No login name specified.'.$end);
  522: 	return;
  523:     }
  524:     if (  $ENV{'form.ccuname'}  =~/\W/) {
  525: 	$r->print($error.'Invalid login name.  '.
  526: 		  'Only letters, numbers, and underscores are valid.'.
  527: 		  $end);
  528: 	return;
  529:     }
  530:     if (! $ENV{'form.ccdomain'}       ) {
  531: 	$r->print($error.'No domain specified.'.$end);
  532: 	return;
  533:     }
  534:     if (  $ENV{'form.ccdomain'} =~/\W/) {
  535: 	$r->print($error.'Invalid domain name.  '.
  536: 		  'Only letters, numbers, and underscores are valid.'.
  537: 		  $end);
  538: 	return;
  539:     }
  540:     if (! exists($ENV{'form.makeuser'})) {
  541:         # Modifying an existing user, so check the validity of the name
  542:         if ($uhome eq 'no_host') {
  543:             $r->print($error.'Unable to determine home server for '.
  544:                       $ENV{'form.ccuname'}.' in domain '.
  545:                       $ENV{'form.ccdomain'}.'.');
  546:             return;
  547:         }
  548:     }
  549:     # Determine authentication method and password for the user being modified
  550:     my $amode='';
  551:     my $genpwd='';
  552:     if ($ENV{'form.login'} eq 'krb') {
  553: 	$amode='krb';
  554: 	$amode.=$ENV{'form.krbver'};
  555: 	$genpwd=$ENV{'form.krbarg'};
  556:     } elsif ($ENV{'form.login'} eq 'int') {
  557: 	$amode='internal';
  558: 	$genpwd=$ENV{'form.intarg'};
  559:     } elsif ($ENV{'form.login'} eq 'fsys') {
  560: 	$amode='unix';
  561: 	$genpwd=$ENV{'form.fsysarg'};
  562:     } elsif ($ENV{'form.login'} eq 'loc') {
  563: 	$amode='localauth';
  564: 	$genpwd=$ENV{'form.locarg'};
  565: 	$genpwd=" " if (!$genpwd);
  566:     } elsif (($ENV{'form.login'} eq 'nochange') ||
  567:              ($ENV{'form.login'} eq ''        )) { 
  568:         # There is no need to tell the user we did not change what they
  569:         # did not ask us to change.
  570:         # If they are creating a new user but have not specified login
  571:         # information this will be caught below.
  572:     } else {
  573: 	    $r->print($error.'Invalid login mode or password'.$end);    
  574: 	    return;
  575:     }
  576:     if ($ENV{'form.makeuser'}) {
  577:         # Create a new user
  578: 	$r->print(<<ENDNEWUSERHEAD);
  579: <h3>Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  580: ENDNEWUSERHEAD
  581:         # Check for the authentication mode and password
  582:         if (! $amode || ! $genpwd) {
  583: 	    $r->print($error.'Invalid login mode or password'.$end);    
  584: 	    return;
  585: 	}
  586:         # Determine desired host
  587:         my $desiredhost = $ENV{'form.hserver'};
  588:         if (lc($desiredhost) eq 'default') {
  589:             $desiredhost = undef;
  590:         } else {
  591:             my %home_servers = &Apache::loncommon::get_library_servers
  592:                 ($ENV{'form.ccdomain'});  
  593:             if (! exists($home_servers{$desiredhost})) {
  594:                 $r->print($error.'Invalid home server specified');
  595:                 return;
  596:             }
  597:         }
  598: 	# Call modifyuser
  599: 	my $result = &Apache::lonnet::modifyuser
  600: 	    ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
  601:              $amode,$genpwd,$ENV{'form.cfirst'},
  602:              $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
  603:              undef,$desiredhost
  604: 	     );
  605: 	$r->print('Generating user: '.$result);
  606:         my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
  607:                                                $ENV{'form.ccdomain'});
  608:         $r->print('<br>Home server: '.$home.' '.
  609:                   $Apache::lonnet::libserv{$home});
  610:     } elsif (($ENV{'form.login'} ne 'nochange') &&
  611:              ($ENV{'form.login'} ne ''        )) {
  612: 	# Modify user privileges
  613: 	$r->print(<<ENDMODIFYUSERHEAD);
  614: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  615: ENDMODIFYUSERHEAD
  616:         if (! $amode || ! $genpwd) {
  617: 	    $r->print($error.'Invalid login mode or password'.$end);    
  618: 	    return;
  619: 	}
  620: 	# Only allow authentification modification if the person has authority
  621: 	if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
  622: 	    $r->print('Modifying authentication: '.
  623:                       &Apache::lonnet::modifyuserauth(
  624: 		       $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  625:                        $amode,$genpwd));
  626:             $r->print('<br>Home server: '.&Apache::lonnet::homeserver
  627: 		  ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
  628: 	} else {
  629: 	    # Okay, this is a non-fatal error.
  630: 	    $r->print($error.'You do not have the authority to modify '.
  631: 		      'this users authentification information.');    
  632: 	}
  633:     }
  634:     ##
  635:     if (! $ENV{'form.makeuser'} ) {
  636:         # Check for need to change
  637:         my %userenv = &Apache::lonnet::get
  638:             ('environment',['firstname','middlename','lastname','generation'],
  639:              $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  640:         my ($tmp) = keys(%userenv);
  641:         if ($tmp =~ /^(con_lost|error)/i) { 
  642:             %userenv = ();
  643:         }
  644:         # Check to see if we need to change user information
  645:         foreach ('firstname','middlename','lastname','generation') {
  646:             # Strip leading and trailing whitespace
  647:             $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
  648:         }
  649:         if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) && 
  650:             ($ENV{'form.cfirstname'}  ne $userenv{'firstname'}  ||
  651:              $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
  652:              $ENV{'form.clastname'}   ne $userenv{'lastname'}   ||
  653:              $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
  654:             # Make the change
  655:             my %changeHash;
  656:             $changeHash{'firstname'}  = $ENV{'form.cfirstname'};
  657:             $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
  658:             $changeHash{'lastname'}   = $ENV{'form.clastname'};
  659:             $changeHash{'generation'} = $ENV{'form.cgeneration'};
  660:             my $putresult = &Apache::lonnet::put
  661:                 ('environment',\%changeHash,
  662:                  $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  663:             if ($putresult eq 'ok') {
  664:             # Tell the user we changed the name
  665:                 $r->print(<<"END");
  666: <table border="2">
  667: <caption>User Information Changed</caption>
  668: <tr><th>&nbsp;</th>
  669:     <th>first</th>
  670:     <th>middle</th>
  671:     <th>last</th>
  672:     <th>generation</th></tr>
  673: <tr><td>Previous</td>
  674:     <td>$userenv{'firstname'}  </td>
  675:     <td>$userenv{'middlename'} </td>
  676:     <td>$userenv{'lastname'}   </td>
  677:     <td>$userenv{'generation'} </td></tr>
  678: <tr><td>Changed To</td>
  679:     <td>$ENV{'form.cfirstname'}  </td>
  680:     <td>$ENV{'form.cmiddlename'} </td>
  681:     <td>$ENV{'form.clastname'}   </td>
  682:     <td>$ENV{'form.cgeneration'} </td></tr>
  683: </table>
  684: END
  685:             } else { # error occurred
  686:                 $r->print("<h2>Unable to successfully change environment for ".
  687:                       $ENV{'form.ccuname'}." in domain ".
  688:                       $ENV{'form.ccdomain'}."</h2>");
  689:             }
  690:         }  else { # End of if ($ENV ... ) logic
  691:             # They did not want to change the users name but we can
  692:             # still tell them what the name is
  693:                 $r->print(<<"END");
  694: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  695: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
  696: <h4>Generation: $userenv{'generation'}</h4>
  697: END
  698:         }
  699:     }
  700:     ##
  701:     my $now=time;
  702:     $r->print('<h3>Modifying Roles</h3>');
  703:     foreach (keys (%ENV)) {
  704: 	next if (! $ENV{$_});
  705: 	# Revoke roles
  706: 	if ($_=~/^form\.rev/) {
  707: 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) {
  708: 	        $r->print('Revoking '.$2.' in '.$1.': '.
  709:                      &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
  710:                      $ENV{'form.ccuname'},$1,$2,$now).'<br>');
  711: 		if ($2 eq 'st') {
  712: 		    $1=~/^\/(\w+)\/(\w+)/;
  713: 		    my $cid=$1.'_'.$2;
  714: 		    $r->print('Drop from classlist: '.
  715: 			 &Apache::lonnet::critical('put:'.
  716:                              $ENV{'course.'.$cid.'.domain'}.':'.
  717: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  718:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  719:                              $ENV{'form.ccdomain'}).'='.
  720:                          &Apache::lonnet::escape($now.':'),
  721: 	                     $ENV{'course.'.$cid.'.home'}).'<br>');
  722: 		}
  723: 	    } 
  724: 	} elsif ($_=~/^form\.act/) {
  725: 	    if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
  726: 		# Activate roles for sections with 3 id numbers
  727: 		# set start, end times, and the url for the class
  728: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
  729: 			      $ENV{'form.start_'.$1.'_'.$2} : 
  730: 			      $now );
  731: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
  732: 			      $ENV{'form.end_'.$1.'_'.$2} :
  733: 			      0 );
  734: 		my $url='/'.$1.'/'.$2;
  735: 		if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
  736: 		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
  737: 		}
  738: 		# Assign the role and report it
  739: 		$r->print('Assigning: '.$3.' in '.$url.': '.
  740:                           &Apache::lonnet::assignrole(
  741:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  742:                               $url,$3,$end,$start).
  743: 			  '<br>');
  744: 		# Handle students differently
  745: 		if ($3 eq 'st') {
  746: 		    $url=~/^\/(\w+)\/(\w+)/;
  747: 		    my $cid=$1.'_'.$2;
  748: 		    $r->print('Add to classlist: '.
  749: 			      &Apache::lonnet::critical(
  750: 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
  751: 	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
  752:                                    &Apache::lonnet::escape(
  753:                                        $ENV{'form.ccuname'}.':'.
  754:                                        $ENV{'form.ccdomain'} ).'='.
  755:                                    &Apache::lonnet::escape($end.':'.$start),
  756: 				       $ENV{'course.'.$cid.'.home'})
  757: 			      .'<br>');
  758: 		}
  759: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
  760: 		# Activate roles for sections with two id numbers
  761: 		# set start, end times, and the url for the class
  762: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
  763: 			      $ENV{'form.start_'.$1.'_'.$2} : 
  764: 			      $now );
  765: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
  766: 			      $ENV{'form.end_'.$1.'_'.$2} :
  767: 			      0 );
  768: 		my $url='/'.$1.'/';
  769: 		# Assign the role and report it.
  770: 		$r->print('Assigning: '.$2.' in '.$url.': '.
  771:                           &Apache::lonnet::assignrole(
  772:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  773:                               $url,$2,$end,$start)
  774: 			  .'<br>');
  775: 	    }
  776: 	} 
  777:     } # End of foreach (keys(%ENV))
  778:     $r->print('</body></html>');
  779: }
  780: 
  781: # ================================================================ Main Handler
  782: sub handler {
  783:     my $r = shift;
  784: 
  785:     if ($r->header_only) {
  786:        $r->content_type('text/html');
  787:        $r->send_http_header;
  788:        return OK;
  789:     }
  790: 
  791:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
  792:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
  793:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
  794:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
  795:         (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
  796:         (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
  797:        $r->content_type('text/html');
  798:        $r->send_http_header;
  799:        unless ($ENV{'form.phase'}) {
  800: 	   &print_username_entry_form($r);
  801:        }
  802:        if ($ENV{'form.phase'} eq 'get_user_info') {
  803:            &print_user_modification_page($r);
  804:        } elsif ($ENV{'form.phase'} eq 'update_user_data') {
  805:            &update_user_data($r);
  806:        }
  807:    } else {
  808:       $ENV{'user.error.msg'}=
  809:         "/adm/createuser:mau:0:0:Cannot modify user data";
  810:       return HTTP_NOT_ACCEPTABLE; 
  811:    }
  812:    return OK;
  813: } 
  814: 
  815: #-------------------------------------------------- functions for &phase_two
  816: sub course_level_table {
  817:     my %inccourses = @_;
  818:     my $table = '';
  819:     foreach (sort( keys(%inccourses))) {
  820: 	my $thiscourse=$_;
  821: 	my $protectedcourse=$_;
  822: 	$thiscourse=~s:_:/:g;
  823: 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
  824: 	my $area=$coursedata{'description'};
  825: 	my $bgcol=$thiscourse;
  826: 	$bgcol=~s/[^8-9b-e]//g;
  827: 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
  828: 	foreach  ('st','ta','ep','ad','in','cc') {
  829: 	    if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
  830: 		my $plrole=&Apache::lonnet::plaintext($_);
  831: 		$table .= <<ENDEXTENT;
  832: <tr bgcolor="#$bgcol">
  833: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
  834: <td>$plrole</td>
  835: <td>$area</td>
  836: ENDEXTENT
  837: 	        if ($_ ne 'cc') {
  838: 		    $table .= <<ENDSECTION;
  839: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
  840: ENDSECTION
  841:                 } else { 
  842: 		    $table .= <<ENDSECTION;
  843: <td>&nbsp</td> 
  844: ENDSECTION
  845:                 }
  846: 		$table .= <<ENDTIMEENTRY;
  847: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
  848: <a href=
  849: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
  850: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
  851: <a href=
  852: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td>
  853: ENDTIMEENTRY
  854:                 $table.= "</tr>\n";
  855:             }
  856:         }
  857:     }
  858:     return '' if ($table eq ''); # return nothing if there is nothing 
  859:                                  # in the table
  860:     my $result = <<ENDTABLE;
  861: <h4>Course Level</h4>
  862: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
  863: <th>Group/Section</th><th>Start</th><th>End</th></tr>
  864: $table
  865: </table>
  866: ENDTABLE
  867:     return $result;
  868: }
  869: #---------------------------------------------- end functions for &phase_two
  870: 
  871: #--------------------------------- functions for &phase_two and &phase_three
  872: 
  873: #--------------------------end of functions for &phase_two and &phase_three
  874: 
  875: 1;
  876: __END__
  877: 
  878: 

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