--- loncom/homework/inputtags.pm 2000/12/04 21:15:33 1.10
+++ loncom/homework/inputtags.pm 2005/08/02 18:15:27 1.174
@@ -1,211 +1,885 @@
# The LearningOnline Network with CAPA
# input definitons
+#
+# $Id: inputtags.pm,v 1.174 2005/08/02 18:15:27 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/
package Apache::inputtags;
+use HTML::Entities();
use strict;
+use Apache::loncommon;
+use Apache::lonlocal;
+use Apache::lonnet;
-sub BEGIN {
- &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission'));
+BEGIN {
+ &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
}
sub initialize_inputtags {
- @Apache::inputtags::input=();
- @Apache::inputtags::response=();
- @Apache::inputtags::responselist=();
- @Apache::inputtags::answergroup=();
- $Apache::inputtags::part='';
- %Apache::inputtags::params=();
-}
-
-sub start_textarea {
- my ($target,$token,$parstack,$parser,$safeeval)=@_;
- my $result = "";
- if ($target eq 'web') {
- $result= '";
- }
- return '';
+ # list of current input ids
+ @Apache::inputtags::input=();
+ # list of all input ids seen in this problem
+ @Apache::inputtags::inputlist=();
+ # list of all current response ids
+ @Apache::inputtags::response=();
+ # list of all response ids seen in this problem
+ @Apache::inputtags::responselist=();
+ # list of all current hint ids
+ @Apache::inputtags::hint=();
+ # list of all hint ids seen in this problem
+ @Apache::inputtags::hintlist=();
+ # list of whether or not a specific response was previously used
+ @Apache::inputtags::previous=();
+ # submission it was used in
+ @Apache::inputtags::previous_version=();
+ # id of current part, 0 means that no part is current
+ # (inside only
+ $Apache::inputtags::part='';
+ # list of all part ids seen
+ @Apache::inputtags::partlist=();
+ # list of problem date statuses, the first element is for
+ # if there is a second element it is for the current
+ @Apache::inputtags::status=();
+ # hash of defined params for the current response
+ %Apache::inputtags::params=();
+ # list of all ids, for , these get join()ed and prepended
+ @Apache::inputtags::import=();
+ # list of all import ids seen
+ @Apache::inputtags::importlist=();
+ # just used to note whether we have seen a response that isn't in a part
+ $Apache::inputtags::response_with_no_part=0;
+ # storage location so the begin <*response> tag can generate the correct
+ # answer string for display by the
+ %Apache::inputtags::answertxt=();
+}
+
+sub check_for_duplicate_ids {
+ my %check;
+ foreach my $id (@Apache::inputtags::partlist,
+ @Apache::inputtags::responselist,
+ @Apache::inputtags::hintlist,
+ @Apache::inputtags::importlist) {
+ $check{$id}++;
+ }
+ my @duplicates;
+ foreach my $id (sort(keys(%check))) {
+ if ($check{$id} > 1) {
+ push(@duplicates,$id);
+ }
+ }
+ if (@duplicates) {
+ &Apache::lonxml::error("Duplicated ids found, problem will operate incorrectly. Duplicated ids seen: ",join(', ',@duplicates));
+ }
+}
+
+sub start_input {
+ my ($parstack,$safeeval)=@_;
+ my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval);
+ if ($id eq '') { $id = $Apache::lonxml::curdepth; }
+ push (@Apache::inputtags::input,$id);
+ push (@Apache::inputtags::inputlist,$id);
+ return $id;
+}
+
+sub end_input {
+ pop @Apache::inputtags::input;
+ return '';
+}
+
+sub addchars {
+ my ($fieldid,$addchars)=@_;
+ my $output='';
+ foreach (split(/\,/,$addchars)) {
+ $output.=''.$_.' ';
+ }
+ return $output;
+}
+
+sub start_textfield {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result = "";
+ my $id = &start_input($parstack,$safeeval);
+ my $resid=$Apache::inputtags::response[-1];
+ if ($target eq 'web') {
+ $Apache::lonxml::evaluate--;
+ if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
+ my $partid=$Apache::inputtags::part;
+ my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"');
+ my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
+ if ( $cols eq '') { $cols = 80; }
+ my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
+ if ( $rows eq '') { $rows = 16; }
+ my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
+ $result='';
+ if ($addchars) {
+ $result.=&addchars('HWVAL_'.$resid,$addchars);
+ }
+ push @Apache::lonxml::htmlareafields,'HWVAL_'.$resid;
+ $result.= '