--- loncom/xml/lonxml.pm 2002/09/04 06:55:27 1.192 +++ loncom/xml/lonxml.pm 2002/10/21 17:10:35 1.206 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.192 2002/09/04 06:55:27 albertel Exp $ +# $Id: lonxml.pm,v 1.206 2002/10/21 17:10:35 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,7 +60,7 @@ package Apache::lonxml; use vars -qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode); +qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode $errorcount $warningcount); use strict; use HTML::LCParser(); use HTML::TreeBuilder(); @@ -99,11 +99,17 @@ use Apache::edit(); use Apache::lonnet(); use Apache::File(); use Apache::loncommon(); +use Apache::lonfeedback(); +use Apache::lonmsg(); #================================================== Main subroutine: xmlparse #debugging control, to turn on debugging modify the correct handler $Apache::lonxml::debug=0; +# keeps count of the number of warnings and errors generated in a parse +$warningcount=0; +$errorcount=0; + #path to the directory containing the file currently being processed @pwd=(); @@ -138,6 +144,10 @@ $Apache::lonxml::registered=0; # a pointer the the Apache request object $Apache::lonxml::request=''; +# a problem number counter, and check on hether it is used +$Apache::lonxml::counter=0; +$Apache::lonxml::counter_changed=0; + sub xmlbegin { my $output=''; if ($ENV{'browser.mathml'}) { @@ -154,6 +164,7 @@ sub xmlbegin { } sub xmlend { + my ($discussiononly,$symb)=@_; my $discussion=''; if ($ENV{'request.course.id'}) { my $crs='/'.$ENV{'request.course.id'}; @@ -162,14 +173,18 @@ sub xmlend { } $crs=~s/\_/\//g; my $seeid=&Apache::lonnet::allowed('rin',$crs); - my $symb=&Apache::lonnet::symbread(); + unless ($symb) { + $symb=&Apache::lonnet::symbread(); + } if ($symb) { my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); if ($contrib{'version'}) { - $discussion.= - '<address><hr /><h2>Course Discussion of Resource</h2>'; + unless ($discussiononly) { + $discussion.= + '<address><hr />'; + } my $idx; for ($idx=1;$idx<=$contrib{'version'};$idx++) { my $hidden=($contrib{'hidden'}=~/\.$idx\./); @@ -181,14 +196,24 @@ sub xmlend { if ($hidden) { $message='<font color="#888888">'.$message.'</font>'; } + my $screenname=&Apache::loncommon::screenname( + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + my $plainname=&Apache::loncommon::nickname( + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + my $sender='Anonymous'; if ((!$contrib{$idx.':anonymous'}) || ($seeid)) { - $sender=$contrib{$idx.':plainname'}.' ('. + $sender=&Apache::loncommon::aboutmewrapper( + $plainname, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}).' ('. $contrib{$idx.':sendername'}.' at '. $contrib{$idx.':senderdomain'}.')'; if ($contrib{$idx.':anonymous'}) { $sender.=' [anonymous] '. - $contrib{$idx.':screenname'}; + $screenname; } if ($seeid) { if ($hidden) { @@ -200,8 +225,8 @@ sub xmlend { } } } else { - if ($contrib{$idx.':screenname'}) { - $sender='<i>'.$contrib{$idx.':screenname'}.'</i>'; + if ($screenname) { + $sender='<i>'.$screenname.'</i>'; } } $discussion.='<p><b>'.$sender.'</b> ('. @@ -211,11 +236,28 @@ sub xmlend { } } } - $discussion.='</address>'; + unless ($discussiononly) { + $discussion.='</address>'; + } + } + if ($discussiononly) { + $discussion.=(<<ENDDISCUSS); +<form action="/adm/feedback" method="post" name="mailform"> +<input type="submit" name="discuss" value="Post Discussion" /> +<input type="submit" name="anondiscuss" value="Post Anonymous Discussion" /> +<input type="hidden" name="symb" value="$symb" /> +<input type="hidden" name="sendit" value="true" /> +<br /> +<font size="1">Note: in anonymous discussion, your name is visible only to +course faculty</font><br /> +<textarea name=comment cols=60 rows=10 wrap=hard></textarea> +</form> +ENDDISCUSS + $discussion.=&Apache::lonfeedback::generate_preview_button(); } } } - return $discussion.'</html>'; + return $discussion.($discussiononly?'':'</html>'); } sub tokeninputfield { @@ -332,6 +374,7 @@ sub registerurl { my $forcereg=shift; my $target = shift; my $result = ''; + if ($target eq 'edit') { $result .="<script>\n". "if (typeof menu != 'undefined') {menu.currentURL=null;}\n". @@ -348,6 +391,10 @@ sub registerurl { $Apache::lonxml::registered=1; my $nothing=''; if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; } + my $newmail=''; + if (&Apache::lonmsg::newmail()) { + $newmail='menu.setstatus("you have","messages");'; + } my $timesync='menu.syncclock(1000*'.time.');'; if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) { my $hwkadd=''; @@ -377,6 +424,7 @@ ENDPARM menu=window.open("$nothing","LONCAPAmenu","",false); menu.clearTimeout(menu.menucltim); $timesync + $newmail menu.currentURL=window.location.pathname; menu.reloadURL=window.location.pathname; menu.currentStale=0; @@ -515,6 +563,7 @@ sub xmlparse { if ($ENV{'request.uri'}) { &writeallows($ENV{'request.uri'}); } + if ($Apache::lonxml::counter_changed) { &store_counter() } return $finaloutput; } @@ -544,8 +593,8 @@ sub latex_special_symbols { $current_token=~s/\\/\\char92 /g; $current_token=~s/\^/\\char94 /g; $current_token=~s/\~/\\char126 /g; - $current_token=~s/(&[^a-z#])/\\$1/g; - $current_token=~s/([^&]\#)/\\$1/g; + $current_token=~s/(&[^a-z\#])/\\$1/g; + $current_token=~s/([^&])\#/$1\\#/g; $current_token=~s/(\$|_|{|})/\\$1/g; $current_token=~s/\\char92 /\\texttt{\\char92}/g; $current_token=~s/>/\$>\$/g; #more @@ -565,7 +614,7 @@ sub inner_xmlparse { if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { if ($metamode<1) { my $text=$token->[1]; - if ($token->[0] eq 'C') { + if ($token->[0] eq 'C' && $target eq 'tex') { $text = '%'.$text; $text =~ s/[\n\r]//g; } @@ -807,6 +856,9 @@ sub setup_globals { my ($request,$target)=@_; $Apache::lonxml::request=$request; $Apache::lonxml::registered = 0; + $errorcount=0; + $warningcount=0; + &init_counter(); @Apache::lonxml::pwd=(); @Apache::lonxml::extlinks=(); if ($target eq 'meta') { @@ -990,6 +1042,26 @@ sub get_all_text_unbalanced { return $result } +sub increment_counter { + $Apache::lonxml::counter++; + $Apache::lonxml::counter_changed=1; +} + +sub init_counter { + if (defined($ENV{'form.counter'})) { + $Apache::lonxml::counter=$ENV{'form.counter'}; + } elsif (not defined($Apache::lonxml::counter)) { + $Apache::lonxml::counter=1; + &store_counter(); + } + $Apache::lonxml::counter_changed=0; +} + +sub store_counter { + &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter)); + return ''; +} + sub get_all_text { my($tag,$pars)= @_; my $depth=0; @@ -1281,11 +1353,12 @@ ENDNOTFOUND sub debug { if ($Apache::lonxml::debug eq 1) { $|=1; - print("DEBUG:".&HTML::Entities::encode($_[0])."<br />\n"); + print('<font size="-2"<pre>DEBUG:'.&HTML::Entities::encode($_[0])."</pre></font>\n"); } } sub error { + $errorcount++; if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) { # If printing in construction space, put the error inside <pre></pre> print "<b>ERROR:</b>".join("\n",@_)."\n"; @@ -1311,6 +1384,7 @@ sub error { } sub warning { + $warningcount++; if ($ENV{'request.state'} eq 'construct') { print "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n"; }