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