179 lines
5.2 KiB
Perl
Executable File
179 lines
5.2 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
# script: loan.cgi
|
|
use CGI qw/:standard :html3/;
|
|
|
|
use DBI;
|
|
|
|
#use STRICT;
|
|
|
|
#ouvrir la base de donnees
|
|
my $conn = DBI->connect("dbi:Pg:dbname=s_marchand");
|
|
|
|
$query = new CGI;
|
|
|
|
# this defines the contents of the fill out forms
|
|
# on each page.
|
|
@PAGES = ('Nos produits','Votre commande','Vos coordonnées','Review','Confirmation');
|
|
%FIELDS = ('Nos produits' => ['Reference','Prix unitaire HT','Descriptif'],
|
|
'Votre commande' => ['ref','designation','qté','PU HT'],
|
|
'Vos coordonnées' => ['Société','Nom','Prénom','Adresse','Code postal','ville','adresse de livraison (si différente de la précédente', 'Code postal', 'Ville']
|
|
);
|
|
# accumulate the field names into %ALL_FIELDS;
|
|
foreach (values %FIELDS) {
|
|
grep($ALL_FIELDS{$_}++,@$_);
|
|
}
|
|
|
|
|
|
# figure out what page we're on and where we're heading.
|
|
$current_page = calculate_page(param('page'),param('go'));
|
|
$page_name = $PAGES[$current_page];
|
|
|
|
print_header();
|
|
print_form($current_page) if $FIELDS{$page_name};
|
|
print_review($current_page) if $page_name eq 'Review';
|
|
print_confirmation($current_page) if $page_name eq 'Confirmation';
|
|
print end_html;
|
|
|
|
# CALCULATE THE CURRENT PAGE
|
|
sub calculate_page {
|
|
my ($prev,$dir) = @_;
|
|
return 0 if $prev eq ''; # start with first page
|
|
return $prev + 1 if $dir eq 'Submit Application';
|
|
return $prev + 1 if $dir eq 'Next Page';
|
|
return $prev - 1 if $dir eq 'Previous Page';
|
|
}
|
|
|
|
# PRINT HTTP AND HTML HEADERS
|
|
sub print_header {
|
|
print header,
|
|
start_html(-title=>"Site marchand AIRTRIA",-BGCOLOR=>'white'),
|
|
h2($page_name);
|
|
}
|
|
|
|
# PRINT ONE OF THE QUESTIONNAIRE PAGES
|
|
sub print_form {
|
|
my $current_page = shift;
|
|
print start_form,
|
|
hr;
|
|
print draw_form(@{$FIELDS{$page_name}});
|
|
print hr;
|
|
print submit(-name=>'go',-value=>'Previous Page')
|
|
if $current_page > 0;
|
|
print submit(-name=>'go',-value=>'Next Page'),
|
|
hidden(-name=>'page',-value=>$current_page,-override=>1),
|
|
end_form;
|
|
}
|
|
|
|
# PRINT THE REVIEW PAGE
|
|
sub print_review {
|
|
my $current_page = shift;
|
|
print "Please review this information carefully before submitting it. ",
|
|
start_form;
|
|
my (@rows);
|
|
foreach $page ('Nos produits','Votre commande','Vos coordonnées') {
|
|
push(@rows,th({-align=>LEFT},em($page)));
|
|
foreach $field (@{$FIELDS{$page}}) {
|
|
push(@rows,
|
|
TR(th({-align=>LEFT},$field),
|
|
td(param($field)))
|
|
);
|
|
print hidden(-name=>$field);
|
|
}
|
|
}
|
|
print table({-border=>1},caption($page),@rows),
|
|
hidden(-name=>'page',-value=>$current_page,-override=>1),
|
|
submit(-name=>'go',-value=>'Previous Page'),
|
|
submit(-name=>'go',-value=>'Submit Application'),
|
|
end_form;
|
|
}
|
|
|
|
# PRINT THE CONFIRMATION PAGE
|
|
sub print_confirmation {
|
|
print "Thank you. A loan officer will be contacting you shortly.",
|
|
p,
|
|
a({-href=>'../source.html'},'Code examples');
|
|
}
|
|
|
|
# CREATE A GENERIC QUESTIONNAIRE
|
|
sub draw_form {
|
|
my (@fields) = @_;
|
|
my (%fields);
|
|
grep ($fields{$_}++,@fields);
|
|
my (@hidden_fields) = grep(!$fields{$_},keys %ALL_FIELDS);
|
|
my (@rows);
|
|
if ($page_name eq "Nos produits"){
|
|
my $conn = DBI->connect("dbi:Pg:dbname=s_marchand");
|
|
|
|
my ($code_famille,$code_produit,$denomination,$prix_ht,$en_stock,$fichier_image,$descriptif);
|
|
my (@rowproduits);
|
|
|
|
#$conn->do("SET DateStyle = 'European'");
|
|
|
|
my $query = $conn->prepare(
|
|
"SELECT *" .
|
|
" FROM produits"
|
|
);
|
|
$query->execute();
|
|
|
|
#while (@rowproduits = $query->fetchrow_array())
|
|
#{
|
|
#($code_famille,$code_produit,$denomination,$prix_ht,$en_stock,$fichier_image,$descriptif) = @rowproduits;
|
|
|
|
#print $code_famille," ",$code_produit," ",$denomination," ", $prix_ht," ",$en_stock," ",$fichier_image," ",$descriptif,br;
|
|
|
|
#}
|
|
|
|
#undef($query);
|
|
#$conn->disconnect();
|
|
#$conn = undef;
|
|
|
|
foreach (@fields) {
|
|
push(@rows,
|
|
print TR(th({-align=>LEFT},$_),
|
|
td(textfield(-name=>$_,-size=>50))
|
|
),br
|
|
);
|
|
}
|
|
#print table({-border=>0},
|
|
#Tr({-align=>LEFT,-valign=>CENTER},
|
|
#[
|
|
#td({-rowspan=>4},img{height=>200,width=>200,border=>1}),
|
|
#td({-align=>RIGHT},['',b('Référence : '), textfield(-name=>$_[0],-size=>10),' ',b('Prix unitaire H.T. : '), textfield(-name=>$_[1],-size=>7),b('Euros')]),
|
|
# ]
|
|
#),
|
|
#Tr({-align=>LEFT,-valign=>CENTER},
|
|
#[
|
|
#td({-align=>RIGHT},['',b('Descriptif : ')]), td({-colspan=>7,-align=>RIGHT},[(textfield(-name=>$_[2],-size=>60))]),
|
|
#]
|
|
#),
|
|
#Tr({-align=>LEFT,-valign=>CENTER},
|
|
#[
|
|
#td({-colspan=>7,-align=>RIGHT},[submit]),
|
|
#]
|
|
#),
|
|
|
|
#); #fin print table
|
|
}elsif ($page_name eq "Votre commande"){
|
|
foreach (@fields) {
|
|
push(@rows,
|
|
print TR(th({-align=>LEFT},$_),
|
|
td(textfield(-name=>$_,-size=>50))
|
|
),br
|
|
);
|
|
}
|
|
}else{
|
|
foreach (@fields) {
|
|
push(@rows,
|
|
print TR(th({-align=>LEFT},$_),
|
|
td(textfield(-name=>$_,-size=>50))
|
|
),br
|
|
);
|
|
}
|
|
}
|
|
#print table(@rows);
|
|
foreach (@hidden_fields) {
|
|
print hidden(-name=>$_);
|
|
}
|
|
}
|