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