File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.96: download - view: text, annotated - select for diffs
Thu Jul 28 03:14:09 2011 UTC (12 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6459.
 - Overwriting previously submitted file in "turned_in" portfolio.
   - Prompt to confirm overwrite now supported for resources in .page.
   - &file_delchk_js() and &file_overwritechk_js() routines in structuretags.pm
     moved to a consolidated routine: &file_submissionchk_js() in lonhtmlcommon.pm
     to facilitate re-use.
   - Calls to &file_overwritechk_js() omitted from individual resources if
     enclosing map is .page.  Single call from lonpage.pm instead (with
     refs to hashes with information about paths and numbers of response items
     in resources in .page included there.
   - Pop-up confirmations for overwrite and/or deletions supported for both
     "Submit Answer" and "Submit All" button presses.
   - Triggers for multiple response items aggregated into one pop-up
     for overwrites, and one for deletions (if applicable).
- Generation of pop-up to confirm deletions in a .task now uses same mechanism
  (separate file_delchk_js() eliminated).`

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

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