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