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