--- loncom/xml/lonxml.pm 2023/11/27 22:44:21 1.563 +++ loncom/xml/lonxml.pm 2024/09/25 00:15:10 1.574 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA -# XML Parser Module +# XML Parser Module # -# $Id: lonxml.pm,v 1.563 2023/11/27 22:44:21 raeburn Exp $ +# $Id: lonxml.pm,v 1.574 2024/09/25 00:15:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,13 +25,13 @@ # # http://www.lon-capa.org/ # -# Copyright for TtHfunc and TtMfunc by Ian Hutchinson. -# TtHfunc and TtMfunc (the "Code") may be compiled and linked into -# binary executable programs or libraries distributed by the -# Michigan State University (the "Licensee"), but any binaries so +# Copyright for TtHfunc and TtMfunc by Ian Hutchinson. +# TtHfunc and TtMfunc (the "Code") may be compiled and linked into +# binary executable programs or libraries distributed by the +# Michigan State University (the "Licensee"), but any binaries so # distributed are hereby licensed only for use in the context -# of a program or computational system for which the Licensee is the -# primary author or distributor, and which performs substantial +# of a program or computational system for which the Licensee is the +# primary author or distributor, and which performs substantial # additional tasks beyond the translation of (La)TeX into HTML. # The C source of the Code may not be distributed by the Licensee # to any other parties under any circumstances. @@ -57,7 +57,7 @@ described at http://www.lon-capa.org. -package Apache::lonxml; +package Apache::lonxml; use vars qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $errorcount $warningcount); use strict; @@ -117,7 +117,7 @@ use Apache::lonhtmlcommon(); use Apache::functionplotresponse(); use Apache::lonnavmaps(); -#==================================== Main subroutine: xmlparse +#==================================== Main subroutine: xmlparse #debugging control, to turn on debugging modify the correct handler @@ -208,7 +208,7 @@ sub xmlend { if ($Apache::lonhomework::parsing_a_problem || $Apache::lonhomework::parsing_a_task ) { $mode='problem'; - $status=$Apache::inputtags::status[-1]; + $status=$Apache::inputtags::status[-1]; } my $discussion; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, @@ -317,7 +317,7 @@ sub xmlparse { } &init_state(); if ($env{'form.return_only_error_and_warning_counts'}) { - if ($env{'request.filename'}=~/\.(html|htm|xml)$/i) { + if ($env{'request.filename'}=~/\.(html|htm|xml)$/i) { my $error=&verify_html($content_file_string); if ($error) { $errorcount++; } } @@ -343,7 +343,7 @@ sub latex_special_symbols { $string=~s/([^\\])\&/$1\\\&/g; $string=~s/([^\\])\#/$1\\\#/g; $string =~ s/_/\\_/g; # _ -> \_ - $string =~ s/\^/\\\^{}/g; # ^ -> \^{} + $string =~ s/\^/\\\^{}/g; # ^ -> \^{} } else { $string=~s/\\/\\ensuremath{\\backslash}/g; $string=~s/\\\%|\%/\\\%/g; @@ -469,7 +469,7 @@ sub inner_xmlparse { if ($token->[0] eq 'E') { if ($dontpop) { - $lastdontpop = $token; + $lastdontpop = $token; } else { $lastendtag = $token->[1]; &end_tag($stack,$parstack,$token); @@ -483,7 +483,7 @@ sub inner_xmlparse { } } - if (($#$stack == 0) && ($stack->[0] eq 'physnet') && ($target eq 'web') && + if (($#$stack == 0) && ($stack->[0] eq 'physnet') && ($target eq 'web') && ($lastendtag eq 'LONCAPA_INTERNAL_TURN_STYLE_ON')) { if ((ref($lastdontpop) eq 'ARRAY') && ($lastdontpop->[1] eq 'physnet')) { &end_tag($stack,$parstack,$lastdontpop); @@ -506,11 +506,11 @@ sub inner_xmlparse { if ($target eq 'modified') { # if modfied, handle startpart and endpart $finaloutput=~s/\]*\>(.*)\]*\>/$1<\/part>/gs; - } + } return $finaloutput; } -## +## ## Looks to see if there is a subroutine defined for this tag. If so, call it, ## otherwise do not call it as we do not know what it is. ## @@ -597,7 +597,7 @@ sub callsub { sub init_state { undef(%state); } - + sub set_state { my ($key,$value) = @_; $state{$key} = $value; @@ -699,7 +699,7 @@ sub init_safespace { $safehole->wrap(\&Apache::lonr::r_check,$safeeval,'&r_check'); $safehole->wrap(\&Apache::lonr::r_cas_formula_fix,$safeeval, '&r_cas_formula_fix'); - + $safehole->wrap(\&Apache::caparesponse::capa_formula_fix,$safeeval, '&capa_formula_fix'); @@ -725,7 +725,7 @@ sub init_safespace { $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1'); $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn'); $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv'); - + $safehole->wrap(\&Math::Cephes::bdtr ,$safeeval,'&bdtr' ); $safehole->wrap(\&Math::Cephes::bdtrc ,$safeeval,'&bdtrc' ); $safehole->wrap(\&Math::Cephes::bdtri ,$safeeval,'&bdtri' ); @@ -1072,7 +1072,7 @@ sub increment_counter { } $Apache::lonxml::counter += $increment; - # If the caller supplied the response_id parameter, + # If the caller supplied the response_id parameter, # Maintain its counter.. creating if necessary. if (defined($part_response)) { @@ -1193,7 +1193,7 @@ sub set_bubble_lines { =item get_bubble_line_hash -Returns the current bubble line hash. This is assumed to +Returns the current bubble line hash. This is assumed to be small so we return a copy @@ -1219,8 +1219,8 @@ sub get_all_text { my $depth=0; my $token; my $result=''; - if ( $tag =~ m:^/: ) { - my $tag=substr($tag,1); + if ( $tag =~ m:^/: ) { + my $tag=substr($tag,1); #&Apache::lonxml::debug("have:$tag:"); my $top_empty=0; while (($depth >=0) && ($#$pars > -1) && (!$top_empty)) { @@ -1321,7 +1321,7 @@ sub newparser { push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]); } else { push (@Apache::lonxml::pwd, $dir); - } + } } sub parstring { @@ -1338,7 +1338,7 @@ sub parstring { push(@values,"\"$val\""); } } - my $var_init = + my $var_init = (@vars) ? 'my ('.join(',',@vars).') = ('.join(',',@values).');' : ''; return $var_init; @@ -1591,7 +1591,7 @@ FULLPAGE } } elsif ($symb || $folderpath) { $deps_button = &Apache::lonhtmlcommon::dependencies_button()."\n"; - $initialize .= + $initialize .= &Apache::lonhtmlcommon::dependencycheck_js($symb,$itemtitle, undef,$folderpath,$uri)."\n"; } @@ -1613,8 +1613,9 @@ FULLPAGE my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit', 'vi' => 'Save and View', 'dv' => 'Discard Edits and View', - 'un' => 'undo', - 'ed' => 'Edit'); + 'un' => 'Undo', + 'ed' => 'Edit', + 'ew' => 'Edit with Daxe'); my $spelllink = &Apache::lonhtmlcommon::spelllink('xmledit','filecont'); my $textarea_events = &Apache::edit::element_change_detection(); my $form_events = &Apache::edit::form_change_detection(); @@ -1622,7 +1623,7 @@ FULLPAGE if ($filetype eq 'html') { $htmlerror=&verify_html($filecontents); if ($htmlerror) { - $htmlerror=''.$htmlerror.''; + $htmlerror=(' 'x3).' '.$htmlerror.''; } if (&Apache::lonhtmlcommon::htmlareabrowser()) { unless ($textareaclass) { @@ -1630,14 +1631,30 @@ FULLPAGE } } } - my $undo; + my ($undo,$daxebutton,%onclick); + foreach my $item ('discard','undo','daxe') { + $onclick{$item} = 'onclick="still_ask=true;setmode(this.form,'."'$item'".')"'; + } + foreach my $item ('saveedit','saveview') { + $onclick{$item} = 'onclick="is_submit=true;setmode(this.form,'."'$item'".')"'; + } unless ($uri =~ m{^/uploaded/}) { - $undo = ''."\n"; + $undo = ''."\n"; + } + $initialize .= &setmode_javascript(); + if ($filetype eq 'html') { + my %editors = &Apache::loncommon::permitted_editors($uri); + if ($editors{'daxe'}) { + $daxebutton = ''."\n"; + } } my $editfooter=(<
+
$filename @@ -1645,13 +1662,13 @@ $initialize $xml_help
-
- - $undo $htmlerror $deps_button $dragmath_button -
- - + + +
+
+ + $undo $deps_button $daxebutton $dragmath_button $htmlerror

