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