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

1.20      harris41    1: # The LearningOnline Network with CAPA
1.1       www         2: # Create a user
                      3: #
1.25    ! matthew     4: # $Id: loncreateuser.pm,v 1.24 2002/02/08 19:40:42 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.25    ! matthew    50: # $Id: loncreateuser.pm,v 1.24 2002/02/08 19:40:42 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/;
                     71:     $authformnop=(<<END);
                     72: <p>
                     73: <input type=radio name=login value=nop checked='checked'
                     74: onClick="clicknop(this.form);">
                     75: Do not change login data
                     76: </p>
                     77: END
                     78:     $authformkrb=(<<END);
                     79: <p>
                     80: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
                     81: Kerberos authenticated with domain
                     82: <input type=text size=10 name=krbdom onChange="setkrb(this.form);">
                     83: </p>
                     84: END
                     85:     $authformint=(<<END);
                     86: <p>
                     87: <input type=radio name=login value=int onClick="clickint(this.form);"> 
                     88: Internally authenticated (with initial password 
                     89: <input type=text size=10 name=intpwd onChange="setint(this.form);">)
                     90: </p>
                     91: END
                     92:     $authformfsys=(<<END);
                     93: <p>
                     94: <input type=radio name=login value=fsys onClick="clickfsys(this.form);"> 
                     95: Filesystem authenticated (with initial password 
                     96: <input type=text size=10 name=fsyspwd onChange="setfsys(this.form);">)
                     97: </p>
                     98: END
                     99:     $authformloc=(<<END);
                    100: <p>
                    101: <input type=radio name=login value=loc onClick="clickloc(this.form);" />
                    102: Local Authentication with argument
                    103: <input type=text size=10 name=locarg onChange="setloc(this.form);" />
                    104: </p>
                    105: END
                    106:     $loginscript=(<<ENDLOGINSCRIPT);
                    107: <script>
                    108: function setkrb(vf) {
                    109:     if (vf.krbdom.value!='') {
                    110:        vf.login[0].checked=true;
                    111:        vf.krbdom.value=vf.krbdom.value.toUpperCase();
                    112:        vf.intpwd.value='';
                    113:        vf.fsyspwd.value='';
                    114:        vf.locarg.value='';
                    115:    }
                    116: }
                    117: 
                    118: function setint(vf) {
                    119:     if (vf.intpwd.value!='') {
                    120:        vf.login[1].checked=true;
                    121:        vf.krbdom.value='';
                    122:        vf.fsyspwd.value='';
                    123:        vf.locarg.value='';
                    124:    }
                    125: }
                    126: 
                    127: function setfsys(vf) {
                    128:     if (vf.fsyspwd.value!='') {
                    129:        vf.login[2].checked=true;
                    130:        vf.krbdom.value='';
                    131:        vf.intpwd.value='';
                    132:        vf.locarg.value='';
                    133:    }
                    134: }
                    135: 
                    136: function setloc(vf) {
                    137:     if (vf.locarg.value!='') {
                    138:        vf.login[3].checked=true;
                    139:        vf.krbdom.value='';
                    140:        vf.intpwd.value='';
                    141:        vf.fsyspwd.value='';
                    142:    }
                    143: }
                    144: 
                    145: function clicknop(vf) {
                    146:     vf.krbdom.value='';
                    147:     vf.intpwd.value='';
                    148:     vf.fsyspwd.value='';
                    149:     vf.locarg.value='';
                    150: }
                    151: 
                    152: function clickkrb(vf) {
                    153:     vf.krbdom.value='$krbdefdom';
                    154:     vf.intpwd.value='';
                    155:     vf.fsyspwd.value='';
                    156:     vf.locarg.value='';
                    157: }
                    158: 
                    159: function clickint(vf) {
                    160:     vf.krbdom.value='';
                    161:     vf.fsyspwd.value='';
                    162:     vf.locarg.value='';
                    163: }
                    164: 
                    165: function clickfsys(vf) {
                    166:     vf.krbdom.value='';
                    167:     vf.intpwd.value='';
                    168:     vf.locarg.value='';
                    169: }
                    170: 
                    171: function clickloc(vf) {
                    172:     vf.krbdom.value='';
                    173:     vf.intpwd.value='';
                    174:     vf.fsyspwd.value='';
                    175: }
                    176: </script>
                    177: ENDLOGINSCRIPT
                    178:     $generalrule=<<END;
                    179: <p>
                    180: <i>As a general rule, only authors or co-authors should be filesystem
                    181: authenticated (which allows access to the server filesystem).</i>
                    182: </p>
                    183: END
                    184: }
                    185: 
