File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.6: download - view: text, annotated - select for diffs
Fri Sep 29 14:36:30 2000 UTC (23 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Steps towards treating a course as a user rather than a resource

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>