Annotation of loncom/interface/loncreateuser.pm, revision 1.129
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.129 ! albertel 4: # $Id: loncreateuser.pm,v 1.128 2006/07/02 12:18:01 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');
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
323: document.cu.elements[numcourse].name = "act"+coursename
1.119 raeburn 324: document.cu.elements[numcourse+5].name = "sec"+coursename
325: document.cu.elements[numcourse+5].value = section
326: document.cu.elements[numcourse+7].name = "start"+coursename
327: document.cu.elements[numcourse+8].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.127 albertel 343: var crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
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.128 raeburn 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.79 albertel 607: $sortkey.="\0$1";
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.37 matthew 622: $inccourses{$1.'_'.$2}=1;
1.53 www 623: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
624: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37 matthew 625: $allowed=1;
626: }
1.53 www 627: if ((&Apache::lonnet::allowed('dro',$1)) ||
628: (&Apache::lonnet::allowed('dro',$ccdomain))) {
629: $delallowed=1;
630: }
1.64 www 631: # - custom role. Needs more info, too
632: if ($croletitle) {
633: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
634: $allowed=1;
635: $thisrole.='.'.$role_code;
636: }
637: }
1.37 matthew 638: # Compute the background color based on $area
639: $bgcol=$1.'_'.$2;
1.62 www 640: $bgcol=~s/[^7-9a-e]//g;
641: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.37 matthew 642: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
1.113 raeburn 643: $carea.='<br />Section: '.$3;
1.87 albertel 644: $sortkey.="\0$3";
1.37 matthew 645: }
646: $area=$carea;
647: } else {
1.79 albertel 648: $sortkey.="\0".$area;
1.37 matthew 649: # Determine if current user is able to revoke privileges
650: if ($area=~ /^\/(\w+)\//) {
1.53 www 651: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
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: ($role_code ne 'dc')) {
658: $delallowed=1;
659: }
1.37 matthew 660: } else {
661: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
662: $allowed=1;
663: }
664: }
1.79 albertel 665: if ($role_code eq 'ca' || $role_code eq 'au') {
666: $class='Construction Space';
667: } elsif ($role_code eq 'su') {
668: $class='System';
669: } else {
670: $class='Domain';
671: }
1.37 matthew 672: }
1.105 www 673: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1.43 www 674: $area=~/\/(\w+)\/(\w+)/;
675: if (&authorpriv($2,$1)) {
676: $allowed=1;
677: } else {
678: $allowed=0;
1.37 matthew 679: }
680: }
1.79 albertel 681: $bgcol='77FF77';
1.37 matthew 682: my $row = '';
1.62 www 683: $row.='<tr bgcolor="#'.$bgcol.'"><td>';
1.37 matthew 684: my $active=1;
685: $active=0 if (($role_end_time) && ($now>$role_end_time));
686: if (($active) && ($allowed)) {
687: $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
688: } else {
1.56 www 689: if ($active) {
690: $row.=' ';
691: } else {
1.72 sakharuk 692: $row.=&mt('expired or revoked');
1.56 www 693: }
1.37 matthew 694: }
1.53 www 695: $row.='</td><td>';
1.81 albertel 696: if ($allowed && !$active) {
697: $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
698: } else {
699: $row.=' ';
700: }
701: $row.='</td><td>';
1.53 www 702: if ($delallowed) {
703: $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
704: } else {
705: $row.=' ';
706: }
1.64 www 707: my $plaintext='';
708: unless ($croletitle) {
1.120 raeburn 709: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1.64 www 710: } else {
711: $plaintext=
712: "Customrole '$croletitle' defined by $croleuname\@$croleudom";
713: }
714: $row.= '</td><td>'.$plaintext.
1.37 matthew 715: '</td><td>'.$area.
716: '</td><td>'.($role_start_time?localtime($role_start_time)
717: : ' ' ).
718: '</td><td>'.($role_end_time ?localtime($role_end_time)
719: : ' ' )
720: ."</td></tr>\n";
1.79 albertel 721: $sortrole{$sortkey}=$envkey;
722: $roletext{$envkey}=$row;
723: $roleclass{$envkey}=$class;
1.89 raeburn 724: $rolepriv{$envkey}=$allowed;
1.79 albertel 725: #$r->print($row);
1.28 matthew 726: } # end of foreach (table building loop)
1.89 raeburn 727: my $rolesdisplay = 0;
728: my %output = ();
1.119 raeburn 729: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1.89 raeburn 730: $output{$type} = '';
1.79 albertel 731: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1.89 raeburn 732: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
733: $output{$type}.=$roletext{$sortrole{$which}};
1.79 albertel 734: }
735: }
1.89 raeburn 736: unless($output{$type} eq '') {
737: $output{$type} = "<tr bgcolor='#BBffBB'>".
738: "<td align='center' colspan='7'>".&mt($type)."</td>".
739: $output{$type};
740: $rolesdisplay = 1;
1.79 albertel 741: }
742: }
1.89 raeburn 743: if ($rolesdisplay == 1) {
744: $r->print(<<END);
745: <hr />
746: <h3>$lt{'rer'}</h3>
747: <table>
748: <tr><th>$lt{'rev'}</th><th>$lt{'ren'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'e
749: xt'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
750: END
1.119 raeburn 751: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1.89 raeburn 752: if ($output{$type}) {
753: $r->print($output{$type}."\n");
754: }
755: }
756: $r->print('</table>');
757: }
1.28 matthew 758: } # End of unless
1.20 harris41 759: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.41 albertel 760: if ($currentauth=~/^krb(4|5):/) {
761: $currentauth=~/^krb(4|5):(.*)/;
1.108 albertel 762: my $krbdefdom=$2;
1.31 matthew 763: my %param = ( formname => 'document.cu',
764: kerb_def_dom => $krbdefdom
765: );
766: $loginscript = &Apache::loncommon::authform_header(%param);
1.20 harris41 767: }
1.26 matthew 768: # Check for a bad authentication type
1.41 albertel 769: unless ($currentauth=~/^krb(4|5):/ or
1.20 harris41 770: $currentauth=~/^unix:/ or
771: $currentauth=~/^internal:/ or
772: $currentauth=~/^localauth:/
1.26 matthew 773: ) { # bad authentication scheme
1.101 albertel 774: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.94 matthew 775: &initialize_authen_forms();
1.73 sakharuk 776: my %lt=&Apache::lonlocal::texthash(
777: 'err' => "ERROR",
778: 'uuas' => "This user has an unrecognized authentication scheme",
779: 'sldb' => "Please specify login data below",
780: 'ld' => "Login Data"
781: );
1.26 matthew 782: $r->print(<<ENDBADAUTH);
1.21 harris41 783: <hr />
1.31 matthew 784: <script type="text/javascript" language="Javascript">
1.21 harris41 785: $loginscript
1.31 matthew 786: </script>
1.73 sakharuk 787: <font color='#ff0000'>$lt{'err'}:</font>
788: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
789: <h3>$lt{'ld'}</h3>
1.31 matthew 790: <p>$generalrule</p>
791: <p>$authformkrb</p>
792: <p>$authformint</p>
793: <p>$authformfsys</p>
794: <p>$authformloc</p>
1.26 matthew 795: ENDBADAUTH
796: } else {
797: # This user is not allowed to modify the users
798: # authentication scheme, so just notify them of the problem
1.73 sakharuk 799: my %lt=&Apache::lonlocal::texthash(
800: 'err' => "ERROR",
801: 'uuas' => "This user has an unrecognized authentication scheme",
802: 'adcs' => "Please alert a domain coordinator of this situation"
803: );
1.26 matthew 804: $r->print(<<ENDBADAUTH);
805: <hr />
1.31 matthew 806: <script type="text/javascript" language="Javascript">
1.26 matthew 807: $loginscript
1.31 matthew 808: </script>
1.73 sakharuk 809: <font color="#ff0000"> $lt{'err'}: </font>
810: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1.26 matthew 811: <hr />
812: ENDBADAUTH
813: }
814: } else { # Authentication type is valid
1.20 harris41 815: my $authformcurrent='';
1.26 matthew 816: my $authform_other='';
1.94 matthew 817: &initialize_authen_forms();
1.41 albertel 818: if ($currentauth=~/^krb(4|5):/) {
1.20 harris41 819: $authformcurrent=$authformkrb;
1.31 matthew 820: $authform_other="<p>$authformint</p>\n".
821: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 822: }
823: elsif ($currentauth=~/^internal:/) {
824: $authformcurrent=$authformint;
1.31 matthew 825: $authform_other="<p>$authformkrb</p>".
826: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 827: }
828: elsif ($currentauth=~/^unix:/) {
829: $authformcurrent=$authformfsys;
1.31 matthew 830: $authform_other="<p>$authformkrb</p>".
831: "<p>$authformint</p><p>$authformloc;</p>";
1.20 harris41 832: }
833: elsif ($currentauth=~/^localauth:/) {
834: $authformcurrent=$authformloc;
1.31 matthew 835: $authform_other="<p>$authformkrb</p>".
836: "<p>$authformint</p><p>$authformfsys</p>";
1.20 harris41 837: }
1.53 www 838: $authformcurrent.=' <i>(will override current values)</i><br />';
1.101 albertel 839: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.26 matthew 840: # Current user has login modification privileges
1.73 sakharuk 841: my %lt=&Apache::lonlocal::texthash(
842: 'ccld' => "Change Current Login Data",
843: 'enld' => "Enter New Login Data"
844: );
1.26 matthew 845: $r->print(<<ENDOTHERAUTHS);
1.21 harris41 846: <hr />
1.31 matthew 847: <script type="text/javascript" language="Javascript">
1.21 harris41 848: $loginscript
1.31 matthew 849: </script>
1.73 sakharuk 850: <h3>$lt{'ccld'}</h3>
1.31 matthew 851: <p>$generalrule</p>
852: <p>$authformnop</p>
853: <p>$authformcurrent</p>
1.73 sakharuk 854: <h3>$lt{'enld'}</h3>
1.26 matthew 855: $authform_other
856: ENDOTHERAUTHS
857: }
858: } ## End of "check for bad authentication type" logic
1.25 matthew 859: } ## End of new user/old user logic
1.72 sakharuk 860: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
1.17 www 861: #
862: # Co-Author
863: #
1.101 albertel 864: if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
865: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1.44 matthew 866: # No sense in assigning co-author role to yourself
1.101 albertel 867: my $cuname=$env{'user.name'};
868: my $cudom=$env{'request.role.domain'};
1.72 sakharuk 869: my %lt=&Apache::lonlocal::texthash(
870: 'cs' => "Construction Space",
871: 'act' => "Activate",
872: 'rol' => "Role",
873: 'ext' => "Extent",
874: 'sta' => "Start",
1.80 www 875: 'end' => "End",
1.72 sakharuk 876: 'cau' => "Co-Author",
1.105 www 877: 'caa' => "Assistant Co-Author",
1.72 sakharuk 878: 'ssd' => "Set Start Date",
879: 'sed' => "Set End Date"
880: );
1.17 www 881: $r->print(<<ENDCOAUTH);
1.72 sakharuk 882: <h4>$lt{'cs'}</h4>
1.74 sakharuk 883: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1.72 sakharuk 884: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.17 www 885: <tr>
1.80 www 886: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
1.72 sakharuk 887: <td>$lt{'cau'}</td>
1.17 www 888: <td>$cudom\_$cuname</td>
1.80 www 889: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
1.17 www 890: <a href=
1.72 sakharuk 891: "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 892: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
1.17 www 893: <a href=
1.72 sakharuk 894: "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 895: </tr>
1.105 www 896: <tr>
897: <td><input type=checkbox name="act_$cudom\_$cuname\_aa" /></td>
898: <td>$lt{'caa'}</td>
899: <td>$cudom\_$cuname</td>
900: <td><input type=hidden name="start_$cudom\_$cuname\_aa" value='' />
901: <a href=
902: "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>
903: <td><input type=hidden name="end_$cudom\_$cuname\_aa" value='' />
904: <a href=
905: "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>
906: </tr>
1.17 www 907: </table>
908: ENDCOAUTH
909: }
1.8 www 910: #
911: # Domain level
912: #
1.89 raeburn 913: my $num_domain_level = 0;
914: my $domaintext =
915: '<h4>'.&mt('Domain Level').'</h4>'.
1.73 sakharuk 916: '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
1.89 raeburn 917: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>';
1.24 matthew 918: foreach ( sort( keys(%incdomains))) {
1.2 www 919: my $thisdomain=$_;
1.69 albertel 920: foreach ('dc','li','dg','au','sc') {
1.2 www 921: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8 www 922: my $plrole=&Apache::lonnet::plaintext($_);
1.72 sakharuk 923: my %lt=&Apache::lonlocal::texthash(
924: 'ssd' => "Set Start Date",
925: 'sed' => "Set End Date"
926: );
1.89 raeburn 927: $num_domain_level ++;
928: $domaintext .= <<"ENDDROW";
1.8 www 929: <tr>
930: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
931: <td>$plrole</td>
932: <td>$thisdomain</td>
933: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
934: <a href=
1.72 sakharuk 935: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.8 www 936: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
937: <a href=
1.72 sakharuk 938: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.8 www 939: </tr>
940: ENDDROW
1.2 www 941: }
1.24 matthew 942: }
943: }
1.89 raeburn 944: $domaintext.='</table>';
945: if ($num_domain_level > 0) {
946: $r->print($domaintext);
947: }
1.8 www 948: #
1.119 raeburn 949: # Course and group levels
1.8 www 950: #
1.88 raeburn 951:
1.101 albertel 952: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
1.119 raeburn 953: $r->print(&course_level_dc($1,'Course'));
1.88 raeburn 954: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
955: } else {
956: $r->print(&course_level_table(%inccourses));
1.89 raeburn 957: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()">'."\n");
1.88 raeburn 958: }
1.110 albertel 959: $r->print("</form>".&Apache::loncommon::end_page());
1.2 www 960: }
1.1 www 961:
1.4 www 962: # ================================================================= Phase Three
1.42 matthew 963: sub update_user_data {
1.4 www 964: my $r=shift;
1.101 albertel 965: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
966: $env{'form.ccdomain'});
1.27 matthew 967: # Error messages
1.73 sakharuk 968: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
1.110 albertel 969: my $end = &Apache::loncommon::end_page();
970:
1.40 www 971: my $title;
1.101 albertel 972: if (exists($env{'form.makeuser'})) {
1.40 www 973: $title='Set Privileges for New User';
974: } else {
975: $title='Modify User Privileges';
976: }
1.110 albertel 977: $r->print(&Apache::loncommon::start_page($title));
1.113 raeburn 978: my %disallowed;
1.27 matthew 979: # Check Inputs
1.101 albertel 980: if (! $env{'form.ccuname'} ) {
1.73 sakharuk 981: $r->print($error.&mt('No login name specified').'.'.$end);
1.27 matthew 982: return;
983: }
1.101 albertel 984: if ( $env{'form.ccuname'} =~/\W/) {
1.73 sakharuk 985: $r->print($error.&mt('Invalid login name').'. '.
986: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 987: $end);
988: return;
989: }
1.101 albertel 990: if (! $env{'form.ccdomain'} ) {
1.73 sakharuk 991: $r->print($error.&mt('No domain specified').'.'.$end);
1.27 matthew 992: return;
993: }
1.101 albertel 994: if ( $env{'form.ccdomain'} =~/\W/) {
1.73 sakharuk 995: $r->print($error.&mt ('Invalid domain name').'. '.
996: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 997: $end);
998: return;
999: }
1.101 albertel 1000: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1001: # Modifying an existing user, so check the validity of the name
1002: if ($uhome eq 'no_host') {
1.73 sakharuk 1003: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1004: $env{'form.ccuname'}.&mt(' in domain ').
1005: $env{'form.ccdomain'}.'.');
1.29 matthew 1006: return;
1007: }
1008: }
1.27 matthew 1009: # Determine authentication method and password for the user being modified
1010: my $amode='';
1011: my $genpwd='';
1.101 albertel 1012: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1013: $amode='krb';
1.101 albertel 1014: $amode.=$env{'form.krbver'};
1015: $genpwd=$env{'form.krbarg'};
1016: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1017: $amode='internal';
1.101 albertel 1018: $genpwd=$env{'form.intarg'};
1019: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1020: $amode='unix';
1.101 albertel 1021: $genpwd=$env{'form.fsysarg'};
1022: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1023: $amode='localauth';
1.101 albertel 1024: $genpwd=$env{'form.locarg'};
1.27 matthew 1025: $genpwd=" " if (!$genpwd);
1.101 albertel 1026: } elsif (($env{'form.login'} eq 'nochange') ||
1027: ($env{'form.login'} eq '' )) {
1.34 matthew 1028: # There is no need to tell the user we did not change what they
1029: # did not ask us to change.
1.35 matthew 1030: # If they are creating a new user but have not specified login
1031: # information this will be caught below.
1.30 matthew 1032: } else {
1.73 sakharuk 1033: $r->print($error.&mt('Invalid login mode or password').$end);
1.30 matthew 1034: return;
1.27 matthew 1035: }
1.101 albertel 1036: if ($env{'form.makeuser'}) {
1.27 matthew 1037: # Create a new user
1.73 sakharuk 1038: my %lt=&Apache::lonlocal::texthash(
1039: 'cru' => "Creating user",
1040: 'id' => "in domain"
1041: );
1.27 matthew 1042: $r->print(<<ENDNEWUSERHEAD);
1.101 albertel 1043: <h3>$lt{'cru'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h3>
1.27 matthew 1044: ENDNEWUSERHEAD
1045: # Check for the authentication mode and password
1046: if (! $amode || ! $genpwd) {
1.73 sakharuk 1047: $r->print($error.&mt('Invalid login mode or password').$end);
1.27 matthew 1048: return;
1.18 albertel 1049: }
1.29 matthew 1050: # Determine desired host
1.101 albertel 1051: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1052: if (lc($desiredhost) eq 'default') {
1053: $desiredhost = undef;
1054: } else {
1.39 matthew 1055: my %home_servers = &Apache::loncommon::get_library_servers
1.101 albertel 1056: ($env{'form.ccdomain'});
1.29 matthew 1057: if (! exists($home_servers{$desiredhost})) {
1.73 sakharuk 1058: $r->print($error.&mt('Invalid home server specified'));
1.29 matthew 1059: return;
1060: }
1061: }
1.27 matthew 1062: # Call modifyuser
1063: my $result = &Apache::lonnet::modifyuser
1.101 albertel 1064: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
1065: $amode,$genpwd,$env{'form.cfirst'},
1066: $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1.29 matthew 1067: undef,$desiredhost
1.27 matthew 1068: );
1.77 www 1069: $r->print(&mt('Generating user').': '.$result);
1.101 albertel 1070: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
1071: $env{'form.ccdomain'});
1.77 www 1072: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.29 matthew 1073: $Apache::lonnet::libserv{$home});
1.101 albertel 1074: } elsif (($env{'form.login'} ne 'nochange') &&
1075: ($env{'form.login'} ne '' )) {
1.27 matthew 1076: # Modify user privileges
1.73 sakharuk 1077: my %lt=&Apache::lonlocal::texthash(
1078: 'usr' => "User",
1079: 'id' => "in domain"
1080: );
1.27 matthew 1081: $r->print(<<ENDMODIFYUSERHEAD);
1.101 albertel 1082: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.27 matthew 1083: ENDMODIFYUSERHEAD
1084: if (! $amode || ! $genpwd) {
1085: $r->print($error.'Invalid login mode or password'.$end);
1086: return;
1.20 harris41 1087: }
1.27 matthew 1088: # Only allow authentification modification if the person has authority
1.101 albertel 1089: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1090: $r->print('Modifying authentication: '.
1.31 matthew 1091: &Apache::lonnet::modifyuserauth(
1.101 albertel 1092: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1093: $amode,$genpwd));
1.102 albertel 1094: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1095: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1096: } else {
1.27 matthew 1097: # Okay, this is a non-fatal error.
1.73 sakharuk 1098: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1.27 matthew 1099: }
1.28 matthew 1100: }
1101: ##
1.101 albertel 1102: if (! $env{'form.makeuser'} ) {
1.28 matthew 1103: # Check for need to change
1104: my %userenv = &Apache::lonnet::get
1105: ('environment',['firstname','middlename','lastname','generation'],
1.101 albertel 1106: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1107: my ($tmp) = keys(%userenv);
1108: if ($tmp =~ /^(con_lost|error)/i) {
1109: %userenv = ();
1110: }
1111: # Check to see if we need to change user information
1112: foreach ('firstname','middlename','lastname','generation') {
1113: # Strip leading and trailing whitespace
1.101 albertel 1114: $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
1.28 matthew 1115: }
1.101 albertel 1116: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1117: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1118: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1119: $env{'form.clastname'} ne $userenv{'lastname'} ||
1120: $env{'form.cgeneration'} ne $userenv{'generation'} )) {
1.28 matthew 1121: # Make the change
1122: my %changeHash;
1.101 albertel 1123: $changeHash{'firstname'} = $env{'form.cfirstname'};
1124: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1125: $changeHash{'lastname'} = $env{'form.clastname'};
1126: $changeHash{'generation'} = $env{'form.cgeneration'};
1.28 matthew 1127: my $putresult = &Apache::lonnet::put
1128: ('environment',\%changeHash,
1.101 albertel 1129: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1130: if ($putresult eq 'ok') {
1131: # Tell the user we changed the name
1.73 sakharuk 1132: my %lt=&Apache::lonlocal::texthash(
1133: 'uic' => "User Information Changed",
1134: 'frst' => "first",
1135: 'mddl' => "middle",
1136: 'lst' => "last",
1137: 'gen' => "generation",
1138: 'prvs' => "Previous",
1139: 'chto' => "Changed To"
1140: );
1.28 matthew 1141: $r->print(<<"END");
1142: <table border="2">
1.73 sakharuk 1143: <caption>$lt{'uic'}</caption>
1.28 matthew 1144: <tr><th> </th>
1.73 sakharuk 1145: <th>$lt{'frst'}</th>
1146: <th>$lt{'mddl'}</th>
1147: <th>$lt{'lst'}</th>
1148: <th>$lt{'gen'}</th></tr>
1149: <tr><td>$lt{'prvs'}</td>
1.28 matthew 1150: <td>$userenv{'firstname'} </td>
1151: <td>$userenv{'middlename'} </td>
1152: <td>$userenv{'lastname'} </td>
1153: <td>$userenv{'generation'} </td></tr>
1.73 sakharuk 1154: <tr><td>$lt{'chto'}</td>
1.101 albertel 1155: <td>$env{'form.cfirstname'} </td>
1156: <td>$env{'form.cmiddlename'} </td>
1157: <td>$env{'form.clastname'} </td>
1158: <td>$env{'form.cgeneration'} </td></tr>
1.28 matthew 1159: </table>
1160: END
1161: } else { # error occurred
1.73 sakharuk 1162: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1.101 albertel 1163: $env{'form.ccuname'}." ".&mt('in domain')." ".
1164: $env{'form.ccdomain'}."</h2>");
1.28 matthew 1165: }
1.101 albertel 1166: } else { # End of if ($env ... ) logic
1.28 matthew 1167: # They did not want to change the users name but we can
1168: # still tell them what the name is
1.73 sakharuk 1169: my %lt=&Apache::lonlocal::texthash(
1170: 'usr' => "User",
1171: 'id' => "in domain",
1172: 'gen' => "Generation"
1173: );
1.28 matthew 1174: $r->print(<<"END");
1.101 albertel 1175: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.28 matthew 1176: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1.73 sakharuk 1177: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1.28 matthew 1178: END
1179: }
1.4 www 1180: }
1.27 matthew 1181: ##
1.4 www 1182: my $now=time;
1.73 sakharuk 1183: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.101 albertel 1184: foreach (keys (%env)) {
1185: next if (! $env{$_});
1.27 matthew 1186: # Revoke roles
1187: if ($_=~/^form\.rev/) {
1.64 www 1188: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1189: # Revoke standard role
1.73 sakharuk 1190: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1.101 albertel 1191: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1.102 albertel 1192: $env{'form.ccuname'},$1,$2).'</b><br />');
1.53 www 1193: if ($2 eq 'st') {
1194: $1=~/^\/(\w+)\/(\w+)/;
1195: my $cid=$1.'_'.$2;
1.73 sakharuk 1196: $r->print(&mt('Drop from classlist').': <b>'.
1.53 www 1197: &Apache::lonnet::critical('put:'.
1.101 albertel 1198: $env{'course.'.$cid.'.domain'}.':'.
1199: $env{'course.'.$cid.'.num'}.':classlist:'.
1.118 www 1200: &escape($env{'form.ccuname'}.':'.
1.101 albertel 1201: $env{'form.ccdomain'}).'='.
1.118 www 1202: &escape($now.':'),
1.102 albertel 1203: $env{'course.'.$cid.'.home'}).'</b><br />');
1.53 www 1204: }
1205: }
1.64 www 1206: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1207: # Revoke custom role
1.113 raeburn 1208: $r->print(&mt('Revoking custom role:').
1.73 sakharuk 1209: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
1.101 albertel 1210: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1211: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 1212: '</b><br />');
1.64 www 1213: }
1.53 www 1214: } elsif ($_=~/^form\.del/) {
1.116 raeburn 1215: if ($_=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1216: # Delete standard role
1.73 sakharuk 1217: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.101 albertel 1218: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1.102 albertel 1219: $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1.27 matthew 1220: if ($2 eq 'st') {
1221: $1=~/^\/(\w+)\/(\w+)/;
1222: my $cid=$1.'_'.$2;
1.73 sakharuk 1223: $r->print(&mt('Drop from classlist').': <b>'.
1.27 matthew 1224: &Apache::lonnet::critical('put:'.
1.101 albertel 1225: $env{'course.'.$cid.'.domain'}.':'.
1226: $env{'course.'.$cid.'.num'}.':classlist:'.
1.118 www 1227: &escape($env{'form.ccuname'}.':'.
1.101 albertel 1228: $env{'form.ccdomain'}).'='.
1.118 www 1229: &escape($now.':'),
1.102 albertel 1230: $env{'course.'.$cid.'.home'}).'</b><br />');
1.81 albertel 1231: }
1.116 raeburn 1232: }
1233: if ($_=~/^form\.del\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1234: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1235: # Delete custom role
1236: $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
1237: $rolename,$rnam,$rdom,$url).': <b>'.
1238: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
1239: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1240: 0,1).'</b><br />');
1241: }
1.81 albertel 1242: } elsif ($_=~/^form\.ren/) {
1.101 albertel 1243: my $udom = $env{'form.ccdomain'};
1244: my $uname = $env{'form.ccuname'};
1.116 raeburn 1245: # Re-enable standard role
1246: if ($_=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 1247: my $url = $1;
1248: my $role = $2;
1249: my $logmsg;
1250: my $output;
1251: if ($role eq 'st') {
1252: if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
1.129 ! albertel 1253: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89 raeburn 1254: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1255: $output = "Error: $result\n";
1256: } else {
1257: $output = &mt('Assigning').' '.$role.' in '.$url.
1258: &mt('starting').' '.localtime($now).
1259: ': <br />'.$logmsg.'<br />'.
1260: &mt('Add to classlist').': <b>ok</b><br />';
1261: }
1262: }
1263: } else {
1.101 albertel 1264: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1265: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 1266: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 1267: $role,$url,$result).'<br />';
1.27 matthew 1268: }
1.89 raeburn 1269: $r->print($output);
1.113 raeburn 1270: }
1.116 raeburn 1271: # Re-enable custom role
1272: if ($_=~/^form\.ren\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1273: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1274: my $result = &Apache::lonnet::assigncustomrole(
1275: $env{'form.ccdomain'}, $env{'form.ccuname'},
1276: $url,$rdom,$rnam,$rolename,0,$now);
1277: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
1278: $rolename,$rnam,$rdom,$url,$result).'<br />');
1279: }
1.27 matthew 1280: } elsif ($_=~/^form\.act/) {
1.101 albertel 1281: my $udom = $env{'form.ccdomain'};
1282: my $uname = $env{'form.ccuname'};
1.83 albertel 1283: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1.65 www 1284: # Activate a custom role
1.83 albertel 1285: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1286: my $url='/'.$one.'/'.$two;
1287: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 1288:
1.101 albertel 1289: my $start = ( $env{'form.start_'.$full} ?
1290: $env{'form.start_'.$full} :
1.88 raeburn 1291: $now );
1.101 albertel 1292: my $end = ( $env{'form.end_'.$full} ?
1293: $env{'form.end_'.$full} :
1.88 raeburn 1294: 0 );
1295:
1296: # split multiple sections
1297: my %sections = ();
1.101 albertel 1298: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 1299: if ($num_sections == 0) {
1.129 ! albertel 1300: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 1301: } else {
1.114 albertel 1302: my %curr_groups =
1.117 raeburn 1303: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 1304: foreach my $sec (sort {$a cmp $b} keys %sections) {
1305: if (($sec eq 'none') || ($sec eq 'all') ||
1306: exists($curr_groups{$sec})) {
1307: $disallowed{$sec} = $url;
1308: next;
1309: }
1310: my $securl = $url.'/'.$sec;
1.129 ! albertel 1311: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 1312: }
1313: }
1.98 albertel 1314: } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
1.27 matthew 1315: # Activate roles for sections with 3 id numbers
1316: # set start, end times, and the url for the class
1.83 albertel 1317: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 1318: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1319: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1320: $now );
1.101 albertel 1321: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1322: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1323: 0 );
1.83 albertel 1324: my $url='/'.$one.'/'.$two;
1.88 raeburn 1325: my $type = 'three';
1326: # split multiple sections
1327: my %sections = ();
1.101 albertel 1328: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 1329: if ($num_sections == 0) {
1.129 ! albertel 1330: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1331: } else {
1.114 albertel 1332: my %curr_groups =
1.117 raeburn 1333: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 1334: my $emptysec = 0;
1335: foreach my $sec (sort {$a cmp $b} keys %sections) {
1336: $sec =~ s/\W//g;
1.113 raeburn 1337: if ($sec ne '') {
1338: if (($sec eq 'none') || ($sec eq 'all') ||
1339: exists($curr_groups{$sec})) {
1340: $disallowed{$sec} = $url;
1341: next;
1342: }
1.88 raeburn 1343: my $securl = $url.'/'.$sec;
1.129 ! albertel 1344: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 1345: } else {
1346: $emptysec = 1;
1347: }
1348: }
1349: if ($emptysec) {
1.129 ! albertel 1350: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1351: }
1352: }
1.27 matthew 1353: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1354: # Activate roles for sections with two id numbers
1355: # set start, end times, and the url for the class
1.101 albertel 1356: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1357: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 1358: $now );
1.101 albertel 1359: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1360: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 1361: 0 );
1362: my $url='/'.$1.'/';
1.88 raeburn 1363: # split multiple sections
1364: my %sections = ();
1.101 albertel 1365: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88 raeburn 1366: if ($num_sections == 0) {
1.129 ! albertel 1367: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1368: } else {
1369: my $emptysec = 0;
1370: foreach my $sec (sort {$a cmp $b} keys %sections) {
1371: if ($sec ne '') {
1372: my $securl = $url.'/'.$sec;
1.129 ! albertel 1373: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88 raeburn 1374: } else {
1375: $emptysec = 1;
1376: }
1377: }
1378: if ($emptysec) {
1.129 ! albertel 1379: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1380: }
1381: }
1.64 www 1382: } else {
1.102 albertel 1383: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br />');
1.64 www 1384: }
1.113 raeburn 1385: foreach my $key (sort(keys(%disallowed))) {
1386: if (($key eq 'none') || ($key eq 'all')) {
1387: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
1388: } else {
1389: $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));
1390: }
1391: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
1392: }
1393: }
1.101 albertel 1394: } # End of foreach (keys(%env))
1.75 www 1395: # Flush the course logs so reverse user roles immediately updated
1396: &Apache::lonnet::flushcourselogs();
1.103 albertel 1397: $r->print('<p><a href="/adm/createuser">Create/Modify Another User</a></p>');
1.110 albertel 1398: $r->print(&Apache::loncommon::end_page());
1.4 www 1399: }
1400:
1.88 raeburn 1401: sub build_roles {
1.89 raeburn 1402: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 1403: my $num_sections = 0;
1404: if ($sectionstr=~ /,/) {
1405: my @secnums = split/,/,$sectionstr;
1.89 raeburn 1406: if ($role eq 'st') {
1407: $secnums[0] =~ s/\W//g;
1408: $$sections{$secnums[0]} = 1;
1409: $num_sections = 1;
1410: } else {
1411: foreach my $sec (@secnums) {
1412: $sec =~ ~s/\W//g;
1413: unless ($sec eq "") {
1414: if (exists($$sections{$sec})) {
1415: $$sections{$sec} ++;
1416: } else {
1417: $$sections{$sec} = 1;
1418: $num_sections ++;
1419: }
1.88 raeburn 1420: }
1421: }
1422: }
1423: } else {
1424: $sectionstr=~s/\W//g;
1425: unless ($sectionstr eq '') {
1426: $$sections{$sectionstr} = 1;
1427: $num_sections ++;
1428: }
1429: }
1.129 ! albertel 1430:
1.88 raeburn 1431: return $num_sections;
1432: }
1433:
1.58 www 1434: # ========================================================== Custom Role Editor
1435:
1436: sub custom_role_editor {
1437: my $r=shift;
1.101 albertel 1438: my $rolename=$env{'form.rolename'};
1.58 www 1439:
1.59 www 1440: if ($rolename eq 'make new role') {
1.101 albertel 1441: $rolename=$env{'form.newrolename'};
1.59 www 1442: }
1443:
1.63 www 1444: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 1445:
1446: unless ($rolename) {
1447: &print_username_entry_form($r);
1448: return;
1449: }
1450:
1.110 albertel 1451: $r->print(&Apache::loncommon::start_page('Custom Role Editor'));
1.61 www 1452: my $syspriv='';
1453: my $dompriv='';
1454: my $coursepriv='';
1.59 www 1455: my ($rdummy,$roledef)=
1456: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 1457: # ------------------------------------------------------- Does this role exist?
1.110 albertel 1458: $r->print('<h2>');
1.59 www 1459: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1460: $r->print(&mt('Existing Role').' "');
1.61 www 1461: # ------------------------------------------------- Get current role privileges
1462: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 1463: } else {
1.73 sakharuk 1464: $r->print(&mt('New Role').' "');
1.59 www 1465: $roledef='';
1466: }
1467: $r->print($rolename.'"</h2>');
1.60 www 1468: # ------------------------------------------------------- What can be assigned?
1469: my %full=();
1470: my %courselevel=();
1.61 www 1471: my %courselevelcurrent=();
1.60 www 1472: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1473: my ($priv,$restrict)=split(/\&/,$_);
1474: unless ($restrict) { $restrict='F'; }
1475: $courselevel{$priv}=$restrict;
1.61 www 1476: if ($coursepriv=~/\:$priv/) {
1477: $courselevelcurrent{$priv}=1;
1478: }
1.60 www 1479: $full{$priv}=1;
1480: }
1481: my %domainlevel=();
1.61 www 1482: my %domainlevelcurrent=();
1.60 www 1483: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1484: my ($priv,$restrict)=split(/\&/,$_);
1485: unless ($restrict) { $restrict='F'; }
1486: $domainlevel{$priv}=$restrict;
1.61 www 1487: if ($dompriv=~/\:$priv/) {
1488: $domainlevelcurrent{$priv}=1;
1489: }
1.60 www 1490: $full{$priv}=1;
1491: }
1.61 www 1492: my %systemlevel=();
1493: my %systemlevelcurrent=();
1494: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1495: my ($priv,$restrict)=split(/\&/,$_);
1496: unless ($restrict) { $restrict='F'; }
1497: $systemlevel{$priv}=$restrict;
1498: if ($syspriv=~/\:$priv/) {
1499: $systemlevelcurrent{$priv}=1;
1500: }
1501: $full{$priv}=1;
1502: }
1.73 sakharuk 1503: my %lt=&Apache::lonlocal::texthash(
1504: 'prv' => "Privilege",
1.119 raeburn 1505: 'crl' => "Course/Group Level",
1.73 sakharuk 1506: 'dml' => "Domain Level",
1507: 'ssl' => "System Level"
1508: );
1.61 www 1509: $r->print(<<ENDCCF);
1510: <form method="post">
1511: <input type="hidden" name="phase" value="set_custom_roles" />
1512: <input type="hidden" name="rolename" value="$rolename" />
1513: <table border="2">
1.73 sakharuk 1514: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1515: <th>$lt{'ssl'}</th></tr>
1.61 www 1516: ENDCCF
1.119 raeburn 1517: foreach my $priv (sort keys %full) {
1518: my $privtext = &Apache::lonnet::plaintext($priv);
1519: $r->print('<tr><td>'.$privtext.'</td><td>'.
1520: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.':c" '.
1521: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1522: '</td><td>'.
1.119 raeburn 1523: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.':d" '.
1524: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1525: '</td><td>'.
1.119 raeburn 1526: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.':s" '.
1527: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1528: '</td></tr>');
1.60 www 1529: }
1.61 www 1530: $r->print(
1.110 albertel 1531: '<table><input type="submit" value="'.&mt('Define Role').'" /></form>'.
1532: &Apache::loncommon::end_page());
1.61 www 1533: }
1534:
1535: # ---------------------------------------------------------- Call to definerole
1536: sub set_custom_role {
1.110 albertel 1537: my ($r) = @_;
1.61 www 1538:
1.101 albertel 1539: my $rolename=$env{'form.rolename'};
1.61 www 1540:
1.63 www 1541: $rolename=~s/[^A-Za-z0-9]//gs;
1.61 www 1542:
1543: unless ($rolename) {
1544: &print_username_entry_form($r);
1545: return;
1546: }
1547:
1.110 albertel 1548: $r->print(&Apache::loncommon::start_page('Save Custom Role').'<h2>');
1.61 www 1549: my ($rdummy,$roledef)=
1.110 albertel 1550: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1551:
1.61 www 1552: # ------------------------------------------------------- Does this role exist?
1553: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1554: $r->print(&mt('Existing Role').' "');
1.61 www 1555: } else {
1.73 sakharuk 1556: $r->print(&mt('New Role').' "');
1.61 www 1557: $roledef='';
1558: }
1559: $r->print($rolename.'"</h2>');
1560: # ------------------------------------------------------- What can be assigned?
1561: my $sysrole='';
1562: my $domrole='';
1563: my $courole='';
1564:
1565: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1566: my ($priv,$restrict)=split(/\&/,$_);
1567: unless ($restrict) { $restrict=''; }
1.101 albertel 1568: if ($env{'form.'.$priv.':c'}) {
1.61 www 1569: $courole.=':'.$_;
1570: }
1571: }
1572:
1573: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1574: my ($priv,$restrict)=split(/\&/,$_);
1575: unless ($restrict) { $restrict=''; }
1.101 albertel 1576: if ($env{'form.'.$priv.':d'}) {
1.61 www 1577: $domrole.=':'.$_;
1578: }
1579: }
1580:
1581: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1582: my ($priv,$restrict)=split(/\&/,$_);
1583: unless ($restrict) { $restrict=''; }
1.101 albertel 1584: if ($env{'form.'.$priv.':s'}) {
1.61 www 1585: $sysrole.=':'.$_;
1586: }
1587: }
1.63 www 1588: $r->print('<br />Defining Role: '.
1.61 www 1589: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 1590: if ($env{'request.course.id'}) {
1591: my $url='/'.$env{'request.course.id'};
1.63 www 1592: $url=~s/\_/\//g;
1.73 sakharuk 1593: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 1594: &Apache::lonnet::assigncustomrole($env{'user.domain'},
1595: $env{'user.name'},
1.63 www 1596: $url,
1.101 albertel 1597: $env{'user.domain'},
1598: $env{'user.name'},
1.63 www 1599: $rolename));
1600: }
1.109 albertel 1601: $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p>');
1.110 albertel 1602: $r->print(&Apache::loncommon::end_page());
1.58 www 1603: }
1604:
1.2 www 1605: # ================================================================ Main Handler
1606: sub handler {
1607: my $r = shift;
1608:
1609: if ($r->header_only) {
1.68 www 1610: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1611: $r->send_http_header;
1612: return OK;
1613: }
1614:
1.101 albertel 1615: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
1616: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
1617: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
1618: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1.104 albertel 1619: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1.101 albertel 1620: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1.68 www 1621: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1622: $r->send_http_header;
1.101 albertel 1623: unless ($env{'form.phase'}) {
1.42 matthew 1624: &print_username_entry_form($r);
1.2 www 1625: }
1.101 albertel 1626: if ($env{'form.phase'} eq 'get_user_info') {
1.42 matthew 1627: &print_user_modification_page($r);
1.101 albertel 1628: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.42 matthew 1629: &update_user_data($r);
1.101 albertel 1630: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1.58 www 1631: &custom_role_editor($r);
1.101 albertel 1632: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1.61 www 1633: &set_custom_role($r);
1.2 www 1634: }
1.1 www 1635: } else {
1.101 albertel 1636: $env{'user.error.msg'}=
1.9 albertel 1637: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 1638: return HTTP_NOT_ACCEPTABLE;
1639: }
1640: return OK;
1641: }
1.26 matthew 1642:
1.27 matthew 1643: #-------------------------------------------------- functions for &phase_two
1.26 matthew 1644: sub course_level_table {
1.89 raeburn 1645: my (%inccourses) = @_;
1.26 matthew 1646: my $table = '';
1.62 www 1647: # Custom Roles?
1648:
1649: my %customroles=&my_custom_roles();
1.89 raeburn 1650: my %lt=&Apache::lonlocal::texthash(
1651: 'exs' => "Existing sections",
1652: 'new' => "Define new section",
1653: 'ssd' => "Set Start Date",
1654: 'sed' => "Set End Date",
1.119 raeburn 1655: 'crl' => "Course/Group Level",
1.89 raeburn 1656: 'act' => "Activate",
1657: 'rol' => "Role",
1658: 'ext' => "Extent",
1.113 raeburn 1659: 'grs' => "Section",
1.89 raeburn 1660: 'sta' => "Start",
1661: 'end' => "End"
1662: );
1.62 www 1663:
1.26 matthew 1664: foreach (sort( keys(%inccourses))) {
1665: my $thiscourse=$_;
1666: my $protectedcourse=$_;
1667: $thiscourse=~s:_:/:g;
1668: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1669: my $area=$coursedata{'description'};
1.119 raeburn 1670: my $type=$coursedata{'type'};
1.72 sakharuk 1671: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1.26 matthew 1672: my $bgcol=$thiscourse;
1.62 www 1673: $bgcol=~s/[^7-9a-e]//g;
1674: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.89 raeburn 1675: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 1676: my %sections_count;
1.101 albertel 1677: if (defined($env{'request.course.id'})) {
1678: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 1679: %sections_count =
1680: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 1681: }
1682: }
1.119 raeburn 1683: foreach ('st','ta','ep','in','cc') {
1.26 matthew 1684: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1685: my $plrole=&Apache::lonnet::plaintext($_);
1686: $table .= <<ENDEXTENT;
1687: <tr bgcolor="#$bgcol">
1688: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1689: <td>$plrole</td>
1.82 albertel 1690: <td>$area<br />Domain: $domain</td>
1.26 matthew 1691: ENDEXTENT
1692: if ($_ ne 'cc') {
1.115 albertel 1693: if (%sections_count) {
1694: my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$_);
1.89 raeburn 1695: $table .=
1696: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1697: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1698: $currsec.'</td>'.
1699: '<td> </td>'.
1700: '<td valign="top"> '.$lt{'new'}.'<br />'.
1701: '<input type="text" name="newsec_'.$protectedcourse.'_'.$_.'" value="" /></td>'.
1702: '<input type="hidden" '.
1703: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>'.
1704: '</tr></table></td>';
1705: } else {
1706: $table .= '<td><input type="text" size="10" '.
1707: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>';
1708: }
1.26 matthew 1709: } else {
1.89 raeburn 1710: $table .= '<td> </td>';
1.26 matthew 1711: }
1712: $table .= <<ENDTIMEENTRY;
1713: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1714: <a href=
1.73 sakharuk 1715: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.26 matthew 1716: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1717: <a href=
1.73 sakharuk 1718: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26 matthew 1719: ENDTIMEENTRY
1720: $table.= "</tr>\n";
1721: }
1722: }
1.62 www 1723: foreach (sort keys %customroles) {
1.65 www 1724: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1725: my $plrole=$_;
1.101 albertel 1726: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
1727: '_'.$env{'user.name'}.'_'.$plrole;
1.89 raeburn 1728: $table .= <<END;
1.62 www 1729: <tr bgcolor="#$bgcol">
1.65 www 1730: <td><input type="checkbox" name="act_$customrole"></td>
1.62 www 1731: <td>$plrole</td>
1732: <td>$area</td>
1.89 raeburn 1733: END
1.115 albertel 1734: if (%sections_count) {
1735: my $currsec = &course_sections(\%sections_count,$customrole);
1.89 raeburn 1736: $table.=
1737: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1738: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1739: $currsec.'</td>'.
1740: '<td> </td>'.
1741: '<td valign="top"> '.$lt{'new'}.'<br />'.
1742: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
1743: '<input type="hidden" '.
1744: 'name="sec_'.$customrole.'"></td>'.
1745: '</tr></table></td>';
1746: } else {
1747: $table .= '<td><input type="text" size="10" '.
1748: 'name="sec_'.$customrole.'"></td>';
1749: }
1750: $table .= <<ENDENTRY;
1.65 www 1751: <td><input type=hidden name="start_$customrole" value=''>
1.62 www 1752: <a href=
1.73 sakharuk 1753: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.65 www 1754: <td><input type=hidden name="end_$customrole" value=''>
1.62 www 1755: <a href=
1.73 sakharuk 1756: "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 1757: ENDENTRY
1.65 www 1758: }
1.62 www 1759: }
1.26 matthew 1760: }
1761: return '' if ($table eq ''); # return nothing if there is nothing
1762: # in the table
1763: my $result = <<ENDTABLE;
1.73 sakharuk 1764: <h4>$lt{'crl'}</h4>
1765: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1766: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.26 matthew 1767: $table
1768: </table>
1769: ENDTABLE
1770: return $result;
1771: }
1.88 raeburn 1772:
1.89 raeburn 1773: sub course_sections {
1.115 albertel 1774: my ($sections_count,$role) = @_;
1.89 raeburn 1775: my $output = '';
1776: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.115 albertel 1777: if (scalar(@sections) == 1) {
1.92 raeburn 1778: $output = '<select name="currsec_'.$role.'" >'."\n".
1779: ' <option value="">Select</option>'."\n".
1.93 raeburn 1780: ' <option value="">No section</option>'."\n".
1.92 raeburn 1781: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1782: } else {
1783: $output = '<select name="currsec_'.$role.'" ';
1784: my $multiple = 4;
1.115 albertel 1785: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.95 albertel 1786: $output .= '"multiple" size="'.$multiple.'">'."\n";
1.92 raeburn 1787: foreach (@sections) {
1788: $output .= '<option value="'.$_.'">'.$_."</option>\n";
1789: }
1.89 raeburn 1790: }
1791: $output .= '</select>';
1792: return $output;
1793: }
1794:
1.88 raeburn 1795: sub course_level_dc {
1796: my ($dcdom) = @_;
1797: my %customroles=&my_custom_roles();
1798: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
1799: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1800: '<input type="hidden" name="dccourse" value="" />';
1801: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.127 albertel 1802: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course/Group').'</b>';
1.119 raeburn 1803: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom);
1.88 raeburn 1804: my %lt=&Apache::lonlocal::texthash(
1.119 raeburn 1805: 'typ' => "Type",
1.88 raeburn 1806: 'rol' => "Role",
1.113 raeburn 1807: 'grs' => "Section",
1.88 raeburn 1808: 'exs' => "Existing sections",
1809: 'new' => "Define new section",
1810: 'sta' => "Start",
1811: 'end' => "End",
1812: 'ssd' => "Set Start Date",
1813: 'sed' => "Set End Date"
1814: );
1.127 albertel 1815: my $header = '<h4>'.&mt('Course/Group Level').'</h4>'.
1816: '<table border="2"><tr><th>'.$lt{'typ'}.'</th><th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th></tr>';
1817: my $otheritems = '<tr><td><select name="crstype" onChange="javascript:setType();">'."\n".
1818: ' <option value="">'.&mt('Please select')."\n".
1819: ' <option value="Course">'.&mt('Course')."\n".
1820: ' <option value="Group">'.&mt('Group')."\n".
1821: '</select>'."\n".
1822: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','".')" /></td>'."\n".
1.88 raeburn 1823: '<td><select name="role">'."\n";
1.119 raeburn 1824: foreach ('st','ta','ep','in','cc') {
1.88 raeburn 1825: my $plrole=&Apache::lonnet::plaintext($_);
1826: $otheritems .= ' <option value="'.$_.'">'.$plrole;
1827: }
1828: if ( keys %customroles > 0) {
1829: foreach (sort keys %customroles) {
1.101 albertel 1830: my $custrole='cr_cr_'.$env{'user.domain'}.
1831: '_'.$env{'user.name'}.'_'.$_;
1.88 raeburn 1832: $otheritems .= ' <option value="'.$custrole.'">'.$_;
1833: }
1834: }
1835: $otheritems .= '</select></td><td>'.
1836: '<table border="0" cellspacing="0" cellpadding="0">'.
1837: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1838: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
1839: '<td> </td>'.
1840: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 1841: '<input type="text" name="newsec" value="" />'.
1842: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 1843: '</tr></table></td>';
1844: $otheritems .= <<ENDTIMEENTRY;
1845: <td><input type=hidden name="start" value=''>
1846: <a href=
1847: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1848: <td><input type=hidden name="end" value=''>
1849: <a href=
1850: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
1851: ENDTIMEENTRY
1852: $otheritems .= "</tr></table>\n";
1853: return $cb_jscript.$header.$hiddenitems.$otheritems;
1854: }
1855:
1.27 matthew 1856: #---------------------------------------------- end functions for &phase_two
1.29 matthew 1857:
1858: #--------------------------------- functions for &phase_two and &phase_three
1859:
1860: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 1861:
1862: 1;
1863: __END__
1.2 www 1864:
1865:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>