File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.73: download - view: text, annotated - select for diffs
Wed Jan 11 09:13:15 2006 UTC (18 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, version_2_1_1, HEAD
- BUG#4560 can't view submissions/grades from .pages

    1: # The LearningOnline Network with CAPA
    2: # Page Handler
    3: #
    4: # $Id: lonpage.pm,v 1.73 2006/01/11 09:13:15 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 my $rid (@colcont) {
  184: 			    my ($mapid,$resid)=split(/\./,$rid);
  185: 			    $symbhash{$hash{'src_'.$rid}}=
  186: 				[$hash{'src_'.$rid},$resid];
  187: 		        }
  188: 		     }
  189: 		  }
  190:                   &Apache::lonnet::symblist($requrl,%symbhash);
  191: 
  192: # ------------------------------------------------------------------ Page parms
  193: 
  194:                   my $j;
  195:                   my $lcm=1;
  196:                   my $contents=0;
  197:                   my $nforms=0;
  198:                   
  199:                   my %ssibody=();
  200:                   my %ssibgcolor=();
  201:                   my %ssitext=();
  202:                   my %ssilink=();
  203:                   my %ssivlink=();
  204:                   my %ssialink=();
  205:      
  206:                   my %metalink=();
  207: 
  208:                   my %cellemb=();
  209: 
  210:                   my $allscript='';
  211:                   my $allmeta='';
  212: 
  213:                   my $isxml=0;
  214:                   my $xmlheader='';
  215:                   my $xmlbody='';
  216: 
  217: # --------------------------------------------- Get SSI output, post parameters
  218: 
  219:                   for ($i=0;$i<=$#rows;$i++) {
  220: 		     if ($rows[$i]) {
  221: 		      $contents++;
  222:                       my @colcont=split(/\&/,$rows[$i]);
  223:                       $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
  224:                       foreach (@colcont) {
  225:                           my $src=$hash{'src_'.$_};
  226: 			  my ($extension)=($src=~/\.(\w+)$/);
  227: 			  if ($hash{'encrypted_'.$_}) {
  228: 			      $src=&Apache::lonenc::encrypted($src);
  229: 			  }
  230:                           $metalink{$_}=$src.'.meta';
  231:                           $cellemb{$_}=
  232: 			      &Apache::loncommon::fileembstyle($extension);
  233:                           if ($cellemb{$_} eq 'ssi') {
  234: # --------------------------------------------------------- This is an SSI cell
  235: 			      my ($mapid,$resid)=split(/\./,$_);
  236: 			      my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
  237: 			      
  238: 			      my $prefix=$_.'_';
  239:                               my %posthash=('request.prefix' => $prefix,
  240: 					    'LONCAPA_INTERNAL_no_discussion' => 'true',
  241: 					    'symb' => $symb);
  242: 			      if ($env{'form.grade_target'} eq 'tex') {
  243: 				  $posthash{'grade_target'}=$env{'form.grade_target'};
  244: 				  $posthash{'textwidth'}=$env{'form.textwidth'};
  245: 				  $posthash{'problem_split'}=$env{'form.problem_split'};
  246: 				  $posthash{'latex_type'}=$env{'form.latex_type'};
  247: 				  $posthash{'rndseed'}=$env{'form.rndseed'};
  248: 			      }
  249: 			      my $submitted=exists($env{'form.all_submit'});
  250: 			      if (!$submitted) {
  251: 				  foreach my $key (keys(%env)) {
  252: 				      if ($key=~/^form.\Q$prefix\Esubmit_/) {
  253: 					  $submitted=1;last;
  254: 				      }
  255: 				  }
  256: 			      }
  257:                               if ($submitted) {
  258: 				  foreach my $key (keys(%env)) {
  259: 				      if ($key=~/^form.\Q$prefix\E/) {
  260: 					  my $name=$key;
  261: 					  $name=~s/^form.\Q$prefix\E//;
  262: 					  $posthash{$name}=$env{$key};
  263: 				      }
  264: 				  }
  265: 				  if (exists($env{'form.all_submit'})) {
  266: 				      $posthash{'all_submit'}='yes';
  267: 				  }
  268: 			      }
  269:                               my $output=Apache::lonnet::ssi($src,%posthash);
  270: 			      $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+// END LON-CAPA Internal\s*(-->)?\s||gs;
  271:                               if ($target eq 'tex') {
  272: 				  $output =~ s/^([^&]+)\\begin{document}//;
  273: 				  $output =~ s/\\end{document}//;
  274: 				  $output = '\parbox{\minipagewidth}{ '.$output.' }';
  275:                                   #some additional cleanup necessary for LateX (due to limitations of table environment 
  276: 				  $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
  277: 			      }
  278:                               my $parser=HTML::TokeParser->new(\$output);
  279:                               my $token;
  280:                               my $thisdir=$src;
  281:                               my $bodydef=0;
  282:                               my $thisxml=0;
  283:                               my @rlinks=();
  284:                               if ($output=~/\?xml/) {
  285:                                  $isxml=1;
  286:                                  $thisxml=1;
  287:                                  $output=~
  288:          /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
  289:                                  $xmlheader=$1;
  290: 			      }
  291:                               while ($token=$parser->get_token) {
  292: 				if ($token->[0] eq 'S') {
  293:                                   if ($token->[1] eq 'a') {
  294: 				      if ($token->[2]->{'href'}) {
  295:                                          $rlinks[$#rlinks+1]=
  296: 					     $token->[2]->{'href'};
  297: 				      }
  298: 				  } elsif ($token->[1] eq 'img') {
  299:                                          $rlinks[$#rlinks+1]=
  300: 					     $token->[2]->{'src'};
  301: 				  } elsif ($token->[1] eq 'embed') {
  302:                                          $rlinks[$#rlinks+1]=
  303: 					     $token->[2]->{'src'};
  304: 				  } elsif ($token->[1] eq 'base') {
  305: 				      $thisdir=$token->[2]->{'href'};
  306: 				  } elsif ($token->[1] eq 'body') {
  307: 				      $bodydef=1;
  308:                                       $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
  309:                                       $ssitext{$_}=$token->[2]->{'text'};
  310:                                       $ssilink{$_}=$token->[2]->{'link'};
  311:                                       $ssivlink{$_}=$token->[2]->{'vlink'};
  312:                                       $ssialink{$_}=$token->[2]->{'alink'};
  313:                                       if ($thisxml) {
  314: 					  $xmlbody=$token->[4];
  315:                                       }
  316:                                   } elsif ($token->[1] eq 'meta') {
  317: 				    if ($token->[4] !~ m:/>$:) {
  318: 				      $allmeta.="\n".$token->[4].'</meta>';
  319: 				    } else {
  320: 				      $allmeta.="\n".$token->[4];
  321: 				    }
  322:                                   } elsif (($token->[1] eq 'script') &&
  323:                                            ($bodydef==0)) {
  324: 				      $allscript.="\n\n"
  325:                                                 .$parser->get_text('/script');
  326:                                   }
  327: 			        }
  328: 			      }
  329:                               if ($output=~/\<body[^\>]*\>(.*)/si) {
  330:                                  $output=$1; 
  331:                               }
  332:                               $output=~s/\<\/body\>.*//si;
  333:                               if ($output=~/\<form/si) {
  334: 				  $nforms++;
  335:                                   $output=~s/\<form[^\>]*\>//gsi;
  336:                                   $output=~s/\<\/form[^\>]*\>//gsi;
  337:                                   $output=~
  338: 				      s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([\w\.\:]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
  339:                               }
  340:                               $thisdir=~s/\/[^\/]*$//;
  341: 			      foreach (@rlinks) {
  342: 				  unless (($_=~/^http:\/\//i) ||
  343: 					  ($_=~/^\//) ||
  344: 					  ($_=~/^javascript:/i) ||
  345: 					  ($_=~/^mailto:/i) ||
  346: 					  ($_=~/^\#/)) {
  347: 				      my $newlocation=
  348: 				    &Apache::lonnet::hreflocation($thisdir,$_);
  349:                      $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
  350: 				  }
  351: 			      }
  352: # -------------------------------------------------- Deal with Applet codebases
  353:   $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
  354: 			      $ssibody{$_}=$output;
  355: # ---------------------------------------------------------------- End SSI cell
  356:                           }
  357:                       }
  358:                      } 
  359:                   }
  360:                   unless ($contents) {
  361:                       &Apache::loncommon::content_type($r,'text/html');
  362:                       $r->send_http_header;
  363:                       $r->print('<html>'."\n".
  364:                                 '<head>'."\n".
  365:                                 &Apache::lonmenu::registerurl(1,undef)."\n".
  366:                                 '</head>'."\n".
  367:                                 '<body bgcolor="#FFFFFF" onLoad="'
  368:                                 .&Apache::lonmenu::loadevents.
  369:                                 '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.
  370:                                  &Apache::lonmenu::menubuttons(undef,$target,1)
  371:                                );
  372:                       $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
  373:                       $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').'.</body></html>');
  374:                   } else {
  375: # ------------------------------------------------------------------ Build page
  376: 
  377: # ---------------------------------------------------------------- Send headers
  378: 		      unless ($target eq 'tex') {
  379: 			  if ($isxml) {
  380: 			      &Apache::loncommon::content_type($r,'text/xml');
  381: 			      $r->send_http_header;
  382: 			      $r->print($xmlheader);
  383: 			  } else {
  384: 			      &Apache::loncommon::content_type($r,'text/html');
  385: 			      $r->send_http_header;
  386: 			      $r->print('<html>');
  387: 			  }
  388: # ------------------------------------------------------------------------ Head
  389: 			  $r->print("\n<head>\n".$allmeta);
  390: 			  if ($allscript) {
  391: 			      $r->print("\n<script language='JavaScript'>\n".
  392: 					$allscript."\n</script>\n");
  393: 			  }
  394: 			  $r->print(&Apache::lonmenu::registerurl(1,undef));
  395: 			  $r->print("\n</head>\n");
  396: # ------------------------------------------------------------------ Start body
  397: 			  if ($isxml) {
  398: 			      $r->print($xmlbody);
  399: 			  } else {
  400: 			      $r->print(
  401:                '<body bgcolor="#FFFFFF" onLoad="'.&Apache::lonmenu::loadevents.
  402:                '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.
  403:                               &Apache::lonmenu::menubuttons(undef,$target,1)
  404: 					);
  405: 			  }
  406: # ------------------------------------------------------------------ Start form
  407: 			  if ($nforms) {
  408: 			      $r->print('<form method="post" action="'.
  409: 					&Apache::lonenc::check_encrypt($requrl)
  410: 					.'">');
  411: 			  }
  412: 		      } elsif ($target eq 'tex') {
  413: 			  $r->print('\documentclass{article}
  414:                                  \newcommand{\keephidden}[1]{}           
  415:                                  \usepackage[dvips]{graphicx}
  416:                                  \usepackage{epsfig}
  417:                                  \usepackage{calc}
  418:                                  \usepackage{longtable}
  419:                                  \begin{document}');
  420: 		      }
  421: # ----------------------------------------------------------------- Start table
  422: 		      if ($target eq 'tex') {
  423: 			  $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
  424: 			  if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
  425: 		      } else {
  426: 			  $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
  427: 		      }
  428:                       for ($i=0;$i<=$#rows;$i++) {
  429: 			if ($rows[$i]) {
  430: 			    unless ($target eq 'tex') {
  431: 				$r->print("\n<tr>");
  432: 			    }
  433:                           my @colcont=split(/\&/,$rows[$i]);
  434:                           my $avespan=$lcm/($#colcont+1);
  435:                           for ($j=0;$j<=$#colcont;$j++) {
  436:                               my $rid=$colcont[$j];
  437:                               my $metainfo = '';
  438: 			      my $esrc=&Apache::lonnet::declutter($hash{'src_'.$rid});
  439: 			      my ($mapid,$resid)=split(/\./,$rid);
  440: 			      my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid});
  441: 			      if ($hash{'encrypted_'.$rid}) {
  442: 				  $symb=&Apache::lonenc::encrypted($symb);
  443: 				  $esrc=&Apache::lonenc::encrypted($esrc);
  444: 			      }
  445:                               unless ($hash{'src_'.$rid} =~ m-^/uploaded/-) { 
  446:                                   $metainfo ='<a name="'.&Apache::lonnet::escape($symb).'" />'.
  447:                                   '<a href="'.$metalink{$rid}.'" target="LONcatInfo">'.
  448:                                   '<img src="/adm/lonMisc/cat_button.gif" border=0>'.
  449:                                   '</img></a>';
  450:                               }
  451:                               $metainfo .= '<a href="/adm/evaluate?postdata='.
  452: 				  &Apache::lonnet::escape($esrc).
  453:                                   '" target="LONcatInfo">'.
  454:                                   '<img src="/adm/lonMisc/eval_button.gif" border=0>'.
  455:                                   '</img></a>';
  456:                               if (
  457:  ($hash{'src_'.$rid}=~/\.(problem|exam|quiz|assess|survey|form)$/) &&
  458:  (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && 
  459:  ($hash{'src_'.$rid} !~ m-^/uploaded/-)) {
  460: 				  my ($mapid,$resid)=split(/\./,$rid);
  461:                                  my $symb=
  462:                 &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
  463:                 '___'.$resid.'___'.
  464: 		&Apache::lonnet::declutter($hash{'src_'.$rid});
  465:                                  $metainfo.=
  466:                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).
  467: #                 '&command=submission" target="LONcatInfo">'.
  468:                   '&command=submission">'.
  469:                           '<img src="/adm/lonMisc/subm_button.gif" border=0>'.
  470: 			  '</img></a>'.
  471:                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).
  472: #                  '&command=gradingmenu" target="LONcatInfo">'.
  473:                   '&command=gradingmenu">'.
  474:                           '<img src="/adm/lonMisc/pgrd_button.gif" border=0>'.
  475: 			  '</img></a>'.
  476:                   '<a href="/adm/parmset?symb='.&Apache::lonnet::escape($symb).
  477: #                          '" target="LONcatInfo">'.
  478:                           '" >'.
  479:                           '<img src="/adm/lonMisc/pprm_button.gif" border=0>'.
  480: 			      '</img></a>';
  481:                               }
  482:                               $metainfo.='<br></br>';
  483: 			    unless ($target eq 'tex') {
  484: 				$r->print('<td colspan="'.$avespan.'"');
  485: 			    }
  486:                               if ($cellemb{$rid} eq 'ssi') {
  487: 				  unless ($target eq 'tex') {
  488: 				      if ($ssibgcolor{$rid}) {
  489: 					  $r->print(' bgcolor="'.
  490: 						    $ssibgcolor{$rid}.'"');
  491: 				      }
  492: 				      $r->print('>'.$metainfo.'<font');
  493: 		    
  494: 				      if ($ssitext{$rid}) {
  495: 					  $r->print(' text="'.$ssitext{$rid}.'"');
  496: 				      }
  497: 				      if ($ssilink{$rid}) {
  498: 					  $r->print(' link="'.$ssilink{$rid}.'"');
  499: 				      }
  500: 				      if ($ssitext{$rid}) {
  501: 					  $r->print(' vlink="'.$ssivlink{$rid}.'"');
  502: 				      }
  503: 				      if ($ssialink{$rid}) {
  504: 					  $r->print(' alink="'.$ssialink{$rid}.'"');
  505: 				      }             
  506: 				      $r->print('>');
  507: 				  }
  508:                                   $r->print($ssibody{$rid});	
  509: 				  unless ($target eq 'tex') {
  510: 				      $r->print('</font>');
  511:                                   }
  512:                                   if ($env{'course.'.
  513:                                       $env{'request.course.id'}.
  514:                                       '.pageseparators'} eq 'yes') {
  515:                                       unless($target eq 'tex') {
  516:                                           $r->print('<hr />');
  517:                                       } else {
  518:                                           $r->print('\hline');
  519:                                       }
  520: 				  }
  521: 			      } elsif ($cellemb{$rid} eq 'img') {
  522:                                   $r->print('>'.$metainfo.'<img src="'.
  523:                                     $hash{'src_'.$rid}.'"></img>');
  524: 			      } elsif ($cellemb{$rid} eq 'emb') {
  525:                                   $r->print('>'.$metainfo.'<embed src="'.
  526:                                     $hash{'src_'.$rid}.'"></embed>');
  527:                               } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
  528:                                   $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />'.
  529:                                   &mt('It is recommended that you use an up-to-date virus scanner before handling this file.').'</p><p><table>'.
  530:                                   &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 />');
  531:                               }
  532: 			      unless ($target eq 'tex') {
  533: 				  $r->print('</td>');
  534: 			      } else {
  535:                                   for (my $incol=1;$incol<=$avespan;$incol++) {
  536: 				      $r->print(' & ');
  537: 				  }
  538: 			      }
  539:                           }
  540: 			      unless ($target eq 'tex') {
  541: 				  $r->print('</tr>');
  542: 			      } else {
  543: 				  $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
  544: 			      }
  545: 		        }
  546:                       }
  547: 		      unless ($target eq 'tex') {
  548: 			  $r->print("\n</table>");
  549: 		      } else {
  550: 			  $r->print('\end{longtable}\strut');
  551: 		      }
  552: # ---------------------------------------------------------------- Submit, etc.
  553:                       if ($nforms) {
  554:                           $r->print(
  555: 	                  '<input name="all_submit" value="Submit All" type="'.
  556: 			  (($nforms>1)?'submit':'hidden').'"></input></form>');
  557:                       }
  558: 		      unless ($target eq 'tex') {
  559: 			  $r->print('</body>'.&Apache::lonxml::xmlend());
  560: 		      } else {
  561: 			  $r->print('\end{document}'.$number_of_columns);
  562: 		      }
  563: 		      &Apache::lonnet::symblist($requrl,%symbhash);
  564: 		      my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  565: 		      &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
  566: # -------------------------------------------------------------------- End page
  567:                   }                  
  568: # ------------------------------------------------------------- End render page
  569:               } else {
  570:                   &Apache::loncommon::content_type($r,'text/html');
  571:                   $r->send_http_header;
  572:                   &Apache::lonsequence::viewmap($r,$requrl);
  573:               }
  574: # ------------------------------------------------------------------ Untie hash
  575:               unless (untie(%hash)) {
  576:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  577:                        "Could not untie coursemap $fn (browse).</font>"); 
  578:               }
  579: # -------------------------------------------------------------------- All done
  580: 	      return OK;
  581: # ----------------------------------------------- Errors, hash could no be tied
  582:           }
  583:       } 
  584:   }
  585:   &Apache::loncommon::content_type($r,'text/html');
  586:   $r->send_http_header;
  587:   &Apache::lonsequence::viewmap($r,$requrl);
  588:   return OK; 
  589: }
  590: 
  591: 1;
  592: __END__
  593: 
  594: =head1 NAME
  595: 
  596: Apache::lonpage - Page Handler
  597: 
  598: =head1 SYNOPSIS
  599: 
  600: Invoked by /etc/httpd/conf/srm.conf:
  601: 
  602:  <LocationMatch "^/res/.*\.page$>
  603:  SetHandler perl-script
  604:  PerlHandler Apache::lonpage
  605:  </LocationMatch>
  606: 
  607: =head1 INTRODUCTION
  608: 
  609: This module renders a .page resource.
  610: 
  611: This is part of the LearningOnline Network with CAPA project
  612: described at http://www.lon-capa.org.
  613: 
  614: =head1 HANDLER SUBROUTINE
  615: 
  616: This routine is called by Apache and mod_perl.
  617: 
  618: =over 4
  619: 
  620: =item *
  621: 
  622: set document type for header only
  623: 
  624: =item *
  625: 
  626: tie db file
  627: 
  628: =item *
  629: 
  630: render page
  631: 
  632: =item *
  633: 
  634: add to symb list
  635: 
  636: =item *
  637: 
  638: page parms
  639: 
  640: =item *
  641: 
  642: Get SSI output, post parameters
  643: 
  644: =item *
  645: 
  646: SSI cell rendering
  647: 
  648: =item *
  649: 
  650: Deal with Applet codebases
  651: 
  652: =item *
  653: 
  654: Build page
  655: 
  656: =item *
  657: 
  658: send headers
  659: 
  660: =item *
  661: 
  662: start body
  663: 
  664: =item *
  665: 
  666: start form
  667: 
  668: =item *
  669: 
  670: start table
  671: 
  672: =item *
  673: 
  674: submit element, etc, render page, untie hash
  675: 
  676: =back
  677: 
  678: =head1 OTHER SUBROUTINES
  679: 
  680: =over 4
  681: 
  682: =item *
  683: 
  684: euclid() : Euclid's method for determining the greatest common denominator.
  685: 
  686: =item *
  687: 
  688: tracetable() : Build page table.
  689: 
  690: =back
  691: 
  692: =cut
  693: 
  694: 
  695: 
  696: 

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