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