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