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

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

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