Annotation of rat/lonsequence.pm, revision 1.3

1.1       www         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: 
1.3     ! www        15: package Apache::lonsequence;
1.1       www        16: 
                     17: use strict;
                     18: use Apache::lonnet;
1.3     ! www        19: use Apache::Constants qw(:common :http REDIRECT);
1.1       www        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>'.
1.3     ! www        31:  'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
1.1       www        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: 
1.2       www        46:    my %hash;
1.1       www        47:    my %bighash;
1.2       www        48:    my $requrl=$r->uri;
                     49: 
1.3     ! www        50: # ------------------------------------------------------------ Tie symb db file
1.1       www        51:   if ($ENV{'request.course.fn'}) {
1.2       www        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:        }
1.3     ! www        58:        my $direction='';
        !            59:        my $prevmap='';
        !            60:        if ($last) {
        !            61: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
        !            62:        }
        !            63: # ------------------------------------------------------------- Tie big db file
1.1       www        64:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                     65:                     &GDBM_READER,0640)) {
1.3     ! www        66: 	   my $disid='';
        !            67:            if ($direction eq 'back') {
        !            68: 	       $disid=$bighash{'map_finish_'.$requrl};
        !            69:            } else {
        !            70:                $disid=$bighash{'map_start_'.$requrl};
        !            71:            } 
        !            72:            my $disurl='';
        !            73:            if ($disid) {
        !            74: 	       $disurl=$bighash{'src_'.$disid};
        !            75:            }
        !            76:            my $symb='';
        !            77:            unless($disurl) {
        !            78:                if ($symb=&Apache::lonnet::symbread()) {
        !            79:                }
        !            80:            }
        !            81: # --------------------------------------- Untie hash, make sure to come by here
        !            82:            untie(%bighash);
        !            83:            if ($disurl) {
        !            84: # -------------------------------------------------- Has first or last resource
        !            85: 	       $r->content_type('text/html');
        !            86:                $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
        !            87:                return REDIRECT;
        !            88:            } else {
        !            89: # ---------- Does not have first or last resource, try to find out where we are
        !            90:                unless ($symb) {
        !            91: 		   $r->internal_redirect('/adm/ambiguous');
        !            92:                }
        !            93:                $r->content_type('text/html');
        !            94:                $r->send_http_header;
        !            95:                $r->print(<<ENDSYMB);
        !            96: <html><body>
        !            97: </body></html>
        !            98: ENDSYMB
        !            99:                return OK
1.2       www       100:            }
1.1       www       101:        } else {
                    102:           &getlost($r,'Could not access course structure.');
                    103:           return OK;
                    104:        }
                    105:    } else {
                    106:       $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    107:       return HTTP_NOT_ACCEPTABLE; 
                    108:    }
                    109: 
                    110:    return OK;
                    111: }
                    112: 
                    113: 1;
                    114: __END__
                    115: 
                    116: 
                    117: 
                    118: 
                    119: 
                    120: 
                    121: 

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