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