File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.136: download - view: text, annotated - select for diffs
Thu Mar 5 16:45:32 2020 UTC (4 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Support jumping to an item in a composite page from the Contents listing:
  (a) for resources without Info icon/link
  (b) for rescource for which encrypturl is in use.

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

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