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