File:  [LON-CAPA] / loncom / auth / lonroles.pm
Revision 1.20: download - view: text, annotated - select for diffs
Mon Jan 15 15:59:52 2001 UTC (23 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Avoid "non acceptable non acceptable" error (error doc on error doc)

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

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