Annotation of loncom/xml/scripttag.pm, revision 1.46

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # <script> definiton
1.34      albertel    3: # 2/21 Guy
1.1       albertel    4: 
                      5: package Apache::scripttag; 
                      6: 
                      7: use strict;
1.3       albertel    8: use Apache::lonnet;
1.42      sakharuk    9: use Apache::style;
1.1       albertel   10: 
                     11: sub BEGIN {
1.6       albertel   12:   &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
1.20      sakharuk   13: 						 'parserlib','import',
1.42      sakharuk   14:                                                  'window','display',
                     15:                                                  'storetc','physnet'));
1.1       albertel   16: }
                     17: 
                     18: sub start_script {
1.40      albertel   19:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.24      albertel   20:   my $result='';
1.39      albertel   21:   my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
                     22:   &Apache::lonxml::debug("found type of $type");
1.17      albertel   23:   if ($type eq "loncapa/perl") {
1.21      albertel   24:     my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
1.17      albertel   25:     if ( $target eq "modified" ) {
1.41      albertel   26:       $result=$token->[4].&Apache::edit::modifiedfield();
1.28      albertel   27:     } elsif ( $target eq "web" || $target eq "grade" ) {
                     28:       &Apache::run::run($bodytext,$safeeval);
                     29:     } elsif ($target eq "edit" ) {
1.41      albertel   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);
1.17      albertel   34:     }
                     35:   } else {
1.28      albertel   36:     if ($target ne "meta") { $result = $token->[4]; }
1.13      albertel   37:   }
1.24      albertel   38:   return $result;
1.17      albertel   39: }
1.13      albertel   40: 
1.17      albertel   41: sub end_script {
1.40      albertel   42:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28      albertel   43:   if ( $target eq "meta" ) { return ''; } 
1.39      albertel   44:   my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29      albertel   45:   my $result='';
                     46:   #other script blocks need to survive
                     47:   if ($type ne "loncapa/perl") { return $token->[2]; }
1.41      albertel   48:   if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
1.28      albertel   49:   return '';
1.24      albertel   50: }
                     51: 
                     52: sub start_display {
1.40      albertel   53:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.39      albertel   54: 
1.24      albertel   55:   my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
1.39      albertel   56: 
1.24      albertel   57:   if ( $target eq "modified" ) {
                     58:   }
                     59:   my $result=&Apache::run::run($bodytext,$safeeval);
1.26      albertel   60:   if ($target eq 'grade' ) {
                     61:     # grade should produce no output
                     62:     $result='';
                     63:   }
1.24      albertel   64:   if ($target eq "edit" ) {
                     65:     $result = 
1.33      albertel   66:       "<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
1.38      albertel   67:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.24      albertel   68:   }
                     69:   return $result;
                     70: }
                     71: 
                     72: sub end_display {
1.38      albertel   73:   return ''
1.1       albertel   74: }
1.3       albertel   75: 
                     76: sub start_scriptlib {
1.40      albertel   77:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel   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 />");
1.18      albertel   99:   }
1.13      albertel  100:   if ($target eq "edit" ) {
1.37      albertel  101:     $result=
1.38      albertel  102:       &Apache::edit::tag_start($target,$token).
                    103: 	&Apache::edit::editfield($token->[1],$bodytext,'New Script Functions',40,1).
1.37      albertel  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);
1.3       albertel  110:   }
                    111:   return $result;
                    112: }
                    113: 
1.37      albertel  114: sub end_scriptlib {
1.40      albertel  115:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel  116:   my $result='';
                    117: #  if ($target eq "edit" ) { $result=" "; }
                    118:   return $result;
                    119: }
1.4       albertel  120: 
                    121: sub start_parserlib {
1.40      albertel  122:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel  123:   my $bodytext;
1.7       albertel  124:   my $result ="";
1.37      albertel  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));
1.18      albertel  143:   }
1.13      albertel  144:   if ($target eq "edit" ) {
1.37      albertel  145:     $result=
1.38      albertel  146:       &Apache::edit::tag_start($target,$token).
                    147: 	&Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions",40,1).
1.37      albertel  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);
1.7       albertel  154:   }
                    155:   return $result;
1.4       albertel  156: }
                    157: 
                    158: sub end_parserlib {
1.40      albertel  159:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37      albertel  160:   my $result='';
                    161: #  if ($target eq "edit" ) { 
1.38      albertel  162: #    $result=&Apache::edit::tag_end($target,$token);
1.37      albertel  163: #  }
                    164:   return $result;
1.6       albertel  165: }
                    166: 
1.30      sakharuk  167: sub start_window {
1.40      albertel  168:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.20      sakharuk  169:   my $result = '';
1.31      albertel  170:   if ($target eq 'web') {
1.34      albertel  171:     &Apache::lonxml::startredirection;
1.35      sakharuk  172:   }  elsif ($target eq 'tex') {
1.42      sakharuk  173:        $result = '\unskip\footnote{';
1.35      sakharuk  174:    }
1.19      sakharuk  175:   return $result;  
                    176: }
                    177: 
1.30      sakharuk  178: sub end_window {
1.40      albertel  179:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30      sakharuk  180:   my $result;
1.31      albertel  181:   if ($target eq 'web') {
1.34      albertel  182:     my $output=&Apache::lonxml::endredirection;
                    183:     $output =~ s/\"/\&quot\;/g;
1.35      sakharuk  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 = '}';
1.30      sakharuk  187:   } else {
1.35      sakharuk  188:       $result = '';
1.30      sakharuk  189:   }
1.20      sakharuk  190:   return $result; 
1.19      sakharuk  191: }
                    192: 
1.6       albertel  193: sub start_import {
1.40      albertel  194:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31      albertel  195:   my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7       albertel  196:   my $result ="";
1.13      albertel  197: 
                    198:   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.14      albertel  199: 
1.46    ! albertel  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:     }
1.13      albertel  209: 
1.46    ! albertel  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:   }
1.13      albertel  215:   if ($target eq "edit" ) {
1.46    ! albertel  216:     $result.=&Apache::edit::tag_start($target,$token);
1.38      albertel  217:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.46    ! albertel  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 />"
1.7       albertel  221:   }
1.46    ! albertel  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;
1.6       albertel  228: }
                    229: 
                    230: sub end_import {
1.45      sakharuk  231:   return '';
1.1       albertel  232: }
1.42      sakharuk  233: 
                    234: sub start_storetc {
1.43      albertel  235:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42      sakharuk  236:   my $result = '';
                    237:   &Apache::lonxml::startredirection;
                    238:   return $result; 
                    239: }
                    240: 
                    241: sub end_storetc {
1.43      albertel  242:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42      sakharuk  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 {
1.45      sakharuk  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);
1.42      sakharuk  256: 
1.45      sakharuk  257:     %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
1.44      albertel  258:     if ( defined($$style{'physnet'}) ) {
1.45      sakharuk  259:         &Apache::lonxml::newparser($parser,\$$style{'physnet'});
1.44      albertel  260:     }
1.45      sakharuk  261:     return "";
                    262: }
1.42      sakharuk  263: 
1.45      sakharuk  264: sub end_physnet {
1.42      sakharuk  265: }
                    266: 
1.3       albertel  267: 
1.1       albertel  268: 1;
                    269: __END__

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