File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.111.2.13: download - view: text, annotated - select for diffs
Wed Nov 11 21:52:05 2020 UTC (3 years, 5 months ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_4_msu, version_2_11_4, version_2_11_3
- For 2.11
  Backport 1.139

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

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