Annotation of rat/lonsequence.pm, revision 1.2

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: 
                     15: package Apache::lonambiguous;
                     16: 
                     17: use strict;
                     18: use Apache::lonnet;
                     19: use Apache::Constants qw(:common 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 ambiguous 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: 
1.2     ! www        46:    my %hash;
1.1       www        47:    my %bighash;
1.2     ! www        48:    my $requrl=$r->uri;
        !            49: 
1.1       www        50: # ----------------------------------------------------------------- Tie db file
                     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.1       www        58:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                     59:                     &GDBM_READER,0640)) {
1.2     ! www        60:            my $direction='';
        !            61:            my $prevmap='';
        !            62: 	   if ($last) {
        !            63: 	       ($prevmap,$direction)=(split(/\_\_\_/,$last));
        !            64:            }
        !            65:               
        !            66: # ===== Stuff goes here
1.1       www        67:           foreach $envkey (keys %ENV) {
                     68:              if ($envkey=~/^form\.(\d+)\.(\d+)$/) {
                     69: 	         my $mapid=$1;
                     70:                  my $resid=$2;
                     71:                  my $resurl=$bighash{'src_'.$mapid.'.'.$resid};
                     72:                  &Apache::lonnet::symblist($bighash{'map_id_'.$mapid},
                     73: 				           $resurl => $resid);
                     74:                  $r->header_out(Location => 
                     75:                                 'http://'.$ENV{'HTTP_HOST'}.$resurl);
                     76:                  return REDIRECT;
                     77:              }
                     78: 	  }
                     79:           untie(%bighash);
                     80:        } else {
                     81:           &getlost($r,'Could not access course structure.');
                     82:           return OK;
                     83:        }
                     84:    } else {
                     85:       $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                     86:       return HTTP_NOT_ACCEPTABLE; 
                     87:    }
                     88: 
                     89:    return OK;
                     90: 
                     91: # ================================================================= TRASH BELOW
                     92: 
                     93: # ---------------------------------------------------------- Do we have a case?
                     94: 
                     95:    my $thisfn;
                     96:    unless (($thisfn=$ENV{'request.ambiguous'})&&($ENV{'request.course.fn'})) {
                     97:        &getlost($r,'Could not find information on resource.');
                     98:        return OK;
                     99:    }
                    100:       
                    101: # ---------------------------------- Should this file have been part of a page?
                    102: 
                    103:     $thisfn=&Apache::lonnet::declutter($thisfn);
                    104:     my %hash;
                    105:     my $syval='';
                    106:     
                    107:     if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
                    108:                   &GDBM_READER,0640)) {
                    109:        $syval=$hash{$thisfn};
                    110:        untie(%hash);
                    111:     }
                    112: 
                    113: # ---------------------------------------------------------- There was an entry
                    114: 
                    115:     if ($syval) {
                    116: 
                    117:        if ($syval=~/\_$/) {
                    118: # ----------------------------------- Okay, this should have appeared on a page
                    119: 	   $syval=~s/\_\_\_$//;
                    120:  	   $r->content_type('text/html');
                    121:            $r->header_out(Location => 
                    122:                 'http://'.$ENV{'HTTP_HOST'}.'/res/'.$syval);
                    123:            return REDIRECT;
                    124:        } else {
                    125: #  There is not really a problem (???), but cannot go back without endless loop
                    126:            &getlost($r,'The nature of the problem is unclear');
                    127:            return OK;
                    128:        }
                    129:     }
                    130: 
                    131: # ------------------------------------------------ Would be standalone resource
                    132: 
                    133:    if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                    134:                     &GDBM_READER,0640)) {
                    135: # ---------------------------------------------- Get ID(s) for current resource
                    136:       my $ids=$bighash{'ids_/res/'.$thisfn};
                    137:       if ($ids) {
                    138: # ------------------------------------------------------------------- Has ID(s)
                    139:          my @possibilities=split(/\,/,$ids);
                    140:          my $couldbe='';
                    141:          map {
                    142:              if (&Apache::lonnet::allowed('bre',$bighash{'src_'.$_})) {
                    143: 	         if ($couldbe) {
                    144: 		     $couldbe.=','.$_;
                    145:                  } else {
                    146:                      $couldbe=$_;
                    147:                  }
                    148:              }
                    149: 	 } @possibilities;
                    150:          if ($couldbe) {
                    151:             @possibilities=split(/\,/,$couldbe);
                    152:             if ($#possibilities>0) {
                    153: # ----------------------------------------------- Okay, really multiple choices
                    154:                $r->content_type('text/html');
                    155:                $r->send_http_header;
                    156:                $r->print(<<ENDSTART);
                    157: <head><title>Choose Location</title></head>
                    158: <body bgcolor="#FFFFFF">
                    159: <h1>LON-CAPA</h1>
                    160: The resource you had been accessing appears more than once in this course,
                    161: and LON-CAPA has insufficient session information to determine which instance
                    162: of the resource you meant.
                    163: <p>
                    164: Please click on the instance of the resource you intended to access:
                    165: <p>
                    166: <form action="/adm/ambiguous" method=post>
                    167: <input type=hidden name=orgurl value="$thisfn">
                    168: <input type=hidden name=selecturl value=1>
                    169: <table border=2>
                    170: <tr><th>&nbsp;</th><th>Title</th><th>Type</th><th>Part of ...</th></tr>
                    171: ENDSTART
                    172:                map {
                    173:                    my $mapurl=$bighash{'map_id_'.(split(/\./,$_))[0]};
                    174:                    $r->print('<tr><td><input type=submit value=Select name="'.
                    175:                               $_.'"></td><td>'.$bighash{'title_'.$_}.
                    176:                               '</td><td>'.$bighash{'type_'.$_}.
                    177:                               '</td><td><a href="'.$mapurl.'">'.$mapurl.
                    178: 			      '</a></td></tr>');
                    179:                } @possibilities;
                    180:                $r->print('</table></form></body></html>');
                    181: 	       untie(%bighash);
                    182:                return OK;
                    183:             }
                    184:          }
                    185:       }
                    186:       untie(%bighash);
                    187:   }
                    188: 
                    189: # ------------------------------------ This handler should not have been called
                    190:    &getlost($r,'Invalid call of handler');
                    191:    return OK;
                    192: }
                    193: 
                    194: 1;
                    195: __END__
                    196: 
                    197: 
                    198: 
                    199: 
                    200: 
                    201: 
                    202: 

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