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