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