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