Annotation of loncom/xml/lonxml.pm, revision 1.510

1.2       sakharuk    1: # The LearningOnline Network with CAPA
1.3       sakharuk    2: # XML Parser Module 
1.2       sakharuk    3: #
1.510   ! raeburn     4: # $Id: lonxml.pm,v 1.509 2010/06/05 19:37:01 www Exp $
1.139     www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
                     29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
                     30: # binary executable programs or libraries distributed by the 
                     31: # Michigan State University (the "Licensee"), but any binaries so 
                     32: # distributed are hereby licensed only for use in the context
                     33: # of a program or computational system for which the Licensee is the 
                     34: # primary author or distributor, and which performs substantial 
                     35: # additional tasks beyond the translation of (La)TeX into HTML.
                     36: # The C source of the Code may not be distributed by the Licensee
                     37: # to any other parties under any circumstances.
                     38: #
1.316     albertel   39: 
1.489     jms        40: =pod
                     41: 
                     42: =head1 NAME
                     43: 
                     44: Apache::lonxml
                     45: 
                     46: =head1 SYNOPSIS
                     47: 
                     48: XML Parsing Module
                     49: 
                     50: This is part of the LearningOnline Network with CAPA project
                     51: described at http://www.lon-capa.org.
                     52: 
                     53: 
                     54: =head1 SUBROUTINES
                     55: 
                     56: =cut
                     57: 
                     58: 
1.2       sakharuk   59: 
1.4       albertel   60: package Apache::lonxml; 
1.33      www        61: use vars 
1.410     albertel   62: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $errorcount $warningcount);
1.1       sakharuk   63: use strict;
1.444     albertel   64: use LONCAPA;
1.167     albertel   65: use HTML::LCParser();
1.161     albertel   66: use HTML::TreeBuilder();
                     67: use HTML::Entities();
                     68: use Safe();
                     69: use Safe::Hole();
                     70: use Math::Cephes();
                     71: use Math::Random();
                     72: use Opcode();
1.271     www        73: use POSIX qw(strftime);
1.339     albertel   74: use Time::HiRes qw( gettimeofday tv_interval );
1.393     albertel   75: use Symbol();
1.266     bowersj2   76: 
1.72      albertel   77: sub register {
1.141     albertel   78:   my ($space,@taglist) = @_;
                     79:   foreach my $temptag (@taglist) {
                     80:     push(@{ $Apache::lonxml::alltags{$temptag} },$space);
1.72      albertel   81:   }
                     82: }
                     83: 
1.141     albertel   84: sub deregister {
                     85:   my ($space,@taglist) = @_;
                     86:   foreach my $temptag (@taglist) {
                     87:     my $tempspace = $Apache::lonxml::alltags{$temptag}[-1];
                     88:     if ($tempspace eq $space) {
                     89:       pop(@{ $Apache::lonxml::alltags{$temptag} });
                     90:     }
                     91:   }
1.142     albertel   92:   #&printalltags();
1.141     albertel   93: }
                     94: 
1.46      www        95: use Apache::Constants qw(:common);
1.161     albertel   96: use Apache::lontexconvert();
                     97: use Apache::style();
                     98: use Apache::run();
                     99: use Apache::londefdef();
                    100: use Apache::scripttag();
1.285     www       101: use Apache::languagetags();
1.161     albertel  102: use Apache::edit();
1.266     bowersj2  103: use Apache::inputtags();
                    104: use Apache::outputtags();
1.372     albertel  105: use Apache::lonnet;
1.161     albertel  106: use Apache::File();
                    107: use Apache::loncommon();
1.198     www       108: use Apache::lonfeedback();
1.200     www       109: use Apache::lonmsg();
1.217     matthew   110: use Apache::loncacc();
1.431     www       111: use Apache::lonmaxima();
1.494     www       112: use Apache::lonr();
1.280     www       113: use Apache::lonlocal;
1.501     raeburn   114: use Apache::lonhtmlcommon();
1.79      www       115: 
1.462     foxr      116: #====================================   Main subroutine: xmlparse  
                    117: 
1.72      albertel  118: #debugging control, to turn on debugging modify the correct handler
1.462     foxr      119: 
1.72      albertel  120: $Apache::lonxml::debug=0;
1.206     albertel  121: 
                    122: # keeps count of the number of warnings and errors generated in a parse
                    123: $warningcount=0;
                    124: $errorcount=0;
1.72      albertel  125: 
                    126: #path to the directory containing the file currently being processed
                    127: @pwd=();
                    128: 
                    129: #these two are used for capturing a subset of the output for later processing,
                    130: #don't touch them directly use &startredirection and &endredirection
                    131: @outputstack = ();
                    132: $redirection = 0;
                    133: 
                    134: #controls wheter the <import> tag actually does
                    135: $import = 1;
                    136: @extlinks=();
                    137: 
                    138: # meta mode is a bit weird only some output is to be turned off
                    139: #<output> tag turns metamode off (defined in londefdef.pm)
                    140: $metamode = 0;
                    141: 
                    142: # turns on and of run::evaluate actually derefencing var refs
                    143: $evaluate = 1;
1.7       albertel  144: 
1.74      albertel  145: # data structure for eidt mode, determines what tags can go into what other tags
                    146: %insertlist=();
1.68      www       147: 
1.99      albertel  148: # stores the list of active tag namespaces
1.76      albertel  149: @namespace=();
                    150: 
1.448     albertel  151: # stores all Scrit Vars displays for later showing
                    152: my @script_var_displays=();
                    153: 
1.172     albertel  154: # a pointer the the Apache request object
                    155: $Apache::lonxml::request='';
                    156: 
1.216     sakharuk  157: # a problem number counter, and check on ether it is used
1.237     sakharuk  158: $Apache::lonxml::counter=1;
1.204     albertel  159: $Apache::lonxml::counter_changed=0;
                    160: 
1.462     foxr      161: # Part counter hash.   In analysis mode, the
                    162: # problems can use this to record which parts increment the counter
                    163: # by how much.  The counter subs will maintain this hash via
                    164: # their optional part parameters.  Note that the assumption is that
                    165: # analysis is done in one request and therefore it is not necessary to
                    166: # save this information request-to-request.
                    167: 
                    168: 
                    169: %Apache::lonxml::counters_per_part = ();
                    170: 
1.212     albertel  171: #internal check on whether to look at style defs
                    172: $Apache::lonxml::usestyle=1;
1.260     albertel  173: 
                    174: #locations used to store the parameter string for style substitutions
                    175: $Apache::lonxml::style_values='';
                    176: $Apache::lonxml::style_end_values='';
1.212     albertel  177: 
1.281     albertel  178: #array of ssi calls that need to occur after we are done parsing
                    179: @Apache::lonxml::ssi_info=();
                    180: 
1.282     albertel  181: #should we do the postag variable interpolation
                    182: $Apache::lonxml::post_evaluate=1;
                    183: 
1.295     albertel  184: #a header message to emit in the case of any generated warning or errors
                    185: $Apache::lonxml::warnings_error_header='';
                    186: 
1.396     foxr      187: #  Control whether or not LaTeX symbols should be substituted for their
                    188: #  \ style equivalents...this may be turned off e.g. in an verbatim
                    189: #  environment.
                    190: 
                    191: $Apache::lonxml::substitute_LaTeX_symbols = 1; # Starts out on.
                    192: 
                    193: sub enable_LaTeX_substitutions {
                    194:     $Apache::lonxml::substitute_LaTeX_symbols = 1;
                    195: }
                    196: sub disable_LaTeX_substitutions {
                    197:     $Apache::lonxml::substitute_LaTeX_symbols = 0;
                    198: }
                    199: 
1.68      www       200: sub xmlend {
1.335     sakharuk  201:     my ($target,$parser)=@_;
1.278     www       202:     my $mode='xml';
                    203:     my $status='OPEN';
1.368     albertel  204:     if ($Apache::lonhomework::parsing_a_problem ||
                    205: 	$Apache::lonhomework::parsing_a_task ) {
1.278     www       206: 	$mode='problem';
                    207: 	$status=$Apache::inputtags::status[-1]; 
                    208:     }
1.362     matthew   209:     my $discussion;
1.379     albertel  210:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    211: 					   ['LONCAPA_INTERNAL_no_discussion']);
1.372     albertel  212:     if (! exists($env{'form.LONCAPA_INTERNAL_no_discussion'}) ||
                    213:         $env{'form.LONCAPA_INTERNAL_no_discussion'} ne 'true') {
1.362     matthew   214:         $discussion=&Apache::lonfeedback::list_discussion($mode,$status);
                    215:     }
1.334     sakharuk  216:     if ($target eq 'tex') {
1.335     sakharuk  217: 	$discussion.='<tex>\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\end{document}</tex>';
1.334     sakharuk  218: 	&Apache::lonxml::newparser($parser,\$discussion,'');
                    219: 	return '';
                    220:     }
1.405     albertel  221: 
1.407     albertel  222:     return $discussion;
1.119     www       223: }
                    224: 
1.48      albertel  225: sub printalltags {
                    226:   my $temp;
                    227:   foreach $temp (sort keys %Apache::lonxml::alltags) {
1.141     albertel  228:     &Apache::lonxml::debug("$temp -- ".
                    229: 		  join(',',@{ $Apache::lonxml::alltags{$temp} }));
1.48      albertel  230:   }
                    231: }
1.31      sakharuk  232: 
1.3       sakharuk  233: sub xmlparse {
1.172     albertel  234:  my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
1.96      albertel  235: 
1.172     albertel  236:  &setup_globals($request,$target);
1.232     albertel  237:  &Apache::inputtags::initialize_inputtags();
1.370     albertel  238:  &Apache::bridgetask::initialize_bridgetask();
1.232     albertel  239:  &Apache::outputtags::initialize_outputtags();
                    240:  &Apache::edit::initialize_edit();
1.287     albertel  241:  &Apache::londefdef::initialize_londefdef();
1.244     albertel  242: 
1.178     www       243: #
                    244: # do we have a course style file?
                    245: #
                    246: 
1.372     albertel  247:  if ($env{'request.course.id'} && $env{'request.state'} ne 'construct') {
1.178     www       248:      my $bodytext=
1.372     albertel  249: 	 $env{'course.'.$env{'request.course.id'}.'.default_xml_style'};
1.178     www       250:      if ($bodytext) {
1.337     albertel  251: 	 foreach my $file (split(',',$bodytext)) {
                    252: 	     my $location=&Apache::lonnet::filelocation('',$file);
                    253: 	     my $styletext=&Apache::lonnet::getfile($location);
                    254: 	     if ($styletext ne '-1') {
                    255: 		 %style_for_target = (%style_for_target,
                    256: 				      &Apache::style::styleparser($target,$styletext));
                    257: 	     }
                    258: 	 }
                    259:      }
1.449     albertel  260:  } elsif ($env{'construct.style'}
                    261: 	  && ($env{'request.state'} eq 'construct')) {
1.372     albertel  262:      my $location=&Apache::lonnet::filelocation('',$env{'construct.style'});
1.291     sakharuk  263:      my $styletext=&Apache::lonnet::getfile($location);
1.449     albertel  264:      if ($styletext ne '-1') {
                    265: 	 %style_for_target = (%style_for_target,
                    266: 			      &Apache::style::styleparser($target,$styletext));
                    267:      }
1.178     www       268:  }
1.255     sakharuk  269: #&printalltags();
1.16      albertel  270:  my @pars = ();
1.372     albertel  271:  my $pwd=$env{'request.filename'};
1.23      albertel  272:  $pwd =~ s:/[^/]*$::;
                    273:  &newparser(\@pars,\$content_file_string,$pwd);
1.24      sakharuk  274: 
1.3       sakharuk  275:  my $safeeval = new Safe;
1.40      albertel  276:  my $safehole = new Safe::Hole;
1.82      ng        277:  &init_safespace($target,$safeeval,$safehole,$safeinit);
1.3       sakharuk  278: #-------------------- Redefinition of the target in the case of compound target
                    279: 
                    280:  ($target, my @tenta) = split('&&',$target);
                    281: 
1.150     albertel  282:  my @stack = ();
1.3       sakharuk  283:  my @parstack = ();
1.358     albertel  284:  &initdepth();
                    285:  &init_alarm();
1.101     albertel  286:  my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
1.394     albertel  287: 				   $safeeval,\%style_for_target,1);
1.255     sakharuk  288: 
1.425     albertel  289:  if (@stack) {
1.482     bisitz    290:      &warning(&mt('At end of file some tags were still left unclosed:').
                    291: 	      ' <tt>&lt;'.join('&gt;</tt>, <tt>&lt;',reverse(@stack)).
1.425     albertel  292: 	      '&gt;</tt>');
                    293:  }
1.372     albertel  294:  if ($env{'request.uri'}) {
                    295:     &writeallows($env{'request.uri'});
1.125     www       296:  }
1.281     albertel  297:  &do_registered_ssi();
1.204     albertel  298:  if ($Apache::lonxml::counter_changed) { &store_counter() }
1.393     albertel  299: 
                    300:  &clean_safespace($safeeval);
                    301: 
1.448     albertel  302:  if (@script_var_displays) {
                    303:      $finaloutput .= join('',@script_var_displays);
                    304:      undef(@script_var_displays);
                    305:  }
1.469     albertel  306:  &init_state();
1.372     albertel  307:  if ($env{'form.return_only_error_and_warning_counts'}) {
1.473     www       308:      if ($env{'request.filename'}=~/\.(html|htm|xml)$/i) { 
                    309:         my $error=&verify_html($content_file_string);
                    310:         if ($error) { $errorcount++; }
                    311:      }
1.361     www       312:      return "$errorcount:$warningcount";
                    313:  }
1.3       sakharuk  314:  return $finaloutput;
1.106     www       315: }
                    316: 
