Annotation of rat/lonpage.pm, revision 1.111.2.5

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

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