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