Annotation of loncom/interface/loncreateuser.pm, revision 1.100
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.100 ! albertel 4: # $Id: loncreateuser.pm,v 1.99 2005/01/30 15:34:46 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.94 matthew 76: sub initialize_authen_forms {
77: my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
78: $krbdefdom= uc($krbdefdom);
1.31 matthew 79: my %param = ( formname => 'document.cu',
80: kerb_def_dom => $krbdefdom
81: );
1.48 albertel 82: # no longer static due to configurable kerberos defaults
83: # $loginscript = &Apache::loncommon::authform_header(%param);
1.31 matthew 84: $generalrule = &Apache::loncommon::authform_authorwarning(%param);
85: $authformnop = &Apache::loncommon::authform_nochange(%param);
1.48 albertel 86: # no longer static due to configurable kerberos defaults
87: # $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 88: $authformint = &Apache::loncommon::authform_internal(%param);
89: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
90: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 91: }
92:
1.43 www 93:
1.59 www 94: # ======================================================= Existing Custom Roles
95:
96: sub my_custom_roles {
97: my %returnhash=();
98: my %rolehash=&Apache::lonnet::dump('roles');
99: foreach (keys %rolehash) {
100: if ($_=~/^rolesdef\_(\w+)$/) {
1.61 www 101: $returnhash{$1}=$1;
1.59 www 102: }
103: }
104: return %returnhash;
105: }
1.43 www 106:
107: # ==================================================== Figure out author access
108:
109: sub authorpriv {
110: my ($auname,$audom)=@_;
111: if (($auname ne $ENV{'user.name'}) ||
112: (($audom ne $ENV{'user.domain'}) &&
113: ($audom ne $ENV{'request.role.domain'}))) { return ''; }
114: unless (&Apache::lonnet::allowed('cca',$audom)) { return ''; }
115: return 1;
116: }
117:
1.2 www 118: # =================================================================== Phase one
1.1 www 119:
1.42 matthew 120: sub print_username_entry_form {
1.2 www 121: my $r=shift;
1.42 matthew 122: my $defdom=$ENV{'request.role.domain'};
1.33 matthew 123: my @domains = &Apache::loncommon::get_domains();
124: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.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;
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.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
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: }
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.28 matthew 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.42 matthew 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.42 matthew 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.44 matthew 768: if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
769: ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
770: # No sense in assigning co-author role to yourself
1.17 www 771: my $cuname=$ENV{'user.name'};
1.42 matthew 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:
845: if ($ENV{'request.role'} =~ m-^dc\./(\w+)/$-) {
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.29 matthew 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;
872: if (exists($ENV{'form.makeuser'})) {
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.29 matthew 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.29 matthew 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.29 matthew 889: if (! $ENV{'form.ccdomain'} ) {
1.73 sakharuk 890: $r->print($error.&mt('No domain specified').'.'.$end);
1.27 matthew 891: return;
892: }
1.29 matthew 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.29 matthew 899: if (! exists($ENV{'form.makeuser'})) {
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 ').
903: $ENV{'form.ccuname'}.&mt(' in domain ').
1.29 matthew 904: $ENV{'form.ccdomain'}.'.');
905: return;
906: }
907: }
1.27 matthew 908: # Determine authentication method and password for the user being modified
909: my $amode='';
910: my $genpwd='';
911: if ($ENV{'form.login'} eq 'krb') {
1.41 albertel 912: $amode='krb';
913: $amode.=$ENV{'form.krbver'};
1.30 matthew 914: $genpwd=$ENV{'form.krbarg'};
1.27 matthew 915: } elsif ($ENV{'form.login'} eq 'int') {
916: $amode='internal';
1.30 matthew 917: $genpwd=$ENV{'form.intarg'};
1.27 matthew 918: } elsif ($ENV{'form.login'} eq 'fsys') {
919: $amode='unix';
1.30 matthew 920: $genpwd=$ENV{'form.fsysarg'};
1.27 matthew 921: } elsif ($ENV{'form.login'} eq 'loc') {
922: $amode='localauth';
923: $genpwd=$ENV{'form.locarg'};
924: $genpwd=" " if (!$genpwd);
1.35 matthew 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: }
935: if ($ENV{'form.makeuser'}) {
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.73 sakharuk 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
950: my $desiredhost = $ENV{'form.hserver'};
951: if (lc($desiredhost) eq 'default') {
952: $desiredhost = undef;
953: } else {
1.39 matthew 954: my %home_servers = &Apache::loncommon::get_library_servers
1.32 matthew 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.29 matthew 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'},
966: undef,$desiredhost
1.27 matthew 967: );
1.77 www 968: $r->print(&mt('Generating user').': '.$result);
1.29 matthew 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.35 matthew 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.73 sakharuk 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.36 matthew 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.29 matthew 991: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
1.21 harris41 992: $amode,$genpwd));
1.73 sakharuk 993: $r->print('<br>'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.29 matthew 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: ##
1001: if (! $ENV{'form.makeuser'} ) {
1002: # Check for need to change
1003: my %userenv = &Apache::lonnet::get
1004: ('environment',['firstname','middlename','lastname','generation'],
1.29 matthew 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
1013: $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
1014: }
1.29 matthew 1015: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) &&
1.28 matthew 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'} )) {
1020: # Make the change
1021: my %changeHash;
1022: $changeHash{'firstname'} = $ENV{'form.cfirstname'};
1023: $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
1024: $changeHash{'lastname'} = $ENV{'form.clastname'};
1025: $changeHash{'generation'} = $ENV{'form.cgeneration'};
1026: my $putresult = &Apache::lonnet::put
1027: ('environment',\%changeHash,
1.29 matthew 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.28 matthew 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>
1058: </table>
1059: END
1060: } else { # error occurred
1.73 sakharuk 1061: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1062: $ENV{'form.ccuname'}." ".&mt('in domain')." ".
1.29 matthew 1063: $ENV{'form.ccdomain'}."</h2>");
1.28 matthew 1064: }
1065: } else { # End of if ($ENV ... ) logic
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.74 sakharuk 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.24 matthew 1083: foreach (keys (%ENV)) {
1.27 matthew 1084: next if (! $ENV{$_});
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.65 www 1090: &Apache::lonnet::revokerole($ENV{'form.ccdomain'},
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:'.
1097: $ENV{'course.'.$cid.'.domain'}.':'.
1098: $ENV{'course.'.$cid.'.num'}.':classlist:'.
1099: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
1100: $ENV{'form.ccdomain'}).'='.
1101: &Apache::lonnet::escape($now.':'),
1.56 www 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>'.
1109: &Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'},
1.65 www 1110: $ENV{'form.ccuname'},$1,$2,$3,$4).
1.64 www 1111: '</b><br>');
1112: }
1.53 www 1113: } elsif ($_=~/^form\.del/) {
1114: if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
1.73 sakharuk 1115: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.53 www 1116: &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
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:'.
1123: $ENV{'course.'.$cid.'.domain'}.':'.
1124: $ENV{'course.'.$cid.'.num'}.':classlist:'.
1.29 matthew 1125: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
1126: $ENV{'form.ccdomain'}).'='.
1.27 matthew 1127: &Apache::lonnet::escape($now.':'),
1.56 www 1128: $ENV{'course.'.$cid.'.home'}).'</b><br>');
1.81 albertel 1129: }
1130: }
1131: } elsif ($_=~/^form\.ren/) {
1.99 raeburn 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 {
1152: my $result=&Apache::lonnet::assignrole($ENV{'form.ccdomain'},
1153: $ENV{'form.ccuname'},$url,$role,0,$now);
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.99 raeburn 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.88 raeburn 1168: my $start = ( $ENV{'form.start_'.$full} ?
1169: $ENV{'form.start_'.$full} :
1170: $now );
1171: my $end = ( $ENV{'form.end_'.$full} ?
1172: $ENV{'form.end_'.$full} :
1173: 0 );
1174:
1175: # split multiple sections
1176: my %sections = ();
1.89 raeburn 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);
1190: my $start = ( $ENV{'form.start_'.$one.'_'.$two.'_'.$three} ?
1191: $ENV{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1192: $now );
1.83 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.89 raeburn 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
1221: my $start = ( $ENV{'form.start_'.$1.'_'.$2} ?
1222: $ENV{'form.start_'.$1.'_'.$2} :
1223: $now );
1224: my $end = ( $ENV{'form.end_'.$1.'_'.$2} ?
1225: $ENV{'form.end_'.$1.'_'.$2} :
1226: 0 );
1227: my $url='/'.$1.'/';
1.88 raeburn 1228: # split multiple sections
1229: my %sections = ();
1.89 raeburn 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.73 sakharuk 1248: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br>');
1.64 www 1249: }
1.27 matthew 1250: }
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.5 www 1254: $r->print('</body></html>');
1.4 www 1255: }
1256:
1.88 raeburn 1257: sub commit_customrole {
1.99 raeburn 1258: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
1.88 raeburn 1259: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1260: ($start?', '.&mt('starting').' '.localtime($start):'').
1261: ($end?', ending '.localtime($end):'').': <b>'.
1262: &Apache::lonnet::assigncustomrole(
1.99 raeburn 1263: $udom,$uname,$url,$three,$four,$five,$end,$start).
1264: '</b><br>';
1.88 raeburn 1265: return $output;
1266: }
1267:
1268: sub commit_standardrole {
1.99 raeburn 1269: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89 raeburn 1270: my $output;
1271: my $logmsg;
1272: if ($three eq 'st') {
1.99 raeburn 1273: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
1.89 raeburn 1274: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1275: $output = "Error: $result\n";
1276: } else {
1277: $output = &mt('Assigning').' '.$three.' in '.$url.
1278: ($start?', '.&mt('starting').' '.localtime($start):'').
1279: ($end?', '.&mt('ending').' '.localtime($end):'').
1280: ': <b>'.$result.'</b><br />'.
1281: &mt('Add to classlist').': <b>ok</b><br />';
1282: }
1283: } else {
1.92 raeburn 1284: $output = &mt('Assigning').' '.$three.' in '.$url.
1.89 raeburn 1285: ($start?', '.&mt('starting').' '.localtime($start):'').
1286: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1287: &Apache::lonnet::assignrole(
1.99 raeburn 1288: $udom,$uname,$url,$three,$end,$start).
1.92 raeburn 1289: '</b><br>';
1.88 raeburn 1290: }
1291: return $output;
1292: }
1293:
1.89 raeburn 1294: sub commit_studentrole {
1.99 raeburn 1295: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89 raeburn 1296: my $linefeed = '<br />'."\n";
1297: my $result;
1298: if (defined($one) && defined($two)) {
1299: my $cid=$one.'_'.$two;
1300: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
1301: my $secchange = 0;
1302: my $expire_role_result;
1303: my $modify_section_result;
1304: unless ($oldsec eq '-1') {
1305: unless ($sec eq $oldsec) {
1306: $secchange = 1;
1307: my $uurl='/'.$cid;
1308: $uurl=~s/\_/\//g;
1309: if ($oldsec) {
1310: $uurl.='/'.$oldsec;
1311: }
1312: $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
1313: $result = $expire_role_result;
1314: }
1315: }
1316: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1317: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
1318: if ($modify_section_result =~ /^ok/) {
1319: if ($secchange == 1) {
1320: $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
1321: } elsif ($oldsec eq '-1') {
1322: $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
1323: } else {
1324: $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
1325: }
1326: } else {
1327: $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
1328: }
1329: $result = $modify_section_result;
1330: } elsif ($secchange == 1) {
1331: $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
1332: }
1333: } else {
1334: $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
1335: $result = "Error: incomplete course id\n";
1336: }
1337: return $result;
1338: }
1.88 raeburn 1339:
1340: sub build_roles {
1.89 raeburn 1341: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 1342: my $num_sections = 0;
1343: if ($sectionstr=~ /,/) {
1344: my @secnums = split/,/,$sectionstr;
1.89 raeburn 1345: if ($role eq 'st') {
1346: $secnums[0] =~ s/\W//g;
1347: $$sections{$secnums[0]} = 1;
1348: $num_sections = 1;
1349: } else {
1350: foreach my $sec (@secnums) {
1351: $sec =~ ~s/\W//g;
1352: unless ($sec eq "") {
1353: if (exists($$sections{$sec})) {
1354: $$sections{$sec} ++;
1355: } else {
1356: $$sections{$sec} = 1;
1357: $num_sections ++;
1358: }
1.88 raeburn 1359: }
1360: }
1361: }
1362: } else {
1363: $sectionstr=~s/\W//g;
1364: unless ($sectionstr eq '') {
1365: $$sections{$sectionstr} = 1;
1366: $num_sections ++;
1367: }
1368: }
1369:
1370: return $num_sections;
1371: }
1372:
1.58 www 1373: # ========================================================== Custom Role Editor
1374:
1375: sub custom_role_editor {
1376: my $r=shift;
1377: my $rolename=$ENV{'form.rolename'};
1378:
1.59 www 1379: if ($rolename eq 'make new role') {
1380: $rolename=$ENV{'form.newrolename'};
1381: }
1382:
1.63 www 1383: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 1384:
1385: unless ($rolename) {
1386: &print_username_entry_form($r);
1387: return;
1388: }
1389:
1390: $r->print(&Apache::loncommon::bodytag(
1.59 www 1391: 'Create Users, Change User Privileges').'<h2>');
1.61 www 1392: my $syspriv='';
1393: my $dompriv='';
1394: my $coursepriv='';
1.59 www 1395: my ($rdummy,$roledef)=
1396: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 1397: # ------------------------------------------------------- Does this role exist?
1.59 www 1398: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1399: $r->print(&mt('Existing Role').' "');
1.61 www 1400: # ------------------------------------------------- Get current role privileges
1401: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 1402: } else {
1.73 sakharuk 1403: $r->print(&mt('New Role').' "');
1.59 www 1404: $roledef='';
1405: }
1406: $r->print($rolename.'"</h2>');
1.60 www 1407: # ------------------------------------------------------- What can be assigned?
1408: my %full=();
1409: my %courselevel=();
1.61 www 1410: my %courselevelcurrent=();
1.60 www 1411: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1412: my ($priv,$restrict)=split(/\&/,$_);
1413: unless ($restrict) { $restrict='F'; }
1414: $courselevel{$priv}=$restrict;
1.61 www 1415: if ($coursepriv=~/\:$priv/) {
1416: $courselevelcurrent{$priv}=1;
1417: }
1.60 www 1418: $full{$priv}=1;
1419: }
1420: my %domainlevel=();
1.61 www 1421: my %domainlevelcurrent=();
1.60 www 1422: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1423: my ($priv,$restrict)=split(/\&/,$_);
1424: unless ($restrict) { $restrict='F'; }
1425: $domainlevel{$priv}=$restrict;
1.61 www 1426: if ($dompriv=~/\:$priv/) {
1427: $domainlevelcurrent{$priv}=1;
1428: }
1.60 www 1429: $full{$priv}=1;
1430: }
1.61 www 1431: my %systemlevel=();
1432: my %systemlevelcurrent=();
1433: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1434: my ($priv,$restrict)=split(/\&/,$_);
1435: unless ($restrict) { $restrict='F'; }
1436: $systemlevel{$priv}=$restrict;
1437: if ($syspriv=~/\:$priv/) {
1438: $systemlevelcurrent{$priv}=1;
1439: }
1440: $full{$priv}=1;
1441: }
1.73 sakharuk 1442: my %lt=&Apache::lonlocal::texthash(
1443: 'prv' => "Privilege",
1444: 'crl' => "Course Level",
1445: 'dml' => "Domain Level",
1446: 'ssl' => "System Level"
1447: );
1.61 www 1448: $r->print(<<ENDCCF);
1449: <form method="post">
1450: <input type="hidden" name="phase" value="set_custom_roles" />
1451: <input type="hidden" name="rolename" value="$rolename" />
1452: <table border="2">
1.73 sakharuk 1453: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1454: <th>$lt{'ssl'}</th></tr>
1.61 www 1455: ENDCCF
1.60 www 1456: foreach (sort keys %full) {
1457: $r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
1.61 www 1458: ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
1459: ($courselevelcurrent{$_}?'checked="1"':'').' />':' ').
1460: '</td><td>'.
1461: ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
1462: ($domainlevelcurrent{$_}?'checked="1"':'').' />':' ').
1463: '</td><td>'.
1464: ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
1465: ($systemlevelcurrent{$_}?'checked="1"':'').' />':' ').
1466: '</td></tr>');
1.60 www 1467: }
1.61 www 1468: $r->print(
1.73 sakharuk 1469: '<table><input type="submit" value="'.&mt('Define Role').'" /></form></body></html>');
1.61 www 1470: }
1471:
1472: # ---------------------------------------------------------- Call to definerole
1473: sub set_custom_role {
1474: my $r=shift;
1475:
1476: my $rolename=$ENV{'form.rolename'};
1477:
1.63 www 1478: $rolename=~s/[^A-Za-z0-9]//gs;
1.61 www 1479:
1480: unless ($rolename) {
1481: &print_username_entry_form($r);
1482: return;
1483: }
1484:
1485: $r->print(&Apache::loncommon::bodytag(
1486: 'Create Users, Change User Privileges').'<h2>');
1487: my ($rdummy,$roledef)=
1488: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1489: # ------------------------------------------------------- Does this role exist?
1490: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1491: $r->print(&mt('Existing Role').' "');
1.61 www 1492: } else {
1.73 sakharuk 1493: $r->print(&mt('New Role').' "');
1.61 www 1494: $roledef='';
1495: }
1496: $r->print($rolename.'"</h2>');
1497: # ------------------------------------------------------- What can be assigned?
1498: my $sysrole='';
1499: my $domrole='';
1500: my $courole='';
1501:
1502: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1503: my ($priv,$restrict)=split(/\&/,$_);
1504: unless ($restrict) { $restrict=''; }
1505: if ($ENV{'form.'.$priv.':c'}) {
1506: $courole.=':'.$_;
1507: }
1508: }
1509:
1510: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1511: my ($priv,$restrict)=split(/\&/,$_);
1512: unless ($restrict) { $restrict=''; }
1513: if ($ENV{'form.'.$priv.':d'}) {
1514: $domrole.=':'.$_;
1515: }
1516: }
1517:
1518: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1519: my ($priv,$restrict)=split(/\&/,$_);
1520: unless ($restrict) { $restrict=''; }
1521: if ($ENV{'form.'.$priv.':s'}) {
1522: $sysrole.=':'.$_;
1523: }
1524: }
1.63 www 1525: $r->print('<br />Defining Role: '.
1.61 www 1526: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.63 www 1527: if ($ENV{'request.course.id'}) {
1528: my $url='/'.$ENV{'request.course.id'};
1529: $url=~s/\_/\//g;
1.73 sakharuk 1530: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.63 www 1531: &Apache::lonnet::assigncustomrole($ENV{'user.domain'},
1532: $ENV{'user.name'},
1533: $url,
1534: $ENV{'user.domain'},
1535: $ENV{'user.name'},
1536: $rolename));
1537: }
1.61 www 1538: $r->print('</body></html>');
1.58 www 1539: }
1540:
1.2 www 1541: # ================================================================ Main Handler
1542: sub handler {
1543: my $r = shift;
1544:
1545: if ($r->header_only) {
1.68 www 1546: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1547: $r->send_http_header;
1548: return OK;
1549: }
1550:
1551: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
1552: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
1553: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
1554: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
1.42 matthew 1555: (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
1556: (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
1.68 www 1557: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1558: $r->send_http_header;
1559: unless ($ENV{'form.phase'}) {
1.42 matthew 1560: &print_username_entry_form($r);
1.2 www 1561: }
1.42 matthew 1562: if ($ENV{'form.phase'} eq 'get_user_info') {
1563: &print_user_modification_page($r);
1564: } elsif ($ENV{'form.phase'} eq 'update_user_data') {
1565: &update_user_data($r);
1.58 www 1566: } elsif ($ENV{'form.phase'} eq 'selected_custom_edit') {
1567: &custom_role_editor($r);
1.61 www 1568: } elsif ($ENV{'form.phase'} eq 'set_custom_roles') {
1569: &set_custom_role($r);
1.2 www 1570: }
1.1 www 1571: } else {
1572: $ENV{'user.error.msg'}=
1.9 albertel 1573: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 1574: return HTTP_NOT_ACCEPTABLE;
1575: }
1576: return OK;
1577: }
1.26 matthew 1578:
1.27 matthew 1579: #-------------------------------------------------- functions for &phase_two
1.26 matthew 1580: sub course_level_table {
1.89 raeburn 1581: my (%inccourses) = @_;
1.26 matthew 1582: my $table = '';
1.62 www 1583: # Custom Roles?
1584:
1585: my %customroles=&my_custom_roles();
1.89 raeburn 1586: my %lt=&Apache::lonlocal::texthash(
1587: 'exs' => "Existing sections",
1588: 'new' => "Define new section",
1589: 'ssd' => "Set Start Date",
1590: 'sed' => "Set End Date",
1591: 'crl' => "Course Level",
1592: 'act' => "Activate",
1593: 'rol' => "Role",
1594: 'ext' => "Extent",
1595: 'grs' => "Group/Section",
1596: 'sta' => "Start",
1597: 'end' => "End"
1598: );
1.62 www 1599:
1.26 matthew 1600: foreach (sort( keys(%inccourses))) {
1601: my $thiscourse=$_;
1602: my $protectedcourse=$_;
1603: $thiscourse=~s:_:/:g;
1604: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1605: my $area=$coursedata{'description'};
1.72 sakharuk 1606: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1.26 matthew 1607: my $bgcol=$thiscourse;
1.62 www 1608: $bgcol=~s/[^7-9a-e]//g;
1609: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.89 raeburn 1610: my ($domain,$cnum)=split(/\//,$thiscourse);
1611: my %sections_count = ();
1.92 raeburn 1612: my $num_sections = 0;
1613: if (defined($ENV{'request.course.id'})) {
1614: if ($ENV{'request.course.id'} eq $domain.'_'.$cnum) {
1615: $num_sections = &Apache::loncommon::get_sections($domain,$cnum,\%sections_count);
1616: }
1617: }
1.26 matthew 1618: foreach ('st','ta','ep','ad','in','cc') {
1619: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1620: my $plrole=&Apache::lonnet::plaintext($_);
1621: $table .= <<ENDEXTENT;
1622: <tr bgcolor="#$bgcol">
1623: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1624: <td>$plrole</td>
1.82 albertel 1625: <td>$area<br />Domain: $domain</td>
1.26 matthew 1626: ENDEXTENT
1627: if ($_ ne 'cc') {
1.89 raeburn 1628: if ($num_sections > 0) {
1629: my $currsec = &course_sections($num_sections,\%sections_count,$protectedcourse.'_'.$_);
1630: $table .=
1631: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1632: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1633: $currsec.'</td>'.
1634: '<td> </td>'.
1635: '<td valign="top"> '.$lt{'new'}.'<br />'.
1636: '<input type="text" name="newsec_'.$protectedcourse.'_'.$_.'" value="" /></td>'.
1637: '<input type="hidden" '.
1638: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>'.
1639: '</tr></table></td>';
1640: } else {
1641: $table .= '<td><input type="text" size="10" '.
1642: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>';
1643: }
1.26 matthew 1644: } else {
1.89 raeburn 1645: $table .= '<td> </td>';
1.26 matthew 1646: }
1647: $table .= <<ENDTIMEENTRY;
1648: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1649: <a href=
1.73 sakharuk 1650: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.26 matthew 1651: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1652: <a href=
1.73 sakharuk 1653: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26 matthew 1654: ENDTIMEENTRY
1655: $table.= "</tr>\n";
1656: }
1657: }
1.62 www 1658: foreach (sort keys %customroles) {
1.65 www 1659: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1660: my $plrole=$_;
1661: my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}.
1662: '_'.$ENV{'user.name'}.'_'.$plrole;
1.89 raeburn 1663: $table .= <<END;
1.62 www 1664: <tr bgcolor="#$bgcol">
1.65 www 1665: <td><input type="checkbox" name="act_$customrole"></td>
1.62 www 1666: <td>$plrole</td>
1667: <td>$area</td>
1.89 raeburn 1668: END
1669: if ($num_sections > 0) {
1670: my $currsec = &course_sections($num_sections,\%sections_count,$customrole);
1671: $table.=
1672: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1673: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1674: $currsec.'</td>'.
1675: '<td> </td>'.
1676: '<td valign="top"> '.$lt{'new'}.'<br />'.
1677: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
1678: '<input type="hidden" '.
1679: 'name="sec_'.$customrole.'"></td>'.
1680: '</tr></table></td>';
1681: } else {
1682: $table .= '<td><input type="text" size="10" '.
1683: 'name="sec_'.$customrole.'"></td>';
1684: }
1685: $table .= <<ENDENTRY;
1.65 www 1686: <td><input type=hidden name="start_$customrole" value=''>
1.62 www 1687: <a href=
1.73 sakharuk 1688: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.65 www 1689: <td><input type=hidden name="end_$customrole" value=''>
1.62 www 1690: <a href=
1.73 sakharuk 1691: "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 1692: ENDENTRY
1.65 www 1693: }
1.62 www 1694: }
1.26 matthew 1695: }
1696: return '' if ($table eq ''); # return nothing if there is nothing
1697: # in the table
1698: my $result = <<ENDTABLE;
1.73 sakharuk 1699: <h4>$lt{'crl'}</h4>
1700: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1701: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.26 matthew 1702: $table
1703: </table>
1704: ENDTABLE
1705: return $result;
1706: }
1.88 raeburn 1707:
1.89 raeburn 1708: sub course_sections {
1709: my ($num_sections,$sections_count,$role) = @_;
1710: my $output = '';
1711: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.92 raeburn 1712: if ($num_sections == 1) {
1713: $output = '<select name="currsec_'.$role.'" >'."\n".
1714: ' <option value="">Select</option>'."\n".
1.93 raeburn 1715: ' <option value="">No section</option>'."\n".
1.92 raeburn 1716: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1717: } else {
1718: $output = '<select name="currsec_'.$role.'" ';
1719: my $multiple = 4;
1720: if ($num_sections <4) { $multiple = $num_sections; }
1.95 albertel 1721: $output .= '"multiple" size="'.$multiple.'">'."\n";
1.92 raeburn 1722: foreach (@sections) {
1723: $output .= '<option value="'.$_.'">'.$_."</option>\n";
1724: }
1.89 raeburn 1725: }
1726: $output .= '</select>';
1727: return $output;
1728: }
1729:
1.88 raeburn 1730: sub course_level_dc {
1731: my ($dcdom) = @_;
1732: my %customroles=&my_custom_roles();
1733: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
1734: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1735: '<input type="hidden" name="dccourse" value="" />';
1736: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1737: ('cu','dccourse','dcdomain','coursedesc').'</b>';
1738:
1739: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom);
1740: my %lt=&Apache::lonlocal::texthash(
1741: 'crl' => "Course Level",
1742: 'crt' => "Course Title",
1743: 'rol' => "Role",
1744: 'grs' => "Group/Section",
1745: 'exs' => "Existing sections",
1746: 'new' => "Define new section",
1747: 'sta' => "Start",
1748: 'end' => "End",
1749: 'ssd' => "Set Start Date",
1750: 'sed' => "Set End Date"
1751: );
1752: my $header = '<h4>'.$lt{'crl'}.'</h4>'.
1753: '<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 1754: my $otheritems = '<tr><td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'".'cu'."'".','."'".'dccourse'."'".','."'".'dcdomain'."'".','."'".'coursedesc'."',''".')" /></td>'.
1.88 raeburn 1755: '<td><select name="role">'."\n";
1756: foreach ('st','ta','ep','ad','in','cc') {
1757: my $plrole=&Apache::lonnet::plaintext($_);
1758: $otheritems .= ' <option value="'.$_.'">'.$plrole;
1759: }
1760: if ( keys %customroles > 0) {
1761: foreach (sort keys %customroles) {
1762: my $custrole='cr_cr_'.$ENV{'user.domain'}.
1763: '_'.$ENV{'user.name'}.'_'.$_;
1764: $otheritems .= ' <option value="'.$custrole.'">'.$_;
1765: }
1766: }
1767: $otheritems .= '</select></td><td>'.
1768: '<table border="0" cellspacing="0" cellpadding="0">'.
1769: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1770: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
1771: '<td> </td>'.
1772: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1773: '<input type="text" name="newsec" value="" /></td>'.
1774: '</tr></table></td>';
1775: $otheritems .= <<ENDTIMEENTRY;
1776: <td><input type=hidden name="start" value=''>
1777: <a href=
1778: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1779: <td><input type=hidden name="end" value=''>
1780: <a href=
1781: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
1782: ENDTIMEENTRY
1783: $otheritems .= "</tr></table>\n";
1784: return $cb_jscript.$header.$hiddenitems.$otheritems;
1785: }
1786:
1.27 matthew 1787: #---------------------------------------------- end functions for &phase_two
1.29 matthew 1788:
1789: #--------------------------------- functions for &phase_two and &phase_three
1790:
1791: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 1792:
1793: 1;
1794: __END__
1.2 www 1795:
1796:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>