1.2       www       186: # =================================================================== Phase one
1.1       www       187: 
1.2       www       188: sub phase_one {
                    189:     my $r=shift;
                    190:     my $defdom=$ENV{'user.domain'};
1.1       www       191:     $r->print(<<ENDDOCUMENT);
                    192: <html>
                    193: <head>
                    194: <title>The LearningOnline Network with CAPA</title>
                    195: </head>
                    196: <body bgcolor="#FFFFFF">
                    197: <h1>Create User, Change User Privileges</h1>
1.2       www       198: <form action=/adm/createuser method=post>
                    199: <input type=hidden name=phase value=two>
                    200: Username: <input type=text size=15 name=ccuname><br>
                    201: Domain: <input type=text size=15 name=ccdomain value=$defdom><p>
                    202: <input type=submit value="Continue">
                    203: </form>
1.1       www       204: </body>
                    205: </html>
                    206: ENDDOCUMENT
1.2       www       207: }
                    208: 
                    209: # =================================================================== Phase two
                    210: 
                    211: sub phase_two {
                    212:     my $r=shift;
                    213:     my $ccuname=$ENV{'form.ccuname'};
                    214:     my $ccdomain=$ENV{'form.ccdomain'};
1.4       www       215: 
                    216:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                    217:     my $krbdefdom=$1;
                    218:     $krbdefdom=~tr/a-z/A-Z/;
                    219: 
                    220:     my $defdom=$ENV{'user.domain'};
                    221: 
1.2       www       222:     $ccuname=~s/\W//g;
                    223:     $ccdomain=~s/\W//g;
1.25    ! matthew   224:     my $dochead =<<"ENDDOCHEAD";
1.2       www       225: <html>
                    226: <head>
                    227: <title>The LearningOnline Network with CAPA</title>
1.3       www       228: <script>
                    229: 
                    230:     function pclose() {
                    231:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    232:                  "height=350,width=350,scrollbars=no,menubar=no");
                    233:         parmwin.close();
                    234:     }
                    235: 
                    236:     function pjump(type,dis,value,marker,ret,call) {
                    237:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
                    238:                  +"&value="+escape(value)+"&marker="+escape(marker)
                    239:                  +"&return="+escape(ret)
                    240:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
                    241:                  "height=350,width=350,scrollbars=no,menubar=no");
                    242: 
                    243:     }
                    244: 
                    245:     function dateset() {
                    246:         eval("document.cu."+document.cu.pres_marker.value+
                    247:             ".value=document.cu.pres_value.value");
                    248:         pclose();
                    249:     }
                    250: 
                    251: </script>
1.2       www       252: </head>
                    253: <body bgcolor="#FFFFFF">
1.25    ! matthew   254: <img align="right" src="/adm/lonIcons/lonlogos.gif">
        !           255: ENDDOCHEAD
        !           256:     my $forminfo =<<"ENDFORMINFO";
        !           257: <form action="/adm/createuser" method="post" name="cu">
        !           258: <input type="hidden" name="phase"       value="three">
        !           259: <input type="hidden" name="ccuname"     value="$ccuname">
        !           260: <input type="hidden" name="ccdomain"    value="$ccdomain">
        !           261: <input type="hidden" name="pres_value"  value="" >
        !           262: <input type="hidden" name="pres_type"   value="" >
        !           263: <input type="hidden" name="pres_marker" value="" >
        !           264: <input type="hidden" name="cuname"      value="$ccuname">
        !           265: <input type="hidden" name="cdomain"     value="$ccdomain">
        !           266: ENDFORMINFO
