1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.52 2003/04/30 15:49:45 matthew 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.52 2003/04/30 15:49:45 matthew 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>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: if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
287: my %coursedata=
288: &Apache::lonnet::coursedescription($1.'_'.$2);
289: my $carea;
290: if (defined($coursedata{'description'})) {
291: $carea='Course: '.$coursedata{'description'};
292: } else {
293: $carea='Unavailable course: '.$area;
294: }
295: $inccourses{$1.'_'.$2}=1;
296: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) {
297: $allowed=1;
298: }
299: # Compute the background color based on $area
300: $bgcol=$1.'_'.$2;
301: $bgcol=~s/[^8-9b-e]//g;
302: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
303: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
304: $carea.='<br>Section/Group: '.$3;
305: }
306: $area=$carea;
307: } else {
308: # Determine if current user is able to revoke privileges
309: if ($area=~ /^\/(\w+)\//) {
310: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
311: $allowed=1;
312: }
313: } else {
314: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
315: $allowed=1;
316: }
317: }
318: }
319: if ($role_code eq 'ca') {
320: $area=~/\/(\w+)\/(\w+)/;
321: if (&authorpriv($2,$1)) {
322: $allowed=1;
323: } else {
324: $allowed=0;
325: }
326: }
327: my $row = '';
328: $row.='<tr bgcolor=#"'.$bgcol.'"><td>';
329: my $active=1;
330: $active=0 if (($role_end_time) && ($now>$role_end_time));
331: if (($active) && ($allowed)) {
332: $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
333: } else {
334: $row.=' ';
335: }
336: $row.= '</td><td>'.&Apache::lonnet::plaintext($role_code).
337: '</td><td>'.$area.
338: '</td><td>'.($role_start_time?localtime($role_start_time)
339: : ' ' ).
340: '</td><td>'.($role_end_time ?localtime($role_end_time)
341: : ' ' )
342: ."</td></tr>\n";
343: $r->print($row);
344: } # end of foreach (table building loop)
345: $r->print('</table>');
346: } # End of unless
347: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
348: if ($currentauth=~/^krb(4|5):/) {
349: $currentauth=~/^krb(4|5):(.*)/;
350: my $krbdefdom=$1;
351: my %param = ( formname => 'document.cu',
352: kerb_def_dom => $krbdefdom
353: );
354: $loginscript = &Apache::loncommon::authform_header(%param);
355: }
356: # Check for a bad authentication type
357: unless ($currentauth=~/^krb(4|5):/ or
358: $currentauth=~/^unix:/ or
359: $currentauth=~/^internal:/ or
360: $currentauth=~/^localauth:/
361: ) { # bad authentication scheme
362: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
363: $r->print(<<ENDBADAUTH);
364: <hr />
365: <script type="text/javascript" language="Javascript">
366: $loginscript
367: </script>
368: <font color='#ff0000'>ERROR:</font>
369: This user has an unrecognized authentication scheme ($currentauth).
370: Please specify login data below.
371: <h3>Login Data</h3>
372: <p>$generalrule</p>
373: <p>$authformkrb</p>
374: <p>$authformint</p>
375: <p>$authformfsys</p>
376: <p>$authformloc</p>
377: ENDBADAUTH
378: } else {
379: # This user is not allowed to modify the users
380: # authentication scheme, so just notify them of the problem
381: $r->print(<<ENDBADAUTH);
382: <hr />
383: <script type="text/javascript" language="Javascript">
384: $loginscript
385: </script>
386: <font color="#ff0000"> ERROR: </font>
387: This user has an unrecognized authentication scheme ($currentauth).
388: Please alert a domain coordinator of this situation.
389: <hr />
390: ENDBADAUTH
391: }
392: } else { # Authentication type is valid
393: my $authformcurrent='';
394: my $authform_other='';
395: if ($currentauth=~/^krb(4|5):/) {
396: $authformcurrent=$authformkrb;
397: $authform_other="<p>$authformint</p>\n".
398: "<p>$authformfsys</p><p>$authformloc</p>";
399: }
400: elsif ($currentauth=~/^internal:/) {
401: $authformcurrent=$authformint;
402: $authform_other="<p>$authformkrb</p>".
403: "<p>$authformfsys</p><p>$authformloc</p>";
404: }
405: elsif ($currentauth=~/^unix:/) {
406: $authformcurrent=$authformfsys;
407: $authform_other="<p>$authformkrb</p>".
408: "<p>$authformint</p><p>$authformloc;</p>";
409: }
410: elsif ($currentauth=~/^localauth:/) {
411: $authformcurrent=$authformloc;
412: $authform_other="<p>$authformkrb</p>".
413: "<p>$authformint</p><p>$authformfsys</p>";
414: }
415: $authformcurrent=<<ENDCURRENTAUTH;
416: <table border='1'>
417: <tr>
418: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
419: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
420: </tr>
421: <tr><td bgcolor='#cbbcbb'>$authformcurrent</td>
422: <td bgcolor='#cbbcbb'>Changing this value will overwrite existing authentication for the user; you should notify the user of this change.</td></tr>
423: </table>
424: ENDCURRENTAUTH
425: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
426: # Current user has login modification privileges
427: $r->print(<<ENDOTHERAUTHS);
428: <hr />
429: <script type="text/javascript" language="Javascript">
430: $loginscript
431: </script>
432: <h3>Change Current Login Data</h3>
433: <p>$generalrule</p>
434: <p>$authformnop</p>
435: <p>$authformcurrent</p>
436: <h3>Enter New Login Data</h3>
437: $authform_other
438: ENDOTHERAUTHS
439: }
440: } ## End of "check for bad authentication type" logic
441: } ## End of new user/old user logic
442: $r->print('<hr /><h3>Add Roles</h3>');
443: #
444: # Co-Author
445: #
446: if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
447: ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
448: # No sense in assigning co-author role to yourself
449: my $cuname=$ENV{'user.name'};
450: my $cudom=$ENV{'request.role.domain'};
451: $r->print(<<ENDCOAUTH);
452: <h4>Construction Space</h4>
453: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
454: <th>Start</th><th>End</th></tr>
455: <tr>
456: <td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
457: <td>Co-Author</td>
458: <td>$cudom\_$cuname</td>
459: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
460: <a href=
461: "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>
462: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
463: <a href=
464: "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>
465: </tr>
466: </table>
467: ENDCOAUTH
468: }
469: #
470: # Domain level
471: #
472: $r->print('<h4>Domain Level</h4>'.
473: '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
474: '<th>Start</th><th>End</th></tr>');
475: foreach ( sort( keys(%incdomains))) {
476: my $thisdomain=$_;
477: foreach ('dc','li','dg','au') {
478: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
479: my $plrole=&Apache::lonnet::plaintext($_);
480: $r->print(<<ENDDROW);
481: <tr>
482: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
483: <td>$plrole</td>
484: <td>$thisdomain</td>
485: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
486: <a href=
487: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">Set Start Date</a></td>
488: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
489: <a href=
490: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">Set End Date</a></td>
491: </tr>
492: ENDDROW
493: }
494: }
495: }
496: $r->print('</table>');
497: #
498: # Course level
499: #
500: $r->print(&course_level_table(%inccourses));
501: $r->print("<hr /><input type=submit value=\"Modify User\">\n");
502: $r->print("</form></body></html>");
503: }
504:
505: # ================================================================= Phase Three
506: sub update_user_data {
507: my $r=shift;
508: my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
509: $ENV{'form.ccdomain'});
510: # Error messages
511: my $error = '<font color="#ff0000">Error:</font>';
512: my $end = '</body></html>';
513: # Print header
514: $r->print(<<ENDTHREEHEAD);
515: <html>
516: <head>
517: <title>The LearningOnline Network with CAPA</title>
518: </head>
519: ENDTHREEHEAD
520: my $title;
521: if (exists($ENV{'form.makeuser'})) {
522: $title='Set Privileges for New User';
523: } else {
524: $title='Modify User Privileges';
525: }
526: $r->print(&Apache::loncommon::bodytag($title));
527: # Check Inputs
528: if (! $ENV{'form.ccuname'} ) {
529: $r->print($error.'No login name specified.'.$end);
530: return;
531: }
532: if ( $ENV{'form.ccuname'} =~/\W/) {
533: $r->print($error.'Invalid login name. '.
534: 'Only letters, numbers, and underscores are valid.'.
535: $end);
536: return;
537: }
538: if (! $ENV{'form.ccdomain'} ) {
539: $r->print($error.'No domain specified.'.$end);
540: return;
541: }
542: if ( $ENV{'form.ccdomain'} =~/\W/) {
543: $r->print($error.'Invalid domain name. '.
544: 'Only letters, numbers, and underscores are valid.'.
545: $end);
546: return;
547: }
548: if (! exists($ENV{'form.makeuser'})) {
549: # Modifying an existing user, so check the validity of the name
550: if ($uhome eq 'no_host') {
551: $r->print($error.'Unable to determine home server for '.
552: $ENV{'form.ccuname'}.' in domain '.
553: $ENV{'form.ccdomain'}.'.');
554: return;
555: }
556: }
557: # Determine authentication method and password for the user being modified
558: my $amode='';
559: my $genpwd='';
560: if ($ENV{'form.login'} eq 'krb') {
561: $amode='krb';
562: $amode.=$ENV{'form.krbver'};
563: $genpwd=$ENV{'form.krbarg'};
564: } elsif ($ENV{'form.login'} eq 'int') {
565: $amode='internal';
566: $genpwd=$ENV{'form.intarg'};
567: } elsif ($ENV{'form.login'} eq 'fsys') {
568: $amode='unix';
569: $genpwd=$ENV{'form.fsysarg'};
570: } elsif ($ENV{'form.login'} eq 'loc') {
571: $amode='localauth';
572: $genpwd=$ENV{'form.locarg'};
573: $genpwd=" " if (!$genpwd);
574: } elsif (($ENV{'form.login'} eq 'nochange') ||
575: ($ENV{'form.login'} eq '' )) {
576: # There is no need to tell the user we did not change what they
577: # did not ask us to change.
578: # If they are creating a new user but have not specified login
579: # information this will be caught below.
580: } else {
581: $r->print($error.'Invalid login mode or password'.$end);
582: return;
583: }
584: if ($ENV{'form.makeuser'}) {
585: # Create a new user
586: $r->print(<<ENDNEWUSERHEAD);
587: <h3>Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
588: ENDNEWUSERHEAD
589: # Check for the authentication mode and password
590: if (! $amode || ! $genpwd) {
591: $r->print($error.'Invalid login mode or password'.$end);
592: return;
593: }
594: # Determine desired host
595: my $desiredhost = $ENV{'form.hserver'};
596: if (lc($desiredhost) eq 'default') {
597: $desiredhost = undef;
598: } else {
599: my %home_servers = &Apache::loncommon::get_library_servers
600: ($ENV{'form.ccdomain'});
601: if (! exists($home_servers{$desiredhost})) {
602: $r->print($error.'Invalid home server specified');
603: return;
604: }
605: }
606: # Call modifyuser
607: my $result = &Apache::lonnet::modifyuser
608: ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
609: $amode,$genpwd,$ENV{'form.cfirst'},
610: $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
611: undef,$desiredhost
612: );
613: $r->print('Generating user: '.$result);
614: my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
615: $ENV{'form.ccdomain'});
616: $r->print('<br>Home server: '.$home.' '.
617: $Apache::lonnet::libserv{$home});
618: } elsif (($ENV{'form.login'} ne 'nochange') &&
619: ($ENV{'form.login'} ne '' )) {
620: # Modify user privileges
621: $r->print(<<ENDMODIFYUSERHEAD);
622: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
623: ENDMODIFYUSERHEAD
624: if (! $amode || ! $genpwd) {
625: $r->print($error.'Invalid login mode or password'.$end);
626: return;
627: }
628: # Only allow authentification modification if the person has authority
629: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
630: $r->print('Modifying authentication: '.
631: &Apache::lonnet::modifyuserauth(
632: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
633: $amode,$genpwd));
634: $r->print('<br>Home server: '.&Apache::lonnet::homeserver
635: ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
636: } else {
637: # Okay, this is a non-fatal error.
638: $r->print($error.'You do not have the authority to modify '.
639: 'this users authentification information.');
640: }
641: }
642: ##
643: if (! $ENV{'form.makeuser'} ) {
644: # Check for need to change
645: my %userenv = &Apache::lonnet::get
646: ('environment',['firstname','middlename','lastname','generation'],
647: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
648: my ($tmp) = keys(%userenv);
649: if ($tmp =~ /^(con_lost|error)/i) {
650: %userenv = ();
651: }
652: # Check to see if we need to change user information
653: foreach ('firstname','middlename','lastname','generation') {
654: # Strip leading and trailing whitespace
655: $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
656: }
657: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) &&
658: ($ENV{'form.cfirstname'} ne $userenv{'firstname'} ||
659: $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
660: $ENV{'form.clastname'} ne $userenv{'lastname'} ||
661: $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
662: # Make the change
663: my %changeHash;
664: $changeHash{'firstname'} = $ENV{'form.cfirstname'};
665: $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
666: $changeHash{'lastname'} = $ENV{'form.clastname'};
667: $changeHash{'generation'} = $ENV{'form.cgeneration'};
668: my $putresult = &Apache::lonnet::put
669: ('environment',\%changeHash,
670: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
671: if ($putresult eq 'ok') {
672: # Tell the user we changed the name
673: $r->print(<<"END");
674: <table border="2">
675: <caption>User Information Changed</caption>
676: <tr><th> </th>
677: <th>first</th>
678: <th>middle</th>
679: <th>last</th>
680: <th>generation</th></tr>
681: <tr><td>Previous</td>
682: <td>$userenv{'firstname'} </td>
683: <td>$userenv{'middlename'} </td>
684: <td>$userenv{'lastname'} </td>
685: <td>$userenv{'generation'} </td></tr>
686: <tr><td>Changed To</td>
687: <td>$ENV{'form.cfirstname'} </td>
688: <td>$ENV{'form.cmiddlename'} </td>
689: <td>$ENV{'form.clastname'} </td>
690: <td>$ENV{'form.cgeneration'} </td></tr>
691: </table>
692: END
693: } else { # error occurred
694: $r->print("<h2>Unable to successfully change environment for ".
695: $ENV{'form.ccuname'}." in domain ".
696: $ENV{'form.ccdomain'}."</h2>");
697: }
698: } else { # End of if ($ENV ... ) logic
699: # They did not want to change the users name but we can
700: # still tell them what the name is
701: $r->print(<<"END");
702: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
703: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
704: <h4>Generation: $userenv{'generation'}</h4>
705: END
706: }
707: }
708: ##
709: my $now=time;
710: $r->print('<h3>Modifying Roles</h3>');
711: foreach (keys (%ENV)) {
712: next if (! $ENV{$_});
713: # Revoke roles
714: if ($_=~/^form\.rev/) {
715: if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) {
716: $r->print('Revoking '.$2.' in '.$1.': '.
717: &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
718: $ENV{'form.ccuname'},$1,$2,$now).'<br>');
719: if ($2 eq 'st') {
720: $1=~/^\/(\w+)\/(\w+)/;
721: my $cid=$1.'_'.$2;
722: $r->print('Drop from classlist: '.
723: &Apache::lonnet::critical('put:'.
724: $ENV{'course.'.$cid.'.domain'}.':'.
725: $ENV{'course.'.$cid.'.num'}.':classlist:'.
726: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
727: $ENV{'form.ccdomain'}).'='.
728: &Apache::lonnet::escape($now.':'),
729: $ENV{'course.'.$cid.'.home'}).'<br>');
730: }
731: }
732: } elsif ($_=~/^form\.act/) {
733: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
734: # Activate roles for sections with 3 id numbers
735: # set start, end times, and the url for the class
736: my $start = ( $ENV{'form.start_'.$1.'_'.$2} ?
737: $ENV{'form.start_'.$1.'_'.$2} :
738: $now );
739: my $end = ( $ENV{'form.end_'.$1.'_'.$2} ?
740: $ENV{'form.end_'.$1.'_'.$2} :
741: 0 );
742: my $url='/'.$1.'/'.$2;
743: if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
744: $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
745: }
746: # Assign the role and report it
747: $r->print('Assigning: '.$3.' in '.$url.': '.
748: &Apache::lonnet::assignrole(
749: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
750: $url,$3,$end,$start).
751: '<br>');
752: # Handle students differently
753: if ($3 eq 'st') {
754: $url=~/^\/(\w+)\/(\w+)/;
755: my $cid=$1.'_'.$2;
756: $r->print('Add to classlist: '.
757: &Apache::lonnet::critical(
758: 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
759: $ENV{'course.'.$cid.'.num'}.':classlist:'.
760: &Apache::lonnet::escape(
761: $ENV{'form.ccuname'}.':'.
762: $ENV{'form.ccdomain'} ).'='.
763: &Apache::lonnet::escape($end.':'.$start),
764: $ENV{'course.'.$cid.'.home'})
765: .'<br>');
766: }
767: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
768: # Activate roles for sections with two id numbers
769: # set start, end times, and the url for the class
770: my $start = ( $ENV{'form.start_'.$1.'_'.$2} ?
771: $ENV{'form.start_'.$1.'_'.$2} :
772: $now );
773: my $end = ( $ENV{'form.end_'.$1.'_'.$2} ?
774: $ENV{'form.end_'.$1.'_'.$2} :
775: 0 );
776: my $url='/'.$1.'/';
777: # Assign the role and report it.
778: $r->print('Assigning: '.$2.' in '.$url.': '.
779: &Apache::lonnet::assignrole(
780: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
781: $url,$2,$end,$start)
782: .'<br>');
783: }
784: }
785: } # End of foreach (keys(%ENV))
786: $r->print('</body></html>');
787: }
788:
789: # ================================================================ Main Handler
790: sub handler {
791: my $r = shift;
792:
793: if ($r->header_only) {
794: $r->content_type('text/html');
795: $r->send_http_header;
796: return OK;
797: }
798:
799: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
800: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
801: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
802: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
803: (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
804: (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
805: $r->content_type('text/html');
806: $r->send_http_header;
807: unless ($ENV{'form.phase'}) {
808: &print_username_entry_form($r);
809: }
810: if ($ENV{'form.phase'} eq 'get_user_info') {
811: &print_user_modification_page($r);
812: } elsif ($ENV{'form.phase'} eq 'update_user_data') {
813: &update_user_data($r);
814: }
815: } else {
816: $ENV{'user.error.msg'}=
817: "/adm/createuser:mau:0:0:Cannot modify user data";
818: return HTTP_NOT_ACCEPTABLE;
819: }
820: return OK;
821: }
822:
823: #-------------------------------------------------- functions for &phase_two
824: sub course_level_table {
825: my %inccourses = @_;
826: my $table = '';
827: foreach (sort( keys(%inccourses))) {
828: my $thiscourse=$_;
829: my $protectedcourse=$_;
830: $thiscourse=~s:_:/:g;
831: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
832: my $area=$coursedata{'description'};
833: if (!defined($area)) { $area='Unavailable course: '.$_; }
834: my $bgcol=$thiscourse;
835: $bgcol=~s/[^8-9b-e]//g;
836: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
837: foreach ('st','ta','ep','ad','in','cc') {
838: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
839: my $plrole=&Apache::lonnet::plaintext($_);
840: $table .= <<ENDEXTENT;
841: <tr bgcolor="#$bgcol">
842: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
843: <td>$plrole</td>
844: <td>$area</td>
845: ENDEXTENT
846: if ($_ ne 'cc') {
847: $table .= <<ENDSECTION;
848: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
849: ENDSECTION
850: } else {
851: $table .= <<ENDSECTION;
852: <td> </td>
853: ENDSECTION
854: }
855: $table .= <<ENDTIMEENTRY;
856: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
857: <a href=
858: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
859: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
860: <a href=
861: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td>
862: ENDTIMEENTRY
863: $table.= "</tr>\n";
864: }
865: }
866: }
867: return '' if ($table eq ''); # return nothing if there is nothing
868: # in the table
869: my $result = <<ENDTABLE;
870: <h4>Course Level</h4>
871: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
872: <th>Group/Section</th><th>Start</th><th>End</th></tr>
873: $table
874: </table>
875: ENDTABLE
876: return $result;
877: }
878: #---------------------------------------------- end functions for &phase_two
879:
880: #--------------------------------- functions for &phase_two and &phase_three
881:
882: #--------------------------end of functions for &phase_two and &phase_three
883:
884: 1;
885: __END__
886:
887:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>