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