File:  [LON-CAPA] / rat / lonpage.pm
Revision 1.88: download - view: text, annotated - select for diffs
Thu Nov 20 13:11:43 2008 UTC (15 years, 5 months ago) by jms
Branches: MAIN
CVS tags: HEAD
Added/created/modified POD documentation

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

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