$spelllink @@ -1661,7 +1678,7 @@ $initialize
ENDFOOTER - return ($editfooter,$add_to_onload,$add_to_onresize);; + return ($editfooter,$add_to_onload,$add_to_onresize); } sub setmode_javascript { @@ -1684,6 +1701,76 @@ function setmode(form,probmode) { ENDSCRIPT } +sub seteditor_javascript { + my ($is_course_doc,$is_supp,$supp_path,$supp_title) = @_; + my $symb; + if ($is_course_doc) { + if (!$is_supp) { + ($symb) = &Apache::lonnet::whichuser(); + if ($symb) { + $symb = &escape($symb); + } + } + } + return <<"ENDSCRIPT"; + +ENDSCRIPT +} + sub get_target { my $viewgrades=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); if ( $env{'request.state'} eq 'published') { @@ -1716,7 +1803,7 @@ sub handler { my $target=&get_target(); $Apache::lonxml::debug=$env{'user.debug'}; - + &Apache::loncommon::content_type($request,'text/html'); &Apache::loncommon::no_cache($request); if ($env{'request.state'} eq 'published') { @@ -1724,7 +1811,7 @@ sub handler { 'lastrevisiondate')); } # Embedded Flash movies from Camtasia served from https will not display in IE - # if XML config file has expired from cache. + # if XML config file has expired from cache. if ($ENV{'SERVER_PORT'} == 443) { if ($request->uri =~ /\.xml$/) { my ($httpbrowser,$clientbrowser) = @@ -1739,7 +1826,7 @@ sub handler { } } $request->send_http_header; - + return OK if $request->header_only; @@ -1786,11 +1873,13 @@ sub handler { # Edit action? Save file. # if (!($env{'request.state'} eq 'published')) { - if ($env{'form.savethisfile'} || $env{'form.viewmode'} || $env{'form.Undo'}) { + if (($env{'form.problemmode'} eq 'saveedit') || + ($env{'form.problemmode'} eq 'saveview') || + ($env{'form.problemmode'} eq 'undo')) { my $html_file=&Apache::lonnet::getfile($file); my $error = &Apache::lonhomework::handle_save_or_undo($request, \$html_file, \$env{'form.filecont'}); - if ($env{'form.savethisfile'}) { - $env{'form.editmode'}='Edit'; #force edit mode + if ($env{'form.problemmode'} eq 'saveedit') { + $env{'form.editmode'}='edit'; #force edit mode } } } @@ -1819,7 +1908,7 @@ ENDNOTFOUND } elsif ($filetype ne 'css' && $filetype ne 'txt' && $filetype ne 'tex') { $filecontents=&createnewhtml(); } - $env{'form.editmode'}='Edit'; #force edit mode + $env{'form.editmode'}='edit'; #force edit mode } } else { unless ($env{'request.state'} eq 'published') { @@ -1831,7 +1920,9 @@ ENDNOTFOUND &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['editmode']); } - if (!$env{'form.editmode'} || $env{'form.viewmode'} || $env{'form.discardview'}) { + if ((!$env{'form.editmode'}) || + ($env{'form.problemmode'} eq 'saveview') || + ($env{'form.problemmode'} eq 'discard')) { if ($filetype eq 'html' || $filetype eq 'sty') { &Apache::structuretags::reset_problem_globals(); $result = &Apache::lonxml::xmlparse($request,$target, @@ -1858,7 +1949,7 @@ ENDNOTFOUND $inhibit_menu = 1; } } - if (($filetype ne 'html') && + if (($filetype ne 'html') && (!$env{'form.return_only_error_and_warning_counts'}) && (!$inhibit_menu)) { my $nochgview = 1; @@ -1908,15 +1999,22 @@ ENDNOTFOUND # Edit action? Insert editing commands # unless (($env{'request.state'} eq 'published') || ($inhibit_menu)) { - if ($env{'form.editmode'} && (!($env{'form.viewmode'})) && (!($env{'form.discardview'}))) - { + if (($env{'form.editmode'}) && + (!($env{'form.problemmode'} eq 'saveview')) && + (!($env{'form.problemmode'} eq 'discard'))) { my ($displayfile,$url,$symb,$itemtitle,$action); $displayfile=$request->uri; if ($request->uri =~ m{^/uploaded/}) { if ($env{'request.course.id'}) { - if ($request->uri =~ m{^\Q/uploaded/$cdom/$cnum/supplemental/\E}) { - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['folderpath','title']); + if ($request->uri =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental)/}) { + if ($1 eq 'supplemental') { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['folderpath','title']); + } + if (($env{'request.state'} eq 'edit') && ($env{'form.editmode'} eq 'edit') && + ($filetype eq 'html')) { + &Apache::lonhtmlcommon::clear_breadcrumbs(); + } } elsif ($request->uri =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) { my $filename = $1; if ($1 eq 'loncapa.html') { @@ -1929,7 +2027,7 @@ ENDNOTFOUND } } unless ($itemtitle) { - ($symb,$itemtitle,$displayfile) = + ($symb,$itemtitle,$displayfile) = &get_courseupload_hierarchy($request->uri, $env{'form.folderpath'}, $env{'form.title'}); @@ -1942,7 +2040,7 @@ ENDNOTFOUND &inserteditinfo($filecontents,$filetype,$displayfile,$symb, $itemtitle,$env{'form.folderpath'},$request->uri,$action); - my %options = + my %options = ('add_entries' => {'onresize' => $add_to_onresize, 'onload' => $add_to_onload, }); @@ -1981,7 +2079,7 @@ ENDNOTFOUND &Apache::lonxml::add_messages(\$result); $request->print($result); - + return OK; } @@ -2014,6 +2112,7 @@ sub get_courseupload_hierarchy { } if ($title) { push(@pathitems,&unescape($title)); + $itemtitle = $title; } $displaypath = join(' » ',@pathitems); } else { @@ -2051,7 +2150,7 @@ sub debug { } sub show_error_warn_msg { - if (($env{'request.filename'} eq + if (($env{'request.filename'} eq $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/lib/templates/simpleproblem.problem') && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { return 1; @@ -2146,7 +2245,7 @@ sub error { sub warning { $warningcount++; - + if ($env{'form.grade_target'} ne 'tex') { if ( &show_error_warn_msg() ) { push(@Apache::lonxml::warning_messages, @@ -2161,7 +2260,7 @@ sub warning { } sub info { - if ($env{'form.grade_target'} ne 'tex' + if ($env{'form.grade_target'} ne 'tex' && $env{'request.state'} eq 'construct') { push(@Apache::lonxml::info_messages,join('
',@_)."
\n"); } @@ -2211,7 +2310,7 @@ sub get_param { } } else { if ( $args =~ /my .*\$\Q$param\E[,\)]/ ) { - + return &Apache::run::run("{$args;".'return $'.$param.'}', $safeeval); #' } else { @@ -2293,7 +2392,7 @@ sub register_insert_xml { } } } - + # parse the allows and ignore tags set to no foreach my $tag (@alltags) { next if (!exists($insertlist{$tag.'.allow'})); @@ -2399,7 +2498,7 @@ sub get_tag { =item &print_pdf_radiobutton(fieldname, value) Returns a latexline to generate a PDF-Form-Radiobutton. -Note: Radiobuttons with equal names are automaticly grouped +Note: Radiobuttons with equal names are automaticly grouped in a selection-group. $fieldname: PDF internalname of the radiobutton(group) @@ -2426,7 +2525,7 @@ sub print_pdf_start_combobox { my $result; my ($fieldName) = @_; $result .= '\begin{tabularx}{\textwidth}{p{2.5cm}X}'."\n"; - $result .= '\comboBox[]{'.$fieldName.'}{2.3cm}{14bp}{'; # + $result .= '\comboBox[]{'.$fieldName.'}{2.3cm}{14bp}{'; # return $result; } @@ -2444,10 +2543,10 @@ $option: PDF internal name of the Combob sub print_pdf_add_combobox_option { my $result; - my ($option) = @_; + my ($option) = @_; $result .= '('.$option.')'; - + return $result; }