Annotation of loncom/auth/lonroles.pm, revision 1.20

1.1       harris41    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)
1.7       www         7: # 1/14,03/06,06/01,07/22,07/24,07/25,
1.19      www         8: # 09/04,09/06,09/28,09/29,09/30,10/2,10/5,10/26,10/28,
1.20    ! www         9: # 12/08,12/28,
        !            10: # 01/15/01 Gerd Kortemeyer
1.1       harris41   11: #
                     12: package Apache::lonroles;
                     13: 
                     14: use strict;
                     15: use Apache::lonnet();
1.7       www        16: use Apache::lonuserstate();
1.1       harris41   17: use Apache::Constants qw(:common);
1.2       www        18: use Apache::File();
1.1       harris41   19: 
                     20: sub handler {
1.10      www        21: 
1.1       harris41   22:     my $r = shift;
                     23: 
1.6       www        24:     my $now=time;
                     25:     my $then=$ENV{'user.login.time'};
                     26:     my $envkey;
                     27: 
1.10      www        28: 
1.6       www        29: # ================================================================== Roles Init
                     30: 
                     31:     if ($ENV{'form.selectrole'}) {
1.13      www        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\./) {
1.6       www        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'; }
1.19      www        52:                   if ($tend<$now) { $tstatus='will_not'; }
1.6       www        53:                }
                     54:                if ($tstatus eq 'is') {
1.13      www        55:                    $where=~s/^\///;
                     56:                    my ($cdom,$cnum,$csec)=split(/\//,$where);
                     57:                    &Apache::lonnet::appenv('request.role' => $trolecode,
1.14      www        58:                                            'request.course.sec' => $csec);
1.7       www        59:                    if ($cnum) {
1.19      www        60: 		      my ($furl,$ferr)=
                     61: 			  &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.20    ! www        62:                       if (($ENV{'form.orgurl'}) && 
        !            63:                           ($ENV{'form.orgurl'}!~/^\/adm\/flip/)) {
1.11      www        64:                          $r->internal_redirect($ENV{'form.orgurl'});
                     65:                          return OK;
1.19      www        66: 		     } else {
1.20    ! www        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;
1.19      www        80:                      }
1.7       www        81:                    }
1.6       www        82:                }
                     83:             } 
                     84: 	  }
                     85:         }
1.20    ! www        86:    }
1.6       www        87:         
1.10      www        88: 
1.6       www        89: # =============================================================== No Roles Init
1.10      www        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
1.6       www       101: 
1.2       www       102: # ------------------------------------------ Get Error Message from Environment
                    103: 
                    104:     my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$ENV{'user.error.msg'});
1.12      www       105:     if ($ENV{'user.error.msg'}) {
                    106:        $r->log_reason(
                    107:      "$msg for $ENV{'user.name'} domain $ENV{'user.domain'} access $priv",$fn);
                    108:     }
1.1       harris41  109: 
1.6       www       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: 
1.2       www       120: # -------------------------------------------------------- Generate Page Output
1.6       www       121: # --------------------------------------------------------------- Error Header?
1.2       www       122:     if ($error) {
                    123: 	$r->print("<h1>LON-CAPA Access Control</h1>");
1.4       www       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>");
1.2       www       128:     } else {
                    129:         $r->print("<h1>LON-CAPA User Roles</h1>");
                    130:     }
1.6       www       131: # -------------------------------------------------------- Choice or no choice?
1.2       www       132:     if ($nochoose) {
1.6       www       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");
1.17      www       150:         }
1.18      www       151:         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
                    152:     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6       www       153:         }
