Annotation of loncom/interface/loncreateuser.pm, revision 1.40

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

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