File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.94: download - view: text, annotated - select for diffs
Tue Jul 13 00:16:23 2010 UTC (13 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_9_X, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, HEAD
- Fix some issues with headers in TeX which caused begin{document} to be missing in some cases:
  (a) generating printouts with answers only
  (b) printing .page

- Fix some issue which caused HTML to be included in .tex files for resources within
  a page. For now change target to "tex_answer" in lonpage.pm,
  if $env{'form.answer_output_mode'} is 'tex' and $env{'form.grade_target'} is 'answer'
  - answers for all resources in page appear after rendering of individual
    resources in .page, when print type is "with answers" for a .page.

- Eliminate some cases where printing would fail.

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

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