File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.111.2.10.2.3: download - view: text, annotated - select for diffs
Fri Nov 13 02:46:48 2020 UTC (3 years, 5 months ago) by raeburn
Branches: version_2_11_3_msu
CVS tags: version_2_11_3_uiuc
- For 2.11.3 (modified)
  Include changes in 1.139

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

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