Annotation of rat/lonambiguous.pm, revision 1.13

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to resolve ambiguous file locations
                      3: #
1.12      albertel    4: # $Id: lonambiguous.pm,v 1.11 2004/12/17 22:40:24 albertel Exp $
1.4       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       www        28: # (TeX Content Handler
                     29: #
                     30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
                     31: #
1.3       www        32: # 10/11,10/12,10/16 Gerd Kortemeyer
1.1       www        33: 
                     34: package Apache::lonambiguous;
                     35: 
                     36: use strict;
                     37: use Apache::lonnet;
                     38: use Apache::Constants qw(:common REDIRECT);
                     39: use GDBM_File;
1.9       www        40: use Apache::loncommon;
1.10      www        41: use Apache::lonlocal;
1.1       www        42: 
1.8       www        43: my %bighash;
                     44: 
                     45: sub cleanup {
                     46:     if (tied(%bighash)){
                     47: 	&Apache::lonnet::logthis('Cleanup ambiguous: bighash');
                     48:         unless (untie(%bighash)) {
                     49: 	    &Apache::lonnet::logthis('Failed cleanup ambiguous: bighash');
                     50:         }
                     51:     }
                     52: }
1.1       www        53: 
                     54: # ----------------------------------------------------------- Could not resolve
                     55: 
                     56: sub getlost {
1.2       www        57:     my ($r,$errmsg)=@_;
1.10      www        58:     $errmsg=&mt($errmsg);
1.1       www        59:     $r->content_type('text/html');
                     60:     $r->send_http_header;
1.2       www        61:     $r->print(
1.9       www        62:  '<head><title>Unknown Error</title></head>'.
                     63:   &Apache::loncommon::bodytag('Could not handle ambiguous resource reference').
                     64:   $errmsg.
1.2       www        65:  '</body></html>');
1.1       www        66: }
                     67: 
                     68: # ================================================================ Main Handler
                     69: 
1.11      albertel   70: sub make_symb {
                     71:     my ($id)=@_;
                     72:     my ($mapid,$resid)=split(/\./,$id);
                     73:     my $map=$bighash{'map_id_'.$mapid};
                     74:     my $res=$bighash{'src_'.$id};
                     75:     my $symb=&Apache::lonnet::encode_symb($map,$resid,$res);
                     76:     return $symb;
                     77: }
                     78: 
1.1       www        79: sub handler {
                     80:    my $r=shift;
                     81: 
                     82:    if ($r->header_only) {
1.10      www        83:       &Apache::loncommon::content_type($r,'text/html');
1.1       www        84:       $r->send_http_header;
                     85:       return OK;
                     86:    }
                     87: 
1.2       www        88: # ---------------------------------------------------------- Is this selecting?
1.8       www        89:  
1.2       www        90:    if ($ENV{'form.selecturl'}) {
                     91:        my $envkey;
                     92:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
1.5       albertel   93:                     &GDBM_READER(),0640)) {
1.2       www        94:           foreach $envkey (keys %ENV) {
                     95:              if ($envkey=~/^form\.(\d+)\.(\d+)$/) {
1.3       www        96: # ---------------------------------------------------- Update symb and redirect
1.2       www        97: 	         my $mapid=$1;
                     98:                  my $resid=$2;
                     99:                  my $resurl=$bighash{'src_'.$mapid.'.'.$resid};
                    100:                  &Apache::lonnet::symblist($bighash{'map_id_'.$mapid},
                    101: 				           $resurl => $resid);
1.3       www       102:                  untie(%bighash);
1.2       www       103:                  $r->header_out(Location => 
                    104:                                 'http://'.$ENV{'HTTP_HOST'}.$resurl);
                    105:                  return REDIRECT;
                    106:              }
                    107: 	  }
                    108:           untie(%bighash);
                    109:        } else {
                    110:           &getlost($r,'Could not access course structure.');
                    111:           return OK;
                    112:        }
                    113:    }
                    114: 
1.1       www       115: # ---------------------------------------------------------- Do we have a case?
                    116: 
                    117:    my $thisfn;
                    118:    unless (($thisfn=$ENV{'request.ambiguous'})&&($ENV{'request.course.fn'})) {
1.2       www       119:        &getlost($r,'Could not find information on resource.');
1.1       www       120:        return OK;
                    121:    }
                    122:       
                    123: # ---------------------------------- Should this file have been part of a page?
                    124: 
                    125:     $thisfn=&Apache::lonnet::declutter($thisfn);
                    126:     my %hash;
                    127:     my $syval='';
                    128:     
                    129:     if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
1.5       albertel  130:                   &GDBM_READER(),0640)) {
1.1       www       131:        $syval=$hash{$thisfn};
                    132:        untie(%hash);
                    133:     }
