Annotation of loncom/auth/lonroles.pm, revision 1.32
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.32 ! harris41 4: # $Id: lonroles.pm,v 1.31 2001/11/29 19:12:44 www Exp $
1.31 www 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.1 harris41 28: # (Directory Indexer
29: # (Login Screen
1.32 ! harris41 30: # YEAR=1999
1.1 harris41 31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
32: # 11/23 Gerd Kortemeyer)
1.32 ! harris41 33: # YEAR=2000
1.7 www 34: # 1/14,03/06,06/01,07/22,07/24,07/25,
1.19 www 35: # 09/04,09/06,09/28,09/29,09/30,10/2,10/5,10/26,10/28,
1.20 www 36: # 12/08,12/28,
1.32 ! harris41 37: # YEAR=2001
1.20 www 38: # 01/15/01 Gerd Kortemeyer
1.22 harris41 39: # 02/27/01 Scott Harrison
1.28 www 40: # 03/02,05/03,05/25,05/30,06/01,07/06,08/06 Gerd Kortemeyer
1.32 ! harris41 41: # 12/21 Scott Harrison
! 42: #
! 43: ###
1.22 harris41 44:
1.1 harris41 45: package Apache::lonroles;
46:
47: use strict;
48: use Apache::lonnet();
1.7 www 49: use Apache::lonuserstate();
1.1 harris41 50: use Apache::Constants qw(:common);
1.2 www 51: use Apache::File();
1.26 www 52: use Apache::lonmenu;
1.29 albertel 53: use Apache::loncommon;
1.1 harris41 54:
55: sub handler {
1.10 www 56:
1.1 harris41 57: my $r = shift;
58:
1.6 www 59: my $now=time;
60: my $then=$ENV{'user.login.time'};
61: my $envkey;
62:
1.10 www 63:
1.6 www 64: # ================================================================== Roles Init
65:
66: if ($ENV{'form.selectrole'}) {
1.13 www 67: &Apache::lonnet::appenv("request.course.id" => '',
68: "request.course.fn" => '',
69: "request.course.uri" => '',
70: "request.course.sec" => '',
71: "request.role" => 'cm');
72: foreach $envkey (keys %ENV) {
73: if ($envkey=~/^user\.role\./) {
1.6 www 74: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
75: my $where=join('.',@pwhere);
76: my $trolecode=$role.'.'.$where;
77: if ($ENV{'form.'.$trolecode}) {
78: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
79: my $tstatus='is';
80: if ($tstart) {
81: if ($tstart>$then) {
82: $tstatus='future';
83: }
84: }
85: if ($tend) {
86: if ($tend<$then) { $tstatus='expired'; }
1.19 www 87: if ($tend<$now) { $tstatus='will_not'; }
1.6 www 88: }
89: if ($tstatus eq 'is') {
1.13 www 90: $where=~s/^\///;
91: my ($cdom,$cnum,$csec)=split(/\//,$where);
92: &Apache::lonnet::appenv('request.role' => $trolecode,
1.14 www 93: 'request.course.sec' => $csec);
1.27 www 94: my $msg='Entering course ...';
1.25 www 95: if (($cnum) && ($role ne 'ca')) {
1.19 www 96: my ($furl,$ferr)=
97: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.20 www 98: if (($ENV{'form.orgurl'}) &&
99: ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
1.11 www 100: $r->internal_redirect($ENV{'form.orgurl'});
101: return OK;
1.19 www 102: } else {
1.27 www 103: unless ($ENV{'request.course.id'}) {
104: &Apache::lonnet::appenv(
105: "request.course.id" => $cdom.'_'.$cnum);
106: $furl='/adm/notfound.html';
107: $msg=
108: '<h1><font color=red>Could not initialize top-level map.</font></h1>';
109: }
1.20 www 110: $r->content_type('text/html');
1.30 albertel 111: &Apache::loncommon::no_cache($r);
1.20 www 112: $r->send_http_header;
1.26 www 113: my $swinfo=&Apache::lonmenu::rawconfig;
1.20 www 114: print (<<ENDREDIR);
115: <head><title>Entering Course</title>
116: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$furl">
117: </head>
118: <html>
119: <body bgcolor="#FFFFFF">
1.26 www 120: <script>
121: $swinfo
122: </script>
1.27 www 123: $msg
1.20 www 124: </body>
125: </html>
126: ENDREDIR
127: return OK;
1.19 www 128: }
1.7 www 129: }
1.6 www 130: }
131: }
132: }
133: }
1.20 www 134: }
1.6 www 135:
1.10 www 136:
1.6 www 137: # =============================================================== No Roles Init
1.10 www 138:
139: $r->content_type('text/html');
1.30 albertel 140: &Apache::loncommon::no_cache($r);
1.10 www 141: $r->send_http_header;
142: return OK if $r->header_only;
143:
1.26 www 144: my $swinfo=&Apache::lonmenu::rawconfig;
1.10 www 145: $r->print(<<ENDHEADER);
146: <html>
147: <head>
148: <title>LON-CAPA User Roles</title>
149: </head><body bgcolor="#FFFFFF">
1.26 www 150: <script>
151: $swinfo
152: window.focus();
153: </script>
1.10 www 154: ENDHEADER
1.6 www 155:
1.2 www 156: # ------------------------------------------ Get Error Message from Environment
157:
158: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12 www 159: if ($ENV{'user.error.msg'}) {
160: $r->log_reason(
161: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
162: }
1.1 harris41 163:
1.6 www 164: # ---------------------------------------------------------------- Who is this?
165:
166: my $advanced=0;
167: foreach $envkey (keys %ENV) {
168: if ($envkey=~/^user\.role\./) {
169: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
170: if ($role ne 'st') { $advanced=1; }
171: }
172: }
173:
1.2 www 174: # -------------------------------------------------------- Generate Page Output
1.6 www 175: # --------------------------------------------------------------- Error Header?
1.2 www 176: if ($error) {
177: $r->print("<h1>LON-CAPA Access Control</h1>");
1.4 www 178: $r->print("<hr><pre>Access : ".
179: Apache::lonnet::plaintext($priv)."\n");
180: $r->print("Resource: $fn\n");
181: $r->print("Action : $msg\n</pre><hr>");
1.2 www 182: } else {
183: $r->print("<h1>LON-CAPA User Roles</h1>");
1.25 www 184: if ($ENV{'user.error.msg'}) {
185: $r->print(
186: '<h3><font color=red>You need to choose another user role or '.
187: 'enter a specific course for this function</font></h3>');
188: }
1.2 www 189: }
1.6 www 190: # -------------------------------------------------------- Choice or no choice?
1.2 www 191: if ($nochoose) {
1.6 www 192: if ($advanced) {
193: $r->print("<h2>Assigned User Roles</h2>\n");
194: } else {
195: $r->print("<h2>Sorry ...</h2>\nThis resource might be part of");
196: if ($ENV{'request.course.id'}) {
197: $r->print(' another');
198: } else {
199: $r->print(' a certain');
200: }
201: $r->print(' course.</body></html>');
202: return OK;
203: }
204: } else {
205: if ($advanced) {
206: $r->print("<h2>Select a User Role</h2>\n");
207: } else {
208: $r->print("<h2>Enter a Course</h2>\n");
1.17 www 209: }
1.18 www 210: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
211: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 212: }
1.11 www 213: $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
1.6 www 214: $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
215: $r->print('<input type=hidden name=selectrole value=1>');
216: }
1.27 www 217: $r->print('<br>Show all roles: <input type=checkbox name=showall');
218: if ($ENV{'form.showall'}) { $r->print(' checked'); }
219: $r->print('><input type=submit value="Display"><br>');
1.6 www 220: # ----------------------------------------------------------------------- Table
221: $r->print('<table><tr>');
222: unless ($nochoose) { $r->print('<th> </th>'); }
223: $r->print('<th>User Role</th><th colspan=2>Extent</th>'.
224: '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
1.4 www 225:
1.3 albertel 226: foreach $envkey (sort keys %ENV) {
1.2 www 227: if ($envkey=~/^user\.role\./) {
1.4 www 228: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
229: my $where=join('.',@pwhere);
1.6 www 230: my $trolecode=$role.'.'.$where;
1.4 www 231: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
232: my $tremark='';
233: my $tstatus='is';
234: my $tpstart=' ';
235: my $tpend=' ';
236: if ($tstart) {
237: if ($tstart>$then) {
238: $tstatus='future';
239: if ($tstart<$now) { $tstatus='will'; }
240: }
241: $tpstart=localtime($tstart);
242: }
243: if ($tend) {
1.23 www 244: if ($tend<$then) {
245: $tstatus='expired';
246: } elsif ($tend<$now) {
247: $tstatus='will_not';
248: }
1.4 www 249: $tpend=localtime($tend);
250: }
1.6 www 251: if ($ENV{'request.role'} eq $trolecode) {
252: $tstatus='selected';
253: }
1.4 www 254: my $tbg;
1.27 www 255: if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
256: ($ENV{'form.showall'})) {
1.4 www 257: if ($tstatus eq 'is') {
258: $tbg='#77FF77';
259: } elsif ($tstatus eq 'future') {
260: $tbg='#FFFF77';
261: } elsif ($tstatus eq 'will') {
262: $tbg='#FFAA77';
1.6 www 263: $tremark.='Active at next login. ';
1.4 www 264: } elsif ($tstatus eq 'expired') {
265: $tbg='#FF7777';
266: } elsif ($tstatus eq 'will_not') {
267: $tbg='#AAFF77';
1.6 www 268: $tremark.='Expired after logout. ';
269: } elsif ($tstatus eq 'selected') {
1.19 www 270: $tbg='#11CC55';
1.6 www 271: $tremark.='Currently selected. ';
1.4 www 272: }
273: my $trole;
274: if ($role =~ /^cr\//) {
275: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
276: $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
277: $trole=$rrole;
278: } else {
279: $trole=Apache::lonnet::plaintext($role);
280: }
281: my $ttype;
282: my $twhere;
1.13 www 283: my ($tdom,$trest,$tsection)=
1.8 www 284: split(/\//,Apache::lonnet::declutter($where));
1.6 www 285: if ($trest) {
1.24 www 286: if ($role eq 'ca') {
287: $ttype='Construction Space';
288: $twhere='User: '.$trest.'<br>Domain: '.$tdom;
289: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
290: } else {
1.4 www 291: $ttype='Course';
1.13 www 292: if ($tsection) {
293: $ttype.='<br>Section/Group: '.$tsection;
294: }
1.16 www 295: my $tcourseid=$tdom.'_'.$trest;
296: if ($ENV{'course.'.$tcourseid.'.description'}) {
297: $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.8 www 298: } else {
299: my %newhash=Apache::lonnet::coursedescription($tcourseid);
300: if (%newhash) {
301: $twhere=$newhash{'description'};
302: } else {
303: $twhere='Currently not available';
1.16 www 304: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.8 www 305: }
1.13 www 306: }
1.24 www 307: }
1.4 www 308: } elsif ($tdom) {
309: $ttype='Domain';
310: $twhere=$tdom;
311: } else {
312: $ttype='System';
1.8 www 313: $twhere='system wide';
1.4 www 314: }
315:
1.6 www 316: $r->print('<tr bgcolor='.$tbg.'>');
317: unless ($nochoose) {
318: if ($tstatus eq 'is') {
319: $r->print('<td><input type=submit value=Select name="'.
1.28 www 320: $trolecode.'"></td>');
321: } elsif ($ENV{'user.adv'}) {
322: $r->print(
323: '<td><input type=submit value="Re-Initialize" name="'.
1.6 www 324: $trolecode.'"></td>');
325: } else {
326: $r->print('<td> </td>');
327: }
328: }
329: $r->print('<td>'.$trole.'</td><td>'.
1.4 www 330: $ttype.'</td><td>'.$twhere.'</td><td>'.$tpstart.
331: '</td><td>'.$tpend.
332: '</td><td>'.$tremark.' </td></tr>'."\n");
1.27 www 333: }
1.4 www 334: }
335: }
1.14 www 336: my $tremark='';
337: if ($ENV{'request.role'} eq 'cm') {
1.19 www 338: $r->print('<tr bgcolor="#11CC55">');
1.14 www 339: $tremark='Currently selected.';
340: } else {
341: $r->print('<tr bgcolor="#77FF77">');
342: }
343: unless ($nochoose) {
344: if ($ENV{'request.role'} ne 'cm') {
345: $r->print('<td><input type=submit value=Select name="cm"></td>');
346: } else {
347: $r->print('<td> </td>');
348: }
349: }
350: $r->print('<td colspan=5>No role specified'.
351: '</td><td>'.$tremark.' </td></tr>'."\n");
1.4 www 352:
353: $r->print('</table>');
354: unless ($nochoose) {
355: $r->print("</form>\n");
356: }
1.22 harris41 357: # ------------------------------------------------------------ Privileges Info
1.6 www 358: if ($advanced) {
1.22 harris41 359: $r->print('<hr><h2>Current Privileges</h2>');
1.4 www 360:
361: foreach $envkey (sort keys %ENV) {
1.15 www 362: if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
363: my $where=$envkey;
364: $where=~s/^user\.priv\.$ENV{'request.role'}\.//;
1.4 www 365: my $ttype;
366: my $twhere;
1.15 www 367: my ($tdom,$trest,$tsec)=
1.8 www 368: split(/\//,Apache::lonnet::declutter($where));
1.6 www 369: if ($trest) {
1.24 www 370: if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
371: $ttype='Construction Space';
372: $twhere='User: '.$trest.', Domain: '.$tdom;
373: } else {
1.4 www 374: $ttype='Course';
1.16 www 375: $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
1.15 www 376: if ($tsec) {
377: $twhere.=' (Section/Group: '.$tsec.')';
378: }
1.24 www 379: }
1.4 www 380: } elsif ($tdom) {
381: $ttype='Domain';
382: $twhere=$tdom;
383: } else {
384: $ttype='System';
385: $twhere='/';
386: }
387: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
1.32 ! harris41 388: foreach (sort split(/:/,$ENV{$envkey})) {
1.4 www 389: if ($_) {
390: my ($prv,$restr)=split(/\&/,$_);
391: my $trestr='';
392: if ($restr ne 'F') {
393: my $i;
1.5 www 394: $trestr.=' (';
1.4 www 395: for ($i=0;$i<length($restr);$i++) {
1.5 www 396: $trestr.=
397: Apache::lonnet::plaintext(substr($restr,$i,1));
398: if ($i<length($restr)-1) { $trestr.=', '; }
399: }
400: $trestr.=')';
1.4 www 401: }
402: $r->print('<li>'.Apache::lonnet::plaintext($prv).$trestr.
403: '</li>');
404: }
1.32 ! harris41 405: }
1.4 www 406: $r->print('</ul>');
1.2 www 407: }
1.4 www 408: }
1.6 www 409: }
1.2 www 410:
1.1 harris41 411: $r->print("</body></html>\n");
412: return OK;
413: }
414:
415: 1;
416: __END__
1.32 ! harris41 417:
! 418: =head1 NAME
! 419:
! 420: Apache::lonroles - User Roles Screen
! 421:
! 422: =head1 SYNOPSIS
! 423:
! 424: Invoked by /etc/httpd/conf/srm.conf:
! 425:
! 426: <Location /adm/roles>
! 427: PerlAccessHandler Apache::lonacc
! 428: SetHandler perl-script
! 429: PerlHandler Apache::lonroles
! 430: ErrorDocument 403 /adm/login
! 431: ErrorDocument 500 /adm/errorhandler
! 432: </Location>
! 433:
! 434: =head1 INTRODUCTION
! 435:
! 436: This module enables a user to select what role he wishes to
! 437: operate under (instructor, student, teaching assistant, course
! 438: coordinator, etc). These roles are pre-established by the actions
! 439: of upper-level users.
! 440:
! 441: This is part of the LearningOnline Network with CAPA project
! 442: described at http://www.lon-capa.org.
! 443:
! 444: =head1 HANDLER SUBROUTINE
! 445:
! 446: This routine is called by Apache and mod_perl.
! 447:
! 448: =over 4
! 449:
! 450: =item *
! 451:
! 452: Roles Initialization (yes/no)
! 453:
! 454: =item *
! 455:
! 456: Get Error Message from Environment
! 457:
! 458: =item *
! 459:
! 460: Who is this?
! 461:
! 462: =item *
! 463:
! 464: Generate Page Output
! 465:
! 466: =item *
! 467:
! 468: Choice or no choice
! 469:
! 470: =item *
! 471:
! 472: Table
! 473:
! 474: =item *
! 475:
! 476: Privileges
! 477:
! 478: =back
! 479:
! 480: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>