File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.111.2.11: download - view: text, annotated - select for diffs
Thu Mar 5 20:46:04 2020 UTC (4 years, 1 month ago) by raeburn
Branches: version_2_11_X
- For 2.11
  Backport 1.130, 1.131, 1.132, 1.133, 1.134, 1.135, 1.136, 1.137

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

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