File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.37: download - view: text, annotated - select for diffs
Wed Aug 7 18:04:35 2002 UTC (21 years, 10 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Bug 565 - user is no longer able to revoke co-author roles for construction
spaces other than their own.
Minor code simplification in places.  Actual comments added to explain
new code.

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

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