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