Annotation of rat/lonsequence.pm, revision 1.10

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Sequence Handler
                      4: #
1.10    ! www         5: # $Id: lonsequence.pm,v 1.9 2002/05/23 10:58:05 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.1       www        47: 
                     48: # ----------------------------------------------------------- Could not resolve
                     49: 
                     50: sub getlost {
                     51:     my ($r,$errmsg)=@_;
                     52:     $r->content_type('text/html');
                     53:     $r->send_http_header;
                     54:     $r->print(
                     55:  '<head><title>Unknown Error</title></head><body bgcolor="#FFFFFF"><h1>'.
1.3       www        56:  'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
1.1       www        57:  '</body></html>');
                     58: }
                     59: 
1.8       www        60: 
                     61: # ----------------------------------------- Attempt to read from resource space
                     62: 
                     63: sub attemptread {
                     64:     my $fn=shift;
                     65:     &Apache::lonnet::repcopy($fn);
                     66:     if (-e $fn) {
                     67: 	return &Apache::lonratedt::attemptread($fn);
                     68:     } else {
                     69:         return ();
                     70:     }
                     71: }
                     72: 
                     73: # ---------------------------------------------------------------- View Handler
                     74: 
                     75: sub viewmap {
1.9       www        76:     my ($r,$url)=@_;
1.8       www        77:     $r->print('<html>');
                     78:     if ($ENV{'form.forceselect'}) { $r->print(<<ENDSCRIPT);
                     79: <script>
                     80: 
                     81: function select_group() {
                     82:     window.location="/adm/groupsort?catalogmode=groupimport&mode=rat&acts="+document.forms.fileattr.acts.value;
                     83: }
                     84: 
                     85: function queue(val) {
                     86:     if (eval("document.forms."+val+".filelink.checked")) {
                     87: 	var l=val.length;
                     88: 	var v=val.substring(4,l);
                     89: 	document.forms.fileattr.acts.value+='1a'+v+'b';
                     90:     }
                     91:     else {
                     92: 	var l=val.length;
                     93: 	var v=val.substring(4,l);
                     94: 	document.forms.fileattr.acts.value+='0a'+v+'b';
                     95:     }
                     96: }
                     97: 
                     98: </script>
                     99: ENDSCRIPT
                    100:     }
1.9       www       101:     $r->print('<body bgcolor="#FFFFFF">');
1.8       www       102:     if ($ENV{'form.forceselect'}) { $r->print(<<ENDSELECT);
                    103: <form name=fileattr><input type=hidden name=acts value=''>
                    104: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    105: <input type="button" name="groupimport" value='GROUP IMPORT'
                    106: onClick="javascript:select_group()">
                    107: </form>   
                    108: ENDSELECT
                    109:     }
                    110:     my $idx=0;
                    111:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
                    112: 	if (defined($_)) {
                    113:             $idx++;
                    114:             if ($ENV{'form.forceselect'}) { 
                    115: 		$r->print('<form name="form'.$idx.'">');
                    116:             }
                    117: 	    my ($title,$url)=split(/\:/,$_);
                    118:             $title=~s/\&colon\;/\:/g;
                    119:             $url=~s/\&colon\;/\:/g;
                    120:             unless ($title) { $title=(split(/\//,$url))[-1] };
                    121:             unless ($title) { $title='<i>Empty</i>'; }
                    122:             if ($url) {
                    123: 		if ($ENV{'form.forceselect'}) {
                    124: 		    $r->print(<<ENDCHECKBOX);
                    125: <input type='checkbox' name='filelink' 
                    126: value='$url' onClick='javascript:queue("form$idx")' >
                    127: <input type='hidden' name='title' value='$title'>
                    128: ENDCHECKBOX
                    129:                 }
                    130: 		$r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
                    131:             }
                    132:             $r->print(&Apache::lonratsrv::qtescape($title));
                    133:             if ($url) { $r->print('</a>'); }
                    134:             if ($ENV{'form.forceselect'}) {
                    135: 		$r->print('</form>');
                    136:             } else {
                    137: 		$r->print('<br>');
                    138:             }
                    139:         }
                    140:     }
                    141:     $r->print('</body></html>');
                    142: }
                    143: 
1.1       www       144: # ================================================================ Main Handler
                    145: 
                    146: sub handler {
                    147:    my $r=shift;
                    148: 
                    149:    if ($r->header_only) {
                    150:       $r->content_type('text/html');
                    151:       $r->send_http_header;
                    152:       return OK;
                    153:    }
1.8       www       154:  
                    155:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    156:                                           ['forceselect']);
1.1       www       157: 
1.2       www       158:    my %hash;
1.1       www       159:    my %bighash;
1.2       www       160:    my $requrl=$r->uri;
                    161: 
1.3       www       162: # ------------------------------------------------------------ Tie symb db file
1.9       www       163:   my $disurl='';
                    164:   my $dismapid='';
                    165: 
                    166:   if (($ENV{'request.course.fn'}) && (!$ENV{'form.forceselect'})) {
1.2       www       167:        my $last;
                    168:        if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
                    169:                     &GDBM_READER,0640)) {
                    170: 	   $last=$hash{'last_direction'};
                    171:            untie(%hash);
                    172:        }
1.3       www       173:        my $direction='';
                    174:        my $prevmap='';
                    175:        if ($last) {
                    176: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
                    177:        }
                    178: # ------------------------------------------------------------- Tie big db file
1.1       www       179:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                    180:                     &GDBM_READER,0640)) {
1.3       www       181: 	   my $disid='';
1.10    ! www       182: 
1.3       www       183:            if ($direction eq 'back') {
                    184: 	       $disid=$bighash{'map_finish_'.$requrl};
                    185:            } else {
                    186:                $disid=$bighash{'map_start_'.$requrl};
                    187:            } 
                    188:            if ($disid) {
                    189: 	       $disurl=$bighash{'src_'.$disid};
1.4       www       190:                $dismapid=(split(/\./,$disid))[1];
1.3       www       191:            }
                    192: # --------------------------------------- Untie hash, make sure to come by here
                    193:            untie(%bighash);
1.9       www       194:        }
                    195:    }
                    196: 
                    197: # now either disurl is set (going to first page), or we need another display
                    198: 
                    199:    if ($disurl) {
1.3       www       200: # -------------------------------------------------- Has first or last resource
1.9       www       201:       &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
1.7       www       202:                    'last_known' => &Apache::lonnet::declutter($disurl)); 
1.9       www       203:       $r->content_type('text/html');
                    204:       $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
                    205:       return REDIRECT;
1.1       www       206:    } else {
1.9       www       207:        $r->content_type('text/html');
                    208:        $r->send_http_header;
                    209:        &viewmap($r,$requrl);
                    210:        return OK;
1.1       www       211:    }
                    212: }
                    213: 
                    214: 1;
                    215: __END__
                    216: 
                    217: 
                    218: 
                    219: 
                    220: 
                    221: 
                    222: 

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