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