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