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