Annotation of rat/lonambiguous.pm, revision 1.1
1.1 ! www 1: # The LearningOnline Network with CAPA
! 2: # Handler to resolve ambiguous file locations
! 3: #
! 4: # (TeX Content Handler
! 5: #
! 6: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
! 7: #
! 8: # 10/11 Gerd Kortemeyer
! 9:
! 10: package Apache::lonambiguous;
! 11:
! 12: use strict;
! 13: use Apache::lonnet;
! 14: use Apache::Constants qw(:common REDIRECT);
! 15: use GDBM_File;
! 16:
! 17:
! 18: # ----------------------------------------------------------- Could not resolve
! 19:
! 20: sub getlost {
! 21: my $r=shift;
! 22: $r->content_type('text/html');
! 23: $r->send_http_header;
! 24: $r->print('<head><title>Unknown Error</title><body bgcolor="#FFFFFF">'.
! 25: '<h1>LON-CAPA</h1>Could not handle ambiguous file reference.</body></html>');
! 26: }
! 27:
! 28: # ================================================================ Main Handler
! 29:
! 30: sub handler {
! 31: my $r=shift;
! 32:
! 33: if ($r->header_only) {
! 34: $r->content_type('text/html');
! 35: $r->send_http_header;
! 36: return OK;
! 37: }
! 38:
! 39: # ---------------------------------------------------------- Do we have a case?
! 40:
! 41: my $thisfn;
! 42: unless (($thisfn=$ENV{'request.ambiguous'})&&($ENV{'request.course.fn'})) {
! 43: getlost($r);
! 44: return OK;
! 45: }
! 46:
! 47: # ---------------------------------- Should this file have been part of a page?
! 48:
! 49: $thisfn=&Apache::lonnet::declutter($thisfn);
! 50: my %hash;
! 51: my %bighash;
! 52: my $syval='';
! 53:
! 54: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
! 55: &GDBM_READER,0640)) {
! 56: $syval=$hash{$thisfn};
! 57: untie(%hash);
! 58: }
! 59: # ---------------------------------------------------------- There was an entry
! 60: if ($syval) {
! 61: if ($syval=~/\_$/) {
! 62: # ----------------------------------- Okay, this should have appeared on a page
! 63: $syval=~s/\_\_\_$//;
! 64: $r->content_type('text/html');
! 65: $r->header_out(Location =>
! 66: 'http://'.$ENV{'HTTP_HOST'}.'/res/'.$syval);
! 67: return REDIRECT;
! 68: } else {
! 69: # There is not really a problem (???), but cannot go back without endless loop
! 70: getlost($r);
! 71: return OK;
! 72: }
! 73: }
! 74:
! 75: # ------------------------------------------------ Would be standalone resource
! 76:
! 77: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
! 78: &GDBM_READER,0640)) {
! 79: # ---------------------------------------------- Get ID(s) for current resource
! 80: my $ids=$bighash{'ids_/res/'.$thisfn};
! 81: if ($ids) {
! 82: # ------------------------------------------------------------------- Has ID(s)
! 83: my @possibilities=split(/\,/,$ids);
! 84: my $couldbe='';
! 85: map {
! 86: if (&allowed('bre',$bighash{'src_'.$_})) {
! 87: if ($couldbe) {
! 88: $couldbe.=','.$_;
! 89: } else {
! 90: $couldbe=$_;
! 91: }
! 92: }
! 93: } @possibilities;
! 94: if ($couldbe) {
! 95: @possibilities=split(/\,/,$couldbe);
! 96: if ($#possibilities>0) {
! 97: # ----------------------------------------------- Okay, really multiple choices
! 98: $r->content_type('text/html');
! 99: $r->send_http_header;
! 100: $r->print(
! 101: '<head><title>Choose Location</title><body bgcolor="#FFFFFF">'.
! 102: '<h1>LON-CAPA</h1>Cool.</body></html>');
! 103: untie(%bighash);
! 104: return OK;
! 105: }
! 106: }
! 107: }
! 108: untie(%bighash);
! 109: }
! 110:
! 111: # ------------------------------------ This handler should not have been called
! 112: getlost($r);
! 113: return OK;
! 114: }
! 115:
! 116: 1;
! 117: __END__
! 118:
! 119:
! 120:
! 121:
! 122:
! 123:
! 124:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>