File:  [LON-CAPA] / rat / lonambiguous.pm
Revision 1.5: download - view: text, annotated - select for diffs
Mon Aug 12 18:21:42 2002 UTC (21 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: version_0_5_1, version_0_5, HEAD
- i think the last of bug#574

    1: # The LearningOnline Network with CAPA
    2: # Handler to resolve ambiguous file locations
    3: #
    4: # $Id: lonambiguous.pm,v 1.5 2002/08/12 18:21:42 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (TeX Content Handler
   29: #
   30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
   31: #
   32: # 10/11,10/12,10/16 Gerd Kortemeyer
   33: 
   34: package Apache::lonambiguous;
   35: 
   36: use strict;
   37: use Apache::lonnet;
   38: use Apache::Constants qw(:common REDIRECT);
   39: use GDBM_File;
   40: 
   41: 
   42: # ----------------------------------------------------------- Could not resolve
   43: 
   44: sub getlost {
   45:     my ($r,$errmsg)=@_;
   46:     $r->content_type('text/html');
   47:     $r->send_http_header;
   48:     $r->print(
   49:  '<head><title>Unknown Error</title></head><body bgcolor="#FFFFFF"><h1>'.
   50:  'LON-CAPA</h1>Could not handle ambiguous resource reference.<p>'.$errmsg.
   51:  '</body></html>');
   52: }
   53: 
   54: # ================================================================ Main Handler
   55: 
   56: sub handler {
   57:    my $r=shift;
   58: 
   59:    if ($r->header_only) {
   60:       $r->content_type('text/html');
   61:       $r->send_http_header;
   62:       return OK;
   63:    }
   64: 
   65: # ---------------------------------------------------------- Is this selecting?
   66:    
   67:    my %bighash;
   68: 
   69:    if ($ENV{'form.selecturl'}) {
   70:        my $envkey;
   71:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
   72:                     &GDBM_READER(),0640)) {
   73:           foreach $envkey (keys %ENV) {
   74:              if ($envkey=~/^form\.(\d+)\.(\d+)$/) {
   75: # ---------------------------------------------------- Update symb and redirect
   76: 	         my $mapid=$1;
   77:                  my $resid=$2;
   78:                  my $resurl=$bighash{'src_'.$mapid.'.'.$resid};
   79:                  &Apache::lonnet::symblist($bighash{'map_id_'.$mapid},
   80: 				           $resurl => $resid);
   81:                  untie(%bighash);
   82:                  $r->header_out(Location => 
   83:                                 'http://'.$ENV{'HTTP_HOST'}.$resurl);
   84:                  return REDIRECT;
   85:              }
   86: 	  }
   87:           untie(%bighash);
   88:        } else {
   89:           &getlost($r,'Could not access course structure.');
   90:           return OK;
   91:        }
   92:    }
   93: 
   94: # ---------------------------------------------------------- Do we have a case?
   95: 
   96:    my $thisfn;
   97:    unless (($thisfn=$ENV{'request.ambiguous'})&&($ENV{'request.course.fn'})) {
   98:        &getlost($r,'Could not find information on resource.');
   99:        return OK;
  100:    }
  101:       
  102: # ---------------------------------- Should this file have been part of a page?
  103: 
  104:     $thisfn=&Apache::lonnet::declutter($thisfn);
  105:     my %hash;
  106:     my $syval='';
  107:     
  108:     if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
  109:                   &GDBM_READER(),0640)) {
  110:        $syval=$hash{$thisfn};
  111:        untie(%hash);
  112:     }
  113: 
  114: # ---------------------------------------------------------- There was an entry
  115: 
  116:     if ($syval) {
  117: 
  118:        if ($syval=~/\_$/) {
  119: # ----------------------------------- Okay, this should have appeared on a page
  120: 	   $syval=~s/\_\_\_$//;
  121:  	   $r->content_type('text/html');
  122:            $r->header_out(Location => 
  123:                 'http://'.$ENV{'HTTP_HOST'}.'/res/'.$syval);
  124:            return REDIRECT;
  125:        } else {
  126: #  There is not really a problem (???), but cannot go back without endless loop
  127:            &getlost($r,'The nature of the problem is unclear');
  128:            return OK;
  129:        }
  130:     }
  131: 
  132: # ------------------------------------------------ Would be standalone resource
  133: 
  134:    if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
  135:                     &GDBM_READER(),0640)) {
  136: # ---------------------------------------------- Get ID(s) for current resource
  137:       my $ids=$bighash{'ids_/res/'.$thisfn};
  138:       if ($ids) {
  139: # ------------------------------------------------------------------- Has ID(s)
  140:          my @possibilities=split(/\,/,$ids);
  141:          my $couldbe='';
  142:          map {
  143:              if (&Apache::lonnet::allowed('bre',$bighash{'src_'.$_})) {
  144: 	         if ($couldbe) {
  145: 		     $couldbe.=','.$_;
  146:                  } else {
  147:                      $couldbe=$_;
  148:                  }
  149:              }
  150: 	 } @possibilities;
  151:          if ($couldbe) {
  152:             @possibilities=split(/\,/,$couldbe);
  153:             if ($#possibilities>0) {
  154: # ----------------------------------------------- Okay, really multiple choices
  155:                $r->content_type('text/html');
  156:                $r->send_http_header;
  157:                $r->print(<<ENDSTART);
  158: <head><title>Choose Location</title></head>
  159: <body bgcolor="#FFFFFF">
  160: <h1>LON-CAPA</h1>
  161: The resource you had been accessing appears more than once in this course,
  162: and LON-CAPA has insufficient session information to determine which instance
  163: of the resource you meant.
  164: <p>
  165: Please click on the instance of the resource you intended to access:
  166: <p>
  167: <form action="/adm/ambiguous" method=post>
  168: <input type=hidden name=orgurl value="$thisfn">
  169: <input type=hidden name=selecturl value=1>
  170: <table border=2>
  171: <tr><th>&nbsp;</th><th>Title</th><th>Type</th><th>Part of ...</th></tr>
  172: ENDSTART
  173:                map {
  174:                    my $mapurl=$bighash{'map_id_'.(split(/\./,$_))[0]};
  175:                    $r->print('<tr><td><input type=submit value=Select name="'.
  176:                               $_.'"></td><td>'.$bighash{'title_'.$_}.
  177:                               '</td><td>'.$bighash{'type_'.$_}.
  178:                               '</td><td><a href="'.$mapurl.'">'.$mapurl.
  179: 			      '</a></td></tr>');
  180:                } @possibilities;
  181:                $r->print('</table></form></body></html>');
  182: 	       untie(%bighash);
  183:                return OK;
  184:             }
  185:          }
  186:       }
  187:       untie(%bighash);
  188:   }
  189: 
  190: # ------------------------------------ This handler should not have been called
  191:    &getlost($r,'Invalid call of handler');
  192:    return OK;
  193: }
  194: 
  195: 1;
  196: __END__
  197: 
  198: 
  199: 
  200: 
  201: 
  202: 
  203: 

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