Annotation of rat/lonsequence.pm, revision 1.8

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Sequence Handler
                      4: #
1.8     ! www         5: # $Id: lonsequence.pm,v 1.7 2002/04/02 21:17:34 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 {
        !            76:     my ($r,$url,$adv,$errtext)=@_;
        !            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: 
        !            99: 
        !           100: </script>
        !           101: ENDSCRIPT
        !           102:     }
        !           103:     $r->print('<body bgcolor="#FFFFFF">'.&buttons($adv));
        !           104:     if ($ENV{'form.forceselect'}) { $r->print(<<ENDSELECT);
        !           105: <form name=fileattr><input type=hidden name=acts value=''>
        !           106: <input type="button" name="close" value='CLOSE' onClick="self.close()">
        !           107: <input type="button" name="groupimport" value='GROUP IMPORT'
        !           108: onClick="javascript:select_group()">
        !           109: </form>   
        !           110: ENDSELECT
        !           111:     }
        !           112:     if ($errtext) {
        !           113: 	$r->print($errtext.'<hr>');
        !           114:     }
        !           115:     my $idx=0;
        !           116:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
        !           117: 	if (defined($_)) {
        !           118:             $idx++;
        !           119:             if ($ENV{'form.forceselect'}) { 
        !           120: 		$r->print('<form name="form'.$idx.'">');
        !           121:             }
        !           122: 	    my ($title,$url)=split(/\:/,$_);
        !           123:             $title=~s/\&colon\;/\:/g;
        !           124:             $url=~s/\&colon\;/\:/g;
        !           125:             unless ($title) { $title=(split(/\//,$url))[-1] };
        !           126:             unless ($title) { $title='<i>Empty</i>'; }
        !           127:             if ($url) {
        !           128: 		if ($ENV{'form.forceselect'}) {
        !           129: 		    $r->print(<<ENDCHECKBOX);
        !           130: <input type='checkbox' name='filelink' 
        !           131: value='$url' onClick='javascript:queue("form$idx")' >
        !           132: <input type='hidden' name='title' value='$title'>
        !           133: ENDCHECKBOX
        !           134:                 }
        !           135: 		$r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
        !           136:             }
        !           137:             $r->print(&Apache::lonratsrv::qtescape($title));
        !           138:             if ($url) { $r->print('</a>'); }
        !           139:             if ($ENV{'form.forceselect'}) {
        !           140: 		$r->print('</form>');
        !           141:             } else {
        !           142: 		$r->print('<br>');
        !           143:             }
        !           144:         }
        !           145:     }
        !           146:     $r->print('</body></html>');
        !           147: }
        !           148: 
1.1       www       149: # ================================================================ Main Handler
                    150: 
                    151: sub handler {
                    152:    my $r=shift;
                    153: 
                    154:    if ($r->header_only) {
                    155:       $r->content_type('text/html');
                    156:       $r->send_http_header;
                    157:       return OK;
                    158:    }
1.8     ! www       159:  
        !           160:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
        !           161:                                           ['forceselect']);
1.1       www       162: 
1.2       www       163:    my %hash;
1.1       www       164:    my %bighash;
1.2       www       165:    my $requrl=$r->uri;
                    166: 
1.3       www       167: # ------------------------------------------------------------ Tie symb db file
1.1       www       168:   if ($ENV{'request.course.fn'}) {
1.2       www       169:        my $last;
                    170:        if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
                    171:                     &GDBM_READER,0640)) {
                    172: 	   $last=$hash{'last_direction'};
                    173:            untie(%hash);
                    174:        }
1.3       www       175:        my $direction='';
                    176:        my $prevmap='';
                    177:        if ($last) {
                    178: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
                    179:        }
                    180: # ------------------------------------------------------------- Tie big db file
1.1       www       181:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                    182:                     &GDBM_READER,0640)) {
1.3       www       183: 	   my $disid='';
1.4       www       184:            my $whatend='';
1.3       www       185:            if ($direction eq 'back') {
                    186: 	       $disid=$bighash{'map_finish_'.$requrl};
1.4       www       187:                $whatend='End';
1.3       www       188:            } else {
                    189:                $disid=$bighash{'map_start_'.$requrl};
1.4       www       190:                $whatend='Beginning';
1.3       www       191:            } 
                    192:            my $disurl='';
1.4       www       193:            my $dismapid='';
1.3       www       194:            if ($disid) {
                    195: 	       $disurl=$bighash{'src_'.$disid};
1.4       www       196:                $dismapid=(split(/\./,$disid))[1];
1.3       www       197:            }
                    198:            my $symb='';
1.4       www       199:            my $sequencetitle='';
1.3       www       200:            unless($disurl) {
                    201:                if ($symb=&Apache::lonnet::symbread()) {
1.4       www       202: 		   my ($mapurl,$mapid)=split(/\_\_\_/,$symb);
                    203:                    $sequencetitle=$bighash{'title_'.
                    204: 				          $bighash{'map_pc_/res/'.$mapurl}.'.'.
                    205: 					  $mapid};
1.3       www       206:                }
                    207:            }
                    208: # --------------------------------------- Untie hash, make sure to come by here
                    209:            untie(%bighash);
                    210:            if ($disurl) {
                    211: # -------------------------------------------------- Has first or last resource
1.7       www       212:                &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
                    213:                    'last_known' => &Apache::lonnet::declutter($disurl)); 
1.3       www       214: 	       $r->content_type('text/html');
                    215:                $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
                    216:                return REDIRECT;
                    217:            } else {
                    218: # ---------- Does not have first or last resource, try to find out where we are
                    219:                unless ($symb) {
                    220: 		   $r->internal_redirect('/adm/ambiguous');
                    221:                }
                    222:                $r->content_type('text/html');
                    223:                $r->send_http_header;
                    224:                $r->print(<<ENDSYMB);
1.4       www       225: <html><body bgcolor="#FFFFFF">
                    226: <h2>$whatend of</h2>
                    227: <h1>$sequencetitle</h1>
1.3       www       228: </body></html>
                    229: ENDSYMB
                    230:                return OK
1.2       www       231:            }
1.1       www       232:        } else {
                    233:           &getlost($r,'Could not access course structure.');
                    234:           return OK;
                    235:        }
                    236:    } else {
                    237:       $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    238:       return HTTP_NOT_ACCEPTABLE; 
                    239:    }
                    240: 
                    241:    return OK;
                    242: }
                    243: 
                    244: 1;
                    245: __END__
                    246: 
                    247: 
                    248: 
                    249: 
                    250: 
                    251: 
                    252: 

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