Annotation of loncom/xml/lonxml.pm, revision 1.225
1.2 sakharuk 1: # The LearningOnline Network with CAPA
1.3 sakharuk 2: # XML Parser Module
1.2 sakharuk 3: #
1.225 ! www 4: # $Id: lonxml.pm,v 1.224 2003/01/13 22:18:34 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.225 ! www 411: my $reopen=&Apache::lonmenu::reopenmenu();
1.200 www 412: my $newmail='';
413: if (&Apache::lonmsg::newmail()) {
1.201 www 414: $newmail='menu.setstatus("you have","messages");';
1.200 www 415: }
1.181 www 416: my $timesync='menu.syncclock(1000*'.time.');';
1.100 www 417: if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
1.87 www 418: my $hwkadd='';
1.168 albertel 419: if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.87 www 420: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
421: $hwkadd.=(<<ENDSUBM);
1.214 www 422: menu.switchbutton(7,1,'subm.gif','view sub','missions','gocmd("/adm/grades","submission")',
423: 'View user submissions for this assessment resource');
1.87 www 424: ENDSUBM
425: }
426: if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
427: $hwkadd.=(<<ENDGRDS);
1.214 www 428: menu.switchbutton(7,2,'pgrd.gif','problem','grades','gocmd("/adm/grades","gradingmenu")',
429: 'Modify user grades for this assessment resource');
1.87 www 430: ENDGRDS
431: }
432: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
433: $hwkadd.=(<<ENDPARM);
1.214 www 434: menu.switchbutton(7,3,'pparm.gif','problem','parms','gocmd("/adm/parmset","set")',
435: 'Modify deadlines, etc, for this assessment resource');
1.87 www 436: ENDPARM
437: }
438: }
1.217 matthew 439: ###
440: ### Determine whether or not to display the 'cstr' button for this
441: ### resource
442: ###
443: my $editbutton = '';
444: if ($ENV{'user.author'}) {
445: if ($ENV{'request.role'}=~/^(ca|au)/) {
446: # Set defaults for authors
447: my ($top,$bottom) = ('con-','struct');
448: my $action = "go('/priv/".$ENV{'user.name'}."');";
449: my $cadom = $ENV{'request.role.domain'};
450: my $caname = $ENV{'user.name'};
451: my $desc = "Enter my resource construction space";
452: # Set defaults for co-authors
453: if ($ENV{'request.role'} =~ /^ca/) {
454: ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
455: ($top,$bottom) = ('co con-','struct');
456: $action = 'go("/priv/'.$caname.'");';
457: $desc = "Enter construction space as co-author";
458: }
459: # Check that we are on the correct machine
460: my $home = &Apache::lonnet::homeserver($caname,$cadom);
461: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
462: $editbutton=&switchmenu
463: (6,1,$top,,$bottom,$action,$desc);
464: }
465: }
466: ##
467: ## Determine if user can edit url.
468: ##
469: my $cfile='';
470: my $cfuname='';
471: my $cfudom='';
472: if ($ENV{'request.filename'}) {
473: my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
474: $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
475: # Chech that the user has permission to edit this resource
476: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
477: if (defined($cfudom)) {
478: if (&Apache::lonnet::homeserver($cfuname,$cfudom)
479: eq $Apache::lonnet::perlvar{'lonHostID'}) {
480: $cfile=$file;
481: }
482: }
483: }
484: # Finally, turn the button on or off
485: if ($cfile) {
486: $editbutton=&switchmenu
487: (6,1,'cstr.gif','edit','resource',
488: 'go("'.$cfile.'");',"Edit this resource");
489: } elsif ($editbutton eq '') {
490: $editbutton = ' menu.clearbut(6,1);';
491: }
492: }
493: ###
494: ###
1.155 matthew 495: $result = (<<ENDREGTHIS);
1.87 www 496:
1.68 www 497: <script language="JavaScript">
1.71 www 498: // BEGIN LON-CAPA Internal
1.86 www 499:
1.69 www 500: function LONCAPAreg() {
1.225 ! www 501: menu=$reopen;
1.86 www 502: menu.clearTimeout(menu.menucltim);
1.174 www 503: $timesync
1.200 www 504: $newmail
1.69 www 505: menu.currentURL=window.location.pathname;
1.175 www 506: menu.reloadURL=window.location.pathname;
1.214 www 507: menu.currentSymb="$ENV{'request.symb'}";
508: menu.reloadSymb="$ENV{'request.symb'}";
1.69 www 509: menu.currentStale=0;
1.85 www 510: menu.clearbut(3,1);
511: menu.switchbutton
1.225 ! www 512: (6,3,'catalog.gif','catalog','info','catalog_info()','Show catalog information');
1.108 www 513: menu.switchbutton
1.214 www 514: (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)','Provide my evaluation of this resource');
1.85 www 515: menu.switchbutton
1.214 www 516: (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 517: menu.switchbutton
1.214 www 518: (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)','Prepare a printable document');
1.85 www 519: menu.switchbutton
1.214 www 520: (2,1,'back.gif','backward','','gopost("/adm/flip","back:"+currentURL)','Go to the previous resource in the course sequence');
1.85 www 521: menu.switchbutton
1.214 www 522: (2,3,'forw.gif','forward','','gopost("/adm/flip","forward:"+currentURL)','Go to the next resource in the course sequence');
1.94 www 523: menu.switchbutton
1.214 www 524: (9,1,'sbkm.gif','set','bookmark','set_bookmark()','Set a bookmark for this resource');
1.94 www 525: menu.switchbutton
1.214 www 526: (9,2,'vbkm.gif','view','bookmark','edit_bookmarks()','Use or edit my bookmark collection');
1.94 www 527: menu.switchbutton
1.214 www 528: (9,3,'anot.gif','anno-','tations','annotate()','Make notes and annotations about this resource');
1.87 www 529: $hwkadd
1.217 matthew 530: $editbutton
1.69 www 531: }
1.86 www 532:
1.69 www 533: function LONCAPAstale() {
1.225 ! www 534: menu=$reopen
1.86 www 535: menu.currentStale=1;
1.175 www 536: if (menu.reloadURL!='' && menu.reloadURL!= null) {
537: menu.switchbutton
1.214 www 538: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
1.175 www 539: }
1.127 www 540: menu.clearbut(7,1);
541: menu.clearbut(7,2);
542: menu.clearbut(7,3);
1.86 www 543: menu.menucltim=menu.setTimeout(
1.94 www 544: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.219 matthew 545: 'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
1.86 www 546: 2000);
547:
1.87 www 548: }
1.86 www 549:
550: // END LON-CAPA Internal
551: </script>
552: ENDREGTHIS
553:
554: } else {
1.155 matthew 555: $result = (<<ENDDONOTREGTHIS);
1.86 www 556:
557: <script language="JavaScript">
558: // BEGIN LON-CAPA Internal
559:
560: function LONCAPAreg() {
1.225 ! www 561: menu=$reopen
1.174 www 562: $timesync
1.69 www 563: menu.currentStale=1;
1.85 www 564: menu.clearbut(2,1);
565: menu.clearbut(2,3);
566: menu.clearbut(8,1);
567: menu.clearbut(8,2);
568: menu.clearbut(8,3);
1.86 www 569: if (menu.currentURL) {
570: menu.switchbutton
571: (3,1,'reload.gif','return','location','go(currentURL)');
572: } else {
573: menu.clearbut(3,1);
574: }
575: }
576:
577: function LONCAPAstale() {
1.68 www 578: }
1.86 www 579:
1.71 www 580: // END LON-CAPA Internal
1.68 www 581: </script>
1.86 www 582: ENDDONOTREGTHIS
1.155 matthew 583: }
584: return $result;
1.69 www 585: }
586:
587: sub loadevents() {
588: return 'LONCAPAreg();';
589: }
590:
591: sub unloadevents() {
592: return 'LONCAPAstale();';
1.68 www 593: }
594:
1.48 albertel 595: sub printalltags {
596: my $temp;
597: foreach $temp (sort keys %Apache::lonxml::alltags) {
1.141 albertel 598: &Apache::lonxml::debug("$temp -- ".
599: join(',',@{ $Apache::lonxml::alltags{$temp} }));
1.48 albertel 600: }
601: }
1.31 sakharuk 602:
1.3 sakharuk 603: sub xmlparse {
1.172 albertel 604: my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
1.96 albertel 605:
1.172 albertel 606: &setup_globals($request,$target);
1.178 www 607: #
608: # do we have a course style file?
609: #
610:
1.208 albertel 611: if ($ENV{'request.course.id'} && $ENV{'request.state'} ne 'construct') {
1.178 www 612: my $bodytext=
613: $ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
614: if ($bodytext) {
615: my $location=&Apache::lonnet::filelocation('',$bodytext);
616: my $styletext=&Apache::lonnet::getfile($location);
617: if ($styletext ne '-1') {
618: %style_for_target = (%style_for_target,
619: &Apache::style::styleparser($target,$styletext));
620: }
621: }
622: }
623:
1.48 albertel 624: #&printalltags();
1.16 albertel 625: my @pars = ();
1.23 albertel 626: my $pwd=$ENV{'request.filename'};
627: $pwd =~ s:/[^/]*$::;
628: &newparser(\@pars,\$content_file_string,$pwd);
1.24 sakharuk 629:
1.3 sakharuk 630: my $safeeval = new Safe;
1.40 albertel 631: my $safehole = new Safe::Hole;
1.82 ng 632: &init_safespace($target,$safeeval,$safehole,$safeinit);
1.3 sakharuk 633: #-------------------- Redefinition of the target in the case of compound target
634:
635: ($target, my @tenta) = split('&&',$target);
636:
1.150 albertel 637: my @stack = ();
1.3 sakharuk 638: my @parstack = ();
1.17 albertel 639: &initdepth;
1.67 www 640:
1.101 albertel 641: my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
642: $safeeval,\%style_for_target);
1.125 www 643: if ($ENV{'request.uri'}) {
644: &writeallows($ENV{'request.uri'});
645: }
1.204 albertel 646: if ($Apache::lonxml::counter_changed) { &store_counter() }
1.3 sakharuk 647: return $finaloutput;
1.106 www 648: }
649:
650: sub htmlclean {
1.107 www 651: my ($raw,$full)=@_;
1.106 www 652:
653: my $tree = HTML::TreeBuilder->new;
654: $tree->ignore_unknown(0);
1.140 albertel 655:
1.106 www 656: $tree->parse($raw);
657:
1.107 www 658: my $output= $tree->as_HTML(undef,' ');
1.140 albertel 659:
1.161 albertel 660: $output=~s/\<(br|hr|img|meta|allow)(.*?)\>/\<$1$2 \/\>/gis;
1.111 www 661: $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
1.107 www 662: unless ($full) {
663: $output=~s/\<[\/]*(body|head|html)\>//gis;
664: }
1.106 www 665:
666: $tree = $tree->delete;
667:
668: return $output;
1.15 albertel 669: }
670:
1.191 albertel 671: sub latex_special_symbols {
1.188 sakharuk 672: my ($current_token,$stack,$parstack)=@_;
1.216 sakharuk 673: $current_token=~s/\\ /\\char92 /g;
1.192 albertel 674: $current_token=~s/\^/\\char94 /g;
675: $current_token=~s/\~/\\char126 /g;
1.197 sakharuk 676: $current_token=~s/(&[^a-z\#])/\\$1/g;
1.203 sakharuk 677: $current_token=~s/([^&])\#/$1\\#/g;
1.192 albertel 678: $current_token=~s/(\$|_|{|})/\\$1/g;
679: $current_token=~s/\\char92 /\\texttt{\\char92}/g;
680: $current_token=~s/>/\$>\$/g; #more
681: $current_token=~s/</\$<\$/g; #less
682: if ($current_token=~m/\d%/) {$current_token =~ s/(\d)%/$1\\%/g;} #percent after digit
683: if ($current_token=~m/\s%/) {$current_token =~ s/(\s)%/$1\\%/g;} #persent after space
1.188 sakharuk 684: return $current_token;
685: }
686:
1.101 albertel 687: sub inner_xmlparse {
688: my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
689: my $finaloutput = '';
690: my $result;
691: my $token;
692: while ( $#$pars > -1 ) {
693: while ($token = $$pars['-1']->get_token) {
694: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
695: if ($metamode<1) {
1.190 albertel 696: my $text=$token->[1];
1.193 albertel 697: if ($token->[0] eq 'C' && $target eq 'tex') {
1.216 sakharuk 698: $text = '%'.$text."\n";
1.182 sakharuk 699: }
1.190 albertel 700: $result.=$text;
1.101 albertel 701: }
702: } elsif ($token->[0] eq 'PI') {
703: if ($metamode<1) {
704: $result=$token->[2];
705: }
706: } elsif ($token->[0] eq 'S') {
1.140 albertel 707: # add tag to stack
1.101 albertel 708: push (@$stack,$token->[1]);
709: # add parameters list to another stack
710: push (@$parstack,&parstring($token));
1.140 albertel 711: &increasedepth($token);
1.212 albertel 712: if ($Apache::lonxml::usestyle &&
713: exists($$style_for_target{$token->[1]})) {
714: $Apache::lonxml::usestyle=0;
715: my $string=$$style_for_target{$token->[1]}.
716: '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
717: &Apache::lonxml::newparser($pars,\$string);
1.101 albertel 718: } else {
719: $result = &callsub("start_$token->[1]", $target, $token, $stack,
720: $parstack, $pars, $safeeval, $style_for_target);
1.140 albertel 721: }
1.101 albertel 722: } elsif ($token->[0] eq 'E') {
723: #clear out any tags that didn't end
724: while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
1.150 albertel 725: my $lasttag=$$stack[-1];
726: if ($token->[1] =~ /^$lasttag$/i) {
727: &Apache::lonxml::warning('Using tag </'.$token->[1].'> as end tag to <'.$$stack[-1].'>');
728: last;
729: } else {
1.152 albertel 730: &Apache::lonxml::warning('Found tag </'.$token->[1].'> when looking for </'.$$stack[-1].'> in file');
1.150 albertel 731: &end_tag($stack,$parstack,$token);
732: }
1.101 albertel 733: }
1.140 albertel 734:
1.212 albertel 735: if ($Apache::lonxml::usestyle &&
736: exists($$style_for_target{'/'."$token->[1]"})) {
737: $Apache::lonxml::usestyle=0;
738: my $string=$$style_for_target{'/'.$token->[1]}.
739: '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
740: &Apache::lonxml::newparser($pars,\$string);
1.101 albertel 741: } else {
742: $result = &callsub("end_$token->[1]", $target, $token, $stack,
743: $parstack, $pars,$safeeval, $style_for_target);
744: }
745: } else {
746: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
747: }
748: #evaluate variable refs in result
749: if ($result ne "") {
750: if ( $#$parstack > -1 ) {
1.169 albertel 751: $result=&Apache::run::evaluate($result,$safeeval,$$parstack[-1]);
1.101 albertel 752: } else {
1.169 albertel 753: $result= &Apache::run::evaluate($result,$safeeval,'');
1.101 albertel 754: }
1.163 albertel 755: }
1.190 albertel 756: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
757: if ($target eq 'tex') {
1.191 albertel 758: $result=&latex_special_symbols($result,$stack,$parstack);
1.190 albertel 759: }
760: }
761:
1.169 albertel 762: # Encode any high ASCII characters
763: if (!$Apache::lonxml::prevent_entity_encode) {
764: $result=&HTML::Entities::encode($result,"\200-\377");
765: }
766: if ($Apache::lonxml::redirection) {
767: $Apache::lonxml::outputstack['-1'] .= $result;
768: } else {
769: $finaloutput.=$result;
770: }
771: $result = '';
772:
1.101 albertel 773: if ($token->[0] eq 'E') {
774: &end_tag($stack,$parstack,$token);
775: }
1.224 albertel 776: }
1.212 albertel 777: if ($#$pars > -1) {
778: pop @$pars;
779: pop @Apache::lonxml::pwd;
780: }
1.101 albertel 781: }
782:
783: # if ($target eq 'meta') {
784: # $finaloutput.=&endredirection;
785: # }
786:
1.169 albertel 787:
1.101 albertel 788: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
789: $finaloutput=&afterburn($finaloutput);
1.216 sakharuk 790: }
1.101 albertel 791: return $finaloutput;
792: }
1.67 www 793:
1.7 albertel 794: sub callsub {
1.84 albertel 795: my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.7 albertel 796: my $currentstring='';
1.72 albertel 797: my $nodefault;
1.7 albertel 798: {
1.59 albertel 799: my $sub1;
1.7 albertel 800: no strict 'refs';
1.68 www 801: my $tag=$token->[1];
1.141 albertel 802: my $space=$Apache::lonxml::alltags{$tag}[-1];
1.68 www 803: if (!$space) {
1.141 albertel 804: $tag=~tr/A-Z/a-z/;
1.68 www 805: $sub=~tr/A-Z/a-z/;
1.141 albertel 806: $space=$Apache::lonxml::alltags{$tag}[-1]
1.68 www 807: }
1.97 albertel 808:
809: my $deleted=0;
810: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
811: if (($token->[0] eq 'S') && ($target eq 'modified')) {
812: $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
813: $parstack,$parser,$safeeval,
814: $style);
815: }
816: if (!$deleted) {
817: if ($space) {
1.220 albertel 818: #&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
1.97 albertel 819: $sub1="$space\:\:$sub";
820: ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
821: $parstack,$parser,$safeeval,
822: $style);
823: } else {
1.220 albertel 824: #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
1.97 albertel 825: if ($metamode <1) {
826: if (defined($token->[4]) && ($metamode < 1)) {
827: $currentstring = $token->[4];
828: } else {
829: $currentstring = $token->[2];
830: }
1.62 sakharuk 831: }
1.7 albertel 832: }
1.97 albertel 833: # &Apache::lonxml::debug("nodefalt:$nodefault:");
834: if ($currentstring eq '' && $nodefault eq '') {
835: if ($target eq 'edit') {
1.220 albertel 836: #&Apache::lonxml::debug("doing default edit for $token->[1]");
1.97 albertel 837: if ($token->[0] eq 'S') {
838: $currentstring = &Apache::edit::tag_start($target,$token);
839: } elsif ($token->[0] eq 'E') {
840: $currentstring = &Apache::edit::tag_end($target,$token);
841: }
842: } elsif ($target eq 'modified') {
843: if ($token->[0] eq 'S') {
844: $currentstring = $token->[4];
845: $currentstring.=&Apache::edit::handle_insert();
1.210 www 846: } elsif ($token->[0] eq 'E') {
847: $currentstring = $token->[2];
848: $currentstring.=&Apache::edit::handle_insertafter($token->[1]);
1.97 albertel 849: } else {
850: $currentstring = $token->[2];
851: }
1.72 albertel 852: }
853: }
1.7 albertel 854: }
855: use strict 'refs';
856: }
857: return $currentstring;
1.82 ng 858: }
859:
1.96 albertel 860: sub setup_globals {
1.172 albertel 861: my ($request,$target)=@_;
862: $Apache::lonxml::request=$request;
1.99 albertel 863: $Apache::lonxml::registered = 0;
1.205 www 864: $errorcount=0;
865: $warningcount=0;
1.207 albertel 866: $Apache::lonxml::default_homework_loaded=0;
1.212 albertel 867: $Apache::lonxml::usestyle=1;
1.204 albertel 868: &init_counter();
1.101 albertel 869: @Apache::lonxml::pwd=();
1.124 albertel 870: @Apache::lonxml::extlinks=();
1.96 albertel 871: if ($target eq 'meta') {
872: $Apache::lonxml::redirection = 0;
873: $Apache::lonxml::metamode = 1;
874: $Apache::lonxml::evaluate = 1;
875: $Apache::lonxml::import = 0;
1.129 albertel 876: } elsif ($target eq 'answer') {
877: $Apache::lonxml::redirection = 0;
878: $Apache::lonxml::metamode = 1;
879: $Apache::lonxml::evaluate = 1;
880: $Apache::lonxml::import = 1;
1.96 albertel 881: } elsif ($target eq 'grade') {
882: &startredirection;
883: $Apache::lonxml::metamode = 0;
884: $Apache::lonxml::evaluate = 1;
885: $Apache::lonxml::import = 1;
886: } elsif ($target eq 'modified') {
887: $Apache::lonxml::redirection = 0;
888: $Apache::lonxml::metamode = 0;
889: $Apache::lonxml::evaluate = 0;
890: $Apache::lonxml::import = 0;
891: } elsif ($target eq 'edit') {
892: $Apache::lonxml::redirection = 0;
893: $Apache::lonxml::metamode = 0;
894: $Apache::lonxml::evaluate = 0;
895: $Apache::lonxml::import = 0;
1.163 albertel 896: } elsif ($target eq 'analyze') {
897: $Apache::lonxml::redirection = 0;
898: $Apache::lonxml::metamode = 0;
899: $Apache::lonxml::evaluate = 1;
900: $Apache::lonxml::import = 1;
1.96 albertel 901: } else {
902: $Apache::lonxml::redirection = 0;
903: $Apache::lonxml::metamode = 0;
904: $Apache::lonxml::evaluate = 1;
905: $Apache::lonxml::import = 1;
906: }
907: }
908:
1.82 ng 909: sub init_safespace {
910: my ($target,$safeeval,$safehole,$safeinit) = @_;
911: $safeeval->permit("entereval");
912: $safeeval->permit(":base_math");
913: $safeeval->permit("sort");
914: $safeeval->deny(":base_io");
1.102 albertel 915: $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
1.82 ng 916: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
917:
918: $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
919: $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
920: $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
921: $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
922: $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
923: $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
924: $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
925: $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
926: $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
927: $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
928: $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
929: $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
930: $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
931: $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
932: $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
933: $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
934: $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
935: $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
936: $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
1.215 albertel 937:
938: $safehole->wrap(\&Math::Cephes::bdtr ,$safeeval,'&bdtr' );
939: $safehole->wrap(\&Math::Cephes::bdtrc ,$safeeval,'&bdtrc' );
940: $safehole->wrap(\&Math::Cephes::bdtri ,$safeeval,'&bdtri' );
941: $safehole->wrap(\&Math::Cephes::btdtr ,$safeeval,'&btdtr' );
942: $safehole->wrap(\&Math::Cephes::chdtr ,$safeeval,'&chdtr' );
943: $safehole->wrap(\&Math::Cephes::chdtrc,$safeeval,'&chdtrc');
944: $safehole->wrap(\&Math::Cephes::chdtri,$safeeval,'&chdtri');
945: $safehole->wrap(\&Math::Cephes::fdtr ,$safeeval,'&fdtr' );
946: $safehole->wrap(\&Math::Cephes::fdtrc ,$safeeval,'&fdtrc' );
947: $safehole->wrap(\&Math::Cephes::fdtri ,$safeeval,'&fdtri' );
948: $safehole->wrap(\&Math::Cephes::gdtr ,$safeeval,'&gdtr' );
949: $safehole->wrap(\&Math::Cephes::gdtrc ,$safeeval,'&gdtrc' );
950: $safehole->wrap(\&Math::Cephes::nbdtr ,$safeeval,'&nbdtr' );
951: $safehole->wrap(\&Math::Cephes::nbdtrc,$safeeval,'&nbdtrc');
952: $safehole->wrap(\&Math::Cephes::nbdtri,$safeeval,'&nbdtri');
953: $safehole->wrap(\&Math::Cephes::ndtr ,$safeeval,'&ndtr' );
954: $safehole->wrap(\&Math::Cephes::ndtri ,$safeeval,'&ndtri' );
955: $safehole->wrap(\&Math::Cephes::pdtr ,$safeeval,'&pdtr' );
956: $safehole->wrap(\&Math::Cephes::pdtrc ,$safeeval,'&pdtrc' );
957: $safehole->wrap(\&Math::Cephes::pdtri ,$safeeval,'&pdtri' );
958: $safehole->wrap(\&Math::Cephes::stdtr ,$safeeval,'&stdtr' );
959: $safehole->wrap(\&Math::Cephes::stdtri,$safeeval,'&stdtri');
960:
961: # $safehole->wrap(\&Math::Cephes::new_fract,$safeeval,'&new_fract');
962: # $safehole->wrap(\&Math::Cephes::radd,$safeeval,'&radd');
963: # $safehole->wrap(\&Math::Cephes::rsub,$safeeval,'&rsub');
964: # $safehole->wrap(\&Math::Cephes::rmul,$safeeval,'&rmul');
965: # $safehole->wrap(\&Math::Cephes::rdiv,$safeeval,'&rdiv');
966: # $safehole->wrap(\&Math::Cephes::euclid,$safeeval,'&euclid');
967:
1.91 ng 968: $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
969: $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
970: $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
971: $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
972: $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
973: $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
974: $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
975: $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
976: $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
977: $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
978: $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
1.93 ng 979: $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
1.91 ng 980: $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
981: $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
982: $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
983: $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
984: $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
985: $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
986: $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
987: $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
988: $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
989:
1.82 ng 990: #need to inspect this class of ops
991: # $safeeval->deny(":base_orig");
1.91 ng 992: $safeinit .= ';$external::target="'.$target.'";';
1.121 albertel 993: my $rndseed;
1.123 albertel 994: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
995: $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
1.121 albertel 996: $safeinit .= ';$external::randomseed='.$rndseed.';';
1.82 ng 997: &Apache::run::run($safeinit,$safeeval);
1.207 albertel 998: }
999:
1000: sub default_homework_load {
1001: my ($safeeval)=@_;
1002: &Apache::lonxml::debug('Loading default_homework');
1003: my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
1004: if ($default == -1) {
1005: &Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
1006: } else {
1007: &Apache::run::run($default,$safeeval);
1008: $Apache::lonxml::default_homework_loaded=1;
1009: }
1.17 albertel 1010: }
1011:
1.55 albertel 1012: sub startredirection {
1013: $Apache::lonxml::redirection++;
1014: push (@Apache::lonxml::outputstack, '');
1015: }
1016:
1017: sub endredirection {
1018: if (!$Apache::lonxml::redirection) {
1.72 albertel 1019: &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
1.55 albertel 1020: return '';
1021: }
1022: $Apache::lonxml::redirection--;
1023: pop @Apache::lonxml::outputstack;
1.97 albertel 1024: }
1025:
1026: sub end_tag {
1027: my ($tagstack,$parstack,$token)=@_;
1028: pop(@$tagstack);
1029: pop(@$parstack);
1030: &decreasedepth($token);
1.55 albertel 1031: }
1032:
1.17 albertel 1033: sub initdepth {
1034: @Apache::lonxml::depthcounter=();
1035: $Apache::lonxml::depth=-1;
1036: $Apache::lonxml::olddepth=-1;
1037: }
1038:
1039: sub increasedepth {
1.19 albertel 1040: my ($token) = @_;
1.17 albertel 1041: $Apache::lonxml::depth++;
1042: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
1043: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
1044: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
1045: }
1.42 albertel 1046: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 1047: &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54 albertel 1048: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17 albertel 1049: }
1050:
1051: sub decreasedepth {
1.19 albertel 1052: my ($token) = @_;
1.17 albertel 1053: $Apache::lonxml::depth--;
1.36 albertel 1054: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
1055: $#Apache::lonxml::depthcounter--;
1056: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
1057: }
1.43 albertel 1058: if ( $Apache::lonxml::depth < -1) {
1.140 albertel 1059: &Apache::lonxml::warning("Missing tags, unable to properly run file.");
1.43 albertel 1060: $Apache::lonxml::depth='-1';
1061: }
1.42 albertel 1062: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 1063: &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54 albertel 1064: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1 sakharuk 1065: }
1.19 albertel 1066:
1.180 albertel 1067: sub get_all_text_unbalanced {
1.190 albertel 1068: #there is a copy of this in lonpublisher.pm
1.180 albertel 1069: my($tag,$pars)= @_;
1070: my $token;
1071: my $result='';
1072: $tag='<'.$tag.'>';
1073: while ($token = $$pars[-1]->get_token) {
1074: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1075: $result.=$token->[1];
1076: } elsif ($token->[0] eq 'PI') {
1077: $result.=$token->[2];
1078: } elsif ($token->[0] eq 'S') {
1079: $result.=$token->[4];
1080: } elsif ($token->[0] eq 'E') {
1081: $result.=$token->[2];
1082: }
1.211 albertel 1083: if ($result =~ /(.*)\Q$tag\E(.*)/s) {
1.180 albertel 1084: &Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
1085: &Apache::lonxml::debug('Result is :'.$1);
1086: $result=$1;
1087: my $redo=$tag.$2;
1088: &Apache::lonxml::newparser($pars,\$redo);
1089: last;
1090: }
1091: }
1092: return $result
1.204 albertel 1093: }
1094:
1095: sub increment_counter {
1096: $Apache::lonxml::counter++;
1097: $Apache::lonxml::counter_changed=1;
1098: }
1099:
1100: sub init_counter {
1101: if (defined($ENV{'form.counter'})) {
1102: $Apache::lonxml::counter=$ENV{'form.counter'};
1103: } elsif (not defined($Apache::lonxml::counter)) {
1104: $Apache::lonxml::counter=1;
1105: &store_counter();
1106: }
1107: $Apache::lonxml::counter_changed=0;
1108: }
1109:
1110: sub store_counter {
1111: &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter));
1112: return '';
1.180 albertel 1113: }
1114:
1.19 albertel 1115: sub get_all_text {
1116: my($tag,$pars)= @_;
1.212 albertel 1117: &Apache::lonxml::debug("Got a ".ref($pars));
1.224 albertel 1118: my $gotfullstack=1;
1.212 albertel 1119: if (ref($pars) ne 'ARRAY') {
1.224 albertel 1120: $gotfullstack=0;
1.212 albertel 1121: $pars=[$pars];
1122: }
1.19 albertel 1123: my $depth=0;
1124: my $token;
1125: my $result='';
1.57 albertel 1126: if ( $tag =~ m:^/: ) {
1127: my $tag=substr($tag,1);
1.212 albertel 1128: #&Apache::lonxml::debug("have:$tag:");
1.223 albertel 1129: my $top_empty=0;
1130: while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) {
1.212 albertel 1131: while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
1132: #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
1133: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
1134: $result.=$token->[1];
1135: } elsif ($token->[0] eq 'PI') {
1136: $result.=$token->[2];
1137: } elsif ($token->[0] eq 'S') {
1138: if ($token->[1] =~ /^$tag$/i) { $depth++; }
1139: $result.=$token->[4];
1140: } elsif ($token->[0] eq 'E') {
1141: if ( $token->[1] =~ /^$tag$/i) { $depth--; }
1142: #skip sending back the last end tag
1143: if ($depth > -1) { $result.=$token->[2]; } else {
1144: $$pars[-1]->unget_token($token);
1145: }
1.57 albertel 1146: }
1147: }
1.212 albertel 1148: if (($depth >=0) && ($#$pars > 0) ) {
1149: pop(@$pars);
1150: pop(@Apache::lonxml::pwd);
1151: }
1.224 albertel 1152: if (($depth >=0) && ($#$pars == 0) ) { &debug("here4");$top_empty=1; }
1153: }
1154: if ($top_empty && $depth >= 0) {
1155: #never found the end tag ran out of text, throw error send back blank
1156: &error('Never found end tag for <'.$tag.'>');
1157: if ($gotfullstack) {
1158: my $newstring='</'.$tag.'>'.$result;
1159: &Apache::lonxml::newparser($pars,\$newstring);
1160: }
1161: $result='';
1.57 albertel 1162: }
1163: } else {
1.212 albertel 1164: while ($#$pars > -1) {
1165: while ($token = $$pars[-1]->get_token) {
1166: #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
1167: if (($token->[0] eq 'T')||($token->[0] eq 'C')||
1168: ($token->[0] eq 'D')) {
1169: $result.=$token->[1];
1170: } elsif ($token->[0] eq 'PI') {
1171: $result.=$token->[2];
1172: } elsif ($token->[0] eq 'S') {
1173: if ( $token->[1] =~ /^$tag$/i) {
1174: $$pars[-1]->unget_token($token); last;
1175: } else {
1176: $result.=$token->[4];
1177: }
1178: } elsif ($token->[0] eq 'E') {
1179: $result.=$token->[2];
1180: }
1181: }
1182: if (($#$pars > 0) ) {
1183: pop(@$pars);
1184: pop(@Apache::lonxml::pwd);
1185: } else { last; }
1.36 albertel 1186: }
1.19 albertel 1187: }
1.212 albertel 1188: if ($result =~ m|<LONCAPA_INTERNAL_TURN_STYLE_ON />|) {
1189: $Apache::lonxml::usestyle=1;
1190: }
1191: #&Apache::lonxml::debug("Exit:$result:");
1.19 albertel 1192: return $result
1193: }
1194:
1.23 albertel 1195: sub newparser {
1196: my ($parser,$contentref,$dir) = @_;
1.167 albertel 1197: push (@$parser,HTML::LCParser->new($contentref));
1.56 albertel 1198: $$parser['-1']->xml_mode('1');
1.23 albertel 1199: if ( $dir eq '' ) {
1200: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
1201: } else {
1202: push (@Apache::lonxml::pwd, $dir);
1203: }
1204: # &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
1205: # &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
1206: }
1.1 sakharuk 1207:
1.8 albertel 1208: sub parstring {
1209: my ($token) = @_;
1210: my $temp='';
1.142 albertel 1211: foreach (@{$token->[3]}) {
1.35 www 1212: unless ($_=~/\W/) {
1.42 albertel 1213: my $val=$token->[2]->{$_};
1.150 albertel 1214: $val =~ s/([\%\@\\\"])/\\$1/g;
1.51 albertel 1215: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42 albertel 1216: $temp .= "my \$$_=\"$val\";"
1.20 albertel 1217: }
1.142 albertel 1218: }
1.8 albertel 1219: return $temp;
1220: }
1.22 albertel 1221:
1.34 www 1222: sub writeallows {
1.126 www 1223: unless ($#extlinks>=0) { return; }
1.34 www 1224: my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
1.111 www 1225: if ($ENV{'httpref.'.$thisurl}) {
1226: $thisurl=$ENV{'httpref.'.$thisurl};
1227: }
1.34 www 1228: my $thisdir=$thisurl;
1229: $thisdir=~s/\/[^\/]+$//;
1230: my %httpref=();
1.142 albertel 1231: foreach (@extlinks) {
1.34 www 1232: $httpref{'httpref.'.
1.125 www 1233: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
1.142 albertel 1234: }
1.126 www 1235: @extlinks=();
1.34 www 1236: &Apache::lonnet::appenv(%httpref);
1237: }
1238:
1.66 www 1239: #
1240: # Afterburner handles anchors, highlights and links
1241: #
1242: sub afterburn {
1243: my $result=shift;
1.154 albertel 1244: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1245: ['highlight','anchor','link']);
1.66 www 1246: if ($ENV{'form.highlight'}) {
1.142 albertel 1247: foreach (split(/\,/,$ENV{'form.highlight'})) {
1.66 www 1248: my $anchorname=$_;
1249: my $matchthis=$anchorname;
1250: $matchthis=~s/\_+/\\s\+/g;
1251: $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
1.142 albertel 1252: }
1.66 www 1253: }
1254: if ($ENV{'form.link'}) {
1.142 albertel 1255: foreach (split(/\,/,$ENV{'form.link'})) {
1.66 www 1256: my ($anchorname,$linkurl)=split(/\>/,$_);
1257: my $matchthis=$anchorname;
1258: $matchthis=~s/\_+/\\s\+/g;
1259: $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
1.142 albertel 1260: }
1.66 www 1261: }
1262: if ($ENV{'form.anchor'}) {
1263: my $anchorname=$ENV{'form.anchor'};
1264: my $matchthis=$anchorname;
1265: $matchthis=~s/\_+/\\s\+/g;
1266: $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
1267: $result.=(<<"ENDSCRIPT");
1268: <script>
1269: document.location.hash='$anchorname';
1270: </script>
1271: ENDSCRIPT
1272: }
1273: return $result;
1274: }
1275:
1.79 www 1276: sub storefile {
1277: my ($file,$contents)=@_;
1278: if (my $fh=Apache::File->new('>'.$file)) {
1279: print $fh $contents;
1280: $fh->close();
1.147 albertel 1281: } else {
1282: &warning("Unable to save file $file");
1.79 www 1283: }
1284: }
1285:
1.151 albertel 1286: sub createnewhtml {
1287: my $filecontents=(<<SIMPLECONTENT);
1.78 www 1288: <html>
1289: <head>
1290: <title>
1291: Title of Document Goes Here
1292: </title>
1293: </head>
1294: <body bgcolor="#FFFFFF">
1295:
1296: Body of Document Goes Here
1297:
1298: </body>
1299: </html>
1300: SIMPLECONTENT
1.151 albertel 1301: return $filecontents;
1302: }
1303:
1.147 albertel 1304:
1.151 albertel 1305: sub inserteditinfo {
1306: my ($result,$filecontents)=@_;
1.157 albertel 1307: $filecontents = &HTML::Entities::encode($filecontents);
1.147 albertel 1308: # my $editheader='<a href="#editsection">Edit below</a><hr />';
1.161 albertel 1309: my $buttons=(<<BUTTONS);
1310: <input type="submit" name="attemptclean"
1311: value="Save and then attempt to clean HTML" />
1312: <input type="submit" name="savethisfile" value="Save this" />
1313: <input type="submit" name="viewmode" value="View" />
1314: BUTTONS
1.78 www 1315: my $editfooter=(<<ENDFOOTER);
1316: <hr />
1317: <a name="editsection" />
1318: <form method="post">
1.161 albertel 1319: <input type="hidden" name="editmode" value="Edit" />
1.170 www 1320: $buttons<br />
1.78 www 1321: <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
1.170 www 1322: <br />$buttons
1.78 www 1323: <br />
1324: </form>
1325: ENDFOOTER
1.147 albertel 1326: # $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
1.78 www 1327: $result=~s/(\<\/body\>)/$editfooter/is;
1328: return $result;
1329: }
1330:
1.152 albertel 1331: sub get_target {
1332: my $viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
1333: if ( $ENV{'request.state'} eq 'published') {
1334: if ( defined($ENV{'form.grade_target'})
1335: && ($viewgrades == 'F' )) {
1336: return ($ENV{'form.grade_target'});
1.153 albertel 1337: } elsif (defined($ENV{'form.grade_target'})) {
1338: if (($ENV{'form.grade_target'} eq 'web') ||
1339: ($ENV{'form.grade_target'} eq 'tex') ) {
1340: return $ENV{'form.grade_target'}
1341: } else {
1342: return 'web';
1343: }
1.152 albertel 1344: } else {
1345: return 'web';
1346: }
1347: } elsif ($ENV{'request.state'} eq 'construct') {
1348: if ( defined($ENV{'form.grade_target'})) {
1349: return ($ENV{'form.grade_target'});
1350: } else {
1351: return 'web';
1352: }
1353: } else {
1354: return 'web';
1355: }
1356: }
1357:
1.24 sakharuk 1358: sub handler {
1359: my $request=shift;
1.68 www 1360:
1.152 albertel 1361: my $target=&get_target();
1.68 www 1362:
1.65 albertel 1363: $Apache::lonxml::debug=0;
1.68 www 1364:
1.25 sakharuk 1365: if ($ENV{'browser.mathml'}) {
1.27 albertel 1366: $request->content_type('text/xml');
1367: } else {
1368: $request->content_type('text/html');
1.25 sakharuk 1369: }
1.141 albertel 1370: &Apache::loncommon::no_cache($request);
1.27 albertel 1371: $request->send_http_header;
1.141 albertel 1372:
1.45 www 1373: return OK if $request->header_only;
1.27 albertel 1374:
1.79 www 1375:
1376: my $file=&Apache::lonnet::filelocation("",$request->uri);
1.78 www 1377: #
1378: # Edit action? Save file.
1379: #
1380: unless ($ENV{'request.state'} eq 'published') {
1.107 www 1381: if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
1.79 www 1382: &storefile($file,$ENV{'form.filecont'});
1.78 www 1383: }
1384: }
1.24 sakharuk 1385: my %mystyle;
1.147 albertel 1386: my $result = '';
1.50 albertel 1387: my $filecontents=&Apache::lonnet::getfile($file);
1388: if ($filecontents == -1) {
1.78 www 1389: $result=(<<ENDNOTFOUND);
1390: <html>
1391: <head>
1392: <title>File not found</title>
1393: </head>
1394: <body bgcolor="#FFFFFF">
1395: <b>File not found: $file</b>
1396: </body>
1397: </html>
1398: ENDNOTFOUND
1.50 albertel 1399: $filecontents='';
1.151 albertel 1400: if ($ENV{'request.state'} ne 'published') {
1401: $filecontents=&createnewhtml();
1.161 albertel 1402: $ENV{'form.editmode'}='Edit'; #force edit mode
1.151 albertel 1403: }
1.50 albertel 1404: } else {
1.147 albertel 1405: unless ($ENV{'request.state'} eq 'published') {
1406: if ($ENV{'form.attemptclean'}) {
1407: $filecontents=&htmlclean($filecontents,1);
1.107 www 1408: }
1.147 albertel 1409: }
1.161 albertel 1410: if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
1.172 albertel 1411: $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
1412: '',%mystyle);
1.147 albertel 1413: }
1.78 www 1414: }
1415:
1416: #
1417: # Edit action? Insert editing commands
1418: #
1419: unless ($ENV{'request.state'} eq 'published') {
1.161 albertel 1420: if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
1.177 www 1421: my $displayfile=$request->uri;
1422: $displayfile=~s/^\/[^\/]*//;
1423: $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
1424: '</h3></body></html>';
1.78 www 1425: $result=&inserteditinfo($result,$filecontents);
1.147 albertel 1426: }
1.66 www 1427: }
1.147 albertel 1428:
1.126 www 1429: writeallows($request->uri);
1.50 albertel 1430:
1.67 www 1431: $request->print($result);
1.64 albertel 1432:
1.45 www 1433: return OK;
1.24 sakharuk 1434: }
1.147 albertel 1435:
1.22 albertel 1436: sub debug {
1437: if ($Apache::lonxml::debug eq 1) {
1.146 albertel 1438: $|=1;
1.202 albertel 1439: print('<font size="-2"<pre>DEBUG:'.&HTML::Entities::encode($_[0])."</pre></font>\n");
1.22 albertel 1440: }
1441: }
1.49 albertel 1442:
1.22 albertel 1443: sub error {
1.205 www 1444: $errorcount++;
1.74 albertel 1445: if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
1.166 matthew 1446: # If printing in construction space, put the error inside <pre></pre>
1.167 albertel 1447: print "<b>ERROR:</b>".join("\n",@_)."\n";
1.52 albertel 1448: } else {
1449: print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
1450: #notify author
1.146 albertel 1451: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},join('<br />',@_));
1.52 albertel 1452: #notify course
1453: if ( $ENV{'request.course.id'} ) {
1.209 www 1454: my (undef,%users)=&Apache::lonfeedback::decide_receiver(undef,0,1,1,1);
1.143 www 1455: my $declutter=&Apache::lonnet::declutter($ENV{'request.filename'});
1.209 www 1456: foreach (keys %users) {
1457: my ($user,$domain) = split(/:/, $_);
1.143 www 1458: &Apache::lonmsg::user_normal_msg($user,$domain,
1.146 albertel 1459: "Error [$declutter]",join('<br />',@_));
1.52 albertel 1460: }
1461: }
1.74 albertel 1462:
1.52 albertel 1463: #FIXME probably shouldn't have me get everything forever.
1.146 albertel 1464: &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",join('<br />',@_));
1.74 albertel 1465: #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 1466: }
1.22 albertel 1467: }
1.49 albertel 1468:
1.22 albertel 1469: sub warning {
1.205 www 1470: $warningcount++;
1.73 harris41 1471: if ($ENV{'request.state'} eq 'construct') {
1.146 albertel 1472: print "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n";
1.73 harris41 1473: }
1.83 albertel 1474: }
1475:
1476: sub get_param {
1.213 albertel 1477: my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1478: if ( ! $context ) { $context = -1; }
1479: my $args ='';
1480: if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1481: if ( ! $args ) { return undef; }
1482: if ( $case_insensitive ) {
1483: if ($args =~ s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei) {
1484: return &Apache::run::run("{$args;".'return $'.$param.'}',
1485: $safeeval); #'
1486: } else {
1487: return undef;
1488: }
1489: } else {
1490: if ( $args =~ /my \$\Q$param\E=\"/ ) {
1491: return &Apache::run::run("{$args;".'return $'.$param.'}',
1492: $safeeval); #'
1493: } else {
1494: return undef;
1495: }
1496: }
1.22 albertel 1497: }
1498:
1.132 albertel 1499: sub get_param_var {
1.213 albertel 1500: my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
1.132 albertel 1501: if ( ! $context ) { $context = -1; }
1502: my $args ='';
1503: if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
1.213 albertel 1504: if ($case_insensitive) {
1505: if (! ($args=~s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei)) {
1506: return undef;
1507: }
1508: } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
1.132 albertel 1509: my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1510: if ($value =~ /^[\$\@\%]/) {
1511: return &Apache::run::run("return $value",$safeeval,1);
1512: } else {
1513: return $value;
1514: }
1515: }
1516:
1.74 albertel 1517: sub register_insert {
1.75 albertel 1518: my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
1.74 albertel 1519: my $i;
1.76 albertel 1520: my $tagnum=0;
1.74 albertel 1521: my @order;
1522: for ($i=0;$i < $#data; $i++) {
1523: my $line = $data[$i];
1524: if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
1525: if ( $line =~ /TABLE/ ) { last; }
1.92 albertel 1526: my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);
1.135 albertel 1527: if ($tag) {
1528: $insertlist{"$tagnum.tag"} = $tag;
1529: $insertlist{"$tagnum.description"} = $descrip;
1530: $insertlist{"$tagnum.color"} = $color;
1531: $insertlist{"$tagnum.function"} = $function;
1532: if (!defined($show)) { $show='yes'; }
1533: $insertlist{"$tagnum.show"}= $show;
1534: $insertlist{"$tag.num"}=$tagnum;
1535: $tagnum++;
1536: }
1.74 albertel 1537: }
1.76 albertel 1538: $i++; #skipping TABLE line
1539: $tagnum = 0;
1.74 albertel 1540: for (;$i < $#data;$i++) {
1541: my $line = $data[$i];
1.76 albertel 1542: my ($mnemonic,@which) = split(/ +/,$line);
1543: my $tag = $insertlist{"$tagnum.tag"};
1.144 matthew 1544: for (my $j=0;$j <=$#which;$j++) {
1.74 albertel 1545: if ( $which[$j] eq 'Y' ) {
1.76 albertel 1546: if ($insertlist{"$j.show"} ne 'no') {
1547: push(@{ $insertlist{"$tag.which"} },$j);
1548: }
1.74 albertel 1549: }
1550: }
1.76 albertel 1551: $tagnum++;
1.74 albertel 1552: }
1553: }
1.98 albertel 1554:
1555: sub description {
1556: my ($token)=@_;
1.138 albertel 1557: my $tagnum;
1558: my $tag=$token->[1];
1559: foreach my $namespace (reverse @Apache::lonxml::namespace) {
1560: my $testtag=$namespace.'::'.$tag;
1561: $tagnum=$insertlist{"$testtag.num"};
1562: if (defined($tagnum)) { last; }
1563: }
1564: if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
1565: return $insertlist{$tagnum.'.description'};
1.98 albertel 1566: }
1.123 albertel 1567:
1568: # ----------------------------------------------------------------- whichuser
1569: # returns a list of $symb, $courseid, $domain, $name that is correct for
1570: # calls to lonnet functions for this setup.
1571: # - looks for form.grade_ parameters
1572: sub whichuser {
1.134 albertel 1573: my ($symb,$courseid,$domain,$name);
1.123 albertel 1574: if (defined($ENV{'form.grade_symb'})) {
1575: my $tmp_courseid=$ENV{'form.grade_courseid'};
1576: my $allowed=&Apache::lonnet::allowed('mgr',$tmp_courseid);
1577: if ($allowed) {
1578: $symb=$ENV{'form.grade_symb'};
1579: $courseid=$ENV{'form.grade_courseid'};
1580: $domain=$ENV{'form.grade_domain'};
1581: $name=$ENV{'form.grade_username'};
1582: }
1.134 albertel 1583: } else {
1584: $symb=&Apache::lonnet::symbread();
1585: $courseid=$ENV{'request.course.id'};
1586: $domain=$ENV{'user.domain'};
1587: $name=$ENV{'user.name'};
1.123 albertel 1588: }
1589: return ($symb,$courseid,$domain,$name);
1590: }
1591:
1.1 sakharuk 1592: 1;
1593: __END__
1.68 www 1594:
1595:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>