-File not found
+$fnf
-
-File not found: $file
+$bodytag
+$fnf: $file
ENDNOTFOUND
- $filecontents='';
- } else {
- $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
- }
-
+ $filecontents='';
+ if ($env{'request.state'} ne 'published') {
+ if ($filetype eq 'sty') {
+ $filecontents=&createnewsty();
+ } else {
+ $filecontents=&createnewhtml();
+ }
+ $env{'form.editmode'}='Edit'; #force edit mode
+ }
+ } else {
+ unless ($env{'request.state'} eq 'published') {
+ if ($filecontents=~/BEGIN LON-CAPA Internal/) {
+ &Apache::lonxml::error(&mt('This file appears to be a rendering of a LON-CAPA resource. If this is correct, this resource will act very oddly and incorrectly.'));
+ }
+#
+# we are in construction space, see if edit mode forced
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['editmode']);
+ }
+ if (!$env{'form.editmode'} || $env{'form.viewmode'}) {
+ $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
+ '',%mystyle);
+ undef($Apache::lonhomework::parsing_a_task);
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['rawmode']);
+ if ($env{'rawmode'}) { $result = $filecontents; }
+ }
+ }
+
#
# Edit action? Insert editing commands
#
- unless ($ENV{'request.state'} eq 'published') {
- $result=&inserteditinfo($result,$filecontents);
- }
-
- $request->print($result);
-
- writeallows($request->uri);
- return OK;
+ unless ($env{'request.state'} eq 'published') {
+ if ($env{'form.editmode'} && (!($env{'form.viewmode'}))) {
+ my $displayfile=$request->uri;
+ $displayfile=~s/^\/[^\/]*//;
+ my $bodytag='';
+ if ($env{'environment.remote'} eq 'off') {
+ $bodytag=&Apache::loncommon::bodytag();
+ }
+ $result=''.$bodytag.
+ &Apache::lonxml::message_location().''.
+ $displayfile.
+ '
';
+ $result=&inserteditinfo($result,$filecontents,$filetype);
+ }
+ }
+ if ($filetype eq 'html') { writeallows($request->uri); }
+
+
+ &Apache::lonxml::add_messages(\$result);
+ $request->print($result);
+
+ return OK;
+}
+
+sub display_title {
+ my $result;
+ if ($env{'request.state'} eq 'construct') {
+ my $title=&Apache::lonnet::gettitle();
+ if (!defined($title) || $title eq '') {
+ $title = $env{'request.filename'};
+ $title = substr($title, rindex($title, '/') + 1);
+ }
+ $result = "";
+ }
+ return $result;
}
-
+
sub debug {
- if ($Apache::lonxml::debug eq 1) {
- print("DEBUG:".$_[0]."
\n");
- }
+ if ($Apache::lonxml::debug eq "1") {
+ $|=1;
+ my $request=$Apache::lonxml::request;
+ if (!$request) {
+ eval { $request=Apache->request; };
+ }
+ if (!$request) {
+ eval { $request=Apache2::RequestUtil->request; };
+ }
+ $request->print('DEBUG:'.&HTML::Entities::encode($_[0],'<>&"')."
\n");
+ #&Apache::lonnet::logthis($_[0]);
+ }
}
-sub error {
- if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
- print "ERROR:".$_[0]."
\n";
- } else {
- print "An Error occured while processing this resource. The instructor has been notified.
";
- #notify author
- &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
- #notify course
- if ( $ENV{'request.course.id'} ) {
- my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
- foreach my $user (split /\,/, $users) {
- ($user,my $domain) = split /:/, $user;
- &Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
- }
+sub show_error_warn_msg {
+ if ($env{'request.filename'} eq '/home/httpd/html/res/lib/templates/simpleproblem.problem' &&
+ &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+ return 1;
}
+ return (($Apache::lonxml::debug eq 1) ||
+ ($env{'request.state'} eq 'construct') ||
+ ($Apache::lonhomework::browse eq 'F'
+ &&
+ $env{'form.show_errors'} eq 'on'));
+}
- #FIXME probably shouldn't have me get everything forever.
- &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
- #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
- }
+sub error {
+ $errorcount++;
+ if ( &show_error_warn_msg() ) {
+ # If printing in construction space, put the error inside
+ push(@Apache::lonxml::error_messages,
+ $Apache::lonxml::warnings_error_header.
+ "ERROR:".join("
\n",@_)."
\n");
+ $Apache::lonxml::warnings_error_header='';
+ } else {
+ my $errormsg;
+ my ($symb)=&Apache::lonnet::symbread();
+ if ( !$symb ) {
+ #public or browsers
+ $errormsg=&mt("An error occured while processing this resource. The author has been notified.");
+ }
+ #notify author
+ &Apache::lonmsg::author_res_msg($env{'request.filename'},join('
',@_));
+ #notify course
+ if ( $symb && $env{'request.course.id'} ) {
+ my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my (undef,%users)=&Apache::lonfeedback::decide_receiver(undef,0,1,1,1);
+ my $declutter=&Apache::lonnet::declutter($env{'request.filename'});
+ my @userlist;
+ foreach (keys %users) {
+ my ($user,$domain) = split(/:/, $_);
+ push(@userlist,"$user\@$domain");
+ my $key=$declutter.'_'.$user.'_'.$domain;
+ my %lastnotified=&Apache::lonnet::get('nohist_xmlerrornotifications',
+ [$key],
+ $cdom,$cnum);
+ my $now=time;
+ if ($now-$lastnotified{$key}>86400) {
+ &Apache::lonmsg::user_normal_msg($user,$domain,
+ "Error [$declutter]",join('
',@_));
+ &Apache::lonnet::put('nohist_xmlerrornotifications',
+ {$key => $now},
+ $cdom,$cnum);
+ }
+ }
+ if ($env{'request.role.adv'}) {
+ $errormsg=&mt("An error occured while processing this resource. The course personnel ([_1]) and the author have been notified.",join(', ',@userlist));
+ } else {
+ $errormsg=&mt("An error occured while processing this resource. The instructor has been notified.");
+ }
+ }
+ push(@Apache::lonxml::error_messages,"$errormsg
");
+ }
}
sub warning {
- if ($ENV{'request.state'} eq 'construct') {
- print "WARNING:".$_[0]."
\n";
- }
+ $warningcount++;
+
+ if ($env{'form.grade_target'} ne 'tex') {
+ if ( &show_error_warn_msg() ) {
+ push(@Apache::lonxml::warning_messages,
+ $Apache::lonxml::warnings_error_header.
+ "WARNING:".join('
',@_)."
\n");
+ $Apache::lonxml::warnings_error_header='';
+ }
+ }
+}
+
+sub info {
+ if ($env{'form.grade_target'} ne 'tex'
+ && $env{'request.state'} eq 'construct') {
+ push(@Apache::lonxml::info_messages,join('
',@_)."
\n");
+ }
+}
+
+sub message_location {
+ return '__LONCAPA_INTERNAL_MESSAGE_LOCATION__';
+}
+
+sub add_messages {
+ my ($msg)=@_;
+ my $result=join(' ',
+ @Apache::lonxml::info_messages,
+ @Apache::lonxml::error_messages,
+ @Apache::lonxml::warning_messages);
+ undef(@Apache::lonxml::info_messages);
+ undef(@Apache::lonxml::error_messages);
+ undef(@Apache::lonxml::warning_messages);
+ $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__/$result/;
+ $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__//g;
}
sub get_param {
- my ($param,$parstack,$safeeval,$context) = @_;
+ my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
+ if ( ! $context ) { $context = -1; }
+ my $args ='';
+ if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
+ if ( ! $Apache::lonxml::usestyle ) {
+ $args=$Apache::lonxml::style_values.$args;
+ }
+ if ( ! $args ) { return undef; }
+ if ( $case_insensitive ) {
+ if ($args =~ s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei) {
+ return &Apache::run::run("{$args;".'return $'.$param.'}',
+ $safeeval); #'
+ } else {
+ return undef;
+ }
+ } else {
+ if ( $args =~ /my \$\Q$param\E=\"/ ) {
+ return &Apache::run::run("{$args;".'return $'.$param.'}',
+ $safeeval); #'
+ } else {
+ return undef;
+ }
+ }
+}
+
+sub get_param_var {
+ my ($param,$parstack,$safeeval,$context,$case_insensitive) = @_;
if ( ! $context ) { $context = -1; }
my $args ='';
if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
- return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
+ if ( ! $Apache::lonxml::usestyle ) {
+ $args=$Apache::lonxml::style_values.$args;
+ }
+ &Apache::lonxml::debug("Args are $args param is $param");
+ if ($case_insensitive) {
+ if (! ($args=~s/(my \$)(\Q$param\E)(=\")/$1.lc($2).$3/ei)) {
+ return undef;
+ }
+ } elsif ( $args !~ /my \$\Q$param\E=\"/ ) { return undef; }
+ my $value=&Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
+ &Apache::lonxml::debug("first run is $value");
+ if ($value =~ /^[\$\@\%][a-zA-Z_]\w*$/) {
+ &Apache::lonxml::debug("doing second");
+ my @result=&Apache::run::run("return $value",$safeeval,1);
+ if (!defined($result[0])) {
+ return $value
+ } else {
+ if (wantarray) { return @result; } else { return $result[0]; }
+ }
+ } else {
+ return $value;
+ }
}
sub register_insert {
@@ -885,14 +1659,19 @@ sub register_insert {
my $line = $data[$i];
if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
if ( $line =~ /TABLE/ ) { last; }
- my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);
- $insertlist{"$tagnum.tag"} = $tag;
- $insertlist{"$tagnum.description"} = $descrip;
- $insertlist{"$tagnum.color"} = $color;
- $insertlist{"$tagnum.function"} = $function;
- $insertlist{"$tagnum.show"}= $show;
- $insertlist{"$tag.num"}=$tagnum;
- $tagnum++;
+ my ($tag,$descrip,$color,$function,$show,$helpfile,$helpdesc) = split(/,/, $line);
+ if ($tag) {
+ $insertlist{"$tagnum.tag"} = $tag;
+ $insertlist{"$tagnum.description"} = $descrip;
+ $insertlist{"$tagnum.color"} = $color;
+ $insertlist{"$tagnum.function"} = $function;
+ if (!defined($show)) { $show='yes'; }
+ $insertlist{"$tagnum.show"}= $show;
+ $insertlist{"$tagnum.helpfile"} = $helpfile;
+ $insertlist{"$tagnum.helpdesc"} = $helpdesc;
+ $insertlist{"$tag.num"}=$tagnum;
+ $tagnum++;
+ }
}
$i++; #skipping TABLE line
$tagnum = 0;
@@ -900,7 +1679,7 @@ sub register_insert {
my $line = $data[$i];
my ($mnemonic,@which) = split(/ +/,$line);
my $tag = $insertlist{"$tagnum.tag"};
- for (my $j=0;$j <$#which;$j++) {
+ for (my $j=0;$j <=$#which;$j++) {
if ( $which[$j] eq 'Y' ) {
if ($insertlist{"$j.show"} ne 'no') {
push(@{ $insertlist{"$tag.which"} },$j);
@@ -913,8 +1692,73 @@ sub register_insert {
sub description {
my ($token)=@_;
- return $insertlist{$insertlist{"$token->[1].num"}.'.description'};
+ my $tagnum;
+ my $tag=$token->[1];
+ foreach my $namespace (reverse @Apache::lonxml::namespace) {
+ my $testtag=$namespace.'::'.$tag;
+ $tagnum=$insertlist{"$testtag.num"};
+ if (defined($tagnum)) { last; }
+ }
+ if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
+ return $insertlist{$tagnum.'.description'};
+}
+
+# Returns a list containing the help file, and the description
+sub helpinfo {
+ my ($token)=@_;
+ my $tagnum;
+ my $tag=$token->[1];
+ foreach my $namespace (reverse @Apache::lonxml::namespace) {
+ my $testtag=$namespace.'::'.$tag;
+ $tagnum=$insertlist{"$testtag.num"};
+ if (defined($tagnum)) { last; }
+ }
+ if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
+ return ($insertlist{$tagnum.'.helpfile'}, $insertlist{$tagnum.'.helpdesc'});
+}
+
+# ----------------------------------------------------------------- whichuser
+# returns a list of $symb, $courseid, $domain, $name that is correct for
+# calls to lonnet functions for this setup.
+# - looks for form.grade_ parameters
+sub whichuser {
+ my ($passedsymb)=@_;
+ my ($symb,$courseid,$domain,$name,$publicuser);
+ if (defined($env{'form.grade_symb'})) {
+ my ($tmp_courseid)=
+ &Apache::loncommon::get_env_multiple('form.grade_courseid');
+ my $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid);
+ if (!$allowed &&
+ exists($env{'request.course.sec'}) &&
+ $env{'request.course.sec'} !~ /^\s*$/) {
+ $allowed=&Apache::lonnet::allowed('vgr',$tmp_courseid.
+ '/'.$env{'request.course.sec'});
+ }
+ if ($allowed) {
+ ($symb)=&Apache::loncommon::get_env_multiple('form.grade_symb');
+ $courseid=$tmp_courseid;
+ ($domain)=&Apache::loncommon::get_env_multiple('form.grade_domain');
+ ($name)=&Apache::loncommon::get_env_multiple('form.grade_username');
+ return ($symb,$courseid,$domain,$name,$publicuser);
+ }
+ }
+ if (!$passedsymb) {
+ $symb=&Apache::lonnet::symbread();
+ } else {
+ $symb=$passedsymb;
+ }
+ $courseid=$env{'request.course.id'};
+ $domain=$env{'user.domain'};
+ $name=$env{'user.name'};
+ if ($name eq 'public' && $domain eq 'public') {
+ if (!defined($env{'form.username'})) {
+ $env{'form.username'}.=time.rand(10000000);
+ }
+ $name.=$env{'form.username'};
+ }
+ return ($symb,$courseid,$domain,$name,$publicuser);
}
+
1;
__END__
500 Internal Server Error
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator at
root@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.
More information about this error may be available
in the server error log.