Annotation of rat/lonsequence.pm, revision 1.11

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Sequence Handler
                      4: #
1.11    ! www         5: # $Id: lonsequence.pm,v 1.10 2002/05/23 13:04:59 www Exp $
1.5       www         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: #
1.1       www        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: 
1.3       www        39: package Apache::lonsequence;
1.1       www        40: 
                     41: use strict;
                     42: use Apache::lonnet;
1.3       www        43: use Apache::Constants qw(:common :http REDIRECT);
1.1       www        44: use GDBM_File;
1.8       www        45: use Apache::lonratedt;
                     46: use Apache::lonratsrv;
1.11    ! www        47: use Apache::lonpageflip;
1.1       www        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>'.
1.3       www        57:  'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
1.1       www        58:  '</body></html>');
                     59: }
                     60: 
1.8       www        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 {
1.9       www        77:     my ($r,$url)=@_;
1.8       www        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:     }
1.9       www       102:     $r->print('<body bgcolor="#FFFFFF">');
1.8       www       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: 
1.1       www       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:    }
1.8       www       155:  
                    156:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    157:                                           ['forceselect']);
1.1       www       158: 
1.2       www       159:    my %hash;
1.1       www       160:    my %bighash;
1.2       www       161:    my $requrl=$r->uri;
                    162: 
1.3       www       163: # ------------------------------------------------------------ Tie symb db file
1.9       www       164:   my $disurl='';
                    165:   my $dismapid='';
                    166: 
                    167:   if (($ENV{'request.course.fn'}) && (!$ENV{'form.forceselect'})) {
1.2       www       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:        }
1.3       www       174:        my $direction='';
                    175:        my $prevmap='';
                    176:        if ($last) {
                    177: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
                    178:        }
                    179: # ------------------------------------------------------------- Tie big db file
1.1       www       180:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                    181:                     &GDBM_READER,0640)) {
1.3       www       182: 	   my $disid='';
1.10      www       183: 
1.3       www       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};
1.4       www       191:                $dismapid=(split(/\./,$disid))[1];
1.3       www       192:            }
1.11    ! www       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: 
1.3       www       205: # --------------------------------------- Untie hash, make sure to come by here
                    206:            untie(%bighash);
1.9       www       207:        }
                    208:    }
                    209: 
                    210: # now either disurl is set (going to first page), or we need another display
                    211: 
                    212:    if ($disurl) {
1.3       www       213: # -------------------------------------------------- Has first or last resource
1.9       www       214:       &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
1.7       www       215:                    'last_known' => &Apache::lonnet::declutter($disurl)); 
1.9       www       216:       $r->content_type('text/html');
                    217:       $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
                    218:       return REDIRECT;
1.1       www       219:    } else {
1.9       www       220:        $r->content_type('text/html');
                    221:        $r->send_http_header;
                    222:        &viewmap($r,$requrl);
                    223:        return OK;
1.1       www       224:    }
                    225: }
                    226: 
                    227: 1;
                    228: __END__
                    229: 
                    230: 
                    231: 
                    232: 
                    233: 
                    234: 
                    235: 

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