# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
# $Id: structuretags.pm,v 1.132 2002/11/06 23:05:02 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# 2/19 Guy
# 6/26/2001 fixed extra web display at end of
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.
\n"; } } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' || $status eq 'UNCHECKEDOUT' ) { if ($target ne 'tex') { $result.="\n"; } } if ($target ne 'tex') { $result.=&Apache::lonxml::xmlend(); } else { $result .= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}'; if (not $ENV{'request.symb'} =~ m/\.page_/) { $result .= '\end{minipage}\end{document} '; } else { $result .= ''; } } } if ($target eq 'grade') { &Apache::lonhomework::showhash(%Apache::lonhomework::results); &finalize_storage(); } } elsif ($target eq 'meta') { if ($Apache::inputtags::part eq '0') { $result=&Apache::response::mandatory_part_meta; } } elsif ($target eq 'edit') { &Apache::lonxml::debug("in end_problem with $target, edit"); $result = &problem_edit_footer(); } return $result; } sub start_library { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my ($result,$head_tag_start,$body_tag_start,$form_tag_start); if ($target eq 'edit') { ($result,$head_tag_start,$body_tag_start,$form_tag_start)= &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); $result.=$head_tag_start."".$body_tag_start.$form_tag_start. &problem_edit_header(); my $temp=&Apache::edit::insertlist($target,$token); $result.=$temp; } elsif ($target eq 'modified') { $result=$token->[4]; $result.=&Apache::edit::handle_insert(); } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' && $ENV{'request.state'} eq "construct" ) { ($result,$head_tag_start,$body_tag_start,$form_tag_start)= &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); my $name=&get_resource_name($parstack,$safeeval); my $rndseed=&setup_rndseed($safeeval); $result.="$head_tag_start
$body_tag_start \n $form_tag_start".
'';
$result.=&problem_web_to_edit_header($rndseed);
}
return $result;
}
sub end_library {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result='';
if ($target eq 'edit') {
$result=&problem_edit_footer();
} elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
$ENV{'request.state'} eq "construct") {
$result.=''.&Apache::lonxml::xmlend();
}
return $result;
}
sub start_block {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result;
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
my $code = @$parstack[$#$parstack];
if ($code) {
$code =~ s/\"//g;
$code .=';return $condition;';
$result = &Apache::run::run($code,$safeeval);
&Apache::lonxml::debug("block :$code: returned :$result:");
} else {
$result='1';
}
if ( ! $result ) {
my $skip=&Apache::lonxml::get_all_text("/block",$$parser[-1]);
&Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
}
$result='';
} elsif ($target eq 'edit') {
$result .=&Apache::edit::tag_start($target,$token);
$result .=&Apache::edit::text_arg('Test Condition:','condition',
$token,40);
$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'condition');
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
}
return $result;
}
sub end_block {
return '';
}
sub start_while {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $code = @$parstack[$#$parstack];
$code =~ s/\"//g;
$code .=';return $condition;';
push( @Apache::structuretags::whileconds, $code);
my $result = &Apache::run::run($code,$safeeval);
my $bodytext=$$parser[$#$parser]->get_text("/while");
push( @Apache::structuretags::whilebody, $bodytext);
if ( $result ) {
&Apache::lonxml::newparser($parser,\$bodytext);
}
return "";
}
sub end_while {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $code = pop @Apache::structuretags::whileconds;
my $bodytext = pop @Apache::structuretags::whilebody;
my $result = &Apache::run::run($code,$safeeval);
if ( $result ) {
&Apache::lonxml::newparser($parser,\$bodytext);
}
return "";
}
#
START-TAG $b_tok->[1], $b_tok->[4], $list_item";
}
if($b_tok->[0] eq 'T') { # text
# what to do with text in between tags?
# print "TEXT $b_tok->[1]
";
}
# if($b_tok->[0] eq 'E') { # end tag, should not happen
# print "END-TAG $b_tok->[1]
";
# }
}
my @idx_arr = (0 .. $#randomlist);
&Apache::structuretags::shuffle(\@idx_arr);
my $bodytext = '';
my $show=$#randomlist;
my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
$showarg--;
if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
for(0 .. $show) {
$bodytext .= "$randomlist[ $idx_arr[$_] ]";
}
&Apache::lonxml::newparser($parser,\$bodytext);
} elsif ($target eq 'edit' ) {
$result .= &Apache::edit::tag_start($target,$token);
$result .= &Apache::edit::text_arg('Maximum Tags to Show:','show',$token,5);
$result .= &Apache::edit::end_row().&Apache::edit::start_spanning_row();
} elsif ($target eq 'modified' ) {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
'show');
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
}
return $result;
}
sub shuffle {
my $a=shift;
my $i;
if (defined(@$a)) {
&Apache::response::setrandomnumber();
for($i=@$a;--$i;) {
my $j=int(&Math::Random::random_uniform() * ($i+1));
next if $i == $j;
@$a[$i,$j] = @$a[$j,$i];
}
}
}
sub end_randomlist {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result;
if ($target eq 'edit' ) {
$result=&Apache::edit::tag_end($target,$token,'End Randomly Parsed Block');
}
return $result;
}
sub start_part {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result='';
my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
if ($id eq '') { $id = $Apache::lonxml::curdepth; }
$Apache::inputtags::part=$id;
@Apache::inputtags::responselist = ();
@Apache::inputtags::previous=();
if ($target eq 'meta') {
return &Apache::response::mandatory_part_meta;
} elsif ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
push (@Apache::inputtags::status,$status);
my $expression='$external::datestatus="'.$status.'";';
$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
&Apache::run::run($expression,$safeeval);
if ( $status eq 'CLOSED' ) {
my $bodytext=&Apache::lonxml::get_all_text("/part",$$parser[$#$parser]);
if ( $target eq "web" ) {
$result="
Part is not open to be viewed. It $accessmsg
";
} elsif ( $target eq 'tex' ) {
$result="\\end{minipage}\\vskip 0 mm Part is not open to be viewed. It $accessmsg \\\\\\begin{minipage}{\\textwidth}";
}
} else {
if ($target eq 'tex') {
if ($$tagstack[-2] ne 'problem') {
$result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
}
}
}
}
return $result;
}
sub end_part {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
&Apache::lonxml::debug("in end_part $target ");
my $status=$Apache::inputtags::status['-1'];
pop @Apache::inputtags::status;
if ( $target eq 'meta' ) { return ''; }
if ( $target eq 'grade' && $status eq 'CAN_ANSWER') {
return &Apache::inputtags::grade;
}
if ($target eq 'web' || $target eq 'tex' ) {
my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
if ($Apache::lonhomework::type eq 'exam') {$gradestatus='';}
return $gradestatus;
}
return '';
}
sub start_preduedate {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' ) {
&Apache::lonxml::get_all_text("/preduedate",$$parser[$#$parser]);
}
}
return '';
}
sub end_preduedate {
return '';
}
sub start_postanswerdate {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
&Apache::lonxml::get_all_text("/postanswerdate",$$parser[$#$parser]);
}
} elsif ($target eq 'tex') {
return '\vskip 0 mm \noindent';
}
return '';
}
sub end_postanswerdate {
return '';
}
sub start_notsolved {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
&Apache::lonxml::debug("not solved has :$gradestatus:");
if ($gradestatus =~ /^correct/) {
&Apache::lonxml::debug("skipping");
&Apache::lonxml::get_all_text("/notsolved",$$parser[$#$parser]);
}
}
return '';
}
sub end_notsolved {
return '';
}
sub start_solved {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
if ($gradestatus !~ /^correct/) {
&Apache::lonxml::get_all_text("/solved",$$parser[$#$parser]);
}
}
return '';
}
sub end_solved {
return '';
}
sub start_startouttext {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my @result=(''.'');
if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
return (@result);
}
sub end_startouttext {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result='';
my $text='';
if ($target eq 'edit') {
$text=&Apache::lonxml::get_all_text("endouttext",$$parser[-1]);
$result.=&Apache::edit::start_table($token)."
".&Apache::edit::end_table()."\n"; }
if ($target eq "modified") {
$result='