Annotation of loncom/interface/loncreateuser.pm, revision 1.87
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.87 ! albertel 4: # $Id: loncreateuser.pm,v 1.86 2004/08/24 23:50:15 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.86 albertel 392: $sortkey.="\0".&mt('Unavailable course').': '.$area;
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.87 ! albertel 416: $sortkey.="\0$3";
1.37 matthew 417: }
418: $area=$carea;
419: } else {
1.79 albertel 420: $sortkey.="\0".$area;
1.37 matthew 421: # Determine if current user is able to revoke privileges
422: if ($area=~ /^\/(\w+)\//) {
1.53 www 423: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
424: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37 matthew 425: $allowed=1;
426: }
1.53 www 427: if (((&Apache::lonnet::allowed('dro',$1)) ||
428: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
429: ($role_code ne 'dc')) {
430: $delallowed=1;
431: }
1.37 matthew 432: } else {
433: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
434: $allowed=1;
435: }
436: }
1.79 albertel 437: if ($role_code eq 'ca' || $role_code eq 'au') {
438: $class='Construction Space';
439: } elsif ($role_code eq 'su') {
440: $class='System';
441: } else {
442: $class='Domain';
443: }
1.37 matthew 444: }
1.43 www 445: if ($role_code eq 'ca') {
446: $area=~/\/(\w+)\/(\w+)/;
447: if (&authorpriv($2,$1)) {
448: $allowed=1;
449: } else {
450: $allowed=0;
1.37 matthew 451: }
452: }
1.79 albertel 453: $bgcol='77FF77';
1.37 matthew 454: my $row = '';
1.62 www 455: $row.='<tr bgcolor="#'.$bgcol.'"><td>';
1.37 matthew 456: my $active=1;
457: $active=0 if (($role_end_time) && ($now>$role_end_time));
458: if (($active) && ($allowed)) {
459: $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
460: } else {
1.56 www 461: if ($active) {
462: $row.=' ';
463: } else {
1.72 sakharuk 464: $row.=&mt('expired or revoked');
1.56 www 465: }
1.37 matthew 466: }
1.53 www 467: $row.='</td><td>';
1.81 albertel 468: if ($allowed && !$active) {
469: $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
470: } else {
471: $row.=' ';
472: }
473: $row.='</td><td>';
1.53 www 474: if ($delallowed) {
475: $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
476: } else {
477: $row.=' ';
478: }
1.64 www 479: my $plaintext='';
480: unless ($croletitle) {
481: $plaintext=&Apache::lonnet::plaintext($role_code);
482: } else {
483: $plaintext=
484: "Customrole '$croletitle' defined by $croleuname\@$croleudom";
485: }
486: $row.= '</td><td>'.$plaintext.
1.37 matthew 487: '</td><td>'.$area.
488: '</td><td>'.($role_start_time?localtime($role_start_time)
489: : ' ' ).
490: '</td><td>'.($role_end_time ?localtime($role_end_time)
491: : ' ' )
492: ."</td></tr>\n";
1.79 albertel 493: $sortrole{$sortkey}=$envkey;
494: $roletext{$envkey}=$row;
495: $roleclass{$envkey}=$class;
496: #$r->print($row);
1.28 matthew 497: } # end of foreach (table building loop)
1.79 albertel 498: foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
499: my $output;
500: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
501: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
502: $output.=$roletext{$sortrole{$which}};
503: }
504: }
505: if (defined($output)) {
506: $r->print("<tr bgcolor='#BBffBB'>".
507: "<td align='center' colspan='7'>".&mt($type)."</td>");
508: }
509: $r->print($output);
510: }
1.2 www 511: $r->print('</table>');
1.28 matthew 512: } # End of unless
1.20 harris41 513: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.41 albertel 514: if ($currentauth=~/^krb(4|5):/) {
515: $currentauth=~/^krb(4|5):(.*)/;
1.45 matthew 516: my $krbdefdom=$1;
1.31 matthew 517: my %param = ( formname => 'document.cu',
518: kerb_def_dom => $krbdefdom
519: );
520: $loginscript = &Apache::loncommon::authform_header(%param);
1.20 harris41 521: }
1.26 matthew 522: # Check for a bad authentication type
1.41 albertel 523: unless ($currentauth=~/^krb(4|5):/ or
1.20 harris41 524: $currentauth=~/^unix:/ or
525: $currentauth=~/^internal:/ or
526: $currentauth=~/^localauth:/
1.26 matthew 527: ) { # bad authentication scheme
1.42 matthew 528: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
1.73 sakharuk 529: my %lt=&Apache::lonlocal::texthash(
530: 'err' => "ERROR",
531: 'uuas' => "This user has an unrecognized authentication scheme",
532: 'sldb' => "Please specify login data below",
533: 'ld' => "Login Data"
534: );
1.26 matthew 535: $r->print(<<ENDBADAUTH);
1.21 harris41 536: <hr />
1.31 matthew 537: <script type="text/javascript" language="Javascript">
1.21 harris41 538: $loginscript
1.31 matthew 539: </script>
1.73 sakharuk 540: <font color='#ff0000'>$lt{'err'}:</font>
541: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
542: <h3>$lt{'ld'}</h3>
1.31 matthew 543: <p>$generalrule</p>
544: <p>$authformkrb</p>
545: <p>$authformint</p>
546: <p>$authformfsys</p>
547: <p>$authformloc</p>
1.26 matthew 548: ENDBADAUTH
549: } else {
550: # This user is not allowed to modify the users
551: # authentication scheme, so just notify them of the problem
1.73 sakharuk 552: my %lt=&Apache::lonlocal::texthash(
553: 'err' => "ERROR",
554: 'uuas' => "This user has an unrecognized authentication scheme",
555: 'adcs' => "Please alert a domain coordinator of this situation"
556: );
1.26 matthew 557: $r->print(<<ENDBADAUTH);
558: <hr />
1.31 matthew 559: <script type="text/javascript" language="Javascript">
1.26 matthew 560: $loginscript
1.31 matthew 561: </script>
1.73 sakharuk 562: <font color="#ff0000"> $lt{'err'}: </font>
563: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1.26 matthew 564: <hr />
565: ENDBADAUTH
566: }
567: } else { # Authentication type is valid
1.20 harris41 568: my $authformcurrent='';
1.26 matthew 569: my $authform_other='';
1.41 albertel 570: if ($currentauth=~/^krb(4|5):/) {
1.20 harris41 571: $authformcurrent=$authformkrb;
1.31 matthew 572: $authform_other="<p>$authformint</p>\n".
573: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 574: }
575: elsif ($currentauth=~/^internal:/) {
576: $authformcurrent=$authformint;
1.31 matthew 577: $authform_other="<p>$authformkrb</p>".
578: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 579: }
580: elsif ($currentauth=~/^unix:/) {
581: $authformcurrent=$authformfsys;
1.31 matthew 582: $authform_other="<p>$authformkrb</p>".
583: "<p>$authformint</p><p>$authformloc;</p>";
1.20 harris41 584: }
585: elsif ($currentauth=~/^localauth:/) {
586: $authformcurrent=$authformloc;
1.31 matthew 587: $authform_other="<p>$authformkrb</p>".
588: "<p>$authformint</p><p>$authformfsys</p>";
1.20 harris41 589: }
1.53 www 590: $authformcurrent.=' <i>(will override current values)</i><br />';
1.42 matthew 591: if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
1.26 matthew 592: # Current user has login modification privileges
1.73 sakharuk 593: my %lt=&Apache::lonlocal::texthash(
594: 'ccld' => "Change Current Login Data",
595: 'enld' => "Enter New Login Data"
596: );
1.26 matthew 597: $r->print(<<ENDOTHERAUTHS);
1.21 harris41 598: <hr />
1.31 matthew 599: <script type="text/javascript" language="Javascript">
1.21 harris41 600: $loginscript
1.31 matthew 601: </script>
1.73 sakharuk 602: <h3>$lt{'ccld'}</h3>
1.31 matthew 603: <p>$generalrule</p>
604: <p>$authformnop</p>
605: <p>$authformcurrent</p>
1.73 sakharuk 606: <h3>$lt{'enld'}</h3>
1.26 matthew 607: $authform_other
608: ENDOTHERAUTHS
609: }
610: } ## End of "check for bad authentication type" logic
1.25 matthew 611: } ## End of new user/old user logic
1.72 sakharuk 612: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
1.17 www 613: #
614: # Co-Author
615: #
1.44 matthew 616: if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
617: ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
618: # No sense in assigning co-author role to yourself
1.17 www 619: my $cuname=$ENV{'user.name'};
1.42 matthew 620: my $cudom=$ENV{'request.role.domain'};
1.72 sakharuk 621: my %lt=&Apache::lonlocal::texthash(
622: 'cs' => "Construction Space",
623: 'act' => "Activate",
624: 'rol' => "Role",
625: 'ext' => "Extent",
626: 'sta' => "Start",
1.80 www 627: 'end' => "End",
1.72 sakharuk 628: 'cau' => "Co-Author",
629: 'ssd' => "Set Start Date",
630: 'sed' => "Set End Date"
631: );
1.17 www 632: $r->print(<<ENDCOAUTH);
1.72 sakharuk 633: <h4>$lt{'cs'}</h4>
1.74 sakharuk 634: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1.72 sakharuk 635: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.17 www 636: <tr>
1.80 www 637: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
1.72 sakharuk 638: <td>$lt{'cau'}</td>
1.17 www 639: <td>$cudom\_$cuname</td>
1.80 www 640: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
1.17 www 641: <a href=
1.72 sakharuk 642: "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 643: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
1.17 www 644: <a href=
1.72 sakharuk 645: "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 646: </tr>
647: </table>
648: ENDCOAUTH
649: }
1.8 www 650: #
651: # Domain level
652: #
1.72 sakharuk 653: $r->print('<h4>'.&mt('Domain Level').'</h4>'.
1.73 sakharuk 654: '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
655: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>');
1.24 matthew 656: foreach ( sort( keys(%incdomains))) {
1.2 www 657: my $thisdomain=$_;
1.69 albertel 658: foreach ('dc','li','dg','au','sc') {
1.2 www 659: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8 www 660: my $plrole=&Apache::lonnet::plaintext($_);
1.72 sakharuk 661: my %lt=&Apache::lonlocal::texthash(
662: 'ssd' => "Set Start Date",
663: 'sed' => "Set End Date"
664: );
1.8 www 665: $r->print(<<ENDDROW);
666: <tr>
667: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
668: <td>$plrole</td>
669: <td>$thisdomain</td>
670: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
671: <a href=
1.72 sakharuk 672: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.8 www 673: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
674: <a href=
1.72 sakharuk 675: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.8 www 676: </tr>
677: ENDDROW
1.2 www 678: }
1.24 matthew 679: }
680: }
1.8 www 681: $r->print('</table>');
682: #
683: # Course level
684: #
1.26 matthew 685: $r->print(&course_level_table(%inccourses));
1.72 sakharuk 686: $r->print("<hr /><input type=submit value=\"".&mt('Modify User')."\">\n");
1.26 matthew 687: $r->print("</form></body></html>");
1.2 www 688: }
1.1 www 689:
1.4 www 690: # ================================================================= Phase Three
1.42 matthew 691: sub update_user_data {
1.4 www 692: my $r=shift;
1.29 matthew 693: my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
694: $ENV{'form.ccdomain'});
1.27 matthew 695: # Error messages
1.73 sakharuk 696: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
1.27 matthew 697: my $end = '</body></html>';
698: # Print header
1.4 www 699: $r->print(<<ENDTHREEHEAD);
700: <html>
701: <head>
702: <title>The LearningOnline Network with CAPA</title>
703: </head>
704: ENDTHREEHEAD
1.40 www 705: my $title;
706: if (exists($ENV{'form.makeuser'})) {
707: $title='Set Privileges for New User';
708: } else {
709: $title='Modify User Privileges';
710: }
711: $r->print(&Apache::loncommon::bodytag($title));
1.27 matthew 712: # Check Inputs
1.29 matthew 713: if (! $ENV{'form.ccuname'} ) {
1.73 sakharuk 714: $r->print($error.&mt('No login name specified').'.'.$end);
1.27 matthew 715: return;
716: }
1.29 matthew 717: if ( $ENV{'form.ccuname'} =~/\W/) {
1.73 sakharuk 718: $r->print($error.&mt('Invalid login name').'. '.
719: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 720: $end);
721: return;
722: }
1.29 matthew 723: if (! $ENV{'form.ccdomain'} ) {
1.73 sakharuk 724: $r->print($error.&mt('No domain specified').'.'.$end);
1.27 matthew 725: return;
726: }
1.29 matthew 727: if ( $ENV{'form.ccdomain'} =~/\W/) {
1.73 sakharuk 728: $r->print($error.&mt ('Invalid domain name').'. '.
729: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 730: $end);
731: return;
732: }
1.29 matthew 733: if (! exists($ENV{'form.makeuser'})) {
734: # Modifying an existing user, so check the validity of the name
735: if ($uhome eq 'no_host') {
1.73 sakharuk 736: $r->print($error.&mt('Unable to determine home server for ').
737: $ENV{'form.ccuname'}.&mt(' in domain ').
1.29 matthew 738: $ENV{'form.ccdomain'}.'.');
739: return;
740: }
741: }
1.27 matthew 742: # Determine authentication method and password for the user being modified
743: my $amode='';
744: my $genpwd='';
745: if ($ENV{'form.login'} eq 'krb') {
1.41 albertel 746: $amode='krb';
747: $amode.=$ENV{'form.krbver'};
1.30 matthew 748: $genpwd=$ENV{'form.krbarg'};
1.27 matthew 749: } elsif ($ENV{'form.login'} eq 'int') {
750: $amode='internal';
1.30 matthew 751: $genpwd=$ENV{'form.intarg'};
1.27 matthew 752: } elsif ($ENV{'form.login'} eq 'fsys') {
753: $amode='unix';
1.30 matthew 754: $genpwd=$ENV{'form.fsysarg'};
1.27 matthew 755: } elsif ($ENV{'form.login'} eq 'loc') {
756: $amode='localauth';
757: $genpwd=$ENV{'form.locarg'};
758: $genpwd=" " if (!$genpwd);
1.35 matthew 759: } elsif (($ENV{'form.login'} eq 'nochange') ||
760: ($ENV{'form.login'} eq '' )) {
1.34 matthew 761: # There is no need to tell the user we did not change what they
762: # did not ask us to change.
1.35 matthew 763: # If they are creating a new user but have not specified login
764: # information this will be caught below.
1.30 matthew 765: } else {
1.73 sakharuk 766: $r->print($error.&mt('Invalid login mode or password').$end);
1.30 matthew 767: return;
1.27 matthew 768: }
769: if ($ENV{'form.makeuser'}) {
770: # Create a new user
1.73 sakharuk 771: my %lt=&Apache::lonlocal::texthash(
772: 'cru' => "Creating user",
773: 'id' => "in domain"
774: );
1.27 matthew 775: $r->print(<<ENDNEWUSERHEAD);
1.73 sakharuk 776: <h3>$lt{'cru'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h3>
1.27 matthew 777: ENDNEWUSERHEAD
778: # Check for the authentication mode and password
779: if (! $amode || ! $genpwd) {
1.73 sakharuk 780: $r->print($error.&mt('Invalid login mode or password').$end);
1.27 matthew 781: return;
1.18 albertel 782: }
1.29 matthew 783: # Determine desired host
784: my $desiredhost = $ENV{'form.hserver'};
785: if (lc($desiredhost) eq 'default') {
786: $desiredhost = undef;
787: } else {
1.39 matthew 788: my %home_servers = &Apache::loncommon::get_library_servers
1.32 matthew 789: ($ENV{'form.ccdomain'});
1.29 matthew 790: if (! exists($home_servers{$desiredhost})) {
1.73 sakharuk 791: $r->print($error.&mt('Invalid home server specified'));
1.29 matthew 792: return;
793: }
794: }
1.27 matthew 795: # Call modifyuser
796: my $result = &Apache::lonnet::modifyuser
1.29 matthew 797: ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
798: $amode,$genpwd,$ENV{'form.cfirst'},
799: $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
800: undef,$desiredhost
1.27 matthew 801: );
1.77 www 802: $r->print(&mt('Generating user').': '.$result);
1.29 matthew 803: my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
804: $ENV{'form.ccdomain'});
1.77 www 805: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.29 matthew 806: $Apache::lonnet::libserv{$home});
1.35 matthew 807: } elsif (($ENV{'form.login'} ne 'nochange') &&
808: ($ENV{'form.login'} ne '' )) {
1.27 matthew 809: # Modify user privileges
1.73 sakharuk 810: my %lt=&Apache::lonlocal::texthash(
811: 'usr' => "User",
812: 'id' => "in domain"
813: );
1.27 matthew 814: $r->print(<<ENDMODIFYUSERHEAD);
1.73 sakharuk 815: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
1.27 matthew 816: ENDMODIFYUSERHEAD
817: if (! $amode || ! $genpwd) {
818: $r->print($error.'Invalid login mode or password'.$end);
819: return;
1.20 harris41 820: }
1.27 matthew 821: # Only allow authentification modification if the person has authority
1.36 matthew 822: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
1.20 harris41 823: $r->print('Modifying authentication: '.
1.31 matthew 824: &Apache::lonnet::modifyuserauth(
1.29 matthew 825: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
1.21 harris41 826: $amode,$genpwd));
1.73 sakharuk 827: $r->print('<br>'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.29 matthew 828: ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
1.4 www 829: } else {
1.27 matthew 830: # Okay, this is a non-fatal error.
1.73 sakharuk 831: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1.27 matthew 832: }
1.28 matthew 833: }
834: ##
835: if (! $ENV{'form.makeuser'} ) {
836: # Check for need to change
837: my %userenv = &Apache::lonnet::get
838: ('environment',['firstname','middlename','lastname','generation'],
1.29 matthew 839: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
1.28 matthew 840: my ($tmp) = keys(%userenv);
841: if ($tmp =~ /^(con_lost|error)/i) {
842: %userenv = ();
843: }
844: # Check to see if we need to change user information
845: foreach ('firstname','middlename','lastname','generation') {
846: # Strip leading and trailing whitespace
847: $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
848: }
1.29 matthew 849: if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) &&
1.28 matthew 850: ($ENV{'form.cfirstname'} ne $userenv{'firstname'} ||
851: $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
852: $ENV{'form.clastname'} ne $userenv{'lastname'} ||
853: $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
854: # Make the change
855: my %changeHash;
856: $changeHash{'firstname'} = $ENV{'form.cfirstname'};
857: $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
858: $changeHash{'lastname'} = $ENV{'form.clastname'};
859: $changeHash{'generation'} = $ENV{'form.cgeneration'};
860: my $putresult = &Apache::lonnet::put
861: ('environment',\%changeHash,
1.29 matthew 862: $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
1.28 matthew 863: if ($putresult eq 'ok') {
864: # Tell the user we changed the name
1.73 sakharuk 865: my %lt=&Apache::lonlocal::texthash(
866: 'uic' => "User Information Changed",
867: 'frst' => "first",
868: 'mddl' => "middle",
869: 'lst' => "last",
870: 'gen' => "generation",
871: 'prvs' => "Previous",
872: 'chto' => "Changed To"
873: );
1.28 matthew 874: $r->print(<<"END");
875: <table border="2">
1.73 sakharuk 876: <caption>$lt{'uic'}</caption>
1.28 matthew 877: <tr><th> </th>
1.73 sakharuk 878: <th>$lt{'frst'}</th>
879: <th>$lt{'mddl'}</th>
880: <th>$lt{'lst'}</th>
881: <th>$lt{'gen'}</th></tr>
882: <tr><td>$lt{'prvs'}</td>
1.28 matthew 883: <td>$userenv{'firstname'} </td>
884: <td>$userenv{'middlename'} </td>
885: <td>$userenv{'lastname'} </td>
886: <td>$userenv{'generation'} </td></tr>
1.73 sakharuk 887: <tr><td>$lt{'chto'}</td>
1.28 matthew 888: <td>$ENV{'form.cfirstname'} </td>
889: <td>$ENV{'form.cmiddlename'} </td>
890: <td>$ENV{'form.clastname'} </td>
891: <td>$ENV{'form.cgeneration'} </td></tr>
892: </table>
893: END
894: } else { # error occurred
1.73 sakharuk 895: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
896: $ENV{'form.ccuname'}." ".&mt('in domain')." ".
1.29 matthew 897: $ENV{'form.ccdomain'}."</h2>");
1.28 matthew 898: }
899: } else { # End of if ($ENV ... ) logic
900: # They did not want to change the users name but we can
901: # still tell them what the name is
1.73 sakharuk 902: my %lt=&Apache::lonlocal::texthash(
903: 'usr' => "User",
904: 'id' => "in domain",
905: 'gen' => "Generation"
906: );
1.28 matthew 907: $r->print(<<"END");
1.74 sakharuk 908: <h2>$lt{'usr'} "$ENV{'form.ccuname'}" $lt{'id'} "$ENV{'form.ccdomain'}"</h2>
1.28 matthew 909: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1.73 sakharuk 910: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1.28 matthew 911: END
912: }
1.4 www 913: }
1.27 matthew 914: ##
1.4 www 915: my $now=time;
1.73 sakharuk 916: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.24 matthew 917: foreach (keys (%ENV)) {
1.27 matthew 918: next if (! $ENV{$_});
919: # Revoke roles
920: if ($_=~/^form\.rev/) {
1.64 www 921: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
922: # Revoke standard role
1.73 sakharuk 923: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1.65 www 924: &Apache::lonnet::revokerole($ENV{'form.ccdomain'},
925: $ENV{'form.ccuname'},$1,$2).'</b><br>');
1.53 www 926: if ($2 eq 'st') {
927: $1=~/^\/(\w+)\/(\w+)/;
928: my $cid=$1.'_'.$2;
1.73 sakharuk 929: $r->print(&mt('Drop from classlist').': <b>'.
1.53 www 930: &Apache::lonnet::critical('put:'.
931: $ENV{'course.'.$cid.'.domain'}.':'.
932: $ENV{'course.'.$cid.'.num'}.':classlist:'.
933: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
934: $ENV{'form.ccdomain'}).'='.
935: &Apache::lonnet::escape($now.':'),
1.56 www 936: $ENV{'course.'.$cid.'.home'}).'</b><br>');
1.53 www 937: }
938: }
1.64 www 939: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
940: # Revoke custom role
1.73 sakharuk 941: $r->print(&mt('Revoking custom role').
942: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
943: &Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'},
1.65 www 944: $ENV{'form.ccuname'},$1,$2,$3,$4).
1.64 www 945: '</b><br>');
946: }
1.53 www 947: } elsif ($_=~/^form\.del/) {
948: if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
1.73 sakharuk 949: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.53 www 950: &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
951: $ENV{'form.ccuname'},$1,$2,$now,0,1).'<br>');
1.27 matthew 952: if ($2 eq 'st') {
953: $1=~/^\/(\w+)\/(\w+)/;
954: my $cid=$1.'_'.$2;
1.73 sakharuk 955: $r->print(&mt('Drop from classlist').': <b>'.
1.27 matthew 956: &Apache::lonnet::critical('put:'.
957: $ENV{'course.'.$cid.'.domain'}.':'.
958: $ENV{'course.'.$cid.'.num'}.':classlist:'.
1.29 matthew 959: &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
960: $ENV{'form.ccdomain'}).'='.
1.27 matthew 961: &Apache::lonnet::escape($now.':'),
1.56 www 962: $ENV{'course.'.$cid.'.home'}).'</b><br>');
1.81 albertel 963: }
964: }
965: } elsif ($_=~/^form\.ren/) {
966: if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) {
967: my $result=&Apache::lonnet::assignrole($ENV{'form.ccdomain'},
968: $ENV{'form.ccuname'},$1,$2,0,$now);
969: $r->print(&mt('Re-Enabling [_1] in [_2]: [_3]',
970: $2,$1,$result).'<br />');
971: if ($2 eq 'st') {
972: $1=~/^\/(\w+)\/(\w+)/;
973: my $cid=$1.'_'.$2;
974: $r->print(&mt('Add to classlist').': <b>'.
975: &Apache::lonnet::critical(
976: 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
977: $ENV{'course.'.$cid.'.num'}.':classlist:'.
978: &Apache::lonnet::escape(
979: $ENV{'form.ccuname'}.':'.
980: $ENV{'form.ccdomain'} ).'='.
981: &Apache::lonnet::escape(':'.$now),
982: $ENV{'course.'.$cid.'.home'})
983: .'</b><br>');
1.27 matthew 984: }
985: }
986: } elsif ($_=~/^form\.act/) {
1.83 albertel 987: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1.65 www 988: # Activate a custom role
1.83 albertel 989: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
990: my $url='/'.$one.'/'.$two;
991: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
992: $ENV{'form.sec_'.$full}=~s/\W//g;
1.65 www 993: if ($ENV{'form.sec_'.$full}) {
994: $url.='/'.$ENV{'form.sec_'.$full};
995: }
996:
997: my $start = ( $ENV{'form.start_'.$full} ?
998: $ENV{'form.start_'.$full} :
999: $now );
1000: my $end = ( $ENV{'form.end_'.$full} ?
1001: $ENV{'form.end_'.$full} :
1002: 0 );
1003:
1.83 albertel 1004: $r->print(&mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1.73 sakharuk 1005: ($start?', '.&mt('starting').' '.localtime($start):'').
1.65 www 1006: ($end?', ending '.localtime($end):'').': <b>'.
1007: &Apache::lonnet::assigncustomrole(
1.83 albertel 1008: $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start).
1.65 www 1009: '</b><br>');
1010: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 1011: # Activate roles for sections with 3 id numbers
1012: # set start, end times, and the url for the class
1.83 albertel 1013: my ($one,$two,$three)=($1,$2,$3);
1014: my $start = ( $ENV{'form.start_'.$one.'_'.$two.'_'.$three} ?
1015: $ENV{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1016: $now );
1.83 albertel 1017: my $end = ( $ENV{'form.end_'.$one.'_'.$two.'_'.$three} ?
1018: $ENV{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1019: 0 );
1.83 albertel 1020: my $url='/'.$one.'/'.$two;
1021: $ENV{'form.sec_'.$one.'_'.$two.'_'.$three}=~s/\W//g;
1022: if ($ENV{'form.sec_'.$one.'_'.$two.'_'.$three}) {
1023: $url.='/'.$ENV{'form.sec_'.$one.'_'.$two.'_'.$three};
1.27 matthew 1024: }
1025: # Assign the role and report it
1.83 albertel 1026: $r->print(&mt('Assigning').' '.$three.' in '.$url.
1.73 sakharuk 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.83 albertel 1031: $url,$three,$end,$start).
1.56 www 1032: '</b><br>');
1.27 matthew 1033: # Handle students differently
1.83 albertel 1034: if ($three eq 'st') {
1.27 matthew 1035: $url=~/^\/(\w+)\/(\w+)/;
1.83 albertel 1036: my $cid=$one.'_'.$two;
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.82 albertel 1300: my ($domain)=split(/\//,$thiscourse);
1.26 matthew 1301: foreach ('st','ta','ep','ad','in','cc') {
1302: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1303: my $plrole=&Apache::lonnet::plaintext($_);
1304: $table .= <<ENDEXTENT;
1305: <tr bgcolor="#$bgcol">
1306: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1307: <td>$plrole</td>
1.82 albertel 1308: <td>$area<br />Domain: $domain</td>
1.26 matthew 1309: ENDEXTENT
1310: if ($_ ne 'cc') {
1311: $table .= <<ENDSECTION;
1312: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
1313: ENDSECTION
1314: } else {
1315: $table .= <<ENDSECTION;
1316: <td> </td>
1317: ENDSECTION
1318: }
1.73 sakharuk 1319: my %lt=&Apache::lonlocal::texthash(
1320: 'ssd' => "Set Start Date",
1321: 'sed' => "Set End Date"
1322: );
1.26 matthew 1323: $table .= <<ENDTIMEENTRY;
1324: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1325: <a href=
1.73 sakharuk 1326: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.26 matthew 1327: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1328: <a href=
1.73 sakharuk 1329: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26 matthew 1330: ENDTIMEENTRY
1331: $table.= "</tr>\n";
1332: }
1333: }
1.62 www 1334: foreach (sort keys %customroles) {
1.65 www 1335: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1336: my $plrole=$_;
1337: my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}.
1338: '_'.$ENV{'user.name'}.'_'.$plrole;
1.73 sakharuk 1339: my %lt=&Apache::lonlocal::texthash(
1340: 'ssd' => "Set Start Date",
1341: 'sed' => "Set End Date"
1342: );
1.65 www 1343: $table .= <<ENDENTRY;
1.62 www 1344: <tr bgcolor="#$bgcol">
1.65 www 1345: <td><input type="checkbox" name="act_$customrole"></td>
1.62 www 1346: <td>$plrole</td>
1347: <td>$area</td>
1.65 www 1348: <td><input type="text" size="5" name="sec_$customrole"></td>
1349: <td><input type=hidden name="start_$customrole" value=''>
1.62 www 1350: <a href=
1.73 sakharuk 1351: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.65 www 1352: <td><input type=hidden name="end_$customrole" value=''>
1.62 www 1353: <a href=
1.73 sakharuk 1354: "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 1355: ENDENTRY
1.65 www 1356: }
1.62 www 1357: }
1.26 matthew 1358: }
1359: return '' if ($table eq ''); # return nothing if there is nothing
1360: # in the table
1.73 sakharuk 1361: my %lt=&Apache::lonlocal::texthash(
1362: 'crl' => "Course Level",
1363: 'act' => "Activate",
1364: 'rol' => "Role",
1365: 'ext' => "Extent",
1366: 'grs' => "Group/Section",
1367: 'sta' => "Start",
1368: 'end' => "End"
1369: );
1.26 matthew 1370: my $result = <<ENDTABLE;
1.73 sakharuk 1371: <h4>$lt{'crl'}</h4>
1372: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1373: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.26 matthew 1374: $table
1375: </table>
1376: ENDTABLE
1377: return $result;
1378: }
1.27 matthew 1379: #---------------------------------------------- end functions for &phase_two
1.29 matthew 1380:
1381: #--------------------------------- functions for &phase_two and &phase_three
1382:
1383: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 1384:
1385: 1;
1386: __END__
1.2 www 1387:
1388:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>