1.2       www       267:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
                    268:     my %incdomains; 
                    269:     my %inccourses;
1.24      matthew   270:     foreach (%Apache::lonnet::hostdom) {
1.13      www       271:        $incdomains{$_}=1;
1.24      matthew   272:     }
                    273:     foreach (keys(%ENV)) {
1.2       www       274: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
                    275: 	    $inccourses{$1.'_'.$2}=1;
                    276:         }
1.24      matthew   277:     }
1.2       www       278:     if ($uhome eq 'no_host') {
1.4       www       279: 	$r->print(<<ENDNUSER);
1.25    ! matthew   280: $dochead
        !           281: <h1>Create New User</h1>
        !           282: $forminfo
        !           283: <h2>New user "$ccuname" in domain $ccdomain</h2>
1.20      harris41  284: ENDNUSER
                    285: 	$r->print(<<ENDNUSER);
                    286: $loginscript
                    287: <input type='hidden' name='makeuser' value='1' />
1.4       www       288: <h3>Personal Data</h3>
1.25    ! matthew   289: <p>
        !           290: <table>
        !           291: <tr><td>First Name  </td>
        !           292:     <td><input type='text' name='cfirst'  size='15' /></td></tr>
        !           293: <tr><td>Middle Name </td> 
        !           294:     <td><input type='text' name='cmiddle' size='15' /></td></tr>
        !           295: <tr><td>Last Name   </td>
        !           296:     <td><input type='text' name='clast'   size='15' /></td></tr>
        !           297: <tr><td>Generation  </td>
        !           298:     <td><input type='text' name='cgen'    size='5'  /></td></tr>
        !           299: </table>
        !           300: ID/Student Number <input type='text' name='cstid'   size='15' /></p>
1.4       www       301: 
1.25    ! matthew   302: <hr />
1.4       www       303: 
                    304: <h3>Login Data</h3>
1.20      harris41  305: $generalrule
                    306: $authformkrb
                    307: $authformint
                    308: $authformfsys
                    309: $authformloc
1.4       www       310: ENDNUSER
1.25    ! matthew   311:     } else { # user already exists
        !           312: 	$r->print(<<ENDCHUSER);
        !           313: $dochead
        !           314: <h1>Change User Privileges</h1>
        !           315: $forminfo
        !           316: <h2>User "$ccuname" in domain $ccdomain </h2>
        !           317: ENDCHUSER
1.2       www       318:         my $rolesdump=&Apache::lonnet::reply(
                    319:                                   "dump:$ccdomain:$ccuname:roles",$uhome);
1.25    ! matthew   320:         # Build up table of user roles to allow revocation of a role.
1.2       www       321:         unless ($rolesdump eq 'con_lost') { 
                    322:            my $now=time;
                    323:            $r->print('<h4>Revoke Existing Roles</h4>'.
                    324:              '<table border=2><tr><th>Revoke</th><th>Role</th><th>Extent</th>'.
                    325: 		     '<th>Start</th><th>End</th>');
1.24      matthew   326: 	   foreach (split(/&/,$rolesdump)) {
1.2       www       327:              if ($_!~/^rolesdef\&/) {
                    328:               my ($area,$role)=split(/=/,$_);
                    329:               my $thisrole=$area;
                    330:               $area=~s/\_\w\w$//;
1.25    ! matthew   331:               my ($role_code,$role_end_time,$role_start_time)=split(/_/,$role);
1.3       www       332:               my $bgcol='ffffff';
1.2       www       333:               my $allows=0;
1.5       www       334:               if ($area=~/^\/(\w+)\/(\d\w+)/) {
1.2       www       335:                  my %coursedata=&Apache::lonnet::coursedescription($1.'_'.$2);
1.5       www       336:                  my $carea='Course: '.$coursedata{'description'};
1.2       www       337:                  $inccourses{$1.'_'.$2}=1;
1.25    ! matthew   338:                  if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) {
1.2       www       339: 		     $allows=1;
                    340:                  }
1.25    ! matthew   341: 		 # What follows is an odd computation.  It seems the value
        !           342: 		 # of the $area variable above is used to compute the 
        !           343: 		 # background color.  This makes sense, but I can't make 
        !           344: 		 # heads or tail of the computation at this point..
1.3       www       345:                  $bgcol=$1.'_'.$2;
                    346:                  $bgcol=~s/[^8-9b-e]//g;
                    347:                  $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.5       www       348:                  if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
                    349:                      $carea.='<br>Section/Group: '.$3;
                    350: 		 }
                    351:                  $area=$carea;
1.2       www       352: 	      } else {
1.7       www       353:                  if ($area=~/^\/(\w+)\//) {
1.25    ! matthew   354:                      if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.7       www       355: 			 $allows=1;
                    356:                      }
                    357:                  } else {
1.25    ! matthew   358:                      if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.2       www       359: 			 $allows=1;
                    360:                      }
                    361:                  }
                    362: 	      }
                    363: 
                    364:               my $active=1;
