File:
[LON-CAPA] /
loncom /
interface /
loncreateuser.pm
Revision
1.117:
download - view:
text,
annotated -
select for diffs
Thu May 18 01:08:51 2006 UTC (18 years, 4 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
&coursegroups() and &get_group_settings() moved to longroup.pm, which contains general utility functions for asking about groups. Also contains &group_changes() which is used to add/drop group memberships as a result of role changes, as determined by group settings for auto-add and auto-drop. 'none' and 'all' are now reserved words which may not be used as section or group names, so they can be used instead of _all and _none when specifying auto-add and auto-drop settings for all sections or no section roles.
1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.117 2006/05/18 01:08:51 raeburn 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: use Apache::longroup;
68:
69: my $loginscript; # piece of javascript used in two separate instances
70: my $generalrule;
71: my $authformnop;
72: my $authformkrb;
73: my $authformint;
74: my $authformfsys;
75: my $authformloc;
76:
77: sub initialize_authen_forms {
78: my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
79: $krbdefdom= uc($krbdefdom);
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: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
113: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
114: return 1;
115: }
116:
117: # =================================================================== Phase one
118:
119: sub print_username_entry_form {
120: my ($r) = @_;
121: my $defdom=$env{'request.role.domain'};
122: my @domains = &Apache::loncommon::get_domains();
123: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
124: my $selscript=&Apache::loncommon::studentbrowser_javascript();
125: my $start_page =
126: &Apache::loncommon::start_page('Create Users, Change User Privileges',
127: $selscript);
128:
129: my $sellink=&Apache::loncommon::selectstudent_link
130: ('crtuser','ccuname','ccdomain');
131: my %existingroles=&my_custom_roles();
132: my $choice=&Apache::loncommon::select_form('make new role','rolename',
133: ('make new role' => 'Generate new role ...',%existingroles));
134: my %lt=&Apache::lonlocal::texthash(
135: 'siur' => "Set Individual User Roles",
136: 'usr' => "Username",
137: 'dom' => "Domain",
138: 'usrr' => "User Roles",
139: 'ecrp' => "Edit Custom Role Privileges",
140: 'nr' => "Name of Role",
141: 'cre' => "Custom Role Editor"
142: );
143: my $help = &Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
144: my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
145: my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
146: $r->print(<<"ENDDOCUMENT");
147: $start_page
148: <form action="/adm/createuser" method="post" name="crtuser">
149: <input type="hidden" name="phase" value="get_user_info">
150: <h2>$lt{siur}$helpsiur</h2>
151: <table>
152: <tr><td>$lt{usr}:</td><td><input type="text" size="15" name="ccuname">
153: </td><td rowspan="2">$sellink</td></tr><tr><td>
154: $lt{'dom'}:</td><td>$domform</td></tr>
155: </table>
156: <input name="userrole" type="submit" value="$lt{usrr}" />
157: </form>
158: ENDDOCUMENT
159: if (&Apache::lonnet::allowed('mcr','/')) {
160: $r->print(<<ENDCUSTOM);
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: </form>
167: ENDCUSTOM
168: }
169: $r->print(&Apache::loncommon::end_page());
170: }
171:
172:
173: sub user_modification_js {
174: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
175:
176: return <<END;
177: <script type="text/javascript" language="Javascript">
178:
179: function pclose() {
180: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
181: "height=350,width=350,scrollbars=no,menubar=no");
182: parmwin.close();
183: }
184:
185: $pjump_def
186: $dc_setcourse_code
187:
188: function dateset() {
189: eval("document.cu."+document.cu.pres_marker.value+
190: ".value=document.cu.pres_value.value");
191: pclose();
192: }
193:
194: $nondc_setsection_code
195:
196: function setSections() {
197: var re1 = /^currsec_/;
198: var groups = new Array($groupslist);
199: for (var i=0;i<document.cu.elements.length;i++) {
200: var str = document.cu.elements[i].name;
201: var checkcurr = str.match(re1);
202: if (checkcurr != null) {
203: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
204: if (document.cu.elements[i-1].checked == true) {
205: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
206: match = re2.exec(str);
207: var role = match[1];
208: if (role == 'cc') {
209: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
210: }
211: else {
212: var sections = '';
213: var numsec = 0;
214: var sections;
215: for (var j=0; j<document.cu.elements[i].length; j++) {
216: if (document.cu.elements[i].options[j].selected == true ) {
217: if (document.cu.elements[i].options[j].value != "") {
218: if (numsec == 0) {
219: if (document.cu.elements[i].options[j].value != "") {
220: sections = document.cu.elements[i].options[j].value;
221: numsec ++;
222: }
223: }
224: else {
225: sections = sections + "," + document.cu.elements[i].options[j].value
226: numsec ++;
227: }
228: }
229: }
230: }
231: if (numsec > 0) {
232: if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
233: sections = sections + "," + document.cu.elements[i+1].value;
234: }
235: }
236: else {
237: sections = document.cu.elements[i+1].value;
238: }
239: var newseclist = document.cu.elements[i+1].value;
240: var newsecs = new Array();
241: if (newseclist != null && newseclist != "") {
242: newsecs = newseclist.split(/,/g);
243: numsec = numsec + newsecs.length;
244: }
245: if ((role == 'st') && (numsec > 1)) {
246: alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
247: return;
248: }
249: else {
250: for (var j=0; j<newsecs.length; j++) {
251: if ((newsecs[j] == 'all') ||
252: (newsecs[j] == 'none')) {
253: alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
254: return;
255: }
256: for (var k=0; k<groups.length; k++) {
257: if (newsecs[j] == groups[k]) {
258: alert("'"+newsecs[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
259: return;
260: }
261: }
262: }
263: document.cu.elements[i+2].value = sections;
264: }
265: }
266: }
267: }
268: }
269: document.cu.submit();
270: }
271: </script>
272: END
273: }
274:
275: # =================================================================== Phase two
276: sub print_user_modification_page {
277: my $r=shift;
278: my $ccuname=$env{'form.ccuname'};
279: my $ccdomain=$env{'form.ccdomain'};
280:
281: $ccuname=~s/\W//g;
282: $ccdomain=~s/\W//g;
283:
284: unless (($ccuname) && ($ccdomain)) {
285: &print_username_entry_form($r);
286: return;
287: }
288:
289: my $defdom=$env{'request.role.domain'};
290:
291: my ($krbdef,$krbdefdom) =
292: &Apache::loncommon::get_kerberos_defaults($defdom);
293:
294: my %param = ( formname => 'document.cu',
295: kerb_def_dom => $krbdefdom,
296: kerb_def_auth => $krbdef
297: );
298: $loginscript = &Apache::loncommon::authform_header(%param);
299: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
300:
301: $ccuname=~s/\W//g;
302: $ccdomain=~s/\W//g;
303: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
304: my $dc_setcourse_code = '';
305: my $nondc_setsection_code = '';
306: my %loaditem;
307:
308: my $groupslist;
309: my %curr_groups = &Apache::longroup::coursegroups();
310: if (%curr_groups) {
311: $groupslist = join('","',sort(keys(%curr_groups)));
312: $groupslist = '"'.$groupslist.'"';
313: }
314:
315: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
316: my $dcdom = $1;
317: $loaditem{'onload'} = "document.cu.coursedesc.value=''";
318: $dc_setcourse_code = <<"ENDSCRIPT";
319: function setCourse() {
320: var course = document.cu.dccourse.value;
321: if (course != "") {
322: if (document.cu.dcdomain.value != document.cu.origdom.value) {
323: alert("You must select a course in the current domain");
324: return;
325: }
326: var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
327: var section="";
328: var numsections = 0;
329: var newsecs = new Array();
330: for (var i=0; i<document.cu.currsec.length; i++) {
331: if (document.cu.currsec.options[i].selected == true ) {
332: if (document.cu.currsec.options[i].value != "" && document.cu.currsec.options[i].value != null) {
333: if (numsections == 0) {
334: section = document.cu.currsec.options[i].value
335: numsections = 1;
336: }
337: else {
338: section = section + "," + document.cu.currsec.options[i].value
339: numsections ++;
340: }
341: }
342: }
343: }
344: if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
345: if (numsections == 0) {
346: section = document.cu.newsec.value
347: }
348: else {
349: section = section + "," + document.cu.newsec.value
350: }
351: newsecs = document.cu.newsec.value.split(/,/g);
352: numsections = numsections + newsecs.length;
353: }
354: if ((userrole == 'st') && (numsections > 1)) {
355: alert("In each course, each user may only have one student role at a time. You had selected "+numsections+" sections.\\nPlease modify your selections so they include no more than one section.")
356: return;
357: }
358: for (var j=0; j<newsecs.length; j++) {
359: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
360: alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
361: return;
362: }
363: if (document.cu.groups.value != '') {
364: var groups = document.cu.groups.value.split(/,/g);
365: for (var k=0; k<groups.length; k++) {
366: if (newsecs[j] == groups[k]) {
367: alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
368: return;
369: }
370: }
371: }
372: }
373: if ((userrole == 'cc') && (numsections > 0)) {
374: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
375: section = "";
376: }
377: var numcourse = getIndex(document.cu.dccourse);
378: if (numcourse == "-1") {
379: alert("There was a problem with your course selection");
380: return
381: }
382: else {
383: var coursename = "_$dcdom"+"_"+course+"_"+userrole
384: document.cu.elements[numcourse].name = "act"+coursename
385: document.cu.elements[numcourse+4].name = "sec"+coursename
386: document.cu.elements[numcourse+4].value = section
387: document.cu.elements[numcourse+5].name = "start"+coursename
388: document.cu.elements[numcourse+6].name = "end"+coursename
389: }
390: }
391: document.cu.submit();
392: }
393:
394: function getIndex(caller) {
395: for (var i=0;i<document.cu.elements.length;i++) {
396: if (document.cu.elements[i] == caller) {
397: return i;
398: }
399: }
400: return -1;
401: }
402: ENDSCRIPT
403: } else {
404: $nondc_setsection_code = <<"ENDSECCODE";
405: function setSections() {
406: var re1 = /^currsec_/;
407: var groups = new Array($groupslist);
408: for (var i=0;i<document.cu.elements.length;i++) {
409: var str = document.cu.elements[i].name;
410: var checkcurr = str.match(re1);
411: if (checkcurr != null) {
412: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
413: if (document.cu.elements[i-1].checked == true) {
414: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
415: match = re2.exec(str);
416: var role = match[1];
417: if (role == 'cc') {
418: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
419: }
420: else {
421: var sections = '';
422: var numsec = 0;
423: var sections;
424: for (var j=0; j<document.cu.elements[i].length; j++) {
425: if (document.cu.elements[i].options[j].selected == true ) {
426: if (document.cu.elements[i].options[j].value != "") {
427: if (numsec == 0) {
428: if (document.cu.elements[i].options[j].value != "") {
429: sections = document.cu.elements[i].options[j].value;
430: numsec ++;
431: }
432: }
433: else {
434: sections = sections + "," + document.cu.elements[i].options[j].value
435: numsec ++;
436: }
437: }
438: }
439: }
440: if (numsec > 0) {
441: if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
442: sections = sections + "," + document.cu.elements[i+1].value;
443: }
444: }
445: else {
446: sections = document.cu.elements[i+1].value;
447: }
448: var newsecs = document.cu.elements[i+1].value;
449: if (newsecs != null && newsecs != "") {
450: var numsplit = newsecs.split(/,/g);
451: numsec = numsec + numsplit.length;
452: }
453: if ((role == 'st') && (numsec > 1)) {
454: alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
455: return;
456: }
457: else {
458: for (var j=0; j<numsplit.length; j++) {
459: if ((numsplit[j] == 'all') ||
460: (numsplit[j] == 'none')) {
461: alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
462: return;
463: }
464: for (var k=0; k<groups.length; k++) {
465: if (numsplit[j] == groups[k]) {
466: alert("'"+numsplit[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
467: return;
468: }
469: }
470: }
471: document.cu.elements[i+2].value = sections;
472: }
473: }
474: }
475: }
476: }
477: document.cu.submit();
478: }
479: ENDSECCODE
480: }
481: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
482: $nondc_setsection_code,$groupslist);
483: my $start_page =
484: &Apache::loncommon::start_page('Create Users, Change User Privileges',
485: $js,{'add_entries' => \%loaditem,});
486:
487: my $forminfo =<<"ENDFORMINFO";
488: <form action="/adm/createuser" method="post" name="cu">
489: <input type="hidden" name="phase" value="update_user_data">
490: <input type="hidden" name="ccuname" value="$ccuname">
491: <input type="hidden" name="ccdomain" value="$ccdomain">
492: <input type="hidden" name="pres_value" value="" >
493: <input type="hidden" name="pres_type" value="" >
494: <input type="hidden" name="pres_marker" value="" >
495: ENDFORMINFO
496: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
497: my %incdomains;
498: my %inccourses;
499: foreach (values(%Apache::lonnet::hostdom)) {
500: $incdomains{$_}=1;
501: }
502: foreach (keys(%env)) {
503: if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
504: $inccourses{$1.'_'.$2}=1;
505: }
506: }
507: if ($uhome eq 'no_host') {
508: my $home_server_list=
509: '<option value="default" selected>default</option>'."\n".
510: &Apache::loncommon::home_server_option_list($ccdomain);
511:
512: my %lt=&Apache::lonlocal::texthash(
513: 'cnu' => "Create New User",
514: 'nu' => "New User",
515: 'id' => "in domain",
516: 'pd' => "Personal Data",
517: 'fn' => "First Name",
518: 'mn' => "Middle Name",
519: 'ln' => "Last Name",
520: 'gen' => "Generation",
521: 'idsn' => "ID/Student Number",
522: 'hs' => "Home Server",
523: 'lg' => "Login Data"
524: );
525: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
526: &initialize_authen_forms();
527: $r->print(<<ENDNEWUSER);
528: $start_page
529: <h1>$lt{'cnu'}</h1>
530: $forminfo
531: <h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
532: <script type="text/javascript" language="Javascript">
533: $loginscript
534: </script>
535: <input type='hidden' name='makeuser' value='1' />
536: <h3>$lt{'pd'}</h3>
537: <p>
538: <table>
539: <tr><td>$lt{'fn'} </td>
540: <td><input type='text' name='cfirst' size='15' /></td></tr>
541: <tr><td>$lt{'mn'} </td>
542: <td><input type='text' name='cmiddle' size='15' /></td></tr>
543: <tr><td>$lt{'ln'} </td>
544: <td><input type='text' name='clast' size='15' /></td></tr>
545: <tr><td>$lt{'gen'}$genhelp</td>
546: <td><input type='text' name='cgen' size='5' /></td></tr>
547: </table>
548: $lt{'idsn'} <input type='text' name='cstid' size='15' /></p>
549: $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
550: <hr />
551: <h3>$lt{'lg'}</h3>
552: <p>$generalrule </p>
553: <p>$authformkrb </p>
554: <p>$authformint </p>
555: <p>$authformfsys</p>
556: <p>$authformloc </p>
557: ENDNEWUSER
558: } else { # user already exists
559: my %lt=&Apache::lonlocal::texthash(
560: 'cup' => "Change User Privileges",
561: 'usr' => "User",
562: 'id' => "in domain",
563: 'fn' => "first name",
564: 'mn' => "middle name",
565: 'ln' => "last name",
566: 'gen' => "generation"
567: );
568: $r->print(<<ENDCHANGEUSER);
569: $start_page
570: <h1>$lt{'cup'}</h1>
571: $forminfo
572: <h2>$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
573: ENDCHANGEUSER
574: # Get the users information
575: my %userenv = &Apache::lonnet::get('environment',
576: ['firstname','middlename','lastname','generation'],
577: $ccdomain,$ccuname);
578: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
579: $r->print(<<END);
580: <hr />
581: <table border="2">
582: <tr>
583: <th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th>
584: </tr>
585: <tr>
586: END
587: foreach ('firstname','middlename','lastname','generation') {
588: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
589: $r->print(<<"END");
590: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
591: END
592: } else {
593: $r->print('<td>'.$userenv{$_}.'</td>');
594: }
595: }
596: $r->print(<<END);
597: </tr>
598: </table>
599: END
600: # Build up table of user roles to allow revocation of a role.
601: my ($tmp) = keys(%rolesdump);
602: unless ($tmp =~ /^(con_lost|error)/i) {
603: my $now=time;
604: my %lt=&Apache::lonlocal::texthash(
605: 'rer' => "Revoke Existing Roles",
606: 'rev' => "Revoke",
607: 'del' => "Delete",
608: 'ren' => "Re-Enable",
609: 'rol' => "Role",
610: 'ext' => "Extent",
611: 'sta' => "Start",
612: 'end' => "End"
613: );
614: my (%roletext,%sortrole,%roleclass,%rolepriv);
615: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
616: my $b1=join('_',(split('_',$b))[1,0]);
617: return $a1 cmp $b1;
618: } keys(%rolesdump)) {
619: next if ($area =~ /^rolesdef/);
620: my $envkey=$area;
621: my $role = $rolesdump{$area};
622: my $thisrole=$area;
623: $area =~ s/\_\w\w$//;
624: my ($role_code,$role_end_time,$role_start_time) =
625: split(/_/,$role);
626: # Is this a custom role? Get role owner and title.
627: my ($croleudom,$croleuname,$croletitle)=
628: ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
629: my $bgcol='ffffff';
630: my $allowed=0;
631: my $delallowed=0;
632: my $sortkey=$role_code;
633: my $class='Unknown';
634: if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
635: $class='Course';
636: my ($coursedom,$coursedir) = ($1,$2);
637: $sortkey.="\0$1";
638: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
639: my %coursedata=
640: &Apache::lonnet::coursedescription($1.'_'.$2);
641: my $carea;
642: if (defined($coursedata{'description'})) {
643: $carea=$coursedata{'description'}.
644: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
645: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
646: $sortkey.="\0".$coursedata{'description'};
647: } else {
648: $carea=&mt('Unavailable course').': '.$area;
649: $sortkey.="\0".&mt('Unavailable course').': '.$area;
650: }
651: $inccourses{$1.'_'.$2}=1;
652: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
653: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
654: $allowed=1;
655: }
656: if ((&Apache::lonnet::allowed('dro',$1)) ||
657: (&Apache::lonnet::allowed('dro',$ccdomain))) {
658: $delallowed=1;
659: }
660: # - custom role. Needs more info, too
661: if ($croletitle) {
662: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
663: $allowed=1;
664: $thisrole.='.'.$role_code;
665: }
666: }
667: # Compute the background color based on $area
668: $bgcol=$1.'_'.$2;
669: $bgcol=~s/[^7-9a-e]//g;
670: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
671: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
672: $carea.='<br />Section: '.$3;
673: $sortkey.="\0$3";
674: }
675: $area=$carea;
676: } else {
677: $sortkey.="\0".$area;
678: # Determine if current user is able to revoke privileges
679: if ($area=~ /^\/(\w+)\//) {
680: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
681: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
682: $allowed=1;
683: }
684: if (((&Apache::lonnet::allowed('dro',$1)) ||
685: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
686: ($role_code ne 'dc')) {
687: $delallowed=1;
688: }
689: } else {
690: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
691: $allowed=1;
692: }
693: }
694: if ($role_code eq 'ca' || $role_code eq 'au') {
695: $class='Construction Space';
696: } elsif ($role_code eq 'su') {
697: $class='System';
698: } else {
699: $class='Domain';
700: }
701: }
702: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
703: $area=~/\/(\w+)\/(\w+)/;
704: if (&authorpriv($2,$1)) {
705: $allowed=1;
706: } else {
707: $allowed=0;
708: }
709: }
710: $bgcol='77FF77';
711: my $row = '';
712: $row.='<tr bgcolor="#'.$bgcol.'"><td>';
713: my $active=1;
714: $active=0 if (($role_end_time) && ($now>$role_end_time));
715: if (($active) && ($allowed)) {
716: $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
717: } else {
718: if ($active) {
719: $row.=' ';
720: } else {
721: $row.=&mt('expired or revoked');
722: }
723: }
724: $row.='</td><td>';
725: if ($allowed && !$active) {
726: $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
727: } else {
728: $row.=' ';
729: }
730: $row.='</td><td>';
731: if ($delallowed) {
732: $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
733: } else {
734: $row.=' ';
735: }
736: my $plaintext='';
737: unless ($croletitle) {
738: $plaintext=&Apache::lonnet::plaintext($role_code);
739: } else {
740: $plaintext=
741: "Customrole '$croletitle' defined by $croleuname\@$croleudom";
742: }
743: $row.= '</td><td>'.$plaintext.
744: '</td><td>'.$area.
745: '</td><td>'.($role_start_time?localtime($role_start_time)
746: : ' ' ).
747: '</td><td>'.($role_end_time ?localtime($role_end_time)
748: : ' ' )
749: ."</td></tr>\n";
750: $sortrole{$sortkey}=$envkey;
751: $roletext{$envkey}=$row;
752: $roleclass{$envkey}=$class;
753: $rolepriv{$envkey}=$allowed;
754: #$r->print($row);
755: } # end of foreach (table building loop)
756: my $rolesdisplay = 0;
757: my %output = ();
758: foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
759: $output{$type} = '';
760: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
761: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
762: $output{$type}.=$roletext{$sortrole{$which}};
763: }
764: }
765: unless($output{$type} eq '') {
766: $output{$type} = "<tr bgcolor='#BBffBB'>".
767: "<td align='center' colspan='7'>".&mt($type)."</td>".
768: $output{$type};
769: $rolesdisplay = 1;
770: }
771: }
772: if ($rolesdisplay == 1) {
773: $r->print(<<END);
774: <hr />
775: <h3>$lt{'rer'}</h3>
776: <table>
777: <tr><th>$lt{'rev'}</th><th>$lt{'ren'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'e
778: xt'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
779: END
780: foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
781: if ($output{$type}) {
782: $r->print($output{$type}."\n");
783: }
784: }
785: $r->print('</table>');
786: }
787: } # End of unless
788: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
789: if ($currentauth=~/^krb(4|5):/) {
790: $currentauth=~/^krb(4|5):(.*)/;
791: my $krbdefdom=$2;
792: my %param = ( formname => 'document.cu',
793: kerb_def_dom => $krbdefdom
794: );
795: $loginscript = &Apache::loncommon::authform_header(%param);
796: }
797: # Check for a bad authentication type
798: unless ($currentauth=~/^krb(4|5):/ or
799: $currentauth=~/^unix:/ or
800: $currentauth=~/^internal:/ or
801: $currentauth=~/^localauth:/
802: ) { # bad authentication scheme
803: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
804: &initialize_authen_forms();
805: my %lt=&Apache::lonlocal::texthash(
806: 'err' => "ERROR",
807: 'uuas' => "This user has an unrecognized authentication scheme",
808: 'sldb' => "Please specify login data below",
809: 'ld' => "Login Data"
810: );
811: $r->print(<<ENDBADAUTH);
812: <hr />
813: <script type="text/javascript" language="Javascript">
814: $loginscript
815: </script>
816: <font color='#ff0000'>$lt{'err'}:</font>
817: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
818: <h3>$lt{'ld'}</h3>
819: <p>$generalrule</p>
820: <p>$authformkrb</p>
821: <p>$authformint</p>
822: <p>$authformfsys</p>
823: <p>$authformloc</p>
824: ENDBADAUTH
825: } else {
826: # This user is not allowed to modify the users
827: # authentication scheme, so just notify them of the problem
828: my %lt=&Apache::lonlocal::texthash(
829: 'err' => "ERROR",
830: 'uuas' => "This user has an unrecognized authentication scheme",
831: 'adcs' => "Please alert a domain coordinator of this situation"
832: );
833: $r->print(<<ENDBADAUTH);
834: <hr />
835: <script type="text/javascript" language="Javascript">
836: $loginscript
837: </script>
838: <font color="#ff0000"> $lt{'err'}: </font>
839: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
840: <hr />
841: ENDBADAUTH
842: }
843: } else { # Authentication type is valid
844: my $authformcurrent='';
845: my $authform_other='';
846: &initialize_authen_forms();
847: if ($currentauth=~/^krb(4|5):/) {
848: $authformcurrent=$authformkrb;
849: $authform_other="<p>$authformint</p>\n".
850: "<p>$authformfsys</p><p>$authformloc</p>";
851: }
852: elsif ($currentauth=~/^internal:/) {
853: $authformcurrent=$authformint;
854: $authform_other="<p>$authformkrb</p>".
855: "<p>$authformfsys</p><p>$authformloc</p>";
856: }
857: elsif ($currentauth=~/^unix:/) {
858: $authformcurrent=$authformfsys;
859: $authform_other="<p>$authformkrb</p>".
860: "<p>$authformint</p><p>$authformloc;</p>";
861: }
862: elsif ($currentauth=~/^localauth:/) {
863: $authformcurrent=$authformloc;
864: $authform_other="<p>$authformkrb</p>".
865: "<p>$authformint</p><p>$authformfsys</p>";
866: }
867: $authformcurrent.=' <i>(will override current values)</i><br />';
868: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
869: # Current user has login modification privileges
870: my %lt=&Apache::lonlocal::texthash(
871: 'ccld' => "Change Current Login Data",
872: 'enld' => "Enter New Login Data"
873: );
874: $r->print(<<ENDOTHERAUTHS);
875: <hr />
876: <script type="text/javascript" language="Javascript">
877: $loginscript
878: </script>
879: <h3>$lt{'ccld'}</h3>
880: <p>$generalrule</p>
881: <p>$authformnop</p>
882: <p>$authformcurrent</p>
883: <h3>$lt{'enld'}</h3>
884: $authform_other
885: ENDOTHERAUTHS
886: }
887: } ## End of "check for bad authentication type" logic
888: } ## End of new user/old user logic
889: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
890: #
891: # Co-Author
892: #
893: if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
894: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
895: # No sense in assigning co-author role to yourself
896: my $cuname=$env{'user.name'};
897: my $cudom=$env{'request.role.domain'};
898: my %lt=&Apache::lonlocal::texthash(
899: 'cs' => "Construction Space",
900: 'act' => "Activate",
901: 'rol' => "Role",
902: 'ext' => "Extent",
903: 'sta' => "Start",
904: 'end' => "End",
905: 'cau' => "Co-Author",
906: 'caa' => "Assistant Co-Author",
907: 'ssd' => "Set Start Date",
908: 'sed' => "Set End Date"
909: );
910: $r->print(<<ENDCOAUTH);
911: <h4>$lt{'cs'}</h4>
912: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
913: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
914: <tr>
915: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
916: <td>$lt{'cau'}</td>
917: <td>$cudom\_$cuname</td>
918: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
919: <a href=
920: "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>
921: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
922: <a href=
923: "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>
924: </tr>
925: <tr>
926: <td><input type=checkbox name="act_$cudom\_$cuname\_aa" /></td>
927: <td>$lt{'caa'}</td>
928: <td>$cudom\_$cuname</td>
929: <td><input type=hidden name="start_$cudom\_$cuname\_aa" value='' />
930: <a href=
931: "javascript:pjump('date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset')">$lt{'ssd'}</a></td>
932: <td><input type=hidden name="end_$cudom\_$cuname\_aa" value='' />
933: <a href=
934: "javascript:pjump('date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset')">$lt{'sed'}</a></td>
935: </tr>
936: </table>
937: ENDCOAUTH
938: }
939: #
940: # Domain level
941: #
942: my $num_domain_level = 0;
943: my $domaintext =
944: '<h4>'.&mt('Domain Level').'</h4>'.
945: '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
946: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>';
947: foreach ( sort( keys(%incdomains))) {
948: my $thisdomain=$_;
949: foreach ('dc','li','dg','au','sc') {
950: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
951: my $plrole=&Apache::lonnet::plaintext($_);
952: my %lt=&Apache::lonlocal::texthash(
953: 'ssd' => "Set Start Date",
954: 'sed' => "Set End Date"
955: );
956: $num_domain_level ++;
957: $domaintext .= <<"ENDDROW";
958: <tr>
959: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
960: <td>$plrole</td>
961: <td>$thisdomain</td>
962: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
963: <a href=
964: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
965: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
966: <a href=
967: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
968: </tr>
969: ENDDROW
970: }
971: }
972: }
973: $domaintext.='</table>';
974: if ($num_domain_level > 0) {
975: $r->print($domaintext);
976: }
977: #
978: # Course level
979: #
980:
981: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
982: $r->print(&course_level_dc($1));
983: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
984: } else {
985: $r->print(&course_level_table(%inccourses));
986: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()">'."\n");
987: }
988: $r->print("</form>".&Apache::loncommon::end_page());
989: }
990:
991: # ================================================================= Phase Three
992: sub update_user_data {
993: my $r=shift;
994: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
995: $env{'form.ccdomain'});
996: # Error messages
997: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
998: my $end = &Apache::loncommon::end_page();
999:
1000: my $title;
1001: if (exists($env{'form.makeuser'})) {
1002: $title='Set Privileges for New User';
1003: } else {
1004: $title='Modify User Privileges';
1005: }
1006: $r->print(&Apache::loncommon::start_page($title));
1007: my %disallowed;
1008: # Check Inputs
1009: if (! $env{'form.ccuname'} ) {
1010: $r->print($error.&mt('No login name specified').'.'.$end);
1011: return;
1012: }
1013: if ( $env{'form.ccuname'} =~/\W/) {
1014: $r->print($error.&mt('Invalid login name').'. '.
1015: &mt('Only letters, numbers, and underscores are valid').'.'.
1016: $end);
1017: return;
1018: }
1019: if (! $env{'form.ccdomain'} ) {
1020: $r->print($error.&mt('No domain specified').'.'.$end);
1021: return;
1022: }
1023: if ( $env{'form.ccdomain'} =~/\W/) {
1024: $r->print($error.&mt ('Invalid domain name').'. '.
1025: &mt('Only letters, numbers, and underscores are valid').'.'.
1026: $end);
1027: return;
1028: }
1029: if (! exists($env{'form.makeuser'})) {
1030: # Modifying an existing user, so check the validity of the name
1031: if ($uhome eq 'no_host') {
1032: $r->print($error.&mt('Unable to determine home server for ').
1033: $env{'form.ccuname'}.&mt(' in domain ').
1034: $env{'form.ccdomain'}.'.');
1035: return;
1036: }
1037: }
1038: # Determine authentication method and password for the user being modified
1039: my $amode='';
1040: my $genpwd='';
1041: if ($env{'form.login'} eq 'krb') {
1042: $amode='krb';
1043: $amode.=$env{'form.krbver'};
1044: $genpwd=$env{'form.krbarg'};
1045: } elsif ($env{'form.login'} eq 'int') {
1046: $amode='internal';
1047: $genpwd=$env{'form.intarg'};
1048: } elsif ($env{'form.login'} eq 'fsys') {
1049: $amode='unix';
1050: $genpwd=$env{'form.fsysarg'};
1051: } elsif ($env{'form.login'} eq 'loc') {
1052: $amode='localauth';
1053: $genpwd=$env{'form.locarg'};
1054: $genpwd=" " if (!$genpwd);
1055: } elsif (($env{'form.login'} eq 'nochange') ||
1056: ($env{'form.login'} eq '' )) {
1057: # There is no need to tell the user we did not change what they
1058: # did not ask us to change.
1059: # If they are creating a new user but have not specified login
1060: # information this will be caught below.
1061: } else {
1062: $r->print($error.&mt('Invalid login mode or password').$end);
1063: return;
1064: }
1065: if ($env{'form.makeuser'}) {
1066: # Create a new user
1067: my %lt=&Apache::lonlocal::texthash(
1068: 'cru' => "Creating user",
1069: 'id' => "in domain"
1070: );
1071: $r->print(<<ENDNEWUSERHEAD);
1072: <h3>$lt{'cru'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h3>
1073: ENDNEWUSERHEAD
1074: # Check for the authentication mode and password
1075: if (! $amode || ! $genpwd) {
1076: $r->print($error.&mt('Invalid login mode or password').$end);
1077: return;
1078: }
1079: # Determine desired host
1080: my $desiredhost = $env{'form.hserver'};
1081: if (lc($desiredhost) eq 'default') {
1082: $desiredhost = undef;
1083: } else {
1084: my %home_servers = &Apache::loncommon::get_library_servers
1085: ($env{'form.ccdomain'});
1086: if (! exists($home_servers{$desiredhost})) {
1087: $r->print($error.&mt('Invalid home server specified'));
1088: return;
1089: }
1090: }
1091: # Call modifyuser
1092: my $result = &Apache::lonnet::modifyuser
1093: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
1094: $amode,$genpwd,$env{'form.cfirst'},
1095: $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1096: undef,$desiredhost
1097: );
1098: $r->print(&mt('Generating user').': '.$result);
1099: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
1100: $env{'form.ccdomain'});
1101: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1102: $Apache::lonnet::libserv{$home});
1103: } elsif (($env{'form.login'} ne 'nochange') &&
1104: ($env{'form.login'} ne '' )) {
1105: # Modify user privileges
1106: my %lt=&Apache::lonlocal::texthash(
1107: 'usr' => "User",
1108: 'id' => "in domain"
1109: );
1110: $r->print(<<ENDMODIFYUSERHEAD);
1111: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1112: ENDMODIFYUSERHEAD
1113: if (! $amode || ! $genpwd) {
1114: $r->print($error.'Invalid login mode or password'.$end);
1115: return;
1116: }
1117: # Only allow authentification modification if the person has authority
1118: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1119: $r->print('Modifying authentication: '.
1120: &Apache::lonnet::modifyuserauth(
1121: $env{'form.ccdomain'},$env{'form.ccuname'},
1122: $amode,$genpwd));
1123: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1124: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1125: } else {
1126: # Okay, this is a non-fatal error.
1127: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1128: }
1129: }
1130: ##
1131: if (! $env{'form.makeuser'} ) {
1132: # Check for need to change
1133: my %userenv = &Apache::lonnet::get
1134: ('environment',['firstname','middlename','lastname','generation'],
1135: $env{'form.ccdomain'},$env{'form.ccuname'});
1136: my ($tmp) = keys(%userenv);
1137: if ($tmp =~ /^(con_lost|error)/i) {
1138: %userenv = ();
1139: }
1140: # Check to see if we need to change user information
1141: foreach ('firstname','middlename','lastname','generation') {
1142: # Strip leading and trailing whitespace
1143: $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
1144: }
1145: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1146: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1147: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1148: $env{'form.clastname'} ne $userenv{'lastname'} ||
1149: $env{'form.cgeneration'} ne $userenv{'generation'} )) {
1150: # Make the change
1151: my %changeHash;
1152: $changeHash{'firstname'} = $env{'form.cfirstname'};
1153: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1154: $changeHash{'lastname'} = $env{'form.clastname'};
1155: $changeHash{'generation'} = $env{'form.cgeneration'};
1156: my $putresult = &Apache::lonnet::put
1157: ('environment',\%changeHash,
1158: $env{'form.ccdomain'},$env{'form.ccuname'});
1159: if ($putresult eq 'ok') {
1160: # Tell the user we changed the name
1161: my %lt=&Apache::lonlocal::texthash(
1162: 'uic' => "User Information Changed",
1163: 'frst' => "first",
1164: 'mddl' => "middle",
1165: 'lst' => "last",
1166: 'gen' => "generation",
1167: 'prvs' => "Previous",
1168: 'chto' => "Changed To"
1169: );
1170: $r->print(<<"END");
1171: <table border="2">
1172: <caption>$lt{'uic'}</caption>
1173: <tr><th> </th>
1174: <th>$lt{'frst'}</th>
1175: <th>$lt{'mddl'}</th>
1176: <th>$lt{'lst'}</th>
1177: <th>$lt{'gen'}</th></tr>
1178: <tr><td>$lt{'prvs'}</td>
1179: <td>$userenv{'firstname'} </td>
1180: <td>$userenv{'middlename'} </td>
1181: <td>$userenv{'lastname'} </td>
1182: <td>$userenv{'generation'} </td></tr>
1183: <tr><td>$lt{'chto'}</td>
1184: <td>$env{'form.cfirstname'} </td>
1185: <td>$env{'form.cmiddlename'} </td>
1186: <td>$env{'form.clastname'} </td>
1187: <td>$env{'form.cgeneration'} </td></tr>
1188: </table>
1189: END
1190: } else { # error occurred
1191: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1192: $env{'form.ccuname'}." ".&mt('in domain')." ".
1193: $env{'form.ccdomain'}."</h2>");
1194: }
1195: } else { # End of if ($env ... ) logic
1196: # They did not want to change the users name but we can
1197: # still tell them what the name is
1198: my %lt=&Apache::lonlocal::texthash(
1199: 'usr' => "User",
1200: 'id' => "in domain",
1201: 'gen' => "Generation"
1202: );
1203: $r->print(<<"END");
1204: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1205: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1206: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1207: END
1208: }
1209: }
1210: ##
1211: my $now=time;
1212: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1213: foreach (keys (%env)) {
1214: next if (! $env{$_});
1215: # Revoke roles
1216: if ($_=~/^form\.rev/) {
1217: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1218: # Revoke standard role
1219: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1220: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1221: $env{'form.ccuname'},$1,$2).'</b><br />');
1222: if ($2 eq 'st') {
1223: $1=~/^\/(\w+)\/(\w+)/;
1224: my $cid=$1.'_'.$2;
1225: $r->print(&mt('Drop from classlist').': <b>'.
1226: &Apache::lonnet::critical('put:'.
1227: $env{'course.'.$cid.'.domain'}.':'.
1228: $env{'course.'.$cid.'.num'}.':classlist:'.
1229: &Apache::lonnet::escape($env{'form.ccuname'}.':'.
1230: $env{'form.ccdomain'}).'='.
1231: &Apache::lonnet::escape($now.':'),
1232: $env{'course.'.$cid.'.home'}).'</b><br />');
1233: }
1234: }
1235: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1236: # Revoke custom role
1237: $r->print(&mt('Revoking custom role:').
1238: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
1239: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1240: $env{'form.ccuname'},$1,$2,$3,$4).
1241: '</b><br />');
1242: }
1243: } elsif ($_=~/^form\.del/) {
1244: if ($_=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1245: # Delete standard role
1246: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1247: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1248: $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1249: if ($2 eq 'st') {
1250: $1=~/^\/(\w+)\/(\w+)/;
1251: my $cid=$1.'_'.$2;
1252: $r->print(&mt('Drop from classlist').': <b>'.
1253: &Apache::lonnet::critical('put:'.
1254: $env{'course.'.$cid.'.domain'}.':'.
1255: $env{'course.'.$cid.'.num'}.':classlist:'.
1256: &Apache::lonnet::escape($env{'form.ccuname'}.':'.
1257: $env{'form.ccdomain'}).'='.
1258: &Apache::lonnet::escape($now.':'),
1259: $env{'course.'.$cid.'.home'}).'</b><br />');
1260: }
1261: }
1262: if ($_=~/^form\.del\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1263: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1264: # Delete custom role
1265: $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
1266: $rolename,$rnam,$rdom,$url).': <b>'.
1267: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
1268: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1269: 0,1).'</b><br />');
1270: }
1271: } elsif ($_=~/^form\.ren/) {
1272: my $udom = $env{'form.ccdomain'};
1273: my $uname = $env{'form.ccuname'};
1274: # Re-enable standard role
1275: if ($_=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1276: my $url = $1;
1277: my $role = $2;
1278: my $logmsg;
1279: my $output;
1280: if ($role eq 'st') {
1281: if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
1282: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1283: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1284: $output = "Error: $result\n";
1285: } else {
1286: $output = &mt('Assigning').' '.$role.' in '.$url.
1287: &mt('starting').' '.localtime($now).
1288: ': <br />'.$logmsg.'<br />'.
1289: &mt('Add to classlist').': <b>ok</b><br />';
1290: }
1291: }
1292: } else {
1293: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1294: $env{'form.ccuname'},$url,$role,0,$now);
1295: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1296: $role,$url,$result).'<br />';
1297: }
1298: $r->print($output);
1299: }
1300: # Re-enable custom role
1301: if ($_=~/^form\.ren\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1302: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1303: my $result = &Apache::lonnet::assigncustomrole(
1304: $env{'form.ccdomain'}, $env{'form.ccuname'},
1305: $url,$rdom,$rnam,$rolename,0,$now);
1306: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
1307: $rolename,$rnam,$rdom,$url,$result).'<br />');
1308: }
1309: } elsif ($_=~/^form\.act/) {
1310: my $udom = $env{'form.ccdomain'};
1311: my $uname = $env{'form.ccuname'};
1312: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1313: # Activate a custom role
1314: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1315: my $url='/'.$one.'/'.$two;
1316: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1317:
1318: my $start = ( $env{'form.start_'.$full} ?
1319: $env{'form.start_'.$full} :
1320: $now );
1321: my $end = ( $env{'form.end_'.$full} ?
1322: $env{'form.end_'.$full} :
1323: 0 );
1324:
1325: # split multiple sections
1326: my %sections = ();
1327: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1328: if ($num_sections == 0) {
1329: $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1330: } else {
1331: my %curr_groups =
1332: &Apache::longroup::coursegroups($one,$two);
1333: foreach my $sec (sort {$a cmp $b} keys %sections) {
1334: if (($sec eq 'none') || ($sec eq 'all') ||
1335: exists($curr_groups{$sec})) {
1336: $disallowed{$sec} = $url;
1337: next;
1338: }
1339: my $securl = $url.'/'.$sec;
1340: $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1341: }
1342: }
1343: } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
1344: # Activate roles for sections with 3 id numbers
1345: # set start, end times, and the url for the class
1346: my ($one,$two,$three)=($1,$2,$3);
1347: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1348: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1349: $now );
1350: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1351: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1352: 0 );
1353: my $url='/'.$one.'/'.$two;
1354: my $type = 'three';
1355: # split multiple sections
1356: my %sections = ();
1357: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1358: if ($num_sections == 0) {
1359: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1360: } else {
1361: my %curr_groups =
1362: &Apache::longroup::coursegroups($one,$two);
1363: my $emptysec = 0;
1364: foreach my $sec (sort {$a cmp $b} keys %sections) {
1365: $sec =~ s/\W//g;
1366: if ($sec ne '') {
1367: if (($sec eq 'none') || ($sec eq 'all') ||
1368: exists($curr_groups{$sec})) {
1369: $disallowed{$sec} = $url;
1370: next;
1371: }
1372: my $securl = $url.'/'.$sec;
1373: $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1374: } else {
1375: $emptysec = 1;
1376: }
1377: }
1378: if ($emptysec) {
1379: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1380: }
1381: }
1382: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1383: # Activate roles for sections with two id numbers
1384: # set start, end times, and the url for the class
1385: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1386: $env{'form.start_'.$1.'_'.$2} :
1387: $now );
1388: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1389: $env{'form.end_'.$1.'_'.$2} :
1390: 0 );
1391: my $url='/'.$1.'/';
1392: # split multiple sections
1393: my %sections = ();
1394: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1395: if ($num_sections == 0) {
1396: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1397: } else {
1398: my $emptysec = 0;
1399: foreach my $sec (sort {$a cmp $b} keys %sections) {
1400: if ($sec ne '') {
1401: my $securl = $url.'/'.$sec;
1402: $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1403: } else {
1404: $emptysec = 1;
1405: }
1406: }
1407: if ($emptysec) {
1408: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1409: }
1410: }
1411: } else {
1412: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br />');
1413: }
1414: foreach my $key (sort(keys(%disallowed))) {
1415: if (($key eq 'none') || ($key eq 'all')) {
1416: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
1417: } else {
1418: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',$key));
1419: }
1420: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
1421: }
1422: }
1423: } # End of foreach (keys(%env))
1424: # Flush the course logs so reverse user roles immediately updated
1425: &Apache::lonnet::flushcourselogs();
1426: $r->print('<p><a href="/adm/createuser">Create/Modify Another User</a></p>');
1427: $r->print(&Apache::loncommon::end_page());
1428: }
1429:
1430: sub commit_customrole {
1431: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
1432: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1433: ($start?', '.&mt('starting').' '.localtime($start):'').
1434: ($end?', ending '.localtime($end):'').': <b>'.
1435: &Apache::lonnet::assigncustomrole(
1436: $udom,$uname,$url,$three,$four,$five,$end,$start).
1437: '</b><br />';
1438: return $output;
1439: }
1440:
1441: sub commit_standardrole {
1442: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1443: my $output;
1444: my $logmsg;
1445: if ($three eq 'st') {
1446: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
1447: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1448: $output = "Error: $result\n";
1449: } else {
1450: $output = &mt('Assigning').' '.$three.' in '.$url.
1451: ($start?', '.&mt('starting').' '.localtime($start):'').
1452: ($end?', '.&mt('ending').' '.localtime($end):'').
1453: ': <b>'.$result.'</b><br />'.
1454: &mt('Add to classlist').': <b>ok</b><br />';
1455: }
1456: } else {
1457: $output = &mt('Assigning').' '.$three.' in '.$url.
1458: ($start?', '.&mt('starting').' '.localtime($start):'').
1459: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1460: &Apache::lonnet::assignrole(
1461: $udom,$uname,$url,$three,$end,$start).
1462: '</b><br />';
1463: }
1464: return $output;
1465: }
1466:
1467: sub commit_studentrole {
1468: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1469: my $linefeed = '<br />'."\n";
1470: my $result;
1471: if (defined($one) && defined($two)) {
1472: my $cid=$one.'_'.$two;
1473: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
1474: my $secchange = 0;
1475: my $expire_role_result;
1476: my $modify_section_result;
1477: unless ($oldsec eq '-1') {
1478: unless ($sec eq $oldsec) {
1479: $secchange = 1;
1480: my $uurl='/'.$cid;
1481: $uurl=~s/\_/\//g;
1482: if ($oldsec) {
1483: $uurl.='/'.$oldsec;
1484: }
1485: $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
1486: $result = $expire_role_result;
1487: }
1488: }
1489: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1490: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
1491: if ($modify_section_result =~ /^ok/) {
1492: if ($secchange == 1) {
1493: $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
1494: } elsif ($oldsec eq '-1') {
1495: $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
1496: } else {
1497: $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
1498: }
1499: } else {
1500: $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
1501: }
1502: $result = $modify_section_result;
1503: } elsif ($secchange == 1) {
1504: $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
1505: }
1506: } else {
1507: $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
1508: $result = "error: incomplete course id\n";
1509: }
1510: return $result;
1511: }
1512:
1513: sub build_roles {
1514: my ($sectionstr,$sections,$role) = @_;
1515: my $num_sections = 0;
1516: if ($sectionstr=~ /,/) {
1517: my @secnums = split/,/,$sectionstr;
1518: if ($role eq 'st') {
1519: $secnums[0] =~ s/\W//g;
1520: $$sections{$secnums[0]} = 1;
1521: $num_sections = 1;
1522: } else {
1523: foreach my $sec (@secnums) {
1524: $sec =~ ~s/\W//g;
1525: unless ($sec eq "") {
1526: if (exists($$sections{$sec})) {
1527: $$sections{$sec} ++;
1528: } else {
1529: $$sections{$sec} = 1;
1530: $num_sections ++;
1531: }
1532: }
1533: }
1534: }
1535: } else {
1536: $sectionstr=~s/\W//g;
1537: unless ($sectionstr eq '') {
1538: $$sections{$sectionstr} = 1;
1539: $num_sections ++;
1540: }
1541: }
1542:
1543: return $num_sections;
1544: }
1545:
1546: # ========================================================== Custom Role Editor
1547:
1548: sub custom_role_editor {
1549: my $r=shift;
1550: my $rolename=$env{'form.rolename'};
1551:
1552: if ($rolename eq 'make new role') {
1553: $rolename=$env{'form.newrolename'};
1554: }
1555:
1556: $rolename=~s/[^A-Za-z0-9]//gs;
1557:
1558: unless ($rolename) {
1559: &print_username_entry_form($r);
1560: return;
1561: }
1562:
1563: $r->print(&Apache::loncommon::start_page('Custom Role Editor'));
1564: my $syspriv='';
1565: my $dompriv='';
1566: my $coursepriv='';
1567: my ($rdummy,$roledef)=
1568: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1569: # ------------------------------------------------------- Does this role exist?
1570: $r->print('<h2>');
1571: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1572: $r->print(&mt('Existing Role').' "');
1573: # ------------------------------------------------- Get current role privileges
1574: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1575: } else {
1576: $r->print(&mt('New Role').' "');
1577: $roledef='';
1578: }
1579: $r->print($rolename.'"</h2>');
1580: # ------------------------------------------------------- What can be assigned?
1581: my %full=();
1582: my %courselevel=();
1583: my %courselevelcurrent=();
1584: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1585: my ($priv,$restrict)=split(/\&/,$_);
1586: unless ($restrict) { $restrict='F'; }
1587: $courselevel{$priv}=$restrict;
1588: if ($coursepriv=~/\:$priv/) {
1589: $courselevelcurrent{$priv}=1;
1590: }
1591: $full{$priv}=1;
1592: }
1593: my %domainlevel=();
1594: my %domainlevelcurrent=();
1595: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1596: my ($priv,$restrict)=split(/\&/,$_);
1597: unless ($restrict) { $restrict='F'; }
1598: $domainlevel{$priv}=$restrict;
1599: if ($dompriv=~/\:$priv/) {
1600: $domainlevelcurrent{$priv}=1;
1601: }
1602: $full{$priv}=1;
1603: }
1604: my %systemlevel=();
1605: my %systemlevelcurrent=();
1606: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1607: my ($priv,$restrict)=split(/\&/,$_);
1608: unless ($restrict) { $restrict='F'; }
1609: $systemlevel{$priv}=$restrict;
1610: if ($syspriv=~/\:$priv/) {
1611: $systemlevelcurrent{$priv}=1;
1612: }
1613: $full{$priv}=1;
1614: }
1615: my %lt=&Apache::lonlocal::texthash(
1616: 'prv' => "Privilege",
1617: 'crl' => "Course Level",
1618: 'dml' => "Domain Level",
1619: 'ssl' => "System Level"
1620: );
1621: $r->print(<<ENDCCF);
1622: <form method="post">
1623: <input type="hidden" name="phase" value="set_custom_roles" />
1624: <input type="hidden" name="rolename" value="$rolename" />
1625: <table border="2">
1626: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1627: <th>$lt{'ssl'}</th></tr>
1628: ENDCCF
1629: foreach (sort keys %full) {
1630: $r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
1631: ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
1632: ($courselevelcurrent{$_}?'checked="1"':'').' />':' ').
1633: '</td><td>'.
1634: ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
1635: ($domainlevelcurrent{$_}?'checked="1"':'').' />':' ').
1636: '</td><td>'.
1637: ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
1638: ($systemlevelcurrent{$_}?'checked="1"':'').' />':' ').
1639: '</td></tr>');
1640: }
1641: $r->print(
1642: '<table><input type="submit" value="'.&mt('Define Role').'" /></form>'.
1643: &Apache::loncommon::end_page());
1644: }
1645:
1646: # ---------------------------------------------------------- Call to definerole
1647: sub set_custom_role {
1648: my ($r) = @_;
1649:
1650: my $rolename=$env{'form.rolename'};
1651:
1652: $rolename=~s/[^A-Za-z0-9]//gs;
1653:
1654: unless ($rolename) {
1655: &print_username_entry_form($r);
1656: return;
1657: }
1658:
1659: $r->print(&Apache::loncommon::start_page('Save Custom Role').'<h2>');
1660: my ($rdummy,$roledef)=
1661: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1662:
1663: # ------------------------------------------------------- Does this role exist?
1664: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1665: $r->print(&mt('Existing Role').' "');
1666: } else {
1667: $r->print(&mt('New Role').' "');
1668: $roledef='';
1669: }
1670: $r->print($rolename.'"</h2>');
1671: # ------------------------------------------------------- What can be assigned?
1672: my $sysrole='';
1673: my $domrole='';
1674: my $courole='';
1675:
1676: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1677: my ($priv,$restrict)=split(/\&/,$_);
1678: unless ($restrict) { $restrict=''; }
1679: if ($env{'form.'.$priv.':c'}) {
1680: $courole.=':'.$_;
1681: }
1682: }
1683:
1684: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1685: my ($priv,$restrict)=split(/\&/,$_);
1686: unless ($restrict) { $restrict=''; }
1687: if ($env{'form.'.$priv.':d'}) {
1688: $domrole.=':'.$_;
1689: }
1690: }
1691:
1692: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1693: my ($priv,$restrict)=split(/\&/,$_);
1694: unless ($restrict) { $restrict=''; }
1695: if ($env{'form.'.$priv.':s'}) {
1696: $sysrole.=':'.$_;
1697: }
1698: }
1699: $r->print('<br />Defining Role: '.
1700: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1701: if ($env{'request.course.id'}) {
1702: my $url='/'.$env{'request.course.id'};
1703: $url=~s/\_/\//g;
1704: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1705: &Apache::lonnet::assigncustomrole($env{'user.domain'},
1706: $env{'user.name'},
1707: $url,
1708: $env{'user.domain'},
1709: $env{'user.name'},
1710: $rolename));
1711: }
1712: $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p>');
1713: $r->print(&Apache::loncommon::end_page());
1714: }
1715:
1716: # ================================================================ Main Handler
1717: sub handler {
1718: my $r = shift;
1719:
1720: if ($r->header_only) {
1721: &Apache::loncommon::content_type($r,'text/html');
1722: $r->send_http_header;
1723: return OK;
1724: }
1725:
1726: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
1727: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
1728: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
1729: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1730: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1731: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1732: &Apache::loncommon::content_type($r,'text/html');
1733: $r->send_http_header;
1734: unless ($env{'form.phase'}) {
1735: &print_username_entry_form($r);
1736: }
1737: if ($env{'form.phase'} eq 'get_user_info') {
1738: &print_user_modification_page($r);
1739: } elsif ($env{'form.phase'} eq 'update_user_data') {
1740: &update_user_data($r);
1741: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1742: &custom_role_editor($r);
1743: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1744: &set_custom_role($r);
1745: }
1746: } else {
1747: $env{'user.error.msg'}=
1748: "/adm/createuser:mau:0:0:Cannot modify user data";
1749: return HTTP_NOT_ACCEPTABLE;
1750: }
1751: return OK;
1752: }
1753:
1754: #-------------------------------------------------- functions for &phase_two
1755: sub course_level_table {
1756: my (%inccourses) = @_;
1757: my $table = '';
1758: # Custom Roles?
1759:
1760: my %customroles=&my_custom_roles();
1761: my %lt=&Apache::lonlocal::texthash(
1762: 'exs' => "Existing sections",
1763: 'new' => "Define new section",
1764: 'ssd' => "Set Start Date",
1765: 'sed' => "Set End Date",
1766: 'crl' => "Course Level",
1767: 'act' => "Activate",
1768: 'rol' => "Role",
1769: 'ext' => "Extent",
1770: 'grs' => "Section",
1771: 'sta' => "Start",
1772: 'end' => "End"
1773: );
1774:
1775: foreach (sort( keys(%inccourses))) {
1776: my $thiscourse=$_;
1777: my $protectedcourse=$_;
1778: $thiscourse=~s:_:/:g;
1779: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1780: my $area=$coursedata{'description'};
1781: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1782: my $bgcol=$thiscourse;
1783: $bgcol=~s/[^7-9a-e]//g;
1784: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1785: my ($domain,$cnum)=split(/\//,$thiscourse);
1786: my %sections_count;
1787: if (defined($env{'request.course.id'})) {
1788: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1789: %sections_count =
1790: &Apache::loncommon::get_sections($domain,$cnum);
1791: }
1792: }
1793: foreach ('st','ta','ep','ad','in','cc') {
1794: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1795: my $plrole=&Apache::lonnet::plaintext($_);
1796: $table .= <<ENDEXTENT;
1797: <tr bgcolor="#$bgcol">
1798: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1799: <td>$plrole</td>
1800: <td>$area<br />Domain: $domain</td>
1801: ENDEXTENT
1802: if ($_ ne 'cc') {
1803: if (%sections_count) {
1804: my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$_);
1805: $table .=
1806: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1807: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1808: $currsec.'</td>'.
1809: '<td> </td>'.
1810: '<td valign="top"> '.$lt{'new'}.'<br />'.
1811: '<input type="text" name="newsec_'.$protectedcourse.'_'.$_.'" value="" /></td>'.
1812: '<input type="hidden" '.
1813: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>'.
1814: '</tr></table></td>';
1815: } else {
1816: $table .= '<td><input type="text" size="10" '.
1817: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>';
1818: }
1819: } else {
1820: $table .= '<td> </td>';
1821: }
1822: $table .= <<ENDTIMEENTRY;
1823: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1824: <a href=
1825: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1826: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1827: <a href=
1828: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1829: ENDTIMEENTRY
1830: $table.= "</tr>\n";
1831: }
1832: }
1833: foreach (sort keys %customroles) {
1834: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1835: my $plrole=$_;
1836: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
1837: '_'.$env{'user.name'}.'_'.$plrole;
1838: $table .= <<END;
1839: <tr bgcolor="#$bgcol">
1840: <td><input type="checkbox" name="act_$customrole"></td>
1841: <td>$plrole</td>
1842: <td>$area</td>
1843: END
1844: if (%sections_count) {
1845: my $currsec = &course_sections(\%sections_count,$customrole);
1846: $table.=
1847: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1848: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1849: $currsec.'</td>'.
1850: '<td> </td>'.
1851: '<td valign="top"> '.$lt{'new'}.'<br />'.
1852: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
1853: '<input type="hidden" '.
1854: 'name="sec_'.$customrole.'"></td>'.
1855: '</tr></table></td>';
1856: } else {
1857: $table .= '<td><input type="text" size="10" '.
1858: 'name="sec_'.$customrole.'"></td>';
1859: }
1860: $table .= <<ENDENTRY;
1861: <td><input type=hidden name="start_$customrole" value=''>
1862: <a href=
1863: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1864: <td><input type=hidden name="end_$customrole" value=''>
1865: <a href=
1866: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td></tr>
1867: ENDENTRY
1868: }
1869: }
1870: }
1871: return '' if ($table eq ''); # return nothing if there is nothing
1872: # in the table
1873: my $result = <<ENDTABLE;
1874: <h4>$lt{'crl'}</h4>
1875: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1876: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1877: $table
1878: </table>
1879: ENDTABLE
1880: return $result;
1881: }
1882:
1883: sub course_sections {
1884: my ($sections_count,$role) = @_;
1885: my $output = '';
1886: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1887: if (scalar(@sections) == 1) {
1888: $output = '<select name="currsec_'.$role.'" >'."\n".
1889: ' <option value="">Select</option>'."\n".
1890: ' <option value="">No section</option>'."\n".
1891: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1892: } else {
1893: $output = '<select name="currsec_'.$role.'" ';
1894: my $multiple = 4;
1895: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1896: $output .= '"multiple" size="'.$multiple.'">'."\n";
1897: foreach (@sections) {
1898: $output .= '<option value="'.$_.'">'.$_."</option>\n";
1899: }
1900: }
1901: $output .= '</select>';
1902: return $output;
1903: }
1904:
1905: sub course_level_dc {
1906: my ($dcdom) = @_;
1907: my %customroles=&my_custom_roles();
1908: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
1909: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1910: '<input type="hidden" name="dccourse" value="" />';
1911: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1912: ('cu','dccourse','dcdomain','coursedesc').'</b>';
1913:
1914: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom);
1915: my %lt=&Apache::lonlocal::texthash(
1916: 'crl' => "Course Level",
1917: 'crt' => "Course Title",
1918: 'rol' => "Role",
1919: 'grs' => "Section",
1920: 'exs' => "Existing sections",
1921: 'new' => "Define new section",
1922: 'sta' => "Start",
1923: 'end' => "End",
1924: 'ssd' => "Set Start Date",
1925: 'sed' => "Set End Date"
1926: );
1927: my $header = '<h4>'.$lt{'crl'}.'</h4>'.
1928: '<table border="2"><tr><th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th></tr>';
1929: my $otheritems = '<tr><td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'".'cu'."'".','."'".'dccourse'."'".','."'".'dcdomain'."'".','."'".'coursedesc'."',''".')" /></td>'.
1930: '<td><select name="role">'."\n";
1931: foreach ('st','ta','ep','ad','in','cc') {
1932: my $plrole=&Apache::lonnet::plaintext($_);
1933: $otheritems .= ' <option value="'.$_.'">'.$plrole;
1934: }
1935: if ( keys %customroles > 0) {
1936: foreach (sort keys %customroles) {
1937: my $custrole='cr_cr_'.$env{'user.domain'}.
1938: '_'.$env{'user.name'}.'_'.$_;
1939: $otheritems .= ' <option value="'.$custrole.'">'.$_;
1940: }
1941: }
1942: $otheritems .= '</select></td><td>'.
1943: '<table border="0" cellspacing="0" cellpadding="0">'.
1944: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1945: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
1946: '<td> </td>'.
1947: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1948: '<input type="text" name="newsec" value="" />'.
1949: '<input type="hidden" name="groups" value="" /></td>'.
1950: '</tr></table></td>';
1951: $otheritems .= <<ENDTIMEENTRY;
1952: <td><input type=hidden name="start" value=''>
1953: <a href=
1954: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1955: <td><input type=hidden name="end" value=''>
1956: <a href=
1957: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
1958: ENDTIMEENTRY
1959: $otheritems .= "</tr></table>\n";
1960: return $cb_jscript.$header.$hiddenitems.$otheritems;
1961: }
1962:
1963: #---------------------------------------------- end functions for &phase_two
1964:
1965: #--------------------------------- functions for &phase_two and &phase_three
1966:
1967: #--------------------------end of functions for &phase_two and &phase_three
1968:
1969: 1;
1970: __END__
1971:
1972:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>