File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.46: download - view: text, annotated - select for diffs
Thu Jul 12 14:29:17 2001 UTC (22 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- fixed <import> for editing and publishing
- removed dead meta code this all exists in londefdef.pm

    1: # The LearningOnline Network with CAPA
    2: # <script> definiton
    3: # 2/21 Guy
    4: 
    5: package Apache::scripttag; 
    6: 
    7: use strict;
    8: use Apache::lonnet;
    9: use Apache::style;
   10: 
   11: sub BEGIN {
   12:   &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
   13: 						 'parserlib','import',
   14:                                                  'window','display',
   15:                                                  'storetc','physnet'));
   16: }
   17: 
   18: sub start_script {
   19:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   20:   my $result='';
   21:   my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
   22:   &Apache::lonxml::debug("found type of $type");
   23:   if ($type eq "loncapa/perl") {
   24:     my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
   25:     if ( $target eq "modified" ) {
   26:       $result=$token->[4].&Apache::edit::modifiedfield();
   27:     } elsif ( $target eq "web" || $target eq "grade" ) {
   28:       &Apache::run::run($bodytext,$safeeval);
   29:     } elsif ($target eq "edit" ) {
   30:       #&Apache::run::run($bodytext,$safeeval);
   31:       #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
   32:       $result=&Apache::edit::tag_start($target,$token,'Script');
   33:       $result.=&Apache::edit::editfield($token->[1],$bodytext,'',50,4);
   34:     }
   35:   } else {
   36:     if ($target ne "meta") { $result = $token->[4]; }
   37:   }
   38:   return $result;
   39: }
   40: 
   41: sub end_script {
   42:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   43:   if ( $target eq "meta" ) { return ''; } 
   44:   my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
   45:   my $result='';
   46:   #other script blocks need to survive
   47:   if ($type ne "loncapa/perl") { return $token->[2]; }
   48:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
   49:   return '';
   50: }
   51: 
   52: sub start_display {
   53:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   54: 
   55:   my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
   56: 
   57:   if ( $target eq "modified" ) {
   58:   }
   59:   my $result=&Apache::run::run($bodytext,$safeeval);
   60:   if ($target eq 'grade' ) {
   61:     # grade should produce no output
   62:     $result='';
   63:   }
   64:   if ($target eq "edit" ) {
   65:     $result = 
   66:       "<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
   67:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
   68:   }
   69:   return $result;
   70: }
   71: 
   72: sub end_display {
   73:   return ''
   74: }
   75: 
   76: sub start_scriptlib {
   77:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   78:   my $bodytext;
   79:   my $result ='';
   80:   my $error='';
   81: 
   82:   if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
   83:     $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
   84:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
   85: 				     $$parstack[$#$parstack]);
   86:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
   87: 					       $bodytext);
   88:     my $script=&Apache::lonnet::getfile($location);
   89:     if ($script == -1) {
   90:       if ($target eq 'edit') {
   91:         $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
   92:       } else {
   93: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
   94: 	return "";
   95:       }
   96:     }
   97:     &Apache::run::run($script,$safeeval);
   98:     #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
   99:   }
  100:   if ($target eq "edit" ) {
  101:     $result=
  102:       &Apache::edit::tag_start($target,$token).
  103: 	&Apache::edit::editfield($token->[1],$bodytext,'New Script Functions',40,1).
  104: 	  $error;
  105:   }
  106:   if ($target eq "modified" ) {
  107:     $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
  108:     $result=&Apache::edit::modifiedfield($token);
  109:     &Apache::lonxml::debug($result);
  110:   }
  111:   return $result;
  112: }
  113: 
  114: sub end_scriptlib {
  115:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  116:   my $result='';
  117: #  if ($target eq "edit" ) { $result=" "; }
  118:   return $result;
  119: }
  120: 
  121: sub start_parserlib {
  122:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  123:   my $bodytext;
  124:   my $result ="";
  125:   my $error='';
  126:   if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
  127:     $bodytext=$$parser[$#$parser]->get_text("/parserlib");
  128:     $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
  129: 				     $$parstack[$#$parstack]);
  130:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
  131: 					       $bodytext);
  132:     my $styletext=&Apache::lonnet::getfile($location);
  133:     #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
  134:     if ($styletext == -1) {
  135:       if ($target eq 'edit') {
  136: 	$error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
  137:       } else {
  138: 	&Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
  139: 	return "";
  140:       }
  141:     }
  142:     %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
  143:   }
  144:   if ($target eq "edit" ) {
  145:     $result=
  146:       &Apache::edit::tag_start($target,$token).
  147: 	&Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions",40,1).
  148: 	  $error;
  149:   }
  150:   if ($target eq "modified" ) {
  151:     $bodytext=$$parser[$#$parser]->get_text("/parserlib");
  152:     $result=&Apache::edit::modifiedfield($token);
  153:     &Apache::lonxml::debug($result);
  154:   }
  155:   return $result;
  156: }
  157: 
  158: sub end_parserlib {
  159:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  160:   my $result='';
  161: #  if ($target eq "edit" ) { 
  162: #    $result=&Apache::edit::tag_end($target,$token);
  163: #  }
  164:   return $result;
  165: }
  166: 
  167: sub start_window {
  168:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  169:   my $result = '';
  170:   if ($target eq 'web') {
  171:     &Apache::lonxml::startredirection;
  172:   }  elsif ($target eq 'tex') {
  173:        $result = '\unskip\footnote{';
  174:    }
  175:   return $result;  
  176: }
  177: 
  178: sub end_window {
  179:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  180:   my $result;
  181:   if ($target eq 'web') {
  182:     my $output=&Apache::lonxml::endredirection;
  183:     $output =~ s/\"/\&quot\;/g;
  184:     $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>";
  185:   } elsif ($target eq 'tex') {
  186:       $result = '}';
  187:   } else {
  188:       $result = '';
  189:   }
  190:   return $result; 
  191: }
  192: 
  193: sub start_import {
  194:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  195:   my $bodytext=$$parser[$#$parser]->get_text("/import");
  196:   my $result ="";
  197: 
  198:   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
  199: 
  200:   if ($target eq 'web' || $target eq 'grade') {
  201:     # FIXME this probably needs to be smart about construction vs.
  202:     # non construction space.
  203:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
  204:     my $file=&Apache::lonnet::getfile($location);
  205:     if ($file == -1) {
  206:       &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
  207:       return "";
  208:     }
  209: 
  210:     my $dir=$location;
  211:     $dir=~s:/[^/]*$::;
  212:     #  &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
  213:     &Apache::lonxml::newparser($parser,\$file,$dir);
  214:   }
  215:   if ($target eq "edit" ) {
  216:     $result.=&Apache::edit::tag_start($target,$token);
  217:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
  218:     #FIXME this need to convert $bodytext to be a contruction space reference
  219:     #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
  220:     #$result.="Click<a href=\"$location\">here</a> to edit<br />"
  221:   }
  222:   if ($target eq 'modified') {
  223:     $bodytext=$$parser[$#$parser]->get_text("/import");
  224:     $result=&Apache::edit::modifiedfield($token);
  225:     &Apache::lonxml::debug($result);
  226:   }
  227:   return $result;
  228: }
  229: 
  230: sub end_import {
  231:   return '';
  232: }
  233: 
  234: sub start_storetc {
  235:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  236:   my $result = '';
  237:   &Apache::lonxml::startredirection;
  238:   return $result; 
  239: }
  240: 
  241: sub end_storetc {
  242:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  243:     my $result;
  244:     my $output=&Apache::lonxml::endredirection;
  245:     $output =~ s/\"/\&quot\;/g;
  246:     $result = "{\bf $output.}}\write\tcfile{\protect\tcpc{ $output.}{\the\value{relpage}}}";
  247:     return $result; 
  248: }
  249: 
  250: 
  251: sub start_physnet {
  252:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  253:     my $bodytext = '/msu/physnet/cbi.sty';
  254:     my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
  255:     my $cbistyletext=&Apache::lonnet::getfile($location);
  256: 
  257:     %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
  258:     if ( defined($$style{'physnet'}) ) {
  259:         &Apache::lonxml::newparser($parser,\$$style{'physnet'});
  260:     }
  261:     return "";
  262: }
  263: 
  264: sub end_physnet {
  265: }
  266: 
  267: 
  268: 1;
  269: __END__

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