--- loncom/homework/hint.pm 2001/02/07 00:27:32 1.7 +++ loncom/homework/hint.pm 2007/05/23 22:36:21 1.68 @@ -1,113 +1,648 @@ +# The LearningOnline Network with CAPA +# implements the tags that control the hints +# +# $Id: hint.pm,v 1.68 2007/05/23 22:36:21 albertel Exp $ +# +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA me&aree 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/ +# + package Apache::hinttags; use strict; -use Apache::lonnet; +use Apache::lonnet(); use capa; +use Apache::caparesponse(); +use Apache::lonmaxima(); +use Apache::response(); +use Apache::lonlocal; +use Storable qw(dclone); -sub BEGIN { - &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint')); +BEGIN { + &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint','customhint')); } @Apache::hint::which=(); sub start_hintgroup { - my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; - my $skiptoend='1'; - my $result; - - if ($target ne 'meta' || $target ne 'grade') { - my $id=$Apache::inputtags::part; - my $numtries=$Apache::lonhomework::history{"resource.$id.tries"}; - if ( $numtries eq '') { $numtries = 0; } - my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries"); - if ( $hinttries eq '') { $hinttries = 1; } - &Apache::lonxml::debug("found :$id:$numtries:$hinttries:"); - if ( $numtries >= $hinttries ) { - $skiptoend='0'; - if ($target eq 'web') {$result='
';} - } - } - if ($skiptoend && $target ne 'meta') { - &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]); - } - @Apache::hint::which=(); - return $result; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $skiptoend='0'; + my $result; + + if ($target eq 'web') { + my $id=$Apache::inputtags::part; + my $numtries=$Apache::lonhomework::history{"resource.$id.tries"}; + if ( $numtries eq '') { $numtries = 0; } + my $hinttries=&Apache::response::get_response_param($id,"hinttries",1); + &Apache::lonxml::debug("found :$id:$numtries:$hinttries:"); + my $gradestatus= + $Apache::lonhomework::history{"resource.$id.solved"}; + my $showoncorrect=lc(&Apache::lonxml::get_param('showoncorrect',$parstack,$safeeval)); + &Apache::lonxml::debug("onc orrect $showoncorrect, $gradestatus"); + if ( ($showoncorrect ne 'yes' && &Apache::response::show_answer()) || + ( $numtries < $hinttries) ) { + &Apache::lonxml::debug("Grabbin all"); + &Apache::lonxml::get_all_text("/hintgroup",$parser,$style); + } + &Apache::lonxml::startredirection; + } elsif ($target eq 'tex') { + $result .= '\keephidden{'; + } elsif ($target eq 'edit') { + $result.=&Apache::edit::tag_start($target,$token); + $result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',[['no',&mt('No')],['yes',&mt('Yes')]],$token); + $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'showoncorrect'); + if ($constructtag) { + $result =&Apache::edit::rebuild_tag($token); + } + } + @Apache::hint::which=(); + return $result; } sub end_hintgroup { - my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; - my $result; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $result; - if ($target ne 'meta' || $target ne 'grade') { - my $id=$Apache::inputtags::part; - my $numtries=$Apache::lonhomework::history{"resource.$id.tries"}; - if ( $numtries eq '') { $numtries = 0; } - my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries"); - if ( $hinttries eq '') { $hinttries = 1; } - &Apache::lonxml::debug("found :$id:$numtries:$hinttries:"); - if ( $numtries >= $hinttries ) { - if ($target eq 'web') {$result=' |
'. + $hinttext.' |