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

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

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