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