--- loncom/xml/lonxml.pm 2017/11/16 23:54:43 1.531.2.22.2.1 +++ loncom/xml/lonxml.pm 2024/07/08 01:05:55 1.531.2.27 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.531.2.22.2.1 2017/11/16 23:54:43 raeburn Exp $ +# $Id: lonxml.pm,v 1.531.2.27 2024/07/08 01:05:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -69,6 +69,8 @@ use Safe(); use Safe::Hole(); use Math::Cephes(); use Math::Random(); +use Math::Calculus::Expression(); +use Number::FormatEng(); use Opcode(); use POSIX qw(strftime); use Time::HiRes qw( gettimeofday tv_interval ); @@ -440,7 +442,7 @@ sub latex_special_symbols { } else { $string=~s/\\/\\ensuremath{\\backslash}/g; $string=~s/\\\%|\%/\\\%/g; - $string=~s/\\\{|{/\\{/g; + $string=~s/\\\{|\{/\\{/g; $string=~s/\\}|}/\\}/g; $string=~s/\\ensuremath\\\{\\backslash\\}/\\ensuremath{\\backslash}/g; $string=~s/\\\$|\$/\\\$/g; @@ -914,6 +916,9 @@ sub init_safespace { $safehole->wrap(\&Apache::functionplotresponse::fpr_objectcoords,$safeeval,'&fpr_objectcoords'); $safehole->wrap(\&Apache::functionplotresponse::fpr_vectorlength,$safeeval,'&fpr_vectorlength'); $safehole->wrap(\&Apache::functionplotresponse::fpr_vectorangle,$safeeval,'&fpr_vectorangle'); + $safehole->wrap(\&Math::Calculus::Expression::math_calculus_expression,$safeeval,'&math_calculus_expression'); + $safehole->wrap(\&Number::FormatEng::format_eng,$safeeval,'&number_format_eng'); + $safehole->wrap(\&Number::FormatEng::format_pref,$safeeval,'&number_format_pref'); # use Data::Dumper; # $safehole->wrap(\&Data::Dumper::Dumper,$safeeval,'&LONCAPA_INTERNAL_Dumper'); @@ -1086,7 +1091,7 @@ sub decreasedepth { sub get_id { my ($parstack,$safeeval)=@_; my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); - if ($env{'request.state'} eq 'construct' && $id =~ /([._]|[^\w\d\s[:punct:]])/) { + if ($env{'request.state'} eq 'construct' && $id =~ /([._]|[^\w\s\-])/) { &error(&mt('ID [_1] contains invalid characters. IDs are only allowed to contain letters, numbers, spaces and -','"<tt>'.$id.'</tt>"')); } if ($id =~ /^\s*$/) { $id = $Apache::lonxml::curdepth; } @@ -1628,6 +1633,21 @@ sub renderingoptions { return $output; } +sub setmode_javascript { + return <<"ENDSCRIPT"; +<script type="text/javascript"> +// <![CDATA[ +function setmode(form,probmode) { + var initial = form.problemmode.value; + form.problemmode.value = probmode; + form.submit(); + form.problemmode.value = initial; +} +// ]]> +</script> +ENDSCRIPT +} + sub inserteditinfo { my ($filecontents,$filetype,$filename,$symb,$itemtitle,$folderpath,$uri,$action) = @_; $filecontents = &HTML::Entities::encode($filecontents,'<>&"'); @@ -1703,7 +1723,7 @@ FULLPAGE my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit', 'vi' => 'Save and View', 'dv' => 'Discard Edits and View', - 'un' => 'undo', + 'un' => 'Undo', 'ed' => 'Edit'); my $spelllink = &Apache::lonhtmlcommon::spelllink('xmledit','filecont'); my $textarea_events = &Apache::edit::element_change_detection(); @@ -1712,7 +1732,7 @@ FULLPAGE if ($filetype eq 'html') { $htmlerror=&verify_html($filecontents); if ($htmlerror) { - $htmlerror='<span class="LC_error">'.$htmlerror.'</span>'; + $htmlerror=(' 'x3).' <span class="LC_error">'.$htmlerror.'</span>'; } if (&Apache::lonhtmlcommon::htmlareabrowser()) { unless ($textareaclass) { @@ -1720,14 +1740,23 @@ FULLPAGE } } } - my $undo; + my ($undo,%onclick); + foreach my $item ('discard','undo') { + $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 = '<input type="submit" name="Undo" accesskey="u" value="'.$lt{'un'}.'" />'."\n"; + $undo = '<input type="button" name="undo" accesskey="u" value="'.$lt{'un'}.'" '. + $onclick{'undo'}.' />'."\n"; } + $initialize .= &setmode_javascript(); my $editfooter=(<<ENDFOOTER); $initialize <a name="editsection" /> <form $form_events method="post" name="xmledit" action="$action"> + <input type="hidden" name="problemmode" value="edit" /> <div class="LC_edit_problem_editxml_header"> <table class="LC_edit_problem_header_title"><tr><td> $filename @@ -1735,13 +1764,13 @@ $initialize $xml_help </td></tr> </table> - <div> - <input type="submit" name="discardview" accesskey="d" value="$lt{'dv'}" /> - $undo $htmlerror $deps_button $dragmath_button - </div> <div style="float:right"> - <input type="submit" name="savethisfile" accesskey="s" value="$lt{'st'}" /> - <input type="submit" name="viewmode" accesskey="v" value="$lt{'vi'}" /> + <input type="button" name="savethisfile" accesskey="s" value="$lt{'st'}" $onclick{'saveedit'} /> + <input type="button" name="viewmode" accesskey="v" value="$lt{'vi'}" $onclick{'saveview'} /> + </div> + <div> + <input type="button" name="discardview" accesskey="d" value="$lt{'dv'}" $onclick{'discard'} /> + $undo $deps_button $dragmath_button $htmlerror </div> </div> <textarea $textarea_events style="width:100%" cols="80" rows="44" name="filecont" id="filecont" $textareaclass>$filecontents</textarea><br />$spelllink @@ -1751,7 +1780,7 @@ $initialize </div> </form> ENDFOOTER - return ($editfooter,$add_to_onload,$add_to_onresize);; + return ($editfooter,$add_to_onload,$add_to_onresize); } sub get_target { @@ -1856,11 +1885,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 } } } @@ -1889,7 +1920,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') { @@ -1901,7 +1932,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, @@ -1969,8 +2002,9 @@ 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/}) {