File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.64: download - view: text, annotated - select for diffs
Fri Dec 10 19:59:55 2004 UTC (19 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- pass symb along

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

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