Diff for /loncom/xml/scripttag.pm between versions 1.76 and 1.92

version 1.76, 2002/07/24 20:10:43 version 1.92, 2003/06/04 22:30:00
Line 43  BEGIN { Line 43  BEGIN {
   &Apache::lonxml::register('Apache::scripttag',    &Apache::lonxml::register('Apache::scripttag',
     ('script','scriptlib','parserlib','import',      ('script','scriptlib','parserlib','import',
      'window','display','storetc','physnet',       'window','display','storetc','physnet',
      'standalone','comment'));       'standalone','comment',
        'LONCAPA_INTERNAL_TURN_STYLE_ON',
        'LONCAPA_INTERNAL_LONHTTPD_PORT'));
   }
   
   sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
       $Apache::lonxml::usestyle=1;
       $Apache::lonxml::style_values='';
       return ('','no');
   }
   
   sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
       my $end=&Apache::lonxml::get_param('end',$parstack,$safeeval);
       if (defined($end)) {
    &Apache::lonxml::end_tag($tagstack,$parstack,$token);
       }
       return ('','no');
   }
   
   sub start_LONCAPA_INTERNAL_LONHTTPD_PORT {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
       if ($target eq 'web') {
    my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
    if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
    return '<script type="text/javascript">var lonhttpdport=\''.
       $lonhttpdPort.'\';</script>';
       }
       return ('','no');
   }
   
   sub end_LONCAPA_INTERNAL_LONHTTPD_PORT {
       return ('','no');
 }  }
   
 sub start_script {  sub start_script {
Line 53  sub start_script { Line 85  sub start_script {
   my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);    my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
   &Apache::lonxml::debug("found type of $type");    &Apache::lonxml::debug("found type of $type");
   if ($type eq "loncapa/perl") {    if ($type eq "loncapa/perl") {
     my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);      my $bodytext=&Apache::lonxml::get_all_text("/script",$parser);
     if ( $target eq "modified" ) {      if ( $target eq "modified" ) {
       $result=$token->[4].&Apache::edit::modifiedfield();        $result=$token->[4].&Apache::edit::modifiedfield();
     } elsif ( $target eq 'web' || $target eq 'tex' ||      } elsif ( $target eq 'web' || $target eq 'tex' ||
       $target eq 'grade' || $target eq 'answer') {        $target eq 'grade' || $target eq 'answer' ||
       &Apache::run::run($bodytext,$safeeval);        $target eq 'analyze' ) {
       if (($target eq 'answer') && ($Apache::lonhomework::viewgrades == 'F')) {   if (!$Apache::lonxml::default_homework_loaded) {
  $Apache::lonxml::evaluate--;      &Apache::lonxml::default_homework_load($safeeval);
  $result.="<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor=&quot;#FFFFFF&quot;><pre>";   }
  my $listing= &HTML::Entities::encode(&Apache::run::dump($target,$safeeval));   &Apache::run::run($bodytext,$safeeval);
    if (($target eq 'answer') &&
  $result.=$listing;      ($ENV{'form.answer_output_mode'} ne 'tex') &&
  $result.= "</pre></body></html>\');newWindow.document.close();void(0);\">Script Vars</a><br />";      ($Apache::lonhomework::viewgrades == 'F')) {
       }      $Apache::lonxml::evaluate--;
       $result.="<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'&lt;html&gt;&lt;head&gt;&lt;title&gt;newwindow&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor=&quot;#FFFFFF&quot;&gt;&lt;pre&gt;";
       my $listing= &HTML::Entities::encode(&Apache::run::dump($target,$safeeval));
   
       $result.=$listing;
       $result.= "&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;\');newWindow.document.close();void(0);\">Script Vars</a><br />";
    }
     } elsif ($target eq "edit" ) {      } elsif ($target eq "edit" ) {
       #&Apache::run::run($bodytext,$safeeval);        #&Apache::run::run($bodytext,$safeeval);
       #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";        #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
       $result=&Apache::edit::tag_start($target,$token,'Script');        $result=&Apache::edit::tag_start($target,$token,'Script');
       $result.=&Apache::edit::editfield($token->[1],$bodytext,'',50,4);        $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
     }      }
   } else {    } else {
     if ($target ne "meta") {      if ($target ne "meta") {
       $result = $token->[4];        $result = $token->[4];
       my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);        my $bodytext=&Apache::lonxml::get_all_text("/script",$parser);
       $result.=$bodytext;        $result.=$bodytext;
     }      }
   }    }
Line 93  sub end_script { Line 131  sub end_script {
     return $token->[2];      return $token->[2];
   } elsif ($target eq 'edit' ) {    } elsif ($target eq 'edit' ) {
     return &Apache::edit::end_table();      return &Apache::edit::end_table();
   } elsif (($target eq 'answer')) {    } elsif ($target eq 'answer') {
     $Apache::lonxml::evaluate++;      $Apache::lonxml::evaluate++;
   }    }
   return '';    return '';
Line 103  sub start_display { Line 141  sub start_display {
   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;    my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   
   my $result;    my $result;
   my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);    my $bodytext=&Apache::lonxml::get_all_text("/display",$parser);
   
   if ( $target eq "modified" ) {    if ( $target eq "modified" ) {
     $result=$token->[4].&Apache::edit::modifiedfield();      $result=$token->[4].&Apache::edit::modifiedfield();
   } elsif ( $target eq 'web' || $target eq 'tex' ||    } elsif ( $target eq 'web' || $target eq 'tex' ||
     $target eq 'grade' || $target eq 'answer') {      $target eq 'grade' || $target eq 'answer' ||
     $result=&Apache::run::run($bodytext,$safeeval);        $target eq 'analyze') {
     if ($target eq 'grade' || $target eq 'answer' ) {        if (!$Apache::lonxml::default_homework_loaded) {
       $result=''; # grade should produce no output    &Apache::lonxml::default_homework_load($safeeval);
     }        }
         $result=&Apache::run::run($bodytext,$safeeval);
         if ($target eq 'grade' || $target eq 'answer' ||
     $target eq 'analyze') {
     $result=''; # grade should produce no output
         }
   } elsif ($target eq "edit" ) {    } elsif ($target eq "edit" ) {
     #$result =       #$result = 
     #  "<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";      #  "<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
     #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);      #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
     $result=&Apache::edit::tag_start($target,$token,'Script With Display');      $result=&Apache::edit::tag_start($target,$token,'Script With Display');
     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1)      $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
   }    }
   return $result;    return $result;
 }  }
