Annotation of rat/lonpage.pm, revision 1.60

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Page Handler
                      3: #
1.60    ! raeburn     4: # $Id: lonpage.pm,v 1.59 2004/08/29 19:25:34 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.1       www        28: # (TeX Content Handler
                     29: #
1.30      harris41   30: # YEAR=2000
1.1       www        31: # 05/29/00,05/30 Gerd Kortemeyer)
1.10      www        32: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
1.24      www        33: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16,
1.30      harris41   34: # YEAR=2001
1.27      www        35: # 08/13/01,08/30,10/1 Gerd Kortemeyer
1.33      www        36: # YEAR=2002
                     37: # 03/19 Gerd Kortemeyer
1.30      harris41   38: #
                     39: ###
1.1       www        40: 
                     41: package Apache::lonpage;
                     42: 
                     43: use strict;
                     44: use Apache::Constants qw(:common :http);
                     45: use Apache::lonnet();
1.30      harris41   46: use Apache::loncommon();
1.21      www        47: use Apache::lonxml();
1.57      raeburn    48: use Apache::lonlocal;
1.49      www        49: use Apache::lonmenu;
1.6       www        50: use HTML::TokeParser;
1.1       www        51: use GDBM_File;
1.39      www        52: use Apache::lonsequence;
1.1       www        53: 
1.2       www        54: # -------------------------------------------------------------- Module Globals
                     55: my %hash;
                     56: my @rows;
1.6       www        57: 
                     58: # ------------------------------------------------------------------ Euclid gcd
                     59: 
                     60: sub euclid {
                     61:     my ($e,$f)=@_;
                     62:     my $a; my $b; my $r;
                     63:     if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
                     64:     while ($r!=0) {
                     65: 	$a=$b; $b=$r;
                     66:         $r=$a%$b;
                     67:     }
                     68:     return $b;
                     69: }
1.2       www        70: 
                     71: # ------------------------------------------------------------ Build page table
                     72: 
                     73: sub tracetable {
                     74:     my ($sofar,$rid,$beenhere)=@_;
                     75:     my $further=$sofar;
1.57      raeburn    76:     my $randomout=0;
1.58      raeburn    77:     unless ($ENV{'request.role.adv'}) {
1.57      raeburn    78:         $randomout = $hash{'randomout_'.$rid};
                     79:     }
1.2       www        80:     unless ($beenhere=~/\&$rid\&/) {
1.57      raeburn    81:         $beenhere.=$rid.'&';
                     82:         unless ($randomout) {
                     83:             if (defined($hash{'is_map_'.$rid})) {
                     84:                 if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
                     85:                     (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
                     86:                     my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
                     87: 	            $sofar=
                     88:                        &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
                     89:                        '&'.$frid.'&');
                     90:                     $sofar++;
                     91:                     if ($hash{'src_'.$frid}) {
                     92:                         my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
                     93:                         if (($brepriv eq '2') || ($brepriv eq 'F')) {
                     94:                             if (defined($rows[$sofar])) {
                     95:                                 $rows[$sofar].='&'.$frid;
                     96:                             } else {
                     97:                                 $rows[$sofar]=$frid;
                     98:                             }
                     99: 	                }
                    100: 	            }
                    101: 	        }
                    102:             } else {
                    103:                 $sofar++;
                    104:                 if ($hash{'src_'.$rid}) {
                    105:                     my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
                    106:                     if (($brepriv eq '2') || ($brepriv eq 'F')) {
                    107:                         if (defined($rows[$sofar])) {
                    108:                             $rows[$sofar].='&'.$rid;
                    109:                         } else {
                    110:                             $rows[$sofar]=$rid;
                    111:                         }
                    112: 	            }
                    113:                 }
                    114:             }
                    115:         }
                    116: 
                    117:         if (defined($hash{'to_'.$rid})) {
                    118: 	    my $mincond=1;
                    119:             my $next='';
                    120:             foreach (split(/\,/,$hash{'to_'.$rid})) {
                    121:                 my $thiscond=
1.11      www       122:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
1.57      raeburn   123:                 if ($thiscond>=$mincond) {
                    124: 		    if ($next) {
                    125: 		        $next.=','.$_.':'.$thiscond;
                    126:                     } else {
                    127:                         $next=$_.':'.$thiscond;
                    128: 		    }
                    129:                     if ($thiscond>$mincond) { $mincond=$thiscond; }
                    130: 	        }
                    131:             }
                    132:             foreach (split(/\,/,$next)) {
                    133:                 my ($linkid,$condval)=split(/\:/,$_);
                    134:                 if ($condval>=$mincond) {
                    135:                     my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
                    136:                     if ($now>$further) { $further=$now; }
                    137: 	        }
                    138:             }
                    139:         }
1.2       www       140:     }
                    141:     return $further;
                    142: }
                    143: 
