"Categories",
"Categories" => "Categories",
"Display" => "ShowRecipe",
"ListRecipes" => "ListRecipes",
"Search" => "Search"
);
function GetRecipeCategories($sql) {
$query = "SELECT name, tag FROM Recipe_Cat ORDER BY name;";
$sql->Query($query);
while ($sql->ReadRow()) {
$results[$sql->RowData['name']] = $sql->RowData['tag'];
}
return $results;
}
function GetNavLinks($sql) {
$categories = GetRecipeCategories($sql);
$links = "";
while (list($name, $url) = each($categories)) {
$links .= "" .
"$name
\n";
}
$links .= "" .
"All
\n";
return $links;
}
function Categories($sql) {
$URL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$tpl = new Template("Templates");
$tpl->set_file("MyTemplateFile", "recipe.html");
$tpl->set_var("TITLE", "Recipe Categories");
$tpl->set_var("NAV", "");
$tpl->set_var("URL", $URL);
$links = GetNavLinks($sql);
$content = "
Recipe Categories
\n" .
"
\n" .
"\n" .
"$links\n" .
"\n" .
"
\n";
$tpl->set_var("BODY", $content);
$tpl->parse("MyPage", "MyTemplateFile");
$tpl->p("MyPage");
}
function Search(&$sql, $search_terms) {
$URL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] .
"?.State=Search&srch=" . $search_terms;
// Duplicate SQL Object
$sql2 = unserialize(serialize($sql));
$sql2->_db_linkid = $sql->_db_linkid;
$base = "recipes.html?.State=Display&id=";
$tpl = new Template("Templates");
$tpl->set_file("MyTemplateFile", "recipe.html");
$tpl->set_var("TITLE", "Recipe Search");
$tpl->set_var("URL", $URL);
$content = "Recipe Search
\n" .
"
\n" .
"Searching for : " .
"$search_terms\n";
$terms = explode( " ", $search_terms );
$srch = "";
for ($i = 0; $i < count($terms); $i++) {
if ($i > 0) {
$srch .= "AND ";
}
$srch .= "(lower(target) LIKE lower('%" . $terms[$i] . "%')) ";
}
$query = "SELECT id, entry_date, title, category" .
" FROM recipe_srch" .
" WHERE status = 'Released' AND" .
" ($srch)" .
" ORDER BY entry_date DESC, title;";
$sql->Query($query);
if ($sql->ReadRow()) {
$categories = GetRecipeCategories($sql2);
while (list($key, $val) = each($categories)) {
$tags[$val] = $key;
}
$content .= "