File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.111.2.13.2.3: download - view: text, annotated - select for diffs
Mon Sep 19 20:01:39 2022 UTC (19 months, 1 week ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.111.2.13: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.141

    1: # The LearningOnline Network with CAPA
    2: # Page Handler
    3: #
    4: # $Id: lonpage.pm,v 1.111.2.13.2.3 2022/09/19 20:01:39 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 Apache::lonhomework;
   44: use Apache::lonparmset;
   45: use Apache::lonenc();
   46: use HTML::TokeParser;
   47: use HTML::Entities();
   48: use GDBM_File;
   49: use Apache::lonsequence;
   50: use lib '/home/httpd/lib/perl/';
   51: use LONCAPA;
   52:  
   53: 
   54: # -------------------------------------------------------------- Module Globals
   55: my %hash;
   56: my @rows;
   57: 
   58: # ------------------------------------------------------------------ Euclid gcd
   59: 
   60: sub euclid {
   61:     my ($e,$f)=@_;
   62:     my $a; my $b; my $r;
   63:     if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
   64:     while ($r!=0) {
   65: 	$a=$b; $b=$r;
   66:         $r=$a%$b;
   67:     }
   68:     return $b;
   69: }
   70: 
   71: # ------------------------------------------------------------ Build page table
   72: 
   73: sub tracetable {
   74:     my ($sofar,$rid,$beenhere)=@_;
   75:     my $further=$sofar;
   76:     my $randomout=0;
   77:     unless ($env{'request.role.adv'}) {
   78:         $randomout = $hash{'randomout_'.$rid};
   79:     }
   80:     unless ($beenhere=~/\&$rid\&/) {
   81:         $beenhere.=$rid.'&';
   82:         unless ($randomout) {
   83:             if (defined($hash{'is_map_'.$rid})) {
   84:                 if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
   85:                     (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
   86:                     my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
   87: 	            $sofar=
   88:                        &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
   89:                        '&'.$frid.$beenhere);
   90:                     $sofar++;
   91:                     if ($hash{'src_'.$frid}) {
   92:                         my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
   93:                         if (($brepriv eq '2') || ($brepriv eq 'F')) {
   94:                             if (defined($rows[$sofar])) {
   95:                                 $rows[$sofar].='&'.$frid;
   96:                             } else {
   97:                                 $rows[$sofar]=$frid;
   98:                             }
   99: 	                }
  100: 	            }
  101: 	        }
  102:             } else {
  103:                 $sofar++;
  104:                 if ($hash{'src_'.$rid}) {
  105:                     my ($mapid,$resid)=split(/\./,$rid);
  106:                     my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid});
  107:                     my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid},$symb);
  108:                     if (($brepriv eq '2') || ($brepriv eq 'F')) {
  109:                         if (defined($rows[$sofar])) {
  110:                             $rows[$sofar].='&'.$rid;
  111:                         } else {
  112:                             $rows[$sofar]=$rid;
  113:                         }
  114: 	            }
  115:                 }
  116:             }
  117:         }
  118: 
  119:         if (defined($hash{'to_'.$rid})) {
  120: 	    my $mincond=1;
  121:             my $next='';
  122:             foreach (split(/\,/,$hash{'to_'.$rid})) {
  123:                 my $thiscond=
  124:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
  125:                 if ($thiscond>=$mincond) {
  126: 		    if ($next) {
  127: 		        $next.=','.$_.':'.$thiscond;
  128:                     } else {
  129:                         $next=$_.':'.$thiscond;
  130: 		    }
  131:                     if ($thiscond>$mincond) { $mincond=$thiscond; }
  132: 	        }
  133:             }
  134:             foreach (split(/\,/,$next)) {
  135:                 my ($linkid,$condval)=split(/\:/,$_);
  136:                 if ($condval>=$mincond) {
  137:                     my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
  138:                     if ($now>$further) { $further=$now; }
  139: 	        }
  140:             }
  141:         }
  142:     }
  143:     return $further;
  144: }
  145: 
  146: # ================================================================ Main Handler
  147: 
  148: sub handler {
  149:   my $r=shift;
  150: 
  151: # ------------------------------------------- Set document type for header only
  152: 
  153:   if ($r->header_only) {
  154:        if ($env{'browser.mathml'}) {
  155:            &Apache::loncommon::content_type($r,'text/xml');
  156:        } else {
  157:            &Apache::loncommon::content_type($r,'text/html'); 
  158:        }
  159:        $r->send_http_header;
  160:        return OK;
  161:    }
  162:   
  163:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  164:                                           ['forceselect','launch']);
  165:   my $number_of_columns = 1;
  166:   my $requrl=$r->uri;  
  167:   my $target = $env{'form.grade_target'};
  168: 
  169: # Short term solution: define target as 'tex_answer' when retrieving answers
  170: # for resources in a .page when generating printouts.
  171: # A better long-term fix would be to modify the way problem rendering, and 
  172: # answer rendering are retrieved for individual resources when printing a .page,
  173: # so rendered problem and answer are sequential for individual resources in 
  174: # the .page
  175: #
  176:   if ($target eq 'answer') {
  177:       if ($env{'form.answer_output_mode'} eq 'tex') {
  178:           $target = 'tex_answer';
  179:       }
  180:   }
  181: #  &Apache::lonnet::logthis("Got a target of $target");
  182:   if ($target eq 'meta') {
  183:       &Apache::loncommon::content_type($r,'text/html');
  184:       $r->send_http_header;
  185:       return OK;
  186:   }
  187: # ----------------------------------------------------------------- Tie db file
  188:   if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
  189:       my $fn=$env{'request.course.fn'};
  190:       if (-e "$fn.db") {
  191:           my %buttonshide;
  192:           my $hostname = $r->hostname();
  193:           my $lonhost = $r->dir_config('lonHostID');
  194:           my $ip = &Apache::lonnet::get_host_ip($lonhost);
  195:           if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
  196: # ------------------------------------------------------------------- Hash tied
  197:               my $firstres=$hash{'map_start_'.$requrl};
  198:               my $lastres=$hash{'map_finish_'.$requrl};
  199:               if (($firstres) && ($lastres)) {
  200: # ------------------------------------------------------------- Countdown Timer
  201:                   my $now = time;
  202:                   my ($pagefirstaccess,%hastimeleft,%countdowndisp,%donebutton,
  203:                       %donebtnextra,%buttonbytime,$donetime,$symbtosetdone);
  204:                   my ($pagesymb,$courseid,$domain,$name)=&Apache::lonnet::whichuser();
  205:                   unless ($pagesymb) {
  206:                       $pagesymb=&Apache::lonnet::symbread($requrl);
  207:                   }
  208:                   if ($pagesymb && ($courseid ne '') && ($domain ne '') && ($name ne '')) {
  209:                       my %times=&Apache::lonnet::get('firstaccesstimes',
  210:                                                      [$courseid."\0".$pagesymb],
  211:                                                      $domain,$name);
  212:                       if ($times{$courseid."\0".$pagesymb} =~ /^\d+$/) {
  213:                           $pagefirstaccess = $times{$courseid."\0".$pagesymb};
  214:                           if ($pagefirstaccess && $env{'form.LC_interval_done'} eq 'true') {
  215:                               $donetime = $now - $pagefirstaccess;
  216:                           }
  217:                       }
  218:                   }
  219: 
  220: # ----------------------------------------------------------------- Render page
  221: 
  222:                   @rows=();
  223: 
  224:                   &tracetable(0,$firstres,'&');
  225: 
  226: # ------------------------------------------------------------ Add to symb list
  227: 
  228:                   my $i;
  229:                   my %symbhash=();
  230:                   for ($i=0;$i<=$#rows;$i++) {
  231: 		     if ($rows[$i]) {
  232:                         my @colcont=split(/\&/,$rows[$i]);
  233:                         foreach my $rid (@colcont) {
  234: 			    my ($mapid,$resid)=split(/\./,$rid);
  235: 			    $symbhash{$hash{'src_'.$rid}}=
  236: 				[$hash{'src_'.$rid},$resid];
  237:                             if (($donetime) && ($symbtosetdone eq '')) {
  238:                                 my $src = $hash{'src_'.$rid};
  239:                                 if ($hash{'encrypted_'.$rid}) {
  240:                                     $src=&Apache::lonenc::encrypted($src);
  241:                                 }
  242:                                 my ($mapid,$resid)=split(/\./,$rid);
  243:                                 my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
  244:                                 if ($src =~ /$LONCAPA::assess_re/) {
  245:                                     my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
  246:                                     if (@interval > 1) {
  247:                                         if (($interval[1] eq 'map') && ($pagefirstaccess)) {
  248:                                             my ($timelimit) = ($interval[0] =~ /^(\d+)/);
  249:                                             if ($timelimit) {
  250:                                                 if ($pagefirstaccess + $timelimit > $now) {
  251:                                                     $symbtosetdone = $symb;
  252:                                                 }
  253:                                             }
  254:                                         }
  255:                                     }
  256:                                 }
  257:                             }
  258: 		        }
  259: 		     }
  260: 		  }
  261:                   &Apache::lonnet::symblist($requrl,%symbhash);
  262: 
  263: # ------------------------------------------------------------------ Page parms
  264: 
  265:                   my $j;
  266:                   my $lcm=1;
  267:                   my $contents=0;
  268:                   my $nforms=0;
  269:                   my $nuploads=0;
  270:                   my $ntimers=0;
  271:                   my %turninpaths;
  272:                   my %multiresps;
  273:                   my $turninparent;
  274:                   
  275:                   my %ssibody=();
  276:                   my %ssibgcolor=();
  277:                   my %ssitext=();
  278:                   my %ssilink=();
  279:                   my %ssivlink=();
  280:                   my %ssialink=();
  281:                   my %cssrefs=();
  282:                   my %httpref=();
  283:      
  284:                   my %cellemb=();
  285:                   my %cellexternal=();
  286: 
  287:                   my $allscript='';
  288:                   my $allmeta='';
  289: 
  290:                   my $isxml=0;
  291:                   my $xmlheader='';
  292:                   my $xmlbody='';
  293: 
  294: # ---------------------------------------------------------- Handle Done button
  295: 
  296:                   # Set the event timer to zero if the "done button" was clicked.
  297:                   if ($donetime && $symbtosetdone) {
  298:                       &Apache::lonparmset::storeparm_by_symb_inner($symbtosetdone,'0_interval',
  299:                                                                    2,$donetime,'date_interval',
  300:                                                                    $name,$domain);
  301:                       undef($env{'form.LC_interval_done'});
  302:                   }
  303: 
  304: # --------------------------------------------- Get SSI output, post parameters
  305: 
  306:                   for ($i=0;$i<=$#rows;$i++) {
  307: 		     if ($rows[$i]) {
  308: 		      $contents++;
  309:                       my @colcont=split(/\&/,$rows[$i]);
  310:                       $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
  311:                       foreach (@colcont) {
  312:                           my $src=$hash{'src_'.$_};
  313:                           my $plainsrc = $src;
  314:                           my $anchor;
  315:                           if ($hash{'ext_'.$_} eq 'true:') {
  316:                               $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
  317:                               $src =~ s{^/ext/}{http://};
  318:                               $src =~ s{http://https://}{https://};
  319:                               if ($src =~ /(\#[^#]+)$/) {
  320:                                   $anchor = $1;
  321:                                   $src =~ s/\#[^#]+$//;
  322:                               }
  323:                           }
  324:                           my $unencsrc = $src;
  325:                           my ($extension)=($src=~/\.(\w+)$/);
  326: 			  if ($hash{'encrypted_'.$_}) {
  327: 			      $src=&Apache::lonenc::encrypted($src);
  328: 			  }
  329:                           my ($mapid,$resid)=split(/\./,$_);
  330:                           my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$plainsrc);
  331:                           unless ($env{'request.role.adv'}) {
  332:                               $buttonshide{$symb} = &Apache::lonnet::EXT("resource.0.buttonshide",$symb);
  333:                           }
  334:                           $cellemb{$_}=
  335: 			      &Apache::loncommon::fileembstyle($extension);
  336:                           if ($cellexternal{$_}) {
  337:                               if (($target eq 'tex') || ($target eq 'tex_answer')) {
  338:                                   my $shown = $src.$anchor;
  339:                                   if (($hash{'encrypted_'.$_}) && (!$env{'request.role.adv'})) {
  340:                                       $shown = &mt('URL not shown (encrypted)');
  341:                                   }
  342:                                   my $title=&Apache::lonnet::gettitle($symb);
  343:                                   $title = &Apache::lonxml::latex_special_symbols($title);
  344:                                   $shown = &Apache::lonxml::latex_special_symbols($shown);
  345:                                   $ssibody{$_} = ' \strut \\\\ \textit{'.$title.'} \strut \\\\ '.$shown.'\\\\';
  346:                               } else {
  347:                                   my $showsrc = $src;
  348:                                   my ($is_pdf,$title,$linktext);
  349:                                   if ($unencsrc =~ /\.pdf$/i) {
  350:                                       $is_pdf = 1;
  351:                                   }
  352:                                   if (($hash{'encrypted_'.$_}) && ($symb)) {
  353:                                       $title=&Apache::lonnet::gettitle(&Apache::lonenc::encrypted($symb));
  354:                                   } else {
  355:                                       $title=&Apache::lonnet::gettitle($symb);
  356:                                   }
  357:                                   if ($env{'browser.mobile'}) {
  358:                                       if ($is_pdf) {
  359:                                           $linktext = &mt('Link to PDF (for mobile devices)');
  360:                                           $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext);
  361:                                       } else {
  362:                                           $linktext = &mt('Link to resource');
  363:                                           $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext);
  364:                                       }
  365:                                   } else {
  366:                                       my $absolute = $env{'request.use_absolute'};
  367:                                       my $uselink = &Apache::loncommon::is_nonframeable($unencsrc,$absolute,$hostname,$ip);
  368:                                       if (($uselink) || (($ENV{'SERVER_PORT'} == 443) && ($unencsrc =~ m{^http://}))) {
  369:                                           $linktext = &mt('Link to resource');
  370:                                           $ssibody{$_} =  &create_extlink($unencsrc,$anchor,$title,$linktext);
  371:                                       } else {
  372:                                           if (($hash{'encrypted_'.$_}) && ($symb) && (!$env{'request.role.adv'})) {
  373:                                               $showsrc .= '?symb='.&Apache::lonenc::encrypted($symb);
  374:                                           } elsif ($anchor) {
  375:                                               $showsrc .= $anchor;
  376:                                           }
  377:                                           $ssibody{$_} = <<ENDEXT;
  378: <iframe src="$showsrc" width="100%" height="300px">No iframe support!</iframe>
  379: ENDEXT
  380:                                       }
  381:                                   }
  382:                               }
  383:                           } elsif ($cellemb{$_} eq 'ssi') {
  384: # --------------------------------------------------------- This is an SSI cell
  385: 			      my $prefix='p_'.$_.'_';
  386:                               my $idprefix='p_'.join('_',($mapid,$resid,''));
  387:                               my %posthash=('request.prefix' => $prefix,
  388: 					    'LONCAPA_INTERNAL_no_discussion' => 'true',
  389: 					    'symb' => $symb);
  390: 			      if (($env{'form.grade_target'} eq 'tex') ||
  391:                                  ($env{'form.answer_output_mode'} eq 'tex')) {
  392: 				  $posthash{'grade_target'}=$env{'form.grade_target'};
  393: 				  $posthash{'textwidth'}=$env{'form.textwidth'};
  394: 				  $posthash{'problem_split'}=$env{'form.problem_split'};
  395: 				  $posthash{'latex_type'}=$env{'form.latex_type'};
  396: 				  $posthash{'rndseed'}=$env{'form.rndseed'};
  397:                                   $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
  398: 			      }
  399: 			      my $submitted=$env{'form.all_submit_pressed'};
  400: 			      if (!$submitted) {
  401: 				  foreach my $key (keys(%env)) {
  402: 				      if ($key=~/^\Qform.$prefix\Esubmit_(.+)_pressed$/) {
  403:                                           if ($env{$key}) {
  404:                                               $submitted=1;
  405:                                               last;
  406:                                           }
  407: 				      }
  408:                                   }
  409: 			      }
  410:                               if ($submitted) {
  411: 				  foreach my $key (keys(%env)) {
  412: 				      if ($key=~/^\Qform.$prefix\E/) {
  413: 					  my $name=$key;
  414: 					  $name=~s/^\Qform.$prefix\E//;
  415: 					  $posthash{$name}=$env{$key};
  416:                                       }
  417: 				  }
  418: 				  if ($env{'form.all_submit_pressed'}) {
  419: 				      $posthash{'all_submit'}='yes';
  420: 				  }
  421: 			      } elsif ($env{'form.'.$prefix.'markaccess'} eq 'yes') {
  422: 		                  $posthash{'markaccess'} = $env{'form.'.$prefix.'markaccess'};
  423: 		              }
  424:                               if ($env{'environment.remote'} eq 'on') {
  425:                                   $posthash{'inhibitmenu'} = 'yes';
  426:                               }
  427:                               my $output=Apache::lonnet::ssi($src,%posthash);
  428: 			      $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
  429:                               if (($target eq 'tex') || ($target eq 'tex_answer')) {
  430: 				  $output =~ s/^([^&]+)\\begin\{document}//;
  431: 				  $output =~ s/\\end\{document}//;
  432: #				  $output = '\parbox{\minipagewidth}{ '.$output.' }';
  433:                                   #some additional cleanup necessary for LateX (due to limitations of table environment 
  434: 				  $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
  435: 			      }
  436:                               my $matheditor;
  437:                               if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
  438:                                   $matheditor = 'dragmath';
  439:                               } elsif ($output =~ /LCmathField/) {
  440:                                   $matheditor = 'lcmath';
  441:                               }
  442:                               my $parser=HTML::TokeParser->new(\$output);
  443:                               my $token;
  444:                               my $thisdir=$src;
  445:                               my $bodydef=0;
  446:                               my $thisxml=0;
  447:                               my @rlinks=();
  448:                               my @css_hrefs=();
  449:                               if ($output=~/\?xml/) {
  450:                                  $isxml=1;
  451:                                  $thisxml=1;
  452:                                  $output=~
  453:          /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
  454:                                  $xmlheader=$1;
  455: 			      }
  456:                               while ($token=$parser->get_token) {
  457: 				if ($token->[0] eq 'S') {
  458:                                   if ($token->[1] eq 'a') {
  459: 				      if ($token->[2]->{'href'}) {
  460:                                          $rlinks[$#rlinks+1]=
  461: 					     $token->[2]->{'href'};
  462: 				      }
  463: 				  } elsif ($token->[1] eq 'img') {
  464:                                          $rlinks[$#rlinks+1]=
  465: 					     $token->[2]->{'src'};
  466: 				  } elsif ($token->[1] eq 'embed') {
  467:                                          $rlinks[$#rlinks+1]=
  468: 					     $token->[2]->{'src'};
  469: 				  } elsif ($token->[1] eq 'base') {
  470: 				      $thisdir=$token->[2]->{'href'};
  471: 				  } elsif ($token->[1] eq 'body') {
  472: 				      $bodydef=1;
  473:                                       $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
  474:                                       $ssitext{$_}=$token->[2]->{'text'};
  475:                                       $ssilink{$_}=$token->[2]->{'link'};
  476:                                       $ssivlink{$_}=$token->[2]->{'vlink'};
  477:                                       $ssialink{$_}=$token->[2]->{'alink'};
  478:                                       if ($thisxml) {
  479: 					  $xmlbody=$token->[4];
  480:                                       }
  481:                                   } elsif ($token->[1] eq 'meta') {
  482: 				    if ($token->[4] !~ m:/>$:) {
  483: 				      $allmeta.="\n".$token->[4].'</meta>';
  484: 				    } else {
  485: 				      $allmeta.="\n".$token->[4];
  486: 				    }
  487:                                   } elsif (($token->[1] eq 'script') &&
  488:                                            ($bodydef==0)) {
  489: 				      $allscript.="\n\n"
  490:                                                 .$parser->get_text('/script');
  491:                                   } elsif (($token->[1] eq 'link') &&
  492:                                            ($bodydef==0)) {
  493:                                       if (($token->[2]->{'href'} !~ m{^/adm/}) &&
  494:                                           ($token->[2]->{'rel'} eq 'stylesheet')) {
  495:                                               $css_hrefs[$#css_hrefs+1]=
  496:                                                   $token->[2]->{'href'};
  497: 
  498:                                       }
  499:                                   }
  500: 			        }
  501: 			      }
  502:                               if ($output=~/\<body[^\>]*\>(.*)/si) {
  503:                                  $output=$1; 
  504:                               }
  505:                               $output=~s/\<\/body\>.*//si;
  506:                               if ($output=~/\<form/si) {
  507:                                   my $hastimer; 
  508: 				  $nforms++;
  509:                                   $output=~s/\<form[^\>]*\>//gsi;
  510:                                   $output=~s/\<\/form[^\>]*\>//gsi;
  511:                                   if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
  512:                                       $nuploads++;
  513:                                   }
  514:                                   if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
  515:                                       $ntimers++;
  516:                                       $hastimer = 1;
  517:                                   }
  518:                                   $output=~
  519: 				      s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
  520:                                   $output=~
  521:                                       s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
  522:                                   $output=~
  523:                                       s/(\Qthis.form.elements['\E)(HW(?:VAL|CHK)_[^']+\'\]\.(?:value=\'|checked))/$1$prefix$2/gsi;
  524:                                   if ($hastimer) {
  525:                                       $output=~
  526:                                           s/\<(input[^\>]+name=\Q"$prefix\Eaccessbutton"[^\>]+)(?:\Qdocument.markaccess.submit();\E)([^\>]*)\>/\<$1pageTimer(this.form,'$prefix')$2\>/gsi;
  527:                                       $output=~  s/\<(input[^\>]+name=\Q"$prefix\Emarkaccess"[^\>]+value=["'])(?:yes)(['"][^\>]*)\>/\<$1$2\>/gsi;
  528:                                   }
  529:                                   if ($matheditor eq 'dragmath') {
  530:                                       $output=~
  531:                                           s/(\Qjavascript:LC_mathedit_\E)(HWVAL_)([^'"]+?)(\(['"]*)(\QHWVAL_\E\3['"]\)\;void\(0\)\;)/$1$idprefix$2$3$4$idprefix$5/g;
  532:                                       $output=~
  533:                                           s/(function\s+LC_mathedit_)(HWVAL_)([^'"]+?)(\s+\(LCtextline\))/$1$idprefix$2$3$4/g;
  534:                                   } elsif ($matheditor eq 'lcmath') {
  535:                                       $output=~
  536:                                           s/(var\s+LCmathField\s+=\s+document\.getElementById\(['"])([^'"]+?)(['"]\)\;)/$1$idprefix$2$3/g;
  537:                                   }
  538:                                   $output=~
  539:                                       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;
  540:                                   $output=~
  541:                                       s/(\Q<td class="LC_status_\E)(\Qsubmit_\E)([^\"]*)(\s*[^\"]*"\>)/$1$idprefix$2$3$4/g;
  542:                                   if ($nuploads) {
  543:                                        ($turninpaths{$prefix},$multiresps{$prefix}) = 
  544:                                            &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
  545:                                        if ($turninparent eq '') {
  546:                                            $turninparent = $turninpaths{$prefix};
  547:                                            $turninparent =~ s{(/[^/]+)$}{}; 
  548:                                        }
  549:                                   }
  550:                                   $output=~
  551:                                       s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
  552:                                   $output=~
  553:                                       s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
  554:                                   unless ($hastimer) {
  555:                                       if ($plainsrc =~ /$LONCAPA::assess_re/) {
  556:                                           %Apache::lonhomework::history =
  557:                                               &Apache::lonnet::restore($symb,$courseid,$domain,$name);
  558:                                           my $type = 'problem';
  559:                                           if ($extension eq 'task') {
  560:                                               $type = 'Task';
  561:                                           }
  562:                                           my ($status,$accessmsg,$slot_name,$slot) =
  563:                                               &Apache::lonhomework::check_slot_access('0',$type,$symb);
  564:                                           undef(%Apache::lonhomework::history);
  565:                                           my $probstatus = &Apache::lonnet::EXT("resource.0.problemstatus",$symb);
  566:                                           if (($status eq 'CAN_ANSWER') || (($status eq 'CANNOT_ANSWER') && 
  567:                                               (($probstatus eq 'no') || ($probstatus eq 'no_feedback_ever'))) ||
  568:                                               (($status eq 'NOT_YET_VIEWED') && ($posthash{'markaccess'} eq 'yes'))) {
  569:                                               my ($slothastime,$timerhastime);
  570:                                               if ($slot_name ne '') {
  571:                                                   if (ref($slot) eq 'HASH') {
  572:                                                       if (($slot->{'starttime'} < $now) &&
  573:                                                           ($slot->{'endtime'} > $now)) {
  574:                                                           $slothastime = $now - $slot->{'endtime'};
  575:                                                       }
  576:                                                   }
  577:                                               }
  578:                                               my $duedate = &Apache::lonnet::EXT("resource.0.duedate",$symb);
  579:                                               my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
  580:                                               if (@interval > 1) {
  581:                                                   my $first_access;
  582:                                                   if ($interval[1] eq 'map') {
  583:                                                       my $ignorecache;
  584:                                                       if ($env{'form.'.$prefix.'markaccess'} eq 'yes') {
  585:                                                           $ignorecache = 1;
  586:                                                       }
  587:                                                       $first_access=&Apache::lonnet::get_first_access($interval[1],undef,$pagesymb,$ignorecache);
  588:                                                       if (($first_access) && (!$pagefirstaccess)) {
  589:                                                           $pagefirstaccess = $first_access;
  590:                                                       }
  591:                                                   } else {
  592:                                                       $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
  593:                                                   }
  594:                                                   if ($first_access > 0) {
  595:                                                       my ($timelimit) = ($interval[0] =~ /^(\d+)/);
  596:                                                       if ($timelimit) {
  597:                                                           my $timeremains = $timelimit + $first_access - $now;
  598:                                                           if ($timeremains > 0) {
  599:                                                               $timerhastime = $timeremains;
  600:                                                           }
  601:                                                       }
  602:                                                   }
  603:                                               }
  604:                                               if (($duedate && $duedate > $now) ||
  605:                                                   (!$duedate && $timerhastime > 0) ||
  606:                                                   ($slot_name ne '' && $slothastime)) {
  607:                                                   if ((@interval > 1 && $timerhastime) ||
  608:                                                       ($type eq 'Task' && $slothastime)) {
  609:                                                       $countdowndisp{$symb} = 'inline';
  610:                                                       if ((@interval > 1) && ($timerhastime)) {
  611:                                                           $hastimeleft{$symb} = $timerhastime;
  612:                                                           if ($pagefirstaccess) {
  613:                                                               my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
  614:                                                               ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
  615:                                                               if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
  616:                                                                   $usesdone = 'done';
  617:                                                                   $donebuttontext = $1;
  618:                                                                   (undef,$proctor,$secret) = split(/_/,$2);
  619:                                                               } elsif ($donesuffix =~ /^done(|_.+)$/) {
  620:                                                                   $donebuttontext = &mt('Done');
  621:                                                                   ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
  622:                                                               }
  623:                                                               if ($usesdone eq 'done') {
  624:                                                                   $donebutton{$symb} = $timelimit;
  625:                                                                   push(@{$buttonbytime{$timelimit}},$symb);
  626:                                                                   $donebtnextra{$symb} = {
  627:                                                                                               text    => $donebuttontext,
  628:                                                                                               proctor => $proctor,
  629:                                                                                               secret  => $secret,
  630:                                                                                               type    => $interval[1],
  631:                                                                                          };
  632:                                                               }
  633:                                                           }
  634:                                                       } else {
  635:                                                           $hastimeleft{$symb} = $slothastime;
  636:                                                       }
  637:                                                   } else {
  638:                                                       $hastimeleft{$symb} = $duedate - $now;
  639:                                                       $countdowndisp{$symb} = 'none';
  640:                                                   }
  641:                                                   unless ($donebutton{$symb}) {
  642:                                                       $donebutton{$symb} = 0;
  643:                                                   }
  644:                                               }
  645:                                           }
  646:                                       }
  647:                                   }
  648:                               }
  649:                               $thisdir=~s/\/[^\/]*$//;
  650: 			      foreach (@rlinks) {
  651: 				  unless (($_=~/^https?\:\/\//i) ||
  652: 					  ($_=~/^\//) ||
  653: 					  ($_=~/^javascript:/i) ||
  654: 					  ($_=~/^mailto:/i) ||
  655: 					  ($_=~/^\#/)) {
  656: 				      my $newlocation=
  657: 				    &Apache::lonnet::hreflocation($thisdir,$_);
  658:                      $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
  659: 				  }
  660: 			      }
  661:                               foreach my $css_href (@css_hrefs) {
  662:                                   next if ($css_href eq '');
  663:                                   unless ($css_href =~ m{https?://}) {
  664:                                       my $proburl = &Apache::lonnet::clutter($plainsrc);
  665:                                       unless ($css_href =~ m{^/}) {
  666:                                           my $probdir = $proburl;
  667:                                           $probdir=~s/\/[^\/]*$//;
  668:                                           $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
  669:                                       }
  670:                                       if ($css_href =~ m{^/(res|uploaded)/}) {
  671:                                           unless (($env{'httpref.'.$css_href}) ||
  672:                                                   ($httpref{'httpref.'.$css_href}) ||
  673:                                                   (&Apache::lonnet::is_on_map($css_href))) {
  674:                                               if ($env{'httpref.'.$proburl}) {
  675:                                                   $proburl = $env{'httpref.'.$proburl};
  676:                                               }
  677:                                               $httpref{'httpref.'.$css_href} = $proburl;
  678:                                           }
  679:                                       }
  680:                                   }
  681:                                   $cssrefs{$css_href} = 1;
  682:                               }
  683: # -------------------------------------------------- Deal with Applet codebases
  684:   $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
  685: 			      $ssibody{$_}=$output;
  686: # ---------------------------------------------------------------- End SSI cell
  687:                           }
  688:                       }
  689:                      } 
  690:                   }
  691:                   unless ($contents) {
  692:                       &Apache::loncommon::content_type($r,'text/html');
  693:                       $r->send_http_header;
  694:                       $r->print(&Apache::loncommon::start_page(undef,undef,
  695: 							       {'force_register' => 1}));
  696:                       $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
  697:                       $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
  698: 				&Apache::loncommon::end_page());
  699:                   } else {
  700: # ------------------------------------------------------------------ Build page
  701: 
  702: # ---------------------------------------------------------------- Send headers
  703: 		      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  704: 			  if ($isxml) {
  705: 			      &Apache::loncommon::content_type($r,'text/xml');
  706: 			  } else {
  707: 			      &Apache::loncommon::content_type($r,'text/html');
  708: 			  }
  709: 			  $r->send_http_header;
  710: # ------------------------------------------------------------------------ Head
  711: 			  if ($allscript) {
  712: 			      $allscript = 
  713: 				  "\n".'<script type="text/javascript">'."\n".
  714: 				  $allscript.
  715: 				  "\n</script>\n";
  716: 			  }
  717:                           if (($nforms) && ($nuploads)) {
  718:                               $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps).
  719:                                             '<script type="text/javascript" '.
  720:                                             'src="/res/adm/includes/file_upload.js"></script>';
  721:                           }
  722:                           if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
  723:                               my %textarea_args = (
  724:                                   dragmath => 'math',
  725:                               );
  726:                               $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
  727:                           }
  728:                           if ($ntimers) {
  729:                               $allscript .= '<script type="text/javascript">'."\n".
  730:                                             '// <![CDATA['."\n".
  731:                                             'function pageTimer(form,prefix) {'."\n".
  732:                                             "   form.elements[prefix+'markaccess'].value = 'yes';\n".
  733:                                             "   form.submit();\n".
  734:                                             '}'."\n".
  735:                                             '// ]]>'.
  736:                                             "\n</script>\n";
  737:                           }
  738:                           &Apache::lonhtmlcommon::clear_breadcrumb_tools();
  739:                           if (keys(%hastimeleft)) {
  740:                               my (%uniquetimes,%uniquedisplays);
  741:                               foreach my $item (values(%hastimeleft)) {
  742:                                   if (exists($uniquetimes{$item})) {
  743:                                       $uniquetimes{$item} ++; 
  744:                                   } else {
  745:                                       $uniquetimes{$item} = 1;
  746:                                   }
  747:                               }
  748:                               if (scalar(keys(%uniquetimes)) == 1) { 
  749:                                   my (%uniquedisplays,%uniquedones,$currdisp,$donebuttontime,
  750:                                       $donebuttonextras);
  751:                                   if (keys(%countdowndisp)) {
  752:                                       foreach my $item (values(%countdowndisp)) {
  753:                                           if (exists($uniquedisplays{$item})) {
  754:                                               $uniquedisplays{$item} ++;
  755:                                           } else {
  756:                                               $uniquedisplays{$item} = 1;
  757:                                           }
  758:                                       }
  759:                                       my @countdowndisplay = keys(%uniquedisplays);
  760:                                       if (scalar(@countdowndisplay) == 1) {
  761:                                           $currdisp = $countdowndisplay[0];
  762:                                       }
  763:                                   }
  764:                                   if (keys(%donebutton)) {
  765:                                       foreach my $item (values(%donebutton)) {
  766:                                           if (exists($uniquedones{$item})) {
  767:                                               $uniquedones{$item} ++;
  768:                                           } else {
  769:                                               $uniquedones{$item} = 1;
  770:                                           }
  771:                                       }
  772:                                       my @donebuttons = sort { $ <=> $b } (keys(%uniquedones));
  773:                                       if (scalar(@donebuttons) == 1) {
  774:                                           if ($donebuttons[0]) {
  775:                                               $donebuttontime = $donebuttons[0];
  776:                                               if (ref($buttonbytime{$donebuttontime}) eq 'ARRAY') {
  777:                                                   $donebuttonextras = $donebtnextra{$buttonbytime{$donebuttontime}->[0]};
  778:                                               }
  779:                                           }
  780:                                       }
  781:                                   }
  782:                                   &add_countdown_timer($currdisp,$donebuttontime,$donebuttonextras);
  783:                               }
  784:                           }
  785:                           my $pagebuttonshide;
  786:                           if (keys(%buttonshide)) {
  787:                               my %uniquebuttonhide;
  788:                               foreach my $item (values(%buttonshide)) {
  789:                                   if (exists($uniquebuttonhide{$item})) {
  790:                                       $uniquebuttonhide{$item} ++;
  791:                                   } else {
  792:                                       $uniquebuttonhide{$item} = 1;
  793:                                   }
  794:                               }
  795:                               if (keys(%uniquebuttonhide) == 1) {
  796:                                   if (lc((keys(%uniquebuttonhide))[0]) eq 'yes') {
  797:                                       $pagebuttonshide = 'yes';
  798:                                   }
  799:                               }
  800:                           }
  801:                           if (keys(%cssrefs)) {
  802:                               my $links;
  803:                               if (keys(%cssrefs)) {
  804:                                   foreach my $css_href (keys(%cssrefs)) {
  805:                                       next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
  806:                                       $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
  807:                                   }
  808:                               }
  809:                               if ($links) {
  810:                                   if (keys(%httpref)) {
  811:                                       &Apache::lonnet::appenv(\%httpref);
  812:                                   }
  813:                                   $allscript .= "\n$links";
  814:                               }
  815:                           }
  816: # ------------------------------------------------------------------ Start body
  817: 			  $r->print(&Apache::loncommon::start_page(undef,$allscript,
  818: 								   {'force_register' => 1,
  819: 								    'bgcolor'        => '#ffffff',
  820: 								    'hide_buttons'   => $pagebuttonshide}));
  821: # ------------------------------------------------------------------ Start form
  822: 			  if ($nforms) {
  823: 			      my $fmtag = '<form name="lonhomework" method="post"  enctype="multipart/form-data"';
  824:                               if ($nuploads) {
  825:                                   my $multi;
  826:                                   if ($nuploads > 1) {
  827:                                       $multi = 1;
  828:                                   }
  829:                                   $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
  830:                               }
  831:                               $fmtag .= ' action="'.
  832: 					&Apache::lonenc::check_encrypt($requrl)
  833: 					.'" id="LC_page">';
  834:                               $r->print($fmtag);
  835: 			  }
  836: 		      } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
  837: 			  #  I think this is not needed as the header
  838: 			  # will be put in for each of the page parts
  839: 			  # by the londefdef.pm now that we are opening up
  840: 			  # the parts of a page.
  841: 			  #$r->print('\documentclass{article}
  842:                           #       \newcommand{\keephidden}[1]{}           
  843:                           #       \usepackage[dvips]{graphicx}
  844:                           #       \usepackage{epsfig}
  845:                           #       \usepackage{calc}
  846:                           #       \usepackage{longtable}
  847:                           #       \begin{document}');
  848: 		      }
  849: # ----------------------------------------------------------------- Start table
  850: 		      if (($target eq 'tex') || ($target eq 'tex_answer')) {
  851: #			 #  $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
  852: 			  if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
  853: 		      } else {
  854: 			  $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
  855: 		      }
  856: # generate rows
  857:                       for ($i=0;$i<=$#rows;$i++) {
  858: 			if ($rows[$i]) {
  859: 			    unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  860: 				$r->print("\n<tr>");
  861: 			    }
  862:                           my @colcont=split(/\&/,$rows[$i]);
  863:                           my $avespan=$lcm/($#colcont+1);
  864:                           for ($j=0;$j<=$#colcont;$j++) {
  865:                               my $rid=$colcont[$j];
  866: 			      my $metainfo =&get_buttons(\%hash,$rid,\%buttonshide,$hostname).'<br />';
  867: 			    unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  868: 				$r->print('<td colspan="'.$avespan.'"');
  869: 			    }
  870:                               if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
  871: 				  unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  872: 				      if ($ssibgcolor{$rid}) {
  873: 					  $r->print(' bgcolor="'.
  874: 						    $ssibgcolor{$rid}.'"');
  875: 				      }
  876: 				      $r->print('>'.$metainfo.'<font');
  877: 		    
  878: 				      if ($ssitext{$rid}) {
  879: 					  $r->print(' text="'.$ssitext{$rid}.'"');
  880: 				      }
  881: 				      if ($ssilink{$rid}) {
  882: 					  $r->print(' link="'.$ssilink{$rid}.'"');
  883: 				      }
  884: 				      if ($ssitext{$rid}) {
  885: 					  $r->print(' vlink="'.$ssivlink{$rid}.'"');
  886: 				      }
  887: 				      if ($ssialink{$rid}) {
  888: 					  $r->print(' alink="'.$ssialink{$rid}.'"');
  889: 				      }             
  890: 				      $r->print('>');
  891: 				  }
  892:                                   $r->print($ssibody{$rid});
  893: 				  unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  894: 				      $r->print('</font>');
  895:                                   }
  896:                                   if ($env{'course.'.
  897:                                       $env{'request.course.id'}.
  898:                                       '.pageseparators'} eq 'yes') {
  899:                                       unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  900:                                           $r->print('<hr />');
  901:                                       } 
  902: 				  }
  903: 			      } elsif ($cellemb{$rid} eq 'img') {
  904:                                   $r->print('>'.$metainfo.'<img src="'.
  905:                                     $hash{'src_'.$rid}.'" />');
  906: 			      } elsif ($cellemb{$rid} eq 'emb') {
  907:                                   $r->print('>'.$metainfo.'<embed src="'.
  908:                                     $hash{'src_'.$rid}.'"></embed>');
  909:                               } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
  910:                                   $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />');
  911:                                   unless ($cellemb{$rid} eq 'wrp') {
  912:                                       $r->print(&mt('It is recommended that you use an up-to-date virus scanner before handling this file.'));
  913:                                   }
  914:                                   $r->print('</p><p><table>'.
  915:                                             &Apache::londocs::entryline(0,
  916:                                                                         &mt("Click to download or use your browser's Save Link function"),
  917:                                                                         '/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).
  918:                                                                         '</table></p><br />');
  919:                               }
  920: 			      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  921: 				  $r->print('</td>');
  922: 			      } else {
  923: #                                  for (my $incol=1;$incol<=$avespan;$incol++) {
  924: #				      $r->print(' & ');
  925: #				  }
  926: 			      }
  927:                           }
  928: 			      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  929: 				  $r->print('</tr>');
  930: 			      } else {
  931: #				  $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
  932: 			      }
  933: 		        }
  934:                       }
  935: 		      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  936: 			  $r->print("\n</table>");
  937: 		      } else {
  938: #			  $r->print('\end{longtable}\strut');
  939: 		      }
  940: # ---------------------------------------------------------------- Submit, etc.
  941:                       if ($nforms) {
  942:                           my $class;
  943:                           if ($nforms > 1) {
  944:                               $class = ' class="LC_hwk_submit"';
  945:                               if ($ntimers) {
  946:                                   $nforms = 1;
  947:                                   $class = '';
  948:                               }
  949:                           }
  950:                           $r->print(
  951: 	                  '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
  952: 			  (($nforms>1)?'submit':'hidden').'"'.$class.' id="all_submit" />'.
  953:                           '<input type="hidden" name="all_submit_pressed" '.
  954:                           'id="all_submit_pressed" value="" />'.
  955:                           '<div id="msg_all_submit" style="display:none">'.
  956:                           &mt('Processing your submission ...').'</div></form>');
  957:                       }
  958: 		      unless (($target eq 'tex') || ($target eq 'tex_answer')) {
  959: 			  $r->print(&Apache::loncommon::end_page({'discussion'
  960: 								      => 1,}));
  961: 		      } else {
  962: 			  $r->print('\end{document}'.$number_of_columns);
  963: 		      }
  964: 		      &Apache::lonnet::symblist($requrl,%symbhash);
  965: 		      my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  966: 		      &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
  967: # -------------------------------------------------------------------- End page
  968:                   }                  
  969: # ------------------------------------------------------------- End render page
  970:               } else {
  971:                   &Apache::loncommon::content_type($r,'text/html');
  972:                   $r->send_http_header;
  973:                   &Apache::lonsequence::viewmap($r,$requrl);
  974:               }
  975: # ------------------------------------------------------------------ Untie hash
  976:               unless (untie(%hash)) {
  977:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
  978:                        "Could not untie coursemap $fn (browse).</font>"); 
  979:               }
  980: # -------------------------------------------------------------------- All done
  981: 	      return OK;
  982: # ----------------------------------------------- Errors, hash could no be tied
  983:           }
  984:       } 
  985:   }
  986:   &Apache::loncommon::content_type($r,'text/html');
  987:   $r->send_http_header;
  988:   &Apache::lonsequence::viewmap($r,$requrl);
  989:   return OK; 
  990: }
  991: 
  992: sub get_buttons {
  993:     my ($hash,$rid,$buttonshide,$hostname) = @_;
  994: 
  995:     my ($mapid,$resid)=split(/\./,$rid);
  996:     my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
  997: 					  $resid,
  998: 					  $hash->{'src_'.$rid});
  999:     my ($aname,$shownsymb);
 1000:     if (($hash->{'encrypted_'.$rid}) && (!$env{'request.role.adv'})) {
 1001:         $aname = 'LC_'.$rid;
 1002:     } else {
 1003:         $shownsymb = $symb;
 1004:         my $dispsymb = $symb;
 1005:         if ($symb =~ /\#([^\#]+)$/) {
 1006:             my $escan = &escape('#');
 1007:             $dispsymb =~ s/#([^\#]+)$/$escan$1/;
 1008:         }
 1009:         $aname = &escape($dispsymb);
 1010:     }
 1011:     my $metainfo = '<a name="'.$aname.'"></a>';
 1012:     unless ($env{'request.role.adv'}) {
 1013:         if ($buttonshide->{$symb} eq 'yes') {
 1014:             return $metainfo;
 1015:         }
 1016:     }
 1017:     my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
 1018:                                                ? "/$env{'request.course.sec'}"
 1019:                                                : '');
 1020:     my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
 1021:     if ($hash->{'encrypted_'.$rid}) {
 1022: 	$esrc=&Apache::lonenc::encrypted($esrc);
 1023:     }
 1024:     if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
 1025:         && $hash->{'src_'.$rid} !~ m{^/ext/}
 1026: 	&& !$env{'request.enc'}
 1027: 	&& ($env{'request.role.adv'}
 1028: 	    || !$hash->{'encrypted_'.$rid})) { 
 1029: 	$metainfo .= '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" '.
 1030: 	    'target="LONcatInfo">'.
 1031:             '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
 1032:             ' alt="'.&mt('Show Metadata').'"'.
 1033:             ' title="'.&mt('Show Metadata').'" />'.
 1034: 	    '</a>';
 1035:     }
 1036:     if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
 1037:         ($hash->{'src_'.$rid} !~ m{^/ext/})) {
 1038:         $metainfo .= '<a href="/adm/evaluate?postdata='.
 1039: 	    &escape($esrc).
 1040: 	    '" target="LONcatInfo">'.
 1041:             '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
 1042:             ' alt="'.&mt('Provide my evaluation of this resource').'"'.
 1043:             ' title="'.&mt('Provide my evaluation of this resource').'" />'.
 1044: 	    '</a>';
 1045:     }
 1046:     if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
 1047: 	($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
 1048: 
 1049: 	if ((&Apache::lonnet::allowed('mgr',$crs_sec)) ||
 1050:             (&Apache::lonnet::allowed('vgr',$crs_sec))) {
 1051: 	    $metainfo.=
 1052: 		'<a href="/adm/grades?symb='.&escape($symb).
 1053: #               '&command=submission" target="LONcatInfo">'.
 1054: 		'&command=submission">'.
 1055:                 '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
 1056:                 ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
 1057:                 ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
 1058: 		'</a>';
 1059:         }
 1060:         if (&Apache::lonnet::allowed('mgr',$crs_sec)) {
 1061:             $metainfo.=
 1062: 		'<a href="/adm/grades?symb='.&escape($symb).
 1063: #               '&command=gradingmenu" target="LONcatInfo">'.
 1064: 		'&command=gradingmenu">'.
 1065:                 '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
 1066:                 ' alt="'.&mt('Content Grades').'"'.
 1067:                 ' title="'.&mt('Content Grades').'" />'.
 1068: 		'</a>';
 1069: 	}
 1070: 	if ((&Apache::lonnet::allowed('opa',$crs_sec)) ||
 1071:             (&Apache::lonnet::allowed('vpa',$crs_sec))) {
 1072: 	    $metainfo.=
 1073: 		'<a href="/adm/parmset?symb='.&escape($symb).
 1074: #               '" target="LONcatInfo">'.
 1075: 		'" >'.
 1076:                 '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
 1077:                 ' alt="'.&mt('Content Settings').'"'.
 1078:                 ' title="'.&mt('Content Settings').'" />'.
 1079: 		'</a>';
 1080: 	}
 1081:     }
 1082:     if ($env{'request.course.id'}) {
 1083:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1084:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1085:         my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
 1086:         my $editbutton = '';
 1087:         if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
 1088:             my ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1089:                 &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
 1090:             if ($cfile ne '') {
 1091:                 my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
 1092:                                                                      $forceedit,1,$symb,$shownsymb,
 1093:                                                                      undef,&escape($env{'form.title'}),
 1094:                                                                      $hostname);
 1095:                 if ($jscall) {
 1096:                     $editbutton = 1;
 1097:                     my $icon = 'pcstr.png';
 1098:                     my $label = &mt('Edit');
 1099:                     my $title = &mt('Edit this resource');
 1100:                     my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
 1101:                               ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
 1102:                     $metainfo .= '&nbsp;<a href="javascript:'.$jscall.';">'.$pic.'</a>';
 1103:                 }
 1104:             }
 1105:         }
 1106:         if ((!$editbutton) && ($file=~/$LONCAPA::assess_re/)) {
 1107:             my $url = &Apache::lonnet::clutter($file);
 1108:             my $viewsrcbutton;
 1109:             if ((&Apache::lonnet::allowed('cre','/')) &&
 1110:                 (&Apache::lonnet::metadata($url,'sourceavail') eq 'open')) {
 1111:                 $viewsrcbutton = 1;
 1112:             } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
 1113:                 if ($url =~ m{^\Q/res/$cdom/\E($LONCAPA::match_username)/}) {
 1114:                     my $auname = $1;
 1115:                     if (($env{'request.course.adhocsrcaccess'} ne '') &&
 1116:                         (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
 1117:                         $viewsrcbutton = 1;
 1118:                     } elsif ((&Apache::lonnet::metadata($url,'sourceavail') eq 'open') &&
 1119:                              (&Apache::lonnet::allowed('bre',$crs_sec))) {
 1120:                         $viewsrcbutton = 1;
 1121:                     }
 1122:                 }
 1123:             }
 1124:             if ($viewsrcbutton) {
 1125:                 my $icon = 'pcstr.png';
 1126:                 my $label = &mt('View Source');
 1127:                 my $title = &mt('View source code');
 1128:                 my $jsrid = $rid;
 1129:                 $jsrid =~ s/\./_/g;
 1130:                 my $showurl = &escape(&Apache::lonenc::check_encrypt($url));
 1131:                 my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
 1132:                           ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
 1133:                 $metainfo .= '&nbsp;<a href="javascript:open_source_'.$jsrid.'();">'.$pic.'</a>'."\n".
 1134:                              '<script type="text/javascript">'."\n".
 1135:                              "function open_source_$jsrid() {\n".
 1136:                              "  sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename=$showurl','LONsource',".
 1137:                              "'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');\n".
 1138:                              "}\n".
 1139:                              "</script>\n";
 1140:             }
 1141:         }
 1142:     }
 1143:     return $metainfo;
 1144: }
 1145: 
 1146: sub add_countdown_timer {
 1147:     my ($currdisp,$donebuttontime,$donebuttonextras) = @_;
 1148:     my ($collapse,$expand,$alttxt,$title,$donebutton);
 1149:     if ($currdisp eq 'inline') {
 1150:         $collapse = '&#9658;&nbsp;';
 1151:     } else {
 1152:         $expand = '&#9668;&nbsp;';
 1153:     }
 1154:     if ($donebuttontime) {
 1155:         my ($type,$proctor,$donebuttontext);
 1156:         if (ref($donebuttonextras) eq 'HASH') {
 1157:             $proctor = $donebuttonextras->{'proctor'};
 1158:             $donebuttontext = $donebuttonextras->{'text'};
 1159:             $type = $donebuttonextras->{'type'};
 1160:         } else {
 1161:             $donebuttontext = &mt('Done');
 1162:             $type = 'map';
 1163:         }
 1164:         $donebutton =
 1165:             &Apache::lonmenu::done_button_js($type,'','',$proctor,$donebuttontext);
 1166:     }
 1167:     unless ($env{'environment.icons'} eq 'iconsonly') {
 1168:         $alttxt = &mt('Timer');
 1169:         $title = $alttxt.'&nbsp;';
 1170:     }
 1171:     my $desc = &mt('Countdown to due date/time');
 1172:     my $output = <<END;
 1173: $donebutton
 1174: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 1175: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 1176: $collapse
 1177: </span></a>
 1178: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 1179: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 1180: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 1181: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 1182: END
 1183:     &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$output);
 1184:     return;
 1185: }
 1186: 
 1187: sub create_extlink {
 1188:     my ($url,$anchor,$title,$linktext) = @_;
 1189:     my $shownlink;
 1190:     unless ($title eq '') {
 1191:         $shownlink = '<span style="font-weight:bold;">'.$title.'</span><br />';
 1192:     }
 1193:     my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
 1194:     $shownlink .= '<a href="'.$dest.'">'.$linktext.'</a>';
 1195:     return $shownlink;
 1196: }
 1197: 
 1198: 1;
 1199: __END__
 1200: 
 1201: 
 1202: =head1 NAME
 1203: 
 1204: Apache::lonpage - Page Handler
 1205: 
 1206: =head1 SYNOPSIS
 1207: 
 1208: Invoked by /etc/httpd/conf/srm.conf:
 1209: 
 1210:  <LocationMatch "^/res/.*\.page$>
 1211:  SetHandler perl-script
 1212:  PerlHandler Apache::lonpage
 1213:  </LocationMatch>
 1214: 
 1215: =head1 INTRODUCTION
 1216: 
 1217: This module renders a .page resource.
 1218: 
 1219: This is part of the LearningOnline Network with CAPA project
 1220: described at http://www.lon-capa.org.
 1221: 
 1222: =head1 HANDLER SUBROUTINE
 1223: 
 1224: This routine is called by Apache and mod_perl.
 1225: 
 1226: =over 4
 1227: 
 1228: =item *
 1229: 
 1230: set document type for header only
 1231: 
 1232: =item *
 1233: 
 1234: tie db file
 1235: 
 1236: =item *
 1237: 
 1238: render page
 1239: 
 1240: =item *
 1241: 
 1242: add to symb list
 1243: 
 1244: =item *
 1245: 
 1246: page parms
 1247: 
 1248: =item *
 1249: 
 1250: Get SSI output, post parameters
 1251: 
 1252: =item *
 1253: 
 1254: SSI cell rendering
 1255: 
 1256: =item *
 1257: 
 1258: Deal with Applet codebases
 1259: 
 1260: =item *
 1261: 
 1262: Build page
 1263: 
 1264: =item *
 1265: 
 1266: send headers
 1267: 
 1268: =item *
 1269: 
 1270: start body
 1271: 
 1272: =item *
 1273: 
 1274: start form
 1275: 
 1276: =item *
 1277: 
 1278: start table
 1279: 
 1280: =item *
 1281: 
 1282: submit element, etc, render page, untie hash
 1283: 
 1284: =back
 1285: 
 1286: =head1 OTHER SUBROUTINES
 1287: 
 1288: =over 4
 1289: 
 1290: =item *
 1291: 
 1292: euclid() : Euclid's method for determining the greatest common denominator.
 1293: 
 1294: =item *
 1295: 
 1296: tracetable() : Build page table.
 1297: 
 1298: =back
 1299: 
 1300: =cut
 1301: 
 1302: 

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