File:  [LON-CAPA] / rat / lonsequence.pm
Revision 1.16: download - view: text, annotated - select for diffs
Mon Sep 22 03:02:06 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
Internationalizing.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Sequence Handler
    4: #
    5: # $Id: lonsequence.pm,v 1.16 2003/09/22 03:02:06 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: use Apache::loncommon;
   49: use Apache::lonlocal;
   50: 
   51: my %selhash;
   52: my $successtied;
   53: 
   54: # ----------------------------------------- Attempt to read from resource space
   55: 
   56: sub attemptread {
   57:     my $fn=shift;
   58:     &Apache::lonnet::repcopy($fn);
   59:     if (-e $fn) {
   60: 	return &Apache::lonratedt::attemptread($fn);
   61:     } else {
   62:         return ();
   63:     }
   64: }
   65: 
   66: sub mapread {
   67:     my $fn=shift;
   68:     &Apache::lonnet::repcopy($fn);
   69:     if (-e $fn) {
   70: 	return &Apache::lonratedt::mapread($fn,'');
   71:     } else {
   72:         return ();
   73:     }
   74: }
   75: 
   76: # ---------------------------------------------------------------- View Handler
   77: 
   78: sub viewmap {
   79:     my ($r,$url)=@_;
   80:     $r->print('<html>');
   81:     if ($ENV{'form.forceselect'}) { $r->print(<<ENDSCRIPT);
   82: <script>
   83: 
   84: function select_group() {
   85:     window.location="/adm/groupsort?catalogmode=groupsec&mode=rat&acts="+document.forms.fileattr.acts.value;
   86: }
   87: 
   88: function queue(val) {
   89:     if (eval("document.forms."+val+".filelink.checked")) {
   90: 	var l=val.length;
   91: 	var v=val.substring(4,l);
   92: 	document.forms.fileattr.acts.value+='1a'+v+'b';
   93:     }
   94:     else {
   95: 	var l=val.length;
   96: 	var v=val.substring(4,l);
   97: 	document.forms.fileattr.acts.value+='0a'+v+'b';
   98:     }
   99: }
  100: 
  101: </script>
  102: ENDSCRIPT
  103:     }
  104:     $r->print(&Apache::loncommon::bodytag('Map Contents').'<h1>'.$url.'</h1>');
  105: # ------------------ This is trying to select. Provide buttons and tie %selhash
  106:     if ($ENV{'form.forceselect'}) { $r->print(<<ENDSELECT);
  107: <form name=fileattr><input type=hidden name=acts value=''>
  108: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  109: <input type="button" name="groupimport" value='GROUP IMPORT'
  110: onClick="javascript:select_group()">
  111: </form>   
  112: ENDSELECT
  113:     my $diropendb = 
  114:     "/home/httpd/perl/tmp/$ENV{'user.domain'}\_$ENV{'user.name'}_groupsec.db";
  115:         if (tie(%selhash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
  116: 	    if ($ENV{'form.launch'} eq '1') {
  117: 	       &start_fresh_session();
  118: 	    }
  119:             $successtied=1;
  120: 
  121: # - Evaluate actions from previous page (both cumulatively and chronologically)
  122:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
  123: 	    my $acts=$ENV{'form.acts'};
  124: 	    my @Acts=split(/b/,$acts);
  125: 	    my %ahash;
  126: 	    my %achash;
  127: 	    my $ac=0;
  128: 	    # some initial hashes for working with data
  129: 	    foreach (@Acts) {
  130: 		my ($state,$ref)=split(/a/);
  131: 		$ahash{$ref}=$state;
  132: 		$achash{$ref}=$ac;
  133: 		$ac++;
  134: 	    }
  135: 	    # sorting through the actions and changing the tied database hash
  136: 	    foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
  137: 		my $key=$_;
  138: 		if ($ahash{$key} eq '1') {
  139: 		    $selhash{'store_'.$selhash{'pre_'.$key.'_link'}}=
  140: 			$selhash{'pre_'.$key.'_title'};
  141: 		    $selhash{'storectr_'.$selhash{'pre_'.$key.'_link'}}=
  142: 			$selhash{'storectr'}+0;
  143: 		    $selhash{'storectr'}++;
  144: 		}
  145: 		if ($ahash{$key} eq '0') {
  146: 		    if ($selhash{'store_'.$selhash{'pre_'.$key.'_link'}}) {
  147: 		       delete $selhash{'store_'.$selhash{'pre_'.$key.'_link'}};
  148: 		    }
  149: 		}
  150: 	    }
  151: 	    # deleting the previously cached listing
  152: 	    foreach (keys %selhash) {
  153: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
  154: 		    my $key = $_;
  155: 		    $key =~ s/^pre_//;
  156: 		    $key =~ s/_[^_]*$//;
  157: 		    delete $selhash{'pre_'.$key.'_title'};
  158: 		    delete $selhash{'pre_'.$key.'_link'};
  159: 		}
  160: 	    }
  161: 	}
  162: # -
  163:         }
  164:     }
  165: # ----------------------------- successtied is now '1' if in working selectmode
  166:     my ($errtext,$fatal)=&mapread(&Apache::lonnet::filelocation('',$url),'');
  167:     if ($fatal==1) {
  168:        $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
  169:     }
  170:     my $idx=0;
  171:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
  172: 	if (defined($_)) {
  173:             $idx++;
  174:             if ($successtied) { 
  175: 		$r->print('<form name="form'.$idx.'">');
  176:             }
  177: 	    my ($title,$url)=split(/\:/,$_);
  178:             $title=~s/\&colon\;/\:/g;
  179:             $url=~s/\&colon\;/\:/g;
  180:             unless ($title) { $title=(split(/\//,$url))[-1] };
  181:             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
  182:             if ($url) {
  183: 		if ($successtied) {
  184: 		    my $checked='';
  185: 	           if ($selhash{'store_'.$url}) {
  186: 	       	      $checked=" checked";
  187: 	           }
  188: 	           $selhash{"pre_${idx}_link"}=$url;
  189: 	           $selhash{"pre_${idx}_title"}=$title;
  190: 
  191: 		    $r->print(<<ENDCHECKBOX);
  192: <input type='checkbox' name='filelink' 
  193: value='$url' onClick='javascript:queue("form$idx")'$checked>
  194: <input type='hidden' name='title' value='$title'>
  195: ENDCHECKBOX
  196:                 }
  197: 		$r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
  198:             }
  199:             $r->print(&Apache::lonratsrv::qtescape($title));
  200:             if ($url) { $r->print('</a>'); }
  201:             if ($successtied) {
  202: 		$r->print('</form>');
  203:             } else {
  204: 		$r->print('<br>');
  205:             }
  206:         }
  207:     }
  208:     $r->print('</body></html>');
  209:     if ($successtied) {
  210: 	untie %selhash;
  211:     }
  212: }
  213: 
  214: # ----------------------------------------------------------- Clean out selhash
  215: sub start_fresh_session {
  216:     foreach (keys %selhash) {
  217: 	if ($_ =~ /^pre_/) {
  218: 	    delete $selhash{$_};
  219: 	}
  220: 	if ($_ =~ /^store/) {
  221: 	    delete $selhash{$_};
  222: 	}
  223:     }
  224: }
  225: 
  226: 
  227: # ================================================================ Main Handler
  228: 
  229: sub handler {
  230:    my $r=shift;
  231: 
  232:    if ($r->header_only) {
  233:       &Apache::loncommon::content_type($r,'text/html');
  234:       $r->send_http_header;
  235:       return OK;
  236:    }
  237:  
  238:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  239:                                           ['forceselect','launch']);
  240: 
  241:    my %hash;
  242:    my %bighash;
  243:    my $requrl=$r->uri;
  244: 
  245:    $successtied=0;
  246: # ------------------------------------------------------------ Tie symb db file
  247:   my $disurl='';
  248:   my $dismapid='';
  249: 
  250:   if (($ENV{'request.course.fn'}) && (!$ENV{'form.forceselect'})) {
  251:        my $last;
  252:        if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
  253:                     &GDBM_READER(),0640)) {
  254: 	   $last=$hash{'last_direction'};
  255:            untie(%hash);
  256:        }
  257:        my $direction='';
  258:        my $prevmap='';
  259:        if ($last) {
  260: 	  ($prevmap,$direction)=(split(/\_\_\_/,$last));
  261:        }
  262: # ------------------------------------------------------------- Tie big db file
  263:        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
  264:                     &GDBM_READER(),0640)) {
  265: 	   my $disid='';
  266: 
  267:            if ($direction eq 'back') {
  268: 	       $disid=$bighash{'map_finish_'.$requrl};
  269:            } else {
  270:                $disid=$bighash{'map_start_'.$requrl};
  271:            } 
  272:            if ($disid) {
  273: 	       $disurl=$bighash{'src_'.$disid};
  274:                $dismapid=(split(/\./,$disid))[1];
  275:            }
  276: # ------------------------- If this is an empty one, skip to next non-empty one
  277:            if ((!$disurl) && ($disid)) {
  278: 	       $direction=($direction?$direction:'forward');
  279:                ($disid,$requrl)=
  280:                          &Apache::lonpageflip::fullmove($disid,
  281:                            &Apache::lonnet::declutter($requrl),$direction);
  282:                if ($disid) {
  283: 	           $disurl=$bighash{'src_'.$disid};
  284:                    $dismapid=(split(/\./,$disid))[1];
  285:                }
  286:  	   }
  287: 
  288: # --------------------------------------- Untie hash, make sure to come by here
  289:            untie(%bighash);
  290:        }
  291:    }
  292: 
  293: # now either disurl is set (going to first page), or we need another display
  294: 
  295:    if ($disurl) {
  296: # -------------------------------------------------- Has first or last resource
  297:       &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
  298:                    'last_known' => &Apache::lonnet::declutter($disurl)); 
  299:       &Apache::loncommon::content_type($r,'text/html');
  300:       $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
  301:       return REDIRECT;
  302:    } else {
  303:        &Apache::loncommon::content_type($r,'text/html');
  304:        $r->send_http_header;
  305:        &viewmap($r,$requrl);
  306:        return OK;
  307:    }
  308: }
  309: 
  310: 1;
  311: __END__
  312: 
  313: 
  314: 
  315: 
  316: 
  317: 
  318: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.