Annotation of loncom/interface/loncreateuser.pm, revision 1.85
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.85 ! albertel 4: # $Id: loncreateuser.pm,v 1.84 2004/07/03 20:45:23 albertel Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser - handler to create users and custom roles
37:
38: =head1 SYNOPSIS
39:
40: Apache::loncreateuser provides an Apache handler for creating users,
41: editing their login parameters, roles, and removing roles, and
42: also creating and assigning custom roles.
43:
44: =head1 OVERVIEW
45:
46: =head2 Custom Roles
47:
48: In LON-CAPA, roles are actually collections of privileges. "Teaching
49: Assistant", "Course Coordinator", and other such roles are really just
50: collection of privileges that are useful in many circumstances.
51:
52: Creating custom roles can be done by the Domain Coordinator through
53: the Create User functionality. That screen will show all privileges
54: that can be assigned to users. For a complete list of privileges,
55: please see C</home/httpd/lonTabs/rolesplain.tab>.
56:
57: Custom role definitions are stored in the C<roles.db> file of the role
58: author.
59:
60: =cut
1.1 www 61:
62: use strict;
63: use Apache::Constants qw(:common :http);
64: use Apache::lonnet;
1.54 bowersj2 65: use Apache::loncommon;
1.68 www 66: use Apache::lonlocal;
1.1 www 67:
1.20 harris41 68: my $loginscript; # piece of javascript used in two separate instances
69: my $generalrule;
70: my $authformnop;
71: my $authformkrb;
72: my $authformint;
73: my $authformfsys;
74: my $authformloc;
75:
1.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.25 matthew 200: my $dochead =<<"ENDDOCHEAD";
1.2 www 201: <html>
202: <head>
203: <title>The LearningOnline Network with CAPA</title>
1.31 matthew 204: <script type="text/javascript" language="Javascript">
1.3 www 205:
206: function pclose() {
207: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
208: "height=350,width=350,scrollbars=no,menubar=no");
209: parmwin.close();
210: }
211:
1.52 matthew 212: $pjump_def
1.3 www 213:
214: function dateset() {
215: eval("document.cu."+document.cu.pres_marker.value+
216: ".value=document.cu.pres_value.value");
217: pclose();
218: }
219:
220: </script>
1.2 www 221: </head>
1.25 matthew 222: ENDDOCHEAD
1.40 www 223: $r->print(&Apache::loncommon::bodytag(
224: 'Create Users, Change User Privileges'));
1.25 matthew 225: my $forminfo =<<"ENDFORMINFO";
226: <form action="/adm/createuser" method="post" name="cu">
1.42 matthew 227: <input type="hidden" name="phase" value="update_user_data">
1.25 matthew 228: <input type="hidden" name="ccuname" value="$ccuname">
229: <input type="hidden" name="ccdomain" value="$ccdomain">
230: <input type="hidden" name="pres_value" value="" >
231: <input type="hidden" name="pres_type" value="" >
232: <input type="hidden" name="pres_marker" value="" >
233: ENDFORMINFO
1.2 www 234: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
235: my %incdomains;
236: my %inccourses;
1.49 albertel 237: foreach (values(%Apache::lonnet::hostdom)) {
1.13 www 238: $incdomains{$_}=1;
1.24 matthew 239: }
240: foreach (keys(%ENV)) {
1.2 www 241: if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
242: $inccourses{$1.'_'.$2}=1;
243: }
1.24 matthew 244: }
1.2 www 245: if ($uhome eq 'no_host') {
1.29 matthew 246: my $home_server_list=
1.32 matthew 247: '<option value="default" selected>default</option>'."\n".
248: &Apache::loncommon::home_server_option_list($ccdomain);
249:
1.79 albertel 250: my %lt=&Apache::lonlocal::texthash(
1.72 sakharuk 251: 'cnu' => "Create New User",
252: 'nu' => "New User",
253: 'id' => "in domain",
254: 'pd' => "Personal Data",
255: 'fn' => "First Name",
256: 'mn' => "Middle Name",
257: 'ln' => "Last Name",
258: 'gen' => "Generation",
259: 'idsn' => "ID/Student Number",
260: 'hs' => "Home Server",
261: 'lg' => "Login Data"
262: );
1.78 www 263: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1.26 matthew 264: $r->print(<<ENDNEWUSER);
1.25 matthew 265: $dochead
1.72 sakharuk 266: <h1>$lt{'cnu'}</h1>
1.25 matthew 267: $forminfo
1.72 sakharuk 268: <h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
1.31 matthew 269: <script type="text/javascript" language="Javascript">
1.20 harris41 270: $loginscript
1.31 matthew 271: </script>
1.20 harris41 272: <input type='hidden' name='makeuser' value='1' />
1.72 sakharuk 273: <h3>$lt{'pd'}</h3>
1.25 matthew 274: <p>
275: <table>
1.72 sakharuk 276: <tr><td>$lt{'fn'} </td>
1.25 matthew 277: <td><input type='text' name='cfirst' size='15' /></td></tr>
1.72 sakharuk 278: <tr><td>$lt{'mn'} </td>
1.25 matthew 279: <td><input type='text' name='cmiddle' size='15' /></td></tr>
1.72 sakharuk 280: <tr><td>$lt{'ln'} </td>
1.25 matthew 281: <td><input type='text' name='clast' size='15' /></td></tr>
1.78 www 282: <tr><td>$lt{'gen'}$genhelp</td>
1.25 matthew 283: <td><input type='text' name='cgen' size='5' /></td></tr>
284: </table>
1.72 sakharuk 285: $lt{'idsn'} <input type='text' name='cstid' size='15' /></p>
1.74 sakharuk 286: $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
1.25 matthew 287: <hr />
1.72 sakharuk 288: <h3>$lt{'lg'}</h3>
1.31 matthew 289: <p>$generalrule </p>
290: <p>$authformkrb </p>
291: <p>$authformint </p>
292: <p>$authformfsys</p>
293: <p>$authformloc </p>
1.26 matthew 294: ENDNEWUSER
1.25 matthew 295: } else { # user already exists
1.79 albertel 296: my %lt=&Apache::lonlocal::texthash(
1.72 sakharuk 297: 'cup' => "Change User Privileges",
298: 'usr' => "User",
299: 'id' => "in domain",
300: 'fn' => "first name",
301: 'mn' => "middle name",
302: 'ln' => "last name",
303: 'gen' => "generation"
304: );
1.26 matthew 305: $r->print(<<ENDCHANGEUSER);
1.25 matthew 306: $dochead
1.72 sakharuk 307: <h1>$lt{'cup'}</h1>
1.25 matthew 308: $forminfo
1.72 sakharuk 309: <h2>$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
1.26 matthew 310: ENDCHANGEUSER
1.28 matthew 311: # Get the users information
312: my %userenv = &Apache::lonnet::get('environment',
313: ['firstname','middlename','lastname','generation'],
314: $ccdomain,$ccuname);
315: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
316: $r->print(<<END);
317: <hr />
318: <table border="2">
319: <tr>
1.72 sakharuk 320: <th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th>
1.28 matthew 321: </tr>
322: <tr>
323: END
324: foreach ('firstname','middlename','lastname','generation') {
325: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
326: $r->print(<<"END");
1.53 www 327: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
1.28 matthew 328: END
329: } else {
330: $r->print('<td>'.$userenv{$_}.'</td>');
331: }
332: }
1.72 sakharuk 333: $r->print(<<END);
1.28 matthew 334: </tr>
335: </table>
336: END
1.25 matthew 337: # Build up table of user roles to allow revocation of a role.
1.28 matthew 338: my ($tmp) = keys(%rolesdump);
339: unless ($tmp =~ /^(con_lost|error)/i) {
1.2 www 340: my $now=time;
1.72 sakharuk 341: my %lt=&Apache::lonlocal::texthash(
342: 'rer' => "Revoke Existing Roles",
343: 'rev' => "Revoke",
344: 'del' => "Delete",
1.81 albertel 345: 'ren' => "Re-Enable",
1.72 sakharuk 346: 'rol' => "Role",
347: 'ext' => "Extent",
348: 'sta' => "Start",
349: 'end' => "End"
350: );
1.37 matthew 351: $r->print(<<END);
352: <hr />
1.72 sakharuk 353: <h3>$lt{'rer'}</h3>
1.79 albertel 354: <table>
1.81 albertel 355: <tr><th>$lt{'rev'}</th><th>$lt{'ren'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
1.37 matthew 356: END
1.79 albertel 357: my (%roletext,%sortrole,%roleclass);
1.67 albertel 358: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
359: my $b1=join('_',(split('_',$b))[1,0]);
360: return $a1 cmp $b1;
361: } keys(%rolesdump)) {
1.37 matthew 362: next if ($area =~ /^rolesdef/);
1.79 albertel 363: my $envkey=$area;
1.37 matthew 364: my $role = $rolesdump{$area};
365: my $thisrole=$area;
366: $area =~ s/\_\w\w$//;
367: my ($role_code,$role_end_time,$role_start_time) =
368: split(/_/,$role);
1.64 www 369: # Is this a custom role? Get role owner and title.
370: my ($croleudom,$croleuname,$croletitle)=
371: ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
1.37 matthew 372: my $bgcol='ffffff';
373: my $allowed=0;
1.53 www 374: my $delallowed=0;
1.79 albertel 375: my $sortkey=$role_code;
376: my $class='Unknown';
1.37 matthew 377: if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
1.79 albertel 378: $class='Course';
1.57 matthew 379: my ($coursedom,$coursedir) = ($1,$2);
1.79 albertel 380: $sortkey.="\0$1";
1.57 matthew 381: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.37 matthew 382: my %coursedata=
383: &Apache::lonnet::coursedescription($1.'_'.$2);
1.51 albertel 384: my $carea;
385: if (defined($coursedata{'description'})) {
1.79 albertel 386: $carea=$coursedata{'description'}.
1.72 sakharuk 387: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1.57 matthew 388: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
1.79 albertel 389: $sortkey.="\0".$coursedata{'description'};
1.51 albertel 390: } else {
1.72 sakharuk 391: $carea=&mt('Unavailable course').': '.$area;
1.79 albertel 392: $sortkey.="\0".&mt('Unavailable course');
1.51 albertel 393: }
1.37 matthew 394: $inccourses{$1.'_'.$2}=1;
1.53 www 395: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
396: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37 matthew 397: $allowed=1;
398: }
1.53 www 399: if ((&Apache::lonnet::allowed('dro',$1)) ||
400: (&Apache::lonnet::allowed('dro',$ccdomain))) {
401: $delallowed=1;
402: }
1.64 www 403: # - custom role. Needs more info, too
404: if ($croletitle) {
405: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
406: $allowed=1;
407: $thisrole.='.'.$role_code;
408: }
409: }
1.37 matthew 410: # Compute the background color based on $area
411: $bgcol=$1.'_'.$2;
1.62 www 412: $bgcol=~s/[^7-9a-e]//g;
413: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.37 matthew 414: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
1.28 matthew 415: $carea.='<br>Section/Group: '.$3;
1.37 matthew 416: }
417: $area=$carea;
418: } else {
1.79 albertel 419: $sortkey.="\0".$area;
1.37 matthew 420: # Determine if current user is able to revoke privileges
421: if ($area=~ /^\/(\w+)\//) {
1.53 www 422: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
423: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37 matthew 424: $allowed=1;
425: }
1.53 www 426: if (((&Apache::lonnet::allowed('dro',$1)) ||
427: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
428: ($role_code ne 'dc')) {
429: $delallowed=1;
430: }
1.37 matthew 431: } else {
432: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
433: $allowed=1;
434: }
435: }
1.79 albertel 436: if ($role_code eq 'ca' || $role_code eq 'au') {
437: $class='Construction Space';
438: } elsif ($role_code eq 'su') {
439: $class='System';
440: } else {
441: $class='Domain';
442: }
1.37 matthew 443: }
1.43 www 444: if ($role_code eq 'ca') {
445: $area=~/\/(\w+)\/(\w+)/;
446: if (&authorpriv($2,$1)) {
447: $allowed=1;
448: } else {
449: $allowed=0;
1.37 matthew 450: }
451: }
1.79 albertel 452: $bgcol='77FF77';
1.37 matthew 453: my $row = '';
1.62 www 454: $row.='<tr bgcolor="#'.$bgcol.'"><td>';
1.37 matthew 455: my $active=1;
456: $active=0 if (($role_end_time) && ($now>$role_end_time));
457: if (($active) && ($allowed)) {
458: $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
459: } else {
1.56 www 460: if ($active) {
461: $row.=' ';
462: } else {
1.72 sakharuk 463: $row.=&mt('expired or revoked');
1.56 www 464: }
1.37 matthew 465: }
1.53 www 466: $row.='</td><td>';
1.81 albertel 467: if ($allowed && !$active) {
468: $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
469: } else {
470: $row.=' ';
471: }
472: $row.='</td><td>';
1.53 www 473: if ($delallowed) {
474: $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
475: } else {
476: $row.=' ';
477: }
1.64 www 478: my $plaintext='';
479: unless ($croletitle) {
480: $plaintext=&Apache::lonnet::plaintext($role_code);
481: } else {
482: $plaintext=
483: "Customrole '$croletitle' defined by $croleuname\@$croleudom";
484: }
485: $row.= '</td><td>'.$plaintext.
1.37 matthew 486: '</td><td>'.$area.
487: '</td><td>'.($role_start_time?localtime($role_start_time)
488: : ' ' ).
489: '</td><td>'.($role_end_time ?localtime($role_end_time)
490: : ' ' )
491: ."</td></tr>\n";
1.79 albertel 492: $sortrole{$sortkey}=$envkey;
493: $roletext{$envkey}=$row;
494: $roleclass{$envkey}=$class;
495: #$r->print($row);
1.28 matthew 496: } # end of foreach (table building loop)
1.79 albertel 497: foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
498: my $output;
499: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
500: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
501: $output.=$roletext{$sortrole{$which}};
502: }
503: }
504: if (defined($output)) {
505: $r->print("<tr bgcolor='#BBffBB'>".
506: "<td align='center' colspan='7'>".&mt($type)."</td>");
507: }
508: $r->print($output);
509: }
1.2 www 510: $r->print('</table>');
1.28 matthew 511: } # End of unless
1.20 harris41 512: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.41 albertel 513: if ($currentauth=~/^krb(4|5):/) {
514: $currentauth=~/^krb(4|5):(.*)/;
1.45 matthew 515: my $krbdefdom=$1;
1.31 matthew 516: my %param = ( formname => 'document.cu',
517: kerb_def_dom => $krbdefdom
518: );
519: $loginscript = &Apache::loncommon::authform_header(%param);
1.20 harris41 520: }
1.26 matthew 521: # Check for a bad authentication type
1.41 albertel 522: unless ($currentauth=~/^krb(4|5):/ or
1.20 harris41 523: $currentauth=~/^unix:/ or
524: $currentauth=~/^internal:/ or
525: $currentauth=~/^localauth:/
1.26 matthew 526: ) { # bad authentication scheme
1.42 matthew 527: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
1.73 sakharuk 528: my %lt=&Apache::lonlocal::texthash(
529: 'err' => "ERROR",
530: 'uuas' => "This user has an unrecognized authentication scheme",
531: 'sldb' => "Please specify login data below",
532: 'ld' => "Login Data"
533: );
1.26 matthew 534: $r->print(<<ENDBADAUTH);
1.21 harris41 535: <hr />
1.31 matthew 536: <script type="text/javascript" language="Javascript">
1.21 harris41 537: $loginscript
1.31 matthew 538: </script>
1.73 sakharuk 539: <font color='#ff0000'>$lt{'err'}:</font>
540: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
541: <h3>$lt{'ld'}</h3>
1.31 matthew 542: <p>$generalrule</p>
543: <p>$authformkrb</p>
544: <p>$authformint</p>
545: <p>$authformfsys</p>
546: <p>$authformloc</p>
1.26 matthew 547: ENDBADAUTH
548: } else {
549: # This user is not allowed to modify the users
550: # authentication scheme, so just notify them of the problem
1.73 sakharuk 551: my %lt=&Apache::lonlocal::texthash(
552: 'err' => "ERROR",
553: 'uuas' => "This user has an unrecognized authentication scheme",
554: 'adcs' => "Please alert a domain coordinator of this situation"
555: );
1.26 matthew 556: $r->print(<<ENDBADAUTH);
557: <hr />
1.31 matthew 558: <script type="text/javascript" language="Javascript">
1.26 matthew 559: $loginscript
1.31 matthew 560: </script>
1.73 sakharuk 561: <font color="#ff0000"> $lt{'err'}: </font>
562: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1.26 matthew 563: <hr />
564: ENDBADAUTH
565: }
566: } else { # Authentication type is valid
1.20 harris41 567: my $authformcurrent='';
1.26 matthew 568: my $authform_other='';
1.41 albertel 569: if ($currentauth=~/^krb(4|5):/) {
1.20 harris41 570: $authformcurrent=$authformkrb;
1.31 matthew 571: $authform_other="<p>$authformint</p>\n".
572: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 573: }
574: elsif ($currentauth=~/^internal:/) {
575: $authformcurrent=$authformint;
1.31 matthew 576: $authform_other="<p>$authformkrb</p>".
577: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 578: }
579: elsif ($currentauth=~/^unix:/) {
580: $authformcurrent=$authformfsys;
1.31 matthew 581: $authform_other="<p>$authformkrb</p>".
582: "<p>$authformint</p><p>$authformloc;</p>";
1.20 harris41 583: }
584: elsif ($currentauth=~/^localauth:/) {
585: $authformcurrent=$authformloc;
1.31 matthew 586: $authform_other="<p>$authformkrb</p>".
587: "<p>$authformint</p><p>$authformfsys</p>";
1.20 harris41 588: }
1.53 www 589: $authformcurrent.=' <i>(will override current values)</i><br />';
1.42 matthew 590: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
1.26 matthew 591: # Current user has login modification privileges
1.73 sakharuk 592: my %lt=&Apache::lonlocal::texthash(
593: 'ccld' => "Change Current Login Data",
594: 'enld' => "Enter New Login Data"
595: );
1.26 matthew 596: $r->print(<<ENDOTHERAUTHS);
1.21 harris41 597: <hr />
1.31 matthew 598: <script type="text/javascript" language="Javascript">
1.21 harris41 599: $loginscript
1.31 matthew 600: </script>
1.73 sakharuk 601: <h3>$lt{'ccld'}</h3>
1.31 matthew 602: <p>$generalrule</p>
603: <p>$authformnop</p>
604: <p>$authformcurrent</p>
1.73 sakharuk 605: <h3>$lt{'enld'}</h3>
1.26 matthew 606: $authform_other
607: ENDOTHERAUTHS
608: }
609: } ## End of "check for bad authentication type" logic
1.25 matthew 610: } ## End of new user/old user logic
1.72 sakharuk 611: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
1.17 www 612: #
613: # Co-Author
614: #
1.44 matthew 615: if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
616: ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
617: # No sense in assigning co-author role to yourself
1.17 www 618: my $cuname=$ENV{'user.name'};
1.42 matthew 619: my $cudom=$ENV{'request.role.domain'};
1.72 sakharuk 620: my %lt=&Apache::lonlocal::texthash(
621: 'cs' => "Construction Space",
622: 'act' => "Activate",
623: 'rol' => "Role",
624: 'ext' => "Extent",
625: 'sta' => "Start",
1.80 www 626: 'end' => "End",
1.72 sakharuk 627: 'cau' => "Co-Author",
628: 'ssd' => "Set Start Date",
629: 'sed' => "Set End Date"
630: );
1.17 www 631: $r->print(<<ENDCOAUTH);
1.72 sakharuk 632: <h4>$lt{'cs'}</h4>
1.74 sakharuk 633: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1.72 sakharuk 634: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.17 www 635: <tr>
1.80 www 636: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
1.72 sakharuk 637: <td>$lt{'cau'}</td>
1.17 www 638: <td>$cudom\_$cuname</td>
1.80 www 639: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
1.17 www 640: <a href=
1.72 sakharuk 641: "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 642: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
1.17 www 643: <a href=
1.72 sakharuk 644: "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 645: </tr>
646: </table>
647: ENDCOAUTH
648: }
1.8 www 649: #
650: # Domain level
651: #
1.72 sakharuk 652: $r->print('<h4>'.&mt('Domain Level').'</h4>'.
1.73 sakharuk 653: '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
654: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>');
1.24 matthew 655: foreach ( sort( keys(%incdomains))) {
1.2 www 656: my $thisdomain=$_;
1.69 albertel 657: foreach ('dc','li','dg','au','sc') {
1.2 www 658: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8 www 659: my $plrole=&Apache::lonnet::plaintext($_);
1.72 sakharuk 660: my %lt=&Apache::lonlocal::texthash(
661: 'ssd' => "Set Start Date",
662: 'sed' => "Set End Date"
663: );
1.8 www 664: $r->print(<<ENDDROW);
665: <tr>
666: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
667: <td>$plrole</td>
668: <td>$thisdomain</td>
669: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
670: <a href=
1.72 sakharuk 671: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.8 www 672: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
673: <a href=
1.72 sakharuk 674: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.8 www 675: </tr>
676: ENDDROW
1.2 www 677: }
1.24 matthew 678: }
679: }
1.8 www 680: $r->print('</table>');
681: #
682: # Course level
683: #
1.26 matthew 684: $r->print(&course_level_table(%inccourses));
1.72 sakharuk 685: $r->print("<hr /><input type=submit value=\"".&mt('Modify User')."\">\n");
1.26 matthew 686: $r->print("</form></body></html>");
1.2 www 687: }
1.1 www 688:
1.4 www 689: # ================================================================= Phase Three
1.42 matthew 690: sub update_user_data {
1.4 www 691: my $r=shift;
1.29 matthew 692: my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
693: $ENV{'form.ccdomain'});
1.27 matthew 694: # Error messages
1.73 sakharuk 695: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
1.27 matthew 696: my $end = '</body></html>';
697: # Print header
1.4 www 698: $r->print(<<ENDTHREEHEAD);
699: <html>
700: <head>
701: <title>The LearningOnline Network with CAPA</title>
702: </head>
703: ENDTHREEHEAD
1.40 www 704: my $title;
705: if (exists($ENV{'form.makeuser'})) {
706: $title='Set Privileges for New User';
707: } else {
708: $title='Modify User Privileges';
709: }
710: $r->print(&Apache::loncommon::bodytag($title));
1.27 matthew 711: # Check Inputs
1.29 matthew 712: if (! $ENV{'form.ccuname'} ) {
1.73 sakharuk 713: $r->print($error.&mt('No login name specified').'.'.$end);
1.27 matthew 714: return;
715: }
1.29 matthew 716: if ( $ENV{'form.ccuname'} =~/\W/) {
1.73 sakharuk 717: $r->print($error.&mt('Invalid login name').'. '.
718: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 719: $end);
720: return;
721: }
1.29 matthew 722: if (! $ENV{'form.ccdomain'} ) {
1.73 sakharuk 723: $r->print($error.&mt('No domain specified').'.'.$end);
1.27 matthew 724: return;
725: }
1.29 matthew 726: if ( $ENV{'form.ccdomain'} =~/\W/) {
1.73 sakharuk 727: $r->print($error.&mt ('Invalid domain name').'. '.
728: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 729: $end);
730: return;
731: }
1.29 matthew 732: if (! exists($ENV{'form.makeuser'})) {
733: # Modifying an existing user, so check the validity of the name
734: if ($uhome eq 'no_host') {
1.73 sakharuk 735: $r->print($error.&mt('Unable to determine home server for ').
736: $ENV{'form.ccuname'}.&mt(' in domain ').
1.29 matthew 737: $ENV{'form.ccdomain'}.'.');
738: return;
739: }
740: }
1.27 matthew 741: # Determine authentication method and password for the user being modified
742: my $amode='';
743: my $genpwd='';
744: if ($ENV{'form.login'} eq 'krb') {
1.41 albertel 745: $amode='krb';
746: $amode.=$ENV{'form.krbver'};
1.30 matthew 747: $genpwd=$ENV{'form.krbarg'};
1.27 matthew 748: } elsif ($ENV{'form.login'} eq 'int') {
749: $amode='internal';
1.30 matthew 750: $genpwd=$ENV{'form.intarg'};
1.27 matthew 751: } elsif ($ENV{'form.login'} eq 'fsys') {
752: $amode='unix';
1.30 matthew 753: $genpwd=$ENV{'form.fsysarg'};
1.27 matthew 754: } elsif ($ENV{'form.login'} eq 'loc') {
755: $amode='localauth';
756: $genpwd=$ENV{'form.locarg'};
757: $genpwd=" " if (!$genpwd);
1.35 matthew 758: } elsif (($ENV{'form.login'} eq 'nochange') ||
759: ($ENV{'form.login'} eq '' )) {
1.34 matthew 760: # There is no need to tell the user we did not change what they
761: # did not ask us to change.
1.35 matthew 762: # If they are creating a new user but have not specified login
763: # information this will be caught below.
1.30 matthew 764: } else {
1.73 sakharuk 765: $r->print($error.&mt('Invalid login mode or password').$end);
1.30 matthew 766: return;
1.27 matthew 767: }
768: if ($ENV{'form.makeuser'}) {
769: # Create a new user
1.73 sakharuk 770: my %lt=&Apache::lonlocal::texthash(
771: 'cru' => "Creating user",
772: 'id' => "in domain"
773: );
1.27 matthew 774: $r->print(<<ENDNEWUSERHEAD);
1.73 sakharuk 775: <h3>$lt{'cru'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h3>
1.27 matthew 776: ENDNEWUSERHEAD
777: # Check for the authentication mode and password
778: if (! $amode || ! $genpwd) {
1.73 sakharuk 779: $r->print($error.&mt('Invalid login mode or password').$end);
1.27 matthew 780: return;
1.18 albertel 781: }
1.29 matthew 782: # Determine desired host
783: my $desiredhost = $ENV{'form.hserver'};
784: if (lc($desiredhost) eq 'default') {
785: $desiredhost = undef;
786: } else {
1.39 matthew 787: my %home_servers = &Apache::loncommon::get_library_servers
1.32 matthew 788: ($ENV{'form.ccdomain'});
1.29 matthew 789: if (! exists($home_servers{$desiredhost})) {
1.73 sakharuk 790: $r->print($error.&mt('Invalid home server specified'));
1.29 matthew 791: return;
792: }
793: }
1.27 matthew 794: # Call modifyuser
795: my $result = &Apache::lonnet::modifyuser
1.29 matthew 796: ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
797: $amode,$genpwd,$ENV{'form.cfirst'},
798: $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
799: undef,$desiredhost
1.27 matthew 800: );
1.77 www 801: $r->print(&mt('Generating user').': '.$result);
1.29 matthew 802: my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
803: $ENV{'form.ccdomain'});
1.77 www 804: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.29 matthew 805: $Apache::lonnet::libserv{$home});
1.35 matthew 806: } elsif (($ENV{'form.login'} ne 'nochange') &&
807: ($ENV{'form.login'} ne '' )) {
1.27 matthew 808: # Modify user privileges
1.73 sakharuk 809: my %lt=&Apache::lonlocal::texthash(
810: 'usr' => "User",
811: 'id' => "in domain"
812: );
1.27 matthew 813: $r->print(<<ENDMODIFYUSERHEAD);
1.73 sakharuk 814: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
1.27 matthew 815: ENDMODIFYUSERHEAD
816: if (! $amode || ! $genpwd) {
817: $r->print($error.'Invalid login mode or password'.$end);
818: return;
1.20 harris41 819: }
1.27 matthew 820: # Only allow authentification modification if the person has authority
1.36 matthew 821: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
1.20 harris41 822: $r->print('Modifying authentication: '.
1.31 matthew 823: &Apache::lonnet::modifyuserauth(
1.29 matthew 824: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
1.21 harris41 825: $amode,$genpwd));
1.73 sakharuk 826: $r->print('<br>'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.29 matthew 827: ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
1.4 www 828: } else {
1.27 matthew 829: # Okay, this is a non-fatal error.
1.73 sakharuk 830: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1.27 matthew 831: }
1.28 matthew 832: }
833: ##
834: if (! $ENV{'form.makeuser'} ) {
835: # Check for need to change
836: my %userenv = &Apache::lonnet::get
837: ('environment',['firstname','middlename','lastname','generation'],
1.29 matthew 838: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
1.28 matthew 839: my ($tmp) = keys(%userenv);
840: if ($tmp =~ /^(con_lost|error)/i) {
841: %userenv = ();
842: }
843: # Check to see if we need to change user information
844: foreach ('firstname','middlename','lastname','generation') {
845: # Strip leading and trailing whitespace
846: $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
847: }
1.29 matthew 848: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) &&
1.28 matthew 849: ($ENV{'form.cfirstname'} ne $userenv{'firstname'} ||
850: $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
851: $ENV{'form.clastname'} ne $userenv{'lastname'} ||
852: $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
853: # Make the change
854: my %changeHash;
855: $changeHash{'firstname'} = $ENV{'form.cfirstname'};
856: $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
857: $changeHash{'lastname'} = $ENV{'form.clastname'};
858: $changeHash{'generation'} = $ENV{'form.cgeneration'};
859: my $putresult = &Apache::lonnet::put
860: ('environment',\%changeHash,
1.29 matthew 861: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
1.28 matthew 862: if ($putresult eq 'ok') {
863: # Tell the user we changed the name
1.73 sakharuk 864: my %lt=&Apache::lonlocal::texthash(
865: 'uic' => "User Information Changed",
866: 'frst' => "first",
867: 'mddl' => "middle",
868: 'lst' => "last",
869: 'gen' => "generation",
870: 'prvs' => "Previous",
871: 'chto' => "Changed To"
872: );
1.28 matthew 873: $r->print(<<"END");
874: <table border="2">
1.73 sakharuk 875: <caption>$lt{'uic'}</caption>
1.28 matthew 876: <tr><th> </th>
1.73 sakharuk 877: <th>$lt{'frst'}</th>
878: <th>$lt{'mddl'}</th>
879: <th>$lt{'lst'}</th>
880: <th>$lt{'gen'}</th></tr>
881: <tr><td>$lt{'prvs'}</td>
1.28 matthew 882: <td>$userenv{'firstname'} </td>
883: <td>$userenv{'middlename'} </td>
884: <td>$userenv{'lastname'} </td>
885: <td>$userenv{'generation'} </td></tr>
1.73 sakharuk 886: <tr><td>$lt{'chto'}</td>
1.28 matthew 887: <td>$ENV{'form.cfirstname'} </td>
888: <td>$ENV{'form.cmiddlename'} </td>
889: <td>$ENV{'form.clastname'} </td>
890: <td>$ENV{'form.cgeneration'} </td></tr>
891: </table>
892: END
893: } else { # error occurred
1.73 sakharuk 894: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
895: $ENV{'form.ccuname'}." ".&mt('in domain')." ".
1.29 matthew 896: $ENV{'form.ccdomain'}."</h2>");
1.28 matthew 897: }
898: } else { # End of if ($ENV ... ) logic
899: # They did not want to change the users name but we can
900: # still tell them what the name is
1.73 sakharuk 901: my %lt=&Apache::lonlocal::texthash(
902: 'usr' => "User",
903: 'id' => "in domain",
904: 'gen' => "Generation"
905: );
1.28 matthew 906: $r->print(<<"END");
1.74 sakharuk 907: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
1.28 matthew 908: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1.73 sakharuk 909: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1.28 matthew 910: END
911: }
1.4 www 912: }
1.27 matthew 913: ##
1.4 www 914: my $now=time;
1.73 sakharuk 915: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.24 matthew 916: foreach (keys (%ENV)) {
1.27 matthew 917: next if (! $ENV{$_});
918: # Revoke roles
919: if ($_=~/^form\.rev/) {
1.64 www 920: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
921: # Revoke standard role
1.73 sakharuk 922: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1.65 www 923: &Apache::lonnet::revokerole($ENV{'form.ccdomain'},
924: $ENV{'form.ccuname'},$1,$2).'</b><br>');
1.53 www 925: if ($2 eq 'st') {
926: $1=~/^\/(\w+)\/(\w+)/;
927: my $cid=$1.'_'.$2;
1.73 sakharuk 928: $r->print(&mt('Drop from classlist').': <b>'.
1.53 www 929: &Apache::lonnet::critical('put:'.
930: $ENV{'course.'.$cid.'.domain'}.':'.
931: $ENV{'course.'.$cid.'.num'}.':classlist:'.
932: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
933: $ENV{'form.ccdomain'}).'='.
934: &Apache::lonnet::escape($now.':'),
1.56 www 935: $ENV{'course.'.$cid.'.home'}).'</b><br>');
1.53 www 936: }
937: }
1.64 www 938: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
939: # Revoke custom role
1.73 sakharuk 940: $r->print(&mt('Revoking custom role').
941: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
942: &Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'},
1.65 www 943: $ENV{'form.ccuname'},$1,$2,$3,$4).
1.64 www 944: '</b><br>');
945: }
1.53 www 946: } elsif ($_=~/^form\.del/) {
947: if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
1.73 sakharuk 948: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.53 www 949: &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
950: $ENV{'form.ccuname'},$1,$2,$now,0,1).'<br>');
1.27 matthew 951: if ($2 eq 'st') {
952: $1=~/^\/(\w+)\/(\w+)/;
953: my $cid=$1.'_'.$2;
1.73 sakharuk 954: $r->print(&mt('Drop from classlist').': <b>'.
1.27 matthew 955: &Apache::lonnet::critical('put:'.
956: $ENV{'course.'.$cid.'.domain'}.':'.
957: $ENV{'course.'.$cid.'.num'}.':classlist:'.
1.29 matthew 958: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
959: $ENV{'form.ccdomain'}).'='.
1.27 matthew 960: &Apache::lonnet::escape($now.':'),
1.56 www 961: $ENV{'course.'.$cid.'.home'}).'</b><br>');
1.81 albertel 962: }
963: }
964: } elsif ($_=~/^form\.ren/) {
965: if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
966: my $result=&Apache::lonnet::assignrole($ENV{'form.ccdomain'},
967: $ENV{'form.ccuname'},$1,$2,0,$now);
968: $r->print(&mt('Re-Enabling [_1] in [_2]: [_3]',
969: $2,$1,$result).'<br />');
970: if ($2 eq 'st') {
971: $1=~/^\/(\w+)\/(\w+)/;
972: my $cid=$1.'_'.$2;
973: $r->print(&mt('Add to classlist').': <b>'.
974: &Apache::lonnet::critical(
975: 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
976: $ENV{'course.'.$cid.'.num'}.':classlist:'.
977: &Apache::lonnet::escape(
978: $ENV{'form.ccuname'}.':'.
979: $ENV{'form.ccdomain'} ).'='.
980: &Apache::lonnet::escape(':'.$now),
981: $ENV{'course.'.$cid.'.home'})
982: .'</b><br>');
1.27 matthew 983: }
984: }
985: } elsif ($_=~/^form\.act/) {
1.83 albertel 986: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1.65 www 987: # Activate a custom role
1.83 albertel 988: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
989: my $url='/'.$one.'/'.$two;
990: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
991: $ENV{'form.sec_'.$full}=~s/\W//g;
1.65 www 992: if ($ENV{'form.sec_'.$full}) {
993: $url.='/'.$ENV{'form.sec_'.$full};
994: }
995:
996: my $start = ( $ENV{'form.start_'.$full} ?
997: $ENV{'form.start_'.$full} :
998: $now );
999: my $end = ( $ENV{'form.end_'.$full} ?
1000: $ENV{'form.end_'.$full} :
1001: 0 );
1002:
1.83 albertel 1003: $r->print(&mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1.73 sakharuk 1004: ($start?', '.&mt('starting').' '.localtime($start):'').
1.65 www 1005: ($end?', ending '.localtime($end):'').': <b>'.
1006: &Apache::lonnet::assigncustomrole(
1.83 albertel 1007: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start).
1.65 www 1008: '</b><br>');
1009: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 1010: # Activate roles for sections with 3 id numbers
1011: # set start, end times, and the url for the class
1.83 albertel 1012: my ($one,$two,$three)=($1,$2,$3);
1013: my $start = ( $ENV{'form.start_'.$one.'_'.$two.'_'.$three} ?
1014: $ENV{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1015: $now );
1.83 albertel 1016: my $end = ( $ENV{'form.end_'.$one.'_'.$two.'_'.$three} ?
1017: $ENV{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1018: 0 );
1.83 albertel 1019: my $url='/'.$one.'/'.$two;
1020: $ENV{'form.sec_'.$one.'_'.$two.'_'.$three}=~s/\W//g;
1021: if ($ENV{'form.sec_'.$one.'_'.$two.'_'.$three}) {
1022: $url.='/'.$ENV{'form.sec_'.$one.'_'.$two.'_'.$three};
1.27 matthew 1023: }
1024: # Assign the role and report it
1.83 albertel 1025: $r->print(&mt('Assigning').' '.$three.' in '.$url.
1.73 sakharuk 1026: ($start?', '.&mt('starting').' '.localtime($start):'').
1027: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1.27 matthew 1028: &Apache::lonnet::assignrole(
1.29 matthew 1029: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
1.83 albertel 1030: $url,$three,$end,$start).
1.56 www 1031: '</b><br>');
1.27 matthew 1032: # Handle students differently
1.83 albertel 1033: if ($three eq 'st') {
1.27 matthew 1034: $url=~/^\/(\w+)\/(\w+)/;
1.83 albertel 1035: my $cid=$one.'_'.$two;
1.73 sakharuk 1036: $r->print(&mt('Add to classlist').': <b>'.
1.27 matthew 1037: &Apache::lonnet::critical(
1038: 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
1039: $ENV{'course.'.$cid.'.num'}.':classlist:'.
1040: &Apache::lonnet::escape(
1.29 matthew 1041: $ENV{'form.ccuname'}.':'.
1042: $ENV{'form.ccdomain'} ).'='.
1.27 matthew 1043: &Apache::lonnet::escape($end.':'.$start),
1044: $ENV{'course.'.$cid.'.home'})
1.56 www 1045: .'</b><br>');
1.27 matthew 1046: }
1047: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1048: # Activate roles for sections with two id numbers
1049: # set start, end times, and the url for the class
1050: my $start = ( $ENV{'form.start_'.$1.'_'.$2} ?
1051: $ENV{'form.start_'.$1.'_'.$2} :
1052: $now );
1053: my $end = ( $ENV{'form.end_'.$1.'_'.$2} ?
1054: $ENV{'form.end_'.$1.'_'.$2} :
1055: 0 );
1056: my $url='/'.$1.'/';
1057: # Assign the role and report it.
1.73 sakharuk 1058: $r->print(&mt('Assigning').' '.$2.' in '.$url.': '.
1059: ($start?', '.&mt('starting').' '.localtime($start):'').
1060: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1.27 matthew 1061: &Apache::lonnet::assignrole(
1.29 matthew 1062: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
1.27 matthew 1063: $url,$2,$end,$start)
1.56 www 1064: .'</b><br>');
1.64 www 1065: } else {
1.73 sakharuk 1066: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br>');
1.64 www 1067: }
1.27 matthew 1068: }
1069: } # End of foreach (keys(%ENV))
1.75 www 1070: # Flush the course logs so reverse user roles immediately updated
1071: &Apache::lonnet::flushcourselogs();
1.5 www 1072: $r->print('</body></html>');
1.4 www 1073: }
1074:
1.58 www 1075: # ========================================================== Custom Role Editor
1076:
1077: sub custom_role_editor {
1078: my $r=shift;
1079: my $rolename=$ENV{'form.rolename'};
1080:
1.59 www 1081: if ($rolename eq 'make new role') {
1082: $rolename=$ENV{'form.newrolename'};
1083: }
1084:
1.63 www 1085: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 1086:
1087: unless ($rolename) {
1088: &print_username_entry_form($r);
1089: return;
1090: }
1091:
1092: $r->print(&Apache::loncommon::bodytag(
1.59 www 1093: 'Create Users, Change User Privileges').'<h2>');
1.61 www 1094: my $syspriv='';
1095: my $dompriv='';
1096: my $coursepriv='';
1.59 www 1097: my ($rdummy,$roledef)=
1098: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 1099: # ------------------------------------------------------- Does this role exist?
1.59 www 1100: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1101: $r->print(&mt('Existing Role').' "');
1.61 www 1102: # ------------------------------------------------- Get current role privileges
1103: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 1104: } else {
1.73 sakharuk 1105: $r->print(&mt('New Role').' "');
1.59 www 1106: $roledef='';
1107: }
1108: $r->print($rolename.'"</h2>');
1.60 www 1109: # ------------------------------------------------------- What can be assigned?
1110: my %full=();
1111: my %courselevel=();
1.61 www 1112: my %courselevelcurrent=();
1.60 www 1113: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1114: my ($priv,$restrict)=split(/\&/,$_);
1115: unless ($restrict) { $restrict='F'; }
1116: $courselevel{$priv}=$restrict;
1.61 www 1117: if ($coursepriv=~/\:$priv/) {
1118: $courselevelcurrent{$priv}=1;
1119: }
1.60 www 1120: $full{$priv}=1;
1121: }
1122: my %domainlevel=();
1.61 www 1123: my %domainlevelcurrent=();
1.60 www 1124: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1125: my ($priv,$restrict)=split(/\&/,$_);
1126: unless ($restrict) { $restrict='F'; }
1127: $domainlevel{$priv}=$restrict;
1.61 www 1128: if ($dompriv=~/\:$priv/) {
1129: $domainlevelcurrent{$priv}=1;
1130: }
1.60 www 1131: $full{$priv}=1;
1132: }
1.61 www 1133: my %systemlevel=();
1134: my %systemlevelcurrent=();
1135: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1136: my ($priv,$restrict)=split(/\&/,$_);
1137: unless ($restrict) { $restrict='F'; }
1138: $systemlevel{$priv}=$restrict;
1139: if ($syspriv=~/\:$priv/) {
1140: $systemlevelcurrent{$priv}=1;
1141: }
1142: $full{$priv}=1;
1143: }
1.73 sakharuk 1144: my %lt=&Apache::lonlocal::texthash(
1145: 'prv' => "Privilege",
1146: 'crl' => "Course Level",
1147: 'dml' => "Domain Level",
1148: 'ssl' => "System Level"
1149: );
1.61 www 1150: $r->print(<<ENDCCF);
1151: <form method="post">
1152: <input type="hidden" name="phase" value="set_custom_roles" />
1153: <input type="hidden" name="rolename" value="$rolename" />
1154: <table border="2">
1.73 sakharuk 1155: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1156: <th>$lt{'ssl'}</th></tr>
1.61 www 1157: ENDCCF
1.60 www 1158: foreach (sort keys %full) {
1159: $r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
1.61 www 1160: ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
1161: ($courselevelcurrent{$_}?'checked="1"':'').' />':' ').
1162: '</td><td>'.
1163: ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
1164: ($domainlevelcurrent{$_}?'checked="1"':'').' />':' ').
1165: '</td><td>'.
1166: ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
1167: ($systemlevelcurrent{$_}?'checked="1"':'').' />':' ').
1168: '</td></tr>');
1.60 www 1169: }
1.61 www 1170: $r->print(
1.73 sakharuk 1171: '<table><input type="submit" value="'.&mt('Define Role').'" /></form></body></html>');
1.61 www 1172: }
1173:
1174: # ---------------------------------------------------------- Call to definerole
1175: sub set_custom_role {
1176: my $r=shift;
1177:
1178: my $rolename=$ENV{'form.rolename'};
1179:
1.63 www 1180: $rolename=~s/[^A-Za-z0-9]//gs;
1.61 www 1181:
1182: unless ($rolename) {
1183: &print_username_entry_form($r);
1184: return;
1185: }
1186:
1187: $r->print(&Apache::loncommon::bodytag(
1188: 'Create Users, Change User Privileges').'<h2>');
1189: my ($rdummy,$roledef)=
1190: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1191: # ------------------------------------------------------- Does this role exist?
1192: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1193: $r->print(&mt('Existing Role').' "');
1.61 www 1194: } else {
1.73 sakharuk 1195: $r->print(&mt('New Role').' "');
1.61 www 1196: $roledef='';
1197: }
1198: $r->print($rolename.'"</h2>');
1199: # ------------------------------------------------------- What can be assigned?
1200: my $sysrole='';
1201: my $domrole='';
1202: my $courole='';
1203:
1204: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1205: my ($priv,$restrict)=split(/\&/,$_);
1206: unless ($restrict) { $restrict=''; }
1207: if ($ENV{'form.'.$priv.':c'}) {
1208: $courole.=':'.$_;
1209: }
1210: }
1211:
1212: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1213: my ($priv,$restrict)=split(/\&/,$_);
1214: unless ($restrict) { $restrict=''; }
1215: if ($ENV{'form.'.$priv.':d'}) {
1216: $domrole.=':'.$_;
1217: }
1218: }
1219:
1220: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1221: my ($priv,$restrict)=split(/\&/,$_);
1222: unless ($restrict) { $restrict=''; }
1223: if ($ENV{'form.'.$priv.':s'}) {
1224: $sysrole.=':'.$_;
1225: }
1226: }
1.63 www 1227: $r->print('<br />Defining Role: '.
1.61 www 1228: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.63 www 1229: if ($ENV{'request.course.id'}) {
1230: my $url='/'.$ENV{'request.course.id'};
1231: $url=~s/\_/\//g;
1.73 sakharuk 1232: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.63 www 1233: &Apache::lonnet::assigncustomrole($ENV{'user.domain'},
1234: $ENV{'user.name'},
1235: $url,
1236: $ENV{'user.domain'},
1237: $ENV{'user.name'},
1238: $rolename));
1239: }
1.61 www 1240: $r->print('</body></html>');
1.58 www 1241: }
1242:
1.2 www 1243: # ================================================================ Main Handler
1244: sub handler {
1245: my $r = shift;
1246:
1247: if ($r->header_only) {
1.68 www 1248: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1249: $r->send_http_header;
1250: return OK;
1251: }
1252:
1253: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
1254: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
1255: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
1256: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
1.42 matthew 1257: (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
1258: (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
1.68 www 1259: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1260: $r->send_http_header;
1261: unless ($ENV{'form.phase'}) {
1.42 matthew 1262: &print_username_entry_form($r);
1.2 www 1263: }
1.42 matthew 1264: if ($ENV{'form.phase'} eq 'get_user_info') {
1265: &print_user_modification_page($r);
1266: } elsif ($ENV{'form.phase'} eq 'update_user_data') {
1267: &update_user_data($r);
1.58 www 1268: } elsif ($ENV{'form.phase'} eq 'selected_custom_edit') {
1269: &custom_role_editor($r);
1.61 www 1270: } elsif ($ENV{'form.phase'} eq 'set_custom_roles') {
1271: &set_custom_role($r);
1.2 www 1272: }
1.1 www 1273: } else {
1274: $ENV{'user.error.msg'}=
1.9 albertel 1275: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 1276: return HTTP_NOT_ACCEPTABLE;
1277: }
1278: return OK;
1279: }
1.26 matthew 1280:
1.27 matthew 1281: #-------------------------------------------------- functions for &phase_two
1.26 matthew 1282: sub course_level_table {
1283: my %inccourses = @_;
1284: my $table = '';
1.62 www 1285: # Custom Roles?
1286:
1287: my %customroles=&my_custom_roles();
1288:
1.26 matthew 1289: foreach (sort( keys(%inccourses))) {
1290: my $thiscourse=$_;
1291: my $protectedcourse=$_;
1292: $thiscourse=~s:_:/:g;
1293: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1294: my $area=$coursedata{'description'};
1.72 sakharuk 1295: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1.26 matthew 1296: my $bgcol=$thiscourse;
1.62 www 1297: $bgcol=~s/[^7-9a-e]//g;
1298: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.82 albertel 1299: my ($domain)=split(/\//,$thiscourse);
1.26 matthew 1300: foreach ('st','ta','ep','ad','in','cc') {
1301: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1302: my $plrole=&Apache::lonnet::plaintext($_);
1303: $table .= <<ENDEXTENT;
1304: <tr bgcolor="#$bgcol">
1305: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1306: <td>$plrole</td>
1.82 albertel 1307: <td>$area<br />Domain: $domain</td>
1.26 matthew 1308: ENDEXTENT
1309: if ($_ ne 'cc') {
1310: $table .= <<ENDSECTION;
1311: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
1312: ENDSECTION
1313: } else {
1314: $table .= <<ENDSECTION;
1315: <td> </td>
1316: ENDSECTION
1317: }
1.73 sakharuk 1318: my %lt=&Apache::lonlocal::texthash(
1319: 'ssd' => "Set Start Date",
1320: 'sed' => "Set End Date"
1321: );
1.26 matthew 1322: $table .= <<ENDTIMEENTRY;
1323: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1324: <a href=
1.73 sakharuk 1325: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.26 matthew 1326: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1327: <a href=
1.73 sakharuk 1328: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26 matthew 1329: ENDTIMEENTRY
1330: $table.= "</tr>\n";
1331: }
1332: }
1.62 www 1333: foreach (sort keys %customroles) {
1.65 www 1334: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1335: my $plrole=$_;
1336: my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}.
1337: '_'.$ENV{'user.name'}.'_'.$plrole;
1.73 sakharuk 1338: my %lt=&Apache::lonlocal::texthash(
1339: 'ssd' => "Set Start Date",
1340: 'sed' => "Set End Date"
1341: );
1.65 www 1342: $table .= <<ENDENTRY;
1.62 www 1343: <tr bgcolor="#$bgcol">
1.65 www 1344: <td><input type="checkbox" name="act_$customrole"></td>
1.62 www 1345: <td>$plrole</td>
1346: <td>$area</td>
1.65 www 1347: <td><input type="text" size="5" name="sec_$customrole"></td>
1348: <td><input type=hidden name="start_$customrole" value=''>
1.62 www 1349: <a href=
1.73 sakharuk 1350: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.65 www 1351: <td><input type=hidden name="end_$customrole" value=''>
1.62 www 1352: <a href=
1.73 sakharuk 1353: "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 1354: ENDENTRY
1.65 www 1355: }
1.62 www 1356: }
1.26 matthew 1357: }
1358: return '' if ($table eq ''); # return nothing if there is nothing
1359: # in the table
1.73 sakharuk 1360: my %lt=&Apache::lonlocal::texthash(
1361: 'crl' => "Course Level",
1362: 'act' => "Activate",
1363: 'rol' => "Role",
1364: 'ext' => "Extent",
1365: 'grs' => "Group/Section",
1366: 'sta' => "Start",
1367: 'end' => "End"
1368: );
1.26 matthew 1369: my $result = <<ENDTABLE;
1.73 sakharuk 1370: <h4>$lt{'crl'}</h4>
1371: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1372: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.26 matthew 1373: $table
1374: </table>
1375: ENDTABLE
1376: return $result;
1377: }
1.27 matthew 1378: #---------------------------------------------- end functions for &phase_two
1.29 matthew 1379:
1380: #--------------------------------- functions for &phase_two and &phase_three
1381:
1382: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 1383:
1384: 1;
1385: __END__
1.2 www 1386:
1387:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>