File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.101: download - view: text, annotated - select for diffs
Sun Jun 9 02:59:25 2013 UTC (10 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Support toggle between Rich Text/Plain Text for multiple textareas in
  a composite page.
  - Add prefix to id in textarea tag with a .page to ensure uniqueness
  - Javascript functions: containsBlockHtml(), startRichEditor(),
    $(document).ready(function() etc only included once.

    1: # The LearningOnline Network with CAPA
    2: # Page Handler
    3: #
    4: # $Id: lonpage.pm,v 1.101 2013/06/09 02:59:25 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:                   my $nuploads=0;
  218:                   my %turninpaths;
  219:                   my %multiresps;
  220:                   my $turninparent;
  221:                   
  222:                   my %ssibody=();
  223:                   my %ssibgcolor=();
  224:                   my %ssitext=();
  225:                   my %ssilink=();
  226:                   my %ssivlink=();
  227:                   my %ssialink=();
  228:      
  229:                   my %cellemb=();
  230:                   my %cellexternal=();
  231: 
  232:                   my $allscript='';
  233:                   my $allmeta='';
  234: 
  235:                   my $isxml=0;
  236:                   my $xmlheader='';
  237:                   my $xmlbody='';
  238: 
  239: # --------------------------------------------- Get SSI output, post parameters
  240: 
  241:                   for ($i=0;$i<=$#rows;$i++) {
  242: 		     if ($rows[$i]) {
  243: 		      $contents++;
  244:                       my @colcont=split(/\&/,$rows[$i]);
  245:                       $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
  246:                       foreach (@colcont) {
  247:                           my $src=$hash{'src_'.$_};
  248:                           my ($extension)=($src=~/\.(\w+)$/);
  249: 			  $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
  250: 			  if ($hash{'encrypted_'.$_}) {
  251: 			      $src=&Apache::lonenc::encrypted($src);
  252: 			  }
  253:                           $cellemb{$_}=
  254: 			      &Apache::loncommon::fileembstyle($extension);
  255:                           if ($cellexternal{$_}) {
  256:                               unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  257:                                   $ssibody{$_} = <<ENDEXT;
  258: <iframe src="$src" width="100%">No iframe support!</iframe>
  259: ENDEXT
  260:                               }
  261:                           } elsif ($cellemb{$_} eq 'ssi') {
  262: # --------------------------------------------------------- This is an SSI cell
  263: 			      my ($mapid,$resid)=split(/\./,$_);
  264: 			      my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
  265: 			      
  266: 			      my $prefix=$_.'_';
  267:                               my $idprefix= join('_',($mapid,$resid,''));
  268:                               my %posthash=('request.prefix' => $prefix,
  269: 					    'LONCAPA_INTERNAL_no_discussion' => 'true',
  270: 					    'symb' => $symb);
  271: 			      if (($env{'form.grade_target'} eq 'tex') ||
  272:                                  ($env{'form.answer_output_mode'} eq 'tex')) {
  273: 				  $posthash{'grade_target'}=$env{'form.grade_target'};
  274: 				  $posthash{'textwidth'}=$env{'form.textwidth'};
  275: 				  $posthash{'problem_split'}=$env{'form.problem_split'};
  276: 				  $posthash{'latex_type'}=$env{'form.latex_type'};
  277: 				  $posthash{'rndseed'}=$env{'form.rndseed'};
  278:                                   $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
  279: 			      }
  280: 			      my $submitted=exists($env{'form.all_submit'});
  281: 			      if (!$submitted) {
  282: 				  foreach my $key (keys(%env)) {
  283: 				      if ($key=~/^form.\Q$prefix\Esubmit_/) {
  284: 					  $submitted=1;last;
  285: 				      }
  286: 				  }
  287: 			      }
  288:                               if ($submitted) {
  289: 				  foreach my $key (keys(%env)) {
  290: 				      if ($key=~/^form.\Q$prefix\E/) {
  291: 					  my $name=$key;
  292: 					  $name=~s/^form.\Q$prefix\E//;
  293: 					  $posthash{$name}=$env{$key};
  294: 				      }
  295: 				  }
  296: 				  if (exists($env{'form.all_submit'})) {
  297: 				      $posthash{'all_submit'}='yes';
  298: 				  }
  299: 			      }
  300:                               my $output=Apache::lonnet::ssi($src,%posthash);
  301: 			      $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
  302:                               if (($target eq 'tex') || ($target eq 'tex_answer')) {
  303: 				  $output =~ s/^([^&]+)\\begin{document}//;
  304: 				  $output =~ s/\\end{document}//;
  305: #				  $output = '\parbox{\minipagewidth}{ '.$output.' }';
  306:                                   #some additional cleanup necessary for LateX (due to limitations of table environment 
  307: 				  $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
  308: 			      }
  309:                               my $parser=HTML::TokeParser->new(\$output);
  310:                               my $token;
  311:                               my $thisdir=$src;
  312:                               my $bodydef=0;
  313:                               my $thisxml=0;
  314:                               my @rlinks=();
  315:                               if ($output=~/\?xml/) {
  316:                                  $isxml=1;
  317:                                  $thisxml=1;
  318:                                  $output=~
  319:          /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
  320:                                  $xmlheader=$1;
  321: 			      }
  322:                               while ($token=$parser->get_token) {
  323: 				if ($token->[0] eq 'S') {
  324:                                   if ($token->[1] eq 'a') {
  325: 				      if ($token->[2]->{'href'}) {
  326:                                          $rlinks[$#rlinks+1]=
  327: 					     $token->[2]->{'href'};
  328: 				      }
  329: 				  } elsif ($token->[1] eq 'img') {
  330:                                          $rlinks[$#rlinks+1]=
  331: 					     $token->[2]->{'src'};
  332: 				  } elsif ($token->[1] eq 'embed') {
  333:                                          $rlinks[$#rlinks+1]=
  334: 					     $token->[2]->{'src'};
  335: 				  } elsif ($token->[1] eq 'base') {
  336: 				      $thisdir=$token->[2]->{'href'};
  337: 				  } elsif ($token->[1] eq 'body') {
  338: 				      $bodydef=1;
  339:                                       $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
  340:                                       $ssitext{$_}=$token->[2]->{'text'};
  341:                                       $ssilink{$_}=$token->[2]->{'link'};
  342:                                       $ssivlink{$_}=$token->[2]->{'vlink'};
  343:                                       $ssialink{$_}=$token->[2]->{'alink'};
  344:                                       if ($thisxml) {
  345: 					  $xmlbody=$token->[4];
  346:                                       }
  347:                                   } elsif ($token->[1] eq 'meta') {
  348: 				    if ($token->[4] !~ m:/>$:) {
  349: 				      $allmeta.="\n".$token->[4].'</meta>';
  350: 				    } else {
  351: 				      $allmeta.="\n".$token->[4];
  352: 				    }
  353:                                   } elsif (($token->[1] eq 'script') &&
  354:                                            ($bodydef==0)) {
  355: 				      $allscript.="\n\n"
  356:                                                 .$parser->get_text('/script');
  357:                                   }
  358: 			        }
  359: 			      }
  360:                               if ($output=~/\<body[^\>]*\>(.*)/si) {
  361:                                  $output=$1; 
  362:                               }
  363:                               $output=~s/\<\/body\>.*//si;
  364:                               if ($output=~/\<form/si) {
  365: 				  $nforms++;
  366:                                   $output=~s/\<form[^\>]*\>//gsi;
  367:                                   $output=~s/\<\/form[^\>]*\>//gsi;
  368:                                   if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
  369:                                       $nuploads++;
  370:                                   }
  371:                                   $output=~
  372: 				      s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
  373:                                   $output=~
  374:                                       s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
  375:                                   if ($nuploads) {
  376:                                       $output=~
  377:                                           s/\<(input[^\>]+name=\"\Q$prefix\EHWFILE[^\>]+)\s*id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\)]*)\>/\<$1 id="$prefix$2" $3\>/gsi;
  378:                                        ($turninpaths{$prefix},$multiresps{$prefix}) = 
  379:                                            &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
  380:                                        if ($turninparent eq '') {
  381:                                            $turninparent = $turninpaths{$prefix};
  382:                                            $turninparent =~ s{(/[^/]+)$}{}; 
  383:                                        }
  384:                                   }
  385:                                   $output=~
  386:                                       s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
  387:                               }
  388:                               $thisdir=~s/\/[^\/]*$//;
  389: 			      foreach (@rlinks) {
  390: 				  unless (($_=~/^https?\:\/\//i) ||
  391: 					  ($_=~/^\//) ||
  392: 					  ($_=~/^javascript:/i) ||
  393: 					  ($_=~/^mailto:/i) ||
  394: 					  ($_=~/^\#/)) {
  395: 				      my $newlocation=
  396: 				    &Apache::lonnet::hreflocation($thisdir,$_);
  397:                      $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
  398: 				  }
  399: 			      }
  400: # -------------------------------------------------- Deal with Applet codebases
  401:   $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
  402: 			      $ssibody{$_}=$output;
  403: # ---------------------------------------------------------------- End SSI cell
  404:                           }
  405:                       }
  406:                      } 
  407:                   }
  408:                   unless ($contents) {
  409:                       &Apache::loncommon::content_type($r,'text/html');
  410:                       $r->send_http_header;
  411:                       $r->print(&Apache::loncommon::start_page(undef,undef,
  412: 							       {'force_register' => 1,}));
  413:                       $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
  414:                       $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
  415: 				&Apache::loncommon::end_page());
  416:                   } else {
  417: # ------------------------------------------------------------------ Build page
  418: 
  419: # ---------------------------------------------------------------- Send headers
  420: 		      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  421: 			  if ($isxml) {
  422: 			      &Apache::loncommon::content_type($r,'text/xml');
  423: 			  } else {
  424: 			      &Apache::loncommon::content_type($r,'text/html');
  425: 			  }
  426: 			  $r->send_http_header;
  427: # ------------------------------------------------------------------------ Head
  428: 			  if ($allscript) {
  429: 			      $allscript = 
  430: 				  "\n".'<script type="text/javascript">'."\n".
  431: 				  $allscript.
  432: 				  "\n</script>\n";
  433: 			  }
  434:                           if (($nforms) && ($nuploads)) {
  435:                               $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
  436:                           }
  437:                           if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
  438:                               my %textarea_args = (
  439:                                   dragmath => 'math',
  440:                               );
  441:                               $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
  442:                           }
  443: # ------------------------------------------------------------------ Start body
  444: 			  $r->print(&Apache::loncommon::start_page(undef,$allscript,
  445: 								   {'force_register' => 1,
  446: 								    'bgcolor'        => '#ffffff',}));
  447: # ------------------------------------------------------------------ Start form
  448: 			  if ($nforms) {
  449: 			      my $fmtag = '<form name="lonhomework" method="post"  enctype="multipart/form-data"';
  450:                               if ($nuploads) {
  451:                                   my $multi;
  452:                                   if ($nuploads > 1) {
  453:                                       $multi = 1;
  454:                                   }
  455:                                   $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
  456:                               }
  457:                               $fmtag .= ' action="'.
  458: 					&Apache::lonenc::check_encrypt($requrl)
  459: 					.'">';
  460:                               $r->print($fmtag);
  461: 			  }
  462: 		      } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
  463: 			  #  I think this is not needed as the header
  464: 			  # will be put in for each of the page parts
  465: 			  # by the londefdef.pm now that we are opening up
  466: 			  # the parts of a page.
  467: 			  #$r->print('\documentclass{article}
  468:                           #       \newcommand{\keephidden}[1]{}           
  469:                           #       \usepackage[dvips]{graphicx}
  470:                           #       \usepackage{epsfig}
  471:                           #       \usepackage{calc}
  472:                           #       \usepackage{longtable}
  473:                           #       \begin{document}');
  474: 		      }
  475: # ----------------------------------------------------------------- Start table
  476: 		      if (($target eq 'tex') || ($target eq 'tex_answer')) {
  477: #			 #  $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
  478: 			  if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
  479: 		      } else {
  480: 			  $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
  481: 		      }
  482: # generate rows
  483:                       for ($i=0;$i<=$#rows;$i++) {
  484: 			if ($rows[$i]) {
  485: 			    unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  486: 				$r->print("\n<tr>");
  487: 			    }
  488:                           my @colcont=split(/\&/,$rows[$i]);
  489:                           my $avespan=$lcm/($#colcont+1);
  490:                           for ($j=0;$j<=$#colcont;$j++) {
  491:                               my $rid=$colcont[$j];
  492: 
  493: 			      my $metainfo =&get_buttons(\%hash,$rid).'<br />';
  494: 			    unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  495: 				$r->print('<td colspan="'.$avespan.'"');
  496: 			    }
  497:                               if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
  498: 				  unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  499: 				      if ($ssibgcolor{$rid}) {
  500: 					  $r->print(' bgcolor="'.
  501: 						    $ssibgcolor{$rid}.'"');
  502: 				      }
  503: 				      $r->print('>'.$metainfo.'<font');
  504: 		    
  505: 				      if ($ssitext{$rid}) {
  506: 					  $r->print(' text="'.$ssitext{$rid}.'"');
  507: 				      }
  508: 				      if ($ssilink{$rid}) {
  509: 					  $r->print(' link="'.$ssilink{$rid}.'"');
  510: 				      }
  511: 				      if ($ssitext{$rid}) {
  512: 					  $r->print(' vlink="'.$ssivlink{$rid}.'"');
  513: 				      }
  514: 				      if ($ssialink{$rid}) {
  515: 					  $r->print(' alink="'.$ssialink{$rid}.'"');
  516: 				      }             
  517: 				      $r->print('>');
  518: 				  }
  519:                                   unless (($cellexternal{$rid}) && 
  520:                                           ($target eq 'tex') && ($target eq 'tex_answer')) {
  521:                                       $r->print($ssibody{$rid});
  522:                                   }
  523: 				  unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  524: 				      $r->print('</font>');
  525:                                   }
  526:                                   if ($env{'course.'.
  527:                                       $env{'request.course.id'}.
  528:                                       '.pageseparators'} eq 'yes') {
  529:                                       unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  530:                                           $r->print('<hr />');
  531:                                       } 
  532: 				  }
  533: 			      } elsif ($cellemb{$rid} eq 'img') {
  534:                                   $r->print('>'.$metainfo.'<img src="'.
  535:                                     $hash{'src_'.$rid}.'" />');
  536: 			      } elsif ($cellemb{$rid} eq 'emb') {
  537:                                   $r->print('>'.$metainfo.'<embed src="'.
  538:                                     $hash{'src_'.$rid}.'"></embed>');
  539:                               } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
  540:                                   $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />'.
  541:                                   &mt('It is recommended that you use an up-to-date virus scanner before handling this file.').'</p><p><table>'.
  542:                                   &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 />');
  543:                               }
  544: 			      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  545: 				  $r->print('</td>');
  546: 			      } else {
  547: #                                  for (my $incol=1;$incol<=$avespan;$incol++) {
  548: #				      $r->print(' & ');
  549: #				  }
  550: 			      }
  551:                           }
  552: 			      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  553: 				  $r->print('</tr>');
  554: 			      } else {
  555: #				  $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
  556: 			      }
  557: 		        }
  558:                       }
  559: 		      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  560: 			  $r->print("\n</table>");
  561: 		      } else {
  562: #			  $r->print('\end{longtable}\strut');
  563: 		      }
  564: # ---------------------------------------------------------------- Submit, etc.
  565:                       if ($nforms) {
  566:                           $r->print(
  567: 	                  '<input name="all_submit" value="Submit All" type="'.
  568: 			  (($nforms>1)?'submit':'hidden').'"></input></form>');
  569:                       }
  570: 		      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  571: 			  $r->print(&Apache::loncommon::end_page({'discussion'
  572: 								      => 1,}));
  573: 		      } else {
  574: 			  $r->print('\end{document}'.$number_of_columns);
  575: 		      }
  576: 		      &Apache::lonnet::symblist($requrl,%symbhash);
  577: 		      my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  578: 		      &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
  579: # -------------------------------------------------------------------- End page
  580:                   }                  
  581: # ------------------------------------------------------------- End render page
  582:               } else {
  583:                   &Apache::loncommon::content_type($r,'text/html');
  584:                   $r->send_http_header;
  585:                   &Apache::lonsequence::viewmap($r,$requrl);
  586:               }
  587: # ------------------------------------------------------------------ Untie hash
  588:               unless (untie(%hash)) {
  589:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  590:                        "Could not untie coursemap $fn (browse).</font>"); 
  591:               }
  592: # -------------------------------------------------------------------- All done
  593: 	      return OK;
  594: # ----------------------------------------------- Errors, hash could no be tied
  595:           }
  596:       } 
  597:   }
  598:   &Apache::loncommon::content_type($r,'text/html');
  599:   $r->send_http_header;
  600:   &Apache::lonsequence::viewmap($r,$requrl);
  601:   return OK; 
  602: }
  603: 
  604: sub get_buttons {
  605:     my ($hash,$rid) = @_;
  606: 
  607:     my $metainfo = '';
  608:     my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
  609:     my ($mapid,$resid)=split(/\./,$rid);
  610:     my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
  611: 					  $resid,
  612: 					  $hash->{'src_'.$rid});
  613:     if ($hash->{'encrypted_'.$rid}) {
  614: 	$symb=&Apache::lonenc::encrypted($symb);
  615: 	$esrc=&Apache::lonenc::encrypted($esrc);
  616:     }
  617:     if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
  618:         && $hash->{'src_'.$rid} !~ m{^https?://}
  619: 	&& !$env{'request.enc'}
  620: 	&& ($env{'request.role.adv'}
  621: 	    || !$hash->{'encrypted_'.$rid})) { 
  622: 	$metainfo .='<a name="'.&escape($symb).'" />'.
  623: 	    '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" target="LONcatInfo">'.
  624:             '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
  625:             ' alt="'.&mt('Show Metadata').'"'.
  626:             ' title="'.&mt('Show Metadata').'" />'.
  627: 	    '</a>';
  628:     }
  629:     if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
  630:         ($hash->{'src_'.$rid} !~ m{^https?://})) {
  631:         $metainfo .= '<a href="/adm/evaluate?postdata='.
  632: 	    &escape($esrc).
  633: 	    '" target="LONcatInfo">'.
  634:             '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
  635:             ' alt="'.&mt('Provide my evaluation of this resource').'"'.
  636:             ' title="'.&mt('Provide my evaluation of this resource').'" />'.
  637: 	    '</a>';
  638:     }
  639:     if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
  640: 	($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
  641: 
  642: 	if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
  643: 	    $metainfo.=
  644: 		'<a href="/adm/grades?symb='.&escape($symb).
  645: #               '&command=submission" target="LONcatInfo">'.
  646: 		'&command=submission">'.
  647:                 '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
  648:                 ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
  649:                 ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
  650: 		'</a>'.
  651: 		'<a href="/adm/grades?symb='.&escape($symb).
  652: #               '&command=gradingmenu" target="LONcatInfo">'.
  653: 		'&command=gradingmenu">'.
  654:                 '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
  655:                 ' alt="'.&mt('Content Grades').'"'.
  656:                 ' title="'.&mt('Content Grades').'" />'.
  657: 		'</a>';
  658: 	}
  659: 	if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
  660: 	    $metainfo.=
  661: 		'<a href="/adm/parmset?symb='.&escape($symb).
  662: #               '" target="LONcatInfo">'.
  663: 		'" >'.
  664:                 '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
  665:                 ' alt="'.&mt('Content Settings').'"'.
  666:                 ' title="'.&mt('Content Settings').'" />'.
  667: 		'</a>';
  668: 	}
  669:     }
  670:     return $metainfo;
  671: }
  672: 
  673: 1;
  674: __END__
  675: 
  676: 
  677: =head1 NAME
  678: 
  679: Apache::lonpage - Page Handler
  680: 
  681: =head1 SYNOPSIS
  682: 
  683: Invoked by /etc/httpd/conf/srm.conf:
  684: 
  685:  <LocationMatch "^/res/.*\.page$>
  686:  SetHandler perl-script
  687:  PerlHandler Apache::lonpage
  688:  </LocationMatch>
  689: 
  690: =head1 INTRODUCTION
  691: 
  692: This module renders a .page resource.
  693: 
  694: This is part of the LearningOnline Network with CAPA project
  695: described at http://www.lon-capa.org.
  696: 
  697: =head1 HANDLER SUBROUTINE
  698: 
  699: This routine is called by Apache and mod_perl.
  700: 
  701: =over 4
  702: 
  703: =item *
  704: 
  705: set document type for header only
  706: 
  707: =item *
  708: 
  709: tie db file
  710: 
  711: =item *
  712: 
  713: render page
  714: 
  715: =item *
  716: 
  717: add to symb list
  718: 
  719: =item *
  720: 
  721: page parms
  722: 
  723: =item *
  724: 
  725: Get SSI output, post parameters
  726: 
  727: =item *
  728: 
  729: SSI cell rendering
  730: 
  731: =item *
  732: 
  733: Deal with Applet codebases
  734: 
  735: =item *
  736: 
  737: Build page
  738: 
  739: =item *
  740: 
  741: send headers
  742: 
  743: =item *
  744: 
  745: start body
  746: 
  747: =item *
  748: 
  749: start form
  750: 
  751: =item *
  752: 
  753: start table
  754: 
  755: =item *
  756: 
  757: submit element, etc, render page, untie hash
  758: 
  759: =back
  760: 
  761: =head1 OTHER SUBROUTINES
  762: 
  763: =over 4
  764: 
  765: =item *
  766: 
  767: euclid() : Euclid's method for determining the greatest common denominator.
  768: 
  769: =item *
  770: 
  771: tracetable() : Build page table.
  772: 
  773: =back
  774: 
  775: =cut
  776: 
  777: 

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