Annotation of rat/lonpage.pm, revision 1.114

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.