File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.120.4.2: download - view: text, annotated - select for diffs
Mon Sep 11 12:48:08 2017 UTC (6 years, 7 months ago) by raeburn
Branches: version_2_11_2_msu
Diff to branchpoint 1.120: preferred, unified
- For 2.11.2 (modified)
  - Support optionresponse using checkboxes instead of select boxes in a
    .page.

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

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