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