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