1.25    ! matthew   365:               if (($role_end_time) && ($now>$role_end_time)) { $active=0; }
        !           366:               $r->print('<tr bgcolor=#"'.$bgcol.'"><td>');
        !           367:               if (!($active) && ($allows)) {
        !           368: 		  $r->print('<input type=checkbox name="rev:'.$thisrole.'">');
1.2       www       369:               } else {
                    370:                   $r->print('&nbsp;');
                    371:               }
1.25    ! matthew   372:               $r->print('</td><td>'.&Apache::lonnet::plaintext($role_code).
1.2       www       373:                         '</td><td>'.$area.'</td><td>'.
1.25    ! matthew   374:                         ($role_start_time ? localtime($role_start_time)
        !           375:                                           : '&nbsp;' )
        !           376: 			.'</td><td>'.
        !           377:                         ($role_end_time   ? localtime($role_end_time)
        !           378:                                           : '&nbsp;' )
        !           379: 			."</td></tr>\n");
1.2       www       380: 	     }
1.24      matthew   381: 	   } 
1.2       www       382: 	   $r->print('</table>');
                    383:          }   
1.20      harris41  384: 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
                    385: 	if ($currentauth=~/^krb4:/) {
                    386: 	    $currentauth=~/^krb4:(.*)/;
                    387: 	    my $krbdefdom2=$1;
                    388: 	    $loginscript=~s/vf\.krbdom\.value='.*?';/vf.krbdom.value='$krbdefdom2';/;
                    389: 	}
1.25    ! matthew   390: 	# Here is where we'll have to check against the permissions of the
        !           391: 	# user attempting to modify this users data.  Only users with
        !           392: 	# MAU (Modify Authentication User) permissions should be able to 
        !           393: 	# make these changes.  I think a subroutine would be in order here.
