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