8 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
sub show {
my( $cgi, $rh_template_variables ) = @_;
my $coupon_code = $cgi->param("coupon_code");
return unless $coupon_code;
my %stmt_lookup = (
codes => 'SELECT codelist_id, active, last_change, start_date, end_date, (start_date IS NULL OR start_date < NOW()) AND (end_date IS NULL OR end_date > NOW()) FROM codes WHERE code = ?',
benefits_codes => {
codelist => 'SELECT type, percent, amount, currency, start_date, end_date, description_de, (start_date IS NULL OR start_date < NOW()) AND (end_date IS NULL OR end_date > NOW()) FROM benefits_codes WHERE codelist_id = ?',
code => 'SELECT type, percent, amount, currency, start_date, end_date, description_de, (start_date IS NULL OR start_date < NOW()) AND (end_date IS NULL OR end_date > NOW()) FROM benefits_codes WHERE coupon_code = ?'
}
);
$rh_template_variables->{coupon_code} = $coupon_code;
my $found_something = 0; # Variable wird auf 0 gesetzt
foreach my $shop_abbr ( @{$SHOP::Constants::supported{shop_abbr}{Server}} ) {
my $db_id = $SHOP::Constants::shop{$shop_abbr}{db_id};
my $dbh = DBI->connect( @{$SHOP::Constants::db{$db_id}{connect}{shop_write}} );
my $rh_code = $rh_template_variables->{code_lookup}{$shop_abbr}{code} = {};
@$rh_code{ qw( codelist_id active last_change start_date end_date is_valid ) } = $dbh->selectrow_array( $stmt_lookup{codes}, {}, $coupon_code );
#### $hash{eins}, $hash{zwei}, $hash{drei} @hash{'eins', 'zweiter key', 'drei'} @hash{ qw(eins zweiter key drei), 'zweiter key', qw(...) }
# my( $codelist_id, $active, $last_change, $start_date, $end_date ) = $dbh->selectrow_array( $stmt_lookup{codes}, {}, $coupon_code );
if ( defined $rh_code->{codelist_id} ) {
$found_something = 1; # Wenn eingegebener Code gefunden dann Variable auf 1 gesetzt
$rh_code->{last_change} =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/;
$rh_template_variables->{code_lookup}{$shop_abbr}{code}{last_change} = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $1, $2, $3, $4, $5, $6 );
$rh_code->{is_used} = ( ($rh_code->{active} == 1 or $rh_code->{codelist_id} == 0 ) ? 1 : 0 );
if ( $rh_code->{codelist_id} > 0 ) {
my $sth_lookup = $dbh->prepare( $stmt_lookup{benefits_codes}{codelist} );
$sth_lookup->execute( $rh_code->{codelist_id} ); #or warn $dbh->errstr();
while ( my $ra_benefits_codes = $sth_lookup->fetchrow_arrayref() ) {
push @{$rh_template_variables->{code_lookup}{$shop_abbr}{actions}}, {
type => $ra_benefits_codes->[0] || '',
percent => $ra_benefits_codes->[1] || '',
amount => $ra_benefits_codes->[2] || '',
currency => $ra_benefits_codes->[3] || '',
start_date => $ra_benefits_codes->[4] || '',
end_date => $ra_benefits_codes->[5] || '',
description_de => $ra_benefits_codes->[6] || '',
is_used => $ra_benefits_codes->[7] || '',
codelist_id => $rh_code->{codelist_id}
};
}
}
} else {
delete $rh_template_variables->{code_lookup}{$shop_abbr};
}
### lookup in benefits_codes über coupon_code
my $sth_lookup = $dbh->prepare( $stmt_lookup{benefits_codes}{code} );
$sth_lookup->execute( $coupon_code );
while ( my $ra_benefits_codes = $sth_lookup->fetchrow_arrayref() ) {
$found_something = 1;
push @{$rh_template_variables->{code_lookup}{$shop_abbr}{actions}}, {
type => $ra_benefits_codes->[0] || '',
percent => $ra_benefits_codes->[1] || '',
amount => $ra_benefits_codes->[2] || '',
currency => $ra_benefits_codes->[3] || '',
start_date => $ra_benefits_codes->[4] || '',
end_date => $ra_benefits_codes->[5] || '',
description_de => $ra_benefits_codes->[6] || '',
is_used => $ra_benefits_codes->[7] || '',
codelist_id => ''
};
}
$dbh->disconnect();
}
# wenn Variable = 0 oder undefiniert dann gib Fehlermeldung aus!
unless( $found_something ) {
$rh_template_variables->{error} = 'nothing_found';
}
}
require show;
show::show($myCGI,\%vars);
1
2
3
4
5
6
7
8
9
10
11
12
package show;
use vars qw(@ISA @EXPORT @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(show);
@EXPORT_OK = qw();
sub show($$)
{
# ...
}
1;
use show;
show($myCGI,\%vars);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package show;
use vars qw(@ISA @EXPORT @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(new);
@EXPORT_OK = qw();
sub new()
{
my $self=shift;
my %vars=@_;
my $obj=\%vars;
bless($obj,$self);
return $obj;
}
sub show($$$)
{
my $obj=shift(@_);
# ...
}
1;
$myshow->show($myCGI,\%vars);
$myshow->show($myCGI,\%vars);
8 Einträge, 1 Seite |