Annotation of loncom/xml/lonxml.pm, revision 1.182

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>