1.191     albertel  317: sub latex_special_symbols {
1.272     albertel  318:     my ($string,$where)=@_;
1.396     foxr      319:     #
                    320:     #  If e.g. in verbatim mode, then don't substitute.
                    321:     #  but return original string.
                    322:     #
                    323:     if (!($Apache::lonxml::substitute_LaTeX_symbols)) {
                    324: 	return $string;
                    325:     }
1.235     sakharuk  326:     if ($where eq 'header') {
1.414     foxr      327: 	$string =~ s/\\/\$\\backslash\$/g; # \  -> $\backslash$ per LaTex line by line pg  10.
1.311     albertel  328: 	$string =~ s/(\$|%|\{|\})/\\$1/g;
                    329: 	$string=&Apache::lonprintout::character_chart($string);
                    330: 	# any & or # leftover should be safe to just escape
                    331:         $string=~s/([^\\])\&/$1\\\&/g;
                    332:         $string=~s/([^\\])\#/$1\\\#/g;
1.415     foxr      333: 	$string =~ s/_/\\_/g;              # _ -> \_
                    334: 	$string =~ s/\^/\\\^{}/g;          # ^ -> \^{} 
1.229     sakharuk  335:     } else {
1.312     albertel  336: 	$string=~s/\\/\\ensuremath{\\backslash}/g;
1.367     albertel  337: 	$string=~s/\\\%|\%/\\\%/g;
                    338: 	$string=~s/\\{|{/\\{/g;
                    339: 	$string=~s/\\}|}/\\}/g;
1.378     albertel  340: 	$string=~s/\\ensuremath\\{\\backslash\\}/\\ensuremath{\\backslash}/g;
1.367     albertel  341: 	$string=~s/\\\$|\$/\\\$/g;
                    342: 	$string=~s/\\\_|\_/\\\_/g;
1.313     albertel  343:         $string=~s/([^\\]|^)(\~|\^)/$1\\$2\\strut /g;
1.310     sakharuk  344: 	$string=~s/(>|<)/\\ensuremath\{$1\}/g; #more or less
1.311     albertel  345: 	$string=&Apache::lonprintout::character_chart($string);
                    346: 	# any & or # leftover should be safe to just escape
1.367     albertel  347: 	$string=~s/\\\&|\&/\\\&/g;
                    348: 	$string=~s/\\\#|\#/\\\#/g;
1.332     sakharuk  349:         $string=~s/\|/\$\\mid\$/g;
1.310     sakharuk  350: #single { or } How to escape?
1.229     sakharuk  351:     }
1.272     albertel  352:     return $string;
1.188     sakharuk  353: }
                    354: 
1.101     albertel  355: sub inner_xmlparse {
1.394     albertel  356:   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target,$start)=@_;
1.101     albertel  357:   my $finaloutput = '';
                    358:   my $result;
                    359:   my $token;
1.258     albertel  360:   my $dontpop=0;
1.389     albertel  361:   my $startredirection = $Apache::lonxml::redirection;
1.101     albertel  362:   while ( $#$pars > -1 ) {
                    363:     while ($token = $$pars['-1']->get_token) {
1.261     albertel  364:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') ) {
1.101     albertel  365: 	if ($metamode<1) {
1.190     albertel  366: 	    my $text=$token->[1];
1.193     albertel  367: 	    if ($token->[0] eq 'C' && $target eq 'tex') {
1.239     sakharuk  368: 		$text = '';
                    369: #		$text = '%'.$text."\n";
1.182     sakharuk  370: 	    }
1.190     albertel  371: 	    $result.=$text;
1.101     albertel  372: 	}
1.261     albertel  373:       } elsif (($token->[0] eq 'D')) {
                    374: 	if ($metamode<1 && $target eq 'web') {
                    375: 	    my $text=$token->[1];
                    376: 	    $result.=$text;
                    377: 	}
1.101     albertel  378:       } elsif ($token->[0] eq 'PI') {
1.261     albertel  379: 	if ($metamode<1 && $target eq 'web') {
1.101     albertel  380: 	  $result=$token->[2];
                    381: 	}
                    382:       } elsif ($token->[0] eq 'S') {
1.140     albertel  383: 	# add tag to stack
1.101     albertel  384: 	push (@$stack,$token->[1]);
                    385: 	# add parameters list to another stack
                    386: 	push (@$parstack,&parstring($token));
1.140     albertel  387: 	&increasedepth($token);
1.212     albertel  388: 	if ($Apache::lonxml::usestyle &&
                    389: 	    exists($$style_for_target{$token->[1]})) {
                    390: 	    $Apache::lonxml::usestyle=0;
                    391: 	    my $string=$$style_for_target{$token->[1]}.
                    392: 	      '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
                    393: 	    &Apache::lonxml::newparser($pars,\$string);
1.257     albertel  394: 	    $Apache::lonxml::style_values=$$parstack[-1];
1.259     albertel  395: 	    $Apache::lonxml::style_end_values=$$parstack[-1];
1.101     albertel  396: 	} else {
                    397: 	  $result = &callsub("start_$token->[1]", $target, $token, $stack,
                    398: 			     $parstack, $pars, $safeeval, $style_for_target);
1.140     albertel  399: 	}
1.101     albertel  400:       } elsif ($token->[0] eq 'E') {
1.212     albertel  401: 	if ($Apache::lonxml::usestyle &&
                    402: 	    exists($$style_for_target{'/'."$token->[1]"})) {
                    403: 	    $Apache::lonxml::usestyle=0;
                    404: 	    my $string=$$style_for_target{'/'.$token->[1]}.
1.258     albertel  405: 	      '<LONCAPA_INTERNAL_TURN_STYLE_ON end="'.$token->[1].'" />';
1.212     albertel  406: 	    &Apache::lonxml::newparser($pars,\$string);
1.259     albertel  407: 	    $Apache::lonxml::style_values=$Apache::lonxml::style_end_values;
                    408: 	    $Apache::lonxml::style_end_values='';
1.258     albertel  409: 	    $dontpop=1;
1.101     albertel  410: 	} else {
1.258     albertel  411: 	    #clear out any tags that didn't end
                    412: 	    while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
                    413: 		my $lasttag=$$stack[-1];
1.317     albertel  414: 		if ($token->[1] =~ /^\Q$lasttag\E$/i) {
1.483     bisitz    415: 		    &Apache::lonxml::warning(&mt('Using tag [_1] on line [_2] as end tag to [_3]','&lt;/'.$token->[1].'&gt;','.$token->[3].','&lt;'.$$stack[-1].'&gt;'));
1.258     albertel  416: 		    last;
                    417: 		} else {
1.483     bisitz    418:                     &Apache::lonxml::warning(&mt('Found tag [_1] on line [_2] when looking for [_3] in file.','&lt;/'.$token->[1].'&gt;',$token->[3],'&lt;/'.$$stack[-1].'&gt;'));
1.258     albertel  419: 		    &end_tag($stack,$parstack,$token);
                    420: 		}
                    421: 	    }
                    422: 	    $result = &callsub("end_$token->[1]", $target, $token, $stack,
                    423: 			       $parstack, $pars,$safeeval, $style_for_target);
1.101     albertel  424: 	}
                    425:       } else {
                    426: 	&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
                    427:       }
                    428:       #evaluate variable refs in result
1.282     albertel  429:       if ($Apache::lonxml::post_evaluate &&$result ne "") {
1.257     albertel  430: 	  my $extras;
                    431: 	  if (!$Apache::lonxml::usestyle) {
                    432: 	      $extras=$Apache::lonxml::style_values;
                    433: 	  }
1.488     raeburn   434: 	  if ( $#$parstack > -1 ) {
                    435: 	      $result=&Apache::run::evaluate($result,$safeeval,$extras.$$parstack[-1]);
                    436: 	  } else {
                    437: 	      $result= &Apache::run::evaluate($result,$safeeval,$extras);
1.487     raeburn   438:           }
1.163     albertel  439:       }
1.282     albertel  440:       $Apache::lonxml::post_evaluate=1;
                    441: 
1.190     albertel  442:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
1.249     albertel  443: 	  #Style file definitions should be correct
1.250     albertel  444: 	  if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {
1.311     albertel  445: 	      $result=&latex_special_symbols($result);
1.249     albertel  446: 	  }
1.190     albertel  447:       }
                    448: 
1.169     albertel  449:       if ($Apache::lonxml::redirection) {
                    450: 	$Apache::lonxml::outputstack['-1'] .= $result;
                    451:       } else {
                    452: 	$finaloutput.=$result;
                    453:       }
                    454:       $result = '';
                    455: 
1.258     albertel  456:       if ($token->[0] eq 'E' && !$dontpop) {
1.101     albertel  457: 	&end_tag($stack,$parstack,$token);
                    458:       }
1.258     albertel  459:       $dontpop=0;
1.224     albertel  460:     }	
1.212     albertel  461:     if ($#$pars > -1) {
                    462: 	pop @$pars;
                    463: 	pop @Apache::lonxml::pwd;
                    464:     }
1.101     albertel  465:   }
                    466: 
                    467:   # if ($target eq 'meta') {
                    468:   #   $finaloutput.=&endredirection;
                    469:   # }
                    470: 
1.394     albertel  471:   if ( $start && $target eq 'grade') { &endredirection(); }
1.389     albertel  472:   if ( $Apache::lonxml::redirection > $startredirection) {
                    473:       while ($Apache::lonxml::redirection > $startredirection) {
                    474: 	  $finaloutput .= &endredirection();
1.387     albertel  475:       }
                    476:   }
1.101     albertel  477:   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
                    478:     $finaloutput=&afterburn($finaloutput);
1.509     www       479:   }
                    480:   if ($target eq 'modified') {
                    481: # if modfied, handle startpart and endpart
                    482:      $finaloutput=~s/\<startpartmarker[^\>]*\>(.*)\<endpartmarker[^\>]*\>/<part>$1<\/part>/gs;
1.216     sakharuk  483:   }	    
1.101     albertel  484:   return $finaloutput;
                    485: }
1.67      www       486: 
1.318     matthew   487: ## 
                    488: ## Looks to see if there is a subroutine defined for this tag.  If so, call it,
                    489: ## otherwise do not call it as we do not know what it is.
                    490: ##
1.7       albertel  491: sub callsub {
1.84      albertel  492:   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.7       albertel  493:   my $currentstring='';
1.72      albertel  494:   my $nodefault;
1.7       albertel  495:   {
1.59      albertel  496:     my $sub1;
1.7       albertel  497:     no strict 'refs';
1.68      www       498:     my $tag=$token->[1];
1.236     www       499: # get utterly rid of extended html tags
                    500:     if ($tag=~/^x\-/i) { return ''; }
1.141     albertel  501:     my $space=$Apache::lonxml::alltags{$tag}[-1];
1.68      www       502:     if (!$space) {
1.141     albertel  503:      	$tag=~tr/A-Z/a-z/;
1.68      www       504: 	$sub=~tr/A-Z/a-z/;
1.141     albertel  505: 	$space=$Apache::lonxml::alltags{$tag}[-1]
1.68      www       506:     }
1.97      albertel  507: 
                    508:     my $deleted=0;
                    509:     if (($token->[0] eq 'S') && ($target eq 'modified')) {
                    510:       $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
                    511: 					     $parstack,$parser,$safeeval,
                    512: 					     $style);
                    513:     }
                    514:     if (!$deleted) {
                    515:       if ($space) {
1.220     albertel  516: 	#&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
1.97      albertel  517: 	$sub1="$space\:\:$sub";
                    518: 	($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
                    519: 					     $parstack,$parser,$safeeval,
                    520: 					     $style);
                    521:       } else {
1.318     matthew   522:           if ($target eq 'tex') {
                    523:               # throw away tag name
                    524:               return '';
                    525:           }
1.220     albertel  526: 	#&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
1.97      albertel  527: 	if ($metamode <1) {
                    528: 	  if (defined($token->[4]) && ($metamode < 1)) {
                    529: 	    $currentstring = $token->[4];
                    530: 	  } else {
                    531: 	    $currentstring = $token->[2];
                    532: 	  }
1.62      sakharuk  533: 	}
1.7       albertel  534:       }
1.97      albertel  535:       #    &Apache::lonxml::debug("nodefalt:$nodefault:");
                    536:       if ($currentstring eq '' && $nodefault eq '') {
                    537: 	if ($target eq 'edit') {
1.220     albertel  538: 	  #&Apache::lonxml::debug("doing default edit for $token->[1]");
1.97      albertel  539: 	  if ($token->[0] eq 'S') {
                    540: 	    $currentstring = &Apache::edit::tag_start($target,$token);
                    541: 	  } elsif ($token->[0] eq 'E') {
                    542: 	    $currentstring = &Apache::edit::tag_end($target,$token);
                    543: 	  }
1.441     albertel  544: 	}
                    545:       }
                    546:       if ($target eq 'modified' && $nodefault eq '') {
                    547: 	  if ($currentstring eq '') {
                    548: 	      if ($token->[0] eq 'S') {
                    549: 		  $currentstring = $token->[4];
                    550: 	      } elsif ($token->[0] eq 'E') {
                    551: 		  $currentstring = $token->[2];
                    552: 	      } else {
                    553: 		  $currentstring = $token->[2];
                    554: 	      }
                    555: 	  }
1.97      albertel  556: 	  if ($token->[0] eq 'S') {
1.447     albertel  557: 	      $currentstring.=&Apache::edit::handle_insert();
1.210     www       558: 	  } elsif ($token->[0] eq 'E') {
1.447     albertel  559: 	      $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
1.97      albertel  560: 	  }
1.72      albertel  561:       }
1.7       albertel  562:     }
                    563:     use strict 'refs';
                    564:   }
                    565:   return $currentstring;
1.82      ng        566: }
                    567: 
1.465     albertel  568: {
                    569:     my %state;
                    570: 
                    571:     sub init_state {
                    572: 	undef(%state);
                    573:     }
                    574:     
                    575:     sub set_state {
                    576: 	my ($key,$value) = @_;
                    577: 	$state{$key} = $value;
                    578: 	return $value;
                    579:     }
                    580:     sub get_state {
                    581: 	my ($key) = @_;
                    582: 	return $state{$key};
                    583:     }
                    584: }
                    585: 
