Annotation of loncom/auth/lonroles.pm, revision 1.31
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 ! www 3: #
! 4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
! 5: #
! 6: # Copyright Michigan State University Board of Trustees
! 7: #
! 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 9: #
! 10: # LON-CAPA is free software; you can redistribute it and/or modify
! 11: # it under the terms of the GNU General Public License as published by
! 12: # the Free Software Foundation; either version 2 of the License, or
! 13: # (at your option) any later version.
! 14: #
! 15: # LON-CAPA is distributed in the hope that it will be useful,
! 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 18: # GNU General Public License for more details.
! 19: #
! 20: # You should have received a copy of the GNU General Public License
! 21: # along with LON-CAPA; if not, write to the Free Software
! 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 23: #
! 24: # /home/httpd/html/adm/gpl.txt
! 25: #
! 26: # http://www.lon-capa.org/
! 27: #
1.1 harris41 28: # (Directory Indexer
29: # (Login Screen
30: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
31: # 11/23 Gerd Kortemeyer)
1.7 www 32: # 1/14,03/06,06/01,07/22,07/24,07/25,
1.19 www 33: # 09/04,09/06,09/28,09/29,09/30,10/2,10/5,10/26,10/28,
1.20 www 34: # 12/08,12/28,
35: # 01/15/01 Gerd Kortemeyer
1.22 harris41 36: # 02/27/01 Scott Harrison
1.28 www 37: # 03/02,05/03,05/25,05/30,06/01,07/06,08/06 Gerd Kortemeyer
1.22 harris41 38:
1.1 harris41 39: package Apache::lonroles;
40:
41: use strict;
42: use Apache::lonnet();
1.7 www 43: use Apache::lonuserstate();
1.1 harris41 44: use Apache::Constants qw(:common);
1.2 www 45: use Apache::File();
1.26 www 46: use Apache::lonmenu;
1.29 albertel 47: use Apache::loncommon;
1.1 harris41 48:
49: sub handler {
1.10 www 50:
1.1 harris41 51: my $r = shift;
52:
1.6 www 53: my $now=time;
54: my $then=$ENV{'user.login.time'};
55: my $envkey;
56:
1.10 www 57:
1.6 www 58: # ================================================================== Roles Init
59:
60: if ($ENV{'form.selectrole'}) {
1.13 www 61: &Apache::lonnet::appenv("request.course.id" => '',
62: "request.course.fn" => '',
63: "request.course.uri" => '',
64: "request.course.sec" => '',
65: "request.role" => 'cm');
66: foreach $envkey (keys %ENV) {
67: if ($envkey=~/^user\.role\./) {
1.6 www 68: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
69: my $where=join('.',@pwhere);
70: my $trolecode=$role.'.'.$where;
71: if ($ENV{'form.'.$trolecode}) {
72: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
73: my $tstatus='is';
74: if ($tstart) {
75: if ($tstart>$then) {
76: $tstatus='future';
77: }
78: }
79: if ($tend) {
80: if ($tend<$then) { $tstatus='expired'; }
1.19 www 81: if ($tend<$now) { $tstatus='will_not'; }
1.6 www 82: }
83: if ($tstatus eq 'is') {
1.13 www 84: $where=~s/^\///;
85: my ($cdom,$cnum,$csec)=split(/\//,$where);
86: &Apache::lonnet::appenv('request.role' => $trolecode,
1.14 www 87: 'request.course.sec' => $csec);
1.27 www 88: my $msg='Entering course ...';
1.25 www 89: if (($cnum) && ($role ne 'ca')) {
1.19 www 90: my ($furl,$ferr)=
91: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.20 www 92: if (($ENV{'form.orgurl'}) &&
93: ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
1.11 www 94: $r->internal_redirect($ENV{'form.orgurl'});
95: return OK;
1.19 www 96: } else {
1.27 www 97: unless ($ENV{'request.course.id'}) {
98: &Apache::lonnet::appenv(
99: "request.course.id" => $cdom.'_'.$cnum);
100: $furl='/adm/notfound.html';
101: $msg=
102: '<h1><font color=red>Could not initialize top-level map.</font></h1>';
103: }
1.20 www 104: $r->content_type('text/html');
1.30 albertel 105: &Apache::loncommon::no_cache($r);
1.20 www 106: $r->send_http_header;
1.26 www 107: my $swinfo=&Apache::lonmenu::rawconfig;
1.20 www 108: print (<<ENDREDIR);
109: <head><title>Entering Course</title>
110: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$furl">
111: </head>
112: <html>
113: <body bgcolor="#FFFFFF">
1.26 www 114: <script>
115: $swinfo
116: </script>
1.27 www 117: $msg
1.20 www 118: </body>
119: </html>
120: ENDREDIR
121: return OK;
1.19 www 122: }
1.7 www 123: }
1.6 www 124: }
125: }
126: }
127: }
1.20 www 128: }
1.6 www 129:
1.10 www 130:
1.6 www 131: # =============================================================== No Roles Init
1.10 www 132:
133: $r->content_type('text/html');
1.30 albertel 134: &Apache::loncommon::no_cache($r);
1.10 www 135: $r->send_http_header;
136: return OK if $r->header_only;
137:
1.26 www 138: my $swinfo=&Apache::lonmenu::rawconfig;
1.10 www 139: $r->print(<<ENDHEADER);
140: <html>
141: <head>
142: <title>LON-CAPA User Roles</title>
143: </head><body bgcolor="#FFFFFF">
1.26 www 144: <script>
145: $swinfo
146: window.focus();
147: </script>
1.10 www 148: ENDHEADER
1.6 www 149:
1.2 www 150: # ------------------------------------------ Get Error Message from Environment
151:
152: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12 www 153: if ($ENV{'user.error.msg'}) {
154: $r->log_reason(
155: "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
156: }
1.1 harris41 157:
1.6 www 158: # ---------------------------------------------------------------- Who is this?
159:
160: my $advanced=0;
161: foreach $envkey (keys %ENV) {
162: if ($envkey=~/^user\.role\./) {
163: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
164: if ($role ne 'st') { $advanced=1; }
165: }
166: }
167:
1.2 www 168: # -------------------------------------------------------- Generate Page Output
1.6 www 169: # --------------------------------------------------------------- Error Header?
1.2 www 170: if ($error) {
171: $r->print("<h1>LON-CAPA Access Control</h1>");
1.4 www 172: $r->print("<hr><pre>Access : ".
173: Apache::lonnet::plaintext($priv)."\n");
174: $r->print("Resource: $fn\n");
175: $r->print("Action : $msg\n</pre><hr>");
1.2 www 176: } else {
177: $r->print("<h1>LON-CAPA User Roles</h1>");
1.25 www 178: if ($ENV{'user.error.msg'}) {
179: $r->print(
180: '<h3><font color=red>You need to choose another user role or '.
181: 'enter a specific course for this function</font></h3>');
182: }
1.2 www 183: }
1.6 www 184: # -------------------------------------------------------- Choice or no choice?
1.2 www 185: if ($nochoose) {
1.6 www 186: if ($advanced) {
187: $r->print("<h2>Assigned User Roles</h2>\n");
188: } else {
189: $r->print("<h2>Sorry ...</h2>\nThis resource might be part of");
190: if ($ENV{'request.course.id'}) {
191: $r->print(' another');
192: } else {
193: $r->print(' a certain');
194: }
195: $r->print(' course.</body></html>');
196: return OK;
197: }
198: } else {
199: if ($advanced) {
200: $r->print("<h2>Select a User Role</h2>\n");
201: } else {
202: $r->print("<h2>Enter a Course</h2>\n");
1.17 www 203: }
1.18 www 204: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
205: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 206: }
1.11 www 207: $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
1.6 www 208: $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
209: $r->print('<input type=hidden name=selectrole value=1>');
210: }
1.27 www 211: $r->print('<br>Show all roles: <input type=checkbox name=showall');
212: if ($ENV{'form.showall'}) { $r->print(' checked'); }
213: $r->print('><input type=submit value="Display"><br>');
1.6 www 214: # ----------------------------------------------------------------------- Table
215: $r->print('<table><tr>');
216: unless ($nochoose) { $r->print('<th> </th>'); }
217: $r->print('<th>User Role</th><th colspan=2>Extent</th>'.
218: '<th>Start</th><th>End</th><th>Remark</th></tr>'."\n");
1.4 www 219:
1.3 albertel 220: foreach $envkey (sort keys %ENV) {
1.2 www 221: if ($envkey=~/^user\.role\./) {
1.4 www 222: my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
223: my $where=join('.',@pwhere);
1.6 www 224: my $trolecode=$role.'.'.$where;
1.4 www 225: my ($tstart,$tend)=split(/\./,$ENV{$envkey});
226: my $tremark='';
227: my $tstatus='is';
228: my $tpstart=' ';
229: my $tpend=' ';
230: if ($tstart) {
231: if ($tstart>$then) {
232: $tstatus='future';
233: if ($tstart<$now) { $tstatus='will'; }
234: }
235: $tpstart=localtime($tstart);
236: }
237: if ($tend) {
1.23 www 238: if ($tend<$then) {
239: $tstatus='expired';
240: } elsif ($tend<$now) {
241: $tstatus='will_not';
242: }
1.4 www 243: $tpend=localtime($tend);
244: }
1.6 www 245: if ($ENV{'request.role'} eq $trolecode) {
246: $tstatus='selected';
247: }
1.4 www 248: my $tbg;
1.27 www 249: if (($tstatus eq 'is') || ($tstatus eq 'selected') ||
250: ($ENV{'form.showall'})) {
1.4 www 251: if ($tstatus eq 'is') {
252: $tbg='#77FF77';
253: } elsif ($tstatus eq 'future') {
254: $tbg='#FFFF77';
255: } elsif ($tstatus eq 'will') {
256: $tbg='#FFAA77';
1.6 www 257: $tremark.='Active at next login. ';
1.4 www 258: } elsif ($tstatus eq 'expired') {
259: $tbg='#FF7777';
260: } elsif ($tstatus eq 'will_not') {
261: $tbg='#AAFF77';
1.6 www 262: $tremark.='Expired after logout. ';
263: } elsif ($tstatus eq 'selected') {
1.19 www 264: $tbg='#11CC55';
1.6 www 265: $tremark.='Currently selected. ';
1.4 www 266: }
267: my $trole;
268: if ($role =~ /^cr\//) {
269: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
270: $tremark.='<br>Defined by '.$rauthor.' at '.$rdomain.'.';
271: $trole=$rrole;
272: } else {
273: $trole=Apache::lonnet::plaintext($role);
274: }
275: my $ttype;
276: my $twhere;
1.13 www 277: my ($tdom,$trest,$tsection)=
1.8 www 278: split(/\//,Apache::lonnet::declutter($where));
1.6 www 279: if ($trest) {
1.24 www 280: if ($role eq 'ca') {
281: $ttype='Construction Space';
282: $twhere='User: '.$trest.'<br>Domain: '.$tdom;
283: $ENV{'course.'.$tdom.'_'.$trest.'.description'}='ca';
284: } else {
1.4 www 285: $ttype='Course';
1.13 www 286: if ($tsection) {
287: $ttype.='<br>Section/Group: '.$tsection;
288: }
1.16 www 289: my $tcourseid=$tdom.'_'.$trest;
290: if ($ENV{'course.'.$tcourseid.'.description'}) {
291: $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.8 www 292: } else {
293: my %newhash=Apache::lonnet::coursedescription($tcourseid);
294: if (%newhash) {
295: $twhere=$newhash{'description'};
296: } else {
297: $twhere='Currently not available';
1.16 www 298: $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.8 www 299: }
1.13 www 300: }
1.24 www 301: }
1.4 www 302: } elsif ($tdom) {
303: $ttype='Domain';
304: $twhere=$tdom;
305: } else {
306: $ttype='System';
1.8 www 307: $twhere='system wide';
1.4 www 308: }
309:
1.6 www 310: $r->print('<tr bgcolor='.$tbg.'>');
311: unless ($nochoose) {
312: if ($tstatus eq 'is') {
313: $r->print('<td><input type=submit value=Select name="'.
1.28 www 314: $trolecode.'"></td>');
315: } elsif ($ENV{'user.adv'}) {
316: $r->print(
317: '<td><input type=submit value="Re-Initialize" name="'.
1.6 www 318: $trolecode.'"></td>');
319: } else {
320: $r->print('<td> </td>');
321: }
322: }
323: $r->print('<td>'.$trole.'</td><td>'.
1.4 www 324: $ttype.'</td><td>'.$twhere.'</td><td>'.$tpstart.
325: '</td><td>'.$tpend.
326: '</td><td>'.$tremark.' </td></tr>'."\n");
1.27 www 327: }
1.4 www 328: }
329: }
1.14 www 330: my $tremark='';
331: if ($ENV{'request.role'} eq 'cm') {
1.19 www 332: $r->print('<tr bgcolor="#11CC55">');
1.14 www 333: $tremark='Currently selected.';
334: } else {
335: $r->print('<tr bgcolor="#77FF77">');
336: }
337: unless ($nochoose) {
338: if ($ENV{'request.role'} ne 'cm') {
339: $r->print('<td><input type=submit value=Select name="cm"></td>');
340: } else {
341: $r->print('<td> </td>');
342: }
343: }
344: $r->print('<td colspan=5>No role specified'.
345: '</td><td>'.$tremark.' </td></tr>'."\n");
1.4 www 346:
347: $r->print('</table>');
348: unless ($nochoose) {
349: $r->print("</form>\n");
350: }
1.22 harris41 351: # ------------------------------------------------------------ Privileges Info
1.6 www 352: if ($advanced) {
1.22 harris41 353: $r->print('<hr><h2>Current Privileges</h2>');
1.4 www 354:
355: foreach $envkey (sort keys %ENV) {
1.15 www 356: if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
357: my $where=$envkey;
358: $where=~s/^user\.priv\.$ENV{'request.role'}\.//;
1.4 www 359: my $ttype;
360: my $twhere;
1.15 www 361: my ($tdom,$trest,$tsec)=
1.8 www 362: split(/\//,Apache::lonnet::declutter($where));
1.6 www 363: if ($trest) {
1.24 www 364: if ($ENV{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
365: $ttype='Construction Space';
366: $twhere='User: '.$trest.', Domain: '.$tdom;
367: } else {
1.4 www 368: $ttype='Course';
1.16 www 369: $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
1.15 www 370: if ($tsec) {
371: $twhere.=' (Section/Group: '.$tsec.')';
372: }
1.24 www 373: }
1.4 www 374: } elsif ($tdom) {
375: $ttype='Domain';
376: $twhere=$tdom;
377: } else {
378: $ttype='System';
379: $twhere='/';
380: }
381: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
382: map {
383: if ($_) {
384: my ($prv,$restr)=split(/\&/,$_);
385: my $trestr='';
386: if ($restr ne 'F') {
387: my $i;
1.5 www 388: $trestr.=' (';
1.4 www 389: for ($i=0;$i<length($restr);$i++) {
1.5 www 390: $trestr.=
391: Apache::lonnet::plaintext(substr($restr,$i,1));
392: if ($i<length($restr)-1) { $trestr.=', '; }
393: }
394: $trestr.=')';
1.4 www 395: }
396: $r->print('<li>'.Apache::lonnet::plaintext($prv).$trestr.
397: '</li>');
398: }
399: } sort split(/:/,$ENV{$envkey});
400: $r->print('</ul>');
1.2 www 401: }
1.4 www 402: }
1.6 www 403: }
1.2 www 404:
1.1 harris41 405: $r->print("</body></html>\n");
406: return OK;
407: }
408:
409: 1;
410: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>