1: # The LearningOnline Network with CAPA
2: # XML Parser Module
3: #
4: # $Id: lonxml.pm,v 1.387 2005/11/10 21:28:21 albertel Exp $
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: #
39:
40:
41: package Apache::lonxml;
42: use vars
43: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $errorcount $warningcount @htmlareafields);
44: use strict;
45: use HTML::LCParser();
46: use HTML::TreeBuilder();
47: use HTML::Entities();
48: use Safe();
49: use Safe::Hole();
50: use Math::Cephes();
51: use Math::Random();
52: use Opcode();
53: use POSIX qw(strftime);
54: use Time::HiRes qw( gettimeofday tv_interval );
55:
56: sub register {
57: my ($space,@taglist) = @_;
58: foreach my $temptag (@taglist) {
59: push(@{ $Apache::lonxml::alltags{$temptag} },$space);
60: }
61: }
62:
63: sub deregister {
64: my ($space,@taglist) = @_;
65: foreach my $temptag (@taglist) {
66: my $tempspace = $Apache::lonxml::alltags{$temptag}[-1];
67: if ($tempspace eq $space) {
68: pop(@{ $Apache::lonxml::alltags{$temptag} });
69: }
70: }
71: #&printalltags();
72: }
73:
74: use Apache::Constants qw(:common);
75: use Apache::lontexconvert();
76: use Apache::style();
77: use Apache::run();
78: use Apache::londefdef();
79: use Apache::scripttag();
80: use Apache::languagetags();
81: use Apache::edit();
82: use Apache::inputtags();
83: use Apache::outputtags();
84: use Apache::lonnet;
85: use Apache::File();
86: use Apache::loncommon();
87: use Apache::lonfeedback();
88: use Apache::lonmsg();
89: use Apache::loncacc();
90: use Apache::lonlocal;
91:
92: #================================================== Main subroutine: xmlparse
93: #debugging control, to turn on debugging modify the correct handler
94: $Apache::lonxml::debug=0;
95:
96: # keeps count of the number of warnings and errors generated in a parse
97: $warningcount=0;
98: $errorcount=0;
99:
100: #path to the directory containing the file currently being processed
101: @pwd=();
102:
103: #these two are used for capturing a subset of the output for later processing,
104: #don't touch them directly use &startredirection and &endredirection
105: @outputstack = ();
106: $redirection = 0;
107:
108: #controls wheter the <import> tag actually does
109: $import = 1;
110: @extlinks=();
111:
112: # meta mode is a bit weird only some output is to be turned off
113: #<output> tag turns metamode off (defined in londefdef.pm)
114: $metamode = 0;
115:
116: # turns on and of run::evaluate actually derefencing var refs
117: $evaluate = 1;
118:
119: # data structure for eidt mode, determines what tags can go into what other tags
120: %insertlist=();
121:
122: # stores the list of active tag namespaces
123: @namespace=();
124:
125: # has the dynamic menu been updated to know about this resource
126: $Apache::lonxml::registered=0;
127:
128: # a pointer the the Apache request object
129: $Apache::lonxml::request='';
130:
131: # a problem number counter, and check on ether it is used
132: $Apache::lonxml::counter=1;
133: $Apache::lonxml::counter_changed=0;
134:
135: #internal check on whether to look at style defs
136: $Apache::lonxml::usestyle=1;
137:
138: #locations used to store the parameter string for style substitutions
139: $Apache::lonxml::style_values='';
140: $Apache::lonxml::style_end_values='';
141:
142: #array of ssi calls that need to occur after we are done parsing
143: @Apache::lonxml::ssi_info=();
144:
145: #should we do the postag variable interpolation
146: $Apache::lonxml::post_evaluate=1;
147:
148: #a header message to emit in the case of any generated warning or errors
149: $Apache::lonxml::warnings_error_header='';
150:
151: sub xmlbegin {
152: my ($style)=@_;
153: my $output='';
154: @htmlareafields=();
155: if ($env{'browser.mathml'}) {
156: $output='<?xml version="1.0"?>'
157: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
158: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
159:
160: # .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >'
161: .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
162: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
163: .'xmlns="http://www.w3.org/1999/xhtml">';
164: } else {
165: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
166: }
167: if ($style eq 'encode') {
168: $output=&HTML::Entities::encode($output,'<>&"');
169: }
170: return $output;
171: }
172:
173: sub xmlend {
174: my ($target,$parser)=@_;
175: my $mode='xml';
176: my $status='OPEN';
177: if ($Apache::lonhomework::parsing_a_problem ||
178: $Apache::lonhomework::parsing_a_task ) {
179: $mode='problem';
180: $status=$Apache::inputtags::status[-1];
181: }
182: my $discussion;
183: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
184: ['LONCAPA_INTERNAL_no_discussion']);
185: if (! exists($env{'form.LONCAPA_INTERNAL_no_discussion'}) ||
186: $env{'form.LONCAPA_INTERNAL_no_discussion'} ne 'true') {
187: $discussion=&Apache::lonfeedback::list_discussion($mode,$status);
188: }
189: if ($target eq 'tex') {
190: $discussion.='<tex>\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\end{document}</tex>';
191: &Apache::lonxml::newparser($parser,\$discussion,'');
192: return '';
193: } else {
194: return $discussion.&Apache::loncommon::endbodytag();
195: }
196: }
197:
198: sub tokeninputfield {
199: my $defhost=$Apache::lonnet::perlvar{'lonHostID'};
200: $defhost=~tr/a-z/A-Z/;
201: return (<<ENDINPUTFIELD)
202: <script type="text/javascript">
203: function updatetoken() {
204: var comp=new Array;
205: var barcode=unescape(document.tokeninput.barcode.value);
206: comp=barcode.split('*');
207: if (typeof(comp[0])!="undefined") {
208: document.tokeninput.codeone.value=comp[0];
209: }
210: if (typeof(comp[1])!="undefined") {
211: document.tokeninput.codetwo.value=comp[1];
212: }
213: if (typeof(comp[2])!="undefined") {
214: comp[2]=comp[2].toUpperCase();
215: document.tokeninput.codethree.value=comp[2];
216: }
217: document.tokeninput.barcode.value='';
218: }
219: </script>
220: <form method="post" name="tokeninput">
221: <table border="2" bgcolor="#FFFFBB">
222: <tr><th>DocID Checkin</th></tr>
223: <tr><td>
224: <table>
225: <tr>
226: <td>Scan in Barcode</td>
227: <td><input type="text" size="22" name="barcode"
228: onChange="updatetoken()"/></td>
229: </tr>
230: <tr><td><i>or</i> Type in DocID</td>
231: <td>
232: <input type="text" size="5" name="codeone" />
233: <b><font size="+2">*</font></b>
234: <input type="text" size="5" name="codetwo" />
235: <b><font size="+2">*</font></b>
236: <input type="text" size="10" name="codethree" value="$defhost"
237: onChange="this.value=this.value.toUpperCase()" />
238: </td></tr>
239: </table>
240: </td></tr>
241: <tr><td><input type="submit" value="Check in DocID" /></td></tr>
242: </table>
243: </form>
244: ENDINPUTFIELD
245: }
246:
247: sub maketoken {
248: my ($symb,$tuname,$tudom,$tcrsid)=@_;
249: unless ($symb) {
250: $symb=&Apache::lonnet::symbread();
251: }
252: unless ($tuname) {
253: $tuname=$env{'user.name'};
254: $tudom=$env{'user.domain'};
255: $tcrsid=$env{'request.course.id'};
256: }
257:
258: return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid);
259: }
260:
261: sub printtokenheader {
262: my ($target,$token,$tsymb,$tcrsid,$tudom,$tuname)=@_;
263: unless ($token) { return ''; }
264:
265: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
266: unless ($tsymb) {
267: $tsymb=$symb;
268: }
269: unless ($tuname) {
270: $tuname=$name;
271: $tudom=$domain;
272: $tcrsid=$courseid;
273: }
274:
275: my %reply=&Apache::lonnet::get('environment',
276: ['firstname','middlename','lastname','generation'],
277: $tudom,$tuname);
278: my $plainname=$reply{'firstname'}.' '.
279: $reply{'middlename'}.' '.
280: $reply{'lastname'}.' '.
281: $reply{'generation'};
282:
283: if ($target eq 'web') {
284: my %idhash=&Apache::lonnet::idrget($tudom,($tuname));
285: return
286: '<img align="right" src="/cgi-bin/barcode.png?encode='.$token.'" />'.
287: &mt('Checked out for').' '.$plainname.
288: '<br />'.&mt('User').': '.$tuname.' at '.$tudom.
289: '<br />'.&mt('ID').': '.$idhash{$tuname}.
290: '<br />'.&mt('CourseID').': '.$tcrsid.
291: '<br />'.&mt('Course').': '.$env{'course.'.$tcrsid.'.description'}.
292: '<br />'.&mt('DocID').': '.$token.
293: '<br />'.&mt('Time').': '.&Apache::lonlocal::locallocaltime().'<hr />';
294: } else {
295: return $token;
296: }
297: }
298:
299: sub fontsettings {
300: my $headerstring='';
301: if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) {
302: $headerstring.=
303: '<meta Content-Type="text/html; charset=x-mac-roman" />';
304: } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
305: $headerstring.=
306: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
307: }
308: return $headerstring;
309: }
310:
311: sub printalltags {
312: my $temp;
313: foreach $temp (sort keys %Apache::lonxml::alltags) {
314: &Apache::lonxml::debug("$temp -- ".
315: join(',',@{ $Apache::lonxml::alltags{$temp} }));
316: }
317: }
318:
319: sub xmlparse {
320: my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
321:
322: &setup_globals($request,$target);
323: &Apache::inputtags::initialize_inputtags();
324: &Apache::bridgetask::initialize_bridgetask();
325: &Apache::outputtags::initialize_outputtags();
326: &Apache::edit::initialize_edit();
327: &Apache::londefdef::initialize_londefdef();
328:
329: #
330: # do we have a course style file?
331: #
332:
333: if ($env{'request.course.id'} && $env{'request.state'} ne 'construct') {
334: my $bodytext=
335: $env{'course.'.$env{'request.course.id'}.'.default_xml_style'};
336: if ($bodytext) {
337: foreach my $file (split(',',$bodytext)) {
338: my $location=&Apache::lonnet::filelocation('',$file);
339: my $styletext=&Apache::lonnet::getfile($location);
340: if ($styletext ne '-1') {
341: %style_for_target = (%style_for_target,
342: &Apache::style::styleparser($target,$styletext));
343: }
344: }
345: }
346: } elsif ($env{'construct.style'} && ($env{'request.state'} eq 'construct')) {
347: my $location=&Apache::lonnet::filelocation('',$env{'construct.style'});
348: my $styletext=&Apache::lonnet::getfile($location);
349: if ($styletext ne '-1') {
350: %style_for_target = (%style_for_target,
351: &Apache::style::styleparser($target,$styletext));
352: }
353: }
354: #&printalltags();
355: my @pars = ();
356: my $pwd=$env{'request.filename'};
357: $pwd =~ s:/[^/]*$::;
358: &newparser(\@pars,\$content_file_string,$pwd);
359:
360: my $safeeval = new Safe;
361: my $safehole = new Safe::Hole;
362: &init_safespace($target,$safeeval,$safehole,$safeinit);
363: #-------------------- Redefinition of the target in the case of compound target
364:
365: ($target, my @tenta) = split('&&',$target);
366:
367: my @stack = ();
368: my @parstack = ();
369: &initdepth();
370: &init_alarm();
371: my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
372: $safeeval,\%style_for_target);
373:
374: if ($env{'request.uri'}) {
375: &writeallows($env{'request.uri'});
376: }
377: &do_registered_ssi();
378: if ($Apache::lonxml::counter_changed) { &store_counter() }
379: if ($env{'form.return_only_error_and_warning_counts'}) {
380: return "$errorcount:$warningcount";
381: }
382: return $finaloutput;
383: }
384:
385: sub latex_special_symbols {
386: my ($string,$where)=@_;
387: if ($where eq 'header') {
388: $string =~ s/(\\|_|\^)/ /g;
389: $string =~ s/(\$|%|\{|\})/\\$1/g;
390: $string =~ s/_/ /g;
391: $string=&Apache::lonprintout::character_chart($string);
392: # any & or # leftover should be safe to just escape
393: $string=~s/([^\\])\&/$1\\\&/g;
394: $string=~s/([^\\])\#/$1\\\#/g;
395: } else {
396: $string=~s/\\/\\ensuremath{\\backslash}/g;
397: $string=~s/\\\%|\%/\\\%/g;
398: $string=~s/\\{|{/\\{/g;
399: $string=~s/\\}|}/\\}/g;
400: $string=~s/\\ensuremath\\{\\backslash\\}/\\ensuremath{\\backslash}/g;
401: $string=~s/\\\$|\$/\\\$/g;
402: $string=~s/\\\_|\_/\\\_/g;
403: $string=~s/([^\\]|^)(\~|\^)/$1\\$2\\strut /g;
404: $string=~s/(>|<)/\\ensuremath\{$1\}/g; #more or less
405: $string=&Apache::lonprintout::character_chart($string);
406: # any & or # leftover should be safe to just escape
407: $string=~s/\\\&|\&/\\\&/g;
408: $string=~s/\\\#|\#/\\\#/g;
409: $string=~s/\|/\$\\mid\$/g;
410: #single { or } How to escape?
411: }
412: return $string;
413: }
414:
415: sub inner_xmlparse {
416: my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
417: my $finaloutput = '';
418: my $result;
419: my $token;
420: my $dontpop=0;
421: while ( $#$pars > -1 ) {
422: while ($token = $$pars['-1']->get_token) {
423: if (($token->[0] eq 'T') || ($token->[0] eq 'C') ) {
424: if ($metamode<1) {
425: my $text=$token->[1];
426: if ($token->[0] eq 'C' && $target eq 'tex') {
427: $text = '';
428: # $text = '%'.$text."\n";
429: }
430: $result.=$text;
431: }
432: } elsif (($token->[0] eq 'D')) {
433: if ($metamode<1 && $target eq 'web') {
434: my $text=$token->[1];
435: $result.=$text;
436: }
437: } elsif ($token->[0] eq 'PI') {
438: if ($metamode<1 && $target eq 'web') {
439: $result=$token->[2];
440: }
441: } elsif ($token->[0] eq 'S') {
442: # add tag to stack
443: push (@$stack,$token->[1]);
444: # add parameters list to another stack
445: push (@$parstack,&parstring($token));
446: &increasedepth($token);
447: if ($Apache::lonxml::usestyle &&
448: exists($$style_for_target{$token->[1]})) {
449: $Apache::lonxml::usestyle=0;
450: my $string=$$style_for_target{$token->[1]}.
451: '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
452: &Apache::lonxml::newparser($pars,\$string);
453: $Apache::lonxml::style_values=$$parstack[-1];
454: $Apache::lonxml::style_end_values=$$parstack[-1];
455: } else {
456: $result = &callsub("start_$token->[1]", $target, $token, $stack,
457: $parstack, $pars, $safeeval, $style_for_target);
458: }
459: } elsif ($token->[0] eq 'E') {
460: if ($Apache::lonxml::usestyle &&
461: exists($$style_for_target{'/'."$token->[1]"})) {
462: $Apache::lonxml::usestyle=0;
463: my $string=$$style_for_target{'/'.$token->[1]}.
464: '<LONCAPA_INTERNAL_TURN_STYLE_ON end="'.$token->[1].'" />';
465: &Apache::lonxml::newparser($pars,\$string);
466: $Apache::lonxml::style_values=$Apache::lonxml::style_end_values;
467: $Apache::lonxml::style_end_values='';
468: $dontpop=1;
469: } else {
470: #clear out any tags that didn't end
471: while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
472: my $lasttag=$$stack[-1];
473: if ($token->[1] =~ /^\Q$lasttag\E$/i) {
474: &Apache::lonxml::warning('Using tag </'.$token->[1].'> on line '.$token->[3].' as end tag to <'.$$stack[-1].'>');
475: last;
476: } else {
477: &Apache::lonxml::warning('Found tag </'.$token->[1].'> on line '.$token->[3].' when looking for </'.$$stack[-1].'> in file');
478: &end_tag($stack,$parstack,$token);
479: }
480: }
481: $result = &callsub("end_$token->[1]", $target, $token, $stack,
482: $parstack, $pars,$safeeval, $style_for_target);
483: }
484: } else {
485: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
486: }
487: #evaluate variable refs in result
488: if ($Apache::lonxml::post_evaluate &&$result ne "") {
489: my $extras;
490: if (!$Apache::lonxml::usestyle) {
491: $extras=$Apache::lonxml::style_values;
492: }
493: if ( $#$parstack > -1 ) {
494: $result=&Apache::run::evaluate($result,$safeeval,$extras.$$parstack[-1]);
495: } else {
496: $result= &Apache::run::evaluate($result,$safeeval,$extras);
497: }
498: }
499: $Apache::lonxml::post_evaluate=1;
500:
501: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
502: #Style file definitions should be correct
503: if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {
504: $result=&latex_special_symbols($result);
505: }
506: }
507:
508: if ($Apache::lonxml::redirection) {
509: $Apache::lonxml::outputstack['-1'] .= $result;
510: } else {
511: $finaloutput.=$result;
512: }
513: $result = '';
514:
515: if ($token->[0] eq 'E' && !$dontpop) {
516: &end_tag($stack,$parstack,$token);
517: }
518: $dontpop=0;
519: }
520: if ($#$pars > -1) {
521: pop @$pars;
522: pop @Apache::lonxml::pwd;
523: }
524: }
525:
526: # if ($target eq 'meta') {
527: # $finaloutput.=&endredirection;
528: # }
529:
530: if ($target eq 'grade') { &endredirection(); }
531: if ( $Apache::lonxml::redirection ) {
532: &error("Unclean exit of parser, text still being redirected. This is likely due to there being missing end tags.");
533: while ($Apache::lonxml::redirection) {
534: $finaloutput.=&endredirection();
535: }
536: }
537: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
538: $finaloutput=&afterburn($finaloutput);
539: }
540: return $finaloutput;
541: }
542:
543: ##
544: ## Looks to see if there is a subroutine defined for this tag. If so, call it,
545: ## otherwise do not call it as we do not know what it is.
546: ##
547: sub callsub {
548: my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
549: my $currentstring='';
550: my $nodefault;
551: {
552: my $sub1;
553: no strict 'refs';
554: my $tag=$token->[1];
555: # get utterly rid of extended html tags
556: if ($tag=~/^x\-/i) { return ''; }
557: my $space=$Apache::lonxml::alltags{$tag}[-1];
558: if (!$space) {
559: $tag=~tr/A-Z/a-z/;
560: $sub=~tr/A-Z/a-z/;
561: $space=$Apache::lonxml::alltags{$tag}[-1]
562: }
563:
564: my $deleted=0;
565: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
566: if (($token->[0] eq 'S') && ($target eq 'modified')) {
567: $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
568: $parstack,$parser,$safeeval,
569: $style);
570: }
571: if (!$deleted) {
572: if ($space) {
573: #&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
574: $sub1="$space\:\:$sub";
575: ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
576: $parstack,$parser,$safeeval,
577: $style);
578: } else {
579: if ($target eq 'tex') {
580: # throw away tag name
581: return '';
582: }
583: #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
584: if ($metamode <1) {
585: if (defined($token->[4]) && ($metamode < 1)) {
586: $currentstring = $token->[4];
587: } else {
588: $currentstring = $token->[2];
589: }
590: }
591: }
592: # &Apache::lonxml::debug("nodefalt:$nodefault:");
593: if ($currentstring eq '' && $nodefault eq '') {
594: if ($target eq 'edit') {
595: #&Apache::lonxml::debug("doing default edit for $token->[1]");
596: if ($token->[0] eq 'S') {
597: $currentstring = &Apache::edit::tag_start($target,$token);
598: } elsif ($token->[0] eq 'E') {
599: $currentstring = &Apache::edit::tag_end($target,$token);
600: }
601: } elsif ($target eq 'modified') {
602: if ($token->[0] eq 'S') {
603: $currentstring = $token->[4];
604: $currentstring.=&Apache::edit::handle_insert();
605: } elsif ($token->[0] eq 'E') {
606: $currentstring = $token->[2];
607: $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
608: } else {
609: $currentstring = $token->[2];
610: }
611: }
612: }
613: }
614: use strict 'refs';
615: }
616: return $currentstring;
617: }
618:
619: sub setup_globals {
620: my ($request,$target)=@_;
621: $Apache::lonxml::request=$request;
622: $Apache::lonxml::registered = 0;
623: @Apache::lonxml::htmlareafields=();
624: $errorcount=0;
625: $warningcount=0;
626: $Apache::lonxml::default_homework_loaded=0;
627: $Apache::lonxml::usestyle=1;
628: &init_counter();
629: @Apache::lonxml::pwd=();
630: @Apache::lonxml::extlinks=();
631: @Apache::lonxml::ssi_info=();
632: $Apache::lonxml::post_evaluate=1;
633: $Apache::lonxml::warnings_error_header='';
634: if ($target eq 'meta') {
635: $Apache::lonxml::redirection = 0;
636: $Apache::lonxml::metamode = 1;
637: $Apache::lonxml::evaluate = 1;
638: $Apache::lonxml::import = 0;
639: } elsif ($target eq 'answer') {
640: $Apache::lonxml::redirection = 0;
641: $Apache::lonxml::metamode = 1;
642: $Apache::lonxml::evaluate = 1;
643: $Apache::lonxml::import = 1;
644: } elsif ($target eq 'grade') {
645: &startredirection(); #ended in inner_xmlparse on exit
646: $Apache::lonxml::metamode = 0;
647: $Apache::lonxml::evaluate = 1;
648: $Apache::lonxml::import = 1;
649: } elsif ($target eq 'modified') {
650: $Apache::lonxml::redirection = 0;
651: $Apache::lonxml::metamode = 0;
652: $Apache::lonxml::evaluate = 0;
653: $Apache::lonxml::import = 0;
654: } elsif ($target eq 'edit') {
655: $Apache::lonxml::redirection = 0;
656: $Apache::lonxml::metamode = 0;
657: $Apache::lonxml::evaluate = 0;
658: $Apache::lonxml::import = 0;
659: } elsif ($target eq 'analyze') {
660: $Apache::lonxml::redirection = 0;
661: $Apache::lonxml::metamode = 0;
662: $Apache::lonxml::evaluate = 1;
663: $Apache::lonxml::import = 1;
664: } else {
665: $Apache::lonxml::redirection = 0;
666: $Apache::lonxml::metamode = 0;
667: $Apache::lonxml::evaluate = 1;
668: $Apache::lonxml::import = 1;
669: }
670: }
671:
672: sub init_safespace {
673: my ($target,$safeeval,$safehole,$safeinit) = @_;
674: $safeeval->deny_only(':dangerous');
675: $safeeval->reval('use Math::Complex;');
676: $safeeval->permit_only(":default");
677: $safeeval->permit("entereval");
678: $safeeval->permit(":base_math");
679: $safeeval->permit("sort");
680: $safeeval->permit("time");
681: $safeeval->deny("rand");
682: $safeeval->deny("srand");
683: $safeeval->deny(":base_io");
684: $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
685: $safehole->wrap(\&Apache::outputtags::multipart,$safeeval,'&multipart');
686: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
687: $safehole->wrap(\&Apache::chemresponse::chem_standard_order,$safeeval,
688: '&chem_standard_order');
689: $safehole->wrap(\&Apache::response::check_status,$safeeval,'&check_status');
690:
691: $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
692: $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
693: $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
694: $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
695: $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
696: $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
697: $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
698: $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
699: $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
700: $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
701: $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
702: $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
703: $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
704: $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
705: $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
706: $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
707: $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
708: $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
709: $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
710:
711: $safehole->wrap(\&Math::Cephes::bdtr ,$safeeval,'&bdtr' );
712: $safehole->wrap(\&Math::Cephes::bdtrc ,$safeeval,'&bdtrc' );
713: $safehole->wrap(\&Math::Cephes::bdtri ,$safeeval,'&bdtri' );
714: $safehole->wrap(\&Math::Cephes::btdtr ,$safeeval,'&btdtr' );
715: $safehole->wrap(\&Math::Cephes::chdtr ,$safeeval,'&chdtr' );
716: $safehole->wrap(\&Math::Cephes::chdtrc,$safeeval,'&chdtrc');
717: $safehole->wrap(\&Math::Cephes::chdtri,$safeeval,'&chdtri');
718: $safehole->wrap(\&Math::Cephes::fdtr ,$safeeval,'&fdtr' );
719: $safehole->wrap(\&Math::Cephes::fdtrc ,$safeeval,'&fdtrc' );
720: $safehole->wrap(\&Math::Cephes::fdtri ,$safeeval,'&fdtri' );
721: $safehole->wrap(\&Math::Cephes::gdtr ,$safeeval,'&gdtr' );
722: $safehole->wrap(\&Math::Cephes::gdtrc ,$safeeval,'&gdtrc' );
723: $safehole->wrap(\&Math::Cephes::nbdtr ,$safeeval,'&nbdtr' );
724: $safehole->wrap(\&Math::Cephes::nbdtrc,$safeeval,'&nbdtrc');
725: $safehole->wrap(\&Math::Cephes::nbdtri,$safeeval,'&nbdtri');
726: $safehole->wrap(\&Math::Cephes::ndtr ,$safeeval,'&ndtr' );
727: $safehole->wrap(\&Math::Cephes::ndtri ,$safeeval,'&ndtri' );
728: $safehole->wrap(\&Math::Cephes::pdtr ,$safeeval,'&pdtr' );
729: $safehole->wrap(\&Math::Cephes::pdtrc ,$safeeval,'&pdtrc' );
730: $safehole->wrap(\&Math::Cephes::pdtri ,$safeeval,'&pdtri' );
731: $safehole->wrap(\&Math::Cephes::stdtr ,$safeeval,'&stdtr' );
732: $safehole->wrap(\&Math::Cephes::stdtri,$safeeval,'&stdtri');
733:
734: $safehole->wrap(\&Math::Cephes::Matrix::mat,$safeeval,'&mat');
735: $safehole->wrap(\&Math::Cephes::Matrix::new,$safeeval,
736: '&Math::Cephes::Matrix::new');
737: $safehole->wrap(\&Math::Cephes::Matrix::coef,$safeeval,
738: '&Math::Cephes::Matrix::coef');
739: $safehole->wrap(\&Math::Cephes::Matrix::clr,$safeeval,
740: '&Math::Cephes::Matrix::clr');
741: $safehole->wrap(\&Math::Cephes::Matrix::add,$safeeval,
742: '&Math::Cephes::Matrix::add');
743: $safehole->wrap(\&Math::Cephes::Matrix::sub,$safeeval,
744: '&Math::Cephes::Matrix::sub');
745: $safehole->wrap(\&Math::Cephes::Matrix::mul,$safeeval,
746: '&Math::Cephes::Matrix::mul');
747: $safehole->wrap(\&Math::Cephes::Matrix::div,$safeeval,
748: '&Math::Cephes::Matrix::div');
749: $safehole->wrap(\&Math::Cephes::Matrix::inv,$safeeval,
750: '&Math::Cephes::Matrix::inv');
751: $safehole->wrap(\&Math::Cephes::Matrix::transp,$safeeval,
752: '&Math::Cephes::Matrix::transp');
753: $safehole->wrap(\&Math::Cephes::Matrix::simq,$safeeval,
754: '&Math::Cephes::Matrix::simq');
755: $safehole->wrap(\&Math::Cephes::Matrix::mat_to_vec,$safeeval,
756: '&Math::Cephes::Matrix::mat_to_vec');
757: $safehole->wrap(\&Math::Cephes::Matrix::vec_to_mat,$safeeval,
758: '&Math::Cephes::Matrix::vec_to_mat');
759: $safehole->wrap(\&Math::Cephes::Matrix::check,$safeeval,
760: '&Math::Cephes::Matrix::check');
761: $safehole->wrap(\&Math::Cephes::Matrix::check,$safeeval,
762: '&Math::Cephes::Matrix::check');
763:
764: # $safehole->wrap(\&Math::Cephes::new_fract,$safeeval,'&new_fract');
765: # $safehole->wrap(\&Math::Cephes::radd,$safeeval,'&radd');
766: # $safehole->wrap(\&Math::Cephes::rsub,$safeeval,'&rsub');
767: # $safehole->wrap(\&Math::Cephes::rmul,$safeeval,'&rmul');
768: # $safehole->wrap(\&Math::Cephes::rdiv,$safeeval,'&rdiv');
769: # $safehole->wrap(\&Math::Cephes::euclid,$safeeval,'&euclid');
770:
771: $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
772: $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
773: $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
774: $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
775: $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
776: $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
777: $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
778: $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
779: $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
780: $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
781: $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
782: $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
783: $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
784: $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
785: $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
786: $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
787: $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
788: $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
789: $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
790: $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
791: $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
792: $safehole->wrap(\&Apache::lonxml::error,$safeeval,'&LONCAPA_INTERNAL_ERROR');
793: $safehole->wrap(\&Apache::lonxml::debug,$safeeval,'&LONCAPA_INTERNAL_DEBUG');
794: $safehole->wrap(\&Apache::caparesponse::get_sigrange,$safeeval,'&LONCAPA_INTERNAL_get_sigrange');
795:
796: #need to inspect this class of ops
797: # $safeeval->deny(":base_orig");
798: $safeeval->permit("require");
799: $safeinit .= ';$external::target="'.$target.'";';
800: &Apache::run::run($safeinit,$safeeval);
801: &initialize_rndseed($safeeval);
802: }
803:
804: sub initialize_rndseed {
805: my ($safeeval)=@_;
806: my $rndseed;
807: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
808: $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
809: my $safeinit = '$external::randomseed="'.$rndseed.'";';
810: &Apache::lonxml::debug("Setting rndseed to $rndseed");
811: &Apache::run::run($safeinit,$safeeval);
812: }
813:
814: sub default_homework_load {
815: my ($safeeval)=@_;
816: &Apache::lonxml::debug('Loading default_homework');
817: my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
818: if ($default eq -1) {
819: &Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
820: } else {
821: &Apache::run::run($default,$safeeval);
822: $Apache::lonxml::default_homework_loaded=1;
823: }
824: }
825:
826: {
827: my $alarm_depth;
828: sub init_alarm {
829: alarm(0);
830: $alarm_depth=0;
831: }
832:
833: sub start_alarm {
834: if ($alarm_depth<1) {
835: my $old=alarm($Apache::lonnet::perlvar{'lonScriptTimeout'});
836: if ($old) {
837: &Apache::lonxml::error("Cancelled an alarm of $old, this shouldn't occur.");
838: }
839: }
840: $alarm_depth++;
841: }
842:
843: sub end_alarm {
844: $alarm_depth--;
845: if ($alarm_depth<1) { alarm(0); }
846: }
847: }
848: my $metamode_was;
849: sub startredirection {
850: if (!$Apache::lonxml::redirection) {
851: $metamode_was=$Apache::lonxml::metamode;
852: }
853: $Apache::lonxml::metamode=0;
854: $Apache::lonxml::redirection++;
855: push (@Apache::lonxml::outputstack, '');
856: }
857:
858: sub endredirection {
859: if (!$Apache::lonxml::redirection) {
860: &Apache::lonxml::error("Endredirection was called before a startredirection, perhaps you have unbalanced tags. Some debugging information:".join ":",caller);
861: return '';
862: }
863: $Apache::lonxml::redirection--;
864: if (!$Apache::lonxml::redirection) {
865: $Apache::lonxml::metamode=$metamode_was;
866: }
867: pop @Apache::lonxml::outputstack;
868: }
869:
870: sub end_tag {
871: my ($tagstack,$parstack,$token)=@_;
872: pop(@$tagstack);
873: pop(@$parstack);
874: &decreasedepth($token);
875: }
876:
877: sub initdepth {
878: @Apache::lonxml::depthcounter=();
879: $Apache::lonxml::depth=-1;
880: $Apache::lonxml::olddepth=-1;
881: }
882:
883: my @timers;
884: my $lasttime;
885: sub increasedepth {
886: my ($token) = @_;
887: $Apache::lonxml::depth++;
888: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
889: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
890: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
891: }
892: my $time;
893: if ($Apache::lonxml::debug eq "1") {
894: push(@timers,[&gettimeofday()]);
895: $time=&tv_interval($lasttime);
896: $lasttime=[&gettimeofday()];
897: }
898: my $spacing=' 'x($Apache::lonxml::depth-1);
899: my $curdepth=join('_',@Apache::lonxml::depthcounter);
900: &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : \n");
901: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
902: }
903:
904: sub decreasedepth {
905: my ($token) = @_;
906: $Apache::lonxml::depth--;
907: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
908: $#Apache::lonxml::depthcounter--;
909: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
910: }
911: if ( $Apache::lonxml::depth < -1) {
912: &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
913: $Apache::lonxml::depth='-1';
914: }
915: my ($timer,$time);
916: if ($Apache::lonxml::debug eq "1") {
917: $timer=pop(@timers);
918: $time=&tv_interval($lasttime);
919: $lasttime=[&gettimeofday()];
920: }
921: my $spacing=' 'x$Apache::lonxml::depth;
922: my $curdepth=join('_',@Apache::lonxml::depthcounter);
923: &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : ".&tv_interval($timer)."\n");
924: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
925: }
926:
927: sub get_all_text_unbalanced {
928: #there is a copy of this in lonpublisher.pm
929: my($tag,$pars)= @_;
930: my $token;
931: my $result='';
932: $tag='<'.$tag.'>';
933: while ($token = $$pars[-1]->get_token) {
934: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
935: if ($token->[0] eq 'T' && $token->[2]) {
936: $result.='<![CDATA['.$token->[1].']]>';
937: } else {
938: $result.=$token->[1];
939: }
940: } elsif ($token->[0] eq 'PI') {
941: $result.=$token->[2];
942: } elsif ($token->[0] eq 'S') {
943: $result.=$token->[4];
944: } elsif ($token->[0] eq 'E') {
945: $result.=$token->[2];
946: }
947: if ($result =~ /\Q$tag\E/is) {
948: ($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is;
949: #&Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
950: #&Apache::lonxml::debug('Result is :'.$1);
951: $redo=$tag.$redo;
952: &Apache::lonxml::newparser($pars,\$redo);
953: last;
954: }
955: }
956: return $result
957: }
958:
959: sub increment_counter {
960: my ($increment) = @_;
961: if (defined($increment) && $increment gt 0) {
962: $Apache::lonxml::counter+=$increment;
963: } else {
964: $Apache::lonxml::counter++;
965: }
966: $Apache::lonxml::counter_changed=1;
967: }
968:
969: sub init_counter {
970: if (defined($env{'form.counter'})) {
971: $Apache::lonxml::counter=$env{'form.counter'};
972: $Apache::lonxml::counter_changed=0;
973: } else {
974: $Apache::lonxml::counter=1;
975: $Apache::lonxml::counter_changed=1;
976: }
977: }
978:
979: sub store_counter {
980: &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter));
981: return '';
982: }
983:
984: sub get_all_text {
985: my($tag,$pars,$style)= @_;
986: my $gotfullstack=1;
987: if (ref($pars) ne 'ARRAY') {
988: $gotfullstack=0;
989: $pars=[$pars];
990: }
991: if (ref($style) ne 'HASH') {
992: $style={};
993: }
994: my $depth=0;
995: my $token;
996: my $result='';
997: if ( $tag =~ m:^/: ) {
998: my $tag=substr($tag,1);
999: #&Apache::lonxml::debug("have:$tag:");
1000: my $top_empty=0;
1001: while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
1002: while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
1003: #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
1004: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1005: if ($token->[2]) {
1006: $result.='<![CDATA['.$token->[1].']]>';
1007: } else {
1008: $result.=$token->[1];
1009: }
1010: } elsif ($token->[0] eq 'PI') {
1011: $result.=$token->[2];
1012: } elsif ($token->[0] eq 'S') {
1013: if ($token->[1] =~ /^\Q$tag\E$/i) { $depth++; }
1014: if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/) { $Apache::lonxml::usestyle=1; }
1015: if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/) { $Apache::lonxml::usestyle=0; }
1016: $result.=$token->[4];
1017: } elsif ($token->[0] eq 'E') {
1018: if ( $token->[1] =~ /^\Q$tag\E$/i) { $depth--; }
1019: #skip sending back the last end tag
1020: if ($depth == 0 && exists($$style{'/'.$token->[1]}) && $Apache::lonxml::usestyle) {
1021: my $string=
1022: '<LONCAPA_INTERNAL_TURN_STYLE_OFF end="yes" />'.
1023: $$style{'/'.$token->[1]}.
1024: $token->[2].
1025: '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
1026: &Apache::lonxml::newparser($pars,\$string);
1027: #&Apache::lonxml::debug("reParsing $string");
1028: next;
1029: }
1030: if ($depth > -1) {
1031: $result.=$token->[2];
1032: } else {
1033: $$pars[-1]->unget_token($token);
1034: }
1035: }
1036: }
1037: if (($depth >=0) && ($#$pars == 0) ) { $top_empty=1; }
1038: if (($depth >=0) && ($#$pars > 0) ) {
1039: pop(@$pars);
1040: pop(@Apache::lonxml::pwd);
1041: }
1042: }
1043: if ($top_empty && $depth >= 0) {
1044: #never found the end tag ran out of text, throw error send back blank
1045: &error('Never found end tag for <'.$tag.
1046: '> current string <pre>'.
1047: &HTML::Entities::encode($result,'<>&"').
1048: '</pre>');
1049: if ($gotfullstack) {
1050: my $newstring='</'.$tag.'>'.$result;
1051: &Apache::lonxml::newparser($pars,\$newstring);
1052: }
1053: $result='';
1054: }
1055: } else {
1056: while ($#$pars > -1) {
1057: while ($token = $$pars[-1]->get_token) {
1058: #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
1059: if (($token->[0] eq 'T')||($token->[0] eq 'C')||
1060: ($token->[0] eq 'D')) {
1061: if ($token->[2]) {
1062: $result.='<![CDATA['.$token->[1].']]>';
1063: } else {
1064: $result.=$token->[1];
1065: }
1066: } elsif ($token->[0] eq 'PI') {
1067: $result.=$token->[2];
1068: } elsif ($token->[0] eq 'S') {
1069: if ( $token->[1] =~ /^\Q$tag\E$/i) {
1070: $$pars[-1]->unget_token($token); last;
1071: } else {
1072: $result.=$token->[4];
1073: }
1074: if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_ON$/) { $Apache::lonxml::usestyle=1; }
1075: if ($token->[1] =~ /^LONCAPA_INTERNAL_TURN_STYLE_OFF$/) { $Apache::lonxml::usestyle=0; }
1076: } elsif ($token->[0] eq 'E') {
1077: $result.=$token->[2];
1078: }
1079: }
1080: if (($#$pars > 0) ) {
1081: pop(@$pars);
1082: pop(@Apache::lonxml::pwd);
1083: } else { last; }
1084: }
1085: }
1086: #&Apache::lonxml::debug("Exit:$result:");
1087: return $result
1088: }
1089:
1090: sub newparser {
1091: my ($parser,$contentref,$dir) = @_;
1092: push (@$parser,HTML::LCParser->new($contentref));
1093: $$parser[-1]->xml_mode(1);
1094: $$parser[-1]->marked_sections(1);
1095: if ( $dir eq '' ) {
1096: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
1097: } else {
1098: push (@Apache::lonxml::pwd, $dir);
1099: }
1100: }
1101:
1102: sub parstring {
1103: my ($token) = @_;
1104: my $temp='';
1105: foreach (@{$token->[3]}) {
1106: unless ($_=~/\W/) {
1107: my $val=$token->[2]->{$_};
1108: $val =~ s/([\%\@\\\"\'])/\\$1/g;
1109: $val =~ s/(\$[^{a-zA-Z_])/\\$1/g;
1110: $val =~ s/(\$)$/\\$1/;
1111: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1112: $temp .= "my \$$_=\"$val\";";
1113: }
1114: }
1115: return $temp;
1116: }
1117:
1118: sub extlink {
1119: my ($res,$exact)=@_;
1120: if (!$exact) {
1121: $res=&Apache::lonnet::hreflocation($Apache::lonxml::pwd[-1],$res);
1122: }
1123: push(@Apache::lonxml::extlinks,$res)
1124: }
1125:
1126: sub writeallows {
1127: unless ($#extlinks>=0) { return; }
1128: my $thisurl = &Apache::lonnet::clutter(shift);
1129: if ($env{'httpref.'.$thisurl}) {
1130: $thisurl=$env{'httpref.'.$thisurl};
1131: }
1132: my $thisdir=$thisurl;
1133: $thisdir=~s/\/[^\/]+$//;
1134: my %httpref=();
1135: foreach (@extlinks) {
1136: $httpref{'httpref.'.
1137: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
1138: }
1139: @extlinks=();
1140: &Apache::lonnet::appenv(%httpref);
1141: }
1142:
1143: sub register_ssi {
1144: my ($url,%form)=@_;
1145: push (@Apache::lonxml::ssi_info,{'url'=>$url,'form'=>\%form});
1146: return '';
1147: }
1148:
1149: sub do_registered_ssi {
1150: foreach my $info (@Apache::lonxml::ssi_info) {
1151: my %form=%{ $info->{'form'}};
1152: my $url=$info->{'url'};
1153: &Apache::lonnet::ssi($url,%form);
1154: }
1155: }
1156: #
1157: # Afterburner handles anchors, highlights and links
1158: #
1159: sub afterburn {
1160: my $result=shift;
1161: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1162: ['highlight','anchor','link']);
1163: if ($env{'form.highlight'}) {
1164: foreach (split(/\,/,$env{'form.highlight'})) {
1165: my $anchorname=$_;
1166: my $matchthis=$anchorname;
1167: $matchthis=~s/\_+/\\s\+/g;
1168: $result=~s/(\Q$matchthis\E)/\<font color=\"red\"\>$1\<\/font\>/gs;
1169: }
1170: }
1171: if ($env{'form.link'}) {
1172: foreach (split(/\,/,$env{'form.link'})) {
1173: my ($anchorname,$linkurl)=split(/\>/,$_);
1174: my $matchthis=$anchorname;
1175: $matchthis=~s/\_+/\\s\+/g;
1176: $result=~s/(\Q$matchthis\E)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
1177: }
1178: }
1179: if ($env{'form.anchor'}) {
1180: my $anchorname=$env{'form.anchor'};
1181: my $matchthis=$anchorname;
1182: $matchthis=~s/\_+/\\s\+/g;
1183: $result=~s/(\Q$matchthis\E)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
1184: $result.=(<<"ENDSCRIPT");
1185: <script type="text/javascript">
1186: document.location.hash='$anchorname';
1187: </script>
1188: ENDSCRIPT
1189: }
1190: return $result;
1191: }
1192:
1193: sub storefile {
1194: my ($file,$contents)=@_;
1195: &Apache::lonnet::correct_line_ends(\$contents);
1196: if (my $fh=Apache::File->new('>'.$file)) {
1197: print $fh $contents;
1198: $fh->close();
1199: return 1;
1200: } else {
1201: &warning("Unable to save file $file");
1202: return 0;
1203: }
1204: }
1205:
1206: sub createnewhtml {
1207: my $title=&mt('Title of document goes here');
1208: my $body=&mt('Body of document goes here');
1209: my $filecontents=(<<SIMPLECONTENT);
1210: <html>
1211: <head>
1212: <title>$title</title>
1213: </head>
1214: <body bgcolor="#FFFFFF">
1215: $body
1216: </body>
1217: </html>
1218: SIMPLECONTENT
1219: return $filecontents;
1220: }
1221:
1222: sub createnewsty {
1223: my $filecontents=(<<SIMPLECONTENT);
1224: <definetag name="">
1225: <render>
1226: <web></web>
1227: <tex></tex>
1228: </render>
1229: </definetag>
1230: SIMPLECONTENT
1231: return $filecontents;
1232: }
1233:
1234:
1235: sub inserteditinfo {
1236: my ($result,$filecontents,$filetype)=@_;
1237: $filecontents = &HTML::Entities::encode($filecontents,'<>&"');
1238: # my $editheader='<a href="#editsection">Edit below</a><hr />';
1239: my $xml_help = '';
1240: my $initialize='';
1241: if ($filetype eq 'html') {
1242: my $addbuttons=&Apache::lonhtmlcommon::htmlareaaddbuttons();
1243: $initialize=&Apache::lonhtmlcommon::htmlareaheaders().
1244: &Apache::lonhtmlcommon::spellheader();
1245: if (!&Apache::lonhtmlcommon::htmlareablocked() &&
1246: &Apache::lonhtmlcommon::htmlareabrowser()) {
1247: $initialize.=(<<FULLPAGE);
1248: <script type="text/javascript">
1249: $addbuttons
1250:
1251: HTMLArea.loadPlugin("FullPage");
1252:
1253: function initDocument() {
1254: var editor=new HTMLArea("filecont",config);
1255: editor.registerPlugin(FullPage);
1256: editor.generate();
1257: }
1258: </script>
1259: FULLPAGE
1260: } else {
1261: $initialize.=(<<FULLPAGE);
1262: <script type="text/javascript">
1263: $addbuttons
1264: function initDocument() {
1265: }
1266: </script>
1267: FULLPAGE
1268: }
1269: $result=~s/\<body([^\>]*)\>/\<body onload="initDocument()" $1\>/i;
1270: $xml_help=&Apache::loncommon::helpLatexCheatsheet();
1271: }
1272: my $cleanbut = '';
1273:
1274: my $titledisplay=&display_title();
1275: my %lt=&Apache::lonlocal::texthash('st' => 'Save this',
1276: 'vi' => 'View',
1277: 'ed' => 'Edit');
1278: my $buttons=(<<BUTTONS);
1279: $cleanbut
1280: <input type="submit" name="savethisfile" accesskey="s" value="$lt{'st'}" />
1281: <input type="submit" name="viewmode" accesskey="v" value="$lt{'vi'}" />
1282: BUTTONS
1283: $buttons.=&Apache::lonhtmlcommon::spelllink('xmledit','filecont');
1284: $buttons.=&Apache::lonhtmlcommon::htmlareaselectactive('filecont');
1285: my $editfooter=(<<ENDFOOTER);
1286: $initialize
1287: <hr />
1288: <a name="editsection" />
1289: <form method="post" name="xmledit">
1290: $xml_help
1291: <input type="hidden" name="editmode" value="$lt{'ed'}" />
1292: $buttons<br />
1293: <textarea style="width:100%" cols="80" rows="44" name="filecont" id="filecont">$filecontents</textarea>
1294: <br />$buttons
1295: <br />
1296: </form>
1297: $titledisplay
1298: </body>
1299: ENDFOOTER
1300: # $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
1301: $result=~s/(\<\/body\>)/$editfooter/is;
1302: return $result;
1303: }
1304:
1305: sub get_target {
1306: my $viewgrades=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
1307: if ( $env{'request.state'} eq 'published') {
1308: if ( defined($env{'form.grade_target'})
1309: && ($viewgrades == 'F' )) {
1310: return ($env{'form.grade_target'});
1311: } elsif (defined($env{'form.grade_target'})) {
1312: if (($env{'form.grade_target'} eq 'web') ||
1313: ($env{'form.grade_target'} eq 'tex') ) {
1314: return $env{'form.grade_target'}
1315: } else {
1316: return 'web';
1317: }
1318: } else {
1319: return 'web';
1320: }
1321: } elsif ($env{'request.state'} eq 'construct') {
1322: if ( defined($env{'form.grade_target'})) {
1323: return ($env{'form.grade_target'});
1324: } else {
1325: return 'web';
1326: }
1327: } else {
1328: return 'web';
1329: }
1330: }
1331:
1332: sub handler {
1333: my $request=shift;
1334:
1335: my $target=&get_target();
1336:
1337: $Apache::lonxml::debug=$env{'user.debug'};
1338:
1339: &Apache::loncommon::content_type($request,'text/html');
1340: &Apache::loncommon::no_cache($request);
1341: if ($env{'request.state'} eq 'published') {
1342: $request->set_last_modified(&Apache::lonnet::metadata($request->uri,
1343: 'lastrevisiondate'));
1344: }
1345: $request->send_http_header;
1346:
1347: return OK if $request->header_only;
1348:
1349:
1350: my $file=&Apache::lonnet::filelocation("",$request->uri);
1351: my $filetype;
1352: if ($file =~ /\.sty$/) {
1353: $filetype='sty';
1354: } else {
1355: $filetype='html';
1356: }
1357: #
1358: # Edit action? Save file.
1359: #
1360: unless ($env{'request.state'} eq 'published') {
1361: if ($env{'form.savethisfile'}) {
1362: if (&storefile($file,$env{'form.filecont'})) {
1363: &Apache::lonxml::info("<font COLOR=\"#0000FF\">".
1364: &mt('Updated').": ".
1365: &Apache::lonlocal::locallocaltime(time).
1366: " </font>");
1367: }
1368: }
1369: }
1370: my %mystyle;
1371: my $result = '';
1372: my $filecontents=&Apache::lonnet::getfile($file);
1373: if ($filecontents eq -1) {
1374: my $bodytag=&Apache::loncommon::bodytag('File Error');
1375: my $fnf=&mt('File not found');
1376: $result=(<<ENDNOTFOUND);
1377: <html>
1378: <head>
1379: <title>$fnf</title>
1380: </head>
1381: $bodytag
1382: <b>$fnf: $file</b>
1383: </body>
1384: </html>
1385: ENDNOTFOUND
1386: $filecontents='';
1387: if ($env{'request.state'} ne 'published') {
1388: if ($filetype eq 'sty') {
1389: $filecontents=&createnewsty();
1390: } else {
1391: $filecontents=&createnewhtml();
1392: }
1393: $env{'form.editmode'}='Edit'; #force edit mode
1394: }
1395: } else {
1396: unless ($env{'request.state'} eq 'published') {
1397: if ($filecontents=~/BEGIN LON-CAPA Internal/) {
1398: &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.'));
1399: }
1400: #
1401: # we are in construction space, see if edit mode forced
1402: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1403: ['editmode']);
1404: }
1405: if (!$env{'form.editmode'} || $env{'form.viewmode'}) {
1406: $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
1407: '',%mystyle);
1408: undef($Apache::lonhomework::parsing_a_task);
1409: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1410: ['rawmode']);
1411: if ($env{'rawmode'}) { $result = $filecontents; }
1412: }
1413: }
1414:
1415: #
1416: # Edit action? Insert editing commands
1417: #
1418: unless ($env{'request.state'} eq 'published') {
1419: if ($env{'form.editmode'} && (!($env{'form.viewmode'}))) {
1420: my $displayfile=$request->uri;
1421: $displayfile=~s/^\/[^\/]*//;
1422: my $bodytag='<body bgcolor="#FFFFFF">';
1423: if ($env{'environment.remote'} eq 'off') {
1424: $bodytag=&Apache::loncommon::bodytag();
1425: }
1426: $result='<html>'.$bodytag.
1427: &Apache::lonxml::message_location().'<h3>'.
1428: $displayfile.
1429: '</h3></body></html>';
1430: $result=&inserteditinfo($result,$filecontents,$filetype);
1431: }
1432: }
1433: if ($filetype eq 'html') { writeallows($request->uri); }
1434:
1435:
1436: &Apache::lonxml::add_messages(\$result);
1437: $request->print($result);
1438:
1439: return OK;
1440: }
1441:
1442: sub display_title {
1443: my $result;
1444: if ($env{'request.state'} eq 'construct') {
1445: my $title=&Apache::lonnet::gettitle();
1446: if (!defined($title) || $title eq '') {
1447: $title = $env{'request.filename'};
1448: $title = substr($title, rindex($title, '/') + 1);
1449: }
1450: $result = "<script type='text/javascript'>top.document.title = '$title - LON-CAPA Construction Space';</script>";
1451: }
1452: return $result;
1453: }
1454:
1455: sub debug {
1456: if ($Apache::lonxml::debug eq "1") {
1457: $|=1;
1458: my $request=$Apache::lonxml::request;
1459: if (!$request) { $request=Apache->request; }
1460: $request->print('<font size="-2"><pre>DEBUG:'.&HTML::Entities::encode($_[0],'<>&"')."</pre></font>\n");
1461: #&Apache::lonnet::logthis($_[0]);
1462: }
1463: }
1464:
1465: sub show_error_warn_msg {
1466: if ($env{'request.filename'} eq '/home/httpd/html/res/lib/templates/simpleproblem.problem' &&
1467: &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1468: return 1;
1469: }
1470: return (($Apache::lonxml::debug eq 1) ||
1471: ($env{'request.state'} eq 'construct') ||
1472: ($Apache::lonhomework::browse eq 'F'
1473: &&
1474: $env{'form.show_errors'} eq 'on'));
1475: }
1476:
1477: sub error {
1478: $errorcount++;
1479: if ( &show_error_warn_msg() ) {
1480: # If printing in construction space, put the error inside <pre></pre>
1481: push(@Apache::lonxml::error_messages,
1482: $Apache::lonxml::warnings_error_header.
1483: "<b>ERROR:</b>".join("<br />\n",@_)."<br />\n");
1484: $Apache::lonxml::warnings_error_header='';
1485: } else {
1486: my $errormsg;
1487: my ($symb)=&Apache::lonnet::symbread();
1488: if ( !$symb ) {
1489: #public or browsers
1490: $errormsg=&mt("An error occured while processing this resource. The author has been notified.");
1491: }
1492: #notify author
1493: &Apache::lonmsg::author_res_msg($env{'request.filename'},join('<br />',@_));
1494: #notify course
1495: if ( $symb && $env{'request.course.id'} ) {
1496: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
1497: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1498: my (undef,%users)=&Apache::lonfeedback::decide_receiver(undef,0,1,1,1);
1499: my $declutter=&Apache::lonnet::declutter($env{'request.filename'});
1500: my @userlist;
1501: foreach (keys %users) {
1502: my ($user,$domain) = split(/:/, $_);
1503: push(@userlist,"$user\@$domain");
1504: my $key=$declutter.'_'.$user.'_'.$domain;
1505: my %lastnotified=&Apache::lonnet::get('nohist_xmlerrornotifications',
1506: [$key],
1507: $cdom,$cnum);
1508: my $now=time;
1509: if ($now-$lastnotified{$key}>86400) {
1510: &Apache::lonmsg::user_normal_msg($user,$domain,
1511: "Error [$declutter]",join('<br />',@_));
1512: &Apache::lonnet::put('nohist_xmlerrornotifications',
1513: {$key => $now},
1514: $cdom,$cnum);
1515: }
1516: }
1517: if ($env{'request.role.adv'}) {
1518: $errormsg=&mt("An error occured while processing this resource. The course personnel ([_1]) and the author have been notified.",join(', ',@userlist));
1519: } else {
1520: $errormsg=&mt("An error occured while processing this resource. The instructor has been notified.");
1521: }
1522: }
1523: push(@Apache::lonxml::error_messages,"<b>$errormsg</b> <br />");
1524: }
1525: }
1526:
1527: sub warning {
1528: $warningcount++;
1529:
1530: if ($env{'form.grade_target'} ne 'tex') {
1531: if ( &show_error_warn_msg() ) {
1532: push(@Apache::lonxml::warning_messages,
1533: $Apache::lonxml::warnings_error_header.
1534: "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n");
1535: $Apache::lonxml::warnings_error_header='';
1536: }
1537: }
1538: }
1539:
1540: sub info {
1541: if ($env{'form.grade_target'} ne 'tex'
1542: && $env{'request.state'} eq 'construct') {
1543: push(@Apache::lonxml::info_messages,join('<br />',@_)."<br />\n");
1544: }
1545: }
1546:
1547: sub message_location {
1548: return '__LONCAPA_INTERNAL_MESSAGE_LOCATION__';
1549: }
1550:
1551: sub add_messages {
1552: my ($msg)=@_;
1553: my $result=join(' ',
1554: @Apache::lonxml::info_messages,
1555: @Apache::lonxml::error_messages,
1556: @Apache::lonxml::warning_messages);
1557: undef(@Apache::lonxml::info_messages);
1558: undef(@Apache::lonxml::error_messages);
1559: undef(@Apache::lonxml::warning_messages);
1560: $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__/$result/;
1561: $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__//g;
1562: }
1563:
1564: sub get_param {
1565: my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1566: if ( ! $context ) { $context = -1; }
1567: my $args ='';
1568: if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1569: if ( ! $Apache::lonxml::usestyle ) {
1570: $args=$Apache::lonxml::style_values.$args;
1571: }
1572: if ( ! $args ) { return undef; }
1573: if ( $case_insensitive ) {
1574: if ($args =~ s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei) {
1575: return &Apache::run::run("{$args;".'return $'.$param.'}',
1576: $safeeval); #'
1577: } else {
1578: return undef;
1579: }
1580: } else {
1581: if ( $args =~ /my \$\Q$param\E=\"/ ) {
1582: return &Apache::run::run("{$args;".'return $'.$param.'}',
1583: $safeeval); #'
1584: } else {
1585: return undef;
1586: }
1587: }
1588: }
1589:
1590: sub get_param_var {
1591: my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1592: if ( ! $context ) { $context = -1; }
1593: my $args ='';
1594: if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1595: if ( ! $Apache::lonxml::usestyle ) {
1596: $args=$Apache::lonxml::style_values.$args;
1597: }
1598: &Apache::lonxml::debug("Args are $args param is $param");
1599: if ($case_insensitive) {
1600: if (! ($args=~s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei)) {
1601: return undef;
1602: }
1603: } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
1604: my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1605: &Apache::lonxml::debug("first run is $value");
1606: if ($value =~ /^[\$\@\%][a-zA-Z_]\w*$/) {
1607: &Apache::lonxml::debug("doing second");
1608: my @result=&Apache::run::run("return $value",$safeeval,1);
1609: if (!defined($result[0])) {
1610: return $value
1611: } else {
1612: if (wantarray) { return @result; } else { return $result[0]; }
1613: }
1614: } else {
1615: return $value;
1616: }
1617: }
1618:
1619: sub register_insert {
1620: my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
1621: my $i;
1622: my $tagnum=0;
1623: my @order;
1624: for ($i=0;$i < $#data; $i++) {
1625: my $line = $data[$i];
1626: if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
1627: if ( $line =~ /TABLE/ ) { last; }
1628: my ($tag,$descrip,$color,$function,$show,$helpfile,$helpdesc) = split(/,/, $line);
1629: if ($tag) {
1630: $insertlist{"$tagnum.tag"} = $tag;
1631: $insertlist{"$tagnum.description"} = $descrip;
1632: $insertlist{"$tagnum.color"} = $color;
1633: $insertlist{"$tagnum.function"} = $function;
1634: if (!defined($show)) { $show='yes'; }
1635: $insertlist{"$tagnum.show"}= $show;
1636: $insertlist{"$tagnum.helpfile"} = $helpfile;
1637: $insertlist{"$tagnum.helpdesc"} = $helpdesc;
1638: $insertlist{"$tag.num"}=$tagnum;
1639: $tagnum++;
1640: }
1641: }
1642: $i++; #skipping TABLE line
1643: $tagnum = 0;
1644: for (;$i < $#data;$i++) {
1645: my $line = $data[$i];
1646: my ($mnemonic,@which) = split(/ +/,$line);
1647: my $tag = $insertlist{"$tagnum.tag"};
1648: for (my $j=0;$j <=$#which;$j++) {
1649: if ( $which[$j] eq 'Y' ) {
1650: if ($insertlist{"$j.show"} ne 'no') {
1651: push(@{ $insertlist{"$tag.which"} },$j);
1652: }
1653: }
1654: }
1655: $tagnum++;
1656: }
1657: }
1658:
1659: sub description {
1660: my ($token)=@_;
1661: my $tagnum;
1662: my $tag=$token->[1];
1663: foreach my $namespace (reverse @Apache::lonxml::namespace) {
1664: my $testtag=$namespace.'::'.$tag;
1665: $tagnum=$insertlist{"$testtag.num"};
1666: if (defined($tagnum)) { last; }
1667: }
1668: if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
1669: return $insertlist{$tagnum.'.description'};
1670: }
1671:
1672: # Returns a list containing the help file, and the description
1673: sub helpinfo {
1674: my ($token)=@_;
1675: my $tagnum;
1676: my $tag=$token->[1];
1677: foreach my $namespace (reverse @Apache::lonxml::namespace) {
1678: my $testtag=$namespace.'::'.$tag;
1679: $tagnum=$insertlist{"$testtag.num"};
1680: if (defined($tagnum)) { last; }
1681: }
1682: if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
1683: return ($insertlist{$tagnum.'.helpfile'}, $insertlist{$tagnum.'.helpdesc'});
1684: }
1685:
1686: # ----------------------------------------------------------------- whichuser
1687: # returns a list of $symb, $courseid, $domain, $name that is correct for
1688: # calls to lonnet functions for this setup.
1689: # - looks for form.grade_ parameters
1690: sub whichuser {
1691: my ($passedsymb)=@_;
1692: my ($symb,$courseid,$domain,$name,$publicuser);
1693: if (defined($env{'form.grade_symb'})) {
1694: my ($tmp_courseid)=
1695: &Apache::loncommon::get_env_multiple('form.grade_courseid');
1696: my $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid);
1697: if (!$allowed &&
1698: exists($env{'request.course.sec'}) &&
1699: $env{'request.course.sec'} !~ /^\s*$/) {
1700: $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid.
1701: '/'.$env{'request.course.sec'});
1702: }
1703: if ($allowed) {
1704: ($symb)=&Apache::loncommon::get_env_multiple('form.grade_symb');
1705: $courseid=$tmp_courseid;
1706: ($domain)=&Apache::loncommon::get_env_multiple('form.grade_domain');
1707: ($name)=&Apache::loncommon::get_env_multiple('form.grade_username');
1708: return ($symb,$courseid,$domain,$name,$publicuser);
1709: }
1710: }
1711: if (!$passedsymb) {
1712: $symb=&Apache::lonnet::symbread();
1713: } else {
1714: $symb=$passedsymb;
1715: }
1716: $courseid=$env{'request.course.id'};
1717: $domain=$env{'user.domain'};
1718: $name=$env{'user.name'};
1719: if ($name eq 'public' && $domain eq 'public') {
1720: if (!defined($env{'form.username'})) {
1721: $env{'form.username'}.=time.rand(10000000);
1722: }
1723: $name.=$env{'form.username'};
1724: }
1725: return ($symb,$courseid,$domain,$name,$publicuser);
1726: }
1727:
1728: 1;
1729: __END__
1730:
1731:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>