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