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