File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.122: download - view: text, annotated - select for diffs
Wed Feb 22 22:10:20 2017 UTC (7 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Pass hostname to &get_buttons() as an additional arg to eliminate ISE
  introducted in rev. 1.121.

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

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