1.20      harris41  394:         unless ($currentauth=~/^krb4:/ or
                    395: 		$currentauth=~/^unix:/ or
                    396: 		$currentauth=~/^internal:/ or
                    397: 		$currentauth=~/^localauth:/
                    398: 		) {
                    399: 	    $r->print(<<END);
1.21      harris41  400: <hr />
                    401: $loginscript
1.20      harris41  402: <font color='#ff0000'>ERROR:</font>
                    403: This user has an unrecognized authentication scheme ($currentauth).
                    404: Please specify login data below.
                    405: <h3>Login Data</h3>
                    406: $generalrule
                    407: $authformkrb
                    408: $authformint
                    409: $authformfsys
                    410: $authformloc
                    411: END
                    412:         }
                    413: 	else {
                    414: 	    my $authformcurrent='';
                    415: 	    my $authformother='';
                    416: 	    if ($currentauth=~/^krb4:/) {
                    417: 		$authformcurrent=$authformkrb;
                    418: 		$authformother=$authformint.$authformfsys.$authformloc;
1.21      harris41  419: 		# embarrassing script hack here
                    420: 		$loginscript=~s/login\[3\]/login\[4\]/; # loc
                    421: 		$loginscript=~s/login\[2\]/login\[3\]/; # fsys
                    422: 		$loginscript=~s/login\[1\]/login\[2\]/; # int
                    423: 		$loginscript=~s/login\[0\]/login\[1\]/; # krb4
1.20      harris41  424: 	    }
                    425: 	    elsif ($currentauth=~/^internal:/) {
                    426: 		$authformcurrent=$authformint;
                    427: 		$authformother=$authformkrb.$authformfsys.$authformloc;
1.21      harris41  428: 		# embarrassing script hack here
                    429: 		$loginscript=~s/login\[3\]/login\[4\]/; # loc
                    430: 		$loginscript=~s/login\[2\]/login\[3\]/; # fsys
                    431: 		$loginscript=~s/login\[1\]/login\[1\]/; # int
                    432: 		$loginscript=~s/login\[0\]/login\[2\]/; # krb4
1.20      harris41  433: 	    }
                    434: 	    elsif ($currentauth=~/^unix:/) {
                    435: 		$authformcurrent=$authformfsys;
                    436: 		$authformother=$authformkrb.$authformint.$authformloc;
1.21      harris41  437: 		# embarrassing script hack here
                    438: 		$loginscript=~s/login\[3\]/login\[4\]/; # loc
                    439: 		$loginscript=~s/login\[1\]/login\[3\]/; # int
                    440: 		$loginscript=~s/login\[2\]/login\[1\]/; # fsys
                    441: 		$loginscript=~s/login\[0\]/login\[2\]/; # krb4
1.20      harris41  442: 	    }
                    443: 	    elsif ($currentauth=~/^localauth:/) {
                    444: 		$authformcurrent=$authformloc;
                    445: 		$authformother=$authformkrb.$authformint.$authformfsys;
1.21      harris41  446: 		# embarrassing script hack here
                    447: 		$loginscript=~s/login\[3\]/login\[loc\]/; # loc
                    448: 		$loginscript=~s/login\[2\]/login\[4\]/; # fsys
                    449: 		$loginscript=~s/login\[1\]/login\[3\]/; # int
                    450: 		$loginscript=~s/login\[0\]/login\[2\]/; # krb4
                    451: 		$loginscript=~s/login\[loc\]/login\[1\]/; # loc
1.20      harris41  452: 	    }
                    453: 	    $authformcurrent=<<END;
                    454: <table border='1'>
                    455: <tr>
                    456: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
                    457: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
                    458: </tr>
                    459: <tr><td bgcolor='#cbbcbb'>$authformcurrent</td>
                    460: <td bgcolor='#cbbcbb'>Changing this value will overwrite existing authentication for the user; you should notify the user of this change.</td></tr>
                    461: </table>
                    462: END
                    463: 		$r->print(<<END);
1.21      harris41  464: <hr />
                    465: $loginscript
1.20      harris41  466: <h3>Change Current Login Data</h3>
                    467: $generalrule
                    468: $authformnop
                    469: $authformcurrent
                    470: <h3>Enter New Login Data</h3>
                    471: $authformother
                    472: END
1.25    ! matthew   473:         }
        !           474:     } ## End of new user/old user logic
1.20      harris41  475:     $r->print('<hr /><h3>Add Roles</h3>');
1.17      www       476: #
                    477: # Co-Author
                    478: # 
                    479: 
                    480:     if (&Apache::lonnet::allowed('cca',$ENV{'user.domain'})) {
                    481: 	my $cuname=$ENV{'user.name'};
                    482:         my $cudom=$ENV{'user.domain'};
                    483:        $r->print(<<ENDCOAUTH);
                    484: <h4>Construction Space</h4>
                    485: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
                    486: <th>Start</th><th>End</th></tr>
                    487: <tr>
                    488: <td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
                    489: <td>Co-Author</td>
                    490: <td>$cudom\_$cuname</td>
                    491: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
                    492: <a href=
                    493: "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>
                    494: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
                    495: <a href=
                    496: "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>
                    497: </tr>
                    498: </table>
                    499: ENDCOAUTH
                    500:     }