1.96      albertel  586: sub setup_globals {
1.172     albertel  587:   my ($request,$target)=@_;
                    588:   $Apache::lonxml::request=$request;
1.205     www       589:   $errorcount=0;
                    590:   $warningcount=0;
1.490     www       591:   $Apache::lonxml::internal_error=0;
1.207     albertel  592:   $Apache::lonxml::default_homework_loaded=0;
1.212     albertel  593:   $Apache::lonxml::usestyle=1;
1.204     albertel  594:   &init_counter();
1.462     foxr      595:   &clear_bubble_lines_for_part();
1.465     albertel  596:   &init_state();
1.469     albertel  597:   &set_state('target',$target);
1.101     albertel  598:   @Apache::lonxml::pwd=();
1.124     albertel  599:   @Apache::lonxml::extlinks=();
1.448     albertel  600:   @script_var_displays=();
1.281     albertel  601:   @Apache::lonxml::ssi_info=();
1.282     albertel  602:   $Apache::lonxml::post_evaluate=1;
1.295     albertel  603:   $Apache::lonxml::warnings_error_header='';
1.397     albertel  604:   $Apache::lonxml::substitute_LaTeX_symbols = 1;
1.96      albertel  605:   if ($target eq 'meta') {
                    606:     $Apache::lonxml::redirection = 0;
                    607:     $Apache::lonxml::metamode = 1;
                    608:     $Apache::lonxml::evaluate = 1;
                    609:     $Apache::lonxml::import = 0;
1.129     albertel  610:   } elsif ($target eq 'answer') {
                    611:     $Apache::lonxml::redirection = 0;
                    612:     $Apache::lonxml::metamode = 1;
                    613:     $Apache::lonxml::evaluate = 1;
                    614:     $Apache::lonxml::import = 1;
1.96      albertel  615:   } elsif ($target eq 'grade') {
1.387     albertel  616:     &startredirection(); #ended in inner_xmlparse on exit
1.96      albertel  617:     $Apache::lonxml::metamode = 0;
                    618:     $Apache::lonxml::evaluate = 1;
                    619:     $Apache::lonxml::import = 1;
                    620:   } elsif ($target eq 'modified') {
                    621:     $Apache::lonxml::redirection = 0;
                    622:     $Apache::lonxml::metamode = 0;
                    623:     $Apache::lonxml::evaluate = 0;
                    624:     $Apache::lonxml::import = 0;
                    625:   } elsif ($target eq 'edit') {
                    626:     $Apache::lonxml::redirection = 0;
                    627:     $Apache::lonxml::metamode = 0;
                    628:     $Apache::lonxml::evaluate = 0;
                    629:     $Apache::lonxml::import = 0;
1.163     albertel  630:   } elsif ($target eq 'analyze') {
                    631:     $Apache::lonxml::redirection = 0;
                    632:     $Apache::lonxml::metamode = 0;
                    633:     $Apache::lonxml::evaluate = 1;
                    634:     $Apache::lonxml::import = 1;
1.96      albertel  635:   } else {
                    636:     $Apache::lonxml::redirection = 0;
                    637:     $Apache::lonxml::metamode = 0;
                    638:     $Apache::lonxml::evaluate = 1;
                    639:     $Apache::lonxml::import = 1;
                    640:   }
                    641: }
                    642: 
1.82      ng        643: sub init_safespace {
                    644:   my ($target,$safeeval,$safehole,$safeinit) = @_;
1.393     albertel  645:   $safeeval->deny_only(':dangerous');
                    646:   $safeeval->reval('use Math::Complex;');
1.383     albertel  647:   $safeeval->permit_only(":default");
1.82      ng        648:   $safeeval->permit("entereval");
                    649:   $safeeval->permit(":base_math");
                    650:   $safeeval->permit("sort");
1.286     albertel  651:   $safeeval->permit("time");
1.480     www       652:   $safeeval->permit("caller");
1.371     albertel  653:   $safeeval->deny("rand");
                    654:   $safeeval->deny("srand");
1.82      ng        655:   $safeeval->deny(":base_io");
1.102     albertel  656:   $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
1.251     albertel  657:   $safehole->wrap(\&Apache::outputtags::multipart,$safeeval,'&multipart');
1.82      ng        658:   $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
1.324     albertel  659:   $safehole->wrap(\&Apache::chemresponse::chem_standard_order,$safeeval,
                    660: 		  '&chem_standard_order');
1.369     albertel  661:   $safehole->wrap(\&Apache::response::check_status,$safeeval,'&check_status');
1.471     bisitz    662:   $safehole->wrap(\&Apache::response::implicit_multiplication,$safeeval,'&implicit_multiplication');
1.324     albertel  663: 
1.431     www       664:   $safehole->wrap(\&Apache::lonmaxima::maxima_eval,$safeeval,'&maxima_eval');
1.432     www       665:   $safehole->wrap(\&Apache::lonmaxima::maxima_check,$safeeval,'&maxima_check');
1.433     albertel  666:   $safehole->wrap(\&Apache::lonmaxima::maxima_cas_formula_fix,$safeeval,
                    667: 		  '&maxima_cas_formula_fix');
                    668: 
1.494     www       669:   $safehole->wrap(\&Apache::lonr::r_eval,$safeeval,'&r_eval');
1.497     www       670:   $safehole->wrap(\&Apache::lonr::Rentry,$safeeval,'&Rentry');
                    671:   $safehole->wrap(\&Apache::lonr::Rarray,$safeeval,'&Rarray');
1.494     www       672:   $safehole->wrap(\&Apache::lonr::r_check,$safeeval,'&r_check');
                    673:   $safehole->wrap(\&Apache::lonr::r_cas_formula_fix,$safeeval,
                    674:                   '&r_cas_formula_fix');
                    675:  
1.433     albertel  676:   $safehole->wrap(\&Apache::caparesponse::capa_formula_fix,$safeeval,
                    677: 		  '&capa_formula_fix');
1.431     www       678: 
1.480     www       679:   $safehole->wrap(\&Apache::lonlocal::locallocaltime,$safeeval,
                    680:                   '&locallocaltime');
                    681: 
1.82      ng        682:   $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
                    683:   $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
                    684:   $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
                    685:   $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
                    686:   $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
                    687:   $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
                    688:   $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
                    689:   $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
                    690:   $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
                    691:   $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
                    692:   $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
                    693:   $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
                    694:   $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
                    695:   $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
                    696:   $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
                    697:   $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
                    698:   $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
                    699:   $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
                    700:   $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
1.215     albertel  701:   
                    702:   $safehole->wrap(\&Math::Cephes::bdtr  ,$safeeval,'&bdtr'  );
                    703:   $safehole->wrap(\&Math::Cephes::bdtrc ,$safeeval,'&bdtrc' );
                    704:   $safehole->wrap(\&Math::Cephes::bdtri ,$safeeval,'&bdtri' );
                    705:   $safehole->wrap(\&Math::Cephes::btdtr ,$safeeval,'&btdtr' );
                    706:   $safehole->wrap(\&Math::Cephes::chdtr ,$safeeval,'&chdtr' );
                    707:   $safehole->wrap(\&Math::Cephes::chdtrc,$safeeval,'&chdtrc');
                    708:   $safehole->wrap(\&Math::Cephes::chdtri,$safeeval,'&chdtri');
                    709:   $safehole->wrap(\&Math::Cephes::fdtr  ,$safeeval,'&fdtr'  );
                    710:   $safehole->wrap(\&Math::Cephes::fdtrc ,$safeeval,'&fdtrc' );
                    711:   $safehole->wrap(\&Math::Cephes::fdtri ,$safeeval,'&fdtri' );
                    712:   $safehole->wrap(\&Math::Cephes::gdtr  ,$safeeval,'&gdtr'  );
                    713:   $safehole->wrap(\&Math::Cephes::gdtrc ,$safeeval,'&gdtrc' );
                    714:   $safehole->wrap(\&Math::Cephes::nbdtr ,$safeeval,'&nbdtr' );
                    715:   $safehole->wrap(\&Math::Cephes::nbdtrc,$safeeval,'&nbdtrc');
                    716:   $safehole->wrap(\&Math::Cephes::nbdtri,$safeeval,'&nbdtri');
                    717:   $safehole->wrap(\&Math::Cephes::ndtr  ,$safeeval,'&ndtr'  );
                    718:   $safehole->wrap(\&Math::Cephes::ndtri ,$safeeval,'&ndtri' );
                    719:   $safehole->wrap(\&Math::Cephes::pdtr  ,$safeeval,'&pdtr'  );
                    720:   $safehole->wrap(\&Math::Cephes::pdtrc ,$safeeval,'&pdtrc' );
                    721:   $safehole->wrap(\&Math::Cephes::pdtri ,$safeeval,'&pdtri' );
                    722:   $safehole->wrap(\&Math::Cephes::stdtr ,$safeeval,'&stdtr' );
                    723:   $safehole->wrap(\&Math::Cephes::stdtri,$safeeval,'&stdtri');
                    724: 
1.383     albertel  725:   $safehole->wrap(\&Math::Cephes::Matrix::mat,$safeeval,'&mat');
                    726:   $safehole->wrap(\&Math::Cephes::Matrix::new,$safeeval,
                    727: 		  '&Math::Cephes::Matrix::new');
                    728:   $safehole->wrap(\&Math::Cephes::Matrix::coef,$safeeval,
                    729: 		  '&Math::Cephes::Matrix::coef');
                    730:   $safehole->wrap(\&Math::Cephes::Matrix::clr,$safeeval,
                    731: 		  '&Math::Cephes::Matrix::clr');
                    732:   $safehole->wrap(\&Math::Cephes::Matrix::add,$safeeval,
                    733: 		  '&Math::Cephes::Matrix::add');
                    734:   $safehole->wrap(\&Math::Cephes::Matrix::sub,$safeeval,
                    735: 		  '&Math::Cephes::Matrix::sub');
                    736:   $safehole->wrap(\&Math::Cephes::Matrix::mul,$safeeval,
                    737: 		  '&Math::Cephes::Matrix::mul');
                    738:   $safehole->wrap(\&Math::Cephes::Matrix::div,$safeeval,
                    739: 		  '&Math::Cephes::Matrix::div');
                    740:   $safehole->wrap(\&Math::Cephes::Matrix::inv,$safeeval,
                    741: 		  '&Math::Cephes::Matrix::inv');
                    742:   $safehole->wrap(\&Math::Cephes::Matrix::transp,$safeeval,
                    743: 		  '&Math::Cephes::Matrix::transp');
                    744:   $safehole->wrap(\&Math::Cephes::Matrix::simq,$safeeval,
                    745: 		  '&Math::Cephes::Matrix::simq');
                    746:   $safehole->wrap(\&Math::Cephes::Matrix::mat_to_vec,$safeeval,
                    747: 		  '&Math::Cephes::Matrix::mat_to_vec');
                    748:   $safehole->wrap(\&Math::Cephes::Matrix::vec_to_mat,$safeeval,
                    749: 		  '&Math::Cephes::Matrix::vec_to_mat');
                    750:   $safehole->wrap(\&Math::Cephes::Matrix::check,$safeeval,
                    751: 		  '&Math::Cephes::Matrix::check');
                    752:   $safehole->wrap(\&Math::Cephes::Matrix::check,$safeeval,
                    753: 		  '&Math::Cephes::Matrix::check');
                    754: 
1.215     albertel  755: #  $safehole->wrap(\&Math::Cephes::new_fract,$safeeval,'&new_fract');
                    756: #  $safehole->wrap(\&Math::Cephes::radd,$safeeval,'&radd');
                    757: #  $safehole->wrap(\&Math::Cephes::rsub,$safeeval,'&rsub');
                    758: #  $safehole->wrap(\&Math::Cephes::rmul,$safeeval,'&rmul');
                    759: #  $safehole->wrap(\&Math::Cephes::rdiv,$safeeval,'&rdiv');
                    760: #  $safehole->wrap(\&Math::Cephes::euclid,$safeeval,'&euclid');
                    761: 
1.91      ng        762:   $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
                    763:   $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
                    764:   $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
                    765:   $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
                    766:   $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
                    767:   $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
                    768:   $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
                    769:   $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
                    770:   $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
                    771:   $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
                    772:   $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
1.93      ng        773:   $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
1.91      ng        774:   $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
                    775:   $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
                    776:   $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
                    777:   $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
                    778:   $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
                    779:   $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
                    780:   $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
                    781:   $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
                    782:   $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
1.458     albertel  783:   $safehole->wrap(\&Apache::loncommon::languages,$safeeval,'&languages');
1.305     albertel  784:   $safehole->wrap(\&Apache::lonxml::error,$safeeval,'&LONCAPA_INTERNAL_ERROR');
1.311     albertel  785:   $safehole->wrap(\&Apache::lonxml::debug,$safeeval,'&LONCAPA_INTERNAL_DEBUG');
1.420     albertel  786:   $safehole->wrap(\&Apache::lonnet::logthis,$safeeval,'&LONCAPA_INTERNAL_LOGTHIS');
                    787:   $safehole->wrap(\&Apache::inputtags::finalizeawards,$safeeval,'&LONCAPA_INTERNAL_FINALIZEAWARDS');
1.322     albertel  788:   $safehole->wrap(\&Apache::caparesponse::get_sigrange,$safeeval,'&LONCAPA_INTERNAL_get_sigrange');
1.430     albertel  789: #  use Data::Dumper;
                    790: #  $safehole->wrap(\&Data::Dumper::Dumper,$safeeval,'&LONCAPA_INTERNAL_Dumper');
1.82      ng        791: #need to inspect this class of ops
                    792: # $safeeval->deny(":base_orig");
1.331     albertel  793:   $safeeval->permit("require");
1.91      ng        794:   $safeinit .= ';$external::target="'.$target.'";';
1.82      ng        795:   &Apache::run::run($safeinit,$safeeval);
1.373     albertel  796:   &initialize_rndseed($safeeval);
                    797: }
1.303     albertel  798: 
1.393     albertel  799: sub clean_safespace {
                    800:     my ($safeeval) = @_;
                    801:     delete_package_recurse($safeeval->{Root});
                    802: }
                    803: 
                    804: sub delete_package_recurse {
                    805:      my ($package) = @_;
                    806:      my @subp;
                    807:      {
                    808: 	 no strict 'refs';
                    809: 	 while (my ($key,$val) = each(%{*{"$package\::"}})) {
                    810: 	     if (!defined($val)) { next; }
                    811: 	     local (*ENTRY) = $val;
                    812: 	     if (defined *ENTRY{HASH} && $key =~ /::$/ &&
                    813: 		 $key ne "main::" && $key ne "<none>::")
                    814: 	     {
                    815: 		 my ($p) = $package ne "main" ? "$package\::" : "";
                    816: 		 ($p .= $key) =~ s/::$//;
                    817: 		 push(@subp,$p);
                    818: 	     }
                    819: 	 }
                    820:      }
                    821:      foreach my $p (@subp) {
                    822: 	 delete_package_recurse($p);
                    823:      }
                    824:      Symbol::delete_package($package);
                    825: }
                    826: 
1.373     albertel  827: sub initialize_rndseed {
                    828:     my ($safeeval)=@_;
                    829:     my $rndseed;
1.423     albertel  830:     my ($symb,$courseid,$domain,$name) = &Apache::lonnet::whichuser();
1.373     albertel  831:     $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
                    832:     my $safeinit = '$external::randomseed="'.$rndseed.'";';
                    833:     &Apache::lonxml::debug("Setting rndseed to $rndseed");
                    834:     &Apache::run::run($safeinit,$safeeval);
1.207     albertel  835: }
                    836: 
                    837: sub default_homework_load {
                    838:     my ($safeeval)=@_;
                    839:     &Apache::lonxml::debug('Loading default_homework');
                    840:     my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
1.241     albertel  841:     if ($default eq -1) {
1.207     albertel  842: 	&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
                    843:     } else {
                    844: 	&Apache::run::run($default,$safeeval);
                    845: 	$Apache::lonxml::default_homework_loaded=1;
                    846:     }
1.17      albertel  847: }
                    848: 
