File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.111.2.14: download - view: text, annotated - select for diffs
Mon Sep 11 13:28:55 2023 UTC (7 months, 3 weeks ago) by raeburn
Branches: version_2_11_X
- For 2.11
  Backport 1.143, 1.144

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

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