= $search_above"; if (!is_numeric($search_above)) { $error_flag = 1; } } if ($mode == 4) { $where = "(price >= $search_between_low AND price <= $search_between_high"; if (!is_numeric($search_between_low) or !is_numeric($search_between_high)) { $error_flag = 1; } } $where .= ") and " . $table_prefix . "items.hidden = 0"; // NAME SQL EXAMPLE: SELECT id FROM cafe_items WHERE name LIKE '%shirt%' // Above SQL Example: SELECT id FROM cafe_items WHERE price > '20' // Below SQL Example: SELECT id FROM cafe_items WHERE price < '20' $get_config_query = "SELECT num_cols, show_images, show_promo_banner, show_referral_banner, sort_by, display_random, display_numitems, store_img_local, local_path, web_path, store_names, display_style, show_special_banner, show_special_code, keep_logs, status, template_store FROM " . $table_prefix . "config"; $get_config_result = mysql_query($get_config_query) or die("Get config query failed"); $get_config_row = mysql_fetch_row($get_config_result); $columns = $get_config_row[0]; $config_show_images = $get_config_row[1]; $config_show_promo_banner = $get_config_row[2]; $config_show_referral_banner = $get_config_row[3]; $config_sort_by = $get_config_row[4]; $config_display_random = $get_config_row[5]; $config_display_numitems = $get_config_row[6]; $config_store_img_local = $get_config_row[7]; $config_local_path_small = $get_config_row[8]; $config_web_path_small = $get_config_row[9]; $config_store_names = $get_config_row[10]; $config_display_style = $get_config_row[11]; $config_show_special_banner = $get_config_row[12]; $config_special_banner_code = $get_config_row[13]; $config_keep_logs = $get_config_row[14]; $config_status = $get_config_row[15]; $config_template_store = $get_config_row[16]; $banner_name = explode(",", $config_store_names); switch ($config_sort_by) { case "date_desc": $sort = "added DESC"; break; case "date_asc": $sort = "added ASC"; break; case "price_asc": $sort = "price ASC"; break; case "price_desc": $sort = "price DESC"; break; case "alpha_az": $sort = "name ASC"; break; case "alpha_za": $sort = "name DESC"; break; case "default": $sort = "id ASC"; break; } $order_by = " ORDER BY " . $table_prefix . "items." . $sort; if ($_POST and $error_flag == 0) { $query = "select " . $table_prefix . "items.name, " . $table_prefix . "items.price, " . $table_prefix . "items.cp_item_num, " . $table_prefix . "items.img_src FROM " . $table_prefix . "items WHERE $where $order_by"; $result = mysql_query($query) or die("Select items for category query failed"); $items = mysql_num_rows($result); /////////////////////////////////////// if ($config_keep_logs) { $current_date = date("Y-m-d"); if ($mode == 1) { $term = $search_name; $type = "SEARCHTEXT"; } if ($mode == 2) { $term = "<" . $search_below; $type = "SEARCHPRICE"; } if ($mode == 3) { $term = ">" . $search_above; $type = "SEARCHPRICE"; } if ($mode == 4) { $term = $search_between_low . "-" . $search_between_high; $type = "SEARCHPRICE"; } $lookup_query = "SELECT * FROM " . $table_prefix . "logs WHERE date = '$current_date' And type = '$type' And term = '$term'"; $lookup_result = mysql_query($lookup_query) or die("Query failed : " . mysql_error()); $lookup_num_rows = mysql_num_rows($lookup_result); if ($lookup_num_rows == 1) // Search term has already been written to logs today. Update count. { $update_row = mysql_fetch_row($lookup_result); $new_count = $update_row[3] + 1; $update_query = "UPDATE " . $table_prefix . "logs SET count = '$new_count' WHERE date = '$current_date' And type = '$type' And term = '$term'"; $update_result = mysql_query($update_query) or die("Query failed : " . mysql_error()); } else // First time search term has been used today. Insert into cafe_logs. { $insert_query = "INSERT INTO " . $table_prefix . "logs VALUES ('$current_date', '$type', '$term', '1')"; $insert_result = mysql_query($insert_query) or die("Query failed : " . mysql_error()); } } /////////////////////////////////////// } // Do this next query only if the display random items has been selected in the config screen $random_query = "SELECT cp_item_num FROM " . $table_prefix . "items WHERE random = 'yes'"; $random_result = mysql_query($random_query) or die("Random item query failed"); $random_rows = mysql_num_rows($random_result); if ($random_rows >= 1) { while ($randomrow = mysql_fetch_array($random_result)) { $randomarray[] = $randomrow[0]; // Build array of item numbers that have been selected for random display } $randitemnum = array_rand($randomarray); $random_item_query = "SELECT name, price, img_src, cp_item_num FROM " . $table_prefix . "items WHERE cp_item_num = '$randomarray[$randitemnum]'"; $random_item_result = mysql_query($random_item_query) or die("Random item query failed"); $random_item_data = mysql_fetch_array($random_item_result); } //////////////////////////////////////////////////////// // TEMPLATE START include "template.class.php"; $template = new Template; $template->load("templates/$config_template_store"); $template->replace("title", "CafeScripts Store - $catdesc[0]"); $template->replace("meta", "$catdesc[1]"); $template->replace("datetime", date("m/d/y")); if ($config_status == "closed" Or $config_status == "maintenance") { $status_message = "Our store is currently unavailable. Please check back later. We apologize for any inconvenience."; $template->replace("items", $status_message); $template->replace("search", ""); $template->replace("category_description", ""); $template->replace("random_item", ""); $template->replace("child_menu", ""); $template->replace("parent_menu", ""); $template->replace("pages", ""); $template->replace("banner", ""); $template->replace("cart_link", ""); $template->replace("search_bar", ""); } else { $template->replace("search", ""); $template->replace("category_description", "Search"); $template->replace("items", template_items()); $template->replace("random_item", template_random()); $template->replace("child_menu", ""); $template->replace("parent_menu", template_parent_menu()); $template->replace("pages", ""); $template->replace("banner", template_banner()); $template->replace("cart_link", cart_link()); $template->replace("search_bar", template_search_bar()); } $template->publish(); // TEMPLATE END //////////////////////////////////////////////////////// //////////////////////////////////////////////////////// // FUNCTIONS function template_items() { global $error_flag; global $search_name; global $search_below; global $search_above; global $search_between_low; global $search_between_high; global $table_prefix; global $row; global $result; global $items; global $config_items_per_page; global $page_counter; global $config_store_img_local; global $config_web_path_small; global $config_display_style; global $counter; global $columns; $items_result = "\n"; if ($_POST and $error_flag == 0) $items_result .= "Your search resulted in $items items.\n"; if ($error_flag == 1) $items_result .= "Please only enter numeric values for the price.\n"; $str = <<
Product Name:
Price Below $
Price Above $
Price greater than $ and less than $
EOD; $items_result .= $str . "\n"; if ($_POST and $error_flag == 0) { while ($row = mysql_fetch_array($result)) { if ($config_store_img_local == "yes") { $img = $config_web_path_small . $row[2] . "_sm.jpg"; } else { $img = $row[3]; } $items_result .= "\n"; // End outer table cell to hold table for item display $counter++; if ($counter % $columns == 0) { $items_result .= ""; } } $items_result .= "
\n"; // Outer table cell to hold table for item display $items_result .= ""; // Inner table to display item $cat_query = "SELECT " . $table_prefix . "categories.name, " . $table_prefix . "categories.id "; $cat_query .= "FROM " . $table_prefix . "items, " . $table_prefix . "categories, " . $table_prefix . "listings "; $cat_query .= "WHERE " . $table_prefix . "items.cp_item_num = '$row[2]' and " . $table_prefix . "listings.item_id = " . $table_prefix . "items.id and " . $table_prefix . "categories.id=" . $table_prefix . "listings.category_id"; $cat_result = mysql_query($cat_query) or die("Find categories for item query failed"); switch ($config_display_style) { case 'img_top': $items_result .= ""; $items_result .= ""; break; case 'img_bottom': $items_result .= ""; $items_result .= ""; break; case 'img_left': $items_result .= ""; $items_result .= ""; break; case 'img_right': $items_result .= ""; $items_result .= ""; break; } $items_result .= "
"; $items_result .= "\""
$row[0]
\$$row[1]"; if (mysql_num_rows($cat_result) > 0) { $items_result .= "
"; } $items_result .= "
$row[0]
\$$row[1]
"; $items_result .= "\"""; if (mysql_num_rows($cat_result) > 0) { $items_result .= "
"; } $items_result .= "
\""$row[0]
\$$row[1]"; if (mysql_num_rows($cat_result) > 0) { $items_result .= "
"; } $items_result .= "
$row[0]
\$$row[1]"; if (mysql_num_rows($cat_result) > 0) { $items_result .= "
"; } $items_result .= "
\""
"; // End innter table to display item $items_result .= "
\n"; } else { $items_result .= "\n"; } $items_result .= "

© 2005 NotOneBit.com. All rights reserved.

\n"; return $items_result; } function template_random() { global $config_display_random; global $random_item_data; if ($config_display_random == "yes") { $result = "Don't miss our other items like...
"; $result .= ""; $result .= "
"; $result .= $random_item_data[0] . "
"; $result .= "$" . $random_item_data[1] . "
"; } return $result; } function template_parent_menu() { $str = "Main » Search\n"; return $str; } function template_search_bar() { $result = '
'; $result .= '
'; return $result; } function template_banner() { global $config_show_promo_banner; global $config_show_referral_banner; global $config_show_special_banner; global $config_special_banner_code; srand((double)microtime()*1000000); if ($config_show_promo_banner == "yes" And $config_show_referral_banner == "yes" And $config_show_special_banner == "yes") // (3) pick one of the three at random { $pick = rand(1,3); if ($pick == 1) { $result = ""; $result .= "\"Sale"; } elseif ($pick == 2) { $result .= ""; $result .= "\"Design"; } else { $result .= "$config_special_banner_code"; } } elseif ($config_show_promo_banner == "yes" And $config_show_referral_banner == "yes") // (2) pick one of the two at random { $pick = rand(1,2); if ($pick == 1) { $result .= ""; $result .= "\"Sale"; } else { $result .= ""; $result .= "\"Design"; } } elseif ($config_show_promo_banner == "yes" And $config_show_special_banner == "yes") // (2) pick one of the two at random { $pick = rand(1,2); if ($pick == 1) { $result .= ""; $result .= "\"Sale"; } else { $result .= "$config_special_banner_code"; } } elseif ($config_show_special_banner == "yes" And $config_show_referral_banner == "yes") // (2) pick one of the two at random { $pick = rand(1,2); if ($pick == 1) { $result .= "$config_special_banner_code"; } else { $result .= ""; $result .= "\"Design"; } } elseif ($config_show_promo_banner == "yes") // (1) show only promo banner { $result .= ""; $result .= "\"Sale"; } elseif ($config_show_referral_banner == "yes") // (1) show only referral banner { $result .= ""; $result .= "\"Design"; } elseif ($config_show_special_banner == "yes") // (1) show only special banner { $result .= "$config_special_banner_code"; } else { $result .= ""; } return $result; } function cart_link() { $str = "View Cart\n"; return $str; } // FUNCTIONS //////////////////////////////////////////////////////// mysql_close($connection); ?>