Annotation of loncom/xml/lonxml.pm, revision 1.224
1.2 sakharuk 1: # The LearningOnline Network with CAPA
1.3 sakharuk 2: # XML Parser Module
1.2 sakharuk 3: #
1.224 ! albertel 4: # $Id: lonxml.pm,v 1.223 2003/01/07 17:02:10 albertel Exp $
1.139 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
1.3 sakharuk 39: # last modified 06/26/00 by Alexander Sakharuk
1.33 www 40: # 11/6 Gerd Kortemeyer
1.45 www 41: # 6/1/1 Gerd Kortemeyer
1.56 albertel 42: # 2/21,3/13 Guy
1.68 www 43: # 3/29,5/4 Gerd Kortemeyer
1.73 harris41 44: # 5/10 Scott Harrison
1.78 www 45: # 5/26 Gerd Kortemeyer
1.80 harris41 46: # 5/27 H. K. Ng
1.89 www 47: # 6/2,6/3,6/8,6/9 Gerd Kortemeyer
1.93 ng 48: # 6/12,6/13 H. K. Ng
1.95 www 49: # 6/16 Gerd Kortemeyer
1.104 ng 50: # 7/27 H. K. Ng
1.127 www 51: # 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 52: # Guy Albertelli
53: # 9/26 Gerd Kortemeyer
1.143 www 54: # Dec Guy Albertelli
55: # YEAR=2002
56: # 1/1 Gerd Kortemeyer
1.145 www 57: # 1/2 Matthew Hall
58: # 1/3 Gerd Kortemeyer
1.143 www 59: #
1.2 sakharuk 60:
1.4 albertel 61: package Apache::lonxml;
1.33 www 62: use vars
1.205 www 63: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode $errorcount $warningcount);
1.1 sakharuk 64: use strict;
1.167 albertel 65: use HTML::LCParser();
1.161 albertel 66: use HTML::TreeBuilder();
67: use HTML::Entities();
68: use Safe();
69: use Safe::Hole();
70: use Math::Cephes();
71: use Math::Random();
72: use Opcode();
1.72 albertel 73:
74: sub register {
1.141 albertel 75: my ($space,@taglist) = @_;
76: foreach my $temptag (@taglist) {
77: push(@{ $Apache::lonxml::alltags{$temptag} },$space);
1.72 albertel 78: }
79: }
80:
1.141 albertel 81: sub deregister {
82: my ($space,@taglist) = @_;
83: foreach my $temptag (@taglist) {
84: my $tempspace = $Apache::lonxml::alltags{$temptag}[-1];
85: if ($tempspace eq $space) {
86: pop(@{ $Apache::lonxml::alltags{$temptag} });
87: }
88: }
1.142 albertel 89: #&printalltags();
1.141 albertel 90: }
91:
1.46 www 92: use Apache::Constants qw(:common);
1.161 albertel 93: use Apache::lontexconvert();
94: use Apache::style();
95: use Apache::run();
96: use Apache::londefdef();
97: use Apache::scripttag();
98: use Apache::edit();
99: use Apache::lonnet();
100: use Apache::File();
101: use Apache::loncommon();
1.198 www 102: use Apache::lonfeedback();
1.200 www 103: use Apache::lonmsg();
1.217 matthew 104: use Apache::loncacc();
1.79 www 105:
1.72 albertel 106: #================================================== Main subroutine: xmlparse
107: #debugging control, to turn on debugging modify the correct handler
108: $Apache::lonxml::debug=0;
1.206 albertel 109:
110: # keeps count of the number of warnings and errors generated in a parse
111: $warningcount=0;
112: $errorcount=0;
1.72 albertel 113:
114: #path to the directory containing the file currently being processed
115: @pwd=();
116:
117: #these two are used for capturing a subset of the output for later processing,
118: #don't touch them directly use &startredirection and &endredirection
119: @outputstack = ();
120: $redirection = 0;
121:
122: #controls wheter the <import> tag actually does
123: $import = 1;
124: @extlinks=();
125:
126: # meta mode is a bit weird only some output is to be turned off
127: #<output> tag turns metamode off (defined in londefdef.pm)
128: $metamode = 0;
129:
130: # turns on and of run::evaluate actually derefencing var refs
131: $evaluate = 1;
1.7 albertel 132:
1.74 albertel 133: # data structure for eidt mode, determines what tags can go into what other tags
134: %insertlist=();
1.68 www 135:
1.99 albertel 136: # stores the list of active tag namespaces
1.76 albertel 137: @namespace=();
138:
1.169 albertel 139: # if 0 all high ASCII characters will be encoded into HTML Entities
140: $prevent_entity_encode=0;
141:
1.99 albertel 142: # has the dynamic menu been updated to know about this resource
143: $Apache::lonxml::registered=0;
144:
1.172 albertel 145: # a pointer the the Apache request object
146: $Apache::lonxml::request='';
147:
1.216 sakharuk 148: # a problem number counter, and check on ether it is used
149: $Apache::lonxml::counter=1;
1.204 albertel 150: $Apache::lonxml::counter_changed=0;
151:
1.212 albertel 152: #internal check on whether to look at style defs
153: $Apache::lonxml::usestyle=1;
154:
1.68 www 155: sub xmlbegin {
156: my $output='';
157: if ($ENV{'browser.mathml'}) {
158: $output='<?xml version="1.0"?>'
159: .'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'
160: .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
161: .'[<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">]>'
162: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
163: .'xmlns="http://www.w3.org/TR/REC-html40">';
164: } else {
165: $output='<html>';
166: }
167: return $output;
168: }
169:
170: sub xmlend {
1.194 www 171: my ($discussiononly,$symb)=@_;
1.103 www 172: my $discussion='';
173: if ($ENV{'request.course.id'}) {
1.109 www 174: my $crs='/'.$ENV{'request.course.id'};
175: if ($ENV{'request.course.sec'}) {
176: $crs.='_'.$ENV{'request.course.sec'};
177: }
178: $crs=~s/\_/\//g;
179: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.194 www 180: unless ($symb) {
181: $symb=&Apache::lonnet::symbread();
182: }
1.103 www 183: if ($symb) {
184: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
185: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
186: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
187: if ($contrib{'version'}) {
1.194 www 188: unless ($discussiononly) {
189: $discussion.=
190: '<address><hr />';
191: }
1.103 www 192: my $idx;
193: for ($idx=1;$idx<=$contrib{'version'};$idx++) {
1.110 www 194: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1.222 www 195: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
196: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.110 www 197: my $message=$contrib{$idx.':message'};
198: $message=~s/\n/\<br \/\>/g;
1.186 www 199: $message=&Apache::lontexconvert::msgtexconverted($message);
1.110 www 200: if ($message) {
201: if ($hidden) {
202: $message='<font color="#888888">'.$message.'</font>';
203: }
1.196 www 204: my $screenname=&Apache::loncommon::screenname(
205: $contrib{$idx.':sendername'},
206: $contrib{$idx.':senderdomain'});
207: my $plainname=&Apache::loncommon::nickname(
208: $contrib{$idx.':sendername'},
209: $contrib{$idx.':senderdomain'});
210:
1.109 www 211: my $sender='Anonymous';
212: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
1.194 www 213: $sender=&Apache::loncommon::aboutmewrapper(
1.196 www 214: $plainname,
1.194 www 215: $contrib{$idx.':sendername'},
216: $contrib{$idx.':senderdomain'}).' ('.
1.164 www 217: $contrib{$idx.':sendername'}.' at '.
218: $contrib{$idx.':senderdomain'}.')';
1.109 www 219: if ($contrib{$idx.':anonymous'}) {
1.164 www 220: $sender.=' [anonymous] '.
1.196 www 221: $screenname;
1.110 www 222: }
223: if ($seeid) {
224: if ($hidden) {
225: $sender.=' <a href="/adm/feedback?unhide='.
226: $symb.':::'.$idx.'">Make Visible</a>';
227: } else {
228: $sender.=' <a href="/adm/feedback?hide='.
229: $symb.':::'.$idx.'">Hide</a>';
1.222 www 230: }
231: $sender.=' <a href="/adm/feedback?deldisc='.
232: $symb.':::'.$idx.'">Delete</a>';
233: }
1.164 www 234: } else {
1.196 www 235: if ($screenname) {
236: $sender='<i>'.$screenname.'</i>';
1.164 www 237: }
1.109 www 238: }
239: $discussion.='<p><b>'.$sender.'</b> ('.
1.103 www 240: localtime($contrib{$idx.':timestamp'}).
241: '):<blockquote>'.$message.
1.110 www 242: '</blockquote></p>';
243: }
244: }
1.103 www 245: }
1.194 www 246: unless ($discussiononly) {
247: $discussion.='</address>';
248: }
249: }
250: if ($discussiononly) {
1.195 www 251: $discussion.=(<<ENDDISCUSS);
1.198 www 252: <form action="/adm/feedback" method="post" name="mailform">
1.195 www 253: <input type="submit" name="discuss" value="Post Discussion" />
254: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
255: <input type="hidden" name="symb" value="$symb" />
256: <input type="hidden" name="sendit" value="true" />
257: <br />
258: <font size="1">Note: in anonymous discussion, your name is visible only to
259: course faculty</font><br />
260: <textarea name=comment cols=60 rows=10 wrap=hard></textarea>
261: </form>
262: ENDDISCUSS
1.198 www 263: $discussion.=&Apache::lonfeedback::generate_preview_button();
1.103 www 264: }
265: }
266: }
1.194 www 267: return $discussion.($discussiononly?'':'</html>');
1.119 www 268: }
269:
270: sub tokeninputfield {
1.120 www 271: my $defhost=$Apache::lonnet::perlvar{'lonHostID'};
272: $defhost=~tr/a-z/A-Z/;
1.119 www 273: return (<<ENDINPUTFIELD)
1.120 www 274: <script>
275: function updatetoken() {
276: var comp=new Array;
277: var barcode=unescape(document.tokeninput.barcode.value);
278: comp=barcode.split('*');
279: if (typeof(comp[0])!="undefined") {
280: document.tokeninput.codeone.value=comp[0];
281: }
282: if (typeof(comp[1])!="undefined") {
283: document.tokeninput.codetwo.value=comp[1];
284: }
285: if (typeof(comp[2])!="undefined") {
286: comp[2]=comp[2].toUpperCase();
287: document.tokeninput.codethree.value=comp[2];
288: }
289: document.tokeninput.barcode.value='';
290: }
291: </script>
292: <form method="post" name="tokeninput">
1.119 www 293: <table border="2" bgcolor="#FFFFBB">
294: <tr><th>DocID Checkin</th></tr>
295: <tr><td>
296: <table>
297: <tr>
298: <td>Scan in Barcode</td>
1.120 www 299: <td><input type="text" size="22" name="barcode"
300: onChange="updatetoken()"/></td>
1.119 www 301: </tr>
302: <tr><td><i>or</i> Type in DocID</td>
303: <td>
304: <input type="text" size="5" name="codeone" />
1.120 www 305: <b><font size="+2">*</font></b>
1.119 www 306: <input type="text" size="5" name="codetwo" />
1.120 www 307: <b><font size="+2">*</font></b>
308: <input type="text" size="10" name="codethree" value="$defhost"
309: onChange="this.value=this.value.toUpperCase()" />
1.119 www 310: </td></tr>
311: </table>
312: </td></tr>
313: <tr><td><input type="submit" value="Check in DocID" /></td></tr>
314: </table>
315: </form>
316: ENDINPUTFIELD
1.112 www 317: }
318:
1.116 www 319: sub maketoken {
1.118 www 320: my ($symb,$tuname,$tudom,$tcrsid)=@_;
1.112 www 321: unless ($symb) {
322: $symb=&Apache::lonnet::symbread();
323: }
324: unless ($tuname) {
325: $tuname=$ENV{'user.name'};
326: $tudom=$ENV{'user.domain'};
327: $tcrsid=$ENV{'request.course.id'};
328: }
1.116 www 329:
1.118 www 330: return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid);
331: }
332:
333: sub printtokenheader {
1.133 albertel 334: my ($target,$token,$tsymb,$tcrsid,$tudom,$tuname)=@_;
1.116 www 335: unless ($token) { return ''; }
1.118 www 336:
1.133 albertel 337: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
338: unless ($tsymb) {
339: $tsymb=$symb;
1.118 www 340: }
341: unless ($tuname) {
1.133 albertel 342: $tuname=$name;
343: $tudom=$domain;
344: $tcrsid=$courseid;
1.118 www 345: }
1.114 www 346:
347: my %reply=&Apache::lonnet::get('environment',
348: ['firstname','middlename','lastname','generation'],
349: $tudom,$tuname);
350: my $plainname=$reply{'firstname'}.' '.
351: $reply{'middlename'}.' '.
352: $reply{'lastname'}.' '.
353: $reply{'generation'};
354:
1.112 www 355: if ($target eq 'web') {
1.145 www 356: my %idhash=&Apache::lonnet::idrget($tudom,($tuname));
1.115 www 357: return
1.221 albertel 358: '<img align="right" src="/cgi-bin/barcode.png?encode='.$token.'" />'.
1.115 www 359: 'Checked out for '.$plainname.
1.114 www 360: '<br />User: '.$tuname.' at '.$tudom.
1.145 www 361: '<br />ID: '.$idhash{$tuname}.
1.117 www 362: '<br />CourseID: '.$tcrsid.
1.145 www 363: '<br />Course: '.$ENV{'course.'.$tcrsid.'.description'}.
1.114 www 364: '<br />DocID: '.$token.
1.116 www 365: '<br />Time: '.localtime().'<hr />';
1.112 www 366: } else {
1.121 albertel 367: return $token;
1.112 www 368: }
1.68 www 369: }
370:
1.70 www 371: sub fontsettings() {
372: my $headerstring='';
373: if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) {
374: $headerstring.=
375: '<meta Content-Type="text/html; charset=x-mac-roman">';
376: }
377: return $headerstring;
378: }
379:
1.217 matthew 380:
381: ##
382: ## switchmenu - modeled on lonmenu::switchmenu, but better.
383: ## Helper function for registerurl
384: ##
385: sub switchmenu {
386: my ($row,$col,$imgsrc,$texttop,$textbot,$action,$description)=@_;
387: return(<<ENDSMENU);
388: menu.switchbutton($row,$col,'$imgsrc','$texttop','$textbot','$action','$description');
389: ENDSMENU
390: }
391:
1.68 www 392: sub registerurl {
1.100 www 393: my $forcereg=shift;
1.155 matthew 394: my $target = shift;
395: my $result = '';
1.197 sakharuk 396:
1.179 matthew 397: if ($target eq 'edit') {
1.187 matthew 398: $result .="<script>\n".
399: "if (typeof menu != 'undefined') {menu.currentURL=null;}\n".
1.179 matthew 400: &Apache::loncommon::browser_and_searcher_javascript().
401: "\n</script>\n";
402: }
1.176 www 403: if ((($ENV{'request.publicaccess'}) ||
404: (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
405: (!$forcereg)) {
1.179 matthew 406: return $result.
1.130 www 407: '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';
408: }
1.128 albertel 409: if ($Apache::lonxml::registered && !$forcereg) { return ''; }
1.105 albertel 410: $Apache::lonxml::registered=1;
1.159 www 411: my $nothing='';
412: if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
1.200 www 413: my $newmail='';
414: if (&Apache::lonmsg::newmail()) {
1.201 www 415: $newmail='menu.setstatus("you have","messages");';
1.200 www 416: }
1.181 www 417: my $timesync='menu.syncclock(1000*'.time.');';
1.100 www 418: if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
1.87 www 419: my $hwkadd='';
1.168 albertel 420: if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.87 www 421: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
422: $hwkadd.=(<<ENDSUBM);
1.214 www 423: menu.switchbutton(7,1,'subm.gif','view sub','missions','gocmd("/adm/grades","submission")',
424: 'View user submissions for this assessment resource');
1.87 www 425: ENDSUBM
426: }
427: if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
428: $hwkadd.=(<<ENDGRDS);
1.214 www 429: menu.switchbutton(7,2,'pgrd.gif','problem','grades','gocmd("/adm/grades","gradingmenu")',
430: 'Modify user grades for this assessment resource');
1.87 www 431: ENDGRDS
432: }
433: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
434: $hwkadd.=(<<ENDPARM);
1.214 www 435: menu.switchbutton(7,3,'pparm.gif','problem','parms','gocmd("/adm/parmset","set")',
436: 'Modify deadlines, etc, for this assessment resource');
1.87 www 437: ENDPARM
438: }
439: }
1.217 matthew 440: ###
441: ### Determine whether or not to display the 'cstr' button for this
442: ### resource
443: ###
444: my $editbutton = '';
445: if ($ENV{'user.author'}) {
446: if ($ENV{'request.role'}=~/^(ca|au)/) {
447: # Set defaults for authors
448: my ($top,$bottom) = ('con-','struct');
449: my $action = "go('/priv/".$ENV{'user.name'}."');";
450: my $cadom = $ENV{'request.role.domain'};
451: my $caname = $ENV{'user.name'};
452: my $desc = "Enter my resource construction space";
453: # Set defaults for co-authors
454: if ($ENV{'request.role'} =~ /^ca/) {
455: ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
456: ($top,$bottom) = ('co con-','struct');
457: $action = 'go("/priv/'.$caname.'");';
458: $desc = "Enter construction space as co-author";
459: }
460: # Check that we are on the correct machine
461: my $home = &Apache::lonnet::homeserver($caname,$cadom);
462: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
463: $editbutton=&switchmenu
464: (6,1,$top,,$bottom,$action,$desc);
465: }
466: }
467: ##
468: ## Determine if user can edit url.
469: ##
470: my $cfile='';
471: my $cfuname='';
472: my $cfudom='';
473: if ($ENV{'request.filename'}) {
474: my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
475: $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
476: # Chech that the user has permission to edit this resource
477: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
478: if (defined($cfudom)) {
479: if (&Apache::lonnet::homeserver($cfuname,$cfudom)
480: eq $Apache::lonnet::perlvar{'lonHostID'}) {
481: $cfile=$file;
482: }
483: }
484: }
485: # Finally, turn the button on or off
486: if ($cfile) {
487: $editbutton=&switchmenu
488: (6,1,'cstr.gif','edit','resource',
489: 'go("'.$cfile.'");',"Edit this resource");
490: } elsif ($editbutton eq '') {
491: $editbutton = ' menu.clearbut(6,1);';
492: }
493: }
494: ###
495: ###
1.155 matthew 496: $result = (<<ENDREGTHIS);
1.87 www 497:
1.68 www 498: <script language="JavaScript">
1.71 www 499: // BEGIN LON-CAPA Internal
1.86 www 500:
1.69 www 501: function LONCAPAreg() {
1.159 www 502: menu=window.open("$nothing","LONCAPAmenu","",false);
1.86 www 503: menu.clearTimeout(menu.menucltim);
1.174 www 504: $timesync
1.200 www 505: $newmail
1.69 www 506: menu.currentURL=window.location.pathname;
1.175 www 507: menu.reloadURL=window.location.pathname;
1.214 www 508: menu.currentSymb="$ENV{'request.symb'}";
509: menu.reloadSymb="$ENV{'request.symb'}";
1.69 www 510: menu.currentStale=0;
1.85 www 511: menu.clearbut(3,1);
512: menu.switchbutton
1.108 www 513: (6,3,'catalog.gif','catalog','info','catalog_info()');
514: menu.switchbutton
1.214 www 515: (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)','Provide my evaluation of this resource');
1.85 www 516: menu.switchbutton
1.214 www 517: (8,2,'fdbk.gif','feedback','discuss','gopost("/adm/feedback",currentURL)','Provide feedback messages or contribute to the course discussion about this resource');
1.85 www 518: menu.switchbutton
1.214 www 519: (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)','Prepare a printable document');
1.85 www 520: menu.switchbutton
1.214 www 521: (2,1,'back.gif','backward','','gopost("/adm/flip","back:"+currentURL)','Go to the previous resource in the course sequence');
1.85 www 522: menu.switchbutton
1.214 www 523: (2,3,'forw.gif','forward','','gopost("/adm/flip","forward:"+currentURL)','Go to the next resource in the course sequence');
1.94 www 524: menu.switchbutton
1.214 www 525: (9,1,'sbkm.gif','set','bookmark','set_bookmark()','Set a bookmark for this resource');
1.94 www 526: menu.switchbutton
1.214 www 527: (9,2,'vbkm.gif','view','bookmark','edit_bookmarks()','Use or edit my bookmark collection');
1.94 www 528: menu.switchbutton
1.214 www 529: (9,3,'anot.gif','anno-','tations','annotate()','Make notes and annotations about this resource');
1.87 www 530: $hwkadd
1.217 matthew 531: $editbutton
1.69 www 532: }
1.86 www 533:
1.69 www 534: function LONCAPAstale() {
1.159 www 535: menu=window.open("$nothing","LONCAPAmenu","",false);
1.86 www 536: menu.currentStale=1;
1.175 www 537: if (menu.reloadURL!='' && menu.reloadURL!= null) {
538: menu.switchbutton
1.214 www 539: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
1.175 www 540: }
1.127 www 541: menu.clearbut(7,1);
542: menu.clearbut(7,2);
543: menu.clearbut(7,3);
1.86 www 544: menu.menucltim=menu.setTimeout(
1.94 www 545: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.219 matthew 546: 'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
1.86 www 547: 2000);
548:
1.87 www 549: }
1.86 www 550:
551: // END LON-CAPA Internal
552: </script>
553: ENDREGTHIS
554:
555: } else {
1.155 matthew 556: $result = (<<ENDDONOTREGTHIS);
1.86 www 557:
558: <script language="JavaScript">
559: // BEGIN LON-CAPA Internal
560:
561: function LONCAPAreg() {
1.159 www 562: menu=window.open("$nothing","LONCAPAmenu","",false);
1.174 www 563: $timesync
1.69 www 564: menu.currentStale=1;
1.85 www 565: menu.clearbut(2,1);
566: menu.clearbut(2,3);
567: menu.clearbut(8,1);
568: menu.clearbut(8,2);
569: menu.clearbut(8,3);
1.86 www 570: if (menu.currentURL) {
571: menu.switchbutton
572: (3,1,'reload.gif','return','location','go(currentURL)');
573: } else {
574: menu.clearbut(3,1);
575: }
576: }
577:
578: function LONCAPAstale() {
1.68 www 579: }
1.86 www 580:
1.71 www 581: // END LON-CAPA Internal
1.68 www 582: </script>
1.86 www 583: ENDDONOTREGTHIS
1.155 matthew 584: }
585: return $result;
1.69 www 586: }
587:
588: sub loadevents() {
589: return 'LONCAPAreg();';
590: }
591:
592: sub unloadevents() {
593: return 'LONCAPAstale();';
1.68 www 594: }
595:
1.48 albertel 596: sub printalltags {
597: my $temp;
598: foreach $temp (sort keys %Apache::lonxml::alltags) {
1.141 albertel 599: &Apache::lonxml::debug("$temp -- ".
600: join(',',@{ $Apache::lonxml::alltags{$temp} }));
1.48 albertel 601: }
602: }
1.31 sakharuk 603:
1.3 sakharuk 604: sub xmlparse {
1.172 albertel 605: my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
1.96 albertel 606:
1.172 albertel 607: &setup_globals($request,$target);
1.178 www 608: #
609: # do we have a course style file?
610: #
611:
1.208 albertel 612: if ($ENV{'request.course.id'} && $ENV{'request.state'} ne 'construct') {
1.178 www 613: my $bodytext=
614: $ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
615: if ($bodytext) {
616: my $location=&Apache::lonnet::filelocation('',$bodytext);
617: my $styletext=&Apache::lonnet::getfile($location);
618: if ($styletext ne '-1') {
619: %style_for_target = (%style_for_target,
620: &Apache::style::styleparser($target,$styletext));
621: }
622: }
623: }
624:
1.48 albertel 625: #&printalltags();
1.16 albertel 626: my @pars = ();
1.23 albertel 627: my $pwd=$ENV{'request.filename'};
628: $pwd =~ s:/[^/]*$::;
629: &newparser(\@pars,\$content_file_string,$pwd);
1.24 sakharuk 630:
1.3 sakharuk 631: my $safeeval = new Safe;
1.40 albertel 632: my $safehole = new Safe::Hole;
1.82 ng 633: &init_safespace($target,$safeeval,$safehole,$safeinit);
1.3 sakharuk 634: #-------------------- Redefinition of the target in the case of compound target
635:
636: ($target, my @tenta) = split('&&',$target);
637:
1.150 albertel 638: my @stack = ();
1.3 sakharuk 639: my @parstack = ();
1.17 albertel 640: &initdepth;
1.67 www 641:
1.101 albertel 642: my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
643: $safeeval,\%style_for_target);
1.125 www 644: if ($ENV{'request.uri'}) {
645: &writeallows($ENV{'request.uri'});
646: }
1.204 albertel 647: if ($Apache::lonxml::counter_changed) { &store_counter() }
1.3 sakharuk 648: return $finaloutput;
1.106 www 649: }
650:
651: sub htmlclean {
1.107 www 652: my ($raw,$full)=@_;
1.106 www 653:
654: my $tree = HTML::TreeBuilder->new;
655: $tree->ignore_unknown(0);
1.140 albertel 656:
1.106 www 657: $tree->parse($raw);
658:
1.107 www 659: my $output= $tree->as_HTML(undef,' ');
1.140 albertel 660:
1.161 albertel 661: $output=~s/\<(br|hr|img|meta|allow)(.*?)\>/\<$1$2 \/\>/gis;
1.111 www 662: $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
1.107 www 663: unless ($full) {
664: $output=~s/\<[\/]*(body|head|html)\>//gis;
665: }
1.106 www 666:
667: $tree = $tree->delete;
668:
669: return $output;
1.15 albertel 670: }
671:
1.191 albertel 672: sub latex_special_symbols {
1.188 sakharuk 673: my ($current_token,$stack,$parstack)=@_;
1.216 sakharuk 674: $current_token=~s/\\ /\\char92 /g;
1.192 albertel 675: $current_token=~s/\^/\\char94 /g;
676: $current_token=~s/\~/\\char126 /g;
1.197 sakharuk 677: $current_token=~s/(&[^a-z\#])/\\$1/g;
1.203 sakharuk 678: $current_token=~s/([^&])\#/$1\\#/g;
1.192 albertel 679: $current_token=~s/(\$|_|{|})/\\$1/g;
680: $current_token=~s/\\char92 /\\texttt{\\char92}/g;
681: $current_token=~s/>/\$>\$/g; #more
682: $current_token=~s/</\$<\$/g; #less
683: if ($current_token=~m/\d%/) {$current_token =~ s/(\d)%/$1\\%/g;} #percent after digit
684: if ($current_token=~m/\s%/) {$current_token =~ s/(\s)%/$1\\%/g;} #persent after space
1.188 sakharuk 685: return $current_token;
686: }
687:
1.101 albertel 688: sub inner_xmlparse {
689: my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
690: my $finaloutput = '';
691: my $result;
692: my $token;
693: while ( $#$pars > -1 ) {
694: while ($token = $$pars['-1']->get_token) {
695: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
696: if ($metamode<1) {
1.190 albertel 697: my $text=$token->[1];
1.193 albertel 698: if ($token->[0] eq 'C' && $target eq 'tex') {
1.216 sakharuk 699: $text = '%'.$text."\n";
1.182 sakharuk 700: }
1.190 albertel 701: $result.=$text;
1.101 albertel 702: }
703: } elsif ($token->[0] eq 'PI') {
704: if ($metamode<1) {
705: $result=$token->[2];
706: }
707: } elsif ($token->[0] eq 'S') {
1.140 albertel 708: # add tag to stack
1.101 albertel 709: push (@$stack,$token->[1]);
710: # add parameters list to another stack
711: push (@$parstack,&parstring($token));
1.140 albertel 712: &increasedepth($token);
1.212 albertel 713: if ($Apache::lonxml::usestyle &&
714: exists($$style_for_target{$token->[1]})) {
715: $Apache::lonxml::usestyle=0;
716: my $string=$$style_for_target{$token->[1]}.
717: '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
718: &Apache::lonxml::newparser($pars,\$string);
1.101 albertel 719: } else {
720: $result = &callsub("start_$token->[1]", $target, $token, $stack,
721: $parstack, $pars, $safeeval, $style_for_target);
1.140 albertel 722: }
1.101 albertel 723: } elsif ($token->[0] eq 'E') {
724: #clear out any tags that didn't end
725: while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
1.150 albertel 726: my $lasttag=$$stack[-1];
727: if ($token->[1] =~ /^$lasttag$/i) {
728: &Apache::lonxml::warning('Using tag </'.$token->[1].'> as end tag to <'.$$stack[-1].'>');
729: last;
730: } else {
1.152 albertel 731: &Apache::lonxml::warning('Found tag </'.$token->[1].'> when looking for </'.$$stack[-1].'> in file');
1.150 albertel 732: &end_tag($stack,$parstack,$token);
733: }
1.101 albertel 734: }
1.140 albertel 735:
1.212 albertel 736: if ($Apache::lonxml::usestyle &&
737: exists($$style_for_target{'/'."$token->[1]"})) {
738: $Apache::lonxml::usestyle=0;
739: my $string=$$style_for_target{'/'.$token->[1]}.
740: '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
741: &Apache::lonxml::newparser($pars,\$string);
1.101 albertel 742: } else {
743: $result = &callsub("end_$token->[1]", $target, $token, $stack,
744: $parstack, $pars,$safeeval, $style_for_target);
745: }
746: } else {
747: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
748: }
749: #evaluate variable refs in result
750: if ($result ne "") {
751: if ( $#$parstack > -1 ) {
1.169 albertel 752: $result=&Apache::run::evaluate($result,$safeeval,$$parstack[-1]);
1.101 albertel 753: } else {
1.169 albertel 754: $result= &Apache::run::evaluate($result,$safeeval,'');
1.101 albertel 755: }
1.163 albertel 756: }
1.190 albertel 757: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
758: if ($target eq 'tex') {
1.191 albertel 759: $result=&latex_special_symbols($result,$stack,$parstack);
1.190 albertel 760: }
761: }
762:
1.169 albertel 763: # Encode any high ASCII characters
764: if (!$Apache::lonxml::prevent_entity_encode) {
765: $result=&HTML::Entities::encode($result,"\200-\377");
766: }
767: if ($Apache::lonxml::redirection) {
768: $Apache::lonxml::outputstack['-1'] .= $result;
769: } else {
770: $finaloutput.=$result;
771: }
772: $result = '';
773:
1.101 albertel 774: if ($token->[0] eq 'E') {
775: &end_tag($stack,$parstack,$token);
776: }
1.224 ! albertel 777: }
1.212 albertel 778: if ($#$pars > -1) {
779: pop @$pars;
780: pop @Apache::lonxml::pwd;
781: }
1.101 albertel 782: }
783:
784: # if ($target eq 'meta') {
785: # $finaloutput.=&endredirection;
786: # }
787:
1.169 albertel 788:
1.101 albertel 789: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
790: $finaloutput=&afterburn($finaloutput);
1.216 sakharuk 791: }
1.101 albertel 792: return $finaloutput;
793: }
1.67 www 794:
1.7 albertel 795: sub callsub {
1.84 albertel 796: my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.7 albertel 797: my $currentstring='';
1.72 albertel 798: my $nodefault;
1.7 albertel 799: {
1.59 albertel 800: my $sub1;
1.7 albertel 801: no strict 'refs';
1.68 www 802: my $tag=$token->[1];
1.141 albertel 803: my $space=$Apache::lonxml::alltags{$tag}[-1];
1.68 www 804: if (!$space) {
1.141 albertel 805: $tag=~tr/A-Z/a-z/;
1.68 www 806: $sub=~tr/A-Z/a-z/;
1.141 albertel 807: $space=$Apache::lonxml::alltags{$tag}[-1]
1.68 www 808: }
1.97 albertel 809:
810: my $deleted=0;
811: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
812: if (($token->[0] eq 'S') && ($target eq 'modified')) {
813: $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
814: $parstack,$parser,$safeeval,
815: $style);
816: }
817: if (!$deleted) {
818: if ($space) {
1.220 albertel 819: #&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
1.97 albertel 820: $sub1="$space\:\:$sub";
821: ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
822: $parstack,$parser,$safeeval,
823: $style);
824: } else {
1.220 albertel 825: #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
1.97 albertel 826: if ($metamode <1) {
827: if (defined($token->[4]) && ($metamode < 1)) {
828: $currentstring = $token->[4];
829: } else {
830: $currentstring = $token->[2];
831: }
1.62 sakharuk 832: }
1.7 albertel 833: }
1.97 albertel 834: # &Apache::lonxml::debug("nodefalt:$nodefault:");
835: if ($currentstring eq '' && $nodefault eq '') {
836: if ($target eq 'edit') {
1.220 albertel 837: #&Apache::lonxml::debug("doing default edit for $token->[1]");
1.97 albertel 838: if ($token->[0] eq 'S') {
839: $currentstring = &Apache::edit::tag_start($target,$token);
840: } elsif ($token->[0] eq 'E') {
841: $currentstring = &Apache::edit::tag_end($target,$token);
842: }
843: } elsif ($target eq 'modified') {
844: if ($token->[0] eq 'S') {
845: $currentstring = $token->[4];
846: $currentstring.=&Apache::edit::handle_insert();
1.210 www 847: } elsif ($token->[0] eq 'E') {
848: $currentstring = $token->[2];
849: $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
1.97 albertel 850: } else {
851: $currentstring = $token->[2];
852: }
1.72 albertel 853: }
854: }
1.7 albertel 855: }
856: use strict 'refs';
857: }
858: return $currentstring;
1.82 ng 859: }
860:
1.96 albertel 861: sub setup_globals {
1.172 albertel 862: my ($request,$target)=@_;
863: $Apache::lonxml::request=$request;
1.99 albertel 864: $Apache::lonxml::registered = 0;
1.205 www 865: $errorcount=0;
866: $warningcount=0;
1.207 albertel 867: $Apache::lonxml::default_homework_loaded=0;
1.212 albertel 868: $Apache::lonxml::usestyle=1;
1.204 albertel 869: &init_counter();
1.101 albertel 870: @Apache::lonxml::pwd=();
1.124 albertel 871: @Apache::lonxml::extlinks=();
1.96 albertel 872: if ($target eq 'meta') {
873: $Apache::lonxml::redirection = 0;
874: $Apache::lonxml::metamode = 1;
875: $Apache::lonxml::evaluate = 1;
876: $Apache::lonxml::import = 0;
1.129 albertel 877: } elsif ($target eq 'answer') {
878: $Apache::lonxml::redirection = 0;
879: $Apache::lonxml::metamode = 1;
880: $Apache::lonxml::evaluate = 1;
881: $Apache::lonxml::import = 1;
1.96 albertel 882: } elsif ($target eq 'grade') {
883: &startredirection;
884: $Apache::lonxml::metamode = 0;
885: $Apache::lonxml::evaluate = 1;
886: $Apache::lonxml::import = 1;
887: } elsif ($target eq 'modified') {
888: $Apache::lonxml::redirection = 0;
889: $Apache::lonxml::metamode = 0;
890: $Apache::lonxml::evaluate = 0;
891: $Apache::lonxml::import = 0;
892: } elsif ($target eq 'edit') {
893: $Apache::lonxml::redirection = 0;
894: $Apache::lonxml::metamode = 0;
895: $Apache::lonxml::evaluate = 0;
896: $Apache::lonxml::import = 0;
1.163 albertel 897: } elsif ($target eq 'analyze') {
898: $Apache::lonxml::redirection = 0;
899: $Apache::lonxml::metamode = 0;
900: $Apache::lonxml::evaluate = 1;
901: $Apache::lonxml::import = 1;
1.96 albertel 902: } else {
903: $Apache::lonxml::redirection = 0;
904: $Apache::lonxml::metamode = 0;
905: $Apache::lonxml::evaluate = 1;
906: $Apache::lonxml::import = 1;
907: }
908: }
909:
1.82 ng 910: sub init_safespace {
911: my ($target,$safeeval,$safehole,$safeinit) = @_;
912: $safeeval->permit("entereval");
913: $safeeval->permit(":base_math");
914: $safeeval->permit("sort");
915: $safeeval->deny(":base_io");
1.102 albertel 916: $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
1.82 ng 917: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
918:
919: $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
920: $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
921: $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
922: $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
923: $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
924: $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
925: $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
926: $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
927: $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
928: $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
929: $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
930: $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
931: $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
932: $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
933: $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
934: $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
935: $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
936: $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
937: $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
1.215 albertel 938:
939: $safehole->wrap(\&Math::Cephes::bdtr ,$safeeval,'&bdtr' );
940: $safehole->wrap(\&Math::Cephes::bdtrc ,$safeeval,'&bdtrc' );
941: $safehole->wrap(\&Math::Cephes::bdtri ,$safeeval,'&bdtri' );
942: $safehole->wrap(\&Math::Cephes::btdtr ,$safeeval,'&btdtr' );
943: $safehole->wrap(\&Math::Cephes::chdtr ,$safeeval,'&chdtr' );
944: $safehole->wrap(\&Math::Cephes::chdtrc,$safeeval,'&chdtrc');
945: $safehole->wrap(\&Math::Cephes::chdtri,$safeeval,'&chdtri');
946: $safehole->wrap(\&Math::Cephes::fdtr ,$safeeval,'&fdtr' );
947: $safehole->wrap(\&Math::Cephes::fdtrc ,$safeeval,'&fdtrc' );
948: $safehole->wrap(\&Math::Cephes::fdtri ,$safeeval,'&fdtri' );
949: $safehole->wrap(\&Math::Cephes::gdtr ,$safeeval,'&gdtr' );
950: $safehole->wrap(\&Math::Cephes::gdtrc ,$safeeval,'&gdtrc' );
951: $safehole->wrap(\&Math::Cephes::nbdtr ,$safeeval,'&nbdtr' );
952: $safehole->wrap(\&Math::Cephes::nbdtrc,$safeeval,'&nbdtrc');
953: $safehole->wrap(\&Math::Cephes::nbdtri,$safeeval,'&nbdtri');
954: $safehole->wrap(\&Math::Cephes::ndtr ,$safeeval,'&ndtr' );
955: $safehole->wrap(\&Math::Cephes::ndtri ,$safeeval,'&ndtri' );
956: $safehole->wrap(\&Math::Cephes::pdtr ,$safeeval,'&pdtr' );
957: $safehole->wrap(\&Math::Cephes::pdtrc ,$safeeval,'&pdtrc' );
958: $safehole->wrap(\&Math::Cephes::pdtri ,$safeeval,'&pdtri' );
959: $safehole->wrap(\&Math::Cephes::stdtr ,$safeeval,'&stdtr' );
960: $safehole->wrap(\&Math::Cephes::stdtri,$safeeval,'&stdtri');
961:
962: # $safehole->wrap(\&Math::Cephes::new_fract,$safeeval,'&new_fract');
963: # $safehole->wrap(\&Math::Cephes::radd,$safeeval,'&radd');
964: # $safehole->wrap(\&Math::Cephes::rsub,$safeeval,'&rsub');
965: # $safehole->wrap(\&Math::Cephes::rmul,$safeeval,'&rmul');
966: # $safehole->wrap(\&Math::Cephes::rdiv,$safeeval,'&rdiv');
967: # $safehole->wrap(\&Math::Cephes::euclid,$safeeval,'&euclid');
968:
1.91 ng 969: $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
970: $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
971: $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
972: $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
973: $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
974: $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
975: $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
976: $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
977: $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
978: $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
979: $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
1.93 ng 980: $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
1.91 ng 981: $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
982: $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
983: $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
984: $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
985: $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
986: $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
987: $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
988: $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
989: $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
990:
1.82 ng 991: #need to inspect this class of ops
992: # $safeeval->deny(":base_orig");
1.91 ng 993: $safeinit .= ';$external::target="'.$target.'";';
1.121 albertel 994: my $rndseed;
1.123 albertel 995: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
996: $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
1.121 albertel 997: $safeinit .= ';$external::randomseed='.$rndseed.';';
1.82 ng 998: &Apache::run::run($safeinit,$safeeval);
1.207 albertel 999: }
1000:
1001: sub default_homework_load {
1002: my ($safeeval)=@_;
1003: &Apache::lonxml::debug('Loading default_homework');
1004: my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
1005: if ($default == -1) {
1006: &Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
1007: } else {
1008: &Apache::run::run($default,$safeeval);
1009: $Apache::lonxml::default_homework_loaded=1;
1010: }
1.17 albertel 1011: }
1012:
1.55 albertel 1013: sub startredirection {
1014: $Apache::lonxml::redirection++;
1015: push (@Apache::lonxml::outputstack, '');
1016: }
1017:
1018: sub endredirection {
1019: if (!$Apache::lonxml::redirection) {
1.72 albertel 1020: &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
1.55 albertel 1021: return '';
1022: }
1023: $Apache::lonxml::redirection--;
1024: pop @Apache::lonxml::outputstack;
1.97 albertel 1025: }
1026:
1027: sub end_tag {
1028: my ($tagstack,$parstack,$token)=@_;
1029: pop(@$tagstack);
1030: pop(@$parstack);
1031: &decreasedepth($token);
1.55 albertel 1032: }
1033:
1.17 albertel 1034: sub initdepth {
1035: @Apache::lonxml::depthcounter=();
1036: $Apache::lonxml::depth=-1;
1037: $Apache::lonxml::olddepth=-1;
1038: }
1039:
1040: sub increasedepth {
1.19 albertel 1041: my ($token) = @_;
1.17 albertel 1042: $Apache::lonxml::depth++;
1043: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
1044: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
1045: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
1046: }
1.42 albertel 1047: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 1048: &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54 albertel 1049: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17 albertel 1050: }
1051:
1052: sub decreasedepth {
1.19 albertel 1053: my ($token) = @_;
1.17 albertel 1054: $Apache::lonxml::depth--;
1.36 albertel 1055: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
1056: $#Apache::lonxml::depthcounter--;
1057: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
1058: }
1.43 albertel 1059: if ( $Apache::lonxml::depth < -1) {
1.140 albertel 1060: &Apache::lonxml::warning("Missing tags, unable to properly run file.");
1.43 albertel 1061: $Apache::lonxml::depth='-1';
1062: }
1.42 albertel 1063: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 1064: &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54 albertel 1065: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1 sakharuk 1066: }
1.19 albertel 1067:
1.180 albertel 1068: sub get_all_text_unbalanced {
1.190 albertel 1069: #there is a copy of this in lonpublisher.pm
1.180 albertel 1070: my($tag,$pars)= @_;
1071: my $token;
1072: my $result='';
1073: $tag='<'.$tag.'>';
1074: while ($token = $$pars[-1]->get_token) {
1075: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1076: $result.=$token->[1];
1077: } elsif ($token->[0] eq 'PI') {
1078: $result.=$token->[2];
1079: } elsif ($token->[0] eq 'S') {
1080: $result.=$token->[4];
1081: } elsif ($token->[0] eq 'E') {
1082: $result.=$token->[2];
1083: }
1.211 albertel 1084: if ($result =~ /(.*)\Q$tag\E(.*)/s) {
1.180 albertel 1085: &Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
1086: &Apache::lonxml::debug('Result is :'.$1);
1087: $result=$1;
1088: my $redo=$tag.$2;
1089: &Apache::lonxml::newparser($pars,\$redo);
1090: last;
1091: }
1092: }
1093: return $result
1.204 albertel 1094: }
1095:
1096: sub increment_counter {
1097: $Apache::lonxml::counter++;
1098: $Apache::lonxml::counter_changed=1;
1099: }
1100:
1101: sub init_counter {
1102: if (defined($ENV{'form.counter'})) {
1103: $Apache::lonxml::counter=$ENV{'form.counter'};
1104: } elsif (not defined($Apache::lonxml::counter)) {
1105: $Apache::lonxml::counter=1;
1106: &store_counter();
1107: }
1108: $Apache::lonxml::counter_changed=0;
1109: }
1110:
1111: sub store_counter {
1112: &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter));
1113: return '';
1.180 albertel 1114: }
1115:
1.19 albertel 1116: sub get_all_text {
1117: my($tag,$pars)= @_;
1.212 albertel 1118: &Apache::lonxml::debug("Got a ".ref($pars));
1.224 ! albertel 1119: my $gotfullstack=1;
1.212 albertel 1120: if (ref($pars) ne 'ARRAY') {
1.224 ! albertel 1121: $gotfullstack=0;
1.212 albertel 1122: $pars=[$pars];
1123: }
1.19 albertel 1124: my $depth=0;
1125: my $token;
1126: my $result='';
1.57 albertel 1127: if ( $tag =~ m:^/: ) {
1128: my $tag=substr($tag,1);
1.212 albertel 1129: #&Apache::lonxml::debug("have:$tag:");
1.223 albertel 1130: my $top_empty=0;
1131: while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
1.212 albertel 1132: while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
1133: #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
1134: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1135: $result.=$token->[1];
1136: } elsif ($token->[0] eq 'PI') {
1137: $result.=$token->[2];
1138: } elsif ($token->[0] eq 'S') {
1139: if ($token->[1] =~ /^$tag$/i) { $depth++; }
1140: $result.=$token->[4];
1141: } elsif ($token->[0] eq 'E') {
1142: if ( $token->[1] =~ /^$tag$/i) { $depth--; }
1143: #skip sending back the last end tag
1144: if ($depth > -1) { $result.=$token->[2]; } else {
1145: $$pars[-1]->unget_token($token);
1146: }
1.57 albertel 1147: }
1148: }
1.212 albertel 1149: if (($depth >=0) && ($#$pars > 0) ) {
1150: pop(@$pars);
1151: pop(@Apache::lonxml::pwd);
1152: }
1.224 ! albertel 1153: if (($depth >=0) && ($#$pars == 0) ) { &debug("here4");$top_empty=1; }
! 1154: }
! 1155: if ($top_empty && $depth >= 0) {
! 1156: #never found the end tag ran out of text, throw error send back blank
! 1157: &error('Never found end tag for <'.$tag.'>');
! 1158: if ($gotfullstack) {
! 1159: my $newstring='</'.$tag.'>'.$result;
! 1160: &Apache::lonxml::newparser($pars,\$newstring);
! 1161: }
! 1162: $result='';
1.57 albertel 1163: }
1164: } else {
1.212 albertel 1165: while ($#$pars > -1) {
1166: while ($token = $$pars[-1]->get_token) {
1167: #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
1168: if (($token->[0] eq 'T')||($token->[0] eq 'C')||
1169: ($token->[0] eq 'D')) {
1170: $result.=$token->[1];
1171: } elsif ($token->[0] eq 'PI') {
1172: $result.=$token->[2];
1173: } elsif ($token->[0] eq 'S') {
1174: if ( $token->[1] =~ /^$tag$/i) {
1175: $$pars[-1]->unget_token($token); last;
1176: } else {
1177: $result.=$token->[4];
1178: }
1179: } elsif ($token->[0] eq 'E') {
1180: $result.=$token->[2];
1181: }
1182: }
1183: if (($#$pars > 0) ) {
1184: pop(@$pars);
1185: pop(@Apache::lonxml::pwd);
1186: } else { last; }
1.36 albertel 1187: }
1.19 albertel 1188: }
1.212 albertel 1189: if ($result =~ m|<LONCAPA_INTERNAL_TURN_STYLE_ON />|) {
1190: $Apache::lonxml::usestyle=1;
1191: }
1192: #&Apache::lonxml::debug("Exit:$result:");
1.19 albertel 1193: return $result
1194: }
1195:
1.23 albertel 1196: sub newparser {
1197: my ($parser,$contentref,$dir) = @_;
1.167 albertel 1198: push (@$parser,HTML::LCParser->new($contentref));
1.56 albertel 1199: $$parser['-1']->xml_mode('1');
1.23 albertel 1200: if ( $dir eq '' ) {
1201: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
1202: } else {
1203: push (@Apache::lonxml::pwd, $dir);
1204: }
1205: # &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
1206: # &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
1207: }
1.1 sakharuk 1208:
1.8 albertel 1209: sub parstring {
1210: my ($token) = @_;
1211: my $temp='';
1.142 albertel 1212: foreach (@{$token->[3]}) {
1.35 www 1213: unless ($_=~/\W/) {
1.42 albertel 1214: my $val=$token->[2]->{$_};
1.150 albertel 1215: $val =~ s/([\%\@\\\"])/\\$1/g;
1.51 albertel 1216: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42 albertel 1217: $temp .= "my \$$_=\"$val\";"
1.20 albertel 1218: }
1.142 albertel 1219: }
1.8 albertel 1220: return $temp;
1221: }
1.22 albertel 1222:
1.34 www 1223: sub writeallows {
1.126 www 1224: unless ($#extlinks>=0) { return; }
1.34 www 1225: my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
1.111 www 1226: if ($ENV{'httpref.'.$thisurl}) {
1227: $thisurl=$ENV{'httpref.'.$thisurl};
1228: }
1.34 www 1229: my $thisdir=$thisurl;
1230: $thisdir=~s/\/[^\/]+$//;
1231: my %httpref=();
1.142 albertel 1232: foreach (@extlinks) {
1.34 www 1233: $httpref{'httpref.'.
1.125 www 1234: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
1.142 albertel 1235: }
1.126 www 1236: @extlinks=();
1.34 www 1237: &Apache::lonnet::appenv(%httpref);
1238: }
1239:
1.66 www 1240: #
1241: # Afterburner handles anchors, highlights and links
1242: #
1243: sub afterburn {
1244: my $result=shift;
1.154 albertel 1245: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1246: ['highlight','anchor','link']);
1.66 www 1247: if ($ENV{'form.highlight'}) {
1.142 albertel 1248: foreach (split(/\,/,$ENV{'form.highlight'})) {
1.66 www 1249: my $anchorname=$_;
1250: my $matchthis=$anchorname;
1251: $matchthis=~s/\_+/\\s\+/g;
1252: $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
1.142 albertel 1253: }
1.66 www 1254: }
1255: if ($ENV{'form.link'}) {
1.142 albertel 1256: foreach (split(/\,/,$ENV{'form.link'})) {
1.66 www 1257: my ($anchorname,$linkurl)=split(/\>/,$_);
1258: my $matchthis=$anchorname;
1259: $matchthis=~s/\_+/\\s\+/g;
1260: $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
1.142 albertel 1261: }
1.66 www 1262: }
1263: if ($ENV{'form.anchor'}) {
1264: my $anchorname=$ENV{'form.anchor'};
1265: my $matchthis=$anchorname;
1266: $matchthis=~s/\_+/\\s\+/g;
1267: $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
1268: $result.=(<<"ENDSCRIPT");
1269: <script>
1270: document.location.hash='$anchorname';
1271: </script>
1272: ENDSCRIPT
1273: }
1274: return $result;
1275: }
1276:
1.79 www 1277: sub storefile {
1278: my ($file,$contents)=@_;
1279: if (my $fh=Apache::File->new('>'.$file)) {
1280: print $fh $contents;
1281: $fh->close();
1.147 albertel 1282: } else {
1283: &warning("Unable to save file $file");
1.79 www 1284: }
1285: }
1286:
1.151 albertel 1287: sub createnewhtml {
1288: my $filecontents=(<<SIMPLECONTENT);
1.78 www 1289: <html>
1290: <head>
1291: <title>
1292: Title of Document Goes Here
1293: </title>
1294: </head>
1295: <body bgcolor="#FFFFFF">
1296:
1297: Body of Document Goes Here
1298:
1299: </body>
1300: </html>
1301: SIMPLECONTENT
1.151 albertel 1302: return $filecontents;
1303: }
1304:
1.147 albertel 1305:
1.151 albertel 1306: sub inserteditinfo {
1307: my ($result,$filecontents)=@_;
1.157 albertel 1308: $filecontents = &HTML::Entities::encode($filecontents);
1.147 albertel 1309: # my $editheader='<a href="#editsection">Edit below</a><hr />';
1.161 albertel 1310: my $buttons=(<<BUTTONS);
1311: <input type="submit" name="attemptclean"
1312: value="Save and then attempt to clean HTML" />
1313: <input type="submit" name="savethisfile" value="Save this" />
1314: <input type="submit" name="viewmode" value="View" />
1315: BUTTONS
1.78 www 1316: my $editfooter=(<<ENDFOOTER);
1317: <hr />
1318: <a name="editsection" />
1319: <form method="post">
1.161 albertel 1320: <input type="hidden" name="editmode" value="Edit" />
1.170 www 1321: $buttons<br />
1.78 www 1322: <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
1.170 www 1323: <br />$buttons
1.78 www 1324: <br />
1325: </form>
1326: ENDFOOTER
1.147 albertel 1327: # $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
1.78 www 1328: $result=~s/(\<\/body\>)/$editfooter/is;
1329: return $result;
1330: }
1331:
1.152 albertel 1332: sub get_target {
1333: my $viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
1334: if ( $ENV{'request.state'} eq 'published') {
1335: if ( defined($ENV{'form.grade_target'})
1336: && ($viewgrades == 'F' )) {
1337: return ($ENV{'form.grade_target'});
1.153 albertel 1338: } elsif (defined($ENV{'form.grade_target'})) {
1339: if (($ENV{'form.grade_target'} eq 'web') ||
1340: ($ENV{'form.grade_target'} eq 'tex') ) {
1341: return $ENV{'form.grade_target'}
1342: } else {
1343: return 'web';
1344: }
1.152 albertel 1345: } else {
1346: return 'web';
1347: }
1348: } elsif ($ENV{'request.state'} eq 'construct') {
1349: if ( defined($ENV{'form.grade_target'})) {
1350: return ($ENV{'form.grade_target'});
1351: } else {
1352: return 'web';
1353: }
1354: } else {
1355: return 'web';
1356: }
1357: }
1358:
1.24 sakharuk 1359: sub handler {
1360: my $request=shift;
1.68 www 1361:
1.152 albertel 1362: my $target=&get_target();
1.68 www 1363:
1.65 albertel 1364: $Apache::lonxml::debug=0;
1.68 www 1365:
1.25 sakharuk 1366: if ($ENV{'browser.mathml'}) {
1.27 albertel 1367: $request->content_type('text/xml');
1368: } else {
1369: $request->content_type('text/html');
1.25 sakharuk 1370: }
1.141 albertel 1371: &Apache::loncommon::no_cache($request);
1.27 albertel 1372: $request->send_http_header;
1.141 albertel 1373:
1.45 www 1374: return OK if $request->header_only;
1.27 albertel 1375:
1.79 www 1376:
1377: my $file=&Apache::lonnet::filelocation("",$request->uri);
1.78 www 1378: #
1379: # Edit action? Save file.
1380: #
1381: unless ($ENV{'request.state'} eq 'published') {
1.107 www 1382: if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
1.79 www 1383: &storefile($file,$ENV{'form.filecont'});
1.78 www 1384: }
1385: }
1.24 sakharuk 1386: my %mystyle;
1.147 albertel 1387: my $result = '';
1.50 albertel 1388: my $filecontents=&Apache::lonnet::getfile($file);
1389: if ($filecontents == -1) {
1.78 www 1390: $result=(<<ENDNOTFOUND);
1391: <html>
1392: <head>
1393: <title>File not found</title>
1394: </head>
1395: <body bgcolor="#FFFFFF">
1396: <b>File not found: $file</b>
1397: </body>
1398: </html>
1399: ENDNOTFOUND
1.50 albertel 1400: $filecontents='';
1.151 albertel 1401: if ($ENV{'request.state'} ne 'published') {
1402: $filecontents=&createnewhtml();
1.161 albertel 1403: $ENV{'form.editmode'}='Edit'; #force edit mode
1.151 albertel 1404: }
1.50 albertel 1405: } else {
1.147 albertel 1406: unless ($ENV{'request.state'} eq 'published') {
1407: if ($ENV{'form.attemptclean'}) {
1408: $filecontents=&htmlclean($filecontents,1);
1.107 www 1409: }
1.147 albertel 1410: }
1.161 albertel 1411: if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
1.172 albertel 1412: $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
1413: '',%mystyle);
1.147 albertel 1414: }
1.78 www 1415: }
1416:
1417: #
1418: # Edit action? Insert editing commands
1419: #
1420: unless ($ENV{'request.state'} eq 'published') {
1.161 albertel 1421: if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
1.177 www 1422: my $displayfile=$request->uri;
1423: $displayfile=~s/^\/[^\/]*//;
1424: $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
1425: '</h3></body></html>';
1.78 www 1426: $result=&inserteditinfo($result,$filecontents);
1.147 albertel 1427: }
1.66 www 1428: }
1.147 albertel 1429:
1.126 www 1430: writeallows($request->uri);
1.50 albertel 1431:
1.67 www 1432: $request->print($result);
1.64 albertel 1433:
1.45 www 1434: return OK;
1.24 sakharuk 1435: }
1.147 albertel 1436:
1.22 albertel 1437: sub debug {
1438: if ($Apache::lonxml::debug eq 1) {
1.146 albertel 1439: $|=1;
1.202 albertel 1440: print('<font size="-2"<pre>DEBUG:'.&HTML::Entities::encode($_[0])."</pre></font>\n");
1.22 albertel 1441: }
1442: }
1.49 albertel 1443:
1.22 albertel 1444: sub error {
1.205 www 1445: $errorcount++;
1.74 albertel 1446: if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
1.166 matthew 1447: # If printing in construction space, put the error inside <pre></pre>
1.167 albertel 1448: print "<b>ERROR:</b>".join("\n",@_)."\n";
1.52 albertel 1449: } else {
1450: print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
1451: #notify author
1.146 albertel 1452: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},join('<br />',@_));
1.52 albertel 1453: #notify course
1454: if ( $ENV{'request.course.id'} ) {
1.209 www 1455: my (undef,%users)=&Apache::lonfeedback::decide_receiver(undef,0,1,1,1);
1.143 www 1456: my $declutter=&Apache::lonnet::declutter($ENV{'request.filename'});
1.209 www 1457: foreach (keys %users) {
1458: my ($user,$domain) = split(/:/, $_);
1.143 www 1459: &Apache::lonmsg::user_normal_msg($user,$domain,
1.146 albertel 1460: "Error [$declutter]",join('<br />',@_));
1.52 albertel 1461: }
1462: }
1.74 albertel 1463:
1.52 albertel 1464: #FIXME probably shouldn't have me get everything forever.
1.146 albertel 1465: &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",join('<br />',@_));
1.74 albertel 1466: #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 1467: }
1.22 albertel 1468: }
1.49 albertel 1469:
1.22 albertel 1470: sub warning {
1.205 www 1471: $warningcount++;
1.73 harris41 1472: if ($ENV{'request.state'} eq 'construct') {
1.146 albertel 1473: print "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n";
1.73 harris41 1474: }
1.83 albertel 1475: }
1476:
1477: sub get_param {
1.213 albertel 1478: my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1479: if ( ! $context ) { $context = -1; }
1480: my $args ='';
1481: if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1482: if ( ! $args ) { return undef; }
1483: if ( $case_insensitive ) {
1484: if ($args =~ s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei) {
1485: return &Apache::run::run("{$args;".'return $'.$param.'}',
1486: $safeeval); #'
1487: } else {
1488: return undef;
1489: }
1490: } else {
1491: if ( $args =~ /my \$\Q$param\E=\"/ ) {
1492: return &Apache::run::run("{$args;".'return $'.$param.'}',
1493: $safeeval); #'
1494: } else {
1495: return undef;
1496: }
1497: }
1.22 albertel 1498: }
1499:
1.132 albertel 1500: sub get_param_var {
1.213 albertel 1501: my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1.132 albertel 1502: if ( ! $context ) { $context = -1; }
1503: my $args ='';
1504: if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1.213 albertel 1505: if ($case_insensitive) {
1506: if (! ($args=~s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei)) {
1507: return undef;
1508: }
1509: } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
1.132 albertel 1510: my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1511: if ($value =~ /^[\$\@\%]/) {
1512: return &Apache::run::run("return $value",$safeeval,1);
1513: } else {
1514: return $value;
1515: }
1516: }
1517:
1.74 albertel 1518: sub register_insert {
1.75 albertel 1519: my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
1.74 albertel 1520: my $i;
1.76 albertel 1521: my $tagnum=0;
1.74 albertel 1522: my @order;
1523: for ($i=0;$i < $#data; $i++) {
1524: my $line = $data[$i];
1525: if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
1526: if ( $line =~ /TABLE/ ) { last; }
1.92 albertel 1527: my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);
1.135 albertel 1528: if ($tag) {
1529: $insertlist{"$tagnum.tag"} = $tag;
1530: $insertlist{"$tagnum.description"} = $descrip;
1531: $insertlist{"$tagnum.color"} = $color;
1532: $insertlist{"$tagnum.function"} = $function;
1533: if (!defined($show)) { $show='yes'; }
1534: $insertlist{"$tagnum.show"}= $show;
1535: $insertlist{"$tag.num"}=$tagnum;
1536: $tagnum++;
1537: }
1.74 albertel 1538: }
1.76 albertel 1539: $i++; #skipping TABLE line
1540: $tagnum = 0;
1.74 albertel 1541: for (;$i < $#data;$i++) {
1542: my $line = $data[$i];
1.76 albertel 1543: my ($mnemonic,@which) = split(/ +/,$line);
1544: my $tag = $insertlist{"$tagnum.tag"};
1.144 matthew 1545: for (my $j=0;$j <=$#which;$j++) {
1.74 albertel 1546: if ( $which[$j] eq 'Y' ) {
1.76 albertel 1547: if ($insertlist{"$j.show"} ne 'no') {
1548: push(@{ $insertlist{"$tag.which"} },$j);
1549: }
1.74 albertel 1550: }
1551: }
1.76 albertel 1552: $tagnum++;
1.74 albertel 1553: }
1554: }
1.98 albertel 1555:
1556: sub description {
1557: my ($token)=@_;
1.138 albertel 1558: my $tagnum;
1559: my $tag=$token->[1];
1560: foreach my $namespace (reverse @Apache::lonxml::namespace) {
1561: my $testtag=$namespace.'::'.$tag;
1562: $tagnum=$insertlist{"$testtag.num"};
1563: if (defined($tagnum)) { last; }
1564: }
1565: if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
1566: return $insertlist{$tagnum.'.description'};
1.98 albertel 1567: }
1.123 albertel 1568:
1569: # ----------------------------------------------------------------- whichuser
1570: # returns a list of $symb, $courseid, $domain, $name that is correct for
1571: # calls to lonnet functions for this setup.
1572: # - looks for form.grade_ parameters
1573: sub whichuser {
1.134 albertel 1574: my ($symb,$courseid,$domain,$name);
1.123 albertel 1575: if (defined($ENV{'form.grade_symb'})) {
1576: my $tmp_courseid=$ENV{'form.grade_courseid'};
1577: my $allowed=&Apache::lonnet::allowed('mgr',$tmp_courseid);
1578: if ($allowed) {
1579: $symb=$ENV{'form.grade_symb'};
1580: $courseid=$ENV{'form.grade_courseid'};
1581: $domain=$ENV{'form.grade_domain'};
1582: $name=$ENV{'form.grade_username'};
1583: }
1.134 albertel 1584: } else {
1585: $symb=&Apache::lonnet::symbread();
1586: $courseid=$ENV{'request.course.id'};
1587: $domain=$ENV{'user.domain'};
1588: $name=$ENV{'user.name'};
1.123 albertel 1589: }
1590: return ($symb,$courseid,$domain,$name);
1591: }
1592:
1.1 sakharuk 1593: 1;
1594: __END__
1.68 www 1595:
1596:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>