1.2       www       134: 
1.1       www       135: # ---------------------------------------------------------- There was an entry
1.2       www       136: 
1.1       www       137:     if ($syval) {
1.2       www       138: 
1.1       www       139:        if ($syval=~/\_$/) {
                    140: # ----------------------------------- Okay, this should have appeared on a page
                    141: 	   $syval=~s/\_\_\_$//;
                    142:  	   $r->content_type('text/html');
                    143:            $r->header_out(Location => 
                    144:                 'http://'.$ENV{'HTTP_HOST'}.'/res/'.$syval);
                    145:            return REDIRECT;
                    146:        } else {
                    147: #  There is not really a problem (???), but cannot go back without endless loop
1.2       www       148:            &getlost($r,'The nature of the problem is unclear');
1.1       www       149:            return OK;
                    150:        }
                    151:     }
1.13    ! albertel  152: # ------------------------------------Encrypted requests go straight to navmaps
        !           153:    if ($ENV{'request.enc'}) {
        !           154:        $r->content_type('text/html');
        !           155:        $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.'/adm/navmaps');
        !           156:        return REDIRECT;
        !           157:    }
1.1       www       158: # ------------------------------------------------ Would be standalone resource
                    159: 
                    160:    if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
1.5       albertel  161:                     &GDBM_READER(),0640)) {
1.1       www       162: # ---------------------------------------------- Get ID(s) for current resource
1.7       albertel  163:       my $ids=$bighash{'ids_'.&Apache::lonnet::clutter($thisfn)};
1.1       www       164:       if ($ids) {
                    165: # ------------------------------------------------------------------- Has ID(s)
                    166:          my @possibilities=split(/\,/,$ids);
                    167:          my $couldbe='';
1.11      albertel  168:          foreach (@possibilities) {
                    169:              if ($bighash{'encrypted_'.$_}) { next; }
                    170: 	     my $symb=&make_symb($_);
                    171:              if (&Apache::lonnet::allowed('bre',$bighash{'src_'.$_},$symb)) {
1.1       www       172: 	         if ($couldbe) {
                    173: 		     $couldbe.=','.$_;
                    174:                  } else {
                    175:                      $couldbe=$_;
                    176:                  }
                    177:              }
1.11      albertel  178: 	 }
1.1       www       179:          if ($couldbe) {
                    180:             @possibilities=split(/\,/,$couldbe);
1.12      albertel  181: 	    if ($#possibilities==0) {
                    182: 		my $id=$possibilities[0];
                    183: 		my $resurl=$bighash{'src_'.$id};
                    184: 		my $mapurl=$bighash{'map_id_'.(split(/\./,$id))[0]};
                    185: 		my $symb=&make_symb($id);
                    186: 		$r->content_type('text/html');
                    187: 		&Apache::lonnet::logthis('http://'.$ENV{'HTTP_HOST'}.$resurl.'?symb='.$symb);
                    188: 		$r->header_out(Location => 
                    189: 			   'http://'.$ENV{'HTTP_HOST'}.$resurl.'?symb='.$symb);
                    190: 		return REDIRECT;
                    191: 	    }
1.1       www       192:             if ($#possibilities>0) {
                    193: # ----------------------------------------------- Okay, really multiple choices
                    194:                $r->content_type('text/html');
                    195:                $r->send_http_header;
1.9       www       196:                my $bodytag=
                    197:                       &Apache::loncommon::bodytag('Pick Instance of Resource');
1.2       www       198:                $r->print(<<ENDSTART);
                    199: <head><title>Choose Location</title></head>
1.9       www       200: $bodytag
1.2       www       201: The resource you had been accessing appears more than once in this course,
                    202: and LON-CAPA has insufficient session information to determine which instance
                    203: of the resource you meant.
                    204: <p>
                    205: Please click on the instance of the resource you intended to access:
1.11      albertel  206: </p>
                    207: <table border="2">
                    208: <tr><th>Title</th><th>Part of ...</th></tr>
1.2       www       209: ENDSTART
                    210:                map {
1.11      albertel  211: 		   my $resurl=$bighash{'src_'.$_};
1.2       www       212:                    my $mapurl=$bighash{'map_id_'.(split(/\./,$_))[0]};
1.11      albertel  213: 		   my $symb=&make_symb($_);
                    214: 		   $r->print('<tr><td><a href="'.$resurl.'?symb='.$symb.'">'.
                    215: 			     &Apache::lonnet::gettitle($symb).
                    216: 			     '</a></td><td>'.
                    217: 			     &Apache::lonnet::gettitle($mapurl).'&nbsp;'.
                    218: 			     '</td></tr>');
1.2       www       219:                } @possibilities;
1.11      albertel  220:                $r->print('</table></body></html>');
1.1       www       221: 	       untie(%bighash);
                    222:                return OK;
                    223:             }
                    224:          }
                    225:       }
                    226:       untie(%bighash);
                    227:   }
                    228: 
                    229: # ------------------------------------ This handler should not have been called
1.2       www       230:    &getlost($r,'Invalid call of handler');
1.1       www       231:    return OK;
                    232: }
                    233: 
                    234: 1;
                    235: __END__
                    236: 
                    237: 
                    238: 
                    239: 
                    240: 
                    241: 
                    242: 

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.