Diff for /loncom/xml/lonxml.pm between versions 1.266.2.1 and 1.286

version 1.266.2.1, 2003/08/07 19:31:16 version 1.286, 2003/10/23 18:14:16
Line 69  use Safe::Hole(); Line 69  use Safe::Hole();
 use Math::Cephes();  use Math::Cephes();
 use Math::Random();  use Math::Random();
 use Opcode();  use Opcode();
   use POSIX qw(strftime);
   
   
 sub register {  sub register {
Line 95  use Apache::style(); Line 96  use Apache::style();
 use Apache::run();  use Apache::run();
 use Apache::londefdef();  use Apache::londefdef();
 use Apache::scripttag();  use Apache::scripttag();
   use Apache::languagetags();
 use Apache::edit();  use Apache::edit();
 use Apache::inputtags();  use Apache::inputtags();
 use Apache::outputtags();  use Apache::outputtags();
Line 104  use Apache::loncommon(); Line 106  use Apache::loncommon();
 use Apache::lonfeedback();  use Apache::lonfeedback();
 use Apache::lonmsg();  use Apache::lonmsg();
 use Apache::loncacc();  use Apache::loncacc();
   use Apache::lonlocal;
   
 #==================================================   Main subroutine: xmlparse    #==================================================   Main subroutine: xmlparse  
 #debugging control, to turn on debugging modify the correct handler  #debugging control, to turn on debugging modify the correct handler
Line 158  $Apache::lonxml::usestyle=1; Line 161  $Apache::lonxml::usestyle=1;
 $Apache::lonxml::style_values='';  $Apache::lonxml::style_values='';
 $Apache::lonxml::style_end_values='';  $Apache::lonxml::style_end_values='';
   
   #array of ssi calls that need to occur after we are done parsing
   @Apache::lonxml::ssi_info=();
   
   #should we do the postag variable interpolation
   $Apache::lonxml::post_evaluate=1;
   
 sub xmlbegin {  sub xmlbegin {
   my $output='';    my $output='';
   if ($ENV{'browser.mathml'}) {    if ($ENV{'browser.mathml'}) {
Line 174  sub xmlbegin { Line 183  sub xmlbegin {
 }  }
   
 sub xmlend {  sub xmlend {
     my ($discussiononly,$symb)=@_;      my $mode='xml';
     my $discussion='';      my $status='OPEN';
     if ($ENV{'request.course.id'}) {      if ($Apache::lonhomework::parsing_a_problem) {
        my $crs='/'.$ENV{'request.course.id'};   $mode='problem';
        if ($ENV{'request.course.sec'}) {   $status=$Apache::inputtags::status[-1]; 
           $crs.='_'.$ENV{'request.course.sec'};  
        }                   
        $crs=~s/\_/\//g;  
        my $seeid=&Apache::lonnet::allowed('rin',$crs);  
        unless ($symb) {  
            $symb=&Apache::lonnet::symbread();  
        }  
        if ($symb) {  
           my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},  
                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},  
      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});  
           if ($contrib{'version'}) {  
               unless ($discussiononly) {  
                  $discussion.=  
                   '<address><hr />';  
      }  
               my $idx;  
               for ($idx=1;$idx<=$contrib{'version'};$idx++) {  
  my $hidden=($contrib{'hidden'}=~/\.$idx\./);  
  my $deleted=($contrib{'deleted'}=~/\.$idx\./);  
  unless ((($hidden) && (!$seeid)) || ($deleted)) {  
                  my $message=$contrib{$idx.':message'};  
                  $message=~s/\n/\<br \/\>/g;  
  $message=&Apache::lontexconvert::msgtexconverted($message);  
                  if ($contrib{$idx.':attachmenturl'}) {  
                      my ($fname,$ft)  
                         =($contrib{$idx.':attachmenturl'}=~/\/(\w+)\.(\w+)$/);  
      $message.='<p>Attachment: <a href="'.  
        &Apache::lonnet::tokenwrapper($contrib{$idx.':attachmenturl'}).  
                      '"><tt>'.$fname.'.'.$ft.'</tt></a>';  
                  }  
                  if ($message) {  
                   if ($hidden) {  
       $message='<font color="#888888">'.$message.'</font>';  
                   }  
                   my $screenname=&Apache::loncommon::screenname(  
                                $contrib{$idx.':sendername'},  
        $contrib{$idx.':senderdomain'});  
                   my $plainname=&Apache::loncommon::nickname(  
                                $contrib{$idx.':sendername'},  
        $contrib{$idx.':senderdomain'});  
   
                   my $sender='Anonymous';  
                   if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {  
                       $sender=&Apache::loncommon::aboutmewrapper(  
                                $plainname,  
                                $contrib{$idx.':sendername'},  
                                $contrib{$idx.':senderdomain'}).' ('.  
                               $contrib{$idx.':sendername'}.' at '.  
       $contrib{$idx.':senderdomain'}.')';  
                       if ($contrib{$idx.':anonymous'}) {  
   $sender.=' [anonymous] '.  
                                      $screenname;  
                       }  
                       if ($seeid) {  
   if ($hidden) {  
                              $sender.=' <a href="/adm/feedback?unhide='.  
  $symb.':::'.$idx.'">Make Visible</a>';  
                           } else {  
                              $sender.=' <a href="/adm/feedback?hide='.  
  $symb.':::'.$idx.'">Hide</a>';  
   }                       
                           $sender.=' <a href="/adm/feedback?deldisc='.  
  $symb.':::'.$idx.'">Delete</a>';  
                       }  
                   } else {  
                       if ($screenname) {  
   $sender='<i>'.$screenname.'</i>';  
                       }  
                   }  
   $discussion.='<p><b>'.$sender.'</b> ('.  
                       localtime($contrib{$idx.':timestamp'}).  
                       '):<blockquote>'.$message.  
                       '</blockquote></p>';  
         }  
                }   
               }  
               unless ($discussiononly) {  
                  $discussion.='</address>';  
       }  
           }  
           if ($discussiononly) {  
       $discussion.=(<<ENDDISCUSS);  
 <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">  
 <input type="submit" name="discuss" value="Post Discussion" />  
 <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />  
 <input type="hidden" name="symb" value="$symb" />  
 <input type="hidden" name="sendit" value="true" />  
 <br />  
 <font size="1">Note: in anonymous discussion, your name is visible only to  
 course faculty</font><br />  
 <textarea name=comment cols=60 rows=10 wrap=hard></textarea>  
 <p>  
 Attachment (128 KB max size): <input type="file" name="attachment" />  
 </p>  
 </form>  
 ENDDISCUSS  
              $discussion.=&Apache::lonfeedback::generate_preview_button();  
           }  
        }  
     }      }
     return $discussion.($discussiononly?'':'</html>');      return &Apache::lonfeedback::list_discussion().'</html>';
 }  }
   
 sub tokeninputfield {  sub tokeninputfield {
Line 372  sub printtokenheader { Line 281  sub printtokenheader {
         my %idhash=&Apache::lonnet::idrget($tudom,($tuname));          my %idhash=&Apache::lonnet::idrget($tudom,($tuname));
  return    return 
  '<img align="right" src="/cgi-bin/barcode.png?encode='.$token.'" />'.   '<img align="right" src="/cgi-bin/barcode.png?encode='.$token.'" />'.
                'Checked out for '.$plainname.                 &mt('Checked out for').' '.$plainname.
                '<br />User: '.$tuname.' at '.$tudom.                 '<br />'.&mt('User').': '.$tuname.' at '.$tudom.
        '<br />ID: '.$idhash{$tuname}.         '<br />'.&mt('ID').': '.$idhash{$tuname}.
        '<br />CourseID: '.$tcrsid.         '<br />'.&mt('CourseID').': '.$tcrsid.
        '<br />Course: '.$ENV{'course.'.$tcrsid.'.description'}.         '<br />'.&mt('Course').': '.$ENV{'course.'.$tcrsid.'.description'}.
                '<br />DocID: '.$token.                 '<br />'.&mt('DocID').': '.$token.
                '<br />Time: '.localtime().'<hr />';                 '<br />'.&mt('Time').': '.&Apache::lonlocal::locallocaltime().'<hr />';
     } else {      } else {
         return $token;          return $token;
     }      }
Line 451  sub xmlparse { Line 360  sub xmlparse {
  if ($ENV{'request.uri'}) {   if ($ENV{'request.uri'}) {
     &writeallows($ENV{'request.uri'});      &writeallows($ENV{'request.uri'});
  }   }
    &do_registered_ssi();
  if ($Apache::lonxml::counter_changed) { &store_counter() }   if ($Apache::lonxml::counter_changed) { &store_counter() }
  return $finaloutput;   return $finaloutput;
 }  }
Line 477  sub htmlclean { Line 387  sub htmlclean {
 }  }
   
 sub latex_special_symbols {  sub latex_special_symbols {
     my ($current_token,$stack,$parstack,$where)=@_;      my ($string,$where)=@_;
     if ($where eq 'header') {      if ($where eq 'header') {
  $current_token =~ s/(\\|_|\^)/ /g;   $string =~ s/(\\|_|\^)/ /g;
  $current_token =~ s/(\$|%|\#|&|\{|\})/\\$1/g;   $string =~ s/(\$|%|\#|&|\{|\})/\\$1/g;
    $string =~ s/_/ /g;
     } else {      } else {
  $current_token=~s/\\ /\\char92 /g;   $string=~s/\\ /\\char92 /g;
  $current_token=~s/\^/\\char94 /g;   $string=~s/\^/\\char94 /g;
  $current_token=~s/\~/\\char126 /g;   $string=~s/\~/\\char126 /g;
  $current_token=~s/(&[^A-Za-z\#])/\\$1/g;   $string=~s/(&[^A-Za-z\#])/\\$1/g;
  $current_token=~s/([^&])\#/$1\\#/g;   $string=~s/([^&])\#/$1\\#/g;
  $current_token=~s/(\$|_|{|})/\\$1/g;   $string=~s/(\$|_|{|})/\\$1/g;
  $current_token=~s/\\char92 /\\texttt{\\char92}/g;   $string=~s/\\char92 /\\texttt{\\char92}/g;
  $current_token=~s/(>|<)/\$$1\$/g; #more or less   $string=~s/(>|<)/\$$1\$/g; #more or less
  if ($current_token=~m/\d%/) {$current_token =~ s/(\d)%/$1\\%/g;} #percent after digit   if ($string=~m/\d%/) {$string =~ s/(\d)%/$1\\%/g;} #percent after digit
  if ($current_token=~m/\s%/) {$current_token =~ s/(\s)%/$1\\%/g;} #persent after space   if ($string=~m/\s%/) {$string =~ s/(\s)%/$1\\%/g;} #percent after space
    if ($string eq '%.') {$string = '\%.';} #percent at the end of statement
     }      }
     return $current_token;      return $string;
 }  }
   
 sub inner_xmlparse {  sub inner_xmlparse {
Line 569  sub inner_xmlparse { Line 481  sub inner_xmlparse {
  &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");   &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
       }        }
       #evaluate variable refs in result        #evaluate variable refs in result
       if ($result ne "") {        if ($Apache::lonxml::post_evaluate &&$result ne "") {
   my $extras;    my $extras;
   if (!$Apache::lonxml::usestyle) {    if (!$Apache::lonxml::usestyle) {
       $extras=$Apache::lonxml::style_values;        $extras=$Apache::lonxml::style_values;
Line 580  sub inner_xmlparse { Line 492  sub inner_xmlparse {
   $result= &Apache::run::evaluate($result,$safeeval,$extras);    $result= &Apache::run::evaluate($result,$safeeval,$extras);
  }   }
       }        }
         $Apache::lonxml::post_evaluate=1;
   
       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {        if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
   #Style file definitions should be correct    #Style file definitions should be correct
   if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {    if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {
       $result=&latex_special_symbols($result,$stack,$parstack);        $result=&latex_special_symbols($result);
   }    }
       }        }
   
       # Encode any high ASCII characters        # Encode any high ASCII characters
       if (!$Apache::lonxml::prevent_entity_encode) {  #      if (!$Apache::lonxml::prevent_entity_encode) {
  $result=&HTML::Entities::encode($result,"\200-\377");  # $result=&HTML::Entities::encode($result,"\200-\377");
       }  #      }
       if ($Apache::lonxml::redirection) {        if ($Apache::lonxml::redirection) {
  $Apache::lonxml::outputstack['-1'] .= $result;   $Apache::lonxml::outputstack['-1'] .= $result;
       } else {        } else {
Line 699  sub setup_globals { Line 613  sub setup_globals {
   &init_counter();    &init_counter();
   @Apache::lonxml::pwd=();    @Apache::lonxml::pwd=();
   @Apache::lonxml::extlinks=();    @Apache::lonxml::extlinks=();
     @Apache::lonxml::ssi_info=();
     $Apache::lonxml::post_evaluate=1;
   if ($target eq 'meta') {    if ($target eq 'meta') {
     $Apache::lonxml::redirection = 0;      $Apache::lonxml::redirection = 0;
     $Apache::lonxml::metamode = 1;      $Apache::lonxml::metamode = 1;
Line 742  sub init_safespace { Line 658  sub init_safespace {
   $safeeval->permit("entereval");    $safeeval->permit("entereval");
   $safeeval->permit(":base_math");    $safeeval->permit(":base_math");
   $safeeval->permit("sort");    $safeeval->permit("sort");
     $safeeval->permit("time");
   $safeeval->deny(":base_io");    $safeeval->deny(":base_io");
   $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');    $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
   $safehole->wrap(\&Apache::outputtags::multipart,$safeeval,'&multipart');    $safehole->wrap(\&Apache::outputtags::multipart,$safeeval,'&multipart');
Line 889  sub decreasedepth { Line 806  sub decreasedepth {
     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;      $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
   }    }
   if (  $Apache::lonxml::depth < -1) {    if (  $Apache::lonxml::depth < -1) {
     &Apache::lonxml::warning("Missing tags, unable to properly run file.");      &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
     $Apache::lonxml::depth='-1';      $Apache::lonxml::depth='-1';
   }    }
   my $curdepth=join('_',@Apache::lonxml::depthcounter);    my $curdepth=join('_',@Apache::lonxml::depthcounter);
Line 951  sub store_counter { Line 868  sub store_counter {
 }  }
   
 sub get_all_text {  sub get_all_text {
  my($tag,$pars)= @_;      my($tag,$pars,$style)= @_;
  &Apache::lonxml::debug("Got a ".ref($pars));      my $gotfullstack=1;
  my $gotfullstack=1;      if (ref($pars) ne 'ARRAY') {
  if (ref($pars) ne 'ARRAY') {   $gotfullstack=0;
      $gotfullstack=0;   $pars=[$pars];
      $pars=[$pars];      }
  }      if (ref($style) ne 'HASH') {
  my $depth=0;   $style={};
  my $token;      }
  my $result='';      my $depth=0;
  if ( $tag =~ m:^/: ) {       my $token;
    my $tag=substr($tag,1);       my $result='';
    #&Apache::lonxml::debug("have:$tag:");      if ( $tag =~ m:^/: ) { 
    my $top_empty=0;   my $tag=substr($tag,1); 
    while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {   #&Apache::lonxml::debug("have:$tag:");
      while (($depth >=0) && ($token = $$pars[-1]->get_token)) {   my $top_empty=0;
        #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);   while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
        if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {      while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
  $result.=$token->[1];   #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
        } elsif ($token->[0] eq 'PI') {   if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
  $result.=$token->[2];      $result.=$token->[1];
        } elsif ($token->[0] eq 'S') {   } elsif ($token->[0] eq 'PI') {
  if ($token->[1] =~ /^$tag$/i) { $depth++; }      $result.=$token->[2];
  $result.=$token->[4];   } elsif ($token->[0] eq 'S') {
        } elsif ($token->[0] eq 'E')  {      if ($token->[1] =~ /^$tag$/i) { $depth++; }
  if ( $token->[1] =~ /^$tag$/i) { $depth--; }      if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/i) { $Apache::lonxml::usestyle=1; }
  #skip sending back the last end tag      if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/i) { $Apache::lonxml::usestyle=0; }
  if ($depth > -1) { $result.=$token->[2]; } else {      $result.=$token->[4];
    $$pars[-1]->unget_token($token);   } elsif ($token->[0] eq 'E')  {
  }      if ( $token->[1] =~ /^$tag$/i) { $depth--; }
        }      #skip sending back the last end tag
      }      if ($depth == 0 && exists($$style{'/'.$token->[1]}) && $Apache::lonxml::usestyle) {
      if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }   my $string=
      if (($depth >=0) && ($#$pars > 0) ) {      '<LONCAPA_INTERNAL_TURN_STYLE_OFF end="yes" />'.
        pop(@$pars);   $$style{'/'.$token->[1]}.
        pop(@Apache::lonxml::pwd);      $token->[2].
      }   '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
    }   &Apache::lonxml::newparser($pars,\$string);
    if ($top_empty && $depth >= 0) {   #&Apache::lonxml::debug("reParsing $string");
        #never found the end tag ran out of text, throw error send back blank   next;
        &error('Never found end tag for &lt;'.$tag.'&gt;');      }
        if ($gotfullstack) {      if ($depth > -1) {
    my $newstring='</'.$tag.'>'.$result;   $result.=$token->[2];
    &Apache::lonxml::newparser($pars,\$newstring);      } else {
        }   $$pars[-1]->unget_token($token);
        $result='';      }
    }   }
  } else {      }
      while ($#$pars > -1) {      if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }
  while ($token = $$pars[-1]->get_token) {      if (($depth >=0) && ($#$pars > 0) ) {
      #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");   pop(@$pars);
      if (($token->[0] eq 'T')||($token->[0] eq 'C')||   pop(@Apache::lonxml::pwd);
  ($token->[0] eq 'D')) {      }
  $result.=$token->[1];   }
      } elsif ($token->[0] eq 'PI') {   if ($top_empty && $depth >= 0) {
  $result.=$token->[2];      #never found the end tag ran out of text, throw error send back blank
      } elsif ($token->[0] eq 'S') {      &error('Never found end tag for &lt;'.$tag.
  if ( $token->[1] =~ /^$tag$/i) {     '&gt; current string <pre>'.
      $$pars[-1]->unget_token($token); last;     &HTML::Entities::encode($result).
  } else {     '</pre>');
      $result.=$token->[4];      if ($gotfullstack) {
  }   my $newstring='</'.$tag.'>'.$result;
      } elsif ($token->[0] eq 'E')  {   &Apache::lonxml::newparser($pars,\$newstring);
  $result.=$token->[2];      }
      }      $result='';
  }   }
  if (($#$pars > 0) ) {      } else {
      pop(@$pars);   while ($#$pars > -1) {
      pop(@Apache::lonxml::pwd);      while ($token = $$pars[-1]->get_token) {
  } else { last; }   #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
      }   if (($token->[0] eq 'T')||($token->[0] eq 'C')||
  }      ($token->[0] eq 'D')) {
  if ($result =~ m|<LONCAPA_INTERNAL_TURN_STYLE_ON />|) {      $result.=$token->[1];
      $Apache::lonxml::usestyle=1;   } elsif ($token->[0] eq 'PI') {
  }      $result.=$token->[2];
  #&Apache::lonxml::debug("Exit:$result:");   } elsif ($token->[0] eq 'S') {
  return $result      if ( $token->[1] =~ /^$tag$/i) {
    $$pars[-1]->unget_token($token); last;
       } else {
    $result.=$token->[4];
       }
       if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/i) { $Apache::lonxml::usestyle=1; }
       if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/i) { $Apache::lonxml::usestyle=0; }
    } elsif ($token->[0] eq 'E')  {
       $result.=$token->[2];
    }
       }
       if (($#$pars > 0) ) {
    pop(@$pars);
    pop(@Apache::lonxml::pwd);
       } else { last; }
    }
       }
       #&Apache::lonxml::debug("Exit:$result:");
       return $result
 }  }
   
 sub newparser {  sub newparser {
Line 1049  sub parstring { Line 984  sub parstring {
       my $val=$token->[2]->{$_};        my $val=$token->[2]->{$_};
       $val =~ s/([\%\@\\\"\'])/\\$1/g;        $val =~ s/([\%\@\\\"\'])/\\$1/g;
       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }        #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
       $temp .= "my \$$_=\"$val\";"        $temp .= "my \$$_=\"$val\";";
     }      }
   }    }
   return $temp;    return $temp;
Line 1072  sub writeallows { Line 1007  sub writeallows {
     &Apache::lonnet::appenv(%httpref);      &Apache::lonnet::appenv(%httpref);
 }  }
   
   sub register_ssi {
       my ($url,%form)=@_;
       push (@Apache::lonxml::ssi_info,{'url'=>$url,'form'=>\%form});
       return '';
   }
   
   sub do_registered_ssi {
       foreach my $info (@Apache::lonxml::ssi_info) {
    my %form=%{ $info->{'form'}};
    my $url=$info->{'url'};
    &Apache::lonnet::ssi($url,%form);
       }
   }
 #  #
 # Afterburner handles anchors, highlights and links  # Afterburner handles anchors, highlights and links
 #  #
Line 1114  sub storefile { Line 1062  sub storefile {
     if (my $fh=Apache::File->new('>'.$file)) {      if (my $fh=Apache::File->new('>'.$file)) {
  print $fh $contents;   print $fh $contents;
         $fh->close();          $fh->close();
           return 1;
     } else {      } else {
       &warning("Unable to save file $file");   &warning("Unable to save file $file");
    return 0;
     }      }
 }  }
   
Line 1137  SIMPLECONTENT Line 1087  SIMPLECONTENT
   return $filecontents;    return $filecontents;
 }  }
   
   sub createnewsty {
     my $filecontents=(<<SIMPLECONTENT);
   <definetag name="">
       <render>
          <web></web>
          <tex></tex>
       </render>
   </definetag>
   SIMPLECONTENT
     return $filecontents;
   }
   
   
 sub inserteditinfo {  sub inserteditinfo {
       my ($result,$filecontents)=@_;        my ($result,$filecontents,$filetype)=@_;
       $filecontents = &HTML::Entities::encode($filecontents);        $filecontents = &HTML::Entities::encode($filecontents);
 #      my $editheader='<a href="#editsection">Edit below</a><hr />';  #      my $editheader='<a href="#editsection">Edit below</a><hr />';
       my $xml_help = Apache::loncommon::helpLatexCheatsheet();        my $xml_help = '';
         if ($filetype eq 'html') {
     $xml_help=Apache::loncommon::helpLatexCheatsheet();
         }
         my $cleanbut = '';
         if ($filetype eq 'html') {
     $cleanbut='<input type="submit" name="attemptclean" value="'.
         &mt('Save and then attempt to clean HTML').'" />';
         }
       my $titledisplay=&display_title();        my $titledisplay=&display_title();
         my %lt=&Apache::lonlocal::texthash('st' => 'Save this',
    'vi' => 'View',
    'ed' => 'Edit');
       my $buttons=(<<BUTTONS);        my $buttons=(<<BUTTONS);
 <input type="submit" name="attemptclean"   $cleanbut
        value="Save and then attempt to clean HTML" />  <input type="submit" name="savethisfile" value="$lt{'st'}" />
 <input type="submit" name="savethisfile" value="Save this" />  <input type="submit" name="viewmode" value="$lt{'vi'}" />
 <input type="submit" name="viewmode" value="View" />  
 BUTTONS  BUTTONS
       my $editfooter=(<<ENDFOOTER);        my $editfooter=(<<ENDFOOTER);
 <hr />  <hr />
 <a name="editsection" />  <a name="editsection" />
 <form method="post">  <form method="post">
 $xml_help  $xml_help
 <input type="hidden" name="editmode" value="Edit" />  <input type="hidden" name="editmode" value="$lt{'ed'}" />
 $buttons<br />  $buttons<br />
 <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>  <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
 <br />$buttons  <br />$buttons
Line 1203  sub handler { Line 1175  sub handler {
     $Apache::lonxml::debug=$ENV{'user.debug'};      $Apache::lonxml::debug=$ENV{'user.debug'};
           
     if ($ENV{'browser.mathml'}) {      if ($ENV{'browser.mathml'}) {
  $request->content_type('text/xml');   &Apache::loncommon::content_type($request,'text/xml');
     } else {      } else {
  $request->content_type('text/html');   &Apache::loncommon::content_type($request,'text/html');
     }      }
     &Apache::loncommon::no_cache($request);      &Apache::loncommon::no_cache($request);
     $request->send_http_header;      $request->send_http_header;
Line 1214  sub handler { Line 1186  sub handler {
   
   
     my $file=&Apache::lonnet::filelocation("",$request->uri);      my $file=&Apache::lonnet::filelocation("",$request->uri);
       my $filetype;
       if ($file =~ /\.sty$/) {
    $filetype='sty';
       } else {
    $filetype='html';
       }
 #  #
 # Edit action? Save file.  # Edit action? Save file.
 #  #
     unless ($ENV{'request.state'} eq 'published') {      unless ($ENV{'request.state'} eq 'published') {
  if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {   if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
     &storefile($file,$ENV{'form.filecont'});      if (&storefile($file,$ENV{'form.filecont'})) {
    $request->print("<font COLOR=\"#0000FF\">".&mt('Updated').": ".
   &Apache::lonlocal::locallocaltime(time)." </font>");
       } 
  }   }
     }      }
     my %mystyle;      my %mystyle;
     my $result = '';      my $result = '';
     my $filecontents=&Apache::lonnet::getfile($file);      my $filecontents=&Apache::lonnet::getfile($file);
     if ($filecontents eq -1) {      if ($filecontents eq -1) {
    my $bodytag=&Apache::loncommon::bodytag('File Error');
    my $fnf=&mt('File not found');
  $result=(<<ENDNOTFOUND);   $result=(<<ENDNOTFOUND);
 <html>  <html>
 <head>  <head>
 <title>File not found</title>  <title>$fnf</title>
 </head>  </head>
 <body bgcolor="#FFFFFF">  $bodytag
 <b>File not found: $file</b>  <b>$fnf: $file</b>
 </body>  </body>
 </html>  </html>
 ENDNOTFOUND  ENDNOTFOUND
     $filecontents='';      $filecontents='';
  if ($ENV{'request.state'} ne 'published') {   if ($ENV{'request.state'} ne 'published') {
     $filecontents=&createnewhtml();      if ($filetype eq 'sty') {
    $filecontents=&createnewsty();
       } else {
    $filecontents=&createnewhtml();
       }
     $ENV{'form.editmode'}='Edit'; #force edit mode      $ENV{'form.editmode'}='Edit'; #force edit mode
  }   }
     } else {      } else {
Line 1266  ENDNOTFOUND Line 1253  ENDNOTFOUND
     $displayfile=~s/^\/[^\/]*//;      $displayfile=~s/^\/[^\/]*//;
     $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.      $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
  '</h3></body></html>';   '</h3></body></html>';
     $result=&inserteditinfo($result,$filecontents);      $result=&inserteditinfo($result,$filecontents,$filetype);
  }   }
     }      }
           if ($filetype eq 'html') { writeallows($request->uri); }
     writeallows($request->uri);  
           
   
     $request->print($result);      $request->print($result);
Line 1392  sub register_insert { Line 1379  sub register_insert {
     my $line = $data[$i];      my $line = $data[$i];
     if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }      if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
     if ( $line =~ /TABLE/ ) { last; }      if ( $line =~ /TABLE/ ) { last; }
     my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);      my ($tag,$descrip,$color,$function,$show,$helpfile,$helpdesc) = split(/,/, $line);
     if ($tag) {      if ($tag) {
       $insertlist{"$tagnum.tag"} = $tag;        $insertlist{"$tagnum.tag"} = $tag;
       $insertlist{"$tagnum.description"} = $descrip;        $insertlist{"$tagnum.description"} = $descrip;
Line 1400  sub register_insert { Line 1387  sub register_insert {
       $insertlist{"$tagnum.function"} = $function;        $insertlist{"$tagnum.function"} = $function;
       if (!defined($show)) { $show='yes'; }        if (!defined($show)) { $show='yes'; }
       $insertlist{"$tagnum.show"}= $show;        $insertlist{"$tagnum.show"}= $show;
         $insertlist{"$tagnum.helpfile"} = $helpfile;
         $insertlist{"$tagnum.helpdesc"} = $helpdesc;
       $insertlist{"$tag.num"}=$tagnum;        $insertlist{"$tag.num"}=$tagnum;
       $tagnum++;        $tagnum++;
     }      }
Line 1434  sub description { Line 1423  sub description {
   return $insertlist{$tagnum.'.description'};    return $insertlist{$tagnum.'.description'};
 }  }
   
   # Returns a list containing the help file, and the description
   sub helpinfo {
     my ($token)=@_;
     my $tagnum;
     my $tag=$token->[1];
     foreach my $namespace (reverse @Apache::lonxml::namespace) {
       my $testtag=$namespace.'::'.$tag;
       $tagnum=$insertlist{"$testtag.num"};
       if (defined($tagnum)) { last; }
     }
     if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
     return ($insertlist{$tagnum.'.helpfile'}, $insertlist{$tagnum.'.helpdesc'});
   }
   
 # ----------------------------------------------------------------- whichuser  # ----------------------------------------------------------------- whichuser
 # returns a list of $symb, $courseid, $domain, $name that is correct for  # returns a list of $symb, $courseid, $domain, $name that is correct for
 # calls to lonnet functions for this setup.  # calls to lonnet functions for this setup.

Removed from v.1.266.2.1  
changed lines
  Added in v.1.286


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