1.358     albertel  849: {
                    850:     my $alarm_depth;
                    851:     sub init_alarm {
                    852: 	alarm(0);
                    853: 	$alarm_depth=0;
                    854:     }
                    855: 
                    856:     sub start_alarm {
                    857: 	if ($alarm_depth<1) {
                    858: 	    my $old=alarm($Apache::lonnet::perlvar{'lonScriptTimeout'});
                    859: 	    if ($old) {
                    860: 		&Apache::lonxml::error("Cancelled an alarm of $old, this shouldn't occur.");
                    861: 	    }
                    862: 	}
                    863: 	$alarm_depth++;
                    864:     }
                    865: 
                    866:     sub end_alarm {
                    867: 	$alarm_depth--;
                    868: 	if ($alarm_depth<1) { alarm(0); }
                    869:     }
                    870: }
1.328     albertel  871: my $metamode_was;
1.55      albertel  872: sub startredirection {
1.328     albertel  873:     if (!$Apache::lonxml::redirection) {
                    874: 	$metamode_was=$Apache::lonxml::metamode;
                    875:     }
                    876:     $Apache::lonxml::metamode=0;
                    877:     $Apache::lonxml::redirection++;
                    878:     push (@Apache::lonxml::outputstack, '');
1.55      albertel  879: }
                    880: 
                    881: sub endredirection {
1.328     albertel  882:     if (!$Apache::lonxml::redirection) {
1.380     www       883: 	&Apache::lonxml::error("Endredirection was called before a startredirection, perhaps you have unbalanced tags. Some debugging information:".join ":",caller);
1.328     albertel  884: 	return '';
                    885:     }
                    886:     $Apache::lonxml::redirection--;
                    887:     if (!$Apache::lonxml::redirection) {
                    888: 	$Apache::lonxml::metamode=$metamode_was;
                    889:     }
                    890:     pop @Apache::lonxml::outputstack;
1.97      albertel  891: }
1.459     albertel  892: sub in_redirection {
                    893:     return ($Apache::lonxml::redirection > 0)
                    894: }
1.97      albertel  895: 
                    896: sub end_tag {
                    897:   my ($tagstack,$parstack,$token)=@_;
                    898:   pop(@$tagstack);
                    899:   pop(@$parstack);
                    900:   &decreasedepth($token);
1.55      albertel  901: }
                    902: 
1.17      albertel  903: sub initdepth {
                    904:   @Apache::lonxml::depthcounter=();
1.439     albertel  905:   undef($Apache::lonxml::last_depth_count);
1.17      albertel  906: }
                    907: 
1.438     albertel  908: 
1.339     albertel  909: my @timers;
                    910: my $lasttime;
1.438     albertel  911: # @Apache::lonxml::depthcounter -> count of tags that exist so
                    912: #                                  far at each level
1.439     albertel  913: # $Apache::lonxml::last_depth_count -> when ascending, need to
                    914: # remember the count for the level below the current level (for
                    915: # example going from 1_2 -> 1 -> 1_3 need to remember the 2 )
1.438     albertel  916: 
1.17      albertel  917: sub increasedepth {
1.19      albertel  918:   my ($token) = @_;
1.439     albertel  919:   push(@Apache::lonxml::depthcounter,$Apache::lonxml::last_depth_count+1);
                    920:   undef($Apache::lonxml::last_depth_count);
1.340     albertel  921:   my $time;
                    922:   if ($Apache::lonxml::debug eq "1") {
                    923:       push(@timers,[&gettimeofday()]);
                    924:       $time=&tv_interval($lasttime);
                    925:       $lasttime=[&gettimeofday()];
                    926:   }
1.439     albertel  927:   my $spacing='  'x($#Apache::lonxml::depthcounter);
1.438     albertel  928:   $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
1.439     albertel  929: #  &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time");
1.54      albertel  930: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17      albertel  931: }
                    932: 
                    933: sub decreasedepth {
1.19      albertel  934:   my ($token) = @_;
1.439     albertel  935:   if (  $#Apache::lonxml::depthcounter == -1) {
                    936:       &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
1.43      albertel  937:   }
1.439     albertel  938:   $Apache::lonxml::last_depth_count = pop(@Apache::lonxml::depthcounter);
                    939: 
1.340     albertel  940:   my ($timer,$time);
                    941:   if ($Apache::lonxml::debug eq "1") {
                    942:       $timer=pop(@timers);
                    943:       $time=&tv_interval($lasttime);
                    944:       $lasttime=[&gettimeofday()];
                    945:   }
1.439     albertel  946:   my $spacing='  'x($#Apache::lonxml::depthcounter);
                    947:   $Apache::lonxml::curdepth = join('_',@Apache::lonxml::depthcounter);
                    948: #  &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time : ".&tv_interval($timer));
1.54      albertel  949: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1       sakharuk  950: }
1.19      albertel  951: 
1.399     albertel  952: sub get_id {
                    953:     my ($parstack,$safeeval)=@_;
                    954:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
1.449     albertel  955:     if ($env{'request.state'} eq 'construct' && $id =~ /([._]|[^\w\d\s[:punct:]])/) {
1.498     bisitz    956: 	&error(&mt('ID [_1] contains invalid characters. IDs are only allowed to contain letters, numbers, spaces and -','"<tt>'.$id.'</tt>"'));
1.399     albertel  957:     }
                    958:     if ($id =~ /^\s*$/) { $id = $Apache::lonxml::curdepth; }
                    959:     return $id;
                    960: }
                    961: 
1.180     albertel  962: sub get_all_text_unbalanced {
1.190     albertel  963: #there is a copy of this in lonpublisher.pm
1.326     albertel  964:     my($tag,$pars)= @_;
                    965:     my $token;
                    966:     my $result='';
                    967:     $tag='<'.$tag.'>';
                    968:     while ($token = $$pars[-1]->get_token) {
                    969: 	if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1.386     albertel  970: 	    if ($token->[0] eq 'T' && $token->[2]) {
1.382     albertel  971: 		$result.='<![CDATA['.$token->[1].']]>';
                    972: 	    } else {
                    973: 		$result.=$token->[1];
                    974: 	    }
1.326     albertel  975: 	} elsif ($token->[0] eq 'PI') {
                    976: 	    $result.=$token->[2];
                    977: 	} elsif ($token->[0] eq 'S') {
                    978: 	    $result.=$token->[4];
                    979: 	} elsif ($token->[0] eq 'E')  {
                    980: 	    $result.=$token->[2];
                    981: 	}
                    982: 	if ($result =~ /\Q$tag\E/is) {
                    983: 	    ($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is;
                    984: 	    #&Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
                    985: 	    #&Apache::lonxml::debug('Result is :'.$1);
                    986: 	    $redo=$tag.$redo;
                    987: 	    &Apache::lonxml::newparser($pars,\$redo);
                    988: 	    last;
                    989: 	}
                    990:     }
                    991:     return $result
1.462     foxr      992: 
1.204     albertel  993: }
                    994: 
1.462     foxr      995: #########################################################################
                    996: #                                                                       #
                    997: #           bubble line counter management                              #
                    998: #                                                                       #
                    999: #########################################################################
                   1000: 
1.447     albertel 1001: =pod
                   1002: 
                   1003: For bubble grading mode and exam bubble printing mode, the tracking of
                   1004: the current 'bubble line number' is stored in the %env element
                   1005: 'form.counter', and is modifed and handled by the following routines.
                   1006: 
                   1007: The value of it is stored in $Apache:lonxml::counter when live and
                   1008: stored back to env after done.
                   1009: 
                   1010: =item &increment_counter($increment);
                   1011: 
                   1012: Increments the internal counter environment variable a specified amount
                   1013: 
                   1014: Optional Arguments:
                   1015:   $increment - amount to increment by (defaults to 1)
1.462     foxr     1016:                Also 1 if the value is negative or zero.
1.467     foxr     1017:   $part_response - A concatenation of the part and response id
                   1018:                    identifying exactly what is being 'answered'.
                   1019: 
1.447     albertel 1020: 
                   1021: =cut
                   1022: 
1.204     albertel 1023: sub increment_counter {
1.467     foxr     1024:     my ($increment, $part_response) = @_;
1.481     raeburn  1025:     if ($env{'form.grade_noincrement'}) { return; }
1.462     foxr     1026:     if (!defined($increment) || $increment le 0) {
                   1027: 	$increment = 1;
                   1028:     }
                   1029:     $Apache::lonxml::counter += $increment;
                   1030: 
1.466     foxr     1031:     # If the caller supplied the response_id parameter, 
1.462     foxr     1032:     # Maintain its counter.. creating if necessary.
                   1033: 
1.470     albertel 1034:     if (defined($part_response)) {
1.467     foxr     1035: 	if (!defined($Apache::lonxml::counters_per_part{$part_response})) {
                   1036: 	    $Apache::lonxml::counters_per_part{$part_response} = 0;
1.462     foxr     1037: 	}
1.467     foxr     1038: 	$Apache::lonxml::counters_per_part{$part_response} += $increment;
                   1039: 	my $new_value = $Apache::lonxml::counters_per_part{$part_response};
1.247     albertel 1040:     }
1.462     foxr     1041: 	
1.289     sakharuk 1042:     $Apache::lonxml::counter_changed=1;
1.204     albertel 1043: }
                   1044: 
1.447     albertel 1045: =pod
                   1046: 
1.461     foxr     1047: =item &init_counter($increment);
1.447     albertel 1048: 
                   1049: Initialize the internal counter environment variable
                   1050: 
                   1051: =cut
                   1052: 
1.204     albertel 1053: sub init_counter {
1.391     albertel 1054:     if ($env{'request.state'} eq 'construct') {
                   1055: 	$Apache::lonxml::counter=1;
                   1056: 	$Apache::lonxml::counter_changed=1;
                   1057:     } elsif (defined($env{'form.counter'})) {
1.372     albertel 1058: 	$Apache::lonxml::counter=$env{'form.counter'};
1.247     albertel 1059: 	$Apache::lonxml::counter_changed=0;
1.237     sakharuk 1060:     } else {
1.204     albertel 1061: 	$Apache::lonxml::counter=1;
1.247     albertel 1062: 	$Apache::lonxml::counter_changed=1;
1.204     albertel 1063:     }
                   1064: }
                   1065: 
                   1066: sub store_counter {
1.474     raeburn  1067:     &Apache::lonnet::appenv({'form.counter' => $Apache::lonxml::counter});
1.401     albertel 1068:     $Apache::lonxml::counter_changed=0;
1.204     albertel 1069:     return '';
1.180     albertel 1070: }
                   1071: 
1.398     albertel 1072: {
                   1073:     my $state;
                   1074:     sub clear_problem_counter {
                   1075: 	undef($state);
                   1076: 	&Apache::lonnet::delenv('form.counter');
                   1077: 	&Apache::lonxml::init_counter();
                   1078: 	&Apache::lonxml::store_counter();
                   1079:     }
                   1080: 
                   1081:     sub remember_problem_counter {
1.422     albertel 1082: 	&Apache::lonnet::transfer_profile_to_env(undef,undef,1);
1.398     albertel 1083: 	$state = $env{'form.counter'};
                   1084:     }
                   1085: 
                   1086:     sub restore_problem_counter {
                   1087: 	if (defined($state)) {
1.474     raeburn  1088: 	    &Apache::lonnet::appenv({'form.counter' => $state});
1.398     albertel 1089: 	}
                   1090:     }
1.401     albertel 1091:     sub get_problem_counter {
                   1092: 	if ($Apache::lonxml::counter_changed) { &store_counter() }
1.422     albertel 1093: 	&Apache::lonnet::transfer_profile_to_env(undef,undef,1);
1.401     albertel 1094: 	return $env{'form.counter'};
                   1095:     }
1.398     albertel 1096: }
                   1097: 
1.462     foxr     1098: =pod
                   1099: 
1.468     albertel 1100: =item  bubble_lines_for_part(part_response)
1.462     foxr     1101: 
                   1102: Returns the number of lines required to get a response for
1.467     foxr     1103: $part_response (this is just $Apache::lonxml::counters_per_part{$part_response}
1.462     foxr     1104: 
                   1105: =cut
                   1106: 
                   1107: sub bubble_lines_for_part {
1.467     foxr     1108:     my ($part_response) = @_;
1.462     foxr     1109: 
1.467     foxr     1110:     if (!defined($Apache::lonxml::counters_per_part{$part_response})) {
1.462     foxr     1111: 	return 0;
                   1112:     } else {
1.467     foxr     1113: 	return $Apache::lonxml::counters_per_part{$part_response};
1.462     foxr     1114:     }
                   1115: }
                   1116: 
                   1117: =pod
                   1118: 
                   1119: =item clear_bubble_lines_for_part
                   1120: 
                   1121: Clears the hash of bubble lines per part.  If a caller
                   1122: needs to analyze several resources this should be called between
                   1123: resources to reset the hash for each problem being analyzed.
                   1124: 
                   1125: =cut
                   1126: 
                   1127: sub clear_bubble_lines_for_part {
                   1128:     undef(%Apache::lonxml::counters_per_part);
                   1129: }
                   1130: 
                   1131: =pod
                   1132: 
1.468     albertel 1133: =item set_bubble_lines(part_response, value)
1.462     foxr     1134: 
                   1135: If there is a problem part, that for whatever reason
                   1136: requires bubble lines that are not
                   1137: the same as the counter increment, it can call this sub during
                   1138: analysis to set its hash value explicitly.
                   1139: 
                   1140: =cut
                   1141: 
                   1142: sub set_bubble_lines {
1.467     foxr     1143:     my ($part_response, $value) = @_;
1.462     foxr     1144: 
1.467     foxr     1145:     $Apache::lonxml::counters_per_part{$part_response} = $value;
1.462     foxr     1146: }
                   1147: 
                   1148: =pod
                   1149: 
                   1150: =item get_bubble_line_hash
                   1151: 
                   1152: Returns the current bubble line hash.  This is assumed to 
                   1153: be small so we return a copy
                   1154: 
                   1155: 
                   1156: =cut
                   1157: 
                   1158: sub get_bubble_line_hash {
                   1159:     return %Apache::lonxml::counters_per_part;
                   1160: }
                   1161: 
                   1162: 
                   1163: #--------------------------------------------------
                   1164: 
1.19      albertel 1165: sub get_all_text {
1.270     albertel 1166:     my($tag,$pars,$style)= @_;
                   1167:     my $gotfullstack=1;
                   1168:     if (ref($pars) ne 'ARRAY') {
                   1169: 	$gotfullstack=0;
                   1170: 	$pars=[$pars];
                   1171:     }
                   1172:     if (ref($style) ne 'HASH') {
                   1173: 	$style={};
                   1174:     }
                   1175:     my $depth=0;
                   1176:     my $token;
                   1177:     my $result='';
                   1178:     if ( $tag =~ m:^/: ) { 
                   1179: 	my $tag=substr($tag,1); 
                   1180: 	#&Apache::lonxml::debug("have:$tag:");
                   1181: 	my $top_empty=0;
                   1182: 	while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
                   1183: 	    while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
                   1184: 		#&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
                   1185: 		if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1.382     albertel 1186: 		    if ($token->[2]) {
                   1187: 			$result.='<![CDATA['.$token->[1].']]>';
                   1188: 		    } else {
                   1189: 			$result.=$token->[1];
                   1190: 		    }
1.270     albertel 1191: 		} elsif ($token->[0] eq 'PI') {
                   1192: 		    $result.=$token->[2];
                   1193: 		} elsif ($token->[0] eq 'S') {
1.316     albertel 1194: 		    if ($token->[1] =~ /^\Q$tag\E$/i) { $depth++; }
                   1195: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/) { $Apache::lonxml::usestyle=1; }
                   1196: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/) { $Apache::lonxml::usestyle=0; }
1.270     albertel 1197: 		    $result.=$token->[4];
                   1198: 		} elsif ($token->[0] eq 'E')  {
1.316     albertel 1199: 		    if ( $token->[1] =~ /^\Q$tag\E$/i) { $depth--; }
1.270     albertel 1200: 		    #skip sending back the last end tag
1.283     albertel 1201: 		    if ($depth == 0 && exists($$style{'/'.$token->[1]}) && $Apache::lonxml::usestyle) {
1.270     albertel 1202: 			my $string=
                   1203: 			    '<LONCAPA_INTERNAL_TURN_STYLE_OFF end="yes" />'.
                   1204: 				$$style{'/'.$token->[1]}.
                   1205: 				    $token->[2].
                   1206: 					'<LONCAPA_INTERNAL_TURN_STYLE_ON />';
                   1207: 			&Apache::lonxml::newparser($pars,\$string);
                   1208: 			#&Apache::lonxml::debug("reParsing $string");
                   1209: 			next;
                   1210: 		    }
                   1211: 		    if ($depth > -1) {
                   1212: 			$result.=$token->[2];
                   1213: 		    } else {
                   1214: 			$$pars[-1]->unget_token($token);
                   1215: 		    }
                   1216: 		}
                   1217: 	    }
                   1218: 	    if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }
                   1219: 	    if (($depth >=0) && ($#$pars > 0) ) {
                   1220: 		pop(@$pars);
                   1221: 		pop(@Apache::lonxml::pwd);
                   1222: 	    }
                   1223: 	}
                   1224: 	if ($top_empty && $depth >= 0) {
                   1225: 	    #never found the end tag ran out of text, throw error send back blank
                   1226: 	    &error('Never found end tag for &lt;'.$tag.
                   1227: 		   '&gt; current string <pre>'.
1.314     albertel 1228: 		   &HTML::Entities::encode($result,'<>&"').
1.270     albertel 1229: 		   '</pre>');
                   1230: 	    if ($gotfullstack) {
                   1231: 		my $newstring='</'.$tag.'>'.$result;
                   1232: 		&Apache::lonxml::newparser($pars,\$newstring);
                   1233: 	    }
                   1234: 	    $result='';
                   1235: 	}
                   1236:     } else {
                   1237: 	while ($#$pars > -1) {
                   1238: 	    while ($token = $$pars[-1]->get_token) {
                   1239: 		#&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
                   1240: 		if (($token->[0] eq 'T')||($token->[0] eq 'C')||
                   1241: 		    ($token->[0] eq 'D')) {
1.382     albertel 1242: 		    if ($token->[2]) {
                   1243: 			$result.='<![CDATA['.$token->[1].']]>';
                   1244: 		    } else {
                   1245: 			$result.=$token->[1];
                   1246: 		    }
1.270     albertel 1247: 		} elsif ($token->[0] eq 'PI') {
                   1248: 		    $result.=$token->[2];
                   1249: 		} elsif ($token->[0] eq 'S') {
1.316     albertel 1250: 		    if ( $token->[1] =~ /^\Q$tag\E$/i) {
1.270     albertel 1251: 			$$pars[-1]->unget_token($token); last;
                   1252: 		    } else {
                   1253: 			$result.=$token->[4];
                   1254: 		    }
1.316     albertel 1255: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/) { $Apache::lonxml::usestyle=1; }
                   1256: 		    if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/) { $Apache::lonxml::usestyle=0; }
1.270     albertel 1257: 		} elsif ($token->[0] eq 'E')  {
                   1258: 		    $result.=$token->[2];
                   1259: 		}
                   1260: 	    }
                   1261: 	    if (($#$pars > 0) ) {
                   1262: 		pop(@$pars);
                   1263: 		pop(@Apache::lonxml::pwd);
                   1264: 	    } else { last; }
                   1265: 	}
                   1266:     }
                   1267:     #&Apache::lonxml::debug("Exit:$result:");
                   1268:     return $result
