--- loncom/xml/lonxml.pm 2002/06/03 21:07:20 1.176 +++ loncom/xml/lonxml.pm 2002/10/17 17:13:44 1.204 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.176 2002/06/03 21:07:20 www Exp $ +# $Id: lonxml.pm,v 1.204 2002/10/17 17:13:44 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,6 +99,8 @@ 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 @@ -138,6 +140,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 +160,7 @@ sub xmlbegin { } sub xmlend { + my ($discussiononly,$symb)=@_; my $discussion=''; if ($ENV{'request.course.id'}) { my $crs='/'.$ENV{'request.course.id'}; @@ -162,32 +169,47 @@ 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.= - '

Course Discussion of Resource

'; + unless ($discussiononly) { + $discussion.= + '

'; + } my $idx; for ($idx=1;$idx<=$contrib{'version'};$idx++) { my $hidden=($contrib{'hidden'}=~/\.$idx\./); unless (($hidden) && (!$seeid)) { my $message=$contrib{$idx.':message'}; $message=~s/\n/\
/g; + $message=&Apache::lontexconvert::msgtexconverted($message); if ($message) { if ($hidden) { $message=''.$message.''; } + 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) { @@ -199,8 +221,8 @@ sub xmlend { } } } else { - if ($contrib{$idx.':screenname'}) { - $sender=''.$contrib{$idx.':screenname'}.''; + if ($screenname) { + $sender=''.$screenname.''; } } $discussion.='

