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