Hi,
The following question is part of another thread in the main DBManSQL section but I haven't had any feedback yet. As it relates to a plugin, I thought that I would start a new thread here incase anyone tries to do the same thing in the future.
I'm writing a plugin that splits dates entered as 01/21,02/05,03/27,04/30,etc... in one form field and adds them to the database as individual dates.
I got the plugin working using the sub below but I am not sure about how to handle the add_success part indicated in red. It works with (1) but I'm not sure what I should really use. The Home.pm add_record sub uses $self->add_success($ret); where $ret return 1. I'm assuming that the 1 means that the record was added successfully. What can I use to make sure that ALL my records were added successfully????
Any ideas?
Thanks.
Simon.
sub split_add_record {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'add_record'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my ($self) = @_;
# Do something useful here
# Ignores the plugin if this is not contact table
($self->{cgi}->{db} ne 'public_holiday') and return @_;
GT::Plugins->action ( STOP );
#----------------------------------------------------------------------
my $splitdate;
my @dates = split ',', $IN->param('public_holiday_202');
foreach $splitdate (@dates) {
$self->{cgi}->{public_holiday_202}=$splitdate;
#----------------------------------------------------------------------
return $self->home($self->_language('PER_ADD')) unless ( $self->{user}->{add_p} );
#------------demo code----------------
# add data to related table
return $self->sadd_record() if ( $self->{cgi}->{sdb} and $self->{cgi}->{sdo} );
# Turn arrays into delimited fields
$self->format_insert_cgi;
if ( $self->{cfg}->{'auth_user_field'} ) {
$self->{cgi}->{$self->{cfg}->{'auth_user_field'}} = $self->{user}->{'Username'};
}
# Check foreign keys
my $msg = $self->_check_fk();
($msg) and return $self->add_form($msg);
# 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');
if ( defined (my $ret = $self->{db}->add($self->{cgi})) ) {
$self->auth_logging('add record ') if ( $self->{cfg}->{log_file} );
#------------demo code-----------
#Don't call up the success page
###$self->add_success($ret);
}
else {
local $^W;
my $error = $GT::SQL::error;
$error =~ s/\n/<br>\n<li>/g;
$self->add_form("<font color=red><ul><li>$error</ul></font>");
}
#end for
}
$self->add_success(1);
#end sub
}
# Always end with a 1.
1;
The following question is part of another thread in the main DBManSQL section but I haven't had any feedback yet. As it relates to a plugin, I thought that I would start a new thread here incase anyone tries to do the same thing in the future.
I'm writing a plugin that splits dates entered as 01/21,02/05,03/27,04/30,etc... in one form field and adds them to the database as individual dates.
I got the plugin working using the sub below but I am not sure about how to handle the add_success part indicated in red. It works with (1) but I'm not sure what I should really use. The Home.pm add_record sub uses $self->add_success($ret); where $ret return 1. I'm assuming that the 1 means that the record was added successfully. What can I use to make sure that ALL my records were added successfully????
Any ideas?
Thanks.
Simon.
sub split_add_record {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'add_record'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my ($self) = @_;
# Do something useful here
# Ignores the plugin if this is not contact table
($self->{cgi}->{db} ne 'public_holiday') and return @_;
GT::Plugins->action ( STOP );
#----------------------------------------------------------------------
my $splitdate;
my @dates = split ',', $IN->param('public_holiday_202');
foreach $splitdate (@dates) {
$self->{cgi}->{public_holiday_202}=$splitdate;
#----------------------------------------------------------------------
return $self->home($self->_language('PER_ADD')) unless ( $self->{user}->{add_p} );
#------------demo code----------------
# add data to related table
return $self->sadd_record() if ( $self->{cgi}->{sdb} and $self->{cgi}->{sdo} );
# Turn arrays into delimited fields
$self->format_insert_cgi;
if ( $self->{cfg}->{'auth_user_field'} ) {
$self->{cgi}->{$self->{cfg}->{'auth_user_field'}} = $self->{user}->{'Username'};
}
# Check foreign keys
my $msg = $self->_check_fk();
($msg) and return $self->add_form($msg);
# 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');
if ( defined (my $ret = $self->{db}->add($self->{cgi})) ) {
$self->auth_logging('add record ') if ( $self->{cfg}->{log_file} );
#------------demo code-----------
#Don't call up the success page
###$self->add_success($ret);
}
else {
local $^W;
my $error = $GT::SQL::error;
$error =~ s/\n/<br>\n<li>/g;
$self->add_form("<font color=red><ul><li>$error</ul></font>");
}
#end for
}
$self->add_success(1);
#end sub
}
# Always end with a 1.
1;