'.$sender.' ('. @@ -210,11 +232,28 @@ sub xmlend { } } } - $discussion.='

'; + unless ($discussiononly) { + $discussion.='
'; + } + } + if ($discussiononly) { + $discussion.=(< + + + + +
+Note: in anonymous discussion, your name is visible only to +course faculty
+ + +ENDDISCUSS + $discussion.=&Apache::lonfeedback::generate_preview_button(); } } } - return $discussion.''; + return $discussion.($discussiononly?'':''); } sub tokeninputfield { @@ -331,17 +370,28 @@ sub registerurl { my $forcereg=shift; my $target = shift; my $result = ''; + + if ($target eq 'edit') { + $result .="\n"; + } if ((($ENV{'request.publicaccess'}) || (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) && (!$forcereg)) { - return + return $result. ''; } if ($Apache::lonxml::registered && !$forcereg) { return ''; } $Apache::lonxml::registered=1; my $nothing=''; if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; } - my $timesync='menu.clock.setTime(1000*'.time.');'; + 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=''; if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) { @@ -370,6 +420,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; @@ -379,7 +430,7 @@ ENDPARM menu.switchbutton (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)'); menu.switchbutton - (8,2,'fdbk.gif','feedback','on this','gopost("/adm/feedback",currentURL)'); + (8,2,'fdbk.gif','feedback','discuss','gopost("/adm/feedback",currentURL)'); menu.switchbutton (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)'); menu.switchbutton @@ -446,61 +497,6 @@ ENDREGTHIS ENDDONOTREGTHIS } - if ($target eq 'edit') { - # Javascript routines for construction space: - # openbrowser and opensearcher will start the file browser - # (lonindexer) and searcher (lonsearchcat) respectively. - # Inputs are the name of the html form being used - # and the name of the element the selected URL should - # be placed in. - # openbrowser also takes arguments only and omit, which are - # comma deliminated lists of file extensions to (only) show - # or omit. - # Here we also set currentURL=null. - $result .=<<"ENDBROWSERSCRIPT"; - -ENDBROWSERSCRIPT - } return $result; } @@ -524,6 +520,23 @@ sub xmlparse { my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_; &setup_globals($request,$target); +# +# do we have a course style file? +# + + if ($ENV{'request.course.id'}) { + my $bodytext= + $ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'}; + if ($bodytext) { + my $location=&Apache::lonnet::filelocation('',$bodytext); + my $styletext=&Apache::lonnet::getfile($location); + if ($styletext ne '-1') { + %style_for_target = (%style_for_target, + &Apache::style::styleparser($target,$styletext)); + } + } + } + #&printalltags(); my @pars = (); my $pwd=$ENV{'request.filename'}; @@ -546,6 +559,7 @@ sub xmlparse { if ($ENV{'request.uri'}) { &writeallows($ENV{'request.uri'}); } + if ($Apache::lonxml::counter_changed) { &store_counter() } return $finaloutput; } @@ -570,6 +584,22 @@ sub htmlclean { return $output; } +sub latex_special_symbols { + my ($current_token,$stack,$parstack)=@_; + $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/(\$|_|{|})/\\$1/g; + $current_token=~s/\\char92 /\\texttt{\\char92}/g; + $current_token=~s/>/\$>\$/g; #more + $current_token=~s/get_token) { if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { if ($metamode<1) { - $result=$token->[1]; + my $text=$token->[1]; + if ($token->[0] eq 'C' && $target eq 'tex') { + $text = '%'.$text; + $text =~ s/[\n\r]//g; + } + $result.=$text; } } elsif ($token->[0] eq 'PI') { if ($metamode<1) { @@ -642,6 +677,12 @@ sub inner_xmlparse { $result= &Apache::run::evaluate($result,$safeeval,''); } } + if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { + if ($target eq 'tex') { + $result=&latex_special_symbols($result,$stack,$parstack); + } + } + # Encode any high ASCII characters if (!$Apache::lonxml::prevent_entity_encode) { $result=&HTML::Entities::encode($result,"\200-\377"); @@ -768,13 +809,13 @@ sub callsub { } if (!$deleted) { if ($space) { - #&Apache::lonxml::debug("Calling sub $sub in $space $metamode"); + &Apache::lonxml::debug("Calling sub $sub in $space $metamode"); $sub1="$space\:\:$sub"; ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack, $parstack,$parser,$safeeval, $style); } else { - #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode"); + &Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode"); if ($metamode <1) { if (defined($token->[4]) && ($metamode < 1)) { $currentstring = $token->[4]; @@ -811,6 +852,7 @@ sub setup_globals { my ($request,$target)=@_; $Apache::lonxml::request=$request; $Apache::lonxml::registered = 0; + &init_counter(); @Apache::lonxml::pwd=(); @Apache::lonxml::extlinks=(); if ($target eq 'meta') { @@ -966,8 +1008,55 @@ sub decreasedepth { #print "
e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n"; } -sub get_all_text { +sub get_all_text_unbalanced { +#there is a copy of this in lonpublisher.pm + my($tag,$pars)= @_; + my $token; + my $result=''; + $tag='<'.$tag.'>'; + while ($token = $$pars[-1]->get_token) { + if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) { + $result.=$token->[1]; + } elsif ($token->[0] eq 'PI') { + $result.=$token->[2]; + } elsif ($token->[0] eq 'S') { + $result.=$token->[4]; + } elsif ($token->[0] eq 'E') { + $result.=$token->[2]; + } + if ($result =~ /(.*)$tag(.*)/) { + &Apache::lonxml::debug('Got a winner with leftovers ::'.$2); + &Apache::lonxml::debug('Result is :'.$1); + $result=$1; + my $redo=$tag.$2; + &Apache::lonxml::newparser($pars,\$redo); + last; + } + } + 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; my $token; @@ -1240,7 +1329,10 @@ ENDNOTFOUND # unless ($ENV{'request.state'} eq 'published') { if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) { - $result=''; + my $displayfile=$request->uri; + $displayfile=~s/^\/[^\/]*//; + $result='

'.$displayfile. + '

'; $result=&inserteditinfo($result,$filecontents); } } @@ -1255,7 +1347,7 @@ ENDNOTFOUND sub debug { if ($Apache::lonxml::debug eq 1) { $|=1; - print("DEBUG:".join('
',@_)."
\n"); + print('DEBUG:'.&HTML::Entities::encode($_[0])."\n"); } }