Diff for /rat/lonpage.pm between versions 1.71 and 1.92

version 1.71, 2005/06/29 19:02:14 version 1.92, 2009/10/26 10:17:58
Line 27 Line 27
 #  #
 ###  ###
   
   
   
   
 package Apache::lonpage;  package Apache::lonpage;
   
 use strict;  use strict;
Line 39  use Apache::lonmenu; Line 42  use Apache::lonmenu;
 use HTML::TokeParser;  use HTML::TokeParser;
 use GDBM_File;  use GDBM_File;
 use Apache::lonsequence;  use Apache::lonsequence;
   use lib '/home/httpd/lib/perl/';
   use LONCAPA;
    
   
 # -------------------------------------------------------------- Module Globals  # -------------------------------------------------------------- Module Globals
 my %hash;  my %hash;
Line 75  sub tracetable { Line 81  sub tracetable {
                     my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};                      my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
             $sofar=              $sofar=
                        &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},                         &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
                        '&'.$frid.'&');                         '&'.$frid.$beenhere);
                     $sofar++;                      $sofar++;
                     if ($hash{'src_'.$frid}) {                      if ($hash{'src_'.$frid}) {
                         my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});                          my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
Line 180  sub handler { Line 186  sub handler {
                   for ($i=0;$i<=$#rows;$i++) {                    for ($i=0;$i<=$#rows;$i++) {
      if ($rows[$i]) {       if ($rows[$i]) {
                         my @colcont=split(/\&/,$rows[$i]);                          my @colcont=split(/\&/,$rows[$i]);
                         foreach (@colcont) {                          foreach my $rid (@colcont) {
                            $symbhash{$hash{'src_'.$_}}=['page','notasymb'];      my ($mapid,$resid)=split(/\./,$rid);
       $symbhash{$hash{'src_'.$rid}}=
    [$hash{'src_'.$rid},$resid];
         }          }
      }       }
   }    }
Line 201  sub handler { Line 209  sub handler {
                   my %ssivlink=();                    my %ssivlink=();
                   my %ssialink=();                    my %ssialink=();
             
                   my %metalink=();  
   
                   my %cellemb=();                    my %cellemb=();
   
                   my $allscript='';                    my $allscript='';
Line 225  sub handler { Line 231  sub handler {
   if ($hash{'encrypted_'.$_}) {    if ($hash{'encrypted_'.$_}) {
       $src=&Apache::lonenc::encrypted($src);        $src=&Apache::lonenc::encrypted($src);
   }    }
                           $metalink{$_}=$src.'.meta';  
                           $cellemb{$_}=                            $cellemb{$_}=
       &Apache::loncommon::fileembstyle($extension);        &Apache::loncommon::fileembstyle($extension);
                           if ($cellemb{$_} eq 'ssi') {                            if ($cellemb{$_} eq 'ssi') {
Line 244  sub handler { Line 249  sub handler {
   $posthash{'latex_type'}=$env{'form.latex_type'};    $posthash{'latex_type'}=$env{'form.latex_type'};
   $posthash{'rndseed'}=$env{'form.rndseed'};    $posthash{'rndseed'}=$env{'form.rndseed'};
       }        }
                               if (($env{'form.'.$prefix.'submit'})         my $submitted=exists($env{'form.all_submit'});
                                || ($env{'form.all_submit'})) {        if (!$submitted) {
                                foreach (keys %env) {    foreach my $key (keys(%env)) {
   if ($_=~/^form.$prefix/) {        if ($key=~/^form.\Q$prefix\Esubmit_/) {
       my $name=$_;    $submitted=1;last;
                                       $name=~s/^form.$prefix//;        }
                                       $posthash{$name}=$env{$_};    }
                                   }        }
                                }                                if ($submitted) {
     foreach my $key (keys(%env)) {
         if ($key=~/^form.\Q$prefix\E/) {
     my $name=$key;
     $name=~s/^form.\Q$prefix\E//;
     $posthash{$name}=$env{$key};
         }
     }
     if (exists($env{'form.all_submit'})) {
         $posthash{'all_submit'}='yes';
     }
       }        }
                               my $output=Apache::lonnet::ssi($src,%posthash);                                my $output=Apache::lonnet::ssi($src,%posthash);
       $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+// END LON-CAPA Internal\s*(-->)?\s||gs;        $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
                               if ($target eq 'tex') {                                if ($target eq 'tex') {
   $output =~ s/^([^&]+)\\begin{document}//;    $output =~ s/^([^&]+)\\begin{document}//;
   $output =~ s/\\end{document}//;    $output =~ s/\\end{document}//;
   $output = '\parbox{\minipagewidth}{ '.$output.' }';  #  $output = '\parbox{\minipagewidth}{ '.$output.' }';
                                   #some additional cleanup necessary for LateX (due to limitations of table environment                                     #some additional cleanup necessary for LateX (due to limitations of table environment 
   $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;    $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
       }        }
Line 323  sub handler { Line 338  sub handler {
                                   $output=~s/\<form[^\>]*\>//gsi;                                    $output=~s/\<form[^\>]*\>//gsi;
                                   $output=~s/\<\/form[^\>]*\>//gsi;                                    $output=~s/\<\/form[^\>]*\>//gsi;
                                   $output=~                                    $output=~
       s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([\w\.\:]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;        s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
                               }                                }
                               $thisdir=~s/\/[^\/]*$//;                                $thisdir=~s/\/[^\/]*$//;
       foreach (@rlinks) {        foreach (@rlinks) {
   unless (($_=~/^http:\/\//i) ||    unless (($_=~/^https?\:\/\//i) ||
   ($_=~/^\//) ||    ($_=~/^\//) ||
   ($_=~/^javascript:/i) ||    ($_=~/^javascript:/i) ||
   ($_=~/^mailto:/i) ||    ($_=~/^mailto:/i) ||
Line 348  sub handler { Line 363  sub handler {
                   unless ($contents) {                    unless ($contents) {
                       &Apache::loncommon::content_type($r,'text/html');                        &Apache::loncommon::content_type($r,'text/html');
                       $r->send_http_header;                        $r->send_http_header;
                       $r->print('<html>'."\n".                        $r->print(&Apache::loncommon::start_page(undef,undef,
                                 '<head>'."\n".         {'force_register' => 1,}));
                                 &Apache::lonmenu::registerurl(1,undef)."\n".  
                                 '</head>'."\n".  
                                 '<body bgcolor="#FFFFFF" onLoad="'  
                                 .&Apache::lonmenu::loadevents.  
                                 '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.  
                                  &Apache::lonmenu::menubuttons(undef,$target,1)  
                                );  
                       $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');                        $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
                       $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').'.</body></html>');                        $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
    &Apache::loncommon::end_page());
                   } else {                    } else {
 # ------------------------------------------------------------------ Build page  # ------------------------------------------------------------------ Build page
   
Line 366  sub handler { Line 375  sub handler {
       unless ($target eq 'tex') {        unless ($target eq 'tex') {
   if ($isxml) {    if ($isxml) {
       &Apache::loncommon::content_type($r,'text/xml');        &Apache::loncommon::content_type($r,'text/xml');
       $r->send_http_header;  
       $r->print($xmlheader);  
   } else {    } else {
       &Apache::loncommon::content_type($r,'text/html');        &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;  
       $r->print('<html>');  
   }    }
     $r->send_http_header;
 # ------------------------------------------------------------------------ Head  # ------------------------------------------------------------------------ Head
   $r->print("\n<head>\n".$allmeta);  
   if ($allscript) {    if ($allscript) {
       $r->print("\n<script language='JavaScript'>\n".        $allscript = 
  $allscript."\n</script>\n");    "\n".'<script type="text/javascript">'."\n".
     $allscript.
     "\n</script>\n";
   }    }
   $r->print(&Apache::lonmenu::registerurl(1,undef));  
   $r->print("\n</head>\n");  
 # ------------------------------------------------------------------ Start body  # ------------------------------------------------------------------ Start body
   if ($isxml) {    $r->print(&Apache::loncommon::start_page(undef,$allscript,
       $r->print($xmlbody);     {'force_register' => 1,
   } else {      'bgcolor'        => '#ffffff',}));
       $r->print(  
                '<body bgcolor="#FFFFFF" onLoad="'.&Apache::lonmenu::loadevents.  
                '" onUnload="'.&Apache::lonmenu::unloadevents.'">'.  
                               &Apache::lonmenu::menubuttons(undef,$target,1)  
  );  
   }  
 # ------------------------------------------------------------------ Start form  # ------------------------------------------------------------------ Start form
   if ($nforms) {    if ($nforms) {
       $r->print('<form method="post" action="'.        $r->print('<form name="lonhomework" method="post"  enctype="multipart/form-data" action="'.
  &Apache::lonenc::check_encrypt($requrl)   &Apache::lonenc::check_encrypt($requrl)
  .'">');   .'">');
   }    }
       } elsif ($target eq 'tex') {        } elsif ($target eq 'tex') {
   $r->print('\documentclass{article}    #  I think this is not needed as the header
                                  \newcommand{\keephidden}[1]{}               # will be put in for each of the page parts
                                  \usepackage[dvips]{graphicx}    # by the londefdef.pm now that we are opening up
                                  \usepackage{epsfig}    # the parts of a page.
                                  \usepackage{calc}    #$r->print('\documentclass{article}
                                  \usepackage{longtable}                            #       \newcommand{\keephidden}[1]{}           
                                  \begin{document}');                            #       \usepackage[dvips]{graphicx}
                             #       \usepackage{epsfig}
                             #       \usepackage{calc}
                             #       \usepackage{longtable}
                             #       \begin{document}');
       }        }
 # ----------------------------------------------------------------- Start table  # ----------------------------------------------------------------- Start table
       if ($target eq 'tex') {        if ($target eq 'tex') {
   $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');  # #  $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
   if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};    if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
       } else {        } else {
   $r->print('<table width="100%" cols="'.$lcm.'" border="0">');    $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
       }        }
   # generate rows
                       for ($i=0;$i<=$#rows;$i++) {                        for ($i=0;$i<=$#rows;$i++) {
  if ($rows[$i]) {   if ($rows[$i]) {
     unless ($target eq 'tex') {      unless ($target eq 'tex') {
Line 422  sub handler { Line 426  sub handler {
                           my $avespan=$lcm/($#colcont+1);                            my $avespan=$lcm/($#colcont+1);
                           for ($j=0;$j<=$#colcont;$j++) {                            for ($j=0;$j<=$#colcont;$j++) {
                               my $rid=$colcont[$j];                                my $rid=$colcont[$j];
                               my $metainfo = '';  
       my $esrc=&Apache::lonnet::declutter($hash{'src_'.$rid});        my $metainfo =&get_buttons(\%hash,$rid).'<br />';
       my ($mapid,$resid)=split(/\./,$rid);  
       my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid});  
       if ($hash{'encrypted_'.$rid}) {  
   $symb=&Apache::lonenc::encrypted($symb);  
   $esrc=&Apache::lonenc::encrypted($esrc);  
       }  
                               unless ($hash{'src_'.$rid} =~ m-^/uploaded/-) {   
                                   $metainfo ='<a name="'.&Apache::lonnet::escape($symb).'" />'.  
                                   '<a href="'.$metalink{$rid}.'" target="LONcatInfo">'.  
                                   '<img src="/adm/lonMisc/cat_button.gif" border=0>'.  
                                   '</img></a>';  
                               }  
                               $metainfo .= '<a href="/adm/evaluate?postdata='.  
   &Apache::lonnet::escape($esrc).  
                                   '" target="LONcatInfo">'.  
                                   '<img src="/adm/lonMisc/eval_button.gif" border=0>'.  
                                   '</img></a>';  
                               if (  
  ($hash{'src_'.$rid}=~/\.(problem|exam|quiz|assess|survey|form)$/) &&  
  (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) &&   
  ($hash{'src_'.$rid} !~ m-^/uploaded/-)) {  
   my ($mapid,$resid)=split(/\./,$rid);  
                                  my $symb=  
                 &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).  
                 '___'.$resid.'___'.  
  &Apache::lonnet::declutter($hash{'src_'.$rid});  
                                  $metainfo.=  
                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).  
 #                 '&command=submission" target="LONcatInfo">'.  
                   '&command=submission">'.  
                           '<img src="/adm/lonMisc/subm_button.gif" border=0>'.  
   '</img></a>'.  
                   '<a href="/adm/grades?symb='.&Apache::lonnet::escape($symb).  
 #                  '&command=gradingmenu" target="LONcatInfo">'.  
                   '&command=gradingmenu">'.  
                           '<img src="/adm/lonMisc/pgrd_button.gif" border=0>'.  
   '</img></a>'.  
                   '<a href="/adm/parmset?symb='.&Apache::lonnet::escape($symb).  
 #                          '" target="LONcatInfo">'.  
                           '" >'.  
                           '<img src="/adm/lonMisc/pprm_button.gif" border=0>'.  
       '</img></a>';  
                               }  
                               $metainfo.='<br></br>';  
     unless ($target eq 'tex') {      unless ($target eq 'tex') {
  $r->print('<td colspan="'.$avespan.'"');   $r->print('<td colspan="'.$avespan.'"');
     }      }
Line 502  sub handler { Line 462  sub handler {
                                       '.pageseparators'} eq 'yes') {                                        '.pageseparators'} eq 'yes') {
                                       unless($target eq 'tex') {                                        unless($target eq 'tex') {
                                           $r->print('<hr />');                                            $r->print('<hr />');
                                       } else {                                        } 
                                           $r->print('\hline');  
                                       }  
   }    }
       } elsif ($cellemb{$rid} eq 'img') {        } elsif ($cellemb{$rid} eq 'img') {
                                   $r->print('>'.$metainfo.'<img src="'.                                    $r->print('>'.$metainfo.'<img src="'.
                                     $hash{'src_'.$rid}.'"></img>');                                      $hash{'src_'.$rid}.'" />');
       } elsif ($cellemb{$rid} eq 'emb') {        } elsif ($cellemb{$rid} eq 'emb') {
                                   $r->print('>'.$metainfo.'<embed src="'.                                    $r->print('>'.$metainfo.'<embed src="'.
                                     $hash{'src_'.$rid}.'"></embed>');                                      $hash{'src_'.$rid}.'"></embed>');
Line 520  sub handler { Line 478  sub handler {
       unless ($target eq 'tex') {        unless ($target eq 'tex') {
   $r->print('</td>');    $r->print('</td>');
       } else {        } else {
                                   for (my $incol=1;$incol<=$avespan;$incol++) {  #                                  for (my $incol=1;$incol<=$avespan;$incol++) {
       $r->print(' & ');  #      $r->print(' & ');
   }  #  }
       }        }
                           }                            }
       unless ($target eq 'tex') {        unless ($target eq 'tex') {
   $r->print('</tr>');    $r->print('</tr>');
       } else {        } else {
   $r->print('REMOVETHEHEADOFLONGTABLE\\\\');  #  $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
       }        }
         }          }
                       }                        }
       unless ($target eq 'tex') {        unless ($target eq 'tex') {
   $r->print("\n</table>");    $r->print("\n</table>");
       } else {        } else {
   $r->print('\end{longtable}\strut');  #  $r->print('\end{longtable}\strut');
       }        }
 # ---------------------------------------------------------------- Submit, etc.  # ---------------------------------------------------------------- Submit, etc.
                       if ($nforms) {                        if ($nforms) {
Line 544  sub handler { Line 502  sub handler {
   (($nforms>1)?'submit':'hidden').'"></input></form>');    (($nforms>1)?'submit':'hidden').'"></input></form>');
                       }                        }
       unless ($target eq 'tex') {        unless ($target eq 'tex') {
   $r->print('</body>'.&Apache::lonxml::xmlend());    $r->print(&Apache::loncommon::end_page({'discussion'
         => 1,}));
       } else {        } else {
   $r->print('\end{document}'.$number_of_columns);    $r->print('\end{document}'.$number_of_columns);
       }        }
Line 576  sub handler { Line 535  sub handler {
   return OK;     return OK; 
 }  }
   
   sub get_buttons {
       my ($hash,$rid) = @_;
   
       # which icons do we use?
       my $extension='png';
       if ($env{'environment.icons'} eq 'classic') { $extension='gif'; }
   
       my $metainfo = '';
       my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
       my ($mapid,$resid)=split(/\./,$rid);
       my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
     $resid,
     $hash->{'src_'.$rid});
       if ($hash->{'encrypted_'.$rid}) {
    $symb=&Apache::lonenc::encrypted($symb);
    $esrc=&Apache::lonenc::encrypted($esrc);
       }
       if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
    && !$env{'request.enc'}
    && ($env{'request.role.adv'}
       || !$hash->{'encrypted_'.$rid})) { 
    $metainfo .='<a name="'.&escape($symb).'" />'.
       '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" target="LONcatInfo">'.
       '<img src="/adm/lonMisc/cat_button.'.$extension.'" class="LC_icon" />'.
       '</a>';
       }
       $metainfo .= '<a href="/adm/evaluate?postdata='.
    &escape($esrc).
    '" target="LONcatInfo">'.
    '<img src="/adm/lonMisc/eval_button.'.$extension.'" class="LC_icon" />'.
    '</a>';
       if (($hash->{'src_'.$rid}=~/\.(problem|exam|quiz|assess|survey|form)$/) &&
    ($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
   
    if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
       $metainfo.=
    '<a href="/adm/grades?symb='.&escape($symb).
   #               '&command=submission" target="LONcatInfo">'.
    '&command=submission">'.
    '<img src="/adm/lonMisc/subm_button.'.$extension.'" class="LC_icon" />'.
    '</a>'.
    '<a href="/adm/grades?symb='.&escape($symb).
   #               '&command=gradingmenu" target="LONcatInfo">'.
    '&command=gradingmenu">'.
    '<img src="/adm/lonMisc/pgrd_button.'.$extension.'" class="LC_icon" />'.
    '</a>';
    }
    if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
       $metainfo.=
    '<a href="/adm/parmset?symb='.&escape($symb).
   #               '" target="LONcatInfo">'.
    '" >'.
    '<img src="/adm/lonMisc/pprm_button.'.$extension.'" class="LC_icon" />'.
    '</a>';
    }
       }
       return $metainfo;
   }
   
 1;  1;
 __END__  __END__
   
   
 =head1 NAME  =head1 NAME
   
 Apache::lonpage - Page Handler  Apache::lonpage - Page Handler
Line 680  tracetable() : Build page table. Line 699  tracetable() : Build page table.
 =cut  =cut
   
   
   
   

Removed from v.1.71  
changed lines
  Added in v.1.92


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