%perl>
# - Search by keyword for recipes
# - Get a summary listing of all recipes by title or by product they relate to
# - Get a detailed listing of the recipe with links to print off the recipe and a direct link to buy the product
# - On the shopping cart side, create a section in the product detail of recipes this product uses
my $sql;
my $sth;
my $h;
my $data;
my @host = split(/\./, $ENV{HTTP_HOST});
my $template;
my $line;
my %recipe_cat;
my $key;
my $cats;
my $main_cat;
my $i = 0;
my $prods;
if(@host == 3) { $host[0] = $host[1]; $host[1] = $host[2]; }
$sql = "SELECT * FROM Webs,Recipes,Templates WHERE Webs.WebSiteName='$host[0].$host[1]'
AND Webs.WebsID=Recipes.WebsID
AND Webs.Template=Templates.TemplateID
ORDER BY RecipeCategory";
$sth = $dbh->prepare($sql);
$sth->execute;
if($sth->rows == 0) {
$data = "
This website has no recipes setup to display
";
}
else {
while($h = $sth->fetchrow_hashref) {
$template = $h->{FileName};
$h->{RecipeDirections} =~ s/\r\n/
/ig;
$prods = &ProdListing($h->{RecipesID});
$recipe_cat{$h->{RecipeCategory}} .= "";
}
}
$sth->finish;
foreach $key(sort(keys %recipe_cat)) {
$cats .= "$key | ";
if($ARGS{action} eq "details" && $key eq $ARGS{cat}) {
$main_cat = $key;
$data .= $recipe_cat{$key};
}
elsif($i == 0 && !$ARGS{action}) {
$main_cat = $key;
$data .= "$recipe_cat{$key}";
}
$i++;
}
$data = "
Recipe Categories: $cats
Recipe Listing for: $main_cat
$data";
open(FILE, "/home/apps/templates/$template/index.html");
$template = "";
while($line = ) {
$template .= $line;
}
close(FILE);
$template =~ s/{{var6}}/$data/;
$template =~ s/{{(.*?)}}//ig;
print $template;
sub ProdListing {
my $sql;
my $sth;
my $h;
my $prods;
$sql = "SELECT * FROM RecipeProducts,Products WHERE RecipesID='$_[0]'
AND RecipeProducts.ProductsID=Products.ProductsID";
$sth = $dbh->prepare($sql);
$sth->execute;
if($sth->rows == 0) {
$prods = "No Prods";
}
else {
while($h = $sth->fetchrow_hashref) {
$h->{ProductsID} = $m->comp("../CreateSeed.mas", uid => $h->{ProductsID});
$prods .= "{ProductsID}>$h->{ProductTitle}
";
}
}
$sth->finish;
return($prods);
}
%perl>