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