File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.71: download - view: text, annotated - select for diffs
Wed Jun 29 19:02:14 2005 UTC (18 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- discussion per reource on a page was happening

    1: # The LearningOnline Network with CAPA
    2: # Page Handler
    3: #
    4: # $Id: lonpage.pm,v 1.71 2005/06/29 19:02:14 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::lonpage;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http);
   34: use Apache::lonnet;
   35: use Apache::loncommon();
   36: use Apache::lonxml();
   37: use Apache::lonlocal;
   38: use Apache::lonmenu;
   39: use HTML::TokeParser;
   40: use GDBM_File;
   41: use Apache::lonsequence;
   42: 
   43: # -------------------------------------------------------------- Module Globals
   44: my %hash;
   45: my @rows;
   46: 
   47: # ------------------------------------------------------------------ Euclid gcd
   48: 
   49: sub euclid {
   50:     my ($e,$f)=@_;
   51:     my $a; my $b; my $r;
   52:     if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
   53:     while ($r!=0) {
   54: 	$a=$b; $b=$r;
   55:         $r=$a%$b;
   56:     }
   57:     return $b;
   58: }
   59: 
   60: # ------------------------------------------------------------ Build page table
   61: 
   62: sub tracetable {
   63:     my ($sofar,$rid,$beenhere)=@_;
   64:     my $further=$sofar;
   65:     my $randomout=0;
   66:     unless ($env{'request.role.adv'}) {
   67:         $randomout = $hash{'randomout_'.$rid};
   68:     }
   69:     unless ($beenhere=~/\&$rid\&/) {
   70:         $beenhere.=$rid.'&';
   71:         unless ($randomout) {
   72:             if (defined($hash{'is_map_'.$rid})) {
   73:                 if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
   74:                     (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
   75:                     my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
   76: 	            $sofar=
   77:                        &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
   78:                        '&'.$frid.'&');
   79:                     $sofar++;
   80:                     if ($hash{'src_'.$frid}) {
   81:                         my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
   82:                         if (($brepriv eq '2') || ($brepriv eq 'F')) {
   83:                             if (defined($rows[$sofar])) {
   84:                                 $rows[$sofar].='&'.$frid;
   85:                             } else {
   86:                                 $rows[$sofar]=$frid;
   87:                             }
   88: 	                }
   89: 	            }
   90: 	        }
   91:             } else {
   92:                 $sofar++;
   93:                 if ($hash{'src_'.$rid}) {
   94:                     my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
   95:                     if (($brepriv eq '2') || ($brepriv eq 'F')) {
   96:                         if (defined($rows[$sofar])) {
   97:                             $rows[$sofar].='&'.$rid;
   98:                         } else {
   99:                             $rows[$sofar]=$rid;
  100:                         }
  101: 	            }
  102:                 }
  103:             }
  104:         }
  105: 
  106:         if (defined($hash{'to_'.$rid})) {
  107: 	    my $mincond=1;
  108:             my $next='';
  109:             foreach (split(/\,/,$hash{'to_'.$rid})) {
  110:                 my $thiscond=
  111:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
  112:                 if ($thiscond>=$mincond) {
  113: 		    if ($next) {
  114: 		        $next.=','.$_.':'.$thiscond;
  115:                     } else {
  116:                         $next=$_.':'.$thiscond;
  117: 		    }
  118:                     if ($thiscond>$mincond) { $mincond=$thiscond; }
  119: 	        }
  120:             }
  121:             foreach (split(/\,/,$next)) {
  122:                 my ($linkid,$condval)=split(/\:/,$_);
  123:                 if ($condval>=$mincond) {
  124:                     my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
  125:                     if ($now>$further) { $further=$now; }
  126: 	        }
  127:             }
  128:         }
  129:     }
  130:     return $further;
  131: }
  132: 
  133: # ================================================================ Main Handler
  134: 
  135: sub handler {
  136:   my $r=shift;
  137: 
  138: # ------------------------------------------- Set document type for header only
  139: 
  140:   if ($r->header_only) {
  141:        if ($env{'browser.mathml'}) {
  142:            &Apache::loncommon::content_type($r,'text/xml');
  143:        } else {
  144:            &Apache::loncommon::content_type($r,'text/html'); 
  145:        }
  146:        $r->send_http_header;
  147:        return OK;
  148:    }
  149:   
  150:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  151:                                           ['forceselect','launch']);
  152:   my $number_of_columns = 1;
  153:   my $requrl=$r->uri;  
  154:   my $target = $env{'form.grade_target'};
  155: #  &Apache::lonnet::logthis("Got a target of $target");
  156:   if ($target eq 'meta') {
  157:       &Apache::loncommon::content_type($r,'text/html');
  158:       $r->send_http_header;
  159:       return OK;
  160:   }
  161: # ----------------------------------------------------------------- Tie db file
  162:   if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
  163:       my $fn=$env{'request.course.fn'};
  164:       if (-e "$fn.db") {
  165:           if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
  166: # ------------------------------------------------------------------- Hash tied
  167:               my $firstres=$hash{'map_start_'.$requrl};
  168:               my $lastres=$hash{'map_finish_'.$requrl};
  169:               if (($firstres) && ($lastres)) {
  170: # ----------------------------------------------------------------- Render page
  171: 
  172:                   @rows=();
  173: 
  174:                   &tracetable(0,$firstres,'&');
  175: 
  176: # ------------------------------------------------------------ Add to symb list
  177: 
  178:                   my $i;
  179:                   my %symbhash=();
  180:                   for ($i=0;$i<=$#rows;$i++) {
  181: 		     if ($rows[$i]) {
  182:                         my @colcont=split(/\&/,$rows[$i]);
  183:                         foreach (@colcont) {
  184:                            $symbhash{$hash{'src_'.$_}}=['page','notasymb'];
  185: 		        }
  186: 		     }
  187: 		  }
  188:                   &Apache::lonnet::symblist($requrl,%symbhash);
  189: 
  190: # ------------------------------------------------------------------ Page parms
  191: 
  192:                   my $j;
  193:                   my $lcm=1;
  194:                   my $contents=0;
  195:                   my $nforms=0;
  196:                   
  197:                   my %ssibody=();
  198:                   my %ssibgcolor=();
  199:                   my %ssitext=();
  200:                   my %ssilink=();
  201:                   my %ssivlink=();
  202:                   my %ssialink=();
  203:      
  204:                   my %metalink=();
  205: 
  206:                   my %cellemb=();
  207: 
  208:                   my $allscript='';
  209:                   my $allmeta='';
  210: 
  211:                   my $isxml=0;
  212:                   my $xmlheader='';
  213:                   my $xmlbody='';
  214: 
  215: # --------------------------------------------- Get SSI output, post parameters
  216: 
  217:                   for ($i=0;$i<=$#rows;$i++) {
  218: 		     if ($rows[$i]) {
  219: 		      $contents++;
  220:                       my @colcont=split(/\&/,$rows[$i]);
  221:                       $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
  222:                       foreach (@colcont) {
  223:                           my $src=$hash{'src_'.$_};
  224: 			  my ($extension)=($src=~/\.(\w+)$/);
  225: 			  if ($hash{'encrypted_'.$_}) {
  226: 			      $src=&Apache::lonenc::encrypted($src);
  227: 			  }
  228:                           $metalink{$_}=$src.'.meta';
  229:                           $cellemb{$_}=
  230: 			      &Apache::loncommon::fileembstyle($extension);
  231:                           if ($cellemb{$_} eq 'ssi') {
  232: # --------------------------------------------------------- This is an SSI cell
  233: 			      my ($mapid,$resid)=split(/\./,$_);
  234: 			      my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
  235: 			      
  236: 			      my $prefix=$_.'_';
  237:                               my %posthash=('request.prefix' => $prefix,
  238: 					    'LONCAPA_INTERNAL_no_discussion' => 'true',
  239: 					    'symb' => $symb);
  240: 			      if ($env{'form.grade_target'} eq 'tex') {
  241: 				  $posthash{'grade_target'}=$env{'form.grade_target'};
  242: 				  $posthash{'textwidth'}=$env{'form.textwidth'};
  243: 				  $posthash{'problem_split'}=$env{'form.problem_split'};
  244: 				  $posthash{'latex_type'}=$env{'form.latex_type'};
  245: 				  $posthash{'rndseed'}=$env{'form.rndseed'};
  246: 			      }
  247:                               if (($env{'form.'.$prefix.'submit'}) 
  248:                                || ($env{'form.all_submit'})) {
  249:                                foreach (keys %env) {
  250: 				  if ($_=~/^form.$prefix/) {
  251: 				      my $name=$_;
  252:                                       $name=~s/^form.$prefix//;
  253:                                       $posthash{$name}=$env{$_};
  254:                                   }
  255:                                }
  256: 			      }
  257:                               my $output=Apache::lonnet::ssi($src,%posthash);
  258: 			      $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+// END LON-CAPA Internal\s*(-->)?\s||gs;
  259:                               if ($target eq 'tex') {
  260: 				  $output =~ s/^([^&]+)\\begin{document}//;
  261: 				  $output =~ s/\\end{document}//;
  262: 				  $output = '\parbox{\minipagewidth}{ '.$output.' }';
  263:                                   #some additional cleanup necessary for LateX (due to limitations of table environment 
  264: 				  $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
  265: 			      }
  266:                               my $parser=HTML::TokeParser->new(\$output);
  267:                               my $token;
  268:                               my $thisdir=$src;
  269:                               my $bodydef=0;
  270:                               my $thisxml=0;
  271:                               my @rlinks=();
  272:                               if ($output=~/\?xml/) {
  273:                                  $isxml=1;
  274:                                  $thisxml=1;
  275:                                  $output=~
  276:          /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
  277:                                  $xmlheader=$1;
  278: 			      }
  279:                               while ($token=$parser->get_token) {
  280: 				if ($token->[0] eq 'S') {
  281:                                   if ($token->[1] eq 'a') {
  282: 				      if ($token->[2]->{'href'}) {
  283:                                          $rlinks[$#rlinks+1]=
  284: 					     $token->[2]->{'href'};
  285: 				      }
  286: 				  } elsif ($token->[1] eq 'img') {
  287:                                          $rlinks[$#rlinks+1]=
  288: 					     $token->[2]->{'src'};
  289: 				  } elsif ($token->[1] eq 'embed') {
  290:                                          $rlinks[$#rlinks+1]=
  291: 					     $token->[2]->{'src'};
  292: 				  } elsif ($token->[1] eq 'base') {
  293: 				      $thisdir=$token->[2]->{'href'};
  294: 				  } elsif ($token->[1] eq 'body') {
  295: 				      $bodydef=1;
  296:                                       $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
  297:                                       $ssitext{$_}=$token->[2]->{'text'};
  298:                                       $ssilink{$_}=$token->[2]->{'link'};
  299:                                       $ssivlink{$_}=$token->[2]->{'vlink'};
  300:                                       $ssialink{$_}=$token->[2]->{'alink'};
  301:                                       if ($thisxml) {
  302: 					  $xmlbody=$token->[4];
  303:                                       }
  304:                                   } elsif ($token->[1] eq 'meta') {
  305: 				    if ($token->[4] !~ m:/>$:) {
  306: 				      $allmeta.="\n".$token->[4].'</meta>';
  307: 				    } else {
  308: 				      $allmeta.="\n".$token->[4];
  309: 				    }
  310:                                   } elsif (($token->[1] eq 'script') &&
  311:                                            ($bodydef==0)) {
  312: 				      $allscript.="\n\n"
  313:                                                 .$parser->get_text('/script');
  314:                                   }
  315: 			        }
  316: 			      }
  317:                               if ($output=~/\<body[^\>]*\>(.*)/si) {
  318:                                  $output=$1; 
  319:                               }
  320:                               $output=~s/\<\/body\>.*//si;
  321:                               if ($output=~/\<form/si) {
  322: 				  $nforms++;
  323:                                   $output=~s/\<form[^\>]*\>//gsi;
  324:                                   $output=~s/\<\/form[^\>]*\>//gsi;
  325:                                   $output=~
  326: 				      s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([\w\.\:]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
  327:                               }
  328:                               $thisdir=~s/\/[^\/]*$//;
  329: 			      foreach (@rlinks) {
  330: 				  unless (($_=~/^http:\/\//i) ||
  331: 					  ($_=~/^\//) ||
  332: 					  ($_=~/^javascript:/i) ||
  333: 					  ($_=~/^mailto:/i) ||
  334: 					  ($_=~/^\#/)) {
  335: 				      my $newlocation=
  336: 				    &Apache::lonnet::hreflocation($thisdir,$_);
  337:                      $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
  338: 				  }
  339: 			      }
  340: # -------------------------------------------------- Deal with Applet codebases
  341:   $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
  342: 			      $ssibody{$_}=$output;
  343: # ---------------------------------------------------------------- End SSI cell
  344:                           }
  345:                       }
  346:                      } 
  347:                   }
  348:                   unless ($contents) {
  349:                       &Apache::loncommon::content_type($r,'text/html');
  350:                       $r->send_http_header;
  351:                       $r->print('<html>'."\n".
  352:                                 '<head>'."\n".
  353:                                 &Apache::lonmenu::registerurl(1,undef)."\n".
  354:                                 '</head>'."\n".
  355:                                 '<body bgcolor="#FFFFFF" onLoad="'
  356:                                 .&Apache::lonmenu::loadevents.
  357:                                 '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.
  358:                                  &Apache::lonmenu::menubuttons(undef,$target,1)
  359:                                );
  360:                       $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
  361:                       $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').'.</body></html>');
  362:                   } else {
  363: # ------------------------------------------------------------------ Build page
  364: 
  365: # ---------------------------------------------------------------- Send headers
  366: 		      unless ($target eq 'tex') {
  367: 			  if ($isxml) {
  368: 			      &Apache::loncommon::content_type($r,'text/xml');
  369: 			      $r->send_http_header;
  370: 			      $r->print($xmlheader);
  371: 			  } else {
  372: 			      &Apache::loncommon::content_type($r,'text/html');
  373: 			      $r->send_http_header;
  374: 			      $r->print('<html>');
  375: 			  }
  376: # ------------------------------------------------------------------------ Head
  377: 			  $r->print("\n<head>\n".$allmeta);
  378: 			  if ($allscript) {
  379: 			      $r->print("\n<script language='JavaScript'>\n".
  380: 					$allscript."\n</script>\n");
  381: 			  }
  382: 			  $r->print(&Apache::lonmenu::registerurl(1,undef));
  383: 			  $r->print("\n</head>\n");
  384: # ------------------------------------------------------------------ Start body
  385: 			  if ($isxml) {
  386: 			      $r->print($xmlbody);
  387: 			  } else {
  388: 			      $r->print(
  389:                '<body bgcolor="#FFFFFF" onLoad="'.&Apache::lonmenu::loadevents.
  390:                '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.
  391:                               &Apache::lonmenu::menubuttons(undef,$target,1)
  392: 					);
  393: 			  }
  394: # ------------------------------------------------------------------ Start form
  395: 			  if ($nforms) {
  396: 			      $r->print('<form method="post" action="'.
  397: 					&Apache::lonenc::check_encrypt($requrl)
  398: 					.'">');
  399: 			  }
  400: 		      } elsif ($target eq 'tex') {
  401: 			  $r->print('\documentclass{article}
  402:                                  \newcommand{\keephidden}[1]{}           
  403:                                  \usepackage[dvips]{graphicx}
  404:                                  \usepackage{epsfig}
  405:                                  \usepackage{calc}
  406:                                  \usepackage{longtable}
  407:                                  \begin{document}');
  408: 		      }
  409: # ----------------------------------------------------------------- Start table
  410: 		      if ($target eq 'tex') {
  411: 			  $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
  412: 			  if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
  413: 		      } else {
  414: 			  $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
  415: 		      }
  416:                       for ($i=0;$i<=$#rows;$i++) {
  417: 			if ($rows[$i]) {
  418: 			    unless ($target eq 'tex') {
  419: 				$r->print("\n<tr>");
  420: 			    }
  421:                           my @colcont=split(/\&/,$rows[$i]);
  422:                           my $avespan=$lcm/($#colcont+1);
  423:                           for ($j=0;$j<=$#colcont;$j++) {
  424:                               my $rid=$colcont[$j];
  425:                               my $metainfo = '';
  426: 			      my $esrc=&Apache::lonnet::declutter($hash{'src_'.$rid});
  427: 			      my ($mapid,$resid)=split(/\./,$rid);
  428: 			      my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid});
  429: 			      if ($hash{'encrypted_'.$rid}) {
  430: 				  $symb=&Apache::lonenc::encrypted($symb);
  431: 				  $esrc=&Apache::lonenc::encrypted($esrc);
  432: 			      }
  433:                               unless ($hash{'src_'.$rid} =~ m-^/uploaded/-) { 
  434:                                   $metainfo ='<a name="'.&Apache::lonnet::escape($symb).'" />'.
  435:                                   '<a href="'.$metalink{$rid}.'" target="LONcatInfo">'.
  436:                                   '<img src="/adm/lonMisc/cat_button.gif" border=0>'.
  437:                                   '</img></a>';
  438:                               }
  439:                               $metainfo .= '<a href="/adm/evaluate?postdata='.
  440: 				  &Apache::lonnet::escape($esrc).
  441:                                   '" target="LONcatInfo">'.
  442:                                   '<img src="/adm/lonMisc/eval_button.gif" border=0>'.
  443:                                   '</img></a>';
  444:                               if (
  445:  ($hash{'src_'.$rid}=~/\.(problem|exam|quiz|assess|survey|form)$/) &&
  446:  (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && 
  447:  ($hash{'src_'.$rid} !~ m-^/uploaded/-)) {
  448: 				  my ($mapid,$resid)=split(/\./,$rid);
  449:                                  my $symb=
  450:                 &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
  451:                 '___'.$resid.'___'.
  452: 		&Apache::lonnet::declutter($hash{'src_'.$rid});
  453:                                  $metainfo.=
  454:                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).
  455: #                 '&command=submission" target="LONcatInfo">'.
  456:                   '&command=submission">'.
  457:                           '<img src="/adm/lonMisc/subm_button.gif" border=0>'.
  458: 			  '</img></a>'.
  459:                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).
  460: #                  '&command=gradingmenu" target="LONcatInfo">'.
  461:                   '&command=gradingmenu">'.
  462:                           '<img src="/adm/lonMisc/pgrd_button.gif" border=0>'.
  463: 			  '</img></a>'.
  464:                   '<a href="/adm/parmset?symb='.&Apache::lonnet::escape($symb).
  465: #                          '" target="LONcatInfo">'.
  466:                           '" >'.
  467:                           '<img src="/adm/lonMisc/pprm_button.gif" border=0>'.
  468: 			      '</img></a>';
  469:                               }
  470:                               $metainfo.='<br></br>';
  471: 			    unless ($target eq 'tex') {
  472: 				$r->print('<td colspan="'.$avespan.'"');
  473: 			    }
  474:                               if ($cellemb{$rid} eq 'ssi') {
  475: 				  unless ($target eq 'tex') {
  476: 				      if ($ssibgcolor{$rid}) {
  477: 					  $r->print(' bgcolor="'.
  478: 						    $ssibgcolor{$rid}.'"');
  479: 				      }
  480: 				      $r->print('>'.$metainfo.'<font');
  481: 		    
  482: 				      if ($ssitext{$rid}) {
  483: 					  $r->print(' text="'.$ssitext{$rid}.'"');
  484: 				      }
  485: 				      if ($ssilink{$rid}) {
  486: 					  $r->print(' link="'.$ssilink{$rid}.'"');
  487: 				      }
  488: 				      if ($ssitext{$rid}) {
  489: 					  $r->print(' vlink="'.$ssivlink{$rid}.'"');
  490: 				      }
  491: 				      if ($ssialink{$rid}) {
  492: 					  $r->print(' alink="'.$ssialink{$rid}.'"');
  493: 				      }             
  494: 				      $r->print('>');
  495: 				  }
  496:                                   $r->print($ssibody{$rid});	
  497: 				  unless ($target eq 'tex') {
  498: 				      $r->print('</font>');
  499:                                   }
  500:                                   if ($env{'course.'.
  501:                                       $env{'request.course.id'}.
  502:                                       '.pageseparators'} eq 'yes') {
  503:                                       unless($target eq 'tex') {
  504:                                           $r->print('<hr />');
  505:                                       } else {
  506:                                           $r->print('\hline');
  507:                                       }
  508: 				  }
  509: 			      } elsif ($cellemb{$rid} eq 'img') {
  510:                                   $r->print('>'.$metainfo.'<img src="'.
  511:                                     $hash{'src_'.$rid}.'"></img>');
  512: 			      } elsif ($cellemb{$rid} eq 'emb') {
  513:                                   $r->print('>'.$metainfo.'<embed src="'.
  514:                                     $hash{'src_'.$rid}.'"></embed>');
  515:                               } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
  516:                                   $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />'.
  517:                                   &mt('It is recommended that you use an up-to-date virus scanner before handling this file.').'</p><p><table>'.
  518:                                   &Apache::londocs::entryline(0,&mt("Click to download or use your browser's Save Link function"),'/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).'</table></p><br />');
  519:                               }
  520: 			      unless ($target eq 'tex') {
  521: 				  $r->print('</td>');
  522: 			      } else {
  523:                                   for (my $incol=1;$incol<=$avespan;$incol++) {
  524: 				      $r->print(' & ');
  525: 				  }
  526: 			      }
  527:                           }
  528: 			      unless ($target eq 'tex') {
  529: 				  $r->print('</tr>');
  530: 			      } else {
  531: 				  $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
  532: 			      }
  533: 		        }
  534:                       }
  535: 		      unless ($target eq 'tex') {
  536: 			  $r->print("\n</table>");
  537: 		      } else {
  538: 			  $r->print('\end{longtable}\strut');
  539: 		      }
  540: # ---------------------------------------------------------------- Submit, etc.
  541:                       if ($nforms) {
  542:                           $r->print(
  543: 	                  '<input name="all_submit" value="Submit All" type="'.
  544: 			  (($nforms>1)?'submit':'hidden').'"></input></form>');
  545:                       }
  546: 		      unless ($target eq 'tex') {
  547: 			  $r->print('</body>'.&Apache::lonxml::xmlend());
  548: 		      } else {
  549: 			  $r->print('\end{document}'.$number_of_columns);
  550: 		      }
  551: 		      &Apache::lonnet::symblist($requrl,%symbhash);
  552: 		      my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  553: 		      &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
  554: # -------------------------------------------------------------------- End page
  555:                   }                  
  556: # ------------------------------------------------------------- End render page
  557:               } else {
  558:                   &Apache::loncommon::content_type($r,'text/html');
  559:                   $r->send_http_header;
  560:                   &Apache::lonsequence::viewmap($r,$requrl);
  561:               }
  562: # ------------------------------------------------------------------ Untie hash
  563:               unless (untie(%hash)) {
  564:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  565:                        "Could not untie coursemap $fn (browse).</font>"); 
  566:               }
  567: # -------------------------------------------------------------------- All done
  568: 	      return OK;
  569: # ----------------------------------------------- Errors, hash could no be tied
  570:           }
  571:       } 
  572:   }
  573:   &Apache::loncommon::content_type($r,'text/html');
  574:   $r->send_http_header;
  575:   &Apache::lonsequence::viewmap($r,$requrl);
  576:   return OK; 
  577: }
  578: 
  579: 1;
  580: __END__
  581: 
  582: =head1 NAME
  583: 
  584: Apache::lonpage - Page Handler
  585: 
  586: =head1 SYNOPSIS
  587: 
  588: Invoked by /etc/httpd/conf/srm.conf:
  589: 
  590:  <LocationMatch "^/res/.*\.page$>
  591:  SetHandler perl-script
  592:  PerlHandler Apache::lonpage
  593:  </LocationMatch>
  594: 
  595: =head1 INTRODUCTION
  596: 
  597: This module renders a .page resource.
  598: 
  599: This is part of the LearningOnline Network with CAPA project
  600: described at http://www.lon-capa.org.
  601: 
  602: =head1 HANDLER SUBROUTINE
  603: 
  604: This routine is called by Apache and mod_perl.
  605: 
  606: =over 4
  607: 
  608: =item *
  609: 
  610: set document type for header only
  611: 
  612: =item *
  613: 
  614: tie db file
  615: 
  616: =item *
  617: 
  618: render page
  619: 
  620: =item *
  621: 
  622: add to symb list
  623: 
  624: =item *
  625: 
  626: page parms
  627: 
  628: =item *
  629: 
  630: Get SSI output, post parameters
  631: 
  632: =item *
  633: 
  634: SSI cell rendering
  635: 
  636: =item *
  637: 
  638: Deal with Applet codebases
  639: 
  640: =item *
  641: 
  642: Build page
  643: 
  644: =item *
  645: 
  646: send headers
  647: 
  648: =item *
  649: 
  650: start body
  651: 
  652: =item *
  653: 
  654: start form
  655: 
  656: =item *
  657: 
  658: start table
  659: 
  660: =item *
  661: 
  662: submit element, etc, render page, untie hash
  663: 
  664: =back
  665: 
  666: =head1 OTHER SUBROUTINES
  667: 
  668: =over 4
  669: 
  670: =item *
  671: 
  672: euclid() : Euclid's method for determining the greatest common denominator.
  673: 
  674: =item *
  675: 
  676: tracetable() : Build page table.
  677: 
  678: =back
  679: 
  680: =cut
  681: 
  682: 
  683: 
  684: 

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