--- loncom/xml/lonxml.pm 2008/12/11 22:19:45 1.484.4.1
+++ loncom/xml/lonxml.pm 2009/07/08 17:55:16 1.498
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.484.4.1 2008/12/11 22:19:45 raeburn Exp $
+# $Id: lonxml.pm,v 1.498 2009/07/08 17:55:16 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,6 +37,25 @@
# to any other parties under any circumstances.
#
+=pod
+
+=head1 NAME
+
+Apache::lonxml
+
+=head1 SYNOPSIS
+
+XML Parsing Module
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+
+=head1 SUBROUTINES
+
+=cut
+
+
package Apache::lonxml;
use vars
@@ -90,6 +109,7 @@ use Apache::lonfeedback();
use Apache::lonmsg();
use Apache::loncacc();
use Apache::lonmaxima();
+use Apache::lonr();
use Apache::lonlocal;
#==================================== Main subroutine: xmlparse
@@ -505,11 +525,11 @@ sub inner_xmlparse {
if (!$Apache::lonxml::usestyle) {
$extras=$Apache::lonxml::style_values;
}
- if ( $#$parstack > -1 ) {
- $result=&Apache::run::evaluate($result,$safeeval,$extras.$$parstack[-1]);
- } else {
- $result= &Apache::run::evaluate($result,$safeeval,$extras);
- }
+ if ( $#$parstack > -1 ) {
+ $result=&Apache::run::evaluate($result,$safeeval,$extras.$$parstack[-1]);
+ } else {
+ $result= &Apache::run::evaluate($result,$safeeval,$extras);
+ }
}
$Apache::lonxml::post_evaluate=1;
@@ -736,6 +756,13 @@ sub init_safespace {
$safehole->wrap(\&Apache::lonmaxima::maxima_cas_formula_fix,$safeeval,
'&maxima_cas_formula_fix');
+ $safehole->wrap(\&Apache::lonr::r_eval,$safeeval,'&r_eval');
+ $safehole->wrap(\&Apache::lonr::Rentry,$safeeval,'&Rentry');
+ $safehole->wrap(\&Apache::lonr::Rarray,$safeeval,'&Rarray');
+ $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');
@@ -1016,7 +1043,7 @@ 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:]])/) {
- &error(&mt("ID "[_1]" contains invalid characters, IDs are only allowed to contain letters, numbers, spaces and -",''.$id.''));
+ &error(&mt('ID [_1] contains invalid characters. IDs are only allowed to contain letters, numbers, spaces and -','"'.$id.'"'));
}
if ($id =~ /^\s*$/) { $id = $Apache::lonxml::curdepth; }
return $id;
@@ -1485,6 +1512,15 @@ SIMPLECONTENT
return $filecontents;
}
+sub createnewjs {
+ my $filecontents=(<
+
+
+SIMPLECONTENT
+ return $filecontents;
+}
+
sub verify_html {
my ($filecontents)=@_;
if ($filecontents!~/(?:\<|\<\;)(?:html|xml)[^\<]*(?:\>|\>\;)/is) {
@@ -1532,6 +1568,7 @@ sub inserteditinfo {
my $xml_help = '';
my $initialize='';
my $textarea_id = 'filecont';
+ my $dragmath_button;
my ($add_to_onload, $add_to_onresize);
$initialize=&Apache::lonhtmlcommon::spellheader();
if ($filetype eq 'html'
@@ -1569,6 +1606,10 @@ FULLPAGE
}
FULLPAGE
+ if ($filetype eq 'html') {
+ $initialize .= "\n".&Apache::lonhtmlcommon::dragmath_js('EditMathPopup');
+ $dragmath_button = &Apache::lonhtmlcommon::dragmath_button('filecont',1);
+ }
}
$add_to_onload = 'initDocument();';
@@ -1587,9 +1628,12 @@ FULLPAGE
my $spelllink .=&Apache::lonhtmlcommon::spelllink('xmledit','filecont');
my $textarea_events = &Apache::edit::element_change_detection();
my $form_events = &Apache::edit::form_change_detection();
- my $htmlerror=&verify_html($filecontents);
- if ($htmlerror) {
- $htmlerror=''.$htmlerror.'';
+ my $htmlerror;
+ if ($filetype eq 'html') {
+ $htmlerror=&verify_html($filecontents);
+ if ($htmlerror) {
+ $htmlerror=''.$htmlerror.'';
+ }
}
my $editfooter=(<
- $spelllink $htmlerror
+ $dragmath_button $spelllink $htmlerror
@@ -1652,9 +1696,8 @@ sub get_target {
sub handler {
my $request=shift;
-
+
my $target=&get_target();
-
$Apache::lonxml::debug=$env{'user.debug'};
&Apache::loncommon::content_type($request,'text/html');
@@ -1670,11 +1713,12 @@ sub handler {
my $file=&Apache::lonnet::filelocation("",$request->uri);
my $filetype;
- if ($file =~ /\.sty$/) {
- $filetype='sty';
+ if ($file =~ /\.(sty|css|js|txt)$/) {
+ $filetype=$1;
} else {
$filetype='html';
}
+
#
# Edit action? Save file.
#
@@ -1693,17 +1737,22 @@ sub handler {
if ($filecontents eq -1) {
my $start_page=&Apache::loncommon::start_page('File Error');
my $end_page=&Apache::loncommon::end_page();
- my $fnf=&mt('File not found');
+ my $errormsg='
'
+ .&mt('File not found: [_1]'
+ ,''.$file.'')
+ .'
';
$result=(<$fnf: $file
+$errormsg
$end_page
ENDNOTFOUND
$filecontents='';
if ($env{'request.state'} ne 'published') {
if ($filetype eq 'sty') {
$filecontents=&createnewsty();
- } else {
+ } elsif ($filetype eq 'js') {
+ $filecontents=&createnewjs();
+ } elsif (($filetype ne 'css') && ($filetype ne 'txt')) {
$filecontents=&createnewhtml();
}
$env{'form.editmode'}='Edit'; #force edit mode
@@ -1719,28 +1768,57 @@ ENDNOTFOUND
['editmode']);
}
if (!$env{'form.editmode'} || $env{'form.viewmode'} || $env{'form.discardview'}) {
- &Apache::structuretags::reset_problem_globals();
- $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
- '',%mystyle);
+ if ($filetype eq 'html' || $filetype eq 'sty') {
+ &Apache::structuretags::reset_problem_globals();
+ $result = &Apache::lonxml::xmlparse($request,$target,
+ $filecontents,'',%mystyle);
# .html files may contain or need to clean
# up if it did
- &Apache::structuretags::reset_problem_globals();
- &Apache::lonhomework::finished_parsing();
+ &Apache::structuretags::reset_problem_globals();
+ &Apache::lonhomework::finished_parsing();
+ } else {
+ $result = $filecontents;
+ }
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['rawmode']);
if ($env{'form.rawmode'}) { $result = $filecontents; }
- if ($filetype eq 'sty') {
- my $controls =
- ($env{'request.state'} eq 'construct') ? &Apache::londefdef::edit_controls()
- : '';
- my %options = ('bgcolor' => '#FFFFFF');
- $result =
- &Apache::loncommon::start_page(undef,undef,\%options).
- $controls.
- $result.
- &Apache::loncommon::end_page();
- }
- }
+ if ($filetype ne 'html') {
+ my $nochgview = 1;
+ my $controls = '';
+ if ($env{'request.state'} eq 'construct') {
+ $controls = &Apache::loncommon::head_subbox(
+ &Apache::loncommon::CSTR_pageheader()
+ .&Apache::londefdef::edit_controls($nochgview));
+ }
+ if ($filetype ne 'sty') {
+ $result =~ s/</g;
+ $result =~ s/>/>/g;
+ $result = '
'.
+ '
'.$result.
+ '
';
+ }
+ if ($env{'environment.remote'} eq 'off') {
+ my $brcrum;
+ if ($env{'request.state'} eq 'construct') {
+ $brcrum = [{'href' => &Apache::loncommon::authorspace(),
+ 'text' => 'Construction Space'},
+ {'href' => '',
+ 'text' => 'Editor'}];
+ } else {
+ $brcrum = ''; # FIXME: Where are we?
+ }
+ my %options = ('bread_crumbs' => $brcrum,
+ 'bgcolor' => '#FFFFFF');
+ $result =
+ &Apache::loncommon::start_page(undef,undef,\%options)
+ .$controls
+ .$result
+ .&Apache::loncommon::end_page();
+ } else {
+ $result = $controls.$result;
+ }
+ }
+ }
}
#
@@ -1757,8 +1835,14 @@ ENDNOTFOUND
my %options =
('add_entries' =>
- {'onresize' => $add_to_onresize,
- 'onload' => $add_to_onload, });
+ {'onresize' => $add_to_onresize,
+ 'onload' => $add_to_onload, });
+
+ $options{'bread_crumbs'} = [{
+ 'href' => &Apache::loncommon::authorspace(),
+ 'text' => 'Construction Space'},
+ {'href' => '',
+ 'text' => 'HTML Editor'}];
if ($env{'environment.remote'} ne 'off') {
$options{'bgcolor'} = '#FFFFFF';
@@ -1769,11 +1853,13 @@ ENDNOTFOUND
&Apache::loncommon::resize_textarea_js();
my $start_page = &Apache::loncommon::start_page(undef,$js,
\%options);
- $result=$start_page.
- &Apache::lonxml::message_location().
- $edit_info.
- &Apache::loncommon::end_page();
- }
+ $result = $start_page
+ .&Apache::loncommon::head_subbox(
+ &Apache::loncommon::CSTR_pageheader())
+ .&Apache::lonxml::message_location()
+ .$edit_info
+ .&Apache::loncommon::end_page();
+ }
}
if ($filetype eq 'html') { &writeallows($request->uri); }
@@ -2140,7 +2226,109 @@ sub get_tag {
return $insertlist{"$tagnum.tag"};
}
+############################################################
+# PDF-FORM-METHODS
+
+=pod
+
+=item &print_pdf_radiobutton(fieldname, value, text)
+
+Returns a latexline to generate a PDF-Form-Radiobutton with Text.
+
+$fieldname: PDF internalname of the radiobutton
+$value: Value of radiobutton (read when dumping the PDF data)
+$text: Text on the rightside of the radiobutton
+
+=cut
+sub print_pdf_radiobutton {
+ my $result = '';
+ my ($fieldName, $value, $text) = @_;
+ $result .= '\begin{tabularx}{\textwidth}{p{0cm}X}'."\n";
+ $result .= '\radioButton[\symbolchoice{circle}]{'.
+ $fieldName.'}{10bp}{10bp}{'.$value.'}&'.$text."\n";
+ $result .= '\end{tabularx}' . "\n";
+ $result .= '\hspace{2mm}' . "\n";
+ return $result;
+}
+
+
+=pod
+
+=item &print_pdf_start_combobox(fieldname)
+
+Starts a latexline to generate a PDF-Form-Combobox with text.
+
+$fieldname: PDF internal name of the Combobox
+
+=cut
+sub print_pdf_start_combobox {
+ my $result;
+ my ($fieldName) = @_;
+ $result .= '\begin{tabularx}{\textwidth}{p{2.5cm}X}'."\n";
+ $result .= '\comboBox[]{'.$fieldName.'}{2.3cm}{14bp}{'; #
+
+ return $result;
+}
+
+
+=pod
+
+=item &print_pdf_add_combobox_option(options)
+
+Generates a latexline to add Options to a PDF-Form-ComboBox.
+
+$option: PDF internal name of the Combobox-Option
+
+=cut
+sub print_pdf_add_combobox_option {
+
+ my $result;
+ my ($option) = @_;
+
+ $result .= '('.$option.')';
+
+ return $result;
+}
+
+
+=pod
+
+=item &print_pdf_end_combobox(text) {
+
+Returns latexcode to end a PDF-Form-Combobox with text.
+
+=cut
+sub print_pdf_end_combobox {
+ my $result;
+ my ($text) = @_;
+
+ $result .= '}&'.$text."\\\\\n";
+ $result .= '\end{tabularx}' . "\n";
+ $result .= '\hspace{2mm}' . "\n";
+ return $result;
+}
+
+
+=pod
+
+=item &print_pdf_hiddenField(fieldname, user, domain)
+
+Returns a latexline to generate a PDF-Form-hiddenField with userdata.
+
+$fieldname label for hiddentextfield
+$user: name of user
+$domain: domain of user
+
+=cut
+sub print_pdf_hiddenfield {
+ my $result;
+ my ($fieldname, $user, $domain) = @_;
+
+ $result .= '\textField [\F{\FHidden}\F{-\FPrint}\V{'.$domain.'&'.$user.'}]{'.$fieldname.'}{0in}{0in}'."\n";
+
+ return $result;
+}
+
1;
__END__
-