File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.85: download - view: text, annotated - select for diffs
Tue Sep 25 23:47:54 2007 UTC (16 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#1566 - finish supprot for imageresponse in a .page

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

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