Annotation of rat/lonsequence.pm, revision 1.7

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Sequence Handler
                      4: #
1.6       www         5: # $Id: lonsequence.pm,v 1.5 2001/11/29 19:23:49 www Exp $
1.5       www         6: #
                      7: # Copyright Michigan State University Board of Trustees
                      8: #
                      9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     10: #
                     11: # LON-CAPA is free software; you can redistribute it and/or modify
                     12: # it under the terms of the GNU General Public License as published by
                     13: # the Free Software Foundation; either version 2 of the License, or
                     14: # (at your option) any later version.
                     15: #
                     16: # LON-CAPA is distributed in the hope that it will be useful,
                     17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     19: # GNU General Public License for more details.
                     20: #
                     21: # You should have received a copy of the GNU General Public License
                     22: # along with LON-CAPA; if not, write to the Free Software
                     23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     24: #
                     25: # /home/httpd/html/adm/gpl.txt
                     26: #
                     27: # http://www.lon-capa.org/
                     28: #
1.1       www        29: # (Handler to resolve ambiguous file locations
                     30: #
                     31: # (TeX Content Handler
                     32: #
                     33: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
                     34: #
                     35: # 10/11,10/12 Gerd Kortemeyer)
                     36: #
                     37: # 10/16 Gerd Kortemeyer
                     38: 
1.3       www        39: package Apache::lonsequence;
1.1       www        40: 
                     41: use strict;
                     42: use Apache::lonnet;
1.3       www        43: use Apache::Constants qw(:common :http REDIRECT);
1.1       www        44: use GDBM_File;
                     45: 
                     46: 
                     47: # ----------------------------------------------------------- Could not resolve
                     48: 
                     49: sub getlost {
                     50:     my ($r,$errmsg)=@_;
                     51:     $r->content_type('text/html');
                     52:     $r->send_http_header;
                     53:     $r->print(
                     54:  '<head><title>Unknown Error</title></head><body bgcolor="#FFFFFF"><h1>'.
1.3       www        55:  'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
1.1       www        56:  '</body></html>');
                     57: }
                     58: 
                     59: # ================================================================ Main Handler
                     60: 
                     61: sub handler {
                     62:    my $r=shift;
                     63: 
                     64:    if ($r->header_only) {
                     65:       $r->content_type('text/html');
                     66:       $r->send_http_header;
                     67:       return OK;
                     68:    }
                     69: 
1.2       www        70:    my %hash;
1.1       www        71:    my %bighash;
1.2       www        72:    my $requrl=$r->uri;
                     73: 
1.3       www        74: # ------------------------------------------------------------ Tie symb db file
1.1       www        75:   if ($ENV{'request.course.fn'}) {
1.2       www        76:        my $last;
                     77:        if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
                     78:                     &GDBM_READER,0640)) {
                     79: 	   $last=$hash{'last_direction'};
                     80:            untie(%hash);
                     81:        }
1.3       www        82:        my $direction='';
                     83:        my $prevmap='';
                     84:        if ($last) {
                     85: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
                     86:        }
                     87: # ------------------------------------------------------------- Tie big db file
1.1       www        88:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                     89:                     &GDBM_READER,0640)) {
1.3       www        90: 	   my $disid='';
1.4       www        91:            my $whatend='';
1.3       www        92:            if ($direction eq 'back') {
                     93: 	       $disid=$bighash{'map_finish_'.$requrl};
1.4       www        94:                $whatend='End';
1.3       www        95:            } else {
                     96:                $disid=$bighash{'map_start_'.$requrl};
1.4       www        97:                $whatend='Beginning';
1.3       www        98:            } 
                     99:            my $disurl='';
1.4       www       100:            my $dismapid='';
1.3       www       101:            if ($disid) {
                    102: 	       $disurl=$bighash{'src_'.$disid};
1.4       www       103:                $dismapid=(split(/\./,$disid))[1];
1.3       www       104:            }
                    105:            my $symb='';
1.4       www       106:            my $sequencetitle='';
1.3       www       107:            unless($disurl) {
                    108:                if ($symb=&Apache::lonnet::symbread()) {
1.4       www       109: 		   my ($mapurl,$mapid)=split(/\_\_\_/,$symb);
                    110:                    $sequencetitle=$bighash{'title_'.
                    111: 				          $bighash{'map_pc_/res/'.$mapurl}.'.'.
                    112: 					  $mapid};
1.3       www       113:                }
                    114:            }
                    115: # --------------------------------------- Untie hash, make sure to come by here
                    116:            untie(%bighash);
                    117:            if ($disurl) {
                    118: # -------------------------------------------------- Has first or last resource
1.7     ! www       119:                &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
        !           120:                    'last_known' => &Apache::lonnet::declutter($disurl)); 
1.3       www       121: 	       $r->content_type('text/html');
                    122:                $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
                    123:                return REDIRECT;
                    124:            } else {
                    125: # ---------- Does not have first or last resource, try to find out where we are
                    126:                unless ($symb) {
                    127: 		   $r->internal_redirect('/adm/ambiguous');
                    128:                }
                    129:                $r->content_type('text/html');
                    130:                $r->send_http_header;
                    131:                $r->print(<<ENDSYMB);
1.4       www       132: <html><body bgcolor="#FFFFFF">
                    133: <h2>$whatend of</h2>
                    134: <h1>$sequencetitle</h1>
1.3       www       135: </body></html>
                    136: ENDSYMB
                    137:                return OK
1.2       www       138:            }
1.1       www       139:        } else {
                    140:           &getlost($r,'Could not access course structure.');
                    141:           return OK;
                    142:        }
                    143:    } else {
                    144:       $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    145:       return HTTP_NOT_ACCEPTABLE; 
                    146:    }
                    147: 
                    148:    return OK;
                    149: }
                    150: 
                    151: 1;
                    152: __END__
                    153: 
                    154: 
                    155: 
                    156: 
                    157: 
                    158: 
                    159: 

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