1.1       www       144: # ================================================================ Main Handler
                    145: 
                    146: sub handler {
                    147:   my $r=shift;
                    148: 
1.3       www       149: # ------------------------------------------- Set document type for header only
1.1       www       150: 
1.3       www       151:   if ($r->header_only) {
                    152:        if ($ENV{'browser.mathml'}) {
1.53      www       153:            &Apache::loncommon::content_type($r,'text/xml');
1.3       www       154:        } else {
1.53      www       155:            &Apache::loncommon::content_type($r,'text/html'); 
1.3       www       156:        }
                    157:        $r->send_http_header;
                    158:        return OK;
                    159:    }
1.43      sakharuk  160:   
1.39      www       161:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    162:                                           ['forceselect','launch']);
1.43      sakharuk  163:   my $number_of_columns = 1;
1.37      sakharuk  164:   my $requrl=$r->uri;  
                    165:   my $target = $ENV{'form.grade_target'};
1.55      www       166: #  &Apache::lonnet::logthis("Got a target of $target");
1.54      albertel  167:   if ($target eq 'meta') {
                    168:       &Apache::loncommon::content_type($r,'text/html');
                    169:       $r->send_http_header;
                    170:       return OK;
                    171:   }
1.1       www       172: # ----------------------------------------------------------------- Tie db file
1.39      www       173:   if (($ENV{'request.course.fn'}) && (!$ENV{'form.forceselect'})) {
1.1       www       174:       my $fn=$ENV{'request.course.fn'};
                    175:       if (-e "$fn.db") {
1.44      albertel  176:           if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
1.1       www       177: # ------------------------------------------------------------------- Hash tied
                    178:               my $firstres=$hash{'map_start_'.$requrl};
                    179:               my $lastres=$hash{'map_finish_'.$requrl};
                    180:               if (($firstres) && ($lastres)) {
                    181: # ----------------------------------------------------------------- Render page
                    182: 
1.3       www       183:                   @rows=();
1.2       www       184: 
1.45      www       185:                   &tracetable(0,$firstres,'&');
1.2       www       186: 
1.9       www       187: # ------------------------------------------------------------ Add to symb list
                    188: 
1.2       www       189:                   my $i;
1.9       www       190:                   my %symbhash=();
                    191:                   for ($i=0;$i<=$#rows;$i++) {
                    192: 		     if ($rows[$i]) {
                    193:                         my @colcont=split(/\&/,$rows[$i]);
1.30      harris41  194:                         foreach (@colcont) {
1.9       www       195:                            $symbhash{$hash{'src_'.$_}}='';
1.30      harris41  196: 		        }
1.9       www       197: 		     }
                    198: 		  }
                    199:                   &Apache::lonnet::symblist($requrl,%symbhash);
                    200: 
                    201: # ------------------------------------------------------------------ Page parms
                    202: 
1.4       www       203:                   my $j;
1.6       www       204:                   my $lcm=1;
                    205:                   my $contents=0;
1.7       www       206:                   my $nforms=0;
1.6       www       207:                   
                    208:                   my %ssibody=();
                    209:                   my %ssibgcolor=();
                    210:                   my %ssitext=();
                    211:                   my %ssilink=();
                    212:                   my %ssivlink=();
                    213:                   my %ssialink=();
1.14      www       214:      
                    215:                   my %metalink=();
                    216: 
1.6       www       217:                   my %cellemb=();
1.3       www       218: 
1.7       www       219:                   my $allscript='';
                    220:                   my $allmeta='';
                    221: 
                    222:                   my $isxml=0;
                    223:                   my $xmlheader='';
                    224:                   my $xmlbody='';
                    225: 
1.3       www       226: # --------------------------------------------- Get SSI output, post parameters
                    227: 
1.2       www       228:                   for ($i=0;$i<=$#rows;$i++) {
1.4       www       229: 		     if ($rows[$i]) {
1.6       www       230: 		      $contents++;
1.3       www       231:                       my @colcont=split(/\&/,$rows[$i]);
1.6       www       232:                       $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
1.30      harris41  233:                       foreach (@colcont) {
1.3       www       234:                           my $src=$hash{'src_'.$_};
1.5       www       235:                           $src=~/\.(\w+)$/;
1.14      www       236:                           $metalink{$_}=$src.'.meta';
1.30      harris41  237:                           $cellemb{$_}=Apache::loncommon::fileembstyle($1);
1.3       www       238:                           if ($cellemb{$_} eq 'ssi') {
                    239: # --------------------------------------------------------- This is an SSI cell
1.5       www       240: 			      my $prefix=$_.'_';
                    241:                               my %posthash=('request.prefix' => $prefix);
1.56      sakharuk  242: 			      if ($ENV{'form.grade_target'} eq 'tex') {
                    243: 				  $posthash{'grade_target'}=$ENV{'form.grade_target'};
                    244: 				  $posthash{'textwidth'}=$ENV{'form.textwidth'};
                    245: 				  $posthash{'problem_split'}=$ENV{'form.problem_split'};
                    246: 				  $posthash{'latex_type'}=$ENV{'form.latex_type'};
                    247: 				  $posthash{'rndseed'}=$ENV{'form.rndseed'};
                    248: 			      }
1.8       www       249:                               if (($ENV{'form.'.$prefix.'submit'}) 
1.7       www       250:                                || ($ENV{'form.all_submit'})) {
1.30      harris41  251:                                foreach (keys %ENV) {
1.5       www       252: 				  if ($_=~/^form.$prefix/) {
                    253: 				      my $name=$_;
                    254:                                       $name=~s/^form.$prefix//;
                    255:                                       $posthash{$name}=$ENV{$_};
                    256:                                   }
1.30      harris41  257:                                }
1.7       www       258: 			      }
1.5       www       259:                               my $output=Apache::lonnet::ssi($src,%posthash);
1.50      www       260: 			      $output=~
                    261: 	    s/\/\/ BEGIN LON\-CAPA Internal.+\/\/ END LON\-CAPA Internal\s//gs;
1.46      sakharuk  262:                               if ($target eq 'tex') {
                    263: 				  $output =~ s/^([^&]+)\\begin{document}//;
                    264: 				  $output =~ s/\\end{document}//;
                    265: 				  $output = '\parbox{\minipagewidth}{ '.$output.' }';
                    266:                                   #some additional cleanup necessary for LateX (due to limitations of table environment 
                    267: 				  $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
                    268: 			      }
1.6       www       269:                               my $parser=HTML::TokeParser->new(\$output);
                    270:                               my $token;
1.12      www       271:                               my $thisdir=$src;
1.6       www       272:                               my $bodydef=0;
1.7       www       273:                               my $thisxml=0;
1.12      www       274:                               my @rlinks=();
1.7       www       275:                               if ($output=~/\?xml/) {
                    276:                                  $isxml=1;
                    277:                                  $thisxml=1;
                    278:                                  $output=~
                    279:          /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
                    280:                                  $xmlheader=$1;
                    281: 			      }
1.12      www       282:                               while ($token=$parser->get_token) {
                    283: 				if ($token->[0] eq 'S') {
                    284:                                   if ($token->[1] eq 'a') {
                    285: 				      if ($token->[2]->{'href'}) {
                    286:                                          $rlinks[$#rlinks+1]=
                    287: 					     $token->[2]->{'href'};
                    288: 				      }
                    289: 				  } elsif ($token->[1] eq 'img') {
                    290:                                          $rlinks[$#rlinks+1]=
                    291: 					     $token->[2]->{'src'};
                    292: 				  } elsif ($token->[1] eq 'embed') {
                    293:                                          $rlinks[$#rlinks+1]=
                    294: 					     $token->[2]->{'src'};
                    295: 				  } elsif ($token->[1] eq 'base') {
                    296: 				      $thisdir=$token->[2]->{'href'};
                    297: 				  } elsif ($token->[1] eq 'body') {
1.7       www       298: 				      $bodydef=1;
                    299:                                       $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
                    300:                                       $ssitext{$_}=$token->[2]->{'text'};
                    301:                                       $ssilink{$_}=$token->[2]->{'link'};
                    302:                                       $ssivlink{$_}=$token->[2]->{'vlink'};
                    303:                                       $ssialink{$_}=$token->[2]->{'alink'};
                    304:                                       if ($thisxml) {
                    305: 					  $xmlbody=$token->[4];
                    306:                                       }
1.12      www       307:                                   } elsif ($token->[1] eq 'meta') {
1.28      albertel  308: 				    if ($token->[4] !~ m:/>$:) {
1.7       www       309: 				      $allmeta.="\n".$token->[4].'</meta>';
1.28      albertel  310: 				    } else {
                    311: 				      $allmeta.="\n".$token->[4];
                    312: 				    }
1.12      www       313:                                   } elsif (($token->[1] eq 'script') &&
                    314:                                            ($bodydef==0)) {
1.7       www       315: 				      $allscript.="\n\n"
                    316:                                                 .$parser->get_text('/script');
1.6       www       317:                                   }
1.12      www       318: 			        }
                    319: 			      }
1.6       www       320:                               if ($output=~/\<body[^\>]*\>(.*)/si) {
                    321:                                  $output=$1; 
                    322:                               }
                    323:                               $output=~s/\<\/body\>.*//si;
1.7       www       324:                               if ($output=~/\<form/si) {
                    325: 				  $nforms++;
                    326:                                   $output=~s/\<form[^\>]*\>//gsi;
                    327:                                   $output=~s/\<\/form[^\>]*\>//gsi;
1.17      www       328:                                   $output=~
1.18      www       329: 				      s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([\w\.\:]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
1.7       www       330:                               }
1.12      www       331:                               $thisdir=~s/\/[^\/]*$//;
1.30      harris41  332: 			      foreach (@rlinks) {
1.12      www       333: 				  unless (($_=~/^http:\/\//i) ||
1.31      albertel  334: 					  ($_=~/^\//) ||
                    335: 					  ($_=~/^javascript:/i) ||
                    336: 					  ($_=~/^mailto:/i) ||
                    337: 					  ($_=~/^\#/)) {
1.12      www       338: 				      my $newlocation=
                    339: 				    &Apache::lonnet::hreflocation($thisdir,$_);
                    340:                      $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
                    341: 				  }
1.30      harris41  342: 			      }
1.24      www       343: # -------------------------------------------------- Deal with Applet codebases
                    344:   $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
1.5       www       345: 			      $ssibody{$_}=$output;
1.3       www       346: # ---------------------------------------------------------------- End SSI cell
                    347:                           }
1.30      harris41  348:                       }
1.4       www       349:                      } 
1.2       www       350:                   }
1.6       www       351:                   unless ($contents) {
1.53      www       352:                       &Apache::loncommon::content_type($r,'text/html');
1.3       www       353:                       $r->send_http_header;
1.59      raeburn   354:                       $r->print('<html>'."\n".
                    355:                                 '<head>'."\n".
                    356:                                 &Apache::lonmenu::registerurl(1,undef)."\n".
                    357:                                 '</head>'."\n".
                    358:                                 '<body bgcolor="#FFFFFF" onLoad="'
                    359:                                 .&Apache::lonmenu::loadevents.
                    360:                                 '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.
                    361:                                  &Apache::lonmenu::menubuttons(undef,$target,1)
                    362:                                );
                    363:                       $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
                    364:                       $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').'.</body></html>');
1.3       www       365:                   } else {
                    366: # ------------------------------------------------------------------ Build page
1.7       www       367: 
                    368: # ---------------------------------------------------------------- Send headers
1.37      sakharuk  369: 		      unless ($target eq 'tex') {
                    370: 			  if ($isxml) {
1.53      www       371: 			      &Apache::loncommon::content_type($r,'text/xml');
1.37      sakharuk  372: 			      $r->send_http_header;
                    373: 			      $r->print($xmlheader);
                    374: 			  } else {
1.53      www       375: 			      &Apache::loncommon::content_type($r,'text/html');
1.37      sakharuk  376: 			      $r->send_http_header;
                    377: 			      $r->print('<html>');
                    378: 			  }
1.7       www       379: # ------------------------------------------------------------------------ Head
1.37      sakharuk  380: 			  $r->print("\n<head>\n".$allmeta);
                    381: 			  if ($allscript) {
                    382: 			      $r->print("\n<script language='JavaScript'>\n".
                    383: 					$allscript."\n</script>\n");
                    384: 			  }
1.49      www       385: 			  $r->print(&Apache::lonmenu::registerurl(1,undef));
1.37      sakharuk  386: 			  $r->print("\n</head>\n");
1.7       www       387: # ------------------------------------------------------------------ Start body
1.37      sakharuk  388: 			  if ($isxml) {
                    389: 			      $r->print($xmlbody);
                    390: 			  } else {
1.51      www       391: 			      $r->print(
                    392:                '<body bgcolor="#FFFFFF" onLoad="'.&Apache::lonmenu::loadevents.
                    393:                '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.
                    394:                               &Apache::lonmenu::menubuttons(undef,$target,1)
                    395: 					);
1.37      sakharuk  396: 			  }
1.7       www       397: # ------------------------------------------------------------------ Start form
1.37      sakharuk  398: 			  if ($nforms) {
                    399: 			      $r->print('<form method="post" action="'.
                    400: 					$requrl.'">');
1.40      sakharuk  401: 			  }
1.56      sakharuk  402: 		      } elsif ($target eq 'tex') {
1.47      sakharuk  403: 			  $r->print('\documentclass{article}
1.40      sakharuk  404:                                  \newcommand{\keephidden}[1]{}           
                    405:                                  \usepackage[dvips]{graphicx}
                    406:                                  \usepackage{epsfig}
                    407:                                  \usepackage{calc}
1.42      sakharuk  408:                                  \usepackage{longtable}
1.40      sakharuk  409:                                  \begin{document}');
                    410: 		      }
1.7       www       411: # ----------------------------------------------------------------- Start table
1.40      sakharuk  412: 		      if ($target eq 'tex') {
1.42      sakharuk  413: 			  $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
1.43      sakharuk  414: 			  if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
1.40      sakharuk  415: 		      } else {
1.37      sakharuk  416: 			  $r->print('<table cols="'.$lcm.'" border="0">');
                    417: 		      }
1.5       www       418:                       for ($i=0;$i<=$#rows;$i++) {
                    419: 			if ($rows[$i]) {
1.37      sakharuk  420: 			    unless ($target eq 'tex') {
                    421: 				$r->print("\n<tr>");
                    422: 			    }
1.4       www       423:                           my @colcont=split(/\&/,$rows[$i]);
1.6       www       424:                           my $avespan=$lcm/($#colcont+1);
                    425:                           for ($j=0;$j<=$#colcont;$j++) {
                    426:                               my $rid=$colcont[$j];
1.60    ! raeburn   427:                               my $metainfo = '';
        !           428:                               print STDERR "src is $hash{'src_'.$rid}\n";
        !           429:                               unless ($hash{'src_'.$rid} =~ m-^/uploaded/-) { 
        !           430:                                   $metainfo ='<a name="'.
        !           431: 	&Apache::lonnet::escape(&Apache::lonnet::declutter($hash{'src_'.$rid})).'" />'.
        !           432:                                   '<a href="'.$metalink{$rid}.'" target="LONcatInfo">'.
        !           433:                                   '<img src="/adm/lonMisc/cat_button.gif" border=0>'.
        !           434:                                   '</img></a>';
        !           435:                               }
        !           436:                               $metainfo .= '<a href="/adm/evaluate?postdata='.
        !           437: 	&Apache::lonnet::escape(&Apache::lonnet::declutter($hash{'src_'.$rid})).
        !           438:                                   '" target="LONcatInfo">'.
        !           439:                                   '<img src="/adm/lonMisc/eval_button.gif" border=0>'.
        !           440:                                   '</img></a>';
1.27      www       441:                               if (
                    442:  ($hash{'src_'.$rid}=~/\.(problem|exam|quiz|assess|survey|form)$/) &&
1.60    ! raeburn   443:  (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && 
        !           444:  ($hash{'src_'.$rid} !~ m-^/uploaded/-)) {
1.27      www       445: 				  my ($mapid,$resid)=split(/\./,$rid);
                    446:                                  my $symb=
                    447:                 &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
                    448:                 '___'.$resid.'___'.
                    449: 		&Apache::lonnet::declutter($hash{'src_'.$rid});
                    450:                                  $metainfo.=
1.36      www       451:                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).
1.52      ng        452: #                 '&command=submission" target="LONcatInfo">'.
                    453:                   '&command=submission">'.
1.27      www       454:                           '<img src="/adm/lonMisc/subm_button.gif" border=0>'.
                    455: 			  '</img></a>'.
1.36      www       456:                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).
1.52      ng        457: #                  '&command=gradingmenu" target="LONcatInfo">'.
                    458:                   '&command=gradingmenu">'.
1.27      www       459:                           '<img src="/adm/lonMisc/pgrd_button.gif" border=0>'.
                    460: 			  '</img></a>'.
1.36      www       461:                   '<a href="/adm/parmset?symb='.&Apache::lonnet::escape($symb).
1.52      ng        462: #                          '" target="LONcatInfo">'.
                    463:                           '" >'.
1.27      www       464:                           '<img src="/adm/lonMisc/pprm_button.gif" border=0>'.
                    465: 			      '</img></a>';
                    466:                               }
                    467:                               $metainfo.='<br></br>';
1.37      sakharuk  468: 			    unless ($target eq 'tex') {
                    469: 				$r->print('<td colspan="'.$avespan.'"');
                    470: 			    }
1.6       www       471:                               if ($cellemb{$rid} eq 'ssi') {
1.37      sakharuk  472: 				  unless ($target eq 'tex') {
                    473: 				      if ($ssibgcolor{$rid}) {
                    474: 					  $r->print(' bgcolor="'.
                    475: 						    $ssibgcolor{$rid}.'"');
                    476: 				      }
                    477: 				      $r->print('>'.$metainfo.'<font');
                    478: 		    
                    479: 				      if ($ssitext{$rid}) {
                    480: 					  $r->print(' text="'.$ssitext{$rid}.'"');
                    481: 				      }
                    482: 				      if ($ssilink{$rid}) {
                    483: 					  $r->print(' link="'.$ssilink{$rid}.'"');
                    484: 				      }
                    485: 				      if ($ssitext{$rid}) {
                    486: 					  $r->print(' vlink="'.$ssivlink{$rid}.'"');
                    487: 				      }
                    488: 				      if ($ssialink{$rid}) {
                    489: 					  $r->print(' alink="'.$ssialink{$rid}.'"');
                    490: 				      }             
                    491: 				      $r->print('>');
                    492: 				  }
                    493:                                   $r->print($ssibody{$rid});	
                    494: 				  unless ($target eq 'tex') {
                    495: 				      $r->print('</font>');
1.41      www       496:                                   }
                    497:                                   if ($ENV{'course.'.
                    498:                                       $ENV{'request.course.id'}.
                    499:                                       '.pageseparators'} eq 'yes') {
                    500:                                       unless($target eq 'tex') {
                    501:                                           $r->print('<hr />');
                    502:                                       } else {
                    503:                                           $r->print('\hline');
                    504:                                       }
1.37      sakharuk  505: 				  }
                    506: 			      } elsif ($cellemb{$rid} eq 'img') {
1.14      www       507:                                   $r->print('>'.$metainfo.'<img src="'.
1.7       www       508:                                     $hash{'src_'.$rid}.'"></img>');
1.13      www       509: 			      } elsif ($cellemb{$rid} eq 'emb') {
1.14      www       510:                                   $r->print('>'.$metainfo.'<embed src="'.
1.13      www       511:                                     $hash{'src_'.$rid}.'"></embed>');
1.60    ! raeburn   512:                               } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
        !           513:                                   $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />'.
        !           514:                                   &mt('It is recommended that you use an up-to-date virus scanner before handling this file.').'</p><p><table>'.
        !           515:                                   &Apache::londocs::entryline(0,&mt("Click to download or use your browser's Save Link function"),'/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).'</table></p><br />');
1.13      www       516:                               }
1.37      sakharuk  517: 			      unless ($target eq 'tex') {
                    518: 				  $r->print('</td>');
1.40      sakharuk  519: 			      } else {
1.43      sakharuk  520:                                   for (my $incol=1;$incol<=$avespan;$incol++) {
                    521: 				      $r->print(' & ');
                    522: 				  }
1.37      sakharuk  523: 			      }
1.4       www       524:                           }
1.37      sakharuk  525: 			      unless ($target eq 'tex') {
                    526: 				  $r->print('</tr>');
1.40      sakharuk  527: 			      } else {
1.42      sakharuk  528: 				  $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
1.37      sakharuk  529: 			      }
1.5       www       530: 		        }
1.4       www       531:                       }
1.37      sakharuk  532: 		      unless ($target eq 'tex') {
                    533: 			  $r->print("\n</table>");
1.40      sakharuk  534: 		      } else {
1.47      sakharuk  535: 			  $r->print('\end{longtable}\strut');
1.37      sakharuk  536: 		      }
1.7       www       537: # ---------------------------------------------------------------- Submit, etc.
                    538:                       if ($nforms) {
                    539:                           $r->print(
                    540: 	                  '<input name="all_submit" value="Submit All" type="'.
                    541: 			  (($nforms>1)?'submit':'hidden').'"></input></form>');
                    542:                       }
1.40      sakharuk  543: 		      unless ($target eq 'tex') {
                    544: 			  $r->print('</body>'.&Apache::lonxml::xmlend());
                    545: 		      } else {
                    546: 			  $r->print('\end{document}'.$number_of_columns);
                    547: 		      }
1.3       www       548: # -------------------------------------------------------------------- End page
                    549:                   }                  
1.1       www       550: # ------------------------------------------------------------- End render page
                    551:               } else {
1.3       www       552:                   $r->content_type('text/html');
                    553:                   $r->send_http_header;
1.39      www       554:                   &Apache::lonsequence::viewmap($r,$requrl);
1.1       www       555:               }
                    556: # ------------------------------------------------------------------ Untie hash
                    557:               unless (untie(%hash)) {
                    558:                    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    559:                        "Could not untie coursemap $fn (browse).</font>"); 
                    560:               }
                    561: # -------------------------------------------------------------------- All done
                    562: 	      return OK;
                    563: # ----------------------------------------------- Errors, hash could no be tied
                    564:           }
                    565:       } 
                    566:   }
1.39      www       567:   $r->content_type('text/html');
                    568:   $r->send_http_header;
                    569:   &Apache::lonsequence::viewmap($r,$requrl);
                    570:   return OK; 
1.1       www       571: }
                    572: 
                    573: 1;
                    574: __END__
                    575: 
1.30      harris41  576: =head1 NAME
                    577: 
                    578: Apache::lonpage - Page Handler
                    579: 
                    580: =head1 SYNOPSIS
                    581: 
                    582: Invoked by /etc/httpd/conf/srm.conf:
                    583: 
                    584:  <LocationMatch "^/res/.*\.page$>
                    585:  SetHandler perl-script
                    586:  PerlHandler Apache::lonpage
                    587:  </LocationMatch>
                    588: 
                    589: =head1 INTRODUCTION
                    590: 
                    591: This module renders a .page resource.
                    592: 
                    593: This is part of the LearningOnline Network with CAPA project
                    594: described at http://www.lon-capa.org.
                    595: 
                    596: =head1 HANDLER SUBROUTINE
                    597: 
                    598: This routine is called by Apache and mod_perl.
                    599: 
                    600: =over 4
                    601: 
                    602: =item *
                    603: 
                    604: set document type for header only
                    605: 
                    606: =item *
                    607: 
                    608: tie db file
                    609: 
                    610: =item *
                    611: 
                    612: render page
                    613: 
                    614: =item *
                    615: 
                    616: add to symb list
                    617: 
                    618: =item *
                    619: 
                    620: page parms
                    621: 
                    622: =item *
                    623: 
                    624: Get SSI output, post parameters
                    625: 
                    626: =item *
                    627: 
                    628: SSI cell rendering
                    629: 
                    630: =item *
                    631: 
                    632: Deal with Applet codebases
                    633: 
                    634: =item *
                    635: 
                    636: Build page
                    637: 
                    638: =item *
                    639: 
                    640: send headers
                    641: 
                    642: =item *
                    643: 
                    644: start body
                    645: 
                    646: =item *
                    647: 
                    648: start form
                    649: 
                    650: =item *
                    651: 
                    652: start table
                    653: 
                    654: =item *
                    655: 
                    656: submit element, etc, render page, untie hash
                    657: 
                    658: =back
                    659: 
                    660: =head1 OTHER SUBROUTINES
                    661: 
                    662: =over 4
                    663: 
                    664: =item *
                    665: 
                    666: euclid() : Euclid's method for determining the greatest common denominator.
                    667: 
                    668: =item *
                    669: 
                    670: tracetable() : Build page table.
1.1       www       671: 
1.30      harris41  672: =back
1.1       www       673: 
1.30      harris41  674: =cut
1.1       www       675: 
                    676: 
                    677: 
                    678: 

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