Annotation of rat/lonpage.pm, revision 1.111.2.12

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

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