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