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