1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.113 2006/05/08 21:40:20 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:
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: sub initialize_authen_forms {
77: my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
78: $krbdefdom= uc($krbdefdom);
79: my %param = ( formname => 'document.cu',
80: kerb_def_dom => $krbdefdom
81: );
82: # no longer static due to configurable kerberos defaults
83: # $loginscript = &Apache::loncommon::authform_header(%param);
84: $generalrule = &Apache::loncommon::authform_authorwarning(%param);
85: $authformnop = &Apache::loncommon::authform_nochange(%param);
86: # no longer static due to configurable kerberos defaults
87: # $authformkrb = &Apache::loncommon::authform_kerberos(%param);
88: $authformint = &Apache::loncommon::authform_internal(%param);
89: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
90: $authformloc = &Apache::loncommon::authform_local(%param);
91: }
92:
93:
94: # ======================================================= Existing Custom Roles
95:
96: sub my_custom_roles {
97: my %returnhash=();
98: my %rolehash=&Apache::lonnet::dump('roles');
99: foreach (keys %rolehash) {
100: if ($_=~/^rolesdef\_(\w+)$/) {
101: $returnhash{$1}=$1;
102: }
103: }
104: return %returnhash;
105: }
106:
107: # ==================================================== Figure out author access
108:
109: sub authorpriv {
110: my ($auname,$audom)=@_;
111: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
112: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
113: return 1;
114: }
115:
116: # =================================================================== Phase one
117:
118: sub print_username_entry_form {
119: my ($r) = @_;
120: my $defdom=$env{'request.role.domain'};
121: my @domains = &Apache::loncommon::get_domains();
122: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
123: my $selscript=&Apache::loncommon::studentbrowser_javascript();
124: my $start_page =
125: &Apache::loncommon::start_page('Create Users, Change User Privileges',
126: $selscript);
127:
128: my $sellink=&Apache::loncommon::selectstudent_link
129: ('crtuser','ccuname','ccdomain');
130: my %existingroles=&my_custom_roles();
131: my $choice=&Apache::loncommon::select_form('make new role','rolename',
132: ('make new role' => 'Generate new role ...',%existingroles));
133: my %lt=&Apache::lonlocal::texthash(
134: 'siur' => "Set Individual User Roles",
135: 'usr' => "Username",
136: 'dom' => "Domain",
137: 'usrr' => "User Roles",
138: 'ecrp' => "Edit Custom Role Privileges",
139: 'nr' => "Name of Role",
140: 'cre' => "Custom Role Editor"
141: );
142: my $help = &Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
143: my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
144: my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
145: $r->print(<<"ENDDOCUMENT");
146: $start_page
147: <form action="/adm/createuser" method="post" name="crtuser">
148: <input type="hidden" name="phase" value="get_user_info">
149: <h2>$lt{siur}$helpsiur</h2>
150: <table>
151: <tr><td>$lt{usr}:</td><td><input type="text" size="15" name="ccuname">
152: </td><td rowspan="2">$sellink</td></tr><tr><td>
153: $lt{'dom'}:</td><td>$domform</td></tr>
154: </table>
155: <input name="userrole" type="submit" value="$lt{usrr}" />
156: </form>
157: ENDDOCUMENT
158: if (&Apache::lonnet::allowed('mcr','/')) {
159: $r->print(<<ENDCUSTOM);
160: <form action="/adm/createuser" method="post" name="docustom">
161: <input type="hidden" name="phase" value="selected_custom_edit">
162: <h2>$lt{'ecrp'}$helpecpr</h2>
163: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
164: <input name="customeditor" type="submit" value="$lt{'cre'}" />
165: </form>
166: ENDCUSTOM
167: }
168: $r->print(&Apache::loncommon::end_page());
169: }
170:
171:
172: sub user_modification_js {
173: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
174:
175: return <<END;
176: <script type="text/javascript" language="Javascript">
177:
178: function pclose() {
179: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
180: "height=350,width=350,scrollbars=no,menubar=no");
181: parmwin.close();
182: }
183:
184: $pjump_def
185: $dc_setcourse_code
186:
187: function dateset() {
188: eval("document.cu."+document.cu.pres_marker.value+
189: ".value=document.cu.pres_value.value");
190: pclose();
191: }
192:
193: $nondc_setsection_code
194:
195: function setSections() {
196: var re1 = /^currsec_/;
197: var groups = new Array($groupslist);
198: for (var i=0;i<document.cu.elements.length;i++) {
199: var str = document.cu.elements[i].name;
200: var checkcurr = str.match(re1);
201: if (checkcurr != null) {
202: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
203: if (document.cu.elements[i-1].checked == true) {
204: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
205: match = re2.exec(str);
206: var role = match[1];
207: if (role == 'cc') {
208: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
209: }
210: else {
211: var sections = '';
212: var numsec = 0;
213: var sections;
214: for (var j=0; j<document.cu.elements[i].length; j++) {
215: if (document.cu.elements[i].options[j].selected == true ) {
216: if (document.cu.elements[i].options[j].value != "") {
217: if (numsec == 0) {
218: if (document.cu.elements[i].options[j].value != "") {
219: sections = document.cu.elements[i].options[j].value;
220: numsec ++;
221: }
222: }
223: else {
224: sections = sections + "," + document.cu.elements[i].options[j].value
225: numsec ++;
226: }
227: }
228: }
229: }
230: if (numsec > 0) {
231: if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
232: sections = sections + "," + document.cu.elements[i+1].value;
233: }
234: }
235: else {
236: sections = document.cu.elements[i+1].value;
237: }
238: var newsecs = document.cu.elements[i+1].value;
239: if (newsecs != null && newsecs != "") {
240: var numsplit = newsecs.split(/,/g);
241: numsec = numsec + numsplit.length;
242: }
243: if ((role == 'st') && (numsec > 1)) {
244: 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.")
245: return;
246: }
247: else {
248: for (var j=0; j<numsplit.length; j++) {
249: if ((numsplit[j] == 'all') ||
250: (numsplit[j] == 'none')) {
251: 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.");
252: return;
253: }
254: for (var k=0; k<groups.length; k++) {
255: if (numsplit[j] == groups[k]) {
256: 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.");
257: return;
258: }
259: }
260: }
261: document.cu.elements[i+2].value = sections;
262: }
263: }
264: }
265: }
266: }
267: document.cu.submit();
268: }
269: </script>
270: END
271: }
272:
273: # =================================================================== Phase two
274: sub print_user_modification_page {
275: my $r=shift;
276: my $ccuname=$env{'form.ccuname'};
277: my $ccdomain=$env{'form.ccdomain'};
278:
279: $ccuname=~s/\W//g;
280: $ccdomain=~s/\W//g;
281:
282: unless (($ccuname) && ($ccdomain)) {
283: &print_username_entry_form($r);
284: return;
285: }
286:
287: my $defdom=$env{'request.role.domain'};
288:
289: my ($krbdef,$krbdefdom) =
290: &Apache::loncommon::get_kerberos_defaults($defdom);
291:
292: my %param = ( formname => 'document.cu',
293: kerb_def_dom => $krbdefdom,
294: kerb_def_auth => $krbdef
295: );
296: $loginscript = &Apache::loncommon::authform_header(%param);
297: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
298:
299: $ccuname=~s/\W//g;
300: $ccdomain=~s/\W//g;
301: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
302: my $dc_setcourse_code = '';
303: my $nondc_setsection_code = '';
304: my %loaditem;
305: my (%curr_groups,$groupslist,$numgroups);
306: if (exists($env{'request.course.id'})) {
307: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
308: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
309: $numgroups = &Apache::loncommon::coursegroups(\%curr_groups,$cdom,
310: $cnum);
311: }
312: if ($numgroups > 0) {
313: $groupslist = join('","',sort(keys(%curr_groups)));
314: $groupslist = '"'.$groupslist.'"';
315: }
316: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
317: my $dcdom = $1;
318: $loaditem{'onload'} = "document.cu.coursedesc.value=''";
319: $dc_setcourse_code = <<"ENDSCRIPT";
320: function setCourse() {
321: var course = document.cu.dccourse.value;
322: if (course != "") {
323: if (document.cu.dcdomain.value != document.cu.origdom.value) {
324: alert("You must select a course in the current domain");
325: return;
326: }
327: var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
328: var section="";
329: var numsections = 0;
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: var numsplit = document.cu.newsec.value.split(/,/g);
352: numsections = numsections + numsplit.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<numsplit.length; j++) {
359: if ((numsplit[j] == 'all') || (numsplit[j] == 'none')) {
360: 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.");
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 (numsplit[j] == groups[k]) {
367: alert("'"+numsplit[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: my $num_sections;
981:
982: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
983: $r->print(&course_level_dc($1));
984: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
985: } else {
986: $r->print(&course_level_table(%inccourses));
987: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()">'."\n");
988: }
989: $r->print("</form>".&Apache::loncommon::end_page());
990: }
991:
992: # ================================================================= Phase Three
993: sub update_user_data {
994: my $r=shift;
995: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
996: $env{'form.ccdomain'});
997: # Error messages
998: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
999: my $end = &Apache::loncommon::end_page();
1000:
1001: my $title;
1002: if (exists($env{'form.makeuser'})) {
1003: $title='Set Privileges for New User';
1004: } else {
1005: $title='Modify User Privileges';
1006: }
1007: $r->print(&Apache::loncommon::start_page($title));
1008: my %disallowed;
1009: # Check Inputs
1010: if (! $env{'form.ccuname'} ) {
1011: $r->print($error.&mt('No login name specified').'.'.$end);
1012: return;
1013: }
1014: if ( $env{'form.ccuname'} =~/\W/) {
1015: $r->print($error.&mt('Invalid login name').'. '.
1016: &mt('Only letters, numbers, and underscores are valid').'.'.
1017: $end);
1018: return;
1019: }
1020: if (! $env{'form.ccdomain'} ) {
1021: $r->print($error.&mt('No domain specified').'.'.$end);
1022: return;
1023: }
1024: if ( $env{'form.ccdomain'} =~/\W/) {
1025: $r->print($error.&mt ('Invalid domain name').'. '.
1026: &mt('Only letters, numbers, and underscores are valid').'.'.
1027: $end);
1028: return;
1029: }
1030: if (! exists($env{'form.makeuser'})) {
1031: # Modifying an existing user, so check the validity of the name
1032: if ($uhome eq 'no_host') {
1033: $r->print($error.&mt('Unable to determine home server for ').
1034: $env{'form.ccuname'}.&mt(' in domain ').
1035: $env{'form.ccdomain'}.'.');
1036: return;
1037: }
1038: }
1039: # Determine authentication method and password for the user being modified
1040: my $amode='';
1041: my $genpwd='';
1042: if ($env{'form.login'} eq 'krb') {
1043: $amode='krb';
1044: $amode.=$env{'form.krbver'};
1045: $genpwd=$env{'form.krbarg'};
1046: } elsif ($env{'form.login'} eq 'int') {
1047: $amode='internal';
1048: $genpwd=$env{'form.intarg'};
1049: } elsif ($env{'form.login'} eq 'fsys') {
1050: $amode='unix';
1051: $genpwd=$env{'form.fsysarg'};
1052: } elsif ($env{'form.login'} eq 'loc') {
1053: $amode='localauth';
1054: $genpwd=$env{'form.locarg'};
1055: $genpwd=" " if (!$genpwd);
1056: } elsif (($env{'form.login'} eq 'nochange') ||
1057: ($env{'form.login'} eq '' )) {
1058: # There is no need to tell the user we did not change what they
1059: # did not ask us to change.
1060: # If they are creating a new user but have not specified login
1061: # information this will be caught below.
1062: } else {
1063: $r->print($error.&mt('Invalid login mode or password').$end);
1064: return;
1065: }
1066: if ($env{'form.makeuser'}) {
1067: # Create a new user
1068: my %lt=&Apache::lonlocal::texthash(
1069: 'cru' => "Creating user",
1070: 'id' => "in domain"
1071: );
1072: $r->print(<<ENDNEWUSERHEAD);
1073: <h3>$lt{'cru'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h3>
1074: ENDNEWUSERHEAD
1075: # Check for the authentication mode and password
1076: if (! $amode || ! $genpwd) {
1077: $r->print($error.&mt('Invalid login mode or password').$end);
1078: return;
1079: }
1080: # Determine desired host
1081: my $desiredhost = $env{'form.hserver'};
1082: if (lc($desiredhost) eq 'default') {
1083: $desiredhost = undef;
1084: } else {
1085: my %home_servers = &Apache::loncommon::get_library_servers
1086: ($env{'form.ccdomain'});
1087: if (! exists($home_servers{$desiredhost})) {
1088: $r->print($error.&mt('Invalid home server specified'));
1089: return;
1090: }
1091: }
1092: # Call modifyuser
1093: my $result = &Apache::lonnet::modifyuser
1094: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
1095: $amode,$genpwd,$env{'form.cfirst'},
1096: $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1097: undef,$desiredhost
1098: );
1099: $r->print(&mt('Generating user').': '.$result);
1100: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
1101: $env{'form.ccdomain'});
1102: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1103: $Apache::lonnet::libserv{$home});
1104: } elsif (($env{'form.login'} ne 'nochange') &&
1105: ($env{'form.login'} ne '' )) {
1106: # Modify user privileges
1107: my %lt=&Apache::lonlocal::texthash(
1108: 'usr' => "User",
1109: 'id' => "in domain"
1110: );
1111: $r->print(<<ENDMODIFYUSERHEAD);
1112: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1113: ENDMODIFYUSERHEAD
1114: if (! $amode || ! $genpwd) {
1115: $r->print($error.'Invalid login mode or password'.$end);
1116: return;
1117: }
1118: # Only allow authentification modification if the person has authority
1119: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1120: $r->print('Modifying authentication: '.
1121: &Apache::lonnet::modifyuserauth(
1122: $env{'form.ccdomain'},$env{'form.ccuname'},
1123: $amode,$genpwd));
1124: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1125: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1126: } else {
1127: # Okay, this is a non-fatal error.
1128: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1129: }
1130: }
1131: ##
1132: if (! $env{'form.makeuser'} ) {
1133: # Check for need to change
1134: my %userenv = &Apache::lonnet::get
1135: ('environment',['firstname','middlename','lastname','generation'],
1136: $env{'form.ccdomain'},$env{'form.ccuname'});
1137: my ($tmp) = keys(%userenv);
1138: if ($tmp =~ /^(con_lost|error)/i) {
1139: %userenv = ();
1140: }
1141: # Check to see if we need to change user information
1142: foreach ('firstname','middlename','lastname','generation') {
1143: # Strip leading and trailing whitespace
1144: $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
1145: }
1146: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1147: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1148: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1149: $env{'form.clastname'} ne $userenv{'lastname'} ||
1150: $env{'form.cgeneration'} ne $userenv{'generation'} )) {
1151: # Make the change
1152: my %changeHash;
1153: $changeHash{'firstname'} = $env{'form.cfirstname'};
1154: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1155: $changeHash{'lastname'} = $env{'form.clastname'};
1156: $changeHash{'generation'} = $env{'form.cgeneration'};
1157: my $putresult = &Apache::lonnet::put
1158: ('environment',\%changeHash,
1159: $env{'form.ccdomain'},$env{'form.ccuname'});
1160: if ($putresult eq 'ok') {
1161: # Tell the user we changed the name
1162: my %lt=&Apache::lonlocal::texthash(
1163: 'uic' => "User Information Changed",
1164: 'frst' => "first",
1165: 'mddl' => "middle",
1166: 'lst' => "last",
1167: 'gen' => "generation",
1168: 'prvs' => "Previous",
1169: 'chto' => "Changed To"
1170: );
1171: $r->print(<<"END");
1172: <table border="2">
1173: <caption>$lt{'uic'}</caption>
1174: <tr><th> </th>
1175: <th>$lt{'frst'}</th>
1176: <th>$lt{'mddl'}</th>
1177: <th>$lt{'lst'}</th>
1178: <th>$lt{'gen'}</th></tr>
1179: <tr><td>$lt{'prvs'}</td>
1180: <td>$userenv{'firstname'} </td>
1181: <td>$userenv{'middlename'} </td>
1182: <td>$userenv{'lastname'} </td>
1183: <td>$userenv{'generation'} </td></tr>
1184: <tr><td>$lt{'chto'}</td>
1185: <td>$env{'form.cfirstname'} </td>
1186: <td>$env{'form.cmiddlename'} </td>
1187: <td>$env{'form.clastname'} </td>
1188: <td>$env{'form.cgeneration'} </td></tr>
1189: </table>
1190: END
1191: } else { # error occurred
1192: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1193: $env{'form.ccuname'}." ".&mt('in domain')." ".
1194: $env{'form.ccdomain'}."</h2>");
1195: }
1196: } else { # End of if ($env ... ) logic
1197: # They did not want to change the users name but we can
1198: # still tell them what the name is
1199: my %lt=&Apache::lonlocal::texthash(
1200: 'usr' => "User",
1201: 'id' => "in domain",
1202: 'gen' => "Generation"
1203: );
1204: $r->print(<<"END");
1205: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1206: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1207: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1208: END
1209: }
1210: }
1211: ##
1212: my %curr_groups;
1213: my $now=time;
1214: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1215: foreach (keys (%env)) {
1216: next if (! $env{$_});
1217: # Revoke roles
1218: if ($_=~/^form\.rev/) {
1219: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1220: # Revoke standard role
1221: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1222: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1223: $env{'form.ccuname'},$1,$2).'</b><br />');
1224: if ($2 eq 'st') {
1225: $1=~/^\/(\w+)\/(\w+)/;
1226: my $cid=$1.'_'.$2;
1227: $r->print(&mt('Drop from classlist').': <b>'.
1228: &Apache::lonnet::critical('put:'.
1229: $env{'course.'.$cid.'.domain'}.':'.
1230: $env{'course.'.$cid.'.num'}.':classlist:'.
1231: &Apache::lonnet::escape($env{'form.ccuname'}.':'.
1232: $env{'form.ccdomain'}).'='.
1233: &Apache::lonnet::escape($now.':'),
1234: $env{'course.'.$cid.'.home'}).'</b><br />');
1235: }
1236: }
1237: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1238: # Revoke custom role
1239: $r->print(&mt('Revoking custom role:').
1240: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
1241: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1242: $env{'form.ccuname'},$1,$2,$3,$4).
1243: '</b><br />');
1244: }
1245: } elsif ($_=~/^form\.del/) {
1246: if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
1247: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1248: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1249: $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1250: if ($2 eq 'st') {
1251: $1=~/^\/(\w+)\/(\w+)/;
1252: my $cid=$1.'_'.$2;
1253: $r->print(&mt('Drop from classlist').': <b>'.
1254: &Apache::lonnet::critical('put:'.
1255: $env{'course.'.$cid.'.domain'}.':'.
1256: $env{'course.'.$cid.'.num'}.':classlist:'.
1257: &Apache::lonnet::escape($env{'form.ccuname'}.':'.
1258: $env{'form.ccdomain'}).'='.
1259: &Apache::lonnet::escape($now.':'),
1260: $env{'course.'.$cid.'.home'}).'</b><br />');
1261: }
1262: }
1263: } elsif ($_=~/^form\.ren/) {
1264: my $udom = $env{'form.ccdomain'};
1265: my $uname = $env{'form.ccuname'};
1266: if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
1267: my $url = $1;
1268: my $role = $2;
1269: my $logmsg;
1270: my $output;
1271: if ($role eq 'st') {
1272: if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
1273: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1274: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1275: $output = "Error: $result\n";
1276: } else {
1277: $output = &mt('Assigning').' '.$role.' in '.$url.
1278: &mt('starting').' '.localtime($now).
1279: ': <br />'.$logmsg.'<br />'.
1280: &mt('Add to classlist').': <b>ok</b><br />';
1281: }
1282: }
1283: } else {
1284: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1285: $env{'form.ccuname'},$url,$role,0,$now);
1286: $output = &mt('Re-Enabling [_1] in [_2]: [_3]',
1287: $role,$url,$result).'<br />';
1288: }
1289: $r->print($output);
1290: }
1291: } elsif ($_=~/^form\.act/) {
1292: my $udom = $env{'form.ccdomain'};
1293: my $uname = $env{'form.ccuname'};
1294: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1295: # Activate a custom role
1296: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1297: my $url='/'.$one.'/'.$two;
1298: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1299:
1300: my $start = ( $env{'form.start_'.$full} ?
1301: $env{'form.start_'.$full} :
1302: $now );
1303: my $end = ( $env{'form.end_'.$full} ?
1304: $env{'form.end_'.$full} :
1305: 0 );
1306:
1307: # split multiple sections
1308: my %sections = ();
1309: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1310: if ($num_sections == 0) {
1311: $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1312: } else {
1313: my $numgrp=&Apache::loncommon::coursegroups(\%curr_groups,
1314: $one,$two);
1315: foreach my $sec (sort {$a cmp $b} keys %sections) {
1316: if (($sec eq 'none') || ($sec eq 'all') ||
1317: exists($curr_groups{$sec})) {
1318: $disallowed{$sec} = $url;
1319: next;
1320: }
1321: my $securl = $url.'/'.$sec;
1322: $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1323: }
1324: }
1325: } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
1326: # Activate roles for sections with 3 id numbers
1327: # set start, end times, and the url for the class
1328: my ($one,$two,$three)=($1,$2,$3);
1329: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1330: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1331: $now );
1332: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1333: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1334: 0 );
1335: my $url='/'.$one.'/'.$two;
1336: my $type = 'three';
1337: # split multiple sections
1338: my %sections = ();
1339: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1340: if ($num_sections == 0) {
1341: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1342: } else {
1343: my $numgrp=&Apache::loncommon::coursegroups(\%curr_groups,
1344: $one,$two);
1345: my $emptysec = 0;
1346: foreach my $sec (sort {$a cmp $b} keys %sections) {
1347: $sec =~ s/\W//g;
1348: if ($sec ne '') {
1349: if (($sec eq 'none') || ($sec eq 'all') ||
1350: exists($curr_groups{$sec})) {
1351: $disallowed{$sec} = $url;
1352: next;
1353: }
1354: my $securl = $url.'/'.$sec;
1355: $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1356: } else {
1357: $emptysec = 1;
1358: }
1359: }
1360: if ($emptysec) {
1361: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1362: }
1363: }
1364: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1365: # Activate roles for sections with two id numbers
1366: # set start, end times, and the url for the class
1367: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1368: $env{'form.start_'.$1.'_'.$2} :
1369: $now );
1370: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1371: $env{'form.end_'.$1.'_'.$2} :
1372: 0 );
1373: my $url='/'.$1.'/';
1374: # split multiple sections
1375: my %sections = ();
1376: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1377: if ($num_sections == 0) {
1378: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1379: } else {
1380: my $emptysec = 0;
1381: foreach my $sec (sort {$a cmp $b} keys %sections) {
1382: if ($sec ne '') {
1383: my $securl = $url.'/'.$sec;
1384: $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1385: } else {
1386: $emptysec = 1;
1387: }
1388: }
1389: if ($emptysec) {
1390: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1391: }
1392: }
1393: } else {
1394: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br />');
1395: }
1396: foreach my $key (sort(keys(%disallowed))) {
1397: if (($key eq 'none') || ($key eq 'all')) {
1398: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
1399: } else {
1400: $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));
1401: }
1402: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
1403: }
1404: }
1405: } # End of foreach (keys(%env))
1406: # Flush the course logs so reverse user roles immediately updated
1407: &Apache::lonnet::flushcourselogs();
1408: $r->print('<p><a href="/adm/createuser">Create/Modify Another User</a></p>');
1409: $r->print(&Apache::loncommon::end_page());
1410: }
1411:
1412: sub commit_customrole {
1413: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
1414: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1415: ($start?', '.&mt('starting').' '.localtime($start):'').
1416: ($end?', ending '.localtime($end):'').': <b>'.
1417: &Apache::lonnet::assigncustomrole(
1418: $udom,$uname,$url,$three,$four,$five,$end,$start).
1419: '</b><br />';
1420: return $output;
1421: }
1422:
1423: sub commit_standardrole {
1424: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1425: my $output;
1426: my $logmsg;
1427: if ($three eq 'st') {
1428: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
1429: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1430: $output = "Error: $result\n";
1431: } else {
1432: $output = &mt('Assigning').' '.$three.' in '.$url.
1433: ($start?', '.&mt('starting').' '.localtime($start):'').
1434: ($end?', '.&mt('ending').' '.localtime($end):'').
1435: ': <b>'.$result.'</b><br />'.
1436: &mt('Add to classlist').': <b>ok</b><br />';
1437: }
1438: } else {
1439: $output = &mt('Assigning').' '.$three.' in '.$url.
1440: ($start?', '.&mt('starting').' '.localtime($start):'').
1441: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1442: &Apache::lonnet::assignrole(
1443: $udom,$uname,$url,$three,$end,$start).
1444: '</b><br />';
1445: }
1446: return $output;
1447: }
1448:
1449: sub commit_studentrole {
1450: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1451: my $linefeed = '<br />'."\n";
1452: my $result;
1453: if (defined($one) && defined($two)) {
1454: my $cid=$one.'_'.$two;
1455: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
1456: my $secchange = 0;
1457: my $expire_role_result;
1458: my $modify_section_result;
1459: unless ($oldsec eq '-1') {
1460: unless ($sec eq $oldsec) {
1461: $secchange = 1;
1462: my $uurl='/'.$cid;
1463: $uurl=~s/\_/\//g;
1464: if ($oldsec) {
1465: $uurl.='/'.$oldsec;
1466: }
1467: $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
1468: $result = $expire_role_result;
1469: }
1470: }
1471: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1472: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
1473: if ($modify_section_result =~ /^ok/) {
1474: if ($secchange == 1) {
1475: $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
1476: } elsif ($oldsec eq '-1') {
1477: $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
1478: } else {
1479: $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
1480: }
1481: } else {
1482: $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
1483: }
1484: $result = $modify_section_result;
1485: } elsif ($secchange == 1) {
1486: $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
1487: }
1488: } else {
1489: $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
1490: $result = "error: incomplete course id\n";
1491: }
1492: return $result;
1493: }
1494:
1495: sub build_roles {
1496: my ($sectionstr,$sections,$role) = @_;
1497: my $num_sections = 0;
1498: if ($sectionstr=~ /,/) {
1499: my @secnums = split/,/,$sectionstr;
1500: if ($role eq 'st') {
1501: $secnums[0] =~ s/\W//g;
1502: $$sections{$secnums[0]} = 1;
1503: $num_sections = 1;
1504: } else {
1505: foreach my $sec (@secnums) {
1506: $sec =~ ~s/\W//g;
1507: unless ($sec eq "") {
1508: if (exists($$sections{$sec})) {
1509: $$sections{$sec} ++;
1510: } else {
1511: $$sections{$sec} = 1;
1512: $num_sections ++;
1513: }
1514: }
1515: }
1516: }
1517: } else {
1518: $sectionstr=~s/\W//g;
1519: unless ($sectionstr eq '') {
1520: $$sections{$sectionstr} = 1;
1521: $num_sections ++;
1522: }
1523: }
1524:
1525: return $num_sections;
1526: }
1527:
1528: # ========================================================== Custom Role Editor
1529:
1530: sub custom_role_editor {
1531: my $r=shift;
1532: my $rolename=$env{'form.rolename'};
1533:
1534: if ($rolename eq 'make new role') {
1535: $rolename=$env{'form.newrolename'};
1536: }
1537:
1538: $rolename=~s/[^A-Za-z0-9]//gs;
1539:
1540: unless ($rolename) {
1541: &print_username_entry_form($r);
1542: return;
1543: }
1544:
1545: $r->print(&Apache::loncommon::start_page('Custom Role Editor'));
1546: my $syspriv='';
1547: my $dompriv='';
1548: my $coursepriv='';
1549: my ($rdummy,$roledef)=
1550: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1551: # ------------------------------------------------------- Does this role exist?
1552: $r->print('<h2>');
1553: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1554: $r->print(&mt('Existing Role').' "');
1555: # ------------------------------------------------- Get current role privileges
1556: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1557: } else {
1558: $r->print(&mt('New Role').' "');
1559: $roledef='';
1560: }
1561: $r->print($rolename.'"</h2>');
1562: # ------------------------------------------------------- What can be assigned?
1563: my %full=();
1564: my %courselevel=();
1565: my %courselevelcurrent=();
1566: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1567: my ($priv,$restrict)=split(/\&/,$_);
1568: unless ($restrict) { $restrict='F'; }
1569: $courselevel{$priv}=$restrict;
1570: if ($coursepriv=~/\:$priv/) {
1571: $courselevelcurrent{$priv}=1;
1572: }
1573: $full{$priv}=1;
1574: }
1575: my %domainlevel=();
1576: my %domainlevelcurrent=();
1577: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1578: my ($priv,$restrict)=split(/\&/,$_);
1579: unless ($restrict) { $restrict='F'; }
1580: $domainlevel{$priv}=$restrict;
1581: if ($dompriv=~/\:$priv/) {
1582: $domainlevelcurrent{$priv}=1;
1583: }
1584: $full{$priv}=1;
1585: }
1586: my %systemlevel=();
1587: my %systemlevelcurrent=();
1588: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1589: my ($priv,$restrict)=split(/\&/,$_);
1590: unless ($restrict) { $restrict='F'; }
1591: $systemlevel{$priv}=$restrict;
1592: if ($syspriv=~/\:$priv/) {
1593: $systemlevelcurrent{$priv}=1;
1594: }
1595: $full{$priv}=1;
1596: }
1597: my %lt=&Apache::lonlocal::texthash(
1598: 'prv' => "Privilege",
1599: 'crl' => "Course Level",
1600: 'dml' => "Domain Level",
1601: 'ssl' => "System Level"
1602: );
1603: $r->print(<<ENDCCF);
1604: <form method="post">
1605: <input type="hidden" name="phase" value="set_custom_roles" />
1606: <input type="hidden" name="rolename" value="$rolename" />
1607: <table border="2">
1608: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1609: <th>$lt{'ssl'}</th></tr>
1610: ENDCCF
1611: foreach (sort keys %full) {
1612: $r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
1613: ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
1614: ($courselevelcurrent{$_}?'checked="1"':'').' />':' ').
1615: '</td><td>'.
1616: ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
1617: ($domainlevelcurrent{$_}?'checked="1"':'').' />':' ').
1618: '</td><td>'.
1619: ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
1620: ($systemlevelcurrent{$_}?'checked="1"':'').' />':' ').
1621: '</td></tr>');
1622: }
1623: $r->print(
1624: '<table><input type="submit" value="'.&mt('Define Role').'" /></form>'.
1625: &Apache::loncommon::end_page());
1626: }
1627:
1628: # ---------------------------------------------------------- Call to definerole
1629: sub set_custom_role {
1630: my ($r) = @_;
1631:
1632: my $rolename=$env{'form.rolename'};
1633:
1634: $rolename=~s/[^A-Za-z0-9]//gs;
1635:
1636: unless ($rolename) {
1637: &print_username_entry_form($r);
1638: return;
1639: }
1640:
1641: $r->print(&Apache::loncommon::start_page('Save Custom Role').'<h2>');
1642: my ($rdummy,$roledef)=
1643: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1644:
1645: # ------------------------------------------------------- Does this role exist?
1646: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1647: $r->print(&mt('Existing Role').' "');
1648: } else {
1649: $r->print(&mt('New Role').' "');
1650: $roledef='';
1651: }
1652: $r->print($rolename.'"</h2>');
1653: # ------------------------------------------------------- What can be assigned?
1654: my $sysrole='';
1655: my $domrole='';
1656: my $courole='';
1657:
1658: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1659: my ($priv,$restrict)=split(/\&/,$_);
1660: unless ($restrict) { $restrict=''; }
1661: if ($env{'form.'.$priv.':c'}) {
1662: $courole.=':'.$_;
1663: }
1664: }
1665:
1666: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1667: my ($priv,$restrict)=split(/\&/,$_);
1668: unless ($restrict) { $restrict=''; }
1669: if ($env{'form.'.$priv.':d'}) {
1670: $domrole.=':'.$_;
1671: }
1672: }
1673:
1674: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1675: my ($priv,$restrict)=split(/\&/,$_);
1676: unless ($restrict) { $restrict=''; }
1677: if ($env{'form.'.$priv.':s'}) {
1678: $sysrole.=':'.$_;
1679: }
1680: }
1681: $r->print('<br />Defining Role: '.
1682: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1683: if ($env{'request.course.id'}) {
1684: my $url='/'.$env{'request.course.id'};
1685: $url=~s/\_/\//g;
1686: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1687: &Apache::lonnet::assigncustomrole($env{'user.domain'},
1688: $env{'user.name'},
1689: $url,
1690: $env{'user.domain'},
1691: $env{'user.name'},
1692: $rolename));
1693: }
1694: $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p>');
1695: $r->print(&Apache::loncommon::end_page());
1696: }
1697:
1698: # ================================================================ Main Handler
1699: sub handler {
1700: my $r = shift;
1701:
1702: if ($r->header_only) {
1703: &Apache::loncommon::content_type($r,'text/html');
1704: $r->send_http_header;
1705: return OK;
1706: }
1707:
1708: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
1709: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
1710: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
1711: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1712: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1713: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1714: &Apache::loncommon::content_type($r,'text/html');
1715: $r->send_http_header;
1716: unless ($env{'form.phase'}) {
1717: &print_username_entry_form($r);
1718: }
1719: if ($env{'form.phase'} eq 'get_user_info') {
1720: &print_user_modification_page($r);
1721: } elsif ($env{'form.phase'} eq 'update_user_data') {
1722: &update_user_data($r);
1723: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1724: &custom_role_editor($r);
1725: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1726: &set_custom_role($r);
1727: }
1728: } else {
1729: $env{'user.error.msg'}=
1730: "/adm/createuser:mau:0:0:Cannot modify user data";
1731: return HTTP_NOT_ACCEPTABLE;
1732: }
1733: return OK;
1734: }
1735:
1736: #-------------------------------------------------- functions for &phase_two
1737: sub course_level_table {
1738: my (%inccourses) = @_;
1739: my $table = '';
1740: # Custom Roles?
1741:
1742: my %customroles=&my_custom_roles();
1743: my %lt=&Apache::lonlocal::texthash(
1744: 'exs' => "Existing sections",
1745: 'new' => "Define new section",
1746: 'ssd' => "Set Start Date",
1747: 'sed' => "Set End Date",
1748: 'crl' => "Course Level",
1749: 'act' => "Activate",
1750: 'rol' => "Role",
1751: 'ext' => "Extent",
1752: 'grs' => "Section",
1753: 'sta' => "Start",
1754: 'end' => "End"
1755: );
1756:
1757: foreach (sort( keys(%inccourses))) {
1758: my $thiscourse=$_;
1759: my $protectedcourse=$_;
1760: $thiscourse=~s:_:/:g;
1761: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1762: my $area=$coursedata{'description'};
1763: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1764: my $bgcol=$thiscourse;
1765: $bgcol=~s/[^7-9a-e]//g;
1766: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1767: my ($domain,$cnum)=split(/\//,$thiscourse);
1768: my %sections_count = ();
1769: my $num_sections = 0;
1770: if (defined($env{'request.course.id'})) {
1771: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1772: $num_sections = &Apache::loncommon::get_sections($domain,$cnum,\%sections_count);
1773: }
1774: }
1775: foreach ('st','ta','ep','ad','in','cc') {
1776: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1777: my $plrole=&Apache::lonnet::plaintext($_);
1778: $table .= <<ENDEXTENT;
1779: <tr bgcolor="#$bgcol">
1780: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1781: <td>$plrole</td>
1782: <td>$area<br />Domain: $domain</td>
1783: ENDEXTENT
1784: if ($_ ne 'cc') {
1785: if ($num_sections > 0) {
1786: my $currsec = &course_sections($num_sections,\%sections_count,$protectedcourse.'_'.$_);
1787: $table .=
1788: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1789: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1790: $currsec.'</td>'.
1791: '<td> </td>'.
1792: '<td valign="top"> '.$lt{'new'}.'<br />'.
1793: '<input type="text" name="newsec_'.$protectedcourse.'_'.$_.'" value="" /></td>'.
1794: '<input type="hidden" '.
1795: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>'.
1796: '</tr></table></td>';
1797: } else {
1798: $table .= '<td><input type="text" size="10" '.
1799: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>';
1800: }
1801: } else {
1802: $table .= '<td> </td>';
1803: }
1804: $table .= <<ENDTIMEENTRY;
1805: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1806: <a href=
1807: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1808: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1809: <a href=
1810: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1811: ENDTIMEENTRY
1812: $table.= "</tr>\n";
1813: }
1814: }
1815: foreach (sort keys %customroles) {
1816: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1817: my $plrole=$_;
1818: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
1819: '_'.$env{'user.name'}.'_'.$plrole;
1820: $table .= <<END;
1821: <tr bgcolor="#$bgcol">
1822: <td><input type="checkbox" name="act_$customrole"></td>
1823: <td>$plrole</td>
1824: <td>$area</td>
1825: END
1826: if ($num_sections > 0) {
1827: my $currsec = &course_sections($num_sections,\%sections_count,$customrole);
1828: $table.=
1829: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1830: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1831: $currsec.'</td>'.
1832: '<td> </td>'.
1833: '<td valign="top"> '.$lt{'new'}.'<br />'.
1834: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
1835: '<input type="hidden" '.
1836: 'name="sec_'.$customrole.'"></td>'.
1837: '</tr></table></td>';
1838: } else {
1839: $table .= '<td><input type="text" size="10" '.
1840: 'name="sec_'.$customrole.'"></td>';
1841: }
1842: $table .= <<ENDENTRY;
1843: <td><input type=hidden name="start_$customrole" value=''>
1844: <a href=
1845: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1846: <td><input type=hidden name="end_$customrole" value=''>
1847: <a href=
1848: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td></tr>
1849: ENDENTRY
1850: }
1851: }
1852: }
1853: return '' if ($table eq ''); # return nothing if there is nothing
1854: # in the table
1855: my $result = <<ENDTABLE;
1856: <h4>$lt{'crl'}</h4>
1857: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1858: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1859: $table
1860: </table>
1861: ENDTABLE
1862: return $result;
1863: }
1864:
1865: sub course_sections {
1866: my ($num_sections,$sections_count,$role) = @_;
1867: my $output = '';
1868: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1869: if ($num_sections == 1) {
1870: $output = '<select name="currsec_'.$role.'" >'."\n".
1871: ' <option value="">Select</option>'."\n".
1872: ' <option value="">No section</option>'."\n".
1873: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1874: } else {
1875: $output = '<select name="currsec_'.$role.'" ';
1876: my $multiple = 4;
1877: if ($num_sections <4) { $multiple = $num_sections; }
1878: $output .= '"multiple" size="'.$multiple.'">'."\n";
1879: foreach (@sections) {
1880: $output .= '<option value="'.$_.'">'.$_."</option>\n";
1881: }
1882: }
1883: $output .= '</select>';
1884: return $output;
1885: }
1886:
1887: sub course_level_dc {
1888: my ($dcdom) = @_;
1889: my %customroles=&my_custom_roles();
1890: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
1891: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1892: '<input type="hidden" name="dccourse" value="" />';
1893: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1894: ('cu','dccourse','dcdomain','coursedesc').'</b>';
1895:
1896: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom);
1897: my %lt=&Apache::lonlocal::texthash(
1898: 'crl' => "Course Level",
1899: 'crt' => "Course Title",
1900: 'rol' => "Role",
1901: 'grs' => "Section",
1902: 'exs' => "Existing sections",
1903: 'new' => "Define new section",
1904: 'sta' => "Start",
1905: 'end' => "End",
1906: 'ssd' => "Set Start Date",
1907: 'sed' => "Set End Date"
1908: );
1909: my $header = '<h4>'.$lt{'crl'}.'</h4>'.
1910: '<table border="2"><tr><th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th></tr>';
1911: my $otheritems = '<tr><td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'".'cu'."'".','."'".'dccourse'."'".','."'".'dcdomain'."'".','."'".'coursedesc'."',''".')" /></td>'.
1912: '<td><select name="role">'."\n";
1913: foreach ('st','ta','ep','ad','in','cc') {
1914: my $plrole=&Apache::lonnet::plaintext($_);
1915: $otheritems .= ' <option value="'.$_.'">'.$plrole;
1916: }
1917: if ( keys %customroles > 0) {
1918: foreach (sort keys %customroles) {
1919: my $custrole='cr_cr_'.$env{'user.domain'}.
1920: '_'.$env{'user.name'}.'_'.$_;
1921: $otheritems .= ' <option value="'.$custrole.'">'.$_;
1922: }
1923: }
1924: $otheritems .= '</select></td><td>'.
1925: '<table border="0" cellspacing="0" cellpadding="0">'.
1926: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1927: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
1928: '<td> </td>'.
1929: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1930: '<input type="text" name="newsec" value="" />'.
1931: '<input type="hidden" name="groups" value="" /></td>'.
1932: '</tr></table></td>';
1933: $otheritems .= <<ENDTIMEENTRY;
1934: <td><input type=hidden name="start" value=''>
1935: <a href=
1936: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1937: <td><input type=hidden name="end" value=''>
1938: <a href=
1939: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
1940: ENDTIMEENTRY
1941: $otheritems .= "</tr></table>\n";
1942: return $cb_jscript.$header.$hiddenitems.$otheritems;
1943: }
1944:
1945: #---------------------------------------------- end functions for &phase_two
1946:
1947: #--------------------------------- functions for &phase_two and &phase_three
1948:
1949: #--------------------------end of functions for &phase_two and &phase_three
1950:
1951: 1;
1952: __END__
1953:
1954:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>