File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.106: download - view: text, annotated - select for diffs
Tue Sep 16 13:28:34 2014 UTC (9 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Bug 6470
- Eliminate multiple submissions of the same response item.
  - Pressing "Submit All" button on composite page (i.e., .page) causes
    all submit buttons to become disabled and input textboxes to be readonly.
  - Text: "Processing ... " displayed.

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

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