File:  [LON-CAPA] / rat / lonsequence.pm
Revision 1.11: download - view: text, annotated - select for diffs
Thu May 23 15:07:55 2002 UTC (21 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #175
If the beginning of a sequence is an empty resource, use "move" from
lonpageflip now to get to non-empty page.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Sequence Handler
    4: #
    5: # $Id: lonsequence.pm,v 1.11 2002/05/23 15:07:55 www Exp $
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: #
   29: # (Handler to resolve ambiguous file locations
   30: #
   31: # (TeX Content Handler
   32: #
   33: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
   34: #
   35: # 10/11,10/12 Gerd Kortemeyer)
   36: #
   37: # 10/16 Gerd Kortemeyer
   38: 
   39: package Apache::lonsequence;
   40: 
   41: use strict;
   42: use Apache::lonnet;
   43: use Apache::Constants qw(:common :http REDIRECT);
   44: use GDBM_File;
   45: use Apache::lonratedt;
   46: use Apache::lonratsrv;
   47: use Apache::lonpageflip;
   48: 
   49: # ----------------------------------------------------------- Could not resolve
   50: 
   51: sub getlost {
   52:     my ($r,$errmsg)=@_;
   53:     $r->content_type('text/html');
   54:     $r->send_http_header;
   55:     $r->print(
   56:  '<head><title>Unknown Error</title></head><body bgcolor="#FFFFFF"><h1>'.
   57:  'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
   58:  '</body></html>');
   59: }
   60: 
   61: 
   62: # ----------------------------------------- Attempt to read from resource space
   63: 
   64: sub attemptread {
   65:     my $fn=shift;
   66:     &Apache::lonnet::repcopy($fn);
   67:     if (-e $fn) {
   68: 	return &Apache::lonratedt::attemptread($fn);
   69:     } else {
   70:         return ();
   71:     }
   72: }
   73: 
   74: # ---------------------------------------------------------------- View Handler
   75: 
   76: sub viewmap {
   77:     my ($r,$url)=@_;
   78:     $r->print('<html>');
   79:     if ($ENV{'form.forceselect'}) { $r->print(<<ENDSCRIPT);
   80: <script>
   81: 
   82: function select_group() {
   83:     window.location="/adm/groupsort?catalogmode=groupimport&mode=rat&acts="+document.forms.fileattr.acts.value;
   84: }
   85: 
   86: function queue(val) {
   87:     if (eval("document.forms."+val+".filelink.checked")) {
   88: 	var l=val.length;
   89: 	var v=val.substring(4,l);
   90: 	document.forms.fileattr.acts.value+='1a'+v+'b';
   91:     }
   92:     else {
   93: 	var l=val.length;
   94: 	var v=val.substring(4,l);
   95: 	document.forms.fileattr.acts.value+='0a'+v+'b';
   96:     }
   97: }
   98: 
   99: </script>
  100: ENDSCRIPT
  101:     }
  102:     $r->print('<body bgcolor="#FFFFFF">');
  103:     if ($ENV{'form.forceselect'}) { $r->print(<<ENDSELECT);
  104: <form name=fileattr><input type=hidden name=acts value=''>
  105: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  106: <input type="button" name="groupimport" value='GROUP IMPORT'
  107: onClick="javascript:select_group()">
  108: </form>   
  109: ENDSELECT
  110:     }
  111:     my $idx=0;
  112:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
  113: 	if (defined($_)) {
  114:             $idx++;
  115:             if ($ENV{'form.forceselect'}) { 
  116: 		$r->print('<form name="form'.$idx.'">');
  117:             }
  118: 	    my ($title,$url)=split(/\:/,$_);
  119:             $title=~s/\&colon\;/\:/g;
  120:             $url=~s/\&colon\;/\:/g;
  121:             unless ($title) { $title=(split(/\//,$url))[-1] };
  122:             unless ($title) { $title='<i>Empty</i>'; }
  123:             if ($url) {
  124: 		if ($ENV{'form.forceselect'}) {
  125: 		    $r->print(<<ENDCHECKBOX);
  126: <input type='checkbox' name='filelink' 
  127: value='$url' onClick='javascript:queue("form$idx")' >
  128: <input type='hidden' name='title' value='$title'>
  129: ENDCHECKBOX
  130:                 }
  131: 		$r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
  132:             }
  133:             $r->print(&Apache::lonratsrv::qtescape($title));
  134:             if ($url) { $r->print('</a>'); }
  135:             if ($ENV{'form.forceselect'}) {
  136: 		$r->print('</form>');
  137:             } else {
  138: 		$r->print('<br>');
  139:             }
  140:         }
  141:     }
  142:     $r->print('</body></html>');
  143: }
  144: 
  145: # ================================================================ Main Handler
  146: 
  147: sub handler {
  148:    my $r=shift;
  149: 
  150:    if ($r->header_only) {
  151:       $r->content_type('text/html');
  152:       $r->send_http_header;
  153:       return OK;
  154:    }
  155:  
  156:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  157:                                           ['forceselect']);
  158: 
  159:    my %hash;
  160:    my %bighash;
  161:    my $requrl=$r->uri;
  162: 
  163: # ------------------------------------------------------------ Tie symb db file
  164:   my $disurl='';
  165:   my $dismapid='';
  166: 
  167:   if (($ENV{'request.course.fn'}) && (!$ENV{'form.forceselect'})) {
  168:        my $last;
  169:        if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
  170:                     &GDBM_READER,0640)) {
  171: 	   $last=$hash{'last_direction'};
  172:            untie(%hash);
  173:        }
  174:        my $direction='';
  175:        my $prevmap='';
  176:        if ($last) {
  177: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
  178:        }
  179: # ------------------------------------------------------------- Tie big db file
  180:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
  181:                     &GDBM_READER,0640)) {
  182: 	   my $disid='';
  183: 
  184:            if ($direction eq 'back') {
  185: 	       $disid=$bighash{'map_finish_'.$requrl};
  186:            } else {
  187:                $disid=$bighash{'map_start_'.$requrl};
  188:            } 
  189:            if ($disid) {
  190: 	       $disurl=$bighash{'src_'.$disid};
  191:                $dismapid=(split(/\./,$disid))[1];
  192:            }
  193: # ------------------------- If this is an empty one, skip to next non-empty one
  194:            if ((!$disurl) && ($disid)) {
  195: 	       $direction=($direction?$direction:'forward');
  196:                ($disid,$requrl)=
  197:                          &Apache::lonpageflip::fullmove($disid,
  198:                            &Apache::lonnet::declutter($requrl),$direction);
  199:                if ($disid) {
  200: 	           $disurl=$bighash{'src_'.$disid};
  201:                    $dismapid=(split(/\./,$disid))[1];
  202:                }
  203:  	   }
  204: 
  205: # --------------------------------------- Untie hash, make sure to come by here
  206:            untie(%bighash);
  207:        }
  208:    }
  209: 
  210: # now either disurl is set (going to first page), or we need another display
  211: 
  212:    if ($disurl) {
  213: # -------------------------------------------------- Has first or last resource
  214:       &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
  215:                    'last_known' => &Apache::lonnet::declutter($disurl)); 
  216:       $r->content_type('text/html');
  217:       $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
  218:       return REDIRECT;
  219:    } else {
  220:        $r->content_type('text/html');
  221:        $r->send_http_header;
  222:        &viewmap($r,$requrl);
  223:        return OK;
  224:    }
  225: }
  226: 
  227: 1;
  228: __END__
  229: 
  230: 
  231: 
  232: 
  233: 
  234: 
  235: 

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