i have a subroutine that works fine when i am modifying or adding a single record. but when i select modify multiple, it hangs up. i need to look at each date field for each record that is being modified. i can't figure out how to pass those variables. here's the code for the multiple routine:
#----------------------------------------------------------------------
# Modify multiple records
#
my $self = shift;
return $self->home($self->_language('PER_MOD')) unless( $self->{user}->{modify_p} );
#------------demo code----------------
# Format the cgi for searching
$self->format_search_cgi;
# Hash to handle errors if there are any errors.
my $errors = {};
my $errcode = {};
# Need to know the names of the columns for this Table.
my @columns = keys %{$self->{db}->cols};
# Need to know the number of records modified
my $rec_modified = 0;
# For through the record numbers. These are the values of the
# check boxes
my $modify = ( ref $self->{cgi}->{modify} eq 'ARRAY' ) ? $self->{cgi}->{modify} : [$self->{cgi}->{modify}];
return $self->modify_search_form($self->_language('MUL_MOD_SUC',0)) if ( !$self->{cgi}->{modify} );
my $pk;
# Check if users can delete only their own records
# 06/23/2011 add Unrestricted status
# if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'} and !$self->{user}->{admin_p} ) {
if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'}) {
unless ( $self->{user}->{admin_p} || ($self->{user}->{'Status'} eq 'Unrestricted')) {
$pk = $self->{db}->{schema}->{pk};
( ref $pk ) or return $self->modify_form ($self->_language('ERR_PK'));
}
} # end if modify own
# Setup the language for GT::SQL.
local $GT::SQL::ERRORS->{ILLEGALVAL} = $self->_language('ADD_ILLEGALVAL');
local $GT::SQL::ERRORS->{UNIQUE} = $self->_language('ADD_UNIQUE');
local $GT::SQL::ERRORS->{NOTNULL} = $self->_language('ADD_NOTNULL');
foreach my $rec_num ( @$modify ) {
# The hash ref, we need, to modify a record.
my $change = {};
# Check if users can delete only their own records
# 06/23/2011 add Unrestricted status
# if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'} and !$self->{user}->{admin_p} ) {
if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'}) {
unless ( $self->{user}->{admin_p} || ($self->{user}->{'Status'} eq 'Unrestricted')) {
my $cond;
%$cond = map {$_ => $self->{cgi}->{"$rec_num-$_"}} @$pk;
my $result = $self->{db}->get($cond);
( $result ) or return $self->modify_search_form($self->_language('SRC_NOTFOUND'));
my $userid = $result->{$self->{cfg}->{'auth_user_field'}};
($userid eq $self->{user}->{'Username'}) or return $self->modify_form($self->_language('ERR_MODIFY_OWN'));
# 7/24/2010 don't reset username field on modify
# $self->{cgi}->{"$rec_num-$self->{cfg}->{'auth_user_field'}"} = $self->{user}->{Username}
}
# For through the column names to build our modification hash
foreach my $column ( @columns ) {
$change->{$column} = $self->{cgi}->{"$rec_num-$column"} if exists $self->{cgi}->{"$rec_num-$column"};
}
### i think this is where my new code should go?
### my ($msg,$tmp) = mysub($??????);
### more stuff depending on $msg
# Make the changes and capture any errors.
my $ret = $self->{db}->modify($change);
if ( defined ($ret) ) {
$rec_modified++;
}
else {
if ( $GT::SQL::error ){
my $error = $GT::SQL::error;
$error =~ s/\n/<br>\n<li>/g;
$errors->{$rec_num} = "<li>$error";
}
$errcode->{$rec_num} = $GT::SQL::errcode if ( $GT::SQL::errcode );
}
}
} # end modify own?
# Return the results page with the proper arguments depending on if we got an error or not.
return ( keys %{$errors} ) ? $self->modify_multi_results($rec_modified, $errors, $errcode) : $self->modify_multi_results($rec_modified);
}
Code:
sub modify_multi_records { #----------------------------------------------------------------------
# Modify multiple records
#
my $self = shift;
return $self->home($self->_language('PER_MOD')) unless( $self->{user}->{modify_p} );
#------------demo code----------------
# Format the cgi for searching
$self->format_search_cgi;
# Hash to handle errors if there are any errors.
my $errors = {};
my $errcode = {};
# Need to know the names of the columns for this Table.
my @columns = keys %{$self->{db}->cols};
# Need to know the number of records modified
my $rec_modified = 0;
# For through the record numbers. These are the values of the
# check boxes
my $modify = ( ref $self->{cgi}->{modify} eq 'ARRAY' ) ? $self->{cgi}->{modify} : [$self->{cgi}->{modify}];
return $self->modify_search_form($self->_language('MUL_MOD_SUC',0)) if ( !$self->{cgi}->{modify} );
my $pk;
# Check if users can delete only their own records
# 06/23/2011 add Unrestricted status
# if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'} and !$self->{user}->{admin_p} ) {
if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'}) {
unless ( $self->{user}->{admin_p} || ($self->{user}->{'Status'} eq 'Unrestricted')) {
$pk = $self->{db}->{schema}->{pk};
( ref $pk ) or return $self->modify_form ($self->_language('ERR_PK'));
}
} # end if modify own
# Setup the language for GT::SQL.
local $GT::SQL::ERRORS->{ILLEGALVAL} = $self->_language('ADD_ILLEGALVAL');
local $GT::SQL::ERRORS->{UNIQUE} = $self->_language('ADD_UNIQUE');
local $GT::SQL::ERRORS->{NOTNULL} = $self->_language('ADD_NOTNULL');
foreach my $rec_num ( @$modify ) {
# The hash ref, we need, to modify a record.
my $change = {};
# Check if users can delete only their own records
# 06/23/2011 add Unrestricted status
# if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'} and !$self->{user}->{admin_p} ) {
if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'}) {
unless ( $self->{user}->{admin_p} || ($self->{user}->{'Status'} eq 'Unrestricted')) {
my $cond;
%$cond = map {$_ => $self->{cgi}->{"$rec_num-$_"}} @$pk;
my $result = $self->{db}->get($cond);
( $result ) or return $self->modify_search_form($self->_language('SRC_NOTFOUND'));
my $userid = $result->{$self->{cfg}->{'auth_user_field'}};
($userid eq $self->{user}->{'Username'}) or return $self->modify_form($self->_language('ERR_MODIFY_OWN'));
# 7/24/2010 don't reset username field on modify
# $self->{cgi}->{"$rec_num-$self->{cfg}->{'auth_user_field'}"} = $self->{user}->{Username}
}
# For through the column names to build our modification hash
foreach my $column ( @columns ) {
$change->{$column} = $self->{cgi}->{"$rec_num-$column"} if exists $self->{cgi}->{"$rec_num-$column"};
}
### i think this is where my new code should go?
### my ($msg,$tmp) = mysub($??????);
### more stuff depending on $msg
# Make the changes and capture any errors.
my $ret = $self->{db}->modify($change);
if ( defined ($ret) ) {
$rec_modified++;
}
else {
if ( $GT::SQL::error ){
my $error = $GT::SQL::error;
$error =~ s/\n/<br>\n<li>/g;
$errors->{$rec_num} = "<li>$error";
}
$errcode->{$rec_num} = $GT::SQL::errcode if ( $GT::SQL::errcode );
}
}
} # end modify own?
# Return the results page with the proper arguments depending on if we got an error or not.
return ( keys %{$errors} ) ? $self->modify_multi_results($rec_modified, $errors, $errcode) : $self->modify_multi_results($rec_modified);
}