File:  [LON-CAPA] / rat / lonsequence.pm
Revision 1.1: download - view: text, annotated - select for diffs
Mon Oct 16 20:47:39 2000 UTC (23 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Further work on flipping pages

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

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