1.19      albertel 1269: }
                   1270: 
1.23      albertel 1271: sub newparser {
                   1272:   my ($parser,$contentref,$dir) = @_;
1.167     albertel 1273:   push (@$parser,HTML::LCParser->new($contentref));
1.365     albertel 1274:   $$parser[-1]->xml_mode(1);
                   1275:   $$parser[-1]->marked_sections(1);
1.23      albertel 1276:   if ( $dir eq '' ) {
                   1277:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
                   1278:   } else {
                   1279:     push (@Apache::lonxml::pwd, $dir);
                   1280:   } 
                   1281: }
1.1       sakharuk 1282: 
1.8       albertel 1283: sub parstring {
1.417     albertel 1284:     my ($token) = @_;
                   1285:     my (@vars,@values);
                   1286:     foreach my $attr (@{$token->[3]}) {
                   1287: 	if ($attr!~/\W/) {
                   1288: 	    my $val=$token->[2]->{$attr};
                   1289: 	    $val =~ s/([\%\@\\\"\'])/\\$1/g;
                   1290: 	    $val =~ s/(\$[^\{a-zA-Z_])/\\$1/g;
                   1291: 	    $val =~ s/(\$)$/\\$1/;
                   1292: 	    #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
                   1293: 	    push(@vars,"\$$attr");
                   1294: 	    push(@values,"\"$val\"");
                   1295: 	}
                   1296:     }
                   1297:     my $var_init = 
                   1298: 	(@vars) ? 'my ('.join(',',@vars).') = ('.join(',',@values).');'
                   1299: 	        : '';
                   1300:     return $var_init;
1.8       albertel 1301: }
1.22      albertel 1302: 
1.384     albertel 1303: sub extlink {
                   1304:     my ($res,$exact)=@_;
                   1305:     if (!$exact) {
                   1306: 	$res=&Apache::lonnet::hreflocation($Apache::lonxml::pwd[-1],$res);
                   1307:     }
                   1308:     push(@Apache::lonxml::extlinks,$res)	 
                   1309: }
                   1310: 
1.34      www      1311: sub writeallows {
1.126     www      1312:     unless ($#extlinks>=0) { return; }
1.377     albertel 1313:     my $thisurl = &Apache::lonnet::clutter(shift);
1.372     albertel 1314:     if ($env{'httpref.'.$thisurl}) {
                   1315: 	$thisurl=$env{'httpref.'.$thisurl};
1.111     www      1316:     }
1.34      www      1317:     my $thisdir=$thisurl;
                   1318:     $thisdir=~s/\/[^\/]+$//;
                   1319:     my %httpref=();
1.142     albertel 1320:     foreach (@extlinks) {
1.34      www      1321:        $httpref{'httpref.'.
1.444     albertel 1322:  	        &Apache::lonnet::hreflocation($thisdir,&unescape($_))}=$thisurl;
1.142     albertel 1323:     }
1.126     www      1324:     @extlinks=();
1.474     raeburn  1325:     &Apache::lonnet::appenv(\%httpref);
1.34      www      1326: }
                   1327: 
1.281     albertel 1328: sub register_ssi {
                   1329:     my ($url,%form)=@_;
                   1330:     push (@Apache::lonxml::ssi_info,{'url'=>$url,'form'=>\%form});
                   1331:     return '';
                   1332: }
                   1333: 
                   1334: sub do_registered_ssi {
                   1335:     foreach my $info (@Apache::lonxml::ssi_info) {
                   1336: 	my %form=%{ $info->{'form'}};
                   1337: 	my $url=$info->{'url'};
                   1338: 	&Apache::lonnet::ssi($url,%form);
                   1339:     }
                   1340: }
1.448     albertel 1341: 
                   1342: sub add_script_result {
                   1343:     my ($display) = @_;
                   1344:     push(@script_var_displays, $display);
                   1345: }
                   1346: 
1.66      www      1347: #
                   1348: # Afterburner handles anchors, highlights and links
                   1349: #
                   1350: sub afterburn {
                   1351:     my $result=shift;
1.154     albertel 1352:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1353: 					    ['highlight','anchor','link']);
1.372     albertel 1354:     if ($env{'form.highlight'}) {
                   1355:        foreach (split(/\,/,$env{'form.highlight'})) {
1.66      www      1356:            my $anchorname=$_;
                   1357: 	   my $matchthis=$anchorname;
                   1358:            $matchthis=~s/\_+/\\s\+/g;
1.317     albertel 1359:            $result=~s/(\Q$matchthis\E)/\<font color=\"red\"\>$1\<\/font\>/gs;
1.142     albertel 1360:        }
1.66      www      1361:     }
1.372     albertel 1362:     if ($env{'form.link'}) {
                   1363:        foreach (split(/\,/,$env{'form.link'})) {
1.66      www      1364:            my ($anchorname,$linkurl)=split(/\>/,$_);
                   1365: 	   my $matchthis=$anchorname;
                   1366:            $matchthis=~s/\_+/\\s\+/g;
1.317     albertel 1367:            $result=~s/(\Q$matchthis\E)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
1.142     albertel 1368:        }
1.66      www      1369:     }
1.372     albertel 1370:     if ($env{'form.anchor'}) {
                   1371:         my $anchorname=$env{'form.anchor'};
1.66      www      1372: 	my $matchthis=$anchorname;
                   1373:         $matchthis=~s/\_+/\\s\+/g;
1.317     albertel 1374:         $result=~s/(\Q$matchthis\E)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
1.66      www      1375:         $result.=(<<"ENDSCRIPT");
1.226     albertel 1376: <script type="text/javascript">
1.66      www      1377:     document.location.hash='$anchorname';
                   1378: </script>
                   1379: ENDSCRIPT
                   1380:     }
                   1381:     return $result;
                   1382: }
                   1383: 
1.79      www      1384: sub storefile {
                   1385:     my ($file,$contents)=@_;
1.290     albertel 1386:     &Apache::lonnet::correct_line_ends(\$contents);
1.79      www      1387:     if (my $fh=Apache::File->new('>'.$file)) {
                   1388: 	print $fh $contents;
                   1389:         $fh->close();
1.271     www      1390:         return 1;
1.147     albertel 1391:     } else {
1.482     bisitz   1392: 	&warning(&mt('Unable to save file [_1]','<tt>'.$file.'</tt>'));
1.271     www      1393: 	return 0;
1.79      www      1394:     }
                   1395: }
                   1396: 
1.151     albertel 1397: sub createnewhtml {
1.321     www      1398:     my $title=&mt('Title of document goes here');
                   1399:     my $body=&mt('Body of document goes here');
                   1400:     my $filecontents=(<<SIMPLECONTENT);
1.78      www      1401: <html>
                   1402: <head>
1.321     www      1403: <title>$title</title>
1.78      www      1404: </head>
                   1405: <body bgcolor="#FFFFFF">
1.321     www      1406: $body
1.78      www      1407: </body>
                   1408: </html>
                   1409: SIMPLECONTENT
1.321     www      1410:     return $filecontents;
1.151     albertel 1411: }
                   1412: 
1.274     albertel 1413: sub createnewsty {
                   1414:   my $filecontents=(<<SIMPLECONTENT);
                   1415: <definetag name="">
                   1416:     <render>
                   1417:        <web></web>
                   1418:        <tex></tex>
                   1419:     </render>
                   1420: </definetag>
                   1421: SIMPLECONTENT
                   1422:   return $filecontents;
                   1423: }
                   1424: 
1.493     raeburn  1425: sub createnewjs {
                   1426:     my $filecontents=(<<SIMPLECONTENT);
                   1427: <script type="text/javascript" language="Javascript">
                   1428: 
                   1429: </script>
                   1430: SIMPLECONTENT
                   1431:     return $filecontents;
                   1432: }
                   1433: 
1.472     www      1434: sub verify_html {
                   1435:     my ($filecontents)=@_;
                   1436:     if ($filecontents!~/(?:\<|\&lt\;)(?:html|xml)[^\<]*(?:\>|\&gt\;)/is) {
                   1437:        return &mt('File does not have [_1] or [_2] starting tag','&lt;html&gt;','&lt;xml&gt;');
                   1438:     }
                   1439:     if ($filecontents!~/(?:\<|\&lt\;)\/(?:html|xml)(?:\>|\&gt\;)/is) {
                   1440:        return &mt('File does not have [_1] or [_2] ending tag','&lt;html&gt;','&lt;xml&gt;');
                   1441:     }
                   1442:     if ($filecontents!~/(?:\<|\&lt\;)(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
                   1443:        return &mt('File does not have [_1] or [_2] starting tag','&lt;body&gt;','&lt;frameset&gt;');
                   1444:     }
                   1445:     if ($filecontents!~/(?:\<|\&lt\;)\/(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
                   1446:        return &mt('File does not have [_1] or [_2] ending tag','&lt;body&gt;','&lt;frameset&gt;');
                   1447:     }
                   1448:     return '';
                   1449: }
1.147     albertel 1450: 
1.478     www      1451: sub renderingoptions {
                   1452:     my %langchoices=('' => '');
                   1453:     foreach (&Apache::loncommon::languageids()) {
                   1454:         if (&Apache::loncommon::supportedlanguagecode($_)) {
                   1455:             $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
                   1456:                        = &Apache::loncommon::plainlanguagedescription($_);
                   1457:         }
                   1458:     }
1.500     raeburn  1459:     my $output;
                   1460:     unless ($env{'form.forceedit'}) {
1.504     bisitz   1461:        $output .=
                   1462:            '<span class="LC_nobreak">'.
1.500     raeburn  1463:            &mt('Language:').' '.
1.504     bisitz   1464:            &Apache::loncommon::select_form(
                   1465:                $env{'form.languages'},
                   1466:                'languages',
1.510   ! raeburn  1467:                {&Apache::lonlocal::texthash(%langchoices)}).
1.504     bisitz   1468:            '</span>';
1.500     raeburn  1469:     }
1.504     bisitz   1470:     $output .=
                   1471:      ' <span class="LC_nobreak">'.
1.479     bisitz   1472:        &mt('Math Rendering:').' '.
1.504     bisitz   1473:        &Apache::loncommon::select_form(
                   1474:            $env{'form.texengine'},
                   1475:            'texengine',
1.510   ! raeburn  1476:            {&Apache::lonlocal::texthash
1.504     bisitz   1477:                (''        => '',
                   1478:                 'tth'     => 'tth (TeX to HTML)',
                   1479:                 'jsMath'  => 'jsMath',
1.510   ! raeburn  1480:                 'mimetex' => 'mimetex (Convert to Images)')}).
1.504     bisitz   1481:      '</span>';
1.500     raeburn  1482:     return $output;
1.478     www      1483: }
                   1484: 
1.151     albertel 1485: sub inserteditinfo {
1.470     albertel 1486:       my ($filecontents, $filetype, $filename)=@_;
1.314     albertel 1487:       $filecontents = &HTML::Entities::encode($filecontents,'<>&"');
1.274     albertel 1488:       my $xml_help = '';
1.321     www      1489:       my $initialize='';
1.452     albertel 1490:       my $textarea_id = 'filecont';
1.492     raeburn  1491:       my $dragmath_button;
1.452     albertel 1492:       my ($add_to_onload, $add_to_onresize);
1.456     albertel 1493:       $initialize=&Apache::lonhtmlcommon::spellheader();
                   1494:       if ($filetype eq 'html' 
                   1495: 	  && (!&Apache::lonhtmlcommon::htmlareablocked() &&
                   1496: 	      &Apache::lonhtmlcommon::htmlareabrowser())) {
1.463     albertel 1497: 	  $textarea_id .= '___Frame';
                   1498: 	  my $lang = &Apache::lonhtmlcommon::htmlarea_lang();
1.456     albertel 1499: 	  $initialize.=(<<FULLPAGE);
1.321     www      1500: <script type="text/javascript">
1.463     albertel 1501: lonca
1.321     www      1502:     function initDocument() {
1.463     albertel 1503:         var oFCKeditor = new FCKeditor('filecont');
                   1504: 	oFCKeditor.Config['CustomConfigurationsPath'] = '/fckeditor/loncapaconfig.js'  ;
                   1505: 	oFCKeditor.Config['FullPage'] = true
                   1506: 	oFCKeditor.Config['AutoDetectLanguage'] = false;
                   1507:         oFCKeditor.Config['DefaultLanguage'] = "$lang";
                   1508: 	oFCKeditor.ReplaceTextarea();
                   1509:     }
                   1510:     function check_if_dirty(editor) {
                   1511: 	if (editor.IsDirty()) {
                   1512: 	    unClean();
                   1513: 	}
                   1514:     }
                   1515:     function FCKeditor_OnComplete(editor) {
                   1516: 	editor.Events.AttachEvent("OnSelectionChange",check_if_dirty);
                   1517: 	resize_textarea('$textarea_id','LC_aftertextarea');
1.321     www      1518:     }
                   1519: </script>
                   1520: FULLPAGE
1.456     albertel 1521:       } else {
                   1522: 	  $initialize.=(<<FULLPAGE);
1.347     albertel 1523: <script type="text/javascript">
                   1524:     function initDocument() {
1.453     albertel 1525: 	resize_textarea('$textarea_id','LC_aftertextarea');
1.347     albertel 1526:     }
                   1527: </script>
                   1528: FULLPAGE
1.502     raeburn  1529:           if ($filetype eq 'html' || $filetype eq 'tex') {
1.492     raeburn  1530:               $initialize .= "\n".&Apache::lonhtmlcommon::dragmath_js('EditMathPopup');
                   1531:               $dragmath_button = &Apache::lonhtmlcommon::dragmath_button('filecont',1);
                   1532:           }
1.456     albertel 1533:       }
                   1534: 
                   1535:       $add_to_onload = 'initDocument();';
                   1536:       $add_to_onresize = "resize_textarea('$textarea_id','LC_aftertextarea');";
                   1537: 
                   1538:       if ($filetype eq 'html') {
1.321     www      1539: 	  $xml_help=&Apache::loncommon::helpLatexCheatsheet();
1.274     albertel 1540:       }
1.452     albertel 1541: 
1.254     albertel 1542:       my $titledisplay=&display_title();
1.501     raeburn  1543:       my $wysiwyglink;
1.426     banghart 1544:       my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit',
                   1545: 					 'vi' => 'Save and View',
1.427     banghart 1546: 					 'dv' => 'Discard Edits and View',
1.428     banghart 1547: 					 'un' => 'undo',
1.280     www      1548: 					 'ed' => 'Edit');
1.470     albertel 1549:       my $spelllink .=&Apache::lonhtmlcommon::spelllink('xmledit','filecont');
1.451     albertel 1550:       my $textarea_events = &Apache::edit::element_change_detection();
                   1551:       my $form_events     = &Apache::edit::form_change_detection();
1.491     raeburn  1552:       my $htmlerror;
                   1553:       if ($filetype eq 'html') {
                   1554:           $htmlerror=&verify_html($filecontents);
                   1555:           if ($htmlerror) {
                   1556:               $htmlerror='<span class="LC_error">'.$htmlerror.'</span>';
                   1557:           }
1.501     raeburn  1558:           if (&Apache::lonhtmlcommon::htmlareabrowser()) {
                   1559:               if (&Apache::lonhtmlcommon::htmlareablocked()) {
                   1560:                   $wysiwyglink = &Apache::lonhtmlcommon::enablelink($textarea_id);
                   1561:               } else {
                   1562:                   $wysiwyglink = &Apache::lonhtmlcommon::disablelink($textarea_id);
                   1563:               }
                   1564:           }
1.472     www      1565:       }
1.78      www      1566:       my $editfooter=(<<ENDFOOTER);
1.321     www      1567: $initialize
1.78      www      1568: <a name="editsection" />
1.451     albertel 1569: <form $form_events method="post" name="xmledit">
1.470     albertel 1570:   <div class="LC_edit_problem_editxml_header">
                   1571:     <table class="LC_edit_problem_header_title"><tr><td>
                   1572:         $filename
                   1573:       </td><td align="right">
                   1574:         $xml_help
                   1575:       </td></tr>
                   1576:     </table>
                   1577:     <div class="LC_edit_problem_discards">
                   1578:       <input type="submit" name="discardview" accesskey="d" value="$lt{'dv'}" />
                   1579:       <input type="submit" name="Undo" accesskey="u" value="$lt{'un'}" />
1.492     raeburn  1580:       $dragmath_button $spelllink $htmlerror
1.470     albertel 1581:     </div>
                   1582:     <div class="LC_edit_problem_saves">
                   1583:       <input type="submit" name="savethisfile" accesskey="s" value="$lt{'st'}" />
                   1584:       <input type="submit" name="viewmode" accesskey="v" value="$lt{'vi'}" />
                   1585:     </div>
                   1586:   </div>
                   1587:   <textarea $textarea_events style="width:100%" cols="80" rows="44" name="filecont" id="filecont">$filecontents</textarea>
                   1588:   <div id="LC_aftertextarea">
1.501     raeburn  1589:     $wysiwyglink
1.470     albertel 1590:     <br />
                   1591:     $titledisplay
                   1592:   </div>
1.78      www      1593: </form>
1.321     www      1594: </body>
1.78      www      1595: ENDFOOTER
1.452     albertel 1596:       return ($editfooter,$add_to_onload,$add_to_onresize);;
1.78      www      1597: }
                   1598: 
1.152     albertel 1599: sub get_target {
1.372     albertel 1600:   my $viewgrades=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
                   1601:   if ( $env{'request.state'} eq 'published') {
                   1602:     if ( defined($env{'form.grade_target'})
1.152     albertel 1603: 	 && ($viewgrades == 'F' )) {
1.372     albertel 1604:       return ($env{'form.grade_target'});
                   1605:     } elsif (defined($env{'form.grade_target'})) {
                   1606:       if (($env{'form.grade_target'} eq 'web') ||
                   1607: 	  ($env{'form.grade_target'} eq 'tex') ) {
                   1608: 	return $env{'form.grade_target'}
1.153     albertel 1609:       } else {
                   1610: 	return 'web';
                   1611:       }
1.152     albertel 1612:     } else {
                   1613:       return 'web';
                   1614:     }
1.372     albertel 1615:   } elsif ($env{'request.state'} eq 'construct') {
                   1616:     if ( defined($env{'form.grade_target'})) {
                   1617:       return ($env{'form.grade_target'});
1.152     albertel 1618:     } else {
                   1619:       return 'web';
                   1620:     }
                   1621:   } else {
                   1622:     return 'web';
                   1623:   }
                   1624: }
                   1625: 
1.24      sakharuk 1626: sub handler {
1.255     sakharuk 1627:     my $request=shift;
1.493     raeburn  1628: 
1.255     sakharuk 1629:     my $target=&get_target();
1.372     albertel 1630:     $Apache::lonxml::debug=$env{'user.debug'};
1.255     sakharuk 1631:     
1.364     albertel 1632:     &Apache::loncommon::content_type($request,'text/html');
1.255     sakharuk 1633:     &Apache::loncommon::no_cache($request);
1.372     albertel 1634:     if ($env{'request.state'} eq 'published') {
1.363     albertel 1635: 	$request->set_last_modified(&Apache::lonnet::metadata($request->uri,
                   1636: 							      'lastrevisiondate'));
                   1637:     }
1.499     raeburn  1638:     # Embedded Flash movies from Camtasia served from https will not display in IE
                   1639:     #   if XML config file has expired from cache.    
                   1640:     if ($ENV{'SERVER_PORT'} == 443) {
                   1641:         if ($request->uri =~ /\.xml$/) {
                   1642:             my ($httpbrowser,$clientbrowser) =
                   1643:                 &Apache::loncommon::decode_user_agent($request);
                   1644:             if ($clientbrowser =~ /^explorer$/i) {
                   1645:                 delete $request->headers_out->{'Cache-control'};
                   1646:                 delete $request->headers_out->{'Pragma'};
                   1647:                 my $expiration = time + 60;
                   1648:                 my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime($expiration));
                   1649:                 $request->headers_out->set("Expires" => $date);
                   1650:             }
                   1651:         }
                   1652:     }
1.255     sakharuk 1653:     $request->send_http_header;
                   1654:     
                   1655:     return OK if $request->header_only;
1.68      www      1656: 
                   1657: 
1.255     sakharuk 1658:     my $file=&Apache::lonnet::filelocation("",$request->uri);
1.502     raeburn  1659:     my ($filetype,$breadcrumbtext);
                   1660:     if ($file =~ /\.(sty|css|js|txt|tex)$/) {
1.493     raeburn  1661: 	$filetype=$1;
1.274     albertel 1662:     } else {
                   1663: 	$filetype='html';
                   1664:     }
1.502     raeburn  1665:     if ($filetype eq 'sty') {
                   1666:         $breadcrumbtext = 'Style File Editor';
                   1667:     } elsif ($filetype eq 'js') {
                   1668:         $breadcrumbtext = 'Javascript Editor';
                   1669:     } elsif ($filetype eq 'css') {
                   1670:         $breadcrumbtext = 'CSS Editor';
                   1671:     } elsif ($filetype eq 'txt') {
                   1672:         $breadcrumbtext = 'Text Editor';
                   1673:     } elsif ($filetype eq 'tex') {
                   1674:         $breadcrumbtext = 'TeX Editor';
                   1675:     } else {
                   1676:         $breadcrumbtext = 'HTML Editor';
                   1677:     }
1.493     raeburn  1678: 
1.78      www      1679: #
                   1680: # Edit action? Save file.
                   1681: #
1.428     banghart 1682:     if (!($env{'request.state'} eq 'published')) {
                   1683: 	if ($env{'form.savethisfile'} || $env{'form.viewmode'} || $env{'form.Undo'}) {
1.429     albertel 1684: 	    my $html_file=&Apache::lonnet::getfile($file);
                   1685: 	    my $error = &Apache::lonhomework::handle_save_or_undo($request, \$html_file, \$env{'form.filecont'});
1.472     www      1686:             if ($env{'form.savethisfile'}) {
                   1687:                 $env{'form.editmode'}='Edit'; #force edit mode
                   1688:             }
1.255     sakharuk 1689: 	}
                   1690:     }
                   1691:     my %mystyle;
                   1692:     my $result = '';
                   1693:     my $filecontents=&Apache::lonnet::getfile($file);
                   1694:     if ($filecontents eq -1) {
1.402     albertel 1695: 	my $start_page=&Apache::loncommon::start_page('File Error');
1.412     albertel 1696: 	my $end_page=&Apache::loncommon::end_page();
1.495     bisitz   1697:         my $errormsg='<p class="LC_error">'
                   1698:                     .&mt('File not found: [_1]'
                   1699:                         ,'<span class="LC_filename">'.$file.'</span>')
                   1700:                     .'</p>';
1.255     sakharuk 1701: 	$result=(<<ENDNOTFOUND);
1.402     albertel 1702: $start_page
1.495     bisitz   1703: $errormsg
1.402     albertel 1704: $end_page
1.78      www      1705: ENDNOTFOUND
1.343     albertel 1706:         $filecontents='';
1.372     albertel 1707: 	if ($env{'request.state'} ne 'published') {
1.274     albertel 1708: 	    if ($filetype eq 'sty') {
                   1709: 		$filecontents=&createnewsty();
1.493     raeburn  1710:             } elsif ($filetype eq 'js') {
                   1711:                 $filecontents=&createnewjs();
1.502     raeburn  1712:             } elsif ($filetype ne 'css' && $filetype ne 'txt' && $filetype ne 'tex') {
1.274     albertel 1713: 		$filecontents=&createnewhtml();
                   1714: 	    }
1.372     albertel 1715: 	    $env{'form.editmode'}='Edit'; #force edit mode
1.255     sakharuk 1716: 	}
                   1717:     } else {
1.372     albertel 1718: 	unless ($env{'request.state'} eq 'published') {
1.343     albertel 1719: 	    if ($filecontents=~/BEGIN LON-CAPA Internal/) {
1.381     www      1720: 		&Apache::lonxml::error(&mt('This file appears to be a rendering of a LON-CAPA resource. If this is correct, this resource will act very oddly and incorrectly.'));
1.343     albertel 1721: 	    }
1.264     www      1722: #
                   1723: # we are in construction space, see if edit mode forced
1.385     albertel 1724:             &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1725: 						    ['editmode']);
1.255     sakharuk 1726: 	}
1.427     banghart 1727: 	if (!$env{'form.editmode'} || $env{'form.viewmode'} || $env{'form.discardview'}) {
1.493     raeburn  1728:             if ($filetype eq 'html' || $filetype eq 'sty') {
                   1729: 	        &Apache::structuretags::reset_problem_globals();
                   1730: 	        $result = &Apache::lonxml::xmlparse($request,$target,
                   1731:                                                     $filecontents,'',%mystyle);
1.455     albertel 1732: 	    # .html files may contain <problem> or <Task> need to clean
                   1733: 	    # up if it did
1.493     raeburn  1734: 	        &Apache::structuretags::reset_problem_globals();
                   1735: 	        &Apache::lonhomework::finished_parsing();
1.502     raeburn  1736:             } elsif ($filetype eq 'tex') {
1.503     raeburn  1737:                 $result = &Apache::lontexconvert::converted(\$filecontents,
                   1738:                               $env{'form.texengine'});
                   1739:                 if ($env{'form.return_only_error_and_warning_counts'}) {
                   1740:                     if (&verify_html('<html><body>'.$result.'</body></html>')) {
                   1741:                         $errorcount++;
                   1742:                     }
                   1743:                     $result = "$errorcount:$warningcount";
                   1744:                 }
1.493     raeburn  1745:             } else {
                   1746:                 $result = $filecontents;
                   1747:             }
1.385     albertel 1748: 	    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   1749: 						    ['rawmode']);
1.395     albertel 1750: 	    if ($env{'form.rawmode'}) { $result = $filecontents; }
1.503     raeburn  1751:             if (($filetype ne 'html') && 
                   1752:                 (!$env{'form.return_only_error_and_warning_counts'})) {
1.502     raeburn  1753:                 my $nochgview = 1;
1.495     bisitz   1754:                 my $controls = '';
                   1755:                     if ($env{'request.state'} eq 'construct') {
                   1756:                         $controls = &Apache::loncommon::head_subbox(
                   1757:                                         &Apache::loncommon::CSTR_pageheader()
                   1758:                                        .&Apache::londefdef::edit_controls($nochgview));
                   1759:                     }
1.502     raeburn  1760:                 if ($filetype ne 'sty' && $filetype ne 'tex') {
1.493     raeburn  1761:                     $result =~ s/</&lt;/g;
                   1762:                     $result =~ s/>/&gt;/g;
                   1763:                     $result = '<table class="LC_sty_begin">'.
                   1764:                               '<tr><td><b><pre>'.$result.
                   1765:                               '</pre></b></td></tr></table>';
                   1766:                 }
1.506     droeschl 1767:                 my $brcrum;
                   1768:                 if ($env{'request.state'} eq 'construct') {
                   1769:                     $brcrum = [{'href' => &Apache::loncommon::authorspace(),
                   1770:                                 'text' => 'Construction Space'},
                   1771:                                {'href' => '',
                   1772:                                 'text' => $breadcrumbtext}];
1.493     raeburn  1773:                 } else {
1.506     droeschl 1774:                     $brcrum = ''; # FIXME: Where are we?
1.493     raeburn  1775:                 }
1.506     droeschl 1776:                 my %options = ('bread_crumbs' => $brcrum,
                   1777:                                'bgcolor'      => '#FFFFFF');
                   1778:                 $result =
                   1779:                     &Apache::loncommon::start_page(undef,undef,\%options)
                   1780:                    .$controls
                   1781:                    .$result
                   1782:                    .&Apache::loncommon::end_page();
1.493     raeburn  1783:             }
1.495     bisitz   1784:         }
1.147     albertel 1785:     }
1.456     albertel 1786: 
1.78      www      1787: #
                   1788: # Edit action? Insert editing commands
                   1789: #
1.372     albertel 1790:     unless ($env{'request.state'} eq 'published') {
1.427     banghart 1791: 	if ($env{'form.editmode'} && (!($env{'form.viewmode'})) && (!($env{'form.discardview'})))
1.450     albertel 1792: 	{
1.470     albertel 1793: 	    my $displayfile=$request->uri;
                   1794: 	    $displayfile=~s/^\/[^\/]*//;
                   1795: 
1.452     albertel 1796: 	    my ($edit_info, $add_to_onload, $add_to_onresize)=
1.470     albertel 1797: 		&inserteditinfo($filecontents,$filetype,$displayfile);
1.450     albertel 1798: 
                   1799: 	    my %options = 
                   1800: 		('add_entries' =>
1.495     bisitz   1801:                    {'onresize'     => $add_to_onresize,
                   1802:                     'onload'       => $add_to_onload,   });
1.500     raeburn  1803:             my $header;
                   1804:             if ($env{'request.state'} eq 'construct') {
                   1805:                 $options{'bread_crumbs'} = [{
                   1806:                             'href' => &Apache::loncommon::authorspace(),
                   1807:                             'text' => 'Construction Space'},
                   1808:                            {'href' => '',
1.502     raeburn  1809:                             'text' => $breadcrumbtext}];
1.500     raeburn  1810:                 $header = &Apache::loncommon::head_subbox(
                   1811:                               &Apache::loncommon::CSTR_pageheader());
                   1812:             }
1.452     albertel 1813: 	    my $js =
                   1814: 		&Apache::edit::js_change_detection().
                   1815: 		&Apache::loncommon::resize_textarea_js();
1.451     albertel 1816: 	    my $start_page = &Apache::loncommon::start_page(undef,$js,
1.402     albertel 1817: 							    \%options);
1.495     bisitz   1818:             $result = $start_page
1.500     raeburn  1819:                      .$header
1.495     bisitz   1820:                      .&Apache::lonxml::message_location()
                   1821:                      .$edit_info
                   1822:                      .&Apache::loncommon::end_page();
1.493     raeburn  1823:         }
1.147     albertel 1824:     }
1.402     albertel 1825:     if ($filetype eq 'html') { &writeallows($request->uri); }
1.501     raeburn  1826: 
1.309     albertel 1827:     &Apache::lonxml::add_messages(\$result);
1.255     sakharuk 1828:     $request->print($result);
                   1829:     
                   1830:     return OK;
1.253     albertel 1831: }
                   1832: 
                   1833: sub display_title {
                   1834:     my $result;
1.372     albertel 1835:     if ($env{'request.state'} eq 'construct') {
1.253     albertel 1836: 	my $title=&Apache::lonnet::gettitle();
                   1837: 	if (!defined($title) || $title eq '') {
1.372     albertel 1838: 	    $title = $env{'request.filename'};
1.253     albertel 1839: 	    $title = substr($title, rindex($title, '/') + 1);
                   1840: 	}
1.476     bisitz   1841:         $result = "<script type='text/javascript'>top.document.title = '$title - LON-CAPA "
                   1842:                   .&mt('Construction Space')."';</script>";
1.253     albertel 1843:     }
                   1844:     return $result;
1.24      sakharuk 1845: }
1.147     albertel 1846: 
1.22      albertel 1847: sub debug {
1.298     albertel 1848:     if ($Apache::lonxml::debug eq "1") {
                   1849: 	$|=1;
1.300     albertel 1850: 	my $request=$Apache::lonxml::request;
1.388     albertel 1851: 	if (!$request) {
                   1852: 	    eval { $request=Apache->request; };
                   1853: 	}
                   1854: 	if (!$request) {
                   1855: 	    eval { $request=Apache2::RequestUtil->request; };
                   1856: 	}
1.314     albertel 1857: 	$request->print('<font size="-2"><pre>DEBUG:'.&HTML::Entities::encode($_[0],'<>&"')."</pre></font>\n");
1.346     albertel 1858: 	#&Apache::lonnet::logthis($_[0]);
1.298     albertel 1859:     }
1.22      albertel 1860: }
1.49      albertel 1861: 
1.348     albertel 1862: sub show_error_warn_msg {
1.372     albertel 1863:     if ($env{'request.filename'} eq '/home/httpd/html/res/lib/templates/simpleproblem.problem' &&
                   1864: 	&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.351     albertel 1865: 	return 1;
                   1866:     }
1.348     albertel 1867:     return (($Apache::lonxml::debug eq 1) ||
1.372     albertel 1868: 	    ($env{'request.state'} eq 'construct') ||
1.348     albertel 1869: 	    ($Apache::lonhomework::browse eq 'F'
                   1870: 	     &&
1.372     albertel 1871: 	     $env{'form.show_errors'} eq 'on'));
1.348     albertel 1872: }
                   1873: 
1.22      albertel 1874: sub error {
1.454     albertel 1875:     my @errors = @_;
                   1876: 
1.336     albertel 1877:     $errorcount++;
1.454     albertel 1878: 
1.490     www      1879:     $Apache::lonxml::internal_error=1;
                   1880: 
1.454     albertel 1881:     if (defined($Apache::inputtags::part)) {
                   1882: 	if ( @Apache::inputtags::response ) {
                   1883: 	    push(@errors,
                   1884: 		 &mt("This error occurred while processing response [_1] in part [_2]",
                   1885: 		     $Apache::inputtags::response[-1],
                   1886: 		     $Apache::inputtags::part));
                   1887: 	} else {
                   1888: 	    push(@errors,
                   1889: 		 &mt("This error occurred while processing part [_1]",
                   1890: 		     $Apache::inputtags::part));
                   1891: 	}
                   1892:     }
                   1893: 
1.348     albertel 1894:     if ( &show_error_warn_msg() ) {
1.336     albertel 1895: 	# If printing in construction space, put the error inside <pre></pre>
                   1896: 	push(@Apache::lonxml::error_messages,
1.484     bisitz   1897: 	     $Apache::lonxml::warnings_error_header
                   1898:              .'<div class="LC_error">'
                   1899:              .'<b>'.&mt('ERROR:').' </b>'.join("<br />\n",@errors)
                   1900:              ."</div>\n");
1.336     albertel 1901: 	$Apache::lonxml::warnings_error_header='';
                   1902:     } else {
                   1903: 	my $errormsg;
                   1904: 	my ($symb)=&Apache::lonnet::symbread();
                   1905: 	if ( !$symb ) {
                   1906: 	    #public or browsers
1.486     bisitz   1907: 	    $errormsg=&mt("An error occurred while processing this resource. The author has been notified.");
1.403     albertel 1908: 	}
1.413     albertel 1909: 	my $host=$Apache::lonnet::perlvar{'lonHostID'};
1.476     bisitz   1910: 	push(@errors,
                   1911:         &mt("The error occurred on host [_1]",
                   1912:              "<tt>$host</tt>"));
1.454     albertel 1913: 
                   1914: 	my $msg = join('<br />', @errors);
                   1915: 
1.336     albertel 1916: 	#notify author
1.403     albertel 1917: 	&Apache::lonmsg::author_res_msg($env{'request.filename'},$msg);
1.336     albertel 1918: 	#notify course
1.372     albertel 1919: 	if ( $symb && $env{'request.course.id'} ) {
1.380     www      1920: 	    my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   1921: 	    my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.440     albertel 1922: 	    my (undef,%users)=&Apache::lonmsg::decide_receiver(undef,0,1,1,1);
1.372     albertel 1923: 	    my $declutter=&Apache::lonnet::declutter($env{'request.filename'});
1.435     raeburn  1924:             my $baseurl = &Apache::lonnet::clutter($declutter);
1.336     albertel 1925: 	    my @userlist;
                   1926: 	    foreach (keys %users) {
                   1927: 		my ($user,$domain) = split(/:/, $_);
                   1928: 		push(@userlist,"$user\@$domain");
1.380     www      1929: 		my $key=$declutter.'_'.$user.'_'.$domain;
                   1930: 		my %lastnotified=&Apache::lonnet::get('nohist_xmlerrornotifications',
                   1931: 						      [$key],
                   1932: 						      $cdom,$cnum);
                   1933: 		my $now=time;
                   1934: 		if ($now-$lastnotified{$key}>86400) {
1.434     raeburn  1935:                     my $title = &Apache::lonnet::gettitle($symb);
                   1936:                     my $sentmessage;
1.380     www      1937: 		    &Apache::lonmsg::user_normal_msg($user,$domain,
1.435     raeburn  1938: 		        "Error [$title]",$msg,'',$baseurl,'','',
1.434     raeburn  1939:                         \$sentmessage,$symb,$title,1);
1.380     www      1940: 		    &Apache::lonnet::put('nohist_xmlerrornotifications',
                   1941: 					 {$key => $now},
                   1942: 					 $cdom,$cnum);		
                   1943: 		}
1.336     albertel 1944: 	    }
1.372     albertel 1945: 	    if ($env{'request.role.adv'}) {
1.486     bisitz   1946: 		$errormsg=&mt("An error occurred while processing this resource. The course personnel ([_1]) and the author have been notified.",join(', ',@userlist));
1.336     albertel 1947: 	    } else {
1.486     bisitz   1948: 		$errormsg=&mt("An error occurred while processing this resource. The instructor has been notified.");
1.336     albertel 1949: 	    }
                   1950: 	}
                   1951: 	push(@Apache::lonxml::error_messages,"<b>$errormsg</b> <br />");
1.52      albertel 1952:     }
1.22      albertel 1953: }
1.49      albertel 1954: 
1.22      albertel 1955: sub warning {
1.295     albertel 1956:     $warningcount++;
1.261     albertel 1957:   
1.372     albertel 1958:     if ($env{'form.grade_target'} ne 'tex') {
1.348     albertel 1959: 	if ( &show_error_warn_msg() ) {
1.309     albertel 1960: 	    push(@Apache::lonxml::warning_messages,
1.484     bisitz   1961: 		 $Apache::lonxml::warnings_error_header
                   1962:                 .'<div class="LC_warning">'
                   1963:                 .&mt('[_1]W[_2]ARNING','<b>','</b>')."<b>:</b> ".join('<br />',@_)
                   1964:                 ."</div>\n"
1.482     bisitz   1965:                 );
1.295     albertel 1966: 	    $Apache::lonxml::warnings_error_header='';
                   1967: 	}
                   1968:     }
1.309     albertel 1969: }
                   1970: 
                   1971: sub info {
1.372     albertel 1972:     if ($env{'form.grade_target'} ne 'tex' 
                   1973: 	&& $env{'request.state'} eq 'construct') {
1.309     albertel 1974: 	push(@Apache::lonxml::info_messages,join('<br />',@_)."<br />\n");
                   1975:     }
                   1976: }
                   1977: 
                   1978: sub message_location {
                   1979:     return '__LONCAPA_INTERNAL_MESSAGE_LOCATION__';
                   1980: }
                   1981: 
                   1982: sub add_messages {
                   1983:     my ($msg)=@_;
                   1984:     my $result=join(' ',
                   1985: 		    @Apache::lonxml::info_messages,
                   1986: 		    @Apache::lonxml::error_messages,
                   1987: 		    @Apache::lonxml::warning_messages);
                   1988:     undef(@Apache::lonxml::info_messages);
                   1989:     undef(@Apache::lonxml::error_messages);
                   1990:     undef(@Apache::lonxml::warning_messages);
                   1991:     $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__/$result/;
                   1992:     $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__//g;
1.83      albertel 1993: }
                   1994: 
                   1995: sub get_param {
1.213     albertel 1996:     my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
                   1997:     if ( ! $context ) { $context = -1; }
                   1998:     my $args ='';
                   1999:     if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1.297     sakharuk 2000:     if ( ! $Apache::lonxml::usestyle ) {
                   2001: 	$args=$Apache::lonxml::style_values.$args;
                   2002:     }
1.213     albertel 2003:     if ( ! $args ) { return undef; }
                   2004:     if ( $case_insensitive ) {
1.417     albertel 2005: 	if ($args =~ s/(my (?:.*))(\$\Q$param\E[,\)])/$1.lc($2)/ei) {
1.213     albertel 2006: 	    return &Apache::run::run("{$args;".'return $'.$param.'}',
                   2007:                                      $safeeval); #'
                   2008: 	} else {
                   2009: 	    return undef;
                   2010: 	}
                   2011:     } else {
1.417     albertel 2012: 	if ( $args =~ /my .*\$\Q$param\E[,\)]/ ) {
1.213     albertel 2013: 	    return &Apache::run::run("{$args;".'return $'.$param.'}',
                   2014:                                      $safeeval); #'
                   2015: 	} else {
                   2016: 	    return undef;
                   2017: 	}
                   2018:     }
