1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.53 2003/05/10 23:06:52 www Exp $
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: #
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: #
37: # YEAR=2001
38: # 3/1/1 Gerd Kortemeyer)
39: #
40: # 3/1 Gerd Kortemeyer)
41: #
42: # 2/14 Gerd Kortemeyer)
43: #
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
45: # April Guy Albertelli
46: # 05/10,10/16 Gerd Kortemeyer
47: # 02/11/02 Matthew Hall
48: #
49: # $Id: loncreateuser.pm,v 1.53 2003/05/10 23:06:52 www Exp $
50: ###
51:
52: package Apache::loncreateuser;
53:
54: use strict;
55: use Apache::Constants qw(:common :http);
56: use Apache::lonnet;
57:
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:
66: BEGIN {
67: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
68: my $krbdefdom=$1;
69: $krbdefdom=~tr/a-z/A-Z/;
70: my %param = ( formname => 'document.cu',
71: kerb_def_dom => $krbdefdom
72: );
73: # no longer static due to configurable kerberos defaults
74: # $loginscript = &Apache::loncommon::authform_header(%param);
75: $generalrule = &Apache::loncommon::authform_authorwarning(%param);
76: $authformnop = &Apache::loncommon::authform_nochange(%param);
77: # no longer static due to configurable kerberos defaults
78: # $authformkrb = &Apache::loncommon::authform_kerberos(%param);
79: $authformint = &Apache::loncommon::authform_internal(%param);
80: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
81: $authformloc = &Apache::loncommon::authform_local(%param);
82: }
83:
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:
97: # =================================================================== Phase one
98:
99: sub print_username_entry_form {
100: my $r=shift;
101: my $defdom=$ENV{'request.role.domain'};
102: my @domains = &Apache::loncommon::get_domains();
103: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
104: my $bodytag =&Apache::loncommon::bodytag(
105: 'Create Users, Change User Privileges');
106: my $selscript=&Apache::loncommon::studentbrowser_javascript();
107: my $sellink=&Apache::loncommon::selectstudent_link
108: ('crtuser','ccuname','ccdomain');
109: $r->print(<<"ENDDOCUMENT");
110: <html>
111: <head>
112: <title>The LearningOnline Network with CAPA</title>
113: $selscript
114: </head>
115: $bodytag
116: <form action="/adm/createuser" method="post" name="crtuser">
117: <input type="hidden" name="phase" value="get_user_info">
118: <p>
119: <table>
120: <tr><td>Username:</td><td><input type="text" size="15" name="ccuname">
121: </td><td rowspan="2">$sellink</td></tr><tr><td>
122: Domain:</td><td>$domform</td></tr>
123: </table>
124: </p>
125: <input type="submit" value="Continue">
126: </form>
127: </body>
128: </html>
129: ENDDOCUMENT
130: }
131:
132: # =================================================================== Phase two
133: sub print_user_modification_page {
134: my $r=shift;
135: my $ccuname=$ENV{'form.ccuname'};
136: my $ccdomain=$ENV{'form.ccdomain'};
137:
138: my $defdom=$ENV{'request.role.domain'};
139:
140: my ($krbdef,$krbdefdom) =
141: &Apache::loncommon::get_kerberos_defaults($defdom);
142:
143: my %param = ( formname => 'document.cu',
144: kerb_def_dom => $krbdefdom,
145: kerb_def_auth => $krbdef
146: );
147: $loginscript = &Apache::loncommon::authform_header(%param);
148: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
149:
150: $ccuname=~s/\W//g;
151: $ccdomain=~s/\W//g;
152: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
153: my $dochead =<<"ENDDOCHEAD";
154: <html>
155: <head>
156: <title>The LearningOnline Network with CAPA</title>
157: <script type="text/javascript" language="Javascript">
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:
165: $pjump_def
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>
174: </head>
175: ENDDOCHEAD
176: $r->print(&Apache::loncommon::bodytag(
177: 'Create Users, Change User Privileges'));
178: my $forminfo =<<"ENDFORMINFO";
179: <form action="/adm/createuser" method="post" name="cu">
180: <input type="hidden" name="phase" value="update_user_data">
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
187: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
188: my %incdomains;
189: my %inccourses;
190: foreach (values(%Apache::lonnet::hostdom)) {
191: $incdomains{$_}=1;
192: }
193: foreach (keys(%ENV)) {
194: if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
195: $inccourses{$1.'_'.$2}=1;
196: }
197: }
198: if ($uhome eq 'no_host') {
199: my $home_server_list=
200: '<option value="default" selected>default</option>'."\n".
201: &Apache::loncommon::home_server_option_list($ccdomain);
202:
203: $r->print(<<ENDNEWUSER);
204: $dochead
205: <h1>Create New User</h1>
206: $forminfo
207: <h2>New user "$ccuname" in domain $ccdomain</h2>
208: <script type="text/javascript" language="Javascript">
209: $loginscript
210: </script>
211: <input type='hidden' name='makeuser' value='1' />
212: <h3>Personal Data</h3>
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>
225: Home Server: <select name="hserver" size="1"> $home_server_list </select>
226: <hr />
227: <h3>Login Data</h3>
228: <p>$generalrule </p>
229: <p>$authformkrb </p>
230: <p>$authformint </p>
231: <p>$authformfsys</p>
232: <p>$authformloc </p>
233: ENDNEWUSER
234: } else { # user already exists
235: $r->print(<<ENDCHANGEUSER);
236: $dochead
237: <h1>Change User Privileges</h1>
238: $forminfo
239: <h2>User "$ccuname" in domain $ccdomain </h2>
240: ENDCHANGEUSER
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");
257: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
258: END
259: } else {
260: $r->print('<td>'.$userenv{$_}.'</td>');
261: }
262: }
263: $r->print(<<END);
264: </tr>
265: </table>
266: END
267: # Build up table of user roles to allow revocation of a role.
268: my ($tmp) = keys(%rolesdump);
269: unless ($tmp =~ /^(con_lost|error)/i) {
270: my $now=time;
271: $r->print(<<END);
272: <hr />
273: <h3>Revoke Existing Roles</h3>
274: <table border=2>
275: <tr><th>Revoke</th><th>Delete</th><th>Role</th><th>Extent</th><th>Start</th><th>End</th>
276: END
277: foreach my $area (keys(%rolesdump)) {
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;
286: my $delallowed=0;
287: if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
288: my %coursedata=
289: &Apache::lonnet::coursedescription($1.'_'.$2);
290: my $carea;
291: if (defined($coursedata{'description'})) {
292: $carea='Course: '.$coursedata{'description'}.
293: '<br />Domain: '.$1;
294: } else {
295: $carea='Unavailable course: '.$area;
296: }
297: $inccourses{$1.'_'.$2}=1;
298: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
299: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
300: $allowed=1;
301: }
302: if ((&Apache::lonnet::allowed('dro',$1)) ||
303: (&Apache::lonnet::allowed('dro',$ccdomain))) {
304: $delallowed=1;
305: }
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+)/) {
311: $carea.='<br>Section/Group: '.$3;
312: }
313: $area=$carea;
314: } else {
315: # Determine if current user is able to revoke privileges
316: if ($area=~ /^\/(\w+)\//) {
317: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
318: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
319: $allowed=1;
320: }
321: if (((&Apache::lonnet::allowed('dro',$1)) ||
322: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
323: ($role_code ne 'dc')) {
324: $delallowed=1;
325: }
326: } else {
327: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
328: $allowed=1;
329: }
330: }
331: }
332: if ($role_code eq 'ca') {
333: $area=~/\/(\w+)\/(\w+)/;
334: if (&authorpriv($2,$1)) {
335: $allowed=1;
336: } else {
337: $allowed=0;
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: }
349: $row.='</td><td>';
350: if ($delallowed) {
351: $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
352: } else {
353: $row.=' ';
354: }
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);
363: } # end of foreach (table building loop)
364: $r->print('</table>');
365: } # End of unless
366: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
367: if ($currentauth=~/^krb(4|5):/) {
368: $currentauth=~/^krb(4|5):(.*)/;
369: my $krbdefdom=$1;
370: my %param = ( formname => 'document.cu',
371: kerb_def_dom => $krbdefdom
372: );
373: $loginscript = &Apache::loncommon::authform_header(%param);
374: }
375: # Check for a bad authentication type
376: unless ($currentauth=~/^krb(4|5):/ or
377: $currentauth=~/^unix:/ or
378: $currentauth=~/^internal:/ or
379: $currentauth=~/^localauth:/
380: ) { # bad authentication scheme
381: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
382: $r->print(<<ENDBADAUTH);
383: <hr />
384: <script type="text/javascript" language="Javascript">
385: $loginscript
386: </script>
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>
391: <p>$generalrule</p>
392: <p>$authformkrb</p>
393: <p>$authformint</p>
394: <p>$authformfsys</p>
395: <p>$authformloc</p>
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 />
402: <script type="text/javascript" language="Javascript">
403: $loginscript
404: </script>
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
412: my $authformcurrent='';
413: my $authform_other='';
414: if ($currentauth=~/^krb(4|5):/) {
415: $authformcurrent=$authformkrb;
416: $authform_other="<p>$authformint</p>\n".
417: "<p>$authformfsys</p><p>$authformloc</p>";
418: }
419: elsif ($currentauth=~/^internal:/) {
420: $authformcurrent=$authformint;
421: $authform_other="<p>$authformkrb</p>".
422: "<p>$authformfsys</p><p>$authformloc</p>";
423: }
424: elsif ($currentauth=~/^unix:/) {
425: $authformcurrent=$authformfsys;
426: $authform_other="<p>$authformkrb</p>".
427: "<p>$authformint</p><p>$authformloc;</p>";
428: }
429: elsif ($currentauth=~/^localauth:/) {
430: $authformcurrent=$authformloc;
431: $authform_other="<p>$authformkrb</p>".
432: "<p>$authformint</p><p>$authformfsys</p>";
433: }
434: $authformcurrent.=' <i>(will override current values)</i><br />';
435: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
436: # Current user has login modification privileges
437: $r->print(<<ENDOTHERAUTHS);
438: <hr />
439: <script type="text/javascript" language="Javascript">
440: $loginscript
441: </script>
442: <h3>Change Current Login Data</h3>
443: <p>$generalrule</p>
444: <p>$authformnop</p>
445: <p>$authformcurrent</p>
446: <h3>Enter New Login Data</h3>
447: $authform_other
448: ENDOTHERAUTHS
449: }
450: } ## End of "check for bad authentication type" logic
451: } ## End of new user/old user logic
452: $r->print('<hr /><h3>Add Roles</h3>');
453: #
454: # Co-Author
455: #
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
459: my $cuname=$ENV{'user.name'};
460: my $cudom=$ENV{'request.role.domain'};
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: }
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>');
485: foreach ( sort( keys(%incdomains))) {
486: my $thisdomain=$_;
487: foreach ('dc','li','dg','au') {
488: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
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
503: }
504: }
505: }
506: $r->print('</table>');
507: #
508: # Course level
509: #
510: $r->print(&course_level_table(%inccourses));
511: $r->print("<hr /><input type=submit value=\"Modify User\">\n");
512: $r->print("</form></body></html>");
513: }
514:
515: # ================================================================= Phase Three
516: sub update_user_data {
517: my $r=shift;
518: my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
519: $ENV{'form.ccdomain'});
520: # Error messages
521: my $error = '<font color="#ff0000">Error:</font>';
522: my $end = '</body></html>';
523: # Print header
524: $r->print(<<ENDTHREEHEAD);
525: <html>
526: <head>
527: <title>The LearningOnline Network with CAPA</title>
528: </head>
529: ENDTHREEHEAD
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));
537: # Check Inputs
538: if (! $ENV{'form.ccuname'} ) {
539: $r->print($error.'No login name specified.'.$end);
540: return;
541: }
542: if ( $ENV{'form.ccuname'} =~/\W/) {
543: $r->print($error.'Invalid login name. '.
544: 'Only letters, numbers, and underscores are valid.'.
545: $end);
546: return;
547: }
548: if (! $ENV{'form.ccdomain'} ) {
549: $r->print($error.'No domain specified.'.$end);
550: return;
551: }
552: if ( $ENV{'form.ccdomain'} =~/\W/) {
553: $r->print($error.'Invalid domain name. '.
554: 'Only letters, numbers, and underscores are valid.'.
555: $end);
556: return;
557: }
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: }
567: # Determine authentication method and password for the user being modified
568: my $amode='';
569: my $genpwd='';
570: if ($ENV{'form.login'} eq 'krb') {
571: $amode='krb';
572: $amode.=$ENV{'form.krbver'};
573: $genpwd=$ENV{'form.krbarg'};
574: } elsif ($ENV{'form.login'} eq 'int') {
575: $amode='internal';
576: $genpwd=$ENV{'form.intarg'};
577: } elsif ($ENV{'form.login'} eq 'fsys') {
578: $amode='unix';
579: $genpwd=$ENV{'form.fsysarg'};
580: } elsif ($ENV{'form.login'} eq 'loc') {
581: $amode='localauth';
582: $genpwd=$ENV{'form.locarg'};
583: $genpwd=" " if (!$genpwd);
584: } elsif (($ENV{'form.login'} eq 'nochange') ||
585: ($ENV{'form.login'} eq '' )) {
586: # There is no need to tell the user we did not change what they
587: # did not ask us to change.
588: # If they are creating a new user but have not specified login
589: # information this will be caught below.
590: } else {
591: $r->print($error.'Invalid login mode or password'.$end);
592: return;
593: }
594: if ($ENV{'form.makeuser'}) {
595: # Create a new user
596: $r->print(<<ENDNEWUSERHEAD);
597: <h3>Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
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;
603: }
604: # Determine desired host
605: my $desiredhost = $ENV{'form.hserver'};
606: if (lc($desiredhost) eq 'default') {
607: $desiredhost = undef;
608: } else {
609: my %home_servers = &Apache::loncommon::get_library_servers
610: ($ENV{'form.ccdomain'});
611: if (! exists($home_servers{$desiredhost})) {
612: $r->print($error.'Invalid home server specified');
613: return;
614: }
615: }
616: # Call modifyuser
617: my $result = &Apache::lonnet::modifyuser
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
622: );
623: $r->print('Generating user: '.$result);
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});
628: } elsif (($ENV{'form.login'} ne 'nochange') &&
629: ($ENV{'form.login'} ne '' )) {
630: # Modify user privileges
631: $r->print(<<ENDMODIFYUSERHEAD);
632: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
633: ENDMODIFYUSERHEAD
634: if (! $amode || ! $genpwd) {
635: $r->print($error.'Invalid login mode or password'.$end);
636: return;
637: }
638: # Only allow authentification modification if the person has authority
639: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
640: $r->print('Modifying authentication: '.
641: &Apache::lonnet::modifyuserauth(
642: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
643: $amode,$genpwd));
644: $r->print('<br>Home server: '.&Apache::lonnet::homeserver
645: ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
646: } else {
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: }
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'],
657: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
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: }
667: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) &&
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,
680: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
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 ".
705: $ENV{'form.ccuname'}." in domain ".
706: $ENV{'form.ccdomain'}."</h2>");
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");
712: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
713: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
714: <h4>Generation: $userenv{'generation'}</h4>
715: END
716: }
717: }
718: ##
719: my $now=time;
720: $r->print('<h3>Modifying Roles</h3>');
721: foreach (keys (%ENV)) {
722: next if (! $ENV{$_});
723: # Revoke roles
724: if ($_=~/^form\.rev/) {
725: if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) {
726: $r->print('Revoking '.$2.' in '.$1.': '.
727: &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
728: $ENV{'form.ccuname'},$1,$2,$now).'<br>');
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>');
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:'.
754: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
755: $ENV{'form.ccdomain'}).'='.
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(
777: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
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(
789: $ENV{'form.ccuname'}.':'.
790: $ENV{'form.ccdomain'} ).'='.
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(
808: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
809: $url,$2,$end,$start)
810: .'<br>');
811: }
812: }
813: } # End of foreach (keys(%ENV))
814: $r->print('</body></html>');
815: }
816:
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'})) ||
831: (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
832: (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
833: $r->content_type('text/html');
834: $r->send_http_header;
835: unless ($ENV{'form.phase'}) {
836: &print_username_entry_form($r);
837: }
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);
842: }
843: } else {
844: $ENV{'user.error.msg'}=
845: "/adm/createuser:mau:0:0:Cannot modify user data";
846: return HTTP_NOT_ACCEPTABLE;
847: }
848: return OK;
849: }
850:
851: #-------------------------------------------------- functions for &phase_two
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'};
861: if (!defined($area)) { $area='Unavailable course: '.$_; }
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: }
906: #---------------------------------------------- end functions for &phase_two
907:
908: #--------------------------------- functions for &phase_two and &phase_three
909:
910: #--------------------------end of functions for &phase_two and &phase_three
911:
912: 1;
913: __END__
914:
915:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>