File:  [LON-CAPA] / rat / lonambiguous.pm
Revision 1.10: download - view: text, annotated - select for diffs
Mon Sep 22 03:02:06 2003 UTC (20 years, 7 months ago) by www
Branches: MAIN
CVS tags: version_1_2_X, version_1_2_99_1, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_X, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
Internationalizing.

    1: # The LearningOnline Network with CAPA
    2: # Handler to resolve ambiguous file locations
    3: #
    4: # $Id: lonambiguous.pm,v 1.10 2003/09/22 03:02:06 www 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: use Apache::loncommon;
   41: use Apache::lonlocal;
   42: 
   43: my %bighash;
   44: 
   45: sub cleanup {
   46:     if (tied(%bighash)){
   47: 	&Apache::lonnet::logthis('Cleanup ambiguous: bighash');
   48:         unless (untie(%bighash)) {
   49: 	    &Apache::lonnet::logthis('Failed cleanup ambiguous: bighash');
   50:         }
   51:     }
   52: }
   53: 
   54: # ----------------------------------------------------------- Could not resolve
   55: 
   56: sub getlost {
   57:     my ($r,$errmsg)=@_;
   58:     $errmsg=&mt($errmsg);
   59:     $r->content_type('text/html');
   60:     $r->send_http_header;
   61:     $r->print(
   62:  '<head><title>Unknown Error</title></head>'.
   63:   &Apache::loncommon::bodytag('Could not handle ambiguous resource reference').
   64:   $errmsg.
   65:  '</body></html>');
   66: }
   67: 
   68: # ================================================================ Main Handler
   69: 
   70: sub handler {
   71:    my $r=shift;
   72: 
   73:    if ($r->header_only) {
   74:       &Apache::loncommon::content_type($r,'text/html');
   75:       $r->send_http_header;
   76:       return OK;
   77:    }
   78: 
   79: # ---------------------------------------------------------- Is this selecting?
   80:  
   81:    if ($ENV{'form.selecturl'}) {
   82:        my $envkey;
   83:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
   84:                     &GDBM_READER(),0640)) {
   85:           foreach $envkey (keys %ENV) {
   86:              if ($envkey=~/^form\.(\d+)\.(\d+)$/) {
   87: # ---------------------------------------------------- Update symb and redirect
   88: 	         my $mapid=$1;
   89:                  my $resid=$2;
   90:                  my $resurl=$bighash{'src_'.$mapid.'.'.$resid};
   91:                  &Apache::lonnet::symblist($bighash{'map_id_'.$mapid},
   92: 				           $resurl => $resid);
   93:                  untie(%bighash);
   94:                  $r->header_out(Location => 
   95:                                 'http://'.$ENV{'HTTP_HOST'}.$resurl);
   96:                  return REDIRECT;
   97:              }
   98: 	  }
   99:           untie(%bighash);
  100:        } else {
  101:           &getlost($r,'Could not access course structure.');
  102:           return OK;
  103:        }
  104:    }
  105: 
  106: # ---------------------------------------------------------- Do we have a case?
  107: 
  108:    my $thisfn;
  109:    unless (($thisfn=$ENV{'request.ambiguous'})&&($ENV{'request.course.fn'})) {
  110:        &getlost($r,'Could not find information on resource.');
  111:        return OK;
  112:    }
  113:       
  114: # ---------------------------------- Should this file have been part of a page?
  115: 
  116:     $thisfn=&Apache::lonnet::declutter($thisfn);
  117:     my %hash;
  118:     my $syval='';
  119:     
  120:     if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
  121:                   &GDBM_READER(),0640)) {
  122:        $syval=$hash{$thisfn};
  123:        untie(%hash);
  124:     }
  125: 
  126: # ---------------------------------------------------------- There was an entry
  127: 
  128:     if ($syval) {
  129: 
  130:        if ($syval=~/\_$/) {
  131: # ----------------------------------- Okay, this should have appeared on a page
  132: 	   $syval=~s/\_\_\_$//;
  133:  	   $r->content_type('text/html');
  134:            $r->header_out(Location => 
  135:                 'http://'.$ENV{'HTTP_HOST'}.'/res/'.$syval);
  136:            return REDIRECT;
  137:        } else {
  138: #  There is not really a problem (???), but cannot go back without endless loop
  139:            &getlost($r,'The nature of the problem is unclear');
  140:            return OK;
  141:        }
  142:     }
  143: 
  144: # ------------------------------------------------ Would be standalone resource
  145: 
  146:    if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
  147:                     &GDBM_READER(),0640)) {
  148: # ---------------------------------------------- Get ID(s) for current resource
  149:       my $ids=$bighash{'ids_'.&Apache::lonnet::clutter($thisfn)};
  150:       if ($ids) {
  151: # ------------------------------------------------------------------- Has ID(s)
  152:          my @possibilities=split(/\,/,$ids);
  153:          my $couldbe='';
  154:          map {
  155:              if (&Apache::lonnet::allowed('bre',$bighash{'src_'.$_})) {
  156: 	         if ($couldbe) {
  157: 		     $couldbe.=','.$_;
  158:                  } else {
  159:                      $couldbe=$_;
  160:                  }
  161:              }
  162: 	 } @possibilities;
  163:          if ($couldbe) {
  164:             @possibilities=split(/\,/,$couldbe);
  165:             if ($#possibilities>0) {
  166: # ----------------------------------------------- Okay, really multiple choices
  167:                $r->content_type('text/html');
  168:                $r->send_http_header;
  169:                my $bodytag=
  170:                       &Apache::loncommon::bodytag('Pick Instance of Resource');
  171:                $r->print(<<ENDSTART);
  172: <head><title>Choose Location</title></head>
  173: $bodytag
  174: The resource you had been accessing appears more than once in this course,
  175: and LON-CAPA has insufficient session information to determine which instance
  176: of the resource you meant.
  177: <p>
  178: Please click on the instance of the resource you intended to access:
  179: <p>
  180: <form action="/adm/ambiguous" method=post>
  181: <input type=hidden name=orgurl value="$thisfn">
  182: <input type=hidden name=selecturl value=1>
  183: <table border=2>
  184: <tr><th>&nbsp;</th><th>Title</th><th>Type</th><th>Part of ...</th></tr>
  185: ENDSTART
  186:                map {
  187:                    my $mapurl=$bighash{'map_id_'.(split(/\./,$_))[0]};
  188:                    $r->print('<tr><td><input type=submit value=Select name="'.
  189:                               $_.'"></td><td>'.$bighash{'title_'.$_}.
  190:                               '</td><td>'.$bighash{'type_'.$_}.
  191:                               '</td><td>'.
  192:                               ($mapurl=~/^\/uploaded\//?'':'<a href="'.$mapurl.'">').
  193:                               &Apache::lonnet::gettitle($mapurl).'&nbsp;'.
  194: 			      ($mapurl=~/^\/uploaded\//?'':'</a>').'</td></tr>');
  195:                } @possibilities;
  196:                $r->print('</table></form></body></html>');
  197: 	       untie(%bighash);
  198:                return OK;
  199:             }
  200:          }
  201:       }
  202:       untie(%bighash);
  203:   }
  204: 
  205: # ------------------------------------ This handler should not have been called
  206:    &getlost($r,'Invalid call of handler');
  207:    return OK;
  208: }
  209: 
  210: 1;
  211: __END__
  212: 
  213: 
  214: 
  215: 
  216: 
  217: 
  218: 

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