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