1.22      albertel 2019: }
                   2020: 
1.132     albertel 2021: sub get_param_var {
1.213     albertel 2022:   my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1.132     albertel 2023:   if ( ! $context ) { $context = -1; }
                   2024:   my $args ='';
                   2025:   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1.297     sakharuk 2026:   if ( ! $Apache::lonxml::usestyle ) {
                   2027:       $args=$Apache::lonxml::style_values.$args;
                   2028:   }
1.230     albertel 2029:   &Apache::lonxml::debug("Args are $args param is $param");
1.213     albertel 2030:   if ($case_insensitive) {
1.419     albertel 2031:       if (! ($args=~s/(my (?:.*))(\$\Q$param\E[,\)])/$1.lc($2)/ei)) {
1.213     albertel 2032: 	  return undef;
                   2033:       }
1.419     albertel 2034:   } elsif ( $args !~ /my .*\$\Q$param\E[,\)]/ ) { return undef; }
1.132     albertel 2035:   my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1.230     albertel 2036:   &Apache::lonxml::debug("first run is $value");
1.341     albertel 2037:   if ($value =~ /^[\$\@\%][a-zA-Z_]\w*$/) {
1.230     albertel 2038:       &Apache::lonxml::debug("doing second");
                   2039:       my @result=&Apache::run::run("return $value",$safeeval,1);
                   2040:       if (!defined($result[0])) {
                   2041: 	  return $value
                   2042:       } else {
                   2043: 	  if (wantarray) { return @result; } else { return $result[0]; }
                   2044:       }
1.132     albertel 2045:   } else {
                   2046:     return $value;
                   2047:   }
                   2048: }
                   2049: 
