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