1.11      www       154:         $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
1.6       www       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");
1.4       www       163: 
1.3       albertel  164:     foreach $envkey (sort keys %ENV) {
1.2       www       165:         if ($envkey=~/^user\.role\./) {
1.4       www       166: 	    my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
                    167:             my $where=join('.',@pwhere);
1.6       www       168:             my $trolecode=$role.'.'.$where;
1.4       www       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'; }
1.19      www       183:                 if ($tend<$now) { $tstatus='will_not'; }
1.4       www       184:                 $tpend=localtime($tend);
                    185:             }
1.6       www       186:             if ($ENV{'request.role'} eq $trolecode) {
                    187: 		$tstatus='selected';
                    188:             }
1.4       www       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';
1.6       www       196:                 $tremark.='Active at next login. ';
1.4       www       197:             } elsif ($tstatus eq 'expired') {
                    198:                 $tbg='#FF7777';
                    199: 	    } elsif ($tstatus eq 'will_not') {
                    200:                 $tbg='#AAFF77';
1.6       www       201:                 $tremark.='Expired after logout. ';
                    202:             } elsif ($tstatus eq 'selected') {
1.19      www       203:                 $tbg='#11CC55';
1.6       www       204:                 $tremark.='Currently selected. ';
1.4       www       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;
1.13      www       216:             my ($tdom,$trest,$tsection)=
1.8       www       217:                split(/\//,Apache::lonnet::declutter($where));
1.6       www       218:             if ($trest) {
1.4       www       219: 		$ttype='Course';
1.13      www       220:                 if ($tsection) {
                    221:                    $ttype.='<br>Section/Group: '.$tsection;
                    222:                 }     
1.16      www       223:                 my $tcourseid=$tdom.'_'.$trest;
                    224:                 if ($ENV{'course.'.$tcourseid.'.description'}) {
                    225: 		    $twhere=$ENV{'course.'.$tcourseid.'.description'};
1.8       www       226:                 } else {
                    227:                     my %newhash=Apache::lonnet::coursedescription($tcourseid);
                    228:                     if (%newhash) {
                    229: 			$twhere=$newhash{'description'};
                    230:                     } else {
                    231:                         $twhere='Currently not available';
1.16      www       232:                         $ENV{'course.'.$tcourseid.'.description'}=$twhere;
1.8       www       233:                     }
1.13      www       234:                 }
1.4       www       235:             } elsif ($tdom) {
                    236:                 $ttype='Domain';
                    237:                 $twhere=$tdom;
                    238:             } else {
                    239:                 $ttype='System';
1.8       www       240:                 $twhere='system wide';
1.4       www       241:             }
                    242:                
1.6       www       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>'.
1.4       www       253: 		      $ttype.'</td><td>'.$twhere.'</td><td>'.$tpstart.
                    254:                       '</td><td>'.$tpend.
                    255:                       '</td><td>'.$tremark.'&nbsp;</td></tr>'."\n");
                    256:         }
                    257:     }
1.14      www       258:     my $tremark='';
                    259:     if ($ENV{'request.role'} eq 'cm') {
1.19      www       260: 	$r->print('<tr bgcolor="#11CC55">');
1.14      www       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");
1.4       www       274: 
                    275:     $r->print('</table>');
                    276:     unless ($nochoose) {
                    277: 	$r->print("</form>\n");
                    278:     }
1.6       www       279: # ------------------------------------------------------------ Priviledges Info
                    280:   if ($advanced) {
1.15      www       281:     $r->print('<hr><h2>Current Priviledges</h2>');
1.4       www       282: 
                    283:     foreach $envkey (sort keys %ENV) {
1.15      www       284:         if ($envkey=~/^user\.priv\.$ENV{'request.role'}\./) {
                    285:             my $where=$envkey;
                    286:             $where=~s/^user\.priv\.$ENV{'request.role'}\.//;
1.4       www       287:             my $ttype;
                    288:             my $twhere;
1.15      www       289:             my ($tdom,$trest,$tsec)=
1.8       www       290:                split(/\//,Apache::lonnet::declutter($where));
1.6       www       291:             if ($trest) {
1.4       www       292: 		$ttype='Course';
1.16      www       293:                 $twhere=$ENV{'course.'.$tdom.'_'.$trest.'.description'};
1.15      www       294:                 if ($tsec) {
                    295: 		    $twhere.=' (Section/Group: '.$tsec.')';
                    296:                 }
1.4       www       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;
1.5       www       311:                       $trestr.=' (';
1.4       www       312:                       for ($i=0;$i<length($restr);$i++) {
1.5       www       313: 		         $trestr.=
                    314:                            Apache::lonnet::plaintext(substr($restr,$i,1));
                    315:                          if ($i<length($restr)-1) { $trestr.=', '; }
                    316: 		      }
                    317:                       $trestr.=')';
1.4       www       318:                   }
                    319:                   $r->print('<li>'.Apache::lonnet::plaintext($prv).$trestr.
                    320:                             '</li>');
                    321: 	      }
                    322:             } sort split(/:/,$ENV{$envkey});
                    323:             $r->print('</ul>');
1.2       www       324:         }
1.4       www       325:     }
1.6       www       326:   }
1.2       www       327: 
1.1       harris41  328:     $r->print("</body></html>\n");
                    329:     return OK;
                    330: } 
                    331: 
                    332: 1;
                    333: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.