#!/usr/bin/perl
if(!$includes_implemented){
require 'includes/include_all.cgi';
$includes_implemented++;
}
&showProducts;
&templateEndPrint;
exit;
sub showProducts{
&templateStartReplace("<
>", "Koegel Meats Recipes");
&templateStartReplace("<>", '');
&templateStartReplace("<>", "");
&templateStartPrint;
$myquery{'get_products'} = "SELECT products.id, products.product_id, products.name, products.size, products.description, products.ingredients, products.gluten_free, products.product_image, products.nutrition_image, recipes_products.id FROM products
LEFT JOIN recipes_products ON (products.product_id = recipes_products.product_id)
WHERE products.status = 'Web' AND products.product_id != '59' AND products.product_id != '480'
GROUP BY products.product_id
ORDER BY products.name";
$query_handle{'get_products'} = $connect->prepare($myquery{'get_products'});
$query_handle{'get_products'}->execute();
$query_handle{'get_products'}->bind_columns(undef, \$product{'id'}, \$product{'product_id'}, \$product{'name'}, \$product{'size'}, \$product{'description'}, \$product{'ingredients'}, \$product{'gluten_free'}, \$product{'product_image'}, \$product{'nutrition_image'}, \$product{'recipe'});
while($query_handle{'get_products'}->fetch()) {
if($product{'product_image'}){
$product{'product_image'} = "";
}
if($product{'nutrition_image'}){
$product{'nutrition_image'} = "";
}
if($product{'size'}){
$product{'size'} = " - $product{'size'}";
}
# if($zipcode_cookie){
# $find_link = "Locate Near $zipcode_cookie
";
# }
# else{
# $find_link = "";
# }
$find_link = "";
my $recipe_link;
if($product{'recipe'}){
$recipe_link = "";
}
else{
$recipe_link = "";
}
my $gluten_free;
if($product{'gluten_free'}){
$gluten_free = "
Gluten Free";
}
push(@products_exist, "
$product{'name'} $product{'size'} $gluten_free $product{'description'} Ingredients $product{'ingredients'} $find_link |
$product{'product_image'} $recipe_link |
$product{'nutrition_image'} |
");
}
print<
.gluten-free{
font-size: 14px;
font-weight: bold;
color: blue;
}
Koegel's Line of Fine Meat Products
ENDPRINT
}
sub searchLocations{
&templateStartReplace("<>", "Koegel Meats Recipes");
&templateStartReplace("<>", '');
&templateStartReplace("<>", "");
&templateStartPrint;
my $zipcode=$query->param('zipcode');
$myquery{'get_zip'} = "SELECT latitude, longitude FROM zipcodes WHERE zipcode = ?";
$query_handle{'get_zip'} = $connect->prepare($myquery{'get_zip'});
$query_handle{'get_zip'}->execute("$zipcode");
$query_handle{'get_zip'}->bind_columns(undef, \$zip{'latitude'}, \$zip{'longitude'});
while($query_handle{'get_zip'}->fetch()) {
}
$myquery{'get'} = "SELECT id, name, address, city, state, zip,
( 3959 * acos( cos( radians(?) )
* cos( radians( Latitude ) )
* cos( radians( Longitude ) - radians(?) )
+ sin( radians(?) )
* sin( radians( Latitude ) ) ) ) AS distance
FROM customers
HAVING distance < ?
ORDER BY distance";
$query_handle{'get'} = $connect->prepare($myquery{'get'});
$query_handle{'get'}->execute("$zip{'latitude'}", "$zip{'longitude'}", "$zip{'latitude'}", "15");
$query_handle{'get'}->bind_columns(undef, \$customer{'id'}, \$customer{'name'}, \$customer{'address'}, \$customer{'city'}, \$customer{'state'}, \$customer{'zip'}, \$customer{'distance'});
while($query_handle{'get'}->fetch()) {
$count_locations++;
my $color;
if($count_locations eq "1"){
$color = "EEEEEE";
}
else{
$color = "FFFFFF";
undef $count_locations;
}
my $distance = sprintf("%.1f", $customer{'distance'});
push(@location_rows, "
About $distance mile(s) |
$customer{'name'} |
$customer{'address'} |
$customer{'city'} |
$customer{'state'} |
$customer{'zip'} |
");
}
print<Koegel's Locations
Locations within 100 mile radius of Birch Run, MI
Mobile users, swipe left to right if you can't view the full table.
Distance |
Retailer |
Street Address |
City |
State |
Zip Code |
@location_rows
ENDPRINT
}
sub viewLocation{
&templateStartReplace("<>", "Koegel Meats Recipes");
&templateStartReplace("<>", '');
&templateStartReplace("<>", "");
&templateStartPrint;
my $location=$query->param('location');
$myquery{'location'} = "SELECT customer_id, name, address, city, state, zip FROM customers WHERE id = ?";
$query_handle{'location'} = $connect->prepare($myquery{'location'});
$query_handle{'location'}->execute("$location");
$query_handle{'location'}->bind_columns(undef, \$customer{'id'}, \$customer{'name'}, \$customer{'address'}, \$customer{'city'}, \$customer{'state'}, \$customer{'zip'});
while($query_handle{'location'}->fetch()) {
}
$myquery{'get_products'} = "SELECT products.id, products.name, products.size, products.description, products.gluten_free, products.product_image, products.nutrition_image FROM products
JOIN invoices_products ON (products.product_id = invoices_products.product_id)
JOIN invoices_customers ON (invoices_products.invoice_id = invoices_customers.invoice_id AND invoices_customers.customer_id = ?)
WHERE products.status = 'Web'
GROUP BY products.id";
$query_handle{'get_products'} = $connect->prepare($myquery{'get_products'});
$query_handle{'get_products'}->execute("$customer{'id'}");
$query_handle{'get_products'}->bind_columns(undef, \$product{'id'}, \$product{'name'}, \$product{'size'}, \$product{'description'}, \$product{'gluten_free'}, \$product{'product_image'}, \$product{'nutrition_image'});
while($query_handle{'get_products'}->fetch()) {
if($product{'product_image'}){
$product{'product_image'} = "";
}
if($product{'nutrition_image'}){
$product{'nutrition_image'} = "";
}
if($product{'size'}){
$product{'size'} = " - $product{'size'}";
}
my $gluten_free;
if($product{'gluten_free'}){
$gluten_free = "
Gluten Free";
}
push(@products_exist, "
$product{'name'} $product{'size'} $gluten_free $product{'description'} |
$product{'product_image'} |
$product{'nutrition_image'} |
");
}
print<
.gluten-free{
font-size: 14px;
font-weight: bold;
color: blue;
}
$customer{'name'}
$customer{'address'}
$customer{'city'}, $customer{'state'} $customer{'zip'}
Don't see the product you're looking for? Click here.
ENDPRINT
}
sub getAction{
my $action=$query->param('action');
if($action eq "view_location"){
&viewLocation;
}
else{
&searchLocations;
}
}
exit;