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