File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.111.2.10.2.2: download - view: text, annotated - select for diffs
Sat Jul 18 21:49:35 2020 UTC (3 years, 9 months ago) by raeburn
Branches: version_2_11_3_msu
- For 2.11.3 (modified)
  Include changes in 1.130, 1.131, 1.132, 1.133, 1.134, 1.135, 1.136, 1.137,
  1.138

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

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