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