1.8       www       501: #
                    502: # Domain level
                    503: #
                    504:     $r->print('<h4>Domain Level</h4>'.
                    505:     '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
                    506:     '<th>Start</th><th>End</th></tr>');
1.24      matthew   507:     foreach ( sort( keys(%incdomains))) {
1.2       www       508: 	my $thisdomain=$_;
1.24      matthew   509:         foreach ('dc','li','dg','au') {
1.2       www       510:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8       www       511:                my $plrole=&Apache::lonnet::plaintext($_);
                    512:                $r->print(<<ENDDROW);
                    513: <tr>
                    514: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
                    515: <td>$plrole</td>
                    516: <td>$thisdomain</td>
                    517: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
                    518: <a href=
                    519: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">Set Start Date</a></td>
                    520: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
                    521: <a href=
                    522: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">Set End Date</a></td>
                    523: </tr>
                    524: ENDDROW
1.2       www       525:             }
1.24      matthew   526:         } 
                    527:     }
1.8       www       528:     $r->print('</table>');
                    529: #
                    530: # Course level
                    531: #
1.6       www       532:     $r->print('<h4>Course Level</h4>'.
1.3       www       533:     '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
                    534:     '<th>Group/Section</th><th>Start</th><th>End</th></tr>');
1.24      matthew   535:     foreach (sort( keys(%inccourses))) {
1.2       www       536: 	my $thiscourse=$_;
1.15      albertel  537: 	my $protectedcourse=$_;
                    538:         $thiscourse=~s:_:/:g;
1.3       www       539:         my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
                    540:         my $area=$coursedata{'description'};
                    541:         my $bgcol=$thiscourse;
                    542:         $bgcol=~s/[^8-9b-e]//g;
                    543:         $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.24      matthew   544:         foreach  ('st','ta','ep','ad','in','cc') {
1.2       www       545:             if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1.3       www       546:                my $plrole=&Apache::lonnet::plaintext($_);
1.16      albertel  547:                $r->print("
1.3       www       548: <tr bgcolor=#$bgcol>
1.16      albertel  549: <td><input type=checkbox name=\"act_$protectedcourse\_$_\"></td>
1.3       www       550: <td>$plrole</td>
                    551: <td>$area</td>
1.16      albertel  552: <td>");
                    553: 	       if ($_ ne 'cc') {
                    554: 		 $r->print("<input type=text size=5 name=\"sec_$protectedcourse\_$_\">");
                    555: 	       } else { $r->print("&nbsp"); }
                    556: 	       $r->print(<<ENDROW);
1.15      albertel  557: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1.3       www       558: <a href=
1.15      albertel  559: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
                    560: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1.3       www       561: <a href=
1.15      albertel  562: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td>
1.3       www       563: </tr>
                    564: ENDROW
1.2       www       565:             }
1.24      matthew   566:         }
                    567:     } 
1.3       www       568:     $r->print('</table>');
1.6       www       569:     $r->print('<input type=submit value="Modify User">');
1.2       www       570:     $r->print('</form></body></html>');
                    571: }
