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