File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.7: download - view: text, annotated - select for diffs
Sat Sep 30 17:25:04 2000 UTC (23 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
More steps towards making a course a user

    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,
    8: # 09/04,09/06,09/28,09/29,09/30 Gerd Kortemeyer
    9: #
   10: package Apache::lonroles;
   11: 
   12: use strict;
   13: use Apache::lonnet();
   14: use Apache::lonuserstate();
   15: use Apache::Constants qw(:common);
   16: use Apache::File();
   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: 
   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);
   59:                    my ($cdom,$cnum)=split(/\//,$where);
   60:                    if ($cnum) {
   61: 		      $r->print( &Apache::lonuserstate::readmap($where) );
   62:                    }
   63:                }
   64:             } 
   65: 	  }
   66:         }
   67:         
   68:         $r->print('<h1>Role not active</h1></body></html>');
   69: 	return OK;
   70:     }
   71: # =============================================================== No Roles Init
   72: 
   73: # ------------------------------------------ Get Error Message from Environment
   74: 
   75:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
   76:     $r->log_reason(
   77:  "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
   78: 
   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: 
   89: # -------------------------------------------------------- Generate Page Output
   90: # --------------------------------------------------------------- Error Header?
   91:     if ($error) {
   92: 	$r->print("<h1>LON-CAPA Access Control</h1>");
   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>");
   97:     } else {
   98:         $r->print("<h1>LON-CAPA User Roles</h1>");
   99:     }
  100: # -------------------------------------------------------- Choice or no choice?
  101:     if ($nochoose) {
  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>&nbsp;</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");
  130:     } else {
  131: 	$r->print('<th>Course</th></tr>'."\n");
  132:     }
  133: 
  134:     foreach $envkey (sort keys %ENV) {
  135:         if ($envkey=~/^user\.role\./) {
  136: 	    my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
  137:             my $where=join('.',@pwhere);
  138:             my $trolecode=$role.'.'.$where;
  139:             my ($tstart,$tend)=split(/\./,$ENV{$envkey});
  140:             my $tremark='';
  141:             my $tstatus='is';
  142:             my $tpstart='&nbsp;';
  143:             my $tpend='&nbsp;';
  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:             }
  156:             if ($ENV{'request.role'} eq $trolecode) {
  157: 		$tstatus='selected';
  158:             }
  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';
  166:                 $tremark.='Active at next login. ';
  167:             } elsif ($tstatus eq 'expired') {
  168:                 $tbg='#FF7777';
  169: 	    } elsif ($tstatus eq 'will_not') {
  170:                 $tbg='#AAFF77';
  171:                 $tremark.='Expired after logout. ';
  172:             } elsif ($tstatus eq 'selected') {
  173:                 $tbg='#33FF33';
  174:                 $tremark.='Currently selected. ';
  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;
  186:             my ($tres,$tdom,$trest)=split(/\//,$where);
  187:             if ($trest) {
  188: 		$ttype='Course';
  189:                 $twhere=$tdom.'/'.$trest;
  190:             } elsif ($tdom) {
  191:                 $ttype='Domain';
  192:                 $twhere=$tdom;
  193:             } else {
  194:                 $ttype='System';
  195:                 $twhere='/';
  196:             }
  197:                
  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>&nbsp;</td>');
  205:                 }
  206:             }
  207:             $r->print('<td>'.$trole.'</td><td>'.
  208: 		      $ttype.'</td><td>'.$twhere.'</td><td>'.$tpstart.
  209:                       '</td><td>'.$tpend.
  210:                       '</td><td>'.$tremark.'&nbsp;</td></tr>'."\n");
  211:         }
  212:     }
  213: 
  214:     $r->print('</table>');
  215:     unless ($nochoose) {
  216: 	$r->print("</form>\n");
  217:     }
  218: # ------------------------------------------------------------ Priviledges Info
  219:   if ($advanced) {
  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;
  228:             my ($tres,$tdom,$trest)=split(/\//,$where);
  229:             if ($trest) {
  230: 		$ttype='Course';
  231:                 $twhere=$tdom.'/'.$trest;
  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;
  246:                       $trestr.=' (';
  247:                       for ($i=0;$i<length($restr);$i++) {
  248: 		         $trestr.=
  249:                            Apache::lonnet::plaintext(substr($restr,$i,1));
  250:                          if ($i<length($restr)-1) { $trestr.=', '; }
  251: 		      }
  252:                       $trestr.=')';
  253:                   }
  254:                   $r->print('<li>'.Apache::lonnet::plaintext($prv).$trestr.
  255:                             '</li>');
  256: 	      }
  257:             } sort split(/:/,$ENV{$envkey});
  258:             $r->print('</ul>');
  259:         }
  260:     }
  261:   }
  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>");
  268:     }
  269: 
  270: # ------------------------------------------------------------------- End Debug
  271: 
  272:     $r->print("</body></html>\n");
  273:     return OK;
  274: } 
  275: 
  276: 1;
  277: __END__

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