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