Annotation of loncom/interface/loncreateuser.pm, revision 1.105
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.105 ! www 4: # $Id: loncreateuser.pm,v 1.104 2005/06/17 21:04:40 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)=@_;
1.105 ! www 111: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
! 112: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
1.43 www 113: return 1;
114: }
115:
1.2 www 116: # =================================================================== Phase one
1.1 www 117:
1.42 matthew 118: sub print_username_entry_form {
1.2 www 119: my $r=shift;
1.101 albertel 120: my $defdom=$env{'request.role.domain'};
1.33 matthew 121: my @domains = &Apache::loncommon::get_domains();
122: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.100 albertel 123: my $html=&Apache::lonxml::xmlbegin();
1.84 albertel 124: my $bodytag =&Apache::loncommon::bodytag('Create Users, Change User Privileges').&Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
1.46 www 125: my $selscript=&Apache::loncommon::studentbrowser_javascript();
126: my $sellink=&Apache::loncommon::selectstudent_link
127: ('crtuser','ccuname','ccdomain');
1.59 www 128: my %existingroles=&my_custom_roles();
129: my $choice=&Apache::loncommon::select_form('make new role','rolename',
130: ('make new role' => 'Generate new role ...',%existingroles));
1.71 sakharuk 131: my %lt=&Apache::lonlocal::texthash(
132: 'siur' => "Set Individual User Roles",
133: 'usr' => "Username",
134: 'dom' => "Domain",
135: 'usrr' => "User Roles",
136: 'ecrp' => "Edit Custom Role Privileges",
1.72 sakharuk 137: 'nr' => "Name of Role",
1.71 sakharuk 138: 'cre' => "Custom Role Editor"
139: );
1.76 www 140: my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
141: my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
1.33 matthew 142: $r->print(<<"ENDDOCUMENT");
1.100 albertel 143: $html
1.1 www 144: <head>
145: <title>The LearningOnline Network with CAPA</title>
1.46 www 146: $selscript
1.1 www 147: </head>
1.40 www 148: $bodytag
1.46 www 149: <form action="/adm/createuser" method="post" name="crtuser">
1.42 matthew 150: <input type="hidden" name="phase" value="get_user_info">
1.76 www 151: <h2>$lt{siur}$helpsiur</h2>
1.43 www 152: <table>
1.71 sakharuk 153: <tr><td>$lt{usr}:</td><td><input type="text" size="15" name="ccuname">
1.46 www 154: </td><td rowspan="2">$sellink</td></tr><tr><td>
1.71 sakharuk 155: $lt{'dom'}:</td><td>$domform</td></tr>
1.58 www 156: </table>
1.71 sakharuk 157: <input name="userrole" type="submit" value="$lt{usrr}" />
1.2 www 158: </form>
1.58 www 159: <form action="/adm/createuser" method="post" name="docustom">
160: <input type="hidden" name="phase" value="selected_custom_edit">
1.76 www 161: <h2>$lt{'ecrp'}$helpecpr</h2>
1.72 sakharuk 162: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
1.71 sakharuk 163: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.1 www 164: </body>
165: </html>
166: ENDDOCUMENT
1.2 www 167: }
168:
169: # =================================================================== Phase two
1.42 matthew 170: sub print_user_modification_page {
1.2 www 171: my $r=shift;
1.101 albertel 172: my $ccuname=$env{'form.ccuname'};
173: my $ccdomain=$env{'form.ccdomain'};
1.4 www 174:
1.98 albertel 175: $ccuname=~s/\W//g;
176: $ccdomain=~s/\W//g;
1.58 www 177:
178: unless (($ccuname) && ($ccdomain)) {
179: &print_username_entry_form($r);
180: return;
181: }
182:
1.101 albertel 183: my $defdom=$env{'request.role.domain'};
1.48 albertel 184:
185: my ($krbdef,$krbdefdom) =
186: &Apache::loncommon::get_kerberos_defaults($defdom);
187:
1.31 matthew 188: my %param = ( formname => 'document.cu',
1.48 albertel 189: kerb_def_dom => $krbdefdom,
190: kerb_def_auth => $krbdef
1.31 matthew 191: );
192: $loginscript = &Apache::loncommon::authform_header(%param);
1.48 albertel 193: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.4 www 194:
1.2 www 195: $ccuname=~s/\W//g;
196: $ccdomain=~s/\W//g;
1.52 matthew 197: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 198: my $dc_setcourse_code = '';
199: my $loaditem;
1.101 albertel 200: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
1.88 raeburn 201: my $dcdom = $1;
202: $loaditem = qq|OnLoad="document.cu.coursedesc.value=''"|;
203: $dc_setcourse_code = <<"ENDSCRIPT";
204: function setCourse() {
205: var course = document.cu.dccourse.value;
206: if (course != "") {
207: if (document.cu.dcdomain.value != document.cu.origdom.value) {
208: alert("You must select a course in the current domain");
209: return;
210: }
211: var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
1.91 raeburn 212: var section="";
1.88 raeburn 213: var numsections = 0;
1.89 raeburn 214: for (var i=0; i<document.cu.currsec.length; i++) {
215: if (document.cu.currsec.options[i].selected == true ) {
216: if (document.cu.currsec.options[i].value != "" && document.cu.currsec.options[i].value != null) {
217: if (numsections == 0) {
218: section = document.cu.currsec.options[i].value
219: numsections = 1;
220: }
221: else {
222: section = section + "," + document.cu.currsec.options[i].value
223: numsections ++;
1.88 raeburn 224: }
225: }
226: }
1.89 raeburn 227: }
228: if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
229: if (numsections == 0) {
230: section = document.cu.newsec.value
231: }
232: else {
233: section = section + "," + document.cu.newsec.value
1.88 raeburn 234: }
1.89 raeburn 235: var numsplit = document.cu.newsec.value.split(/,/g);
236: numsections = numsections + numsplit.length;
237: }
238: if ((userrole == 'st') && (numsections > 1)) {
239: 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.")
240: return;
241: }
242: if ((userrole == 'cc') && (numsections > 0)) {
243: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
244: section = "";
1.88 raeburn 245: }
246: var numcourse = getIndex(document.cu.dccourse);
247: if (numcourse == "-1") {
248: alert("There was a problem with your course selection");
249: return
250: }
251: else {
252: var coursename = "_$dcdom"+"_"+course+"_"+userrole
253: document.cu.elements[numcourse].name = "act"+coursename
254: document.cu.elements[numcourse+4].name = "sec"+coursename
255: document.cu.elements[numcourse+4].value = section
256: document.cu.elements[numcourse+5].name = "start"+coursename
257: document.cu.elements[numcourse+6].name = "end"+coursename
258: }
259: }
260: document.cu.submit();
261: }
262:
263: function getIndex(caller) {
264: for (var i=0;i<document.cu.elements.length;i++) {
265: if (document.cu.elements[i] == caller) {
266: return i;
267: }
268: }
269: return -1;
270: }
271: ENDSCRIPT
272: }
1.100 albertel 273: my $html=&Apache::lonxml::xmlbegin();
1.25 matthew 274: my $dochead =<<"ENDDOCHEAD";
1.100 albertel 275: $html
1.2 www 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: }
1.101 albertel 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.102 albertel 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.105 ! www 575: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1.43 www 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.101 albertel 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.101 albertel 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.101 albertel 766: if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
767: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1.44 matthew 768: # No sense in assigning co-author role to yourself
1.101 albertel 769: my $cuname=$env{'user.name'};
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",
1.105 ! www 779: 'caa' => "Assistant Co-Author",
1.72 sakharuk 780: 'ssd' => "Set Start Date",
781: 'sed' => "Set End Date"
782: );
1.17 www 783: $r->print(<<ENDCOAUTH);
1.72 sakharuk 784: <h4>$lt{'cs'}</h4>
1.74 sakharuk 785: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1.72 sakharuk 786: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.17 www 787: <tr>
1.80 www 788: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
1.72 sakharuk 789: <td>$lt{'cau'}</td>
1.17 www 790: <td>$cudom\_$cuname</td>
1.80 www 791: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
1.17 www 792: <a href=
1.72 sakharuk 793: "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 794: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
1.17 www 795: <a href=
1.72 sakharuk 796: "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 797: </tr>
1.105 ! www 798: <tr>
! 799: <td><input type=checkbox name="act_$cudom\_$cuname\_aa" /></td>
! 800: <td>$lt{'caa'}</td>
! 801: <td>$cudom\_$cuname</td>
! 802: <td><input type=hidden name="start_$cudom\_$cuname\_aa" value='' />
! 803: <a href=
! 804: "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>
! 805: <td><input type=hidden name="end_$cudom\_$cuname\_aa" value='' />
! 806: <a href=
! 807: "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>
! 808: </tr>
1.17 www 809: </table>
810: ENDCOAUTH
811: }
1.8 www 812: #
813: # Domain level
814: #
1.89 raeburn 815: my $num_domain_level = 0;
816: my $domaintext =
817: '<h4>'.&mt('Domain Level').'</h4>'.
1.73 sakharuk 818: '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
1.89 raeburn 819: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>';
1.24 matthew 820: foreach ( sort( keys(%incdomains))) {
1.2 www 821: my $thisdomain=$_;
1.69 albertel 822: foreach ('dc','li','dg','au','sc') {
1.2 www 823: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8 www 824: my $plrole=&Apache::lonnet::plaintext($_);
1.72 sakharuk 825: my %lt=&Apache::lonlocal::texthash(
826: 'ssd' => "Set Start Date",
827: 'sed' => "Set End Date"
828: );
1.89 raeburn 829: $num_domain_level ++;
830: $domaintext .= <<"ENDDROW";
1.8 www 831: <tr>
832: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
833: <td>$plrole</td>
834: <td>$thisdomain</td>
835: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
836: <a href=
1.72 sakharuk 837: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.8 www 838: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
839: <a href=
1.72 sakharuk 840: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.8 www 841: </tr>
842: ENDDROW
1.2 www 843: }
1.24 matthew 844: }
845: }
1.89 raeburn 846: $domaintext.='</table>';
847: if ($num_domain_level > 0) {
848: $r->print($domaintext);
849: }
1.8 www 850: #
851: # Course level
852: #
1.89 raeburn 853: my $num_sections;
1.88 raeburn 854:
1.101 albertel 855: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
1.88 raeburn 856: $r->print(&course_level_dc($1));
857: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
858: } else {
859: $r->print(&course_level_table(%inccourses));
1.89 raeburn 860: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()">'."\n");
1.88 raeburn 861: }
1.26 matthew 862: $r->print("</form></body></html>");
1.2 www 863: }
1.1 www 864:
1.4 www 865: # ================================================================= Phase Three
1.42 matthew 866: sub update_user_data {
1.4 www 867: my $r=shift;
1.101 albertel 868: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
869: $env{'form.ccdomain'});
1.27 matthew 870: # Error messages
1.73 sakharuk 871: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
1.27 matthew 872: my $end = '</body></html>';
873: # Print header
1.100 albertel 874: my $html=&Apache::lonxml::xmlbegin();
1.4 www 875: $r->print(<<ENDTHREEHEAD);
1.100 albertel 876: $html
1.4 www 877: <head>
878: <title>The LearningOnline Network with CAPA</title>
879: </head>
880: ENDTHREEHEAD
1.40 www 881: my $title;
1.101 albertel 882: if (exists($env{'form.makeuser'})) {
1.40 www 883: $title='Set Privileges for New User';
884: } else {
885: $title='Modify User Privileges';
886: }
887: $r->print(&Apache::loncommon::bodytag($title));
1.27 matthew 888: # Check Inputs
1.101 albertel 889: if (! $env{'form.ccuname'} ) {
1.73 sakharuk 890: $r->print($error.&mt('No login name specified').'.'.$end);
1.27 matthew 891: return;
892: }
1.101 albertel 893: if ( $env{'form.ccuname'} =~/\W/) {
1.73 sakharuk 894: $r->print($error.&mt('Invalid login name').'. '.
895: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 896: $end);
897: return;
898: }
1.101 albertel 899: if (! $env{'form.ccdomain'} ) {
1.73 sakharuk 900: $r->print($error.&mt('No domain specified').'.'.$end);
1.27 matthew 901: return;
902: }
1.101 albertel 903: if ( $env{'form.ccdomain'} =~/\W/) {
1.73 sakharuk 904: $r->print($error.&mt ('Invalid domain name').'. '.
905: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 906: $end);
907: return;
908: }
1.101 albertel 909: if (! exists($env{'form.makeuser'})) {
1.29 matthew 910: # Modifying an existing user, so check the validity of the name
911: if ($uhome eq 'no_host') {
1.73 sakharuk 912: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 913: $env{'form.ccuname'}.&mt(' in domain ').
914: $env{'form.ccdomain'}.'.');
1.29 matthew 915: return;
916: }
917: }
1.27 matthew 918: # Determine authentication method and password for the user being modified
919: my $amode='';
920: my $genpwd='';
1.101 albertel 921: if ($env{'form.login'} eq 'krb') {
1.41 albertel 922: $amode='krb';
1.101 albertel 923: $amode.=$env{'form.krbver'};
924: $genpwd=$env{'form.krbarg'};
925: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 926: $amode='internal';
1.101 albertel 927: $genpwd=$env{'form.intarg'};
928: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 929: $amode='unix';
1.101 albertel 930: $genpwd=$env{'form.fsysarg'};
931: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 932: $amode='localauth';
1.101 albertel 933: $genpwd=$env{'form.locarg'};
1.27 matthew 934: $genpwd=" " if (!$genpwd);
1.101 albertel 935: } elsif (($env{'form.login'} eq 'nochange') ||
936: ($env{'form.login'} eq '' )) {
1.34 matthew 937: # There is no need to tell the user we did not change what they
938: # did not ask us to change.
1.35 matthew 939: # If they are creating a new user but have not specified login
940: # information this will be caught below.
1.30 matthew 941: } else {
1.73 sakharuk 942: $r->print($error.&mt('Invalid login mode or password').$end);
1.30 matthew 943: return;
1.27 matthew 944: }
1.101 albertel 945: if ($env{'form.makeuser'}) {
1.27 matthew 946: # Create a new user
1.73 sakharuk 947: my %lt=&Apache::lonlocal::texthash(
948: 'cru' => "Creating user",
949: 'id' => "in domain"
950: );
1.27 matthew 951: $r->print(<<ENDNEWUSERHEAD);
1.101 albertel 952: <h3>$lt{'cru'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h3>
1.27 matthew 953: ENDNEWUSERHEAD
954: # Check for the authentication mode and password
955: if (! $amode || ! $genpwd) {
1.73 sakharuk 956: $r->print($error.&mt('Invalid login mode or password').$end);
1.27 matthew 957: return;
1.18 albertel 958: }
1.29 matthew 959: # Determine desired host
1.101 albertel 960: my $desiredhost = $env{'form.hserver'};
1.29 matthew 961: if (lc($desiredhost) eq 'default') {
962: $desiredhost = undef;
963: } else {
1.39 matthew 964: my %home_servers = &Apache::loncommon::get_library_servers
1.101 albertel 965: ($env{'form.ccdomain'});
1.29 matthew 966: if (! exists($home_servers{$desiredhost})) {
1.73 sakharuk 967: $r->print($error.&mt('Invalid home server specified'));
1.29 matthew 968: return;
969: }
970: }
1.27 matthew 971: # Call modifyuser
972: my $result = &Apache::lonnet::modifyuser
1.101 albertel 973: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
974: $amode,$genpwd,$env{'form.cfirst'},
975: $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1.29 matthew 976: undef,$desiredhost
1.27 matthew 977: );
1.77 www 978: $r->print(&mt('Generating user').': '.$result);
1.101 albertel 979: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
980: $env{'form.ccdomain'});
1.77 www 981: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.29 matthew 982: $Apache::lonnet::libserv{$home});
1.101 albertel 983: } elsif (($env{'form.login'} ne 'nochange') &&
984: ($env{'form.login'} ne '' )) {
1.27 matthew 985: # Modify user privileges
1.73 sakharuk 986: my %lt=&Apache::lonlocal::texthash(
987: 'usr' => "User",
988: 'id' => "in domain"
989: );
1.27 matthew 990: $r->print(<<ENDMODIFYUSERHEAD);
1.101 albertel 991: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.27 matthew 992: ENDMODIFYUSERHEAD
993: if (! $amode || ! $genpwd) {
994: $r->print($error.'Invalid login mode or password'.$end);
995: return;
1.20 harris41 996: }
1.27 matthew 997: # Only allow authentification modification if the person has authority
1.101 albertel 998: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 999: $r->print('Modifying authentication: '.
1.31 matthew 1000: &Apache::lonnet::modifyuserauth(
1.101 albertel 1001: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1002: $amode,$genpwd));
1.102 albertel 1003: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1004: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1005: } else {
1.27 matthew 1006: # Okay, this is a non-fatal error.
1.73 sakharuk 1007: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1.27 matthew 1008: }
1.28 matthew 1009: }
1010: ##
1.101 albertel 1011: if (! $env{'form.makeuser'} ) {
1.28 matthew 1012: # Check for need to change
1013: my %userenv = &Apache::lonnet::get
1014: ('environment',['firstname','middlename','lastname','generation'],
1.101 albertel 1015: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1016: my ($tmp) = keys(%userenv);
1017: if ($tmp =~ /^(con_lost|error)/i) {
1018: %userenv = ();
1019: }
1020: # Check to see if we need to change user information
1021: foreach ('firstname','middlename','lastname','generation') {
1022: # Strip leading and trailing whitespace
1.101 albertel 1023: $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
1.28 matthew 1024: }
1.101 albertel 1025: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1026: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1027: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1028: $env{'form.clastname'} ne $userenv{'lastname'} ||
1029: $env{'form.cgeneration'} ne $userenv{'generation'} )) {
1.28 matthew 1030: # Make the change
1031: my %changeHash;
1.101 albertel 1032: $changeHash{'firstname'} = $env{'form.cfirstname'};
1033: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1034: $changeHash{'lastname'} = $env{'form.clastname'};
1035: $changeHash{'generation'} = $env{'form.cgeneration'};
1.28 matthew 1036: my $putresult = &Apache::lonnet::put
1037: ('environment',\%changeHash,
1.101 albertel 1038: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1039: if ($putresult eq 'ok') {
1040: # Tell the user we changed the name
1.73 sakharuk 1041: my %lt=&Apache::lonlocal::texthash(
1042: 'uic' => "User Information Changed",
1043: 'frst' => "first",
1044: 'mddl' => "middle",
1045: 'lst' => "last",
1046: 'gen' => "generation",
1047: 'prvs' => "Previous",
1048: 'chto' => "Changed To"
1049: );
1.28 matthew 1050: $r->print(<<"END");
1051: <table border="2">
1.73 sakharuk 1052: <caption>$lt{'uic'}</caption>
1.28 matthew 1053: <tr><th> </th>
1.73 sakharuk 1054: <th>$lt{'frst'}</th>
1055: <th>$lt{'mddl'}</th>
1056: <th>$lt{'lst'}</th>
1057: <th>$lt{'gen'}</th></tr>
1058: <tr><td>$lt{'prvs'}</td>
1.28 matthew 1059: <td>$userenv{'firstname'} </td>
1060: <td>$userenv{'middlename'} </td>
1061: <td>$userenv{'lastname'} </td>
1062: <td>$userenv{'generation'} </td></tr>
1.73 sakharuk 1063: <tr><td>$lt{'chto'}</td>
1.101 albertel 1064: <td>$env{'form.cfirstname'} </td>
1065: <td>$env{'form.cmiddlename'} </td>
1066: <td>$env{'form.clastname'} </td>
1067: <td>$env{'form.cgeneration'} </td></tr>
1.28 matthew 1068: </table>
1069: END
1070: } else { # error occurred
1.73 sakharuk 1071: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1.101 albertel 1072: $env{'form.ccuname'}." ".&mt('in domain')." ".
1073: $env{'form.ccdomain'}."</h2>");
1.28 matthew 1074: }
1.101 albertel 1075: } else { # End of if ($env ... ) logic
1.28 matthew 1076: # They did not want to change the users name but we can
1077: # still tell them what the name is
1.73 sakharuk 1078: my %lt=&Apache::lonlocal::texthash(
1079: 'usr' => "User",
1080: 'id' => "in domain",
1081: 'gen' => "Generation"
1082: );
1.28 matthew 1083: $r->print(<<"END");
1.101 albertel 1084: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.28 matthew 1085: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1.73 sakharuk 1086: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1.28 matthew 1087: END
1088: }
1.4 www 1089: }
1.27 matthew 1090: ##
1.4 www 1091: my $now=time;
1.73 sakharuk 1092: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.101 albertel 1093: foreach (keys (%env)) {
1094: next if (! $env{$_});
1.27 matthew 1095: # Revoke roles
1096: if ($_=~/^form\.rev/) {
1.64 www 1097: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1098: # Revoke standard role
1.73 sakharuk 1099: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1.101 albertel 1100: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1.102 albertel 1101: $env{'form.ccuname'},$1,$2).'</b><br />');
1.53 www 1102: if ($2 eq 'st') {
1103: $1=~/^\/(\w+)\/(\w+)/;
1104: my $cid=$1.'_'.$2;
1.73 sakharuk 1105: $r->print(&mt('Drop from classlist').': <b>'.
1.53 www 1106: &Apache::lonnet::critical('put:'.
1.101 albertel 1107: $env{'course.'.$cid.'.domain'}.':'.
1108: $env{'course.'.$cid.'.num'}.':classlist:'.
1109: &Apache::lonnet::escape($env{'form.ccuname'}.':'.
1110: $env{'form.ccdomain'}).'='.
1.53 www 1111: &Apache::lonnet::escape($now.':'),
1.102 albertel 1112: $env{'course.'.$cid.'.home'}).'</b><br />');
1.53 www 1113: }
1114: }
1.64 www 1115: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1116: # Revoke custom role
1.73 sakharuk 1117: $r->print(&mt('Revoking custom role').
1118: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
1.101 albertel 1119: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1120: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 1121: '</b><br />');
1.64 www 1122: }
1.53 www 1123: } elsif ($_=~/^form\.del/) {
1124: if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
1.73 sakharuk 1125: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.101 albertel 1126: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1.102 albertel 1127: $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1.27 matthew 1128: if ($2 eq 'st') {
1129: $1=~/^\/(\w+)\/(\w+)/;
1130: my $cid=$1.'_'.$2;
1.73 sakharuk 1131: $r->print(&mt('Drop from classlist').': <b>'.
1.27 matthew 1132: &Apache::lonnet::critical('put:'.
1.101 albertel 1133: $env{'course.'.$cid.'.domain'}.':'.
1134: $env{'course.'.$cid.'.num'}.':classlist:'.
1135: &Apache::lonnet::escape($env{'form.ccuname'}.':'.
1136: $env{'form.ccdomain'}).'='.
1.27 matthew 1137: &Apache::lonnet::escape($now.':'),
1.102 albertel 1138: $env{'course.'.$cid.'.home'}).'</b><br />');
1.81 albertel 1139: }
1140: }
1141: } elsif ($_=~/^form\.ren/) {
1.101 albertel 1142: my $udom = $env{'form.ccdomain'};
1143: my $uname = $env{'form.ccuname'};
1.81 albertel 1144: if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
1.89 raeburn 1145: my $url = $1;
1146: my $role = $2;
1147: my $logmsg;
1148: my $output;
1149: if ($role eq 'st') {
1150: if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
1.99 raeburn 1151: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89 raeburn 1152: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1153: $output = "Error: $result\n";
1154: } else {
1155: $output = &mt('Assigning').' '.$role.' in '.$url.
1156: &mt('starting').' '.localtime($now).
1157: ': <br />'.$logmsg.'<br />'.
1158: &mt('Add to classlist').': <b>ok</b><br />';
1159: }
1160: }
1161: } else {
1.101 albertel 1162: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1163: $env{'form.ccuname'},$url,$role,0,$now);
1.89 raeburn 1164: $output = &mt('Re-Enabling [_1] in [_2]: [_3]',
1165: $role,$url,$result).'<br />';
1.27 matthew 1166: }
1.89 raeburn 1167: $r->print($output);
1.27 matthew 1168: }
1169: } elsif ($_=~/^form\.act/) {
1.101 albertel 1170: my $udom = $env{'form.ccdomain'};
1171: my $uname = $env{'form.ccuname'};
1.83 albertel 1172: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1.65 www 1173: # Activate a custom role
1.83 albertel 1174: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1175: my $url='/'.$one.'/'.$two;
1176: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 1177:
1.101 albertel 1178: my $start = ( $env{'form.start_'.$full} ?
1179: $env{'form.start_'.$full} :
1.88 raeburn 1180: $now );
1.101 albertel 1181: my $end = ( $env{'form.end_'.$full} ?
1182: $env{'form.end_'.$full} :
1.88 raeburn 1183: 0 );
1184:
1185: # split multiple sections
1186: my %sections = ();
1.101 albertel 1187: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 1188: if ($num_sections == 0) {
1.99 raeburn 1189: $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 1190: } else {
1191: foreach (sort {$a cmp $b} keys %sections) {
1192: my $securl = $url.'/'.$_;
1.99 raeburn 1193: $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 1194: }
1195: }
1.98 albertel 1196: } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
1.27 matthew 1197: # Activate roles for sections with 3 id numbers
1198: # set start, end times, and the url for the class
1.83 albertel 1199: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 1200: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1201: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1202: $now );
1.101 albertel 1203: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1204: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1205: 0 );
1.83 albertel 1206: my $url='/'.$one.'/'.$two;
1.88 raeburn 1207: my $type = 'three';
1208: # split multiple sections
1209: my %sections = ();
1.101 albertel 1210: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 1211: if ($num_sections == 0) {
1.99 raeburn 1212: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1213: } else {
1214: my $emptysec = 0;
1215: foreach my $sec (sort {$a cmp $b} keys %sections) {
1216: $sec =~ s/\W//g;
1217: if ($sec ne '') {
1218: my $securl = $url.'/'.$sec;
1.99 raeburn 1219: $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 1220: } else {
1221: $emptysec = 1;
1222: }
1223: }
1224: if ($emptysec) {
1.99 raeburn 1225: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1226: }
1227: }
1.27 matthew 1228: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1229: # Activate roles for sections with two id numbers
1230: # set start, end times, and the url for the class
1.101 albertel 1231: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1232: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 1233: $now );
1.101 albertel 1234: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1235: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 1236: 0 );
1237: my $url='/'.$1.'/';
1.88 raeburn 1238: # split multiple sections
1239: my %sections = ();
1.101 albertel 1240: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88 raeburn 1241: if ($num_sections == 0) {
1.99 raeburn 1242: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1243: } else {
1244: my $emptysec = 0;
1245: foreach my $sec (sort {$a cmp $b} keys %sections) {
1246: if ($sec ne '') {
1247: my $securl = $url.'/'.$sec;
1.99 raeburn 1248: $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88 raeburn 1249: } else {
1250: $emptysec = 1;
1251: }
1252: }
1253: if ($emptysec) {
1.99 raeburn 1254: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1255: }
1256: }
1.64 www 1257: } else {
1.102 albertel 1258: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br />');
1.64 www 1259: }
1.27 matthew 1260: }
1.101 albertel 1261: } # End of foreach (keys(%env))
1.75 www 1262: # Flush the course logs so reverse user roles immediately updated
1263: &Apache::lonnet::flushcourselogs();
1.103 albertel 1264: $r->print('<p><a href="/adm/createuser">Create/Modify Another User</a></p>');
1.5 www 1265: $r->print('</body></html>');
1.4 www 1266: }
1267:
1.88 raeburn 1268: sub commit_customrole {
1.99 raeburn 1269: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
1.88 raeburn 1270: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1271: ($start?', '.&mt('starting').' '.localtime($start):'').
1272: ($end?', ending '.localtime($end):'').': <b>'.
1273: &Apache::lonnet::assigncustomrole(
1.99 raeburn 1274: $udom,$uname,$url,$three,$four,$five,$end,$start).
1.102 albertel 1275: '</b><br />';
1.88 raeburn 1276: return $output;
1277: }
1278:
1279: sub commit_standardrole {
1.99 raeburn 1280: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89 raeburn 1281: my $output;
1282: my $logmsg;
1283: if ($three eq 'st') {
1.99 raeburn 1284: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
1.89 raeburn 1285: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1286: $output = "Error: $result\n";
1287: } else {
1288: $output = &mt('Assigning').' '.$three.' in '.$url.
1289: ($start?', '.&mt('starting').' '.localtime($start):'').
1290: ($end?', '.&mt('ending').' '.localtime($end):'').
1291: ': <b>'.$result.'</b><br />'.
1292: &mt('Add to classlist').': <b>ok</b><br />';
1293: }
1294: } else {
1.92 raeburn 1295: $output = &mt('Assigning').' '.$three.' in '.$url.
1.89 raeburn 1296: ($start?', '.&mt('starting').' '.localtime($start):'').
1297: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1298: &Apache::lonnet::assignrole(
1.99 raeburn 1299: $udom,$uname,$url,$three,$end,$start).
1.102 albertel 1300: '</b><br />';
1.88 raeburn 1301: }
1302: return $output;
1303: }
1304:
1.89 raeburn 1305: sub commit_studentrole {
1.99 raeburn 1306: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89 raeburn 1307: my $linefeed = '<br />'."\n";
1308: my $result;
1309: if (defined($one) && defined($two)) {
1310: my $cid=$one.'_'.$two;
1311: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
1312: my $secchange = 0;
1313: my $expire_role_result;
1314: my $modify_section_result;
1315: unless ($oldsec eq '-1') {
1316: unless ($sec eq $oldsec) {
1317: $secchange = 1;
1318: my $uurl='/'.$cid;
1319: $uurl=~s/\_/\//g;
1320: if ($oldsec) {
1321: $uurl.='/'.$oldsec;
1322: }
1323: $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
1324: $result = $expire_role_result;
1325: }
1326: }
1327: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1328: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
1329: if ($modify_section_result =~ /^ok/) {
1330: if ($secchange == 1) {
1331: $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
1332: } elsif ($oldsec eq '-1') {
1333: $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
1334: } else {
1335: $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
1336: }
1337: } else {
1338: $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
1339: }
1340: $result = $modify_section_result;
1341: } elsif ($secchange == 1) {
1342: $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
1343: }
1344: } else {
1345: $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
1346: $result = "Error: incomplete course id\n";
1347: }
1348: return $result;
1349: }
1.88 raeburn 1350:
1351: sub build_roles {
1.89 raeburn 1352: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 1353: my $num_sections = 0;
1354: if ($sectionstr=~ /,/) {
1355: my @secnums = split/,/,$sectionstr;
1.89 raeburn 1356: if ($role eq 'st') {
1357: $secnums[0] =~ s/\W//g;
1358: $$sections{$secnums[0]} = 1;
1359: $num_sections = 1;
1360: } else {
1361: foreach my $sec (@secnums) {
1362: $sec =~ ~s/\W//g;
1363: unless ($sec eq "") {
1364: if (exists($$sections{$sec})) {
1365: $$sections{$sec} ++;
1366: } else {
1367: $$sections{$sec} = 1;
1368: $num_sections ++;
1369: }
1.88 raeburn 1370: }
1371: }
1372: }
1373: } else {
1374: $sectionstr=~s/\W//g;
1375: unless ($sectionstr eq '') {
1376: $$sections{$sectionstr} = 1;
1377: $num_sections ++;
1378: }
1379: }
1380:
1381: return $num_sections;
1382: }
1383:
1.58 www 1384: # ========================================================== Custom Role Editor
1385:
1386: sub custom_role_editor {
1387: my $r=shift;
1.101 albertel 1388: my $rolename=$env{'form.rolename'};
1.58 www 1389:
1.59 www 1390: if ($rolename eq 'make new role') {
1.101 albertel 1391: $rolename=$env{'form.newrolename'};
1.59 www 1392: }
1393:
1.63 www 1394: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 1395:
1396: unless ($rolename) {
1397: &print_username_entry_form($r);
1398: return;
1399: }
1400:
1401: $r->print(&Apache::loncommon::bodytag(
1.59 www 1402: 'Create Users, Change User Privileges').'<h2>');
1.61 www 1403: my $syspriv='';
1404: my $dompriv='';
1405: my $coursepriv='';
1.59 www 1406: my ($rdummy,$roledef)=
1407: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 1408: # ------------------------------------------------------- Does this role exist?
1.59 www 1409: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1410: $r->print(&mt('Existing Role').' "');
1.61 www 1411: # ------------------------------------------------- Get current role privileges
1412: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 1413: } else {
1.73 sakharuk 1414: $r->print(&mt('New Role').' "');
1.59 www 1415: $roledef='';
1416: }
1417: $r->print($rolename.'"</h2>');
1.60 www 1418: # ------------------------------------------------------- What can be assigned?
1419: my %full=();
1420: my %courselevel=();
1.61 www 1421: my %courselevelcurrent=();
1.60 www 1422: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1423: my ($priv,$restrict)=split(/\&/,$_);
1424: unless ($restrict) { $restrict='F'; }
1425: $courselevel{$priv}=$restrict;
1.61 www 1426: if ($coursepriv=~/\:$priv/) {
1427: $courselevelcurrent{$priv}=1;
1428: }
1.60 www 1429: $full{$priv}=1;
1430: }
1431: my %domainlevel=();
1.61 www 1432: my %domainlevelcurrent=();
1.60 www 1433: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1434: my ($priv,$restrict)=split(/\&/,$_);
1435: unless ($restrict) { $restrict='F'; }
1436: $domainlevel{$priv}=$restrict;
1.61 www 1437: if ($dompriv=~/\:$priv/) {
1438: $domainlevelcurrent{$priv}=1;
1439: }
1.60 www 1440: $full{$priv}=1;
1441: }
1.61 www 1442: my %systemlevel=();
1443: my %systemlevelcurrent=();
1444: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1445: my ($priv,$restrict)=split(/\&/,$_);
1446: unless ($restrict) { $restrict='F'; }
1447: $systemlevel{$priv}=$restrict;
1448: if ($syspriv=~/\:$priv/) {
1449: $systemlevelcurrent{$priv}=1;
1450: }
1451: $full{$priv}=1;
1452: }
1.73 sakharuk 1453: my %lt=&Apache::lonlocal::texthash(
1454: 'prv' => "Privilege",
1455: 'crl' => "Course Level",
1456: 'dml' => "Domain Level",
1457: 'ssl' => "System Level"
1458: );
1.61 www 1459: $r->print(<<ENDCCF);
1460: <form method="post">
1461: <input type="hidden" name="phase" value="set_custom_roles" />
1462: <input type="hidden" name="rolename" value="$rolename" />
1463: <table border="2">
1.73 sakharuk 1464: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1465: <th>$lt{'ssl'}</th></tr>
1.61 www 1466: ENDCCF
1.60 www 1467: foreach (sort keys %full) {
1468: $r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
1.61 www 1469: ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
1470: ($courselevelcurrent{$_}?'checked="1"':'').' />':' ').
1471: '</td><td>'.
1472: ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
1473: ($domainlevelcurrent{$_}?'checked="1"':'').' />':' ').
1474: '</td><td>'.
1475: ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
1476: ($systemlevelcurrent{$_}?'checked="1"':'').' />':' ').
1477: '</td></tr>');
1.60 www 1478: }
1.61 www 1479: $r->print(
1.73 sakharuk 1480: '<table><input type="submit" value="'.&mt('Define Role').'" /></form></body></html>');
1.61 www 1481: }
1482:
1483: # ---------------------------------------------------------- Call to definerole
1484: sub set_custom_role {
1485: my $r=shift;
1486:
1.101 albertel 1487: my $rolename=$env{'form.rolename'};
1.61 www 1488:
1.63 www 1489: $rolename=~s/[^A-Za-z0-9]//gs;
1.61 www 1490:
1491: unless ($rolename) {
1492: &print_username_entry_form($r);
1493: return;
1494: }
1495:
1496: $r->print(&Apache::loncommon::bodytag(
1497: 'Create Users, Change User Privileges').'<h2>');
1498: my ($rdummy,$roledef)=
1499: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1500: # ------------------------------------------------------- Does this role exist?
1501: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1502: $r->print(&mt('Existing Role').' "');
1.61 www 1503: } else {
1.73 sakharuk 1504: $r->print(&mt('New Role').' "');
1.61 www 1505: $roledef='';
1506: }
1507: $r->print($rolename.'"</h2>');
1508: # ------------------------------------------------------- What can be assigned?
1509: my $sysrole='';
1510: my $domrole='';
1511: my $courole='';
1512:
1513: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1514: my ($priv,$restrict)=split(/\&/,$_);
1515: unless ($restrict) { $restrict=''; }
1.101 albertel 1516: if ($env{'form.'.$priv.':c'}) {
1.61 www 1517: $courole.=':'.$_;
1518: }
1519: }
1520:
1521: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1522: my ($priv,$restrict)=split(/\&/,$_);
1523: unless ($restrict) { $restrict=''; }
1.101 albertel 1524: if ($env{'form.'.$priv.':d'}) {
1.61 www 1525: $domrole.=':'.$_;
1526: }
1527: }
1528:
1529: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1530: my ($priv,$restrict)=split(/\&/,$_);
1531: unless ($restrict) { $restrict=''; }
1.101 albertel 1532: if ($env{'form.'.$priv.':s'}) {
1.61 www 1533: $sysrole.=':'.$_;
1534: }
1535: }
1.63 www 1536: $r->print('<br />Defining Role: '.
1.61 www 1537: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 1538: if ($env{'request.course.id'}) {
1539: my $url='/'.$env{'request.course.id'};
1.63 www 1540: $url=~s/\_/\//g;
1.73 sakharuk 1541: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 1542: &Apache::lonnet::assigncustomrole($env{'user.domain'},
1543: $env{'user.name'},
1.63 www 1544: $url,
1.101 albertel 1545: $env{'user.domain'},
1546: $env{'user.name'},
1.63 www 1547: $rolename));
1548: }
1.61 www 1549: $r->print('</body></html>');
1.58 www 1550: }
1551:
1.2 www 1552: # ================================================================ Main Handler
1553: sub handler {
1554: my $r = shift;
1555:
1556: if ($r->header_only) {
1.68 www 1557: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1558: $r->send_http_header;
1559: return OK;
1560: }
1561:
1.101 albertel 1562: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
1563: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
1564: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
1565: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1.104 albertel 1566: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1.101 albertel 1567: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1.68 www 1568: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1569: $r->send_http_header;
1.101 albertel 1570: unless ($env{'form.phase'}) {
1.42 matthew 1571: &print_username_entry_form($r);
1.2 www 1572: }
1.101 albertel 1573: if ($env{'form.phase'} eq 'get_user_info') {
1.42 matthew 1574: &print_user_modification_page($r);
1.101 albertel 1575: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.42 matthew 1576: &update_user_data($r);
1.101 albertel 1577: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1.58 www 1578: &custom_role_editor($r);
1.101 albertel 1579: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1.61 www 1580: &set_custom_role($r);
1.2 www 1581: }
1.1 www 1582: } else {
1.101 albertel 1583: $env{'user.error.msg'}=
1.9 albertel 1584: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 1585: return HTTP_NOT_ACCEPTABLE;
1586: }
1587: return OK;
1588: }
1.26 matthew 1589:
1.27 matthew 1590: #-------------------------------------------------- functions for &phase_two
1.26 matthew 1591: sub course_level_table {
1.89 raeburn 1592: my (%inccourses) = @_;
1.26 matthew 1593: my $table = '';
1.62 www 1594: # Custom Roles?
1595:
1596: my %customroles=&my_custom_roles();
1.89 raeburn 1597: my %lt=&Apache::lonlocal::texthash(
1598: 'exs' => "Existing sections",
1599: 'new' => "Define new section",
1600: 'ssd' => "Set Start Date",
1601: 'sed' => "Set End Date",
1602: 'crl' => "Course Level",
1603: 'act' => "Activate",
1604: 'rol' => "Role",
1605: 'ext' => "Extent",
1606: 'grs' => "Group/Section",
1607: 'sta' => "Start",
1608: 'end' => "End"
1609: );
1.62 www 1610:
1.26 matthew 1611: foreach (sort( keys(%inccourses))) {
1612: my $thiscourse=$_;
1613: my $protectedcourse=$_;
1614: $thiscourse=~s:_:/:g;
1615: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1616: my $area=$coursedata{'description'};
1.72 sakharuk 1617: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1.26 matthew 1618: my $bgcol=$thiscourse;
1.62 www 1619: $bgcol=~s/[^7-9a-e]//g;
1620: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.89 raeburn 1621: my ($domain,$cnum)=split(/\//,$thiscourse);
1622: my %sections_count = ();
1.92 raeburn 1623: my $num_sections = 0;
1.101 albertel 1624: if (defined($env{'request.course.id'})) {
1625: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.92 raeburn 1626: $num_sections = &Apache::loncommon::get_sections($domain,$cnum,\%sections_count);
1627: }
1628: }
1.26 matthew 1629: foreach ('st','ta','ep','ad','in','cc') {
1630: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1631: my $plrole=&Apache::lonnet::plaintext($_);
1632: $table .= <<ENDEXTENT;
1633: <tr bgcolor="#$bgcol">
1634: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1635: <td>$plrole</td>
1.82 albertel 1636: <td>$area<br />Domain: $domain</td>
1.26 matthew 1637: ENDEXTENT
1638: if ($_ ne 'cc') {
1.89 raeburn 1639: if ($num_sections > 0) {
1640: my $currsec = &course_sections($num_sections,\%sections_count,$protectedcourse.'_'.$_);
1641: $table .=
1642: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1643: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1644: $currsec.'</td>'.
1645: '<td> </td>'.
1646: '<td valign="top"> '.$lt{'new'}.'<br />'.
1647: '<input type="text" name="newsec_'.$protectedcourse.'_'.$_.'" value="" /></td>'.
1648: '<input type="hidden" '.
1649: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>'.
1650: '</tr></table></td>';
1651: } else {
1652: $table .= '<td><input type="text" size="10" '.
1653: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>';
1654: }
1.26 matthew 1655: } else {
1.89 raeburn 1656: $table .= '<td> </td>';
1.26 matthew 1657: }
1658: $table .= <<ENDTIMEENTRY;
1659: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1660: <a href=
1.73 sakharuk 1661: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.26 matthew 1662: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1663: <a href=
1.73 sakharuk 1664: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26 matthew 1665: ENDTIMEENTRY
1666: $table.= "</tr>\n";
1667: }
1668: }
1.62 www 1669: foreach (sort keys %customroles) {
1.65 www 1670: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1671: my $plrole=$_;
1.101 albertel 1672: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
1673: '_'.$env{'user.name'}.'_'.$plrole;
1.89 raeburn 1674: $table .= <<END;
1.62 www 1675: <tr bgcolor="#$bgcol">
1.65 www 1676: <td><input type="checkbox" name="act_$customrole"></td>
1.62 www 1677: <td>$plrole</td>
1678: <td>$area</td>
1.89 raeburn 1679: END
1680: if ($num_sections > 0) {
1681: my $currsec = &course_sections($num_sections,\%sections_count,$customrole);
1682: $table.=
1683: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1684: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1685: $currsec.'</td>'.
1686: '<td> </td>'.
1687: '<td valign="top"> '.$lt{'new'}.'<br />'.
1688: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
1689: '<input type="hidden" '.
1690: 'name="sec_'.$customrole.'"></td>'.
1691: '</tr></table></td>';
1692: } else {
1693: $table .= '<td><input type="text" size="10" '.
1694: 'name="sec_'.$customrole.'"></td>';
1695: }
1696: $table .= <<ENDENTRY;
1.65 www 1697: <td><input type=hidden name="start_$customrole" value=''>
1.62 www 1698: <a href=
1.73 sakharuk 1699: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.65 www 1700: <td><input type=hidden name="end_$customrole" value=''>
1.62 www 1701: <a href=
1.73 sakharuk 1702: "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 1703: ENDENTRY
1.65 www 1704: }
1.62 www 1705: }
1.26 matthew 1706: }
1707: return '' if ($table eq ''); # return nothing if there is nothing
1708: # in the table
1709: my $result = <<ENDTABLE;
1.73 sakharuk 1710: <h4>$lt{'crl'}</h4>
1711: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1712: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.26 matthew 1713: $table
1714: </table>
1715: ENDTABLE
1716: return $result;
1717: }
1.88 raeburn 1718:
1.89 raeburn 1719: sub course_sections {
1720: my ($num_sections,$sections_count,$role) = @_;
1721: my $output = '';
1722: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.92 raeburn 1723: if ($num_sections == 1) {
1724: $output = '<select name="currsec_'.$role.'" >'."\n".
1725: ' <option value="">Select</option>'."\n".
1.93 raeburn 1726: ' <option value="">No section</option>'."\n".
1.92 raeburn 1727: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1728: } else {
1729: $output = '<select name="currsec_'.$role.'" ';
1730: my $multiple = 4;
1731: if ($num_sections <4) { $multiple = $num_sections; }
1.95 albertel 1732: $output .= '"multiple" size="'.$multiple.'">'."\n";
1.92 raeburn 1733: foreach (@sections) {
1734: $output .= '<option value="'.$_.'">'.$_."</option>\n";
1735: }
1.89 raeburn 1736: }
1737: $output .= '</select>';
1738: return $output;
1739: }
1740:
1.88 raeburn 1741: sub course_level_dc {
1742: my ($dcdom) = @_;
1743: my %customroles=&my_custom_roles();
1744: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
1745: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1746: '<input type="hidden" name="dccourse" value="" />';
1747: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1748: ('cu','dccourse','dcdomain','coursedesc').'</b>';
1749:
1750: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom);
1751: my %lt=&Apache::lonlocal::texthash(
1752: 'crl' => "Course Level",
1753: 'crt' => "Course Title",
1754: 'rol' => "Role",
1755: 'grs' => "Group/Section",
1756: 'exs' => "Existing sections",
1757: 'new' => "Define new section",
1758: 'sta' => "Start",
1759: 'end' => "End",
1760: 'ssd' => "Set Start Date",
1761: 'sed' => "Set End Date"
1762: );
1763: my $header = '<h4>'.$lt{'crl'}.'</h4>'.
1764: '<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 1765: my $otheritems = '<tr><td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'".'cu'."'".','."'".'dccourse'."'".','."'".'dcdomain'."'".','."'".'coursedesc'."',''".')" /></td>'.
1.88 raeburn 1766: '<td><select name="role">'."\n";
1767: foreach ('st','ta','ep','ad','in','cc') {
1768: my $plrole=&Apache::lonnet::plaintext($_);
1769: $otheritems .= ' <option value="'.$_.'">'.$plrole;
1770: }
1771: if ( keys %customroles > 0) {
1772: foreach (sort keys %customroles) {
1.101 albertel 1773: my $custrole='cr_cr_'.$env{'user.domain'}.
1774: '_'.$env{'user.name'}.'_'.$_;
1.88 raeburn 1775: $otheritems .= ' <option value="'.$custrole.'">'.$_;
1776: }
1777: }
1778: $otheritems .= '</select></td><td>'.
1779: '<table border="0" cellspacing="0" cellpadding="0">'.
1780: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1781: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
1782: '<td> </td>'.
1783: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1784: '<input type="text" name="newsec" value="" /></td>'.
1785: '</tr></table></td>';
1786: $otheritems .= <<ENDTIMEENTRY;
1787: <td><input type=hidden name="start" value=''>
1788: <a href=
1789: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1790: <td><input type=hidden name="end" value=''>
1791: <a href=
1792: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
1793: ENDTIMEENTRY
1794: $otheritems .= "</tr></table>\n";
1795: return $cb_jscript.$header.$hiddenitems.$otheritems;
1796: }
1797:
1.27 matthew 1798: #---------------------------------------------- end functions for &phase_two
1.29 matthew 1799:
1800: #--------------------------------- functions for &phase_two and &phase_three
1801:
1802: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 1803:
1804: 1;
1805: __END__
1.2 www 1806:
1807:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>