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