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