1.438     albertel 2050: sub register_insert_xml {
                   2051:     my $parser = HTML::LCParser->new($Apache::lonnet::perlvar{'lonTabDir'}
                   2052: 				     .'/insertlist.xml');
                   2053:     my ($tagnum,$in_help)=(0,0);
1.442     albertel 2054:     my @alltags;
1.438     albertel 2055:     my $tag;
                   2056:     while (my $token = $parser->get_token()) {
                   2057: 	if ($token->[0] eq 'S') {
                   2058: 	    my $key;
                   2059: 	    if      ($token->[1] eq 'tag') {
                   2060: 		$tag = $token->[2]{'name'};
                   2061: 		$insertlist{"$tagnum.tag"} = $tag;
                   2062: 		$insertlist{"$tag.num"}   = $tagnum;
1.442     albertel 2063: 		push(@alltags,$tag);
1.438     albertel 2064: 	    } elsif ($in_help && $token->[1] eq 'file') {
                   2065: 		$key = $tag.'.helpfile';
                   2066: 	    } elsif ($in_help && $token->[1] eq 'description') {
                   2067: 		$key = $tag.'.helpdesc';
                   2068: 	    } elsif ($token->[1] eq 'description' ||
                   2069: 		     $token->[1] eq 'color'       ||
                   2070: 		     $token->[1] eq 'show'          ) {
                   2071: 		$key = $tag.'.'.$token->[1];
                   2072: 	    } elsif ($token->[1] eq 'insert_sub') {
                   2073: 		$key = $tag.'.function';
                   2074: 	    } elsif ($token->[1] eq 'help') {
                   2075: 		$in_help=1;
                   2076: 	    } elsif ($token->[1] eq 'allow') {
1.442     albertel 2077: 		$key = $tag.'.allow';
1.438     albertel 2078: 	    }
                   2079: 	    if (defined($key)) {
                   2080: 		$insertlist{$key} = $parser->get_text();
                   2081: 		$insertlist{$key} =~ s/(^\s*|\s*$ )//gx;
                   2082: 	    }
                   2083: 	} elsif ($token->[0] eq 'E') {
                   2084: 	    if      ($token->[1] eq 'tag') {
                   2085: 		undef($tag);
                   2086: 		$tagnum++;
                   2087: 	    } elsif ($token->[1] eq 'help') {
                   2088: 		undef($in_help);
                   2089: 	    }
                   2090: 	}
                   2091:     }
1.442     albertel 2092:     
                   2093:     # parse the allows and ignore tags set to <show>no</show>
                   2094:     foreach my $tag (@alltags) {	
1.445     albertel 2095:         next if (!exists($insertlist{"$tag.allow"}));
1.442     albertel 2096: 	my $allow =  $insertlist{"$tag.allow"};
                   2097:        	foreach my $element (split(',',$allow)) {
                   2098: 	    $element =~ s/(^\s*|\s*$ )//gx;
1.446     albertel 2099: 	    if (!exists($insertlist{"$element.show"})
                   2100:                 || $insertlist{"$element.show"} ne 'no') {
1.442     albertel 2101: 		push(@{ $insertlist{$tag.'.which'} },$element);
                   2102: 	    }
                   2103: 	}
                   2104:     }
1.438     albertel 2105: }
                   2106: 
                   2107: sub register_insert {
                   2108:     return &register_insert_xml(@_);
                   2109: #    &dump_insertlist('2');
                   2110: }
                   2111: 
                   2112: sub dump_insertlist {
                   2113:     my ($ext) = @_;
                   2114:     open(XML,">/tmp/insertlist.xml.$ext");
                   2115:     print XML ("<insertlist>");
                   2116:     my $i=0;
                   2117: 
                   2118:     while (exists($insertlist{"$i.tag"})) {
                   2119: 	my $tag = $insertlist{"$i.tag"};
                   2120: 	print XML ("
                   2121: \t<tag name=\"$tag\">");
                   2122: 	if (defined($insertlist{"$tag.description"})) {
                   2123: 	    print XML ("
                   2124: \t\t<description>".$insertlist{"$tag.description"}."</description>");
                   2125: 	}
                   2126: 	if (defined($insertlist{"$tag.color"})) {
                   2127: 	    print XML ("
                   2128: \t\t<color>".$insertlist{"$tag.color"}."</color>");
                   2129: 	}
                   2130: 	if (defined($insertlist{"$tag.function"})) {
                   2131: 	    print XML ("
                   2132: \t\t<insert_sub>".$insertlist{"$tag.function"}."</insert_sub>");
                   2133: 	}
                   2134: 	if (defined($insertlist{"$tag.show"})
                   2135: 	    && $insertlist{"$tag.show"} ne 'yes') {
                   2136: 	    print XML ("
                   2137: \t\t<show>".$insertlist{"$tag.show"}."</show>");
                   2138: 	}
                   2139: 	if (defined($insertlist{"$tag.helpfile"})) {
                   2140: 	    print XML ("
                   2141: \t\t<help>
                   2142: \t\t\t<file>".$insertlist{"$tag.helpfile"}."</file>");
                   2143: 	    if ($insertlist{"$tag.helpdesc"} ne '') {
                   2144: 		print XML ("
                   2145: \t\t\t<description>".$insertlist{"$tag.helpdesc"}."</description>");
                   2146: 	    }
                   2147: 	    print XML ("
                   2148: \t\t</help>");
                   2149: 	}
                   2150: 	if (defined($insertlist{"$tag.which"})) {
                   2151: 	    print XML ("
                   2152: \t\t<allow>".join(',',sort(@{ $insertlist{"$tag.which"} }))."</allow>");
                   2153: 	}
                   2154: 	print XML ("
                   2155: \t</tag>");
                   2156: 	$i++;
                   2157:     }
                   2158:     print XML ("\n</insertlist>\n");
                   2159:     close(XML);
                   2160: }
                   2161: 
1.98      albertel 2162: sub description {
1.437     albertel 2163:     my ($token)=@_;
                   2164:     my $tag = &get_tag($token);
                   2165:     return $insertlist{$tag.'.description'};
1.268     bowersj2 2166: }
                   2167: 
                   2168: # Returns a list containing the help file, and the description
                   2169: sub helpinfo {
1.437     albertel 2170:     my ($token)=@_;
                   2171:     my $tag = &get_tag($token);
                   2172:     return ($insertlist{$tag.'.helpfile'}, $insertlist{$tag.'.helpdesc'});
                   2173: }
                   2174: 
                   2175: sub get_tag {
                   2176:     my ($token)=@_;
                   2177:     my $tagnum;
                   2178:     my $tag=$token->[1];
                   2179:     foreach my $namespace (reverse(@Apache::lonxml::namespace)) {
                   2180: 	my $testtag = $namespace.'::'.$tag;
                   2181: 	$tagnum = $insertlist{"$testtag.num"};
                   2182: 	last if (defined($tagnum));
                   2183:     }
                   2184:     if (!defined($tagnum)) {
                   2185: 	$tagnum = $Apache::lonxml::insertlist{"$tag.num"};
                   2186:     }
                   2187:     return $insertlist{"$tagnum.tag"};
1.98      albertel 2188: }
1.123     albertel 2189: 
1.485     onken    2190: ############################################################
                   2191: #                                           PDF-FORM-METHODS
                   2192: 
                   2193: =pod
                   2194: 
1.508     onken    2195: =item &print_pdf_radiobutton(fieldname, value)
1.485     onken    2196: 
1.508     onken    2197: Returns a latexline to generate a PDF-Form-Radiobutton.
                   2198: Note: Radiobuttons with equal names are automaticly grouped 
                   2199:       in a selection-group.
1.485     onken    2200: 
1.508     onken    2201: $fieldname: PDF internalname of the radiobutton(group)
                   2202: $value:     Value of radiobutton
1.485     onken    2203: 
                   2204: =cut
                   2205: sub print_pdf_radiobutton {
1.508     onken    2206:     my ($fieldname, $value) = @_;
                   2207:     return '\radioButton[\symbolchoice{circle}]{'
                   2208:            .$fieldname.'}{10bp}{10bp}{'.$value.'}';
1.485     onken    2209: }
                   2210: 
                   2211: 
                   2212: =pod
                   2213: 
                   2214: =item &print_pdf_start_combobox(fieldname)
                   2215: 
                   2216: Starts a latexline to generate a PDF-Form-Combobox with text.
                   2217: 
                   2218: $fieldname: PDF internal name of the Combobox
                   2219: 
                   2220: =cut
                   2221: sub print_pdf_start_combobox {
                   2222:     my $result;
                   2223:     my ($fieldName) = @_;
                   2224:     $result .= '\begin{tabularx}{\textwidth}{p{2.5cm}X}'."\n";
                   2225:     $result .= '\comboBox[]{'.$fieldName.'}{2.3cm}{14bp}{'; # 
                   2226: 
                   2227:     return $result;
                   2228: }
                   2229: 
                   2230: 
                   2231: =pod
                   2232: 
                   2233: =item &print_pdf_add_combobox_option(options)
                   2234: 
                   2235: Generates a latexline to add Options to a PDF-Form-ComboBox.
                   2236: 
                   2237: $option: PDF internal name of the Combobox-Option
                   2238: 
                   2239: =cut
                   2240: sub print_pdf_add_combobox_option {
                   2241: 
                   2242:     my $result;
                   2243:     my ($option) = @_;  
                   2244: 
                   2245:     $result .= '('.$option.')';
                   2246:     
                   2247:     return $result;
                   2248: }
                   2249: 
                   2250: 
                   2251: =pod
                   2252: 
                   2253: =item &print_pdf_end_combobox(text) {
                   2254: 
                   2255: Returns latexcode to end a PDF-Form-Combobox with text.
                   2256: 
                   2257: =cut
                   2258: sub print_pdf_end_combobox {
                   2259:     my $result;
                   2260:     my ($text) = @_;
                   2261: 
                   2262:     $result .= '}&'.$text."\\\\\n";
                   2263:     $result .= '\end{tabularx}' . "\n";
                   2264:     $result .= '\hspace{2mm}' . "\n";
                   2265:     return $result;
                   2266: }
                   2267: 
                   2268: 
                   2269: =pod
                   2270: 
                   2271: =item &print_pdf_hiddenField(fieldname, user, domain)
                   2272: 
                   2273: Returns a latexline to generate a PDF-Form-hiddenField with userdata.
                   2274: 
                   2275: $fieldname label for hiddentextfield
                   2276: $user:    name of user
                   2277: $domain:  domain of user
                   2278: 
                   2279: =cut
                   2280: sub print_pdf_hiddenfield {
                   2281:     my $result;
                   2282:     my ($fieldname, $user, $domain) = @_;
                   2283: 
                   2284:     $result .= '\textField [\F{\FHidden}\F{-\FPrint}\V{'.$domain.'&'.$user.'}]{'.$fieldname.'}{0in}{0in}'."\n";
                   2285: 
                   2286:     return $result;
                   2287: }
                   2288: 
1.1       sakharuk 2289: 1;
                   2290: __END__
1.68      www      2291: 

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