File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.19: download - view: text, annotated - select for diffs
Thu Dec 28 21:46:08 2000 UTC (23 years, 5 months ago) by www
Branches: MAIN
CVS tags: HEAD
Small bug fixes, and jump to first URL

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

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