1.1       www       572: 
1.4       www       573: # ================================================================= Phase Three
                    574: 
                    575: sub phase_three {
                    576:     my $r=shift;
                    577:     $r->print(<<ENDTHREEHEAD);
                    578: <html>
                    579: <head>
                    580: <title>The LearningOnline Network with CAPA</title>
                    581: </head>
                    582: <body bgcolor="#FFFFFF">
                    583: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    584: <h1>Create User, Change User Privileges</h1>
                    585: ENDTHREEHEAD
1.6       www       586:    $r->print('<h2>'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'</h2>');
1.4       www       587:    if ($ENV{'form.makeuser'}) {
                    588:     $r->print('<h3>Creating User</h3>');
                    589:     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
                    590:         ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
                    591: 	my $amode='';
                    592:         my $genpwd='';
                    593:         if ($ENV{'form.login'} eq 'krb') {
                    594:            $amode='krb4';
                    595:            $genpwd=$ENV{'form.krbdom'};
                    596:         } elsif ($ENV{'form.login'} eq 'int') {
                    597:            $amode='internal';
                    598:            $genpwd=$ENV{'form.intpwd'};
1.20      harris41  599:         } elsif ($ENV{'form.login'} eq 'fsys') {
                    600:            $amode='unix';
                    601:            $genpwd=$ENV{'form.fsyspwd'};
1.18      albertel  602:         } elsif ($ENV{'form.login'} eq 'loc') {
                    603: 	    $amode='localauth';
                    604: 	    $genpwd=$ENV{'form.locarg'};
                    605: 	    if (!$genpwd) { $genpwd=" "; }
                    606: 	}
1.4       www       607:         if (($amode) && ($genpwd)) {
1.6       www       608:           $r->print('Generating user: '.&Apache::lonnet::modifyuser(
1.4       www       609:                       $ENV{'form.cdomain'},$ENV{'form.cuname'},
                    610:                       $ENV{'form.cstid'},$amode,$genpwd,
                    611:  	              $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
1.6       www       612:                       $ENV{'form.clast'},$ENV{'form.cgen'}));
                    613:           $r->print('<br>Home server: '.&Apache::lonnet::homeserver
1.20      harris41  614:                       ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
                    615: 
                    616: 	} else {
                    617:            $r->print('Invalid login mode or password');    
                    618:         }          
                    619:     } else {
                    620:         $r->print('Invalid username or domain');
                    621:     }
                    622:    }
                    623:    if (!$ENV{'form.makeuser'} and $ENV{'form.login'} ne 'nop') {
                    624:     $r->print('<h3>Changing User Login Data</h3>');
                    625:     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
                    626:         ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
                    627: 	my $amode='';
                    628:         my $genpwd='';
                    629:         if ($ENV{'form.login'} eq 'krb') {
                    630:            $amode='krb4';
                    631:            $genpwd=$ENV{'form.krbdom'};
                    632:         } elsif ($ENV{'form.login'} eq 'int') {
                    633:            $amode='internal';
                    634:            $genpwd=$ENV{'form.intpwd'};
                    635:         } elsif ($ENV{'form.login'} eq 'fsys') {
                    636:            $amode='unix';
                    637:            $genpwd=$ENV{'form.fsyspwd'};
                    638:         } elsif ($ENV{'form.login'} eq 'loc') {
                    639: 	    $amode='localauth';
                    640: 	    $genpwd=$ENV{'form.locarg'};
                    641: 	    if (!$genpwd) { $genpwd=" "; }
                    642: 	}
                    643:         if (($amode) && ($genpwd)) {
                    644: 	    $r->print('Modifying authentication: '.
                    645: 		 &Apache::lonnet::modifyuserauth(
                    646: 		       $ENV{'form.cdomain'},$ENV{'form.cuname'},
1.21      harris41  647:                        $amode,$genpwd));
1.20      harris41  648:             $r->print('<br>Home server: '.&Apache::lonnet::homeserver
1.6       www       649:                       ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
                    650: 
1.4       www       651: 	} else {
                    652:            $r->print('Invalid login mode or password');    
                    653:         }          
                    654:     } else {
                    655:         $r->print('Invalid username or domain');
                    656:     }
                    657:    }
                    658:     my $now=time;
1.6       www       659:     $r->print('<h3>Modifying Roles</h3>');
1.24      matthew   660:     foreach (keys (%ENV)) {
1.4       www       661: 	if (($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
                    662:            $r->print('Revoking '.$2.' in '.$1.': '.
                    663:           &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
                    664:                                       $1,$2,$now).'<br>');
1.11      www       665:            if ($2 eq 'st') {
                    666:                $1=~/^\/(\w+)\/(\w+)/;
                    667:                my $cid=$1.'_'.$2;
                    668: 	       $r->print('Drop from classlist: '.
                    669:           &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
                    670: 	              $ENV{'course.'.$cid.'.num'}.':classlist:'.
                    671:                       &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
                    672:                                               $ENV{'form.cdomain'}).'='.
                    673:                       &Apache::lonnet::escape($now.':'),
                    674: 	              $ENV{'course.'.$cid.'.home'}).'<br>');
                    675:            }
1.4       www       676: 	}
1.24      matthew   677:     } 
                    678:     foreach (keys(%ENV)) {
1.4       www       679: 	if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
1.5       www       680:             my $url='/'.$1.'/'.$2;
                    681:             if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
                    682: 		$url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
                    683:             }
                    684:             my $start=$now;
                    685:             if ($ENV{'form.start_'.$1.'_'.$2.'_'.$3}) {
                    686: 		$start=$ENV{'form.start_'.$1.'_'.$2.'_'.$3};
                    687:             }
                    688:             my $end=0;
                    689:             if ($ENV{'form.end_'.$1.'_'.$2.'_'.$3}) {
                    690: 		$end=$ENV{'form.end_'.$1.'_'.$2.'_'.$3};
                    691:             }
                    692:             $r->print('Assigning: '.$3.' in '.$url.': '.
                    693:           &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
                    694:                                       $url,$3,$end,$start).'<br>');
