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

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

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