Line 135  sub start_scriptlib { Line 178  sub start_scriptlib {
   my $result ='';    my $result ='';
   my $error='';    my $error='';
   
   if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit' || $target eq 'answer') {    if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || 
         $target eq 'edit' || $target eq 'answer' || $target eq 'analyze') {
     $bodytext=$$parser[$#$parser]->get_text("/scriptlib");      $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,      $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
      $$parstack[$#$parstack]);       $$parstack[$#$parstack]);
Line 156  sub start_scriptlib { Line 200  sub start_scriptlib {
   if ($target eq "edit" ) {    if ($target eq "edit" ) {
     $result=      $result=
       &Apache::edit::tag_start($target,$token,'New Script Functions').        &Apache::edit::tag_start($target,$token,'New Script Functions').
  &Apache::edit::editline($token->[1],$bodytext,'',40).   &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
               &Apache::edit::browse(undef,'textnode').
   $error.'</td></tr>'.    $error.'</td></tr>'.
     &Apache::edit::end_table();      &Apache::edit::end_table();
   }    }
Line 180  sub start_parserlib { Line 225  sub start_parserlib {
   my $bodytext;    my $bodytext;
   my $result ="";    my $result ="";
   my $error='';    my $error='';
   if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit' || $target eq 'answer') {    if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' ||
         $target eq 'edit' || $target eq 'answer' || $target eq 'analyze') {
     $bodytext=$$parser[$#$parser]->get_text("/parserlib");      $bodytext=$$parser[$#$parser]->get_text("/parserlib");
     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,      $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
      $$parstack[$#$parstack]);       $$parstack[$#$parstack]);
Line 236  sub end_window { Line 282  sub end_window {
   my $result;    my $result;
   if ($target eq 'web') {    if ($target eq 'web') {
     my $output=&Apache::lonxml::endredirection;      my $output=&Apache::lonxml::endredirection;
       my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
       if (!$linktext) { $linktext='<sup>*</sup>'; }
       my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
       if (!$width) { $width='500'; }
       my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
       if (!$height) { $height='200'; }
     $output =~ s/\"/\&quot\;/g;      $output =~ s/\"/\&quot\;/g;
     $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor=&quot;#FFFFFF&quot;> $output </body></html>\');newWindow.document.close();void(0);\"><sup>*</sup></a>";      $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=$width,height=$height,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor=&quot;#FFFFFF&quot;> $output </body></html>\');newWindow.document.close();void(0);\">$linktext</a>";
   } elsif ($target eq 'tex') {    } elsif ($target eq 'tex') {
       $result = '}';        $result = '}';
   } else {    } else {
Line 253  sub start_import { Line 305  sub start_import {
   
   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);    $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
   
   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||$target eq 'tex') {    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
         $target eq 'tex' || $target eq 'analyze' ) {
     # FIXME this probably needs to be smart about construction vs.      # FIXME this probably needs to be smart about construction vs.
     # non construction space.      # non construction space.
     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);      my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
Line 269  sub start_import { Line 322  sub start_import {
     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);      my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
     if (!$id) { $id=$Apache::lonxml::curdepth; }      if (!$id) { $id=$Apache::lonxml::curdepth; }
     push(@Apache::inputtags::import,$id);      push(@Apache::inputtags::import,$id);
     &Apache::lonxml::newparser($parser,\$file,$dir);      push(@Apache::inputtags::importlist,$id);
   
    &Apache::lonxml::newparser($parser,\$file,$dir);
   
   } elsif ($target eq "edit" ) {    } elsif ($target eq "edit" ) {
     $result.=&Apache::edit::tag_start($target,$token);      $result.=&Apache::edit::tag_start($target,$token);
     $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);      $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
       $result.=&Apache::edit::browse(undef,'textnode');
     #FIXME this need to convert $bodytext to be a contruction space reference      #FIXME this need to convert $bodytext to be a contruction space reference
     #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);      #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
     #$result.="Click<a href=\"$location\">here</a> to edit<br />"      #$result.="Click<a href=\"$location\">here</a> to edit<br />"
Line 341  sub start_standalone { Line 398  sub start_standalone {
   my $result='';    my $result='';
   if ($target eq 'web' ) {    if ($target eq 'web' ) {
     if ( $ENV{'request.course.id'} ) {      if ( $ENV{'request.course.id'} ) {
       my $inside = &Apache::lonxml::get_all_text("/standalone",$$parser[-1]);        my $inside = &Apache::lonxml::get_all_text("/standalone",$parser);
     } else {      } else {
       $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';        $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
     }      }
Line 366  sub start_comment { Line 423  sub start_comment {
   my $result='';    my $result='';
   if ($target eq 'edit') {    if ($target eq 'edit') {
     $result=&Apache::edit::tag_start($target,$token);      $result=&Apache::edit::tag_start($target,$token);
     my $bodytext=&Apache::lonxml::get_all_text("/comment",$$parser[$#$parser]);      my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,4)      $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
   } elsif ( $target eq 'modified') {    } elsif ( $target eq 'modified') {
     $result=$token->[4].&Apache::edit::modifiedfield($token);      $result=$token->[4].&Apache::edit::modifiedfield($token);
   } elsif ( $target eq 'web' || $target eq 'tex' ||    } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
     $target eq 'grade' || $target eq 'answer' || $target eq 'meta') {      $target eq 'answer' || $target eq 'meta' || $target eq 'analyze') {
     #normally throw away comments      #normally throw away comments
     my $bodytext=&Apache::lonxml::get_all_text("/comment",$$parser[$#$parser]);      my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
   }    }
   return $result;    return $result;
 }  }
Line 387  sub end_comment { Line 444  sub end_comment {
   
 sub xmlparse {  sub xmlparse {
   my ($string) = @_;    my ($string) = @_;
   &Apache::lonxml::debug("Got $string");  #  &Apache::lonxml::debug("Got $string");
   my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=    my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
     @Apache::scripttag::parser_env;      @Apache::scripttag::parser_env;
   my @parser;    my @parser;

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


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