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