File:  [LON-CAPA] / rat / lonsequence.pm
Revision 1.4: download - view: text, annotated - select for diffs
Tue Oct 17 17:06:15 2000 UTC (23 years, 6 months ago) by www
Branches: MAIN
CVS tags: stable_2001_fall, HEAD
Fixed bug in "last known" resource

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Sequence Handler
    4: #
    5: # (Handler to resolve ambiguous file locations
    6: #
    7: # (TeX Content Handler
    8: #
    9: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
   10: #
   11: # 10/11,10/12 Gerd Kortemeyer)
   12: #
   13: # 10/16 Gerd Kortemeyer
   14: 
   15: package Apache::lonsequence;
   16: 
   17: use strict;
   18: use Apache::lonnet;
   19: use Apache::Constants qw(:common :http REDIRECT);
   20: use GDBM_File;
   21: 
   22: 
   23: # ----------------------------------------------------------- Could not resolve
   24: 
   25: sub getlost {
   26:     my ($r,$errmsg)=@_;
   27:     $r->content_type('text/html');
   28:     $r->send_http_header;
   29:     $r->print(
   30:  '<head><title>Unknown Error</title></head><body bgcolor="#FFFFFF"><h1>'.
   31:  'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
   32:  '</body></html>');
   33: }
   34: 
   35: # ================================================================ Main Handler
   36: 
   37: sub handler {
   38:    my $r=shift;
   39: 
   40:    if ($r->header_only) {
   41:       $r->content_type('text/html');
   42:       $r->send_http_header;
   43:       return OK;
   44:    }
   45: 
   46:    my %hash;
   47:    my %bighash;
   48:    my $requrl=$r->uri;
   49: 
   50: # ------------------------------------------------------------ Tie symb db file
   51:   if ($ENV{'request.course.fn'}) {
   52:        my $last;
   53:        if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
   54:                     &GDBM_READER,0640)) {
   55: 	   $last=$hash{'last_direction'};
   56:            untie(%hash);
   57:        }
   58:        my $direction='';
   59:        my $prevmap='';
   60:        if ($last) {
   61: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
   62:        }
   63: # ------------------------------------------------------------- Tie big db file
   64:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
   65:                     &GDBM_READER,0640)) {
   66: 	   my $disid='';
   67:            my $whatend='';
   68:            if ($direction eq 'back') {
   69: 	       $disid=$bighash{'map_finish_'.$requrl};
   70:                $whatend='End';
   71:            } else {
   72:                $disid=$bighash{'map_start_'.$requrl};
   73:                $whatend='Beginning';
   74:            } 
   75:            my $disurl='';
   76:            my $dismapid='';
   77:            if ($disid) {
   78: 	       $disurl=$bighash{'src_'.$disid};
   79:                $dismapid=(split(/\./,$disid))[1];
   80:            }
   81:            my $symb='';
   82:            my $sequencetitle='';
   83:            unless($disurl) {
   84:                if ($symb=&Apache::lonnet::symbread()) {
   85: 		   my ($mapurl,$mapid)=split(/\_\_\_/,$symb);
   86:                    $sequencetitle=$bighash{'title_'.
   87: 				          $bighash{'map_pc_/res/'.$mapurl}.'.'.
   88: 					  $mapid};
   89:                }
   90:            }
   91: # --------------------------------------- Untie hash, make sure to come by here
   92:            untie(%bighash);
   93:            if ($disurl) {
   94: # -------------------------------------------------- Has first or last resource
   95:                &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
   96:                    'last_known' => &Apache::lonnet::declutter($disurl)); 
   97: 	       $r->content_type('text/html');
   98:                $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
   99:                return REDIRECT;
  100:            } else {
  101: # ---------- Does not have first or last resource, try to find out where we are
  102:                unless ($symb) {
  103: 		   $r->internal_redirect('/adm/ambiguous');
  104:                }
  105:                $r->content_type('text/html');
  106:                $r->send_http_header;
  107:                $r->print(<<ENDSYMB);
  108: <html><body bgcolor="#FFFFFF">
  109: <h2>$whatend of</h2>
  110: <h1>$sequencetitle</h1>
  111: </body></html>
  112: ENDSYMB
  113:                return OK
  114:            }
  115:        } else {
  116:           &getlost($r,'Could not access course structure.');
  117:           return OK;
  118:        }
  119:    } else {
  120:       $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
  121:       return HTTP_NOT_ACCEPTABLE; 
  122:    }
  123: 
  124:    return OK;
  125: }
  126: 
  127: 1;
  128: __END__
  129: 
  130: 
  131: 
  132: 
  133: 
  134: 
  135: 

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