Annotation of loncom/xml/lonxml.pm, revision 1.128
1.2 sakharuk 1: # The LearningOnline Network with CAPA
1.3 sakharuk 2: # XML Parser Module
1.2 sakharuk 3: #
1.3 sakharuk 4: # last modified 06/26/00 by Alexander Sakharuk
1.33 www 5: # 11/6 Gerd Kortemeyer
1.45 www 6: # 6/1/1 Gerd Kortemeyer
1.56 albertel 7: # 2/21,3/13 Guy
1.68 www 8: # 3/29,5/4 Gerd Kortemeyer
1.73 harris41 9: # 5/10 Scott Harrison
1.78 www 10: # 5/26 Gerd Kortemeyer
1.80 harris41 11: # 5/27 H. K. Ng
1.89 www 12: # 6/2,6/3,6/8,6/9 Gerd Kortemeyer
1.93 ng 13: # 6/12,6/13 H. K. Ng
1.95 www 14: # 6/16 Gerd Kortemeyer
1.104 ng 15: # 7/27 H. K. Ng
1.127 www 16: # 8/7,8/9,8/10,8/11,8/15,8/16,8/17,8/18,8/20,8/23,8/24 Gerd Kortemeyer
1.2 sakharuk 17:
1.4 albertel 18: package Apache::lonxml;
1.33 www 19: use vars
1.76 albertel 20: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
1.1 sakharuk 21: use strict;
22: use HTML::TokeParser;
1.106 www 23: use HTML::TreeBuilder;
1.3 sakharuk 24: use Safe;
1.40 albertel 25: use Safe::Hole;
1.81 ng 26: use Math::Cephes qw(:trigs :hypers :bessels erf erfc);
1.91 ng 27: use Math::Random qw(:all);
1.13 albertel 28: use Opcode;
1.72 albertel 29:
30: sub register {
31: my $space;
32: my @taglist;
33: my $temptag;
34: ($space,@taglist) = @_;
35: foreach $temptag (@taglist) {
36: $Apache::lonxml::alltags{$temptag}=$space;
37: }
38: }
39:
1.46 www 40: use Apache::Constants qw(:common);
1.71 www 41: use Apache::lontexconvert;
1.72 albertel 42: use Apache::style;
43: use Apache::run;
44: use Apache::londefdef;
45: use Apache::scripttag;
46: use Apache::edit;
1.79 www 47: use Apache::lonnet;
48: use Apache::File;
49:
1.72 albertel 50: #================================================== Main subroutine: xmlparse
51: #debugging control, to turn on debugging modify the correct handler
52: $Apache::lonxml::debug=0;
53:
54: #path to the directory containing the file currently being processed
55: @pwd=();
56:
57: #these two are used for capturing a subset of the output for later processing,
58: #don't touch them directly use &startredirection and &endredirection
59: @outputstack = ();
60: $redirection = 0;
61:
62: #controls wheter the <import> tag actually does
63: $import = 1;
64: @extlinks=();
65:
66: # meta mode is a bit weird only some output is to be turned off
67: #<output> tag turns metamode off (defined in londefdef.pm)
68: $metamode = 0;
69:
70: # turns on and of run::evaluate actually derefencing var refs
71: $evaluate = 1;
1.7 albertel 72:
1.74 albertel 73: # data structure for eidt mode, determines what tags can go into what other tags
74: %insertlist=();
1.68 www 75:
1.99 albertel 76: # stores the list of active tag namespaces
1.76 albertel 77: @namespace=();
78:
1.99 albertel 79: # has the dynamic menu been updated to know about this resource
80: $Apache::lonxml::registered=0;
81:
1.68 www 82: sub xmlbegin {
83: my $output='';
84: if ($ENV{'browser.mathml'}) {
85: $output='<?xml version="1.0"?>'
86: .'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'
87: .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
88: .'[<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">]>'
89: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
90: .'xmlns="http://www.w3.org/TR/REC-html40">';
91: } else {
92: $output='<html>';
93: }
94: return $output;
95: }
96:
97: sub xmlend {
1.103 www 98: my $discussion='';
99: if ($ENV{'request.course.id'}) {
1.109 www 100: my $crs='/'.$ENV{'request.course.id'};
101: if ($ENV{'request.course.sec'}) {
102: $crs.='_'.$ENV{'request.course.sec'};
103: }
104: $crs=~s/\_/\//g;
105: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.103 www 106: my $symb=&Apache::lonnet::symbread();
107: if ($symb) {
108: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
109: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
110: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
111: if ($contrib{'version'}) {
112: $discussion.=
113: '<address><hr /><h2>Course Discussion of Resource</h2>';
114: my $idx;
115: for ($idx=1;$idx<=$contrib{'version'};$idx++) {
1.110 www 116: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
117: unless (($hidden) && (!$seeid)) {
118: my $message=$contrib{$idx.':message'};
119: $message=~s/\n/\<br \/\>/g;
120: if ($message) {
121: if ($hidden) {
122: $message='<font color="#888888">'.$message.'</font>';
123: }
1.109 www 124: my $sender='Anonymous';
125: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
126: $sender=$contrib{$idx.':sendername'}.' at '.
127: $contrib{$idx.':senderdomain'};
128: if ($contrib{$idx.':anonymous'}) {
129: $sender.=' (anonymous)';
1.110 www 130: }
131: if ($seeid) {
132: if ($hidden) {
133: $sender.=' <a href="/adm/feedback?unhide='.
134: $symb.':::'.$idx.'">Make Visible</a>';
135: } else {
136: $sender.=' <a href="/adm/feedback?hide='.
137: $symb.':::'.$idx.'">Hide</a>';
138: }
1.109 www 139: }
140: }
141: $discussion.='<p><b>'.$sender.'</b> ('.
1.103 www 142: localtime($contrib{$idx.':timestamp'}).
143: '):<blockquote>'.$message.
1.110 www 144: '</blockquote></p>';
145: }
146: }
1.103 www 147: }
148: $discussion.='</address>';
149: }
150: }
151: }
152: return $discussion.'</html>';
1.119 www 153: }
154:
155: sub tokeninputfield {
1.120 www 156: my $defhost=$Apache::lonnet::perlvar{'lonHostID'};
157: $defhost=~tr/a-z/A-Z/;
1.119 www 158: return (<<ENDINPUTFIELD)
1.120 www 159: <script>
160: function updatetoken() {
161: var comp=new Array;
162: var barcode=unescape(document.tokeninput.barcode.value);
163: comp=barcode.split('*');
164: if (typeof(comp[0])!="undefined") {
165: document.tokeninput.codeone.value=comp[0];
166: }
167: if (typeof(comp[1])!="undefined") {
168: document.tokeninput.codetwo.value=comp[1];
169: }
170: if (typeof(comp[2])!="undefined") {
171: comp[2]=comp[2].toUpperCase();
172: document.tokeninput.codethree.value=comp[2];
173: }
174: document.tokeninput.barcode.value='';
175: }
176: </script>
177: <form method="post" name="tokeninput">
1.119 www 178: <table border="2" bgcolor="#FFFFBB">
179: <tr><th>DocID Checkin</th></tr>
180: <tr><td>
181: <table>
182: <tr>
183: <td>Scan in Barcode</td>
1.120 www 184: <td><input type="text" size="22" name="barcode"
185: onChange="updatetoken()"/></td>
1.119 www 186: </tr>
187: <tr><td><i>or</i> Type in DocID</td>
188: <td>
189: <input type="text" size="5" name="codeone" />
1.120 www 190: <b><font size="+2">*</font></b>
1.119 www 191: <input type="text" size="5" name="codetwo" />
1.120 www 192: <b><font size="+2">*</font></b>
193: <input type="text" size="10" name="codethree" value="$defhost"
194: onChange="this.value=this.value.toUpperCase()" />
1.119 www 195: </td></tr>
196: </table>
197: </td></tr>
198: <tr><td><input type="submit" value="Check in DocID" /></td></tr>
199: </table>
200: </form>
201: ENDINPUTFIELD
1.112 www 202: }
203:
1.116 www 204: sub maketoken {
1.118 www 205: my ($symb,$tuname,$tudom,$tcrsid)=@_;
1.112 www 206: unless ($symb) {
207: $symb=&Apache::lonnet::symbread();
208: }
209: unless ($tuname) {
210: $tuname=$ENV{'user.name'};
211: $tudom=$ENV{'user.domain'};
212: $tcrsid=$ENV{'request.course.id'};
213: }
1.116 www 214:
1.118 www 215: return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid);
216: }
217:
218: sub printtokenheader {
219: my ($target,$token,$symb,$tuname,$tudom,$tcrsid)=@_;
1.116 www 220: unless ($token) { return ''; }
1.118 www 221:
222: unless ($symb) {
223: $symb=&Apache::lonnet::symbread();
224: }
225: unless ($tuname) {
226: $tuname=$ENV{'user.name'};
227: $tudom=$ENV{'user.domain'};
228: $tcrsid=$ENV{'request.course.id'};
229: }
1.114 www 230:
231: my %reply=&Apache::lonnet::get('environment',
232: ['firstname','middlename','lastname','generation'],
233: $tudom,$tuname);
234: my $plainname=$reply{'firstname'}.' '.
235: $reply{'middlename'}.' '.
236: $reply{'lastname'}.' '.
237: $reply{'generation'};
238:
1.112 www 239: if ($target eq 'web') {
1.115 www 240: return
241: '<img align="right" src="/cgi-bin/barcode.gif?encode='.$token.'" />'.
242: 'Checked out for '.$plainname.
1.114 www 243: '<br />User: '.$tuname.' at '.$tudom.
1.117 www 244: '<br />CourseID: '.$tcrsid.
1.114 www 245: '<br />DocID: '.$token.
1.116 www 246: '<br />Time: '.localtime().'<hr />';
1.112 www 247: } else {
1.121 albertel 248: return $token;
1.112 www 249: }
1.68 www 250: }
251:
1.70 www 252: sub fontsettings() {
253: my $headerstring='';
254: if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) {
255: $headerstring.=
256: '<meta Content-Type="text/html; charset=x-mac-roman">';
257: }
258: return $headerstring;
259: }
260:
1.68 www 261: sub registerurl {
1.100 www 262: my $forcereg=shift;
1.128 ! albertel 263: if ($Apache::lonxml::registered && !$forcereg) { return ''; }
1.105 albertel 264: $Apache::lonxml::registered=1;
1.100 www 265: if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
1.87 www 266: my $hwkadd='';
267: if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
268: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
269: $hwkadd.=(<<ENDSUBM);
270: menu.switchbutton
271: (7,1,'subm.gif','view sub','missions',
1.88 www 272: 'gocmd("/adm/grades","submission")');
1.87 www 273: ENDSUBM
274: }
275: if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
276: $hwkadd.=(<<ENDGRDS);
277: menu.switchbutton
278: (7,2,'pgrd.gif','problem','grades',
1.88 www 279: 'gocmd("/adm/grades","viewgrades")');
1.87 www 280: ENDGRDS
281: }
282: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
283: $hwkadd.=(<<ENDPARM);
284: menu.switchbutton
285: (7,3,'pparm.gif','problem','parms',
1.88 www 286: 'gocmd("/adm/parmset","set")');
1.87 www 287: ENDPARM
288: }
289: }
1.86 www 290: return (<<ENDREGTHIS);
1.87 www 291:
1.68 www 292: <script language="JavaScript">
1.71 www 293: // BEGIN LON-CAPA Internal
1.86 www 294:
1.69 www 295: function LONCAPAreg() {
296: menu=window.open("","LONCAPAmenu");
1.86 www 297: menu.clearTimeout(menu.menucltim);
1.69 www 298: menu.currentURL=window.location.pathname;
299: menu.currentStale=0;
1.85 www 300: menu.clearbut(3,1);
301: menu.switchbutton
1.108 www 302: (6,3,'catalog.gif','catalog','info','catalog_info()');
303: menu.switchbutton
1.85 www 304: (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)');
305: menu.switchbutton
306: (8,2,'fdbk.gif','feedback','on this','gopost("/adm/feedback",currentURL)');
307: menu.switchbutton
308: (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)');
309: menu.switchbutton
310: (2,1,'back.gif','backward','','gopost("/adm/flip","back:"+currentURL)');
311: menu.switchbutton
312: (2,3,'forw.gif','forward','','gopost("/adm/flip","forward:"+currentURL)');
1.94 www 313: menu.switchbutton
314: (9,1,'sbkm.gif','set','bookmark','set_bookmark()');
315: menu.switchbutton
316: (9,2,'vbkm.gif','view','bookmark','edit_bookmarks()');
317: menu.switchbutton
1.95 www 318: (9,3,'anot.gif','anno-','tations','annotate()');
1.87 www 319: $hwkadd
1.69 www 320: }
1.86 www 321:
1.69 www 322: function LONCAPAstale() {
1.86 www 323: menu=window.open("","LONCAPAmenu");
324: menu.currentStale=1;
1.127 www 325: menu.switchbutton
326: (3,1,'reload.gif','return','location','go(currentURL)');
327: menu.clearbut(7,1);
328: menu.clearbut(7,2);
329: menu.clearbut(7,3);
1.86 www 330: menu.menucltim=menu.setTimeout(
1.94 www 331: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.108 www 332: 'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3)',
1.86 www 333: 2000);
334:
1.87 www 335: }
1.86 www 336:
337: // END LON-CAPA Internal
338: </script>
339: ENDREGTHIS
340:
341: } else {
342: return (<<ENDDONOTREGTHIS);
343:
344: <script language="JavaScript">
345: // BEGIN LON-CAPA Internal
346:
347: function LONCAPAreg() {
1.69 www 348: menu=window.open("","LONCAPAmenu");
349: menu.currentStale=1;
1.85 www 350: menu.clearbut(2,1);
351: menu.clearbut(2,3);
352: menu.clearbut(8,1);
353: menu.clearbut(8,2);
354: menu.clearbut(8,3);
1.86 www 355: if (menu.currentURL) {
356: menu.switchbutton
357: (3,1,'reload.gif','return','location','go(currentURL)');
358: } else {
359: menu.clearbut(3,1);
360: }
361: }
362:
363: function LONCAPAstale() {
1.68 www 364: }
1.86 www 365:
1.71 www 366: // END LON-CAPA Internal
1.68 www 367: </script>
1.86 www 368: ENDDONOTREGTHIS
369:
370: }
1.69 www 371: }
372:
373: sub loadevents() {
374: return 'LONCAPAreg();';
375: }
376:
377: sub unloadevents() {
378: return 'LONCAPAstale();';
1.68 www 379: }
380:
1.48 albertel 381: sub printalltags {
382: my $temp;
383: foreach $temp (sort keys %Apache::lonxml::alltags) {
1.64 albertel 384: &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
1.48 albertel 385: }
386: }
1.31 sakharuk 387:
1.3 sakharuk 388: sub xmlparse {
1.18 albertel 389: my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
1.96 albertel 390:
391: &setup_globals($target);
1.48 albertel 392: #&printalltags();
1.16 albertel 393: my @pars = ();
1.23 albertel 394: my $pwd=$ENV{'request.filename'};
395: $pwd =~ s:/[^/]*$::;
396: &newparser(\@pars,\$content_file_string,$pwd);
1.24 sakharuk 397:
1.3 sakharuk 398: my $safeeval = new Safe;
1.40 albertel 399: my $safehole = new Safe::Hole;
1.82 ng 400: &init_safespace($target,$safeeval,$safehole,$safeinit);
1.3 sakharuk 401: #-------------------- Redefinition of the target in the case of compound target
402:
403: ($target, my @tenta) = split('&&',$target);
404:
405: my @stack = ();
406: my @parstack = ();
1.17 albertel 407: &initdepth;
1.67 www 408:
1.101 albertel 409: my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
410: $safeeval,\%style_for_target);
1.125 www 411: if ($ENV{'request.uri'}) {
412: &writeallows($ENV{'request.uri'});
413: }
1.3 sakharuk 414: return $finaloutput;
1.106 www 415: }
416:
417: sub htmlclean {
1.107 www 418: my ($raw,$full)=@_;
1.106 www 419:
420: my $tree = HTML::TreeBuilder->new;
421: $tree->ignore_unknown(0);
422:
423: $tree->parse($raw);
424:
1.107 www 425: my $output= $tree->as_HTML(undef,' ');
1.106 www 426:
1.111 www 427: $output=~s/\<(br|hr|img|meta|allow)([^\>\/]*)\>/\<$1$2 \/\>/gis;
428: $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
1.107 www 429: unless ($full) {
430: $output=~s/\<[\/]*(body|head|html)\>//gis;
431: }
1.106 www 432:
433: $tree = $tree->delete;
434:
435: return $output;
1.15 albertel 436: }
437:
1.101 albertel 438: sub inner_xmlparse {
439: my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
440: my $finaloutput = '';
441: my $result;
442: my $token;
443: while ( $#$pars > -1 ) {
444: while ($token = $$pars['-1']->get_token) {
445: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
446: if ($metamode<1) {
447: $result=$token->[1];
448: }
449: } elsif ($token->[0] eq 'PI') {
450: if ($metamode<1) {
451: $result=$token->[2];
452: }
453: } elsif ($token->[0] eq 'S') {
454: # add tag to stack
455: push (@$stack,$token->[1]);
456: # add parameters list to another stack
457: push (@$parstack,&parstring($token));
458: &increasedepth($token);
459: if (exists $$style_for_target{$token->[1]}) {
460: if ($Apache::lonxml::redirection) {
461: $Apache::lonxml::outputstack['-1'] .=
462: &recurse($$style_for_target{$token->[1]},$target,$safeeval,
463: $style_for_target,@$parstack);
464: } else {
465: $finaloutput .= &recurse($$style_for_target{$token->[1]},$target,
466: $safeeval,$style_for_target,@$parstack);
467: }
468: } else {
469: $result = &callsub("start_$token->[1]", $target, $token, $stack,
470: $parstack, $pars, $safeeval, $style_for_target);
471: }
472: } elsif ($token->[0] eq 'E') {
473: #clear out any tags that didn't end
474: while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
475: &Apache::lonxml::warning("Unbalanced tags in resource $$stack['-1']");
476: &end_tag($stack,$parstack,$token);
477: }
478:
479: if (exists $$style_for_target{'/'."$token->[1]"}) {
480: if ($Apache::lonxml::redirection) {
481: $Apache::lonxml::outputstack['-1'] .=
482: &recurse($$style_for_target{'/'."$token->[1]"},
483: $target,$safeeval,$style_for_target,@$parstack);
484: } else {
485: $finaloutput .= &recurse($$style_for_target{'/'."$token->[1]"},
486: $target,$safeeval,$style_for_target,
487: @$parstack);
488: }
489:
490: } else {
491: $result = &callsub("end_$token->[1]", $target, $token, $stack,
492: $parstack, $pars,$safeeval, $style_for_target);
493: }
494: } else {
495: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
496: }
497: #evaluate variable refs in result
498: if ($result ne "") {
499: if ( $#$parstack > -1 ) {
500: if ($Apache::lonxml::redirection) {
501: $Apache::lonxml::outputstack['-1'] .=
502: &Apache::run::evaluate($result,$safeeval,$$parstack['-1']);
503: } else {
504: $finaloutput .= &Apache::run::evaluate($result,$safeeval,
505: $$parstack['-1']);
506: }
507: } else {
508: $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
509: }
510: $result = '';
511: }
512: if ($token->[0] eq 'E') {
513: &end_tag($stack,$parstack,$token);
514: }
515: }
516: pop @$pars;
517: pop @Apache::lonxml::pwd;
518: }
519:
520: # if ($target eq 'meta') {
521: # $finaloutput.=&endredirection;
522: # }
523:
524: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
525: $finaloutput=&afterburn($finaloutput);
526: }
527: return $finaloutput;
528: }
1.67 www 529:
1.15 albertel 530: sub recurse {
531: my @innerstack = ();
532: my @innerparstack = ();
533: my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
1.16 albertel 534: my @pat = ();
1.23 albertel 535: &newparser(\@pat,\$newarg);
1.15 albertel 536: my $tokenpat;
537: my $partstring = '';
538: my $output='';
1.16 albertel 539: my $decls='';
540: while ( $#pat > -1 ) {
541: while ($tokenpat = $pat[$#pat]->get_token) {
1.57 albertel 542: if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
1.61 albertel 543: if ($metamode<1) { $partstring=$tokenpat->[1]; }
1.57 albertel 544: } elsif ($tokenpat->[0] eq 'PI') {
1.61 albertel 545: if ($metamode<1) { $partstring=$tokenpat->[2]; }
1.16 albertel 546: } elsif ($tokenpat->[0] eq 'S') {
547: push (@innerstack,$tokenpat->[1]);
548: push (@innerparstack,&parstring($tokenpat));
1.19 albertel 549: &increasedepth($tokenpat);
1.84 albertel 550: $partstring = &callsub("start_$tokenpat->[1]", $target, $tokenpat,
551: \@innerstack, \@innerparstack, \@pat,
552: $safeeval, $style_for_target);
1.16 albertel 553: } elsif ($tokenpat->[0] eq 'E') {
554: #clear out any tags that didn't end
555: while ($tokenpat->[1] ne $innerstack[$#innerstack]
1.43 albertel 556: && ($#innerstack > -1)) {
1.49 albertel 557: &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
1.97 albertel 558: &end_tag(\@innerstack,\@innerparstack,$tokenpat);
1.43 albertel 559: }
1.84 albertel 560: $partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat,
561: \@innerstack, \@innerparstack, \@pat,
562: $safeeval, $style_for_target);
1.57 albertel 563: } else {
564: &Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
1.16 albertel 565: }
566: #pass both the variable to the style tag, and the tag we
567: #are processing inside the <definedtag>
568: if ( $partstring ne "" ) {
569: if ( $#parstack > -1 ) {
570: if ( $#innerparstack > -1 ) {
571: $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
572: } else {
573: $decls= $parstack[$#parstack];
574: }
575: } else {
576: if ( $#innerparstack > -1 ) {
577: $decls=$innerparstack[$#innerparstack];
578: } else {
579: $decls='';
580: }
581: }
582: $output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
583: $partstring = '';
584: }
1.17 albertel 585: if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
1.19 albertel 586: &decreasedepth($tokenpat);}
1.15 albertel 587: }
1.16 albertel 588: pop @pat;
1.23 albertel 589: pop @Apache::lonxml::pwd;
1.15 albertel 590: }
591: return $output;
1.7 albertel 592: }
593:
594: sub callsub {
1.84 albertel 595: my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.7 albertel 596: my $currentstring='';
1.72 albertel 597: my $nodefault;
1.7 albertel 598: {
1.59 albertel 599: my $sub1;
1.7 albertel 600: no strict 'refs';
1.68 www 601: my $tag=$token->[1];
602: my $space=$Apache::lonxml::alltags{$tag};
603: if (!$space) {
604: $tag=~tr/A-Z/a-z/;
605: $sub=~tr/A-Z/a-z/;
606: $space=$Apache::lonxml::alltags{$tag}
607: }
1.97 albertel 608:
609: my $deleted=0;
610: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
611: if (($token->[0] eq 'S') && ($target eq 'modified')) {
612: $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
613: $parstack,$parser,$safeeval,
614: $style);
615: }
616: if (!$deleted) {
617: if ($space) {
618: #&Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
619: $sub1="$space\:\:$sub";
620: ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
621: $parstack,$parser,$safeeval,
622: $style);
623: } else {
624: #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
625: if ($metamode <1) {
626: if (defined($token->[4]) && ($metamode < 1)) {
627: $currentstring = $token->[4];
628: } else {
629: $currentstring = $token->[2];
630: }
1.62 sakharuk 631: }
1.7 albertel 632: }
1.97 albertel 633: # &Apache::lonxml::debug("nodefalt:$nodefault:");
634: if ($currentstring eq '' && $nodefault eq '') {
635: if ($target eq 'edit') {
636: &Apache::lonxml::debug("doing default edit for $token->[1]");
637: if ($token->[0] eq 'S') {
638: $currentstring = &Apache::edit::tag_start($target,$token);
639: } elsif ($token->[0] eq 'E') {
640: $currentstring = &Apache::edit::tag_end($target,$token);
641: }
642: } elsif ($target eq 'modified') {
643: if ($token->[0] eq 'S') {
644: $currentstring = $token->[4];
645: $currentstring.=&Apache::edit::handle_insert();
646: } else {
647: $currentstring = $token->[2];
648: }
1.72 albertel 649: }
650: }
1.7 albertel 651: }
652: use strict 'refs';
653: }
654: return $currentstring;
1.82 ng 655: }
656:
1.96 albertel 657: sub setup_globals {
658: my ($target)=@_;
1.99 albertel 659: $Apache::lonxml::registered = 0;
1.101 albertel 660: @Apache::lonxml::pwd=();
1.124 albertel 661: @Apache::lonxml::extlinks=();
1.96 albertel 662: if ($target eq 'meta') {
663: $Apache::lonxml::redirection = 0;
664: $Apache::lonxml::metamode = 1;
665: $Apache::lonxml::evaluate = 1;
666: $Apache::lonxml::import = 0;
667: } elsif ($target eq 'grade') {
668: &startredirection;
669: $Apache::lonxml::metamode = 0;
670: $Apache::lonxml::evaluate = 1;
671: $Apache::lonxml::import = 1;
672: } elsif ($target eq 'modified') {
673: $Apache::lonxml::redirection = 0;
674: $Apache::lonxml::metamode = 0;
675: $Apache::lonxml::evaluate = 0;
676: $Apache::lonxml::import = 0;
677: } elsif ($target eq 'edit') {
678: $Apache::lonxml::redirection = 0;
679: $Apache::lonxml::metamode = 0;
680: $Apache::lonxml::evaluate = 0;
681: $Apache::lonxml::import = 0;
682: } else {
683: $Apache::lonxml::redirection = 0;
684: $Apache::lonxml::metamode = 0;
685: $Apache::lonxml::evaluate = 1;
686: $Apache::lonxml::import = 1;
687: }
688: }
689:
1.82 ng 690: sub init_safespace {
691: my ($target,$safeeval,$safehole,$safeinit) = @_;
692: $safeeval->permit("entereval");
693: $safeeval->permit(":base_math");
694: $safeeval->permit("sort");
695: $safeeval->deny(":base_io");
1.102 albertel 696: $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
1.82 ng 697: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
698:
699: $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
700: $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
701: $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
702: $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
703: $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
704: $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
705: $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
706: $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
707: $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
708: $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
709: $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
710: $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
711: $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
712: $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
713: $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
714: $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
715: $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
716: $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
717: $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
1.91 ng 718: $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
719: $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
720: $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
721: $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
722: $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
723: $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
724: $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
725: $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
726: $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
727: $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
728: $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
1.93 ng 729: $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
1.91 ng 730: $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
731: $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
732: $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
733: $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
734: $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
735: $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
736: $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
737: $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
738: $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
739:
1.82 ng 740: #need to inspect this class of ops
741: # $safeeval->deny(":base_orig");
1.91 ng 742: $safeinit .= ';$external::target="'.$target.'";';
1.121 albertel 743: my $rndseed;
1.123 albertel 744: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
745: $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
1.121 albertel 746: $safeinit .= ';$external::randomseed='.$rndseed.';';
1.82 ng 747: &Apache::run::run($safeinit,$safeeval);
1.17 albertel 748: }
749:
1.55 albertel 750: sub startredirection {
751: $Apache::lonxml::redirection++;
752: push (@Apache::lonxml::outputstack, '');
753: }
754:
755: sub endredirection {
756: if (!$Apache::lonxml::redirection) {
1.72 albertel 757: &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
1.55 albertel 758: return '';
759: }
760: $Apache::lonxml::redirection--;
761: pop @Apache::lonxml::outputstack;
1.97 albertel 762: }
763:
764: sub end_tag {
765: my ($tagstack,$parstack,$token)=@_;
766: pop(@$tagstack);
767: pop(@$parstack);
768: &decreasedepth($token);
1.55 albertel 769: }
770:
1.17 albertel 771: sub initdepth {
772: @Apache::lonxml::depthcounter=();
773: $Apache::lonxml::depth=-1;
774: $Apache::lonxml::olddepth=-1;
775: }
776:
777: sub increasedepth {
1.19 albertel 778: my ($token) = @_;
1.17 albertel 779: $Apache::lonxml::depth++;
780: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
781: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
782: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
783: }
1.42 albertel 784: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 785: &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54 albertel 786: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17 albertel 787: }
788:
789: sub decreasedepth {
1.19 albertel 790: my ($token) = @_;
1.17 albertel 791: $Apache::lonxml::depth--;
1.36 albertel 792: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
793: $#Apache::lonxml::depthcounter--;
794: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
795: }
1.43 albertel 796: if ( $Apache::lonxml::depth < -1) {
1.49 albertel 797: &Apache::lonxml::warning("Unbalanced tags in resource");
1.43 albertel 798: $Apache::lonxml::depth='-1';
799: }
1.42 albertel 800: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 801: &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54 albertel 802: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1 sakharuk 803: }
1.19 albertel 804:
805: sub get_all_text {
806:
807: my($tag,$pars)= @_;
808: my $depth=0;
809: my $token;
810: my $result='';
1.57 albertel 811: if ( $tag =~ m:^/: ) {
812: my $tag=substr($tag,1);
813: # &Apache::lonxml::debug("have:$tag:");
814: while (($depth >=0) && ($token = $pars->get_token)) {
815: # &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
816: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
817: $result.=$token->[1];
818: } elsif ($token->[0] eq 'PI') {
819: $result.=$token->[2];
820: } elsif ($token->[0] eq 'S') {
821: if ($token->[1] eq $tag) { $depth++; }
822: $result.=$token->[4];
823: } elsif ($token->[0] eq 'E') {
824: if ( $token->[1] eq $tag) { $depth--; }
825: #skip sending back the last end tag
826: if ($depth > -1) { $result.=$token->[2]; } else {
827: $pars->unget_token($token);
828: }
829: }
830: }
831: } else {
832: while ($token = $pars->get_token) {
833: # &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
834: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
835: $result.=$token->[1];
836: } elsif ($token->[0] eq 'PI') {
837: $result.=$token->[2];
838: } elsif ($token->[0] eq 'S') {
839: if ( $token->[1] eq $tag) {
840: $pars->unget_token($token); last;
841: } else {
842: $result.=$token->[4];
843: }
844: } elsif ($token->[0] eq 'E') {
845: $result.=$token->[2];
1.36 albertel 846: }
1.19 albertel 847: }
848: }
1.49 albertel 849: # &Apache::lonxml::debug("Exit:$result:");
1.19 albertel 850: return $result
851: }
852:
1.23 albertel 853: sub newparser {
854: my ($parser,$contentref,$dir) = @_;
855: push (@$parser,HTML::TokeParser->new($contentref));
1.56 albertel 856: $$parser['-1']->xml_mode('1');
1.23 albertel 857: if ( $dir eq '' ) {
858: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
859: } else {
860: push (@Apache::lonxml::pwd, $dir);
861: }
862: # &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
863: # &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
864: }
1.1 sakharuk 865:
1.8 albertel 866: sub parstring {
867: my ($token) = @_;
868: my $temp='';
1.20 albertel 869: map {
1.35 www 870: unless ($_=~/\W/) {
1.42 albertel 871: my $val=$token->[2]->{$_};
1.53 albertel 872: $val =~ s/([\%\@\\])/\\$1/g;
1.51 albertel 873: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42 albertel 874: $temp .= "my \$$_=\"$val\";"
1.20 albertel 875: }
876: } @{$token->[3]};
1.8 albertel 877: return $temp;
878: }
1.22 albertel 879:
1.34 www 880: sub writeallows {
1.126 www 881: unless ($#extlinks>=0) { return; }
1.34 www 882: my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
1.111 www 883: if ($ENV{'httpref.'.$thisurl}) {
884: $thisurl=$ENV{'httpref.'.$thisurl};
885: }
1.34 www 886: my $thisdir=$thisurl;
887: $thisdir=~s/\/[^\/]+$//;
888: my %httpref=();
889: map {
890: $httpref{'httpref.'.
1.125 www 891: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
892: } @extlinks;
1.126 www 893: @extlinks=();
1.34 www 894: &Apache::lonnet::appenv(%httpref);
895: }
896:
1.66 www 897: #
898: # Afterburner handles anchors, highlights and links
899: #
900: sub afterburn {
901: my $result=shift;
902: map {
903: my ($name, $value) = split(/=/,$_);
904: $value =~ tr/+/ /;
905: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
906: if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
907: unless ($ENV{'form.'.$name}) {
908: $ENV{'form.'.$name}=$value;
909: }
910: }
911: } (split(/&/,$ENV{'QUERY_STRING'}));
912: if ($ENV{'form.highlight'}) {
913: map {
914: my $anchorname=$_;
915: my $matchthis=$anchorname;
916: $matchthis=~s/\_+/\\s\+/g;
917: $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
918: } split(/\,/,$ENV{'form.highlight'});
919: }
920: if ($ENV{'form.link'}) {
921: map {
922: my ($anchorname,$linkurl)=split(/\>/,$_);
923: my $matchthis=$anchorname;
924: $matchthis=~s/\_+/\\s\+/g;
925: $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
926: } split(/\,/,$ENV{'form.link'});
927: }
928: if ($ENV{'form.anchor'}) {
929: my $anchorname=$ENV{'form.anchor'};
930: my $matchthis=$anchorname;
931: $matchthis=~s/\_+/\\s\+/g;
932: $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
933: $result.=(<<"ENDSCRIPT");
934: <script>
935: document.location.hash='$anchorname';
936: </script>
937: ENDSCRIPT
938: }
939: return $result;
940: }
941:
1.79 www 942: sub storefile {
943: my ($file,$contents)=@_;
944: if (my $fh=Apache::File->new('>'.$file)) {
945: print $fh $contents;
946: $fh->close();
947: }
948: }
949:
1.78 www 950: sub inserteditinfo {
951: my ($result,$filecontents)=@_;
952: unless ($filecontents) {
953: $filecontents=(<<SIMPLECONTENT);
954: <html>
955: <head>
956: <title>
957: Title of Document Goes Here
958: </title>
959: </head>
960: <body bgcolor="#FFFFFF">
961:
962: Body of Document Goes Here
963:
964: </body>
965: </html>
966: SIMPLECONTENT
967: }
968: my $editheader='<a href="#editsection">Edit below</a><hr />';
969: my $editfooter=(<<ENDFOOTER);
970: <hr />
971: <a name="editsection" />
972: <form method="post">
973: <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
974: <br />
1.107 www 975: <input type="submit" name="attemptclean"
976: value="Save and then attempt to clean HTML" />
977: <input type="submit" name="savethisfile" value="Save this" />
1.78 www 978: </form>
979: ENDFOOTER
980: $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
981: $result=~s/(\<\/body\>)/$editfooter/is;
982: return $result;
983: }
984:
1.24 sakharuk 985: sub handler {
986: my $request=shift;
1.68 www 987:
1.64 albertel 988: my $target='web';
1.68 www 989:
1.65 albertel 990: $Apache::lonxml::debug=0;
1.68 www 991:
1.25 sakharuk 992: if ($ENV{'browser.mathml'}) {
1.27 albertel 993: $request->content_type('text/xml');
994: } else {
995: $request->content_type('text/html');
1.25 sakharuk 996: }
1.64 albertel 997:
1.27 albertel 998: $request->send_http_header;
1.64 albertel 999:
1.45 www 1000: return OK if $request->header_only;
1.27 albertel 1001:
1.79 www 1002:
1003: my $file=&Apache::lonnet::filelocation("",$request->uri);
1.78 www 1004: #
1005: # Edit action? Save file.
1006: #
1007: unless ($ENV{'request.state'} eq 'published') {
1.107 www 1008: if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
1.79 www 1009: &storefile($file,$ENV{'form.filecont'});
1.78 www 1010: }
1011: }
1.24 sakharuk 1012: my %mystyle;
1.50 albertel 1013: my $result = '';
1014: my $filecontents=&Apache::lonnet::getfile($file);
1015: if ($filecontents == -1) {
1.78 www 1016: $result=(<<ENDNOTFOUND);
1017: <html>
1018: <head>
1019: <title>File not found</title>
1020: </head>
1021: <body bgcolor="#FFFFFF">
1022: <b>File not found: $file</b>
1023: </body>
1024: </html>
1025: ENDNOTFOUND
1.50 albertel 1026: $filecontents='';
1027: } else {
1.107 www 1028: unless ($ENV{'request.state'} eq 'published') {
1029: if ($ENV{'form.attemptclean'}) {
1030: $filecontents=&htmlclean($filecontents,1);
1031: }
1032: }
1.50 albertel 1033: $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
1.78 www 1034: }
1035:
1036: #
1037: # Edit action? Insert editing commands
1038: #
1039: unless ($ENV{'request.state'} eq 'published') {
1040: $result=&inserteditinfo($result,$filecontents);
1.66 www 1041: }
1.126 www 1042:
1043: writeallows($request->uri);
1.50 albertel 1044:
1.67 www 1045: $request->print($result);
1.64 albertel 1046:
1.45 www 1047: return OK;
1.24 sakharuk 1048: }
1049:
1.22 albertel 1050: sub debug {
1051: if ($Apache::lonxml::debug eq 1) {
1.96 albertel 1052: print("DEBUG:".$_[0]."<br />\n");
1.22 albertel 1053: }
1054: }
1.49 albertel 1055:
1.22 albertel 1056: sub error {
1.74 albertel 1057: if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
1.55 albertel 1058: print "<b>ERROR:</b>".$_[0]."<br />\n";
1.52 albertel 1059: } else {
1060: print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
1061: #notify author
1062: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
1063: #notify course
1064: if ( $ENV{'request.course.id'} ) {
1065: my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
1066: foreach my $user (split /\,/, $users) {
1067: ($user,my $domain) = split /:/, $user;
1.54 albertel 1068: &Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 1069: }
1070: }
1.74 albertel 1071:
1.52 albertel 1072: #FIXME probably shouldn't have me get everything forever.
1.54 albertel 1073: &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
1.74 albertel 1074: #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 1075: }
1.22 albertel 1076: }
1.49 albertel 1077:
1.22 albertel 1078: sub warning {
1.73 harris41 1079: if ($ENV{'request.state'} eq 'construct') {
1.55 albertel 1080: print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
1.73 harris41 1081: }
1.83 albertel 1082: }
1083:
1084: sub get_param {
1085: my ($param,$parstack,$safeeval,$context) = @_;
1086: if ( ! $context ) { $context = -1; }
1087: my $args ='';
1088: if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1089: return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1.22 albertel 1090: }
1091:
1.74 albertel 1092: sub register_insert {
1.75 albertel 1093: my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
1.74 albertel 1094: my $i;
1.76 albertel 1095: my $tagnum=0;
1.74 albertel 1096: my @order;
1097: for ($i=0;$i < $#data; $i++) {
1098: my $line = $data[$i];
1099: if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
1100: if ( $line =~ /TABLE/ ) { last; }
1.92 albertel 1101: my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);
1.76 albertel 1102: $insertlist{"$tagnum.tag"} = $tag;
1103: $insertlist{"$tagnum.description"} = $descrip;
1.92 albertel 1104: $insertlist{"$tagnum.color"} = $color;
1.76 albertel 1105: $insertlist{"$tagnum.function"} = $function;
1106: $insertlist{"$tagnum.show"}= $show;
1.92 albertel 1107: $insertlist{"$tag.num"}=$tagnum;
1.76 albertel 1108: $tagnum++;
1.74 albertel 1109: }
1.76 albertel 1110: $i++; #skipping TABLE line
1111: $tagnum = 0;
1.74 albertel 1112: for (;$i < $#data;$i++) {
1113: my $line = $data[$i];
1.76 albertel 1114: my ($mnemonic,@which) = split(/ +/,$line);
1115: my $tag = $insertlist{"$tagnum.tag"};
1.74 albertel 1116: for (my $j=0;$j <$#which;$j++) {
1117: if ( $which[$j] eq 'Y' ) {
1.76 albertel 1118: if ($insertlist{"$j.show"} ne 'no') {
1119: push(@{ $insertlist{"$tag.which"} },$j);
1120: }
1.74 albertel 1121: }
1122: }
1.76 albertel 1123: $tagnum++;
1.74 albertel 1124: }
1125: }
1.98 albertel 1126:
1127: sub description {
1128: my ($token)=@_;
1129: return $insertlist{$insertlist{"$token->[1].num"}.'.description'};
1130: }
1.123 albertel 1131:
1132: # ----------------------------------------------------------------- whichuser
1133: # returns a list of $symb, $courseid, $domain, $name that is correct for
1134: # calls to lonnet functions for this setup.
1135: # - looks for form.grade_ parameters
1136: sub whichuser {
1137: my $symb=&Apache::lonnet::symbread();
1138: my $courseid=$ENV{'request.course.id'};
1139: my $domain=$ENV{'user.domain'};
1140: my $name=$ENV{'user.name'};
1141: if (defined($ENV{'form.grade_symb'})) {
1142: my $tmp_courseid=$ENV{'form.grade_courseid'};
1143: my $allowed=&Apache::lonnet::allowed('mgr',$tmp_courseid);
1144: if ($allowed) {
1145: $symb=$ENV{'form.grade_symb'};
1146: $courseid=$ENV{'form.grade_courseid'};
1147: $domain=$ENV{'form.grade_domain'};
1148: $name=$ENV{'form.grade_username'};
1149: }
1150: }
1151: return ($symb,$courseid,$domain,$name);
1152: }
1153:
1.1 sakharuk 1154: 1;
1155: __END__
1.68 www 1156:
1157:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>