1.10      www       695:             if ($3 eq 'st') {
1.11      www       696: 		$url=~/^\/(\w+)\/(\w+)/;
                    697:                 my $cid=$1.'_'.$2;
1.10      www       698:                $r->print('Add to classlist: '.
                    699:           &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
                    700: 	              $ENV{'course.'.$cid.'.num'}.':classlist:'.
                    701:                       &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
                    702:                                               $ENV{'form.cdomain'}).'='.
                    703:                       &Apache::lonnet::escape($end.':'.$start),
                    704: 	              $ENV{'course.'.$cid.'.home'}).'<br>');
                    705: 	    }
1.8       www       706: 	} elsif (($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
                    707:             my $url='/'.$1.'/';
                    708:             my $start=$now;
                    709:             if ($ENV{'form.start_'.$1.'_'.$2}) {
                    710: 		$start=$ENV{'form.start_'.$1.'_'.$2};
                    711:             }
                    712:             my $end=0;
                    713:             if ($ENV{'form.end_'.$1.'_'.$2}) {
                    714: 		$end=$ENV{'form.end_'.$1.'_'.$2};
                    715:             }
                    716:             $r->print('Assigning: '.$2.' in '.$url.': '.
                    717:           &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
                    718:                                       $url,$2,$end,$start).'<br>');
                    719:         }
1.24      matthew   720:     }
1.5       www       721:     $r->print('</body></html>');
1.4       www       722: }
                    723: 
1.2       www       724: # ================================================================ Main Handler
                    725: sub handler {
                    726:     my $r = shift;
                    727: 
                    728:     if ($r->header_only) {
                    729:        $r->content_type('text/html');
                    730:        $r->send_http_header;
                    731:        return OK;
                    732:     }
                    733: 
                    734:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
                    735:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
                    736:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
                    737:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
1.19      www       738:         (&Apache::lonnet::allowed('cca',$ENV{'user.domain'})) ||
1.2       www       739:         (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
                    740:        $r->content_type('text/html');
                    741:        $r->send_http_header;
                    742:        unless ($ENV{'form.phase'}) {
                    743: 	   &phase_one($r);
                    744:        }
                    745:        if ($ENV{'form.phase'} eq 'two') {
                    746:            &phase_two($r);
1.4       www       747:        } elsif ($ENV{'form.phase'} eq 'three') {
                    748:            &phase_three($r);
1.2       www       749:        }
1.1       www       750:    } else {
                    751:       $ENV{'user.error.msg'}=
1.9       albertel  752:         "/adm/createuser:mau:0:0:Cannot modify user data";
1.1       www       753:       return HTTP_NOT_ACCEPTABLE; 
                    754:    }
                    755:    return OK;
                    756: } 
                    757: 
                    758: 1;
                    759: __END__
1.2       www       760: 
                    761: 

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