File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.91: download - view: text, annotated - select for diffs
Fri Dec 19 14:30:51 2008 UTC (15 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_8_99_0, bz5969, bz2851, HEAD, GCI_2
- Escape : in regexp, and separate ? and :

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

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