1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.87 2004/09/23 22:51:24 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: ###
29:
30: package Apache::loncreateuser;
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser - handler to create users and custom roles
37:
38: =head1 SYNOPSIS
39:
40: Apache::loncreateuser provides an Apache handler for creating users,
41: editing their login parameters, roles, and removing roles, and
42: also creating and assigning custom roles.
43:
44: =head1 OVERVIEW
45:
46: =head2 Custom Roles
47:
48: In LON-CAPA, roles are actually collections of privileges. "Teaching
49: Assistant", "Course Coordinator", and other such roles are really just
50: collection of privileges that are useful in many circumstances.
51:
52: Creating custom roles can be done by the Domain Coordinator through
53: the Create User functionality. That screen will show all privileges
54: that can be assigned to users. For a complete list of privileges,
55: please see C</home/httpd/lonTabs/rolesplain.tab>.
56:
57: Custom role definitions are stored in the C<roles.db> file of the role
58: author.
59:
60: =cut
61:
62: use strict;
63: use Apache::Constants qw(:common :http);
64: use Apache::lonnet;
65: use Apache::loncommon;
66: use Apache::lonlocal;
67:
68: my $loginscript; # piece of javascript used in two separate instances
69: my $generalrule;
70: my $authformnop;
71: my $authformkrb;
72: my $authformint;
73: my $authformfsys;
74: my $authformloc;
75:
76: BEGIN {
77: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
78: my $krbdefdom=$1;
79: $krbdefdom=~tr/a-z/A-Z/;
80: my %param = ( formname => 'document.cu',
81: kerb_def_dom => $krbdefdom
82: );
83: # no longer static due to configurable kerberos defaults
84: # $loginscript = &Apache::loncommon::authform_header(%param);
85: $generalrule = &Apache::loncommon::authform_authorwarning(%param);
86: $authformnop = &Apache::loncommon::authform_nochange(%param);
87: # no longer static due to configurable kerberos defaults
88: # $authformkrb = &Apache::loncommon::authform_kerberos(%param);
89: $authformint = &Apache::loncommon::authform_internal(%param);
90: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
91: $authformloc = &Apache::loncommon::authform_local(%param);
92: }
93:
94:
95: # ======================================================= Existing Custom Roles
96:
97: sub my_custom_roles {
98: my %returnhash=();
99: my %rolehash=&Apache::lonnet::dump('roles');
100: foreach (keys %rolehash) {
101: if ($_=~/^rolesdef\_(\w+)$/) {
102: $returnhash{$1}=$1;
103: }
104: }
105: return %returnhash;
106: }
107:
108: # ==================================================== Figure out author access
109:
110: sub authorpriv {
111: my ($auname,$audom)=@_;
112: if (($auname ne $ENV{'user.name'}) ||
113: (($audom ne $ENV{'user.domain'}) &&
114: ($audom ne $ENV{'request.role.domain'}))) { return ''; }
115: unless (&Apache::lonnet::allowed('cca',$audom)) { return ''; }
116: return 1;
117: }
118:
119: # =================================================================== Phase one
120:
121: sub print_username_entry_form {
122: my $r=shift;
123: my $defdom=$ENV{'request.role.domain'};
124: my @domains = &Apache::loncommon::get_domains();
125: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
126: my $bodytag =&Apache::loncommon::bodytag('Create Users, Change User Privileges').&Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
127: my $selscript=&Apache::loncommon::studentbrowser_javascript();
128: my $sellink=&Apache::loncommon::selectstudent_link
129: ('crtuser','ccuname','ccdomain');
130: my %existingroles=&my_custom_roles();
131: my $choice=&Apache::loncommon::select_form('make new role','rolename',
132: ('make new role' => 'Generate new role ...',%existingroles));
133: my %lt=&Apache::lonlocal::texthash(
134: 'siur' => "Set Individual User Roles",
135: 'usr' => "Username",
136: 'dom' => "Domain",
137: 'usrr' => "User Roles",
138: 'ecrp' => "Edit Custom Role Privileges",
139: 'nr' => "Name of Role",
140: 'cre' => "Custom Role Editor"
141: );
142: my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
143: my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
144: $r->print(<<"ENDDOCUMENT");
145: <html>
146: <head>
147: <title>The LearningOnline Network with CAPA</title>
148: $selscript
149: </head>
150: $bodytag
151: <form action="/adm/createuser" method="post" name="crtuser">
152: <input type="hidden" name="phase" value="get_user_info">
153: <h2>$lt{siur}$helpsiur</h2>
154: <table>
155: <tr><td>$lt{usr}:</td><td><input type="text" size="15" name="ccuname">
156: </td><td rowspan="2">$sellink</td></tr><tr><td>
157: $lt{'dom'}:</td><td>$domform</td></tr>
158: </table>
159: <input name="userrole" type="submit" value="$lt{usrr}" />
160: </form>
161: <form action="/adm/createuser" method="post" name="docustom">
162: <input type="hidden" name="phase" value="selected_custom_edit">
163: <h2>$lt{'ecrp'}$helpecpr</h2>
164: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
165: <input name="customeditor" type="submit" value="$lt{'cre'}" />
166: </body>
167: </html>
168: ENDDOCUMENT
169: }
170:
171: # =================================================================== Phase two
172: sub print_user_modification_page {
173: my $r=shift;
174: my $ccuname=$ENV{'form.ccuname'};
175: my $ccdomain=$ENV{'form.ccdomain'};
176:
177: $ccuname=~s/[\W|_]//gs;
178: $ccdomain=~s/[\W|_]//gs;
179:
180: unless (($ccuname) && ($ccdomain)) {
181: &print_username_entry_form($r);
182: return;
183: }
184:
185: my $defdom=$ENV{'request.role.domain'};
186:
187: my ($krbdef,$krbdefdom) =
188: &Apache::loncommon::get_kerberos_defaults($defdom);
189:
190: my %param = ( formname => 'document.cu',
191: kerb_def_dom => $krbdefdom,
192: kerb_def_auth => $krbdef
193: );
194: $loginscript = &Apache::loncommon::authform_header(%param);
195: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
196:
197: $ccuname=~s/\W//g;
198: $ccdomain=~s/\W//g;
199: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
200: my $dochead =<<"ENDDOCHEAD";
201: <html>
202: <head>
203: <title>The LearningOnline Network with CAPA</title>
204: <script type="text/javascript" language="Javascript">
205:
206: function pclose() {
207: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
208: "height=350,width=350,scrollbars=no,menubar=no");
209: parmwin.close();
210: }
211:
212: $pjump_def
213:
214: function dateset() {
215: eval("document.cu."+document.cu.pres_marker.value+
216: ".value=document.cu.pres_value.value");
217: pclose();
218: }
219:
220: </script>
221: </head>
222: ENDDOCHEAD
223: $r->print(&Apache::loncommon::bodytag(
224: 'Create Users, Change User Privileges'));
225: my $forminfo =<<"ENDFORMINFO";
226: <form action="/adm/createuser" method="post" name="cu">
227: <input type="hidden" name="phase" value="update_user_data">
228: <input type="hidden" name="ccuname" value="$ccuname">
229: <input type="hidden" name="ccdomain" value="$ccdomain">
230: <input type="hidden" name="pres_value" value="" >
231: <input type="hidden" name="pres_type" value="" >
232: <input type="hidden" name="pres_marker" value="" >
233: ENDFORMINFO
234: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
235: my %incdomains;
236: my %inccourses;
237: foreach (values(%Apache::lonnet::hostdom)) {
238: $incdomains{$_}=1;
239: }
240: foreach (keys(%ENV)) {
241: if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
242: $inccourses{$1.'_'.$2}=1;
243: }
244: }
245: if ($uhome eq 'no_host') {
246: my $home_server_list=
247: '<option value="default" selected>default</option>'."\n".
248: &Apache::loncommon::home_server_option_list($ccdomain);
249:
250: my %lt=&Apache::lonlocal::texthash(
251: 'cnu' => "Create New User",
252: 'nu' => "New User",
253: 'id' => "in domain",
254: 'pd' => "Personal Data",
255: 'fn' => "First Name",
256: 'mn' => "Middle Name",
257: 'ln' => "Last Name",
258: 'gen' => "Generation",
259: 'idsn' => "ID/Student Number",
260: 'hs' => "Home Server",
261: 'lg' => "Login Data"
262: );
263: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
264: $r->print(<<ENDNEWUSER);
265: $dochead
266: <h1>$lt{'cnu'}</h1>
267: $forminfo
268: <h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
269: <script type="text/javascript" language="Javascript">
270: $loginscript
271: </script>
272: <input type='hidden' name='makeuser' value='1' />
273: <h3>$lt{'pd'}</h3>
274: <p>
275: <table>
276: <tr><td>$lt{'fn'} </td>
277: <td><input type='text' name='cfirst' size='15' /></td></tr>
278: <tr><td>$lt{'mn'} </td>
279: <td><input type='text' name='cmiddle' size='15' /></td></tr>
280: <tr><td>$lt{'ln'} </td>
281: <td><input type='text' name='clast' size='15' /></td></tr>
282: <tr><td>$lt{'gen'}$genhelp</td>
283: <td><input type='text' name='cgen' size='5' /></td></tr>
284: </table>
285: $lt{'idsn'} <input type='text' name='cstid' size='15' /></p>
286: $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
287: <hr />
288: <h3>$lt{'lg'}</h3>
289: <p>$generalrule </p>
290: <p>$authformkrb </p>
291: <p>$authformint </p>
292: <p>$authformfsys</p>
293: <p>$authformloc </p>
294: ENDNEWUSER
295: } else { # user already exists
296: my %lt=&Apache::lonlocal::texthash(
297: 'cup' => "Change User Privileges",
298: 'usr' => "User",
299: 'id' => "in domain",
300: 'fn' => "first name",
301: 'mn' => "middle name",
302: 'ln' => "last name",
303: 'gen' => "generation"
304: );
305: $r->print(<<ENDCHANGEUSER);
306: $dochead
307: <h1>$lt{'cup'}</h1>
308: $forminfo
309: <h2>$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
310: ENDCHANGEUSER
311: # Get the users information
312: my %userenv = &Apache::lonnet::get('environment',
313: ['firstname','middlename','lastname','generation'],
314: $ccdomain,$ccuname);
315: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
316: $r->print(<<END);
317: <hr />
318: <table border="2">
319: <tr>
320: <th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th>
321: </tr>
322: <tr>
323: END
324: foreach ('firstname','middlename','lastname','generation') {
325: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
326: $r->print(<<"END");
327: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
328: END
329: } else {
330: $r->print('<td>'.$userenv{$_}.'</td>');
331: }
332: }
333: $r->print(<<END);
334: </tr>
335: </table>
336: END
337: # Build up table of user roles to allow revocation of a role.
338: my ($tmp) = keys(%rolesdump);
339: unless ($tmp =~ /^(con_lost|error)/i) {
340: my $now=time;
341: my %lt=&Apache::lonlocal::texthash(
342: 'rer' => "Revoke Existing Roles",
343: 'rev' => "Revoke",
344: 'del' => "Delete",
345: 'ren' => "Re-Enable",
346: 'rol' => "Role",
347: 'ext' => "Extent",
348: 'sta' => "Start",
349: 'end' => "End"
350: );
351: $r->print(<<END);
352: <hr />
353: <h3>$lt{'rer'}</h3>
354: <table>
355: <tr><th>$lt{'rev'}</th><th>$lt{'ren'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
356: END
357: my (%roletext,%sortrole,%roleclass);
358: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
359: my $b1=join('_',(split('_',$b))[1,0]);
360: return $a1 cmp $b1;
361: } keys(%rolesdump)) {
362: next if ($area =~ /^rolesdef/);
363: my $envkey=$area;
364: my $role = $rolesdump{$area};
365: my $thisrole=$area;
366: $area =~ s/\_\w\w$//;
367: my ($role_code,$role_end_time,$role_start_time) =
368: split(/_/,$role);
369: # Is this a custom role? Get role owner and title.
370: my ($croleudom,$croleuname,$croletitle)=
371: ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
372: my $bgcol='ffffff';
373: my $allowed=0;
374: my $delallowed=0;
375: my $sortkey=$role_code;
376: my $class='Unknown';
377: if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
378: $class='Course';
379: my ($coursedom,$coursedir) = ($1,$2);
380: $sortkey.="\0$1";
381: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
382: my %coursedata=
383: &Apache::lonnet::coursedescription($1.'_'.$2);
384: my $carea;
385: if (defined($coursedata{'description'})) {
386: $carea=$coursedata{'description'}.
387: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
388: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
389: $sortkey.="\0".$coursedata{'description'};
390: } else {
391: $carea=&mt('Unavailable course').': '.$area;
392: $sortkey.="\0".&mt('Unavailable course').': '.$area;
393: }
394: $inccourses{$1.'_'.$2}=1;
395: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
396: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
397: $allowed=1;
398: }
399: if ((&Apache::lonnet::allowed('dro',$1)) ||
400: (&Apache::lonnet::allowed('dro',$ccdomain))) {
401: $delallowed=1;
402: }
403: # - custom role. Needs more info, too
404: if ($croletitle) {
405: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
406: $allowed=1;
407: $thisrole.='.'.$role_code;
408: }
409: }
410: # Compute the background color based on $area
411: $bgcol=$1.'_'.$2;
412: $bgcol=~s/[^7-9a-e]//g;
413: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
414: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
415: $carea.='<br>Section/Group: '.$3;
416: $sortkey.="\0$3";
417: }
418: $area=$carea;
419: } else {
420: $sortkey.="\0".$area;
421: # Determine if current user is able to revoke privileges
422: if ($area=~ /^\/(\w+)\//) {
423: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
424: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
425: $allowed=1;
426: }
427: if (((&Apache::lonnet::allowed('dro',$1)) ||
428: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
429: ($role_code ne 'dc')) {
430: $delallowed=1;
431: }
432: } else {
433: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
434: $allowed=1;
435: }
436: }
437: if ($role_code eq 'ca' || $role_code eq 'au') {
438: $class='Construction Space';
439: } elsif ($role_code eq 'su') {
440: $class='System';
441: } else {
442: $class='Domain';
443: }
444: }
445: if ($role_code eq 'ca') {
446: $area=~/\/(\w+)\/(\w+)/;
447: if (&authorpriv($2,$1)) {
448: $allowed=1;
449: } else {
450: $allowed=0;
451: }
452: }
453: $bgcol='77FF77';
454: my $row = '';
455: $row.='<tr bgcolor="#'.$bgcol.'"><td>';
456: my $active=1;
457: $active=0 if (($role_end_time) && ($now>$role_end_time));
458: if (($active) && ($allowed)) {
459: $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
460: } else {
461: if ($active) {
462: $row.=' ';
463: } else {
464: $row.=&mt('expired or revoked');
465: }
466: }
467: $row.='</td><td>';
468: if ($allowed && !$active) {
469: $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
470: } else {
471: $row.=' ';
472: }
473: $row.='</td><td>';
474: if ($delallowed) {
475: $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
476: } else {
477: $row.=' ';
478: }
479: my $plaintext='';
480: unless ($croletitle) {
481: $plaintext=&Apache::lonnet::plaintext($role_code);
482: } else {
483: $plaintext=
484: "Customrole '$croletitle' defined by $croleuname\@$croleudom";
485: }
486: $row.= '</td><td>'.$plaintext.
487: '</td><td>'.$area.
488: '</td><td>'.($role_start_time?localtime($role_start_time)
489: : ' ' ).
490: '</td><td>'.($role_end_time ?localtime($role_end_time)
491: : ' ' )
492: ."</td></tr>\n";
493: $sortrole{$sortkey}=$envkey;
494: $roletext{$envkey}=$row;
495: $roleclass{$envkey}=$class;
496: #$r->print($row);
497: } # end of foreach (table building loop)
498: foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
499: my $output;
500: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
501: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
502: $output.=$roletext{$sortrole{$which}};
503: }
504: }
505: if (defined($output)) {
506: $r->print("<tr bgcolor='#BBffBB'>".
507: "<td align='center' colspan='7'>".&mt($type)."</td>");
508: }
509: $r->print($output);
510: }
511: $r->print('</table>');
512: } # End of unless
513: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
514: if ($currentauth=~/^krb(4|5):/) {
515: $currentauth=~/^krb(4|5):(.*)/;
516: my $krbdefdom=$1;
517: my %param = ( formname => 'document.cu',
518: kerb_def_dom => $krbdefdom
519: );
520: $loginscript = &Apache::loncommon::authform_header(%param);
521: }
522: # Check for a bad authentication type
523: unless ($currentauth=~/^krb(4|5):/ or
524: $currentauth=~/^unix:/ or
525: $currentauth=~/^internal:/ or
526: $currentauth=~/^localauth:/
527: ) { # bad authentication scheme
528: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
529: my %lt=&Apache::lonlocal::texthash(
530: 'err' => "ERROR",
531: 'uuas' => "This user has an unrecognized authentication scheme",
532: 'sldb' => "Please specify login data below",
533: 'ld' => "Login Data"
534: );
535: $r->print(<<ENDBADAUTH);
536: <hr />
537: <script type="text/javascript" language="Javascript">
538: $loginscript
539: </script>
540: <font color='#ff0000'>$lt{'err'}:</font>
541: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
542: <h3>$lt{'ld'}</h3>
543: <p>$generalrule</p>
544: <p>$authformkrb</p>
545: <p>$authformint</p>
546: <p>$authformfsys</p>
547: <p>$authformloc</p>
548: ENDBADAUTH
549: } else {
550: # This user is not allowed to modify the users
551: # authentication scheme, so just notify them of the problem
552: my %lt=&Apache::lonlocal::texthash(
553: 'err' => "ERROR",
554: 'uuas' => "This user has an unrecognized authentication scheme",
555: 'adcs' => "Please alert a domain coordinator of this situation"
556: );
557: $r->print(<<ENDBADAUTH);
558: <hr />
559: <script type="text/javascript" language="Javascript">
560: $loginscript
561: </script>
562: <font color="#ff0000"> $lt{'err'}: </font>
563: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
564: <hr />
565: ENDBADAUTH
566: }
567: } else { # Authentication type is valid
568: my $authformcurrent='';
569: my $authform_other='';
570: if ($currentauth=~/^krb(4|5):/) {
571: $authformcurrent=$authformkrb;
572: $authform_other="<p>$authformint</p>\n".
573: "<p>$authformfsys</p><p>$authformloc</p>";
574: }
575: elsif ($currentauth=~/^internal:/) {
576: $authformcurrent=$authformint;
577: $authform_other="<p>$authformkrb</p>".
578: "<p>$authformfsys</p><p>$authformloc</p>";
579: }
580: elsif ($currentauth=~/^unix:/) {
581: $authformcurrent=$authformfsys;
582: $authform_other="<p>$authformkrb</p>".
583: "<p>$authformint</p><p>$authformloc;</p>";
584: }
585: elsif ($currentauth=~/^localauth:/) {
586: $authformcurrent=$authformloc;
587: $authform_other="<p>$authformkrb</p>".
588: "<p>$authformint</p><p>$authformfsys</p>";
589: }
590: $authformcurrent.=' <i>(will override current values)</i><br />';
591: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
592: # Current user has login modification privileges
593: my %lt=&Apache::lonlocal::texthash(
594: 'ccld' => "Change Current Login Data",
595: 'enld' => "Enter New Login Data"
596: );
597: $r->print(<<ENDOTHERAUTHS);
598: <hr />
599: <script type="text/javascript" language="Javascript">
600: $loginscript
601: </script>
602: <h3>$lt{'ccld'}</h3>
603: <p>$generalrule</p>
604: <p>$authformnop</p>
605: <p>$authformcurrent</p>
606: <h3>$lt{'enld'}</h3>
607: $authform_other
608: ENDOTHERAUTHS
609: }
610: } ## End of "check for bad authentication type" logic
611: } ## End of new user/old user logic
612: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
613: #
614: # Co-Author
615: #
616: if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
617: ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
618: # No sense in assigning co-author role to yourself
619: my $cuname=$ENV{'user.name'};
620: my $cudom=$ENV{'request.role.domain'};
621: my %lt=&Apache::lonlocal::texthash(
622: 'cs' => "Construction Space",
623: 'act' => "Activate",
624: 'rol' => "Role",
625: 'ext' => "Extent",
626: 'sta' => "Start",
627: 'end' => "End",
628: 'cau' => "Co-Author",
629: 'ssd' => "Set Start Date",
630: 'sed' => "Set End Date"
631: );
632: $r->print(<<ENDCOAUTH);
633: <h4>$lt{'cs'}</h4>
634: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
635: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
636: <tr>
637: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
638: <td>$lt{'cau'}</td>
639: <td>$cudom\_$cuname</td>
640: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
641: <a href=
642: "javascript:pjump('date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'ssd'}</a></td>
643: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
644: <a href=
645: "javascript:pjump('date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset')">$lt{'sed'}</a></td>
646: </tr>
647: </table>
648: ENDCOAUTH
649: }
650: #
651: # Domain level
652: #
653: $r->print('<h4>'.&mt('Domain Level').'</h4>'.
654: '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
655: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>');
656: foreach ( sort( keys(%incdomains))) {
657: my $thisdomain=$_;
658: foreach ('dc','li','dg','au','sc') {
659: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
660: my $plrole=&Apache::lonnet::plaintext($_);
661: my %lt=&Apache::lonlocal::texthash(
662: 'ssd' => "Set Start Date",
663: 'sed' => "Set End Date"
664: );
665: $r->print(<<ENDDROW);
666: <tr>
667: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
668: <td>$plrole</td>
669: <td>$thisdomain</td>
670: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
671: <a href=
672: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
673: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
674: <a href=
675: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
676: </tr>
677: ENDDROW
678: }
679: }
680: }
681: $r->print('</table>');
682: #
683: # Course level
684: #
685: $r->print(&course_level_table(%inccourses));
686: $r->print("<hr /><input type=submit value=\"".&mt('Modify User')."\">\n");
687: $r->print("</form></body></html>");
688: }
689:
690: # ================================================================= Phase Three
691: sub update_user_data {
692: my $r=shift;
693: my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
694: $ENV{'form.ccdomain'});
695: # Error messages
696: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
697: my $end = '</body></html>';
698: # Print header
699: $r->print(<<ENDTHREEHEAD);
700: <html>
701: <head>
702: <title>The LearningOnline Network with CAPA</title>
703: </head>
704: ENDTHREEHEAD
705: my $title;
706: if (exists($ENV{'form.makeuser'})) {
707: $title='Set Privileges for New User';
708: } else {
709: $title='Modify User Privileges';
710: }
711: $r->print(&Apache::loncommon::bodytag($title));
712: # Check Inputs
713: if (! $ENV{'form.ccuname'} ) {
714: $r->print($error.&mt('No login name specified').'.'.$end);
715: return;
716: }
717: if ( $ENV{'form.ccuname'} =~/\W/) {
718: $r->print($error.&mt('Invalid login name').'. '.
719: &mt('Only letters, numbers, and underscores are valid').'.'.
720: $end);
721: return;
722: }
723: if (! $ENV{'form.ccdomain'} ) {
724: $r->print($error.&mt('No domain specified').'.'.$end);
725: return;
726: }
727: if ( $ENV{'form.ccdomain'} =~/\W/) {
728: $r->print($error.&mt ('Invalid domain name').'. '.
729: &mt('Only letters, numbers, and underscores are valid').'.'.
730: $end);
731: return;
732: }
733: if (! exists($ENV{'form.makeuser'})) {
734: # Modifying an existing user, so check the validity of the name
735: if ($uhome eq 'no_host') {
736: $r->print($error.&mt('Unable to determine home server for ').
737: $ENV{'form.ccuname'}.&mt(' in domain ').
738: $ENV{'form.ccdomain'}.'.');
739: return;
740: }
741: }
742: # Determine authentication method and password for the user being modified
743: my $amode='';
744: my $genpwd='';
745: if ($ENV{'form.login'} eq 'krb') {
746: $amode='krb';
747: $amode.=$ENV{'form.krbver'};
748: $genpwd=$ENV{'form.krbarg'};
749: } elsif ($ENV{'form.login'} eq 'int') {
750: $amode='internal';
751: $genpwd=$ENV{'form.intarg'};
752: } elsif ($ENV{'form.login'} eq 'fsys') {
753: $amode='unix';
754: $genpwd=$ENV{'form.fsysarg'};
755: } elsif ($ENV{'form.login'} eq 'loc') {
756: $amode='localauth';
757: $genpwd=$ENV{'form.locarg'};
758: $genpwd=" " if (!$genpwd);
759: } elsif (($ENV{'form.login'} eq 'nochange') ||
760: ($ENV{'form.login'} eq '' )) {
761: # There is no need to tell the user we did not change what they
762: # did not ask us to change.
763: # If they are creating a new user but have not specified login
764: # information this will be caught below.
765: } else {
766: $r->print($error.&mt('Invalid login mode or password').$end);
767: return;
768: }
769: if ($ENV{'form.makeuser'}) {
770: # Create a new user
771: my %lt=&Apache::lonlocal::texthash(
772: 'cru' => "Creating user",
773: 'id' => "in domain"
774: );
775: $r->print(<<ENDNEWUSERHEAD);
776: <h3>$lt{'cru'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h3>
777: ENDNEWUSERHEAD
778: # Check for the authentication mode and password
779: if (! $amode || ! $genpwd) {
780: $r->print($error.&mt('Invalid login mode or password').$end);
781: return;
782: }
783: # Determine desired host
784: my $desiredhost = $ENV{'form.hserver'};
785: if (lc($desiredhost) eq 'default') {
786: $desiredhost = undef;
787: } else {
788: my %home_servers = &Apache::loncommon::get_library_servers
789: ($ENV{'form.ccdomain'});
790: if (! exists($home_servers{$desiredhost})) {
791: $r->print($error.&mt('Invalid home server specified'));
792: return;
793: }
794: }
795: # Call modifyuser
796: my $result = &Apache::lonnet::modifyuser
797: ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
798: $amode,$genpwd,$ENV{'form.cfirst'},
799: $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
800: undef,$desiredhost
801: );
802: $r->print(&mt('Generating user').': '.$result);
803: my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
804: $ENV{'form.ccdomain'});
805: $r->print('<br />'.&mt('Home server').': '.$home.' '.
806: $Apache::lonnet::libserv{$home});
807: } elsif (($ENV{'form.login'} ne 'nochange') &&
808: ($ENV{'form.login'} ne '' )) {
809: # Modify user privileges
810: my %lt=&Apache::lonlocal::texthash(
811: 'usr' => "User",
812: 'id' => "in domain"
813: );
814: $r->print(<<ENDMODIFYUSERHEAD);
815: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
816: ENDMODIFYUSERHEAD
817: if (! $amode || ! $genpwd) {
818: $r->print($error.'Invalid login mode or password'.$end);
819: return;
820: }
821: # Only allow authentification modification if the person has authority
822: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
823: $r->print('Modifying authentication: '.
824: &Apache::lonnet::modifyuserauth(
825: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
826: $amode,$genpwd));
827: $r->print('<br>'.&mt('Home server').': '.&Apache::lonnet::homeserver
828: ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
829: } else {
830: # Okay, this is a non-fatal error.
831: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
832: }
833: }
834: ##
835: if (! $ENV{'form.makeuser'} ) {
836: # Check for need to change
837: my %userenv = &Apache::lonnet::get
838: ('environment',['firstname','middlename','lastname','generation'],
839: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
840: my ($tmp) = keys(%userenv);
841: if ($tmp =~ /^(con_lost|error)/i) {
842: %userenv = ();
843: }
844: # Check to see if we need to change user information
845: foreach ('firstname','middlename','lastname','generation') {
846: # Strip leading and trailing whitespace
847: $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
848: }
849: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) &&
850: ($ENV{'form.cfirstname'} ne $userenv{'firstname'} ||
851: $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
852: $ENV{'form.clastname'} ne $userenv{'lastname'} ||
853: $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
854: # Make the change
855: my %changeHash;
856: $changeHash{'firstname'} = $ENV{'form.cfirstname'};
857: $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
858: $changeHash{'lastname'} = $ENV{'form.clastname'};
859: $changeHash{'generation'} = $ENV{'form.cgeneration'};
860: my $putresult = &Apache::lonnet::put
861: ('environment',\%changeHash,
862: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
863: if ($putresult eq 'ok') {
864: # Tell the user we changed the name
865: my %lt=&Apache::lonlocal::texthash(
866: 'uic' => "User Information Changed",
867: 'frst' => "first",
868: 'mddl' => "middle",
869: 'lst' => "last",
870: 'gen' => "generation",
871: 'prvs' => "Previous",
872: 'chto' => "Changed To"
873: );
874: $r->print(<<"END");
875: <table border="2">
876: <caption>$lt{'uic'}</caption>
877: <tr><th> </th>
878: <th>$lt{'frst'}</th>
879: <th>$lt{'mddl'}</th>
880: <th>$lt{'lst'}</th>
881: <th>$lt{'gen'}</th></tr>
882: <tr><td>$lt{'prvs'}</td>
883: <td>$userenv{'firstname'} </td>
884: <td>$userenv{'middlename'} </td>
885: <td>$userenv{'lastname'} </td>
886: <td>$userenv{'generation'} </td></tr>
887: <tr><td>$lt{'chto'}</td>
888: <td>$ENV{'form.cfirstname'} </td>
889: <td>$ENV{'form.cmiddlename'} </td>
890: <td>$ENV{'form.clastname'} </td>
891: <td>$ENV{'form.cgeneration'} </td></tr>
892: </table>
893: END
894: } else { # error occurred
895: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
896: $ENV{'form.ccuname'}." ".&mt('in domain')." ".
897: $ENV{'form.ccdomain'}."</h2>");
898: }
899: } else { # End of if ($ENV ... ) logic
900: # They did not want to change the users name but we can
901: # still tell them what the name is
902: my %lt=&Apache::lonlocal::texthash(
903: 'usr' => "User",
904: 'id' => "in domain",
905: 'gen' => "Generation"
906: );
907: $r->print(<<"END");
908: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
909: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
910: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
911: END
912: }
913: }
914: ##
915: my $now=time;
916: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
917: foreach (keys (%ENV)) {
918: next if (! $ENV{$_});
919: # Revoke roles
920: if ($_=~/^form\.rev/) {
921: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
922: # Revoke standard role
923: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
924: &Apache::lonnet::revokerole($ENV{'form.ccdomain'},
925: $ENV{'form.ccuname'},$1,$2).'</b><br>');
926: if ($2 eq 'st') {
927: $1=~/^\/(\w+)\/(\w+)/;
928: my $cid=$1.'_'.$2;
929: $r->print(&mt('Drop from classlist').': <b>'.
930: &Apache::lonnet::critical('put:'.
931: $ENV{'course.'.$cid.'.domain'}.':'.
932: $ENV{'course.'.$cid.'.num'}.':classlist:'.
933: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
934: $ENV{'form.ccdomain'}).'='.
935: &Apache::lonnet::escape($now.':'),
936: $ENV{'course.'.$cid.'.home'}).'</b><br>');
937: }
938: }
939: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
940: # Revoke custom role
941: $r->print(&mt('Revoking custom role').
942: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
943: &Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'},
944: $ENV{'form.ccuname'},$1,$2,$3,$4).
945: '</b><br>');
946: }
947: } elsif ($_=~/^form\.del/) {
948: if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
949: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
950: &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
951: $ENV{'form.ccuname'},$1,$2,$now,0,1).'<br>');
952: if ($2 eq 'st') {
953: $1=~/^\/(\w+)\/(\w+)/;
954: my $cid=$1.'_'.$2;
955: $r->print(&mt('Drop from classlist').': <b>'.
956: &Apache::lonnet::critical('put:'.
957: $ENV{'course.'.$cid.'.domain'}.':'.
958: $ENV{'course.'.$cid.'.num'}.':classlist:'.
959: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
960: $ENV{'form.ccdomain'}).'='.
961: &Apache::lonnet::escape($now.':'),
962: $ENV{'course.'.$cid.'.home'}).'</b><br>');
963: }
964: }
965: } elsif ($_=~/^form\.ren/) {
966: if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
967: my $result=&Apache::lonnet::assignrole($ENV{'form.ccdomain'},
968: $ENV{'form.ccuname'},$1,$2,0,$now);
969: $r->print(&mt('Re-Enabling [_1] in [_2]: [_3]',
970: $2,$1,$result).'<br />');
971: if ($2 eq 'st') {
972: $1=~/^\/(\w+)\/(\w+)/;
973: my $cid=$1.'_'.$2;
974: $r->print(&mt('Add to classlist').': <b>'.
975: &Apache::lonnet::critical(
976: 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
977: $ENV{'course.'.$cid.'.num'}.':classlist:'.
978: &Apache::lonnet::escape(
979: $ENV{'form.ccuname'}.':'.
980: $ENV{'form.ccdomain'} ).'='.
981: &Apache::lonnet::escape(':'.$now),
982: $ENV{'course.'.$cid.'.home'})
983: .'</b><br>');
984: }
985: }
986: } elsif ($_=~/^form\.act/) {
987: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
988: # Activate a custom role
989: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
990: my $url='/'.$one.'/'.$two;
991: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
992: $ENV{'form.sec_'.$full}=~s/\W//g;
993: if ($ENV{'form.sec_'.$full}) {
994: $url.='/'.$ENV{'form.sec_'.$full};
995: }
996:
997: my $start = ( $ENV{'form.start_'.$full} ?
998: $ENV{'form.start_'.$full} :
999: $now );
1000: my $end = ( $ENV{'form.end_'.$full} ?
1001: $ENV{'form.end_'.$full} :
1002: 0 );
1003:
1004: $r->print(&mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1005: ($start?', '.&mt('starting').' '.localtime($start):'').
1006: ($end?', ending '.localtime($end):'').': <b>'.
1007: &Apache::lonnet::assigncustomrole(
1008: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start).
1009: '</b><br>');
1010: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
1011: # Activate roles for sections with 3 id numbers
1012: # set start, end times, and the url for the class
1013: my ($one,$two,$three)=($1,$2,$3);
1014: my $start = ( $ENV{'form.start_'.$one.'_'.$two.'_'.$three} ?
1015: $ENV{'form.start_'.$one.'_'.$two.'_'.$three} :
1016: $now );
1017: my $end = ( $ENV{'form.end_'.$one.'_'.$two.'_'.$three} ?
1018: $ENV{'form.end_'.$one.'_'.$two.'_'.$three} :
1019: 0 );
1020: my $url='/'.$one.'/'.$two;
1021: $ENV{'form.sec_'.$one.'_'.$two.'_'.$three}=~s/\W//g;
1022: if ($ENV{'form.sec_'.$one.'_'.$two.'_'.$three}) {
1023: $url.='/'.$ENV{'form.sec_'.$one.'_'.$two.'_'.$three};
1024: }
1025: # Assign the role and report it
1026: $r->print(&mt('Assigning').' '.$three.' in '.$url.
1027: ($start?', '.&mt('starting').' '.localtime($start):'').
1028: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1029: &Apache::lonnet::assignrole(
1030: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
1031: $url,$three,$end,$start).
1032: '</b><br>');
1033: # Handle students differently
1034: if ($three eq 'st') {
1035: $url=~/^\/(\w+)\/(\w+)/;
1036: my $cid=$one.'_'.$two;
1037: $r->print(&mt('Add to classlist').': <b>'.
1038: &Apache::lonnet::critical(
1039: 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
1040: $ENV{'course.'.$cid.'.num'}.':classlist:'.
1041: &Apache::lonnet::escape(
1042: $ENV{'form.ccuname'}.':'.
1043: $ENV{'form.ccdomain'} ).'='.
1044: &Apache::lonnet::escape($end.':'.$start),
1045: $ENV{'course.'.$cid.'.home'})
1046: .'</b><br>');
1047: }
1048: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1049: # Activate roles for sections with two id numbers
1050: # set start, end times, and the url for the class
1051: my $start = ( $ENV{'form.start_'.$1.'_'.$2} ?
1052: $ENV{'form.start_'.$1.'_'.$2} :
1053: $now );
1054: my $end = ( $ENV{'form.end_'.$1.'_'.$2} ?
1055: $ENV{'form.end_'.$1.'_'.$2} :
1056: 0 );
1057: my $url='/'.$1.'/';
1058: # Assign the role and report it.
1059: $r->print(&mt('Assigning').' '.$2.' in '.$url.': '.
1060: ($start?', '.&mt('starting').' '.localtime($start):'').
1061: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1062: &Apache::lonnet::assignrole(
1063: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
1064: $url,$2,$end,$start)
1065: .'</b><br>');
1066: } else {
1067: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br>');
1068: }
1069: }
1070: } # End of foreach (keys(%ENV))
1071: # Flush the course logs so reverse user roles immediately updated
1072: &Apache::lonnet::flushcourselogs();
1073: $r->print('</body></html>');
1074: }
1075:
1076: # ========================================================== Custom Role Editor
1077:
1078: sub custom_role_editor {
1079: my $r=shift;
1080: my $rolename=$ENV{'form.rolename'};
1081:
1082: if ($rolename eq 'make new role') {
1083: $rolename=$ENV{'form.newrolename'};
1084: }
1085:
1086: $rolename=~s/[^A-Za-z0-9]//gs;
1087:
1088: unless ($rolename) {
1089: &print_username_entry_form($r);
1090: return;
1091: }
1092:
1093: $r->print(&Apache::loncommon::bodytag(
1094: 'Create Users, Change User Privileges').'<h2>');
1095: my $syspriv='';
1096: my $dompriv='';
1097: my $coursepriv='';
1098: my ($rdummy,$roledef)=
1099: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1100: # ------------------------------------------------------- Does this role exist?
1101: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1102: $r->print(&mt('Existing Role').' "');
1103: # ------------------------------------------------- Get current role privileges
1104: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1105: } else {
1106: $r->print(&mt('New Role').' "');
1107: $roledef='';
1108: }
1109: $r->print($rolename.'"</h2>');
1110: # ------------------------------------------------------- What can be assigned?
1111: my %full=();
1112: my %courselevel=();
1113: my %courselevelcurrent=();
1114: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1115: my ($priv,$restrict)=split(/\&/,$_);
1116: unless ($restrict) { $restrict='F'; }
1117: $courselevel{$priv}=$restrict;
1118: if ($coursepriv=~/\:$priv/) {
1119: $courselevelcurrent{$priv}=1;
1120: }
1121: $full{$priv}=1;
1122: }
1123: my %domainlevel=();
1124: my %domainlevelcurrent=();
1125: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1126: my ($priv,$restrict)=split(/\&/,$_);
1127: unless ($restrict) { $restrict='F'; }
1128: $domainlevel{$priv}=$restrict;
1129: if ($dompriv=~/\:$priv/) {
1130: $domainlevelcurrent{$priv}=1;
1131: }
1132: $full{$priv}=1;
1133: }
1134: my %systemlevel=();
1135: my %systemlevelcurrent=();
1136: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1137: my ($priv,$restrict)=split(/\&/,$_);
1138: unless ($restrict) { $restrict='F'; }
1139: $systemlevel{$priv}=$restrict;
1140: if ($syspriv=~/\:$priv/) {
1141: $systemlevelcurrent{$priv}=1;
1142: }
1143: $full{$priv}=1;
1144: }
1145: my %lt=&Apache::lonlocal::texthash(
1146: 'prv' => "Privilege",
1147: 'crl' => "Course Level",
1148: 'dml' => "Domain Level",
1149: 'ssl' => "System Level"
1150: );
1151: $r->print(<<ENDCCF);
1152: <form method="post">
1153: <input type="hidden" name="phase" value="set_custom_roles" />
1154: <input type="hidden" name="rolename" value="$rolename" />
1155: <table border="2">
1156: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1157: <th>$lt{'ssl'}</th></tr>
1158: ENDCCF
1159: foreach (sort keys %full) {
1160: $r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
1161: ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
1162: ($courselevelcurrent{$_}?'checked="1"':'').' />':' ').
1163: '</td><td>'.
1164: ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
1165: ($domainlevelcurrent{$_}?'checked="1"':'').' />':' ').
1166: '</td><td>'.
1167: ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
1168: ($systemlevelcurrent{$_}?'checked="1"':'').' />':' ').
1169: '</td></tr>');
1170: }
1171: $r->print(
1172: '<table><input type="submit" value="'.&mt('Define Role').'" /></form></body></html>');
1173: }
1174:
1175: # ---------------------------------------------------------- Call to definerole
1176: sub set_custom_role {
1177: my $r=shift;
1178:
1179: my $rolename=$ENV{'form.rolename'};
1180:
1181: $rolename=~s/[^A-Za-z0-9]//gs;
1182:
1183: unless ($rolename) {
1184: &print_username_entry_form($r);
1185: return;
1186: }
1187:
1188: $r->print(&Apache::loncommon::bodytag(
1189: 'Create Users, Change User Privileges').'<h2>');
1190: my ($rdummy,$roledef)=
1191: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1192: # ------------------------------------------------------- Does this role exist?
1193: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1194: $r->print(&mt('Existing Role').' "');
1195: } else {
1196: $r->print(&mt('New Role').' "');
1197: $roledef='';
1198: }
1199: $r->print($rolename.'"</h2>');
1200: # ------------------------------------------------------- What can be assigned?
1201: my $sysrole='';
1202: my $domrole='';
1203: my $courole='';
1204:
1205: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1206: my ($priv,$restrict)=split(/\&/,$_);
1207: unless ($restrict) { $restrict=''; }
1208: if ($ENV{'form.'.$priv.':c'}) {
1209: $courole.=':'.$_;
1210: }
1211: }
1212:
1213: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1214: my ($priv,$restrict)=split(/\&/,$_);
1215: unless ($restrict) { $restrict=''; }
1216: if ($ENV{'form.'.$priv.':d'}) {
1217: $domrole.=':'.$_;
1218: }
1219: }
1220:
1221: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1222: my ($priv,$restrict)=split(/\&/,$_);
1223: unless ($restrict) { $restrict=''; }
1224: if ($ENV{'form.'.$priv.':s'}) {
1225: $sysrole.=':'.$_;
1226: }
1227: }
1228: $r->print('<br />Defining Role: '.
1229: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1230: if ($ENV{'request.course.id'}) {
1231: my $url='/'.$ENV{'request.course.id'};
1232: $url=~s/\_/\//g;
1233: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1234: &Apache::lonnet::assigncustomrole($ENV{'user.domain'},
1235: $ENV{'user.name'},
1236: $url,
1237: $ENV{'user.domain'},
1238: $ENV{'user.name'},
1239: $rolename));
1240: }
1241: $r->print('</body></html>');
1242: }
1243:
1244: # ================================================================ Main Handler
1245: sub handler {
1246: my $r = shift;
1247:
1248: if ($r->header_only) {
1249: &Apache::loncommon::content_type($r,'text/html');
1250: $r->send_http_header;
1251: return OK;
1252: }
1253:
1254: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
1255: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
1256: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
1257: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
1258: (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
1259: (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
1260: &Apache::loncommon::content_type($r,'text/html');
1261: $r->send_http_header;
1262: unless ($ENV{'form.phase'}) {
1263: &print_username_entry_form($r);
1264: }
1265: if ($ENV{'form.phase'} eq 'get_user_info') {
1266: &print_user_modification_page($r);
1267: } elsif ($ENV{'form.phase'} eq 'update_user_data') {
1268: &update_user_data($r);
1269: } elsif ($ENV{'form.phase'} eq 'selected_custom_edit') {
1270: &custom_role_editor($r);
1271: } elsif ($ENV{'form.phase'} eq 'set_custom_roles') {
1272: &set_custom_role($r);
1273: }
1274: } else {
1275: $ENV{'user.error.msg'}=
1276: "/adm/createuser:mau:0:0:Cannot modify user data";
1277: return HTTP_NOT_ACCEPTABLE;
1278: }
1279: return OK;
1280: }
1281:
1282: #-------------------------------------------------- functions for &phase_two
1283: sub course_level_table {
1284: my %inccourses = @_;
1285: my $table = '';
1286: # Custom Roles?
1287:
1288: my %customroles=&my_custom_roles();
1289:
1290: foreach (sort( keys(%inccourses))) {
1291: my $thiscourse=$_;
1292: my $protectedcourse=$_;
1293: $thiscourse=~s:_:/:g;
1294: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1295: my $area=$coursedata{'description'};
1296: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1297: my $bgcol=$thiscourse;
1298: $bgcol=~s/[^7-9a-e]//g;
1299: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1300: my ($domain)=split(/\//,$thiscourse);
1301: foreach ('st','ta','ep','ad','in','cc') {
1302: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1303: my $plrole=&Apache::lonnet::plaintext($_);
1304: $table .= <<ENDEXTENT;
1305: <tr bgcolor="#$bgcol">
1306: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1307: <td>$plrole</td>
1308: <td>$area<br />Domain: $domain</td>
1309: ENDEXTENT
1310: if ($_ ne 'cc') {
1311: $table .= <<ENDSECTION;
1312: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
1313: ENDSECTION
1314: } else {
1315: $table .= <<ENDSECTION;
1316: <td> </td>
1317: ENDSECTION
1318: }
1319: my %lt=&Apache::lonlocal::texthash(
1320: 'ssd' => "Set Start Date",
1321: 'sed' => "Set End Date"
1322: );
1323: $table .= <<ENDTIMEENTRY;
1324: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1325: <a href=
1326: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1327: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1328: <a href=
1329: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1330: ENDTIMEENTRY
1331: $table.= "</tr>\n";
1332: }
1333: }
1334: foreach (sort keys %customroles) {
1335: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1336: my $plrole=$_;
1337: my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}.
1338: '_'.$ENV{'user.name'}.'_'.$plrole;
1339: my %lt=&Apache::lonlocal::texthash(
1340: 'ssd' => "Set Start Date",
1341: 'sed' => "Set End Date"
1342: );
1343: $table .= <<ENDENTRY;
1344: <tr bgcolor="#$bgcol">
1345: <td><input type="checkbox" name="act_$customrole"></td>
1346: <td>$plrole</td>
1347: <td>$area</td>
1348: <td><input type="text" size="5" name="sec_$customrole"></td>
1349: <td><input type=hidden name="start_$customrole" value=''>
1350: <a href=
1351: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1352: <td><input type=hidden name="end_$customrole" value=''>
1353: <a href=
1354: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td></tr>
1355: ENDENTRY
1356: }
1357: }
1358: }
1359: return '' if ($table eq ''); # return nothing if there is nothing
1360: # in the table
1361: my %lt=&Apache::lonlocal::texthash(
1362: 'crl' => "Course Level",
1363: 'act' => "Activate",
1364: 'rol' => "Role",
1365: 'ext' => "Extent",
1366: 'grs' => "Group/Section",
1367: 'sta' => "Start",
1368: 'end' => "End"
1369: );
1370: my $result = <<ENDTABLE;
1371: <h4>$lt{'crl'}</h4>
1372: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1373: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1374: $table
1375: </table>
1376: ENDTABLE
1377: return $result;
1378: }
1379: #---------------------------------------------- end functions for &phase_two
1380:
1381: #--------------------------------- functions for &phase_two and &phase_three
1382:
1383: #--------------------------end of functions for &phase_two and &phase_three
1384:
1385: 1;
1386: __END__
1387:
1388:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>