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