getPermissionGroupIds(),
fn($permissionGroupId) => $permissionGroupId <> '555'
);
if (!empty($permissionGroups)) {
$db->query(
'SELECT c.id FROM ' . TABLE_CATEGORY . ' c
JOIN ' . TABLE_CATEGORY_TO_PERMISSION_GROUP . ' ctpg
ON c.id = ctpg.category_id
AND ctpg.permission_group_id in ( ' . implode(',', $permissionGroups) . ')'
);
if ($userCategoryId = $db->nextRecord()) {
$userCategory = new Category($userCategoryId['id']);
$redirectTo = $userCategory->getAnchorLink();
tep_redirect($redirectTo);
}
}
$featuredCategories = new FeaturedCategoriesWidget();
$template->set('featuredCategoriesWidget', $featuredCategories->render(true));
$rushGuaranteesWidget = new RushGuaranteesWidget();
$template->set('rushGuaranteesWidget', $rushGuaranteesWidget->render(true));
$brandsWidget = new ShopByBrandWidget();
$template->set('brandsWidget', $brandsWidget->render(true));
}
if (!empty($_GET['page'])) {
$template->startHTML();
$template->startPage();
$template->parseTemplate($_GET['page']);
$template->endPage();
exit;
}
$db = new MySql();
$listing_sql = '';
$manufacturerId = (int) ($_GET['manufacturer_id'] ?? 0);
$filterId = (int) ($_GET['filter_id'] ?? 0);
$current_category_id = (int) $current_category_id;
if (USE_MOD_REWRITE && $current_category_id != 0) {
try {
$oCategory = new Category($current_category_id);
} catch (InvalidArgumentException $ex) {
tep_redirect('404.php', 404);
}
$current_category_page_url = $oCategory->getAnchorLink();
$has_params = count(explode('?', $current_category_page_url)) > 1;
if (!$has_params) {
$request_url_parts = explode('?', $_SERVER['REQUEST_URI']);
$request_url = $request_url_parts[0];
if (isset($request_url_parts[1])) {
$params = explode('&', $request_url_parts[1]);
foreach ($params as $key => $value) {
$parameter = explode('=', $value);
if (in_array($parameter[0], ['categoryID', 'page'])) {
unset($params[$key]);
}
}
$request_url_parts[1] = implode('&', $params);
}
} else {
$request_url = $_SERVER['REQUEST_URI'];
}
if ($current_category_page_url != (HTTPS_SERVER . $request_url)) {
tep_redirect($current_category_page_url . (!$has_params && isset($request_url_parts[1]) && !empty($request_url_parts[1]) ? '?' . $request_url_parts[1] : ''), 301);
}
}
if (FRANCHISE_MODE) {
$group_objs = [];
$customer_groups = $current_customer->customerGroupIds;
if (is_array($customer_groups) && (count($customer_groups) > 0)) {
foreach ($customer_groups as $customer_group) {
$group_objs[] = new CustomerGroup($customer_group);
}
}
$roleGroup = new FranchiseRoleGroup();
foreach ($current_customer->getFranchiseId() as $franchise_id) {
$roleGroup->addRole(new FranchiseRole($current_customer->getID(), $group_objs, $franchise_id));
}
$customers = $roleGroup->getCustomers();
if ($roleGroup->onCreditHold()) {
$hold_msg = ' ';
$hold_msg .= 'Your ' . strtolower(TERM_FOR_FRANCHISE) . ' has been placed on Credit Hold. Please contact Clayton Kendall for payment arrangements.';
$hold_msg .= ' ';
$template->set('hold_msg', $hold_msg);
}
}
// if we have a login message in the session, get it and remove it from the session
$login_msg = '';
if (strlen(trim($_SESSION['my_login_msg'] ?? ''))) {
$login_msg = $_SESSION['my_login_msg'];
$template->set('login_msg', base64_decode($login_msg));
unset($_SESSION['my_login_msg']);
}
$db->selectSimple(
['all_product_display', 'dont_show_products_images', 'is_brand'],
TABLE_CATEGORY,
[
'id' => $current_category_id,
'status' => 1
]
);
$check_category = $db->nextRecord();
$is_brand = $check_category['is_brand'] ?? 0;
// the following cPath references come from application_top.php
$category_depth = 'top';
$column_list = [];
if (isset($cPath) && tep_not_null($cPath)) {
$define_list = [
'PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE,
'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW
];
asort($define_list);
foreach ($define_list as $key => $value) {
if ($value > 0) {
$column_list[] = $key;
}
}
$select_column_list = '';
for ($i = 0, $n = sizeof($column_list); $i < $n; $i++) {
switch ($column_list[$i]) {
case 'PRODUCT_LIST_MODEL':
$select_column_list .= 'p.model, ';
break;
case 'PRODUCT_LIST_NAME':
$select_column_list .= 'p.name, ';
break;
case 'PRODUCT_LIST_MANUFACTURER':
$select_column_list .= 'm.name AS manufacturer_name, ';
break;
case 'PRODUCT_LIST_IMAGE':
$select_column_list .= 'p.image, ';
break;
case 'PRODUCT_LIST_WEIGHT':
$select_column_list .= 'p.weight, ';
break;
}
}
$select_column_list .= 'p.description, ';
// START ADD SEO FIELDs IN SELECT COLUMN LIST
// show the products of a specified manufacturer
if ($manufacturerId) {
if ($filterId) {
// We are asked to show only a specific category
$listing_sql = "
SELECT p.id
FROM product AS p
JOIN manufacturer AS m
ON (p.manufacturer_id = m.id)
JOIN product_to_category AS p2c
ON (p.id = p2c.product_id)
WHERE (p.status = 1)
AND (m.id = {$manufacturerId})
AND (p2c.category_id = {$filterId})
AND (p.id = products_prices.product_id)
";
} else {
// We show them all
$listing_sql = "
SELECT p.id
FROM product AS p
JOIN manufacturer AS m
ON (p.manufacturer_id = m.id)
WHERE (p.status = 1)
AND (m.id = {$manufacturerId})
";
}
} else {
// show the products in a given categorie
if ($filterId) {
// We are asked to show only specific catgeory
$listing_sql = "
SELECT p.id
FROM product AS p
JOIN manufacturer AS m
ON (p.manufacturer_id = m.id)
JOIN product_to_category AS p2c
ON (p.id = p2c.product_id)
WHERE (p.status = 1)
AND (m.id = {$filterId})
AND (p2c.category_id = {$current_category_id})
";
} else {
// We show them all
$listing_sql = "
SELECT p.id
FROM product AS p
LEFT JOIN product_to_category AS p2c
ON (p.id = p2c.product_id)
WHERE (p.status = 1)
AND (p2c.category_id = {$current_category_id})
";
}
}
$categories_products_query = $db->query($listing_sql);
$cateqories_products['total'] = $db->numRows($categories_products_query);
if ($cateqories_products['total'] > 0) {
$category_depth = 'products'; // display products
} else {
$db->query("
SELECT COUNT(*)+(SELECT count(*) as total FROM `category_to_category` WHERE `parent_id`='" . (int) $current_category_id . "') AS total
FROM category
WHERE
parent_id = '" . (int) $current_category_id . "'
AND status = 1
");
$category_parent = $db->nextRecord($category_parent_query);
if ($category_parent['total'] > 0) {
$category_depth = 'nested'; // navigate through the categories
} else {
$category_depth = 'products'; // category has no products, but display the 'no products' message
}
}
}
/** karn: put this here so the template willk know that this is the home page (for meta keywords purpose) * */
$template->set('is_home_page', true);
//Natalie 12-Feb-2008: remember last visited category (for navigation)
// think this bit is obsolete, do not believe $category is being set anywhere
if (
!isset($_SESSION['lastvisitedCategory'])
&& isset($category)
) {
$_SESSION['lastvisitedCategory'] = [
'id' => $current_category_id,
'name' => $category['name'],
'name_truncated' => substr($category['name'], 0, 37)
];
}
switch (FRONT_PAGE_PRODUCT_SLIDER) {
case 'featured_products':
$db->selectSimple(
[
'id',
'clean_rewrite_url',
'price',
'name'
],
TABLE_PRODUCT,
['featured' => 1]
);
$flex_item_width = (int) ($_GET['fw'] ?? 120);
while ($row = $db->nextRecord()) {
$product = new Product($row['id']);
$caption = <<
As Low As {$currencies->format($product->getLowestPrice())}
{$row['name']}
CAPTION;
$images[] = [
'src' => 'ajax_handler.php?page=get_product_image&dimension='
. $flex_item_width
. '&pID=' . $row['id'],
'caption' => $caption,
'name' => $row['name'],
'link' => ROOT_URL . $row['clean_rewrite_url'] . '.html'
];
}
$flex_slider_widget = new FlexSliderWidget($images, 'slide', true, $flex_item_width);
$template->set('flex_slider_widget', $flex_slider_widget->render(true));
break;
case 'top_products':
$top_products_carousel_widget = new TopProductsCarouselWidget();
$template->set('top_products_carousel_widget', $top_products_carousel_widget->render(true));
$product_finder_widget = new ProductFinderWidget();
$template->set('product_finder_widget', $product_finder_widget->render(true));
break;
case 'new_products_simple':
$new_products_carousel_widget = new NewProductsCarouselWidget(
NewProductsCarouselWidget::SELECT_TYPE_SIMPLE,
5,
142
);
$template->set('new_products_carousel_widget', $new_products_carousel_widget->render(true));
break;
case 'new_products_category':
$newProductsCarouselWidget = new NewProductsCarouselWidget(
NewProductsCarouselWidget::SELECT_TYPE_CATEGORY,
5,
142,
10,
30,
"What's New"
);
$template->set('newProductsCarouselWidget', $newProductsCarouselWidget->render(true));
break;
default:
}
if (TEMPLATE_BASE <> TemplateSystem::BASE_HTML5) {
TemplateJS::addInclude("includes/js/jquery/plugins/ck_banner.js", 10);
}
$template->startHTML($current_category_id);
$template->startPage();
$template->set('breadcrumb_trail', $breadcrumb->trail(BREADCRUMB_SEPARATOR));
$template->set('categoryName', $categoryName ?? '');
$franchise_products = [];
$filterlist_query = null;
if (($category_depth == 'nested') || ($is_brand == 1)) {
if (isset($cPath) && strpos('_', $cPath)) {
// check to see if there are deeper categories within the current category
$category_links = array_reverse($cPath_array);
for ($i = 0, $n = sizeof($category_links); $i < $n; $i++) {
$db->query("
SELECT COUNT(*) AS total
FROM category AS c
WHERE
c.parent_id = '" . (int) $category_links[$i] . "'
AND c.status = 1
");
$categories = $db->nextRecord();
if ($categories['total'] < 1) {
// do nothing, go through the loop
} else {
// START ADD SEO FIELD IN SELECT COLUMN LIST
//CG-Testing category access control query 11/13/07
$categories_sql = "
SELECT DISTINCT
c.enable_zoom,
c.id,
c.name,
c.image,
c.parent_id,
IF (c.seo_link_title <> '', c.seo_link_title, c.name) as seo_link_title,
IF (c.seo_alt_text <> '', c.seo_alt_text, c.name) as seo_alt_text
FROM category AS c
JOIN category_to_permission_group AS ctpg
ON (c.id = ctpg.category_id)
WHERE (c.parent_id = '" . (int) $category_links[$i] . "')
AND (c.status = 1)
{$current_customer->categoryFilter}
GROUP BY c.id
ORDER BY sort_order, c.name
";
$categories_query = $db->query($categories_sql);
break; // we've found the deepest category the customer is in
}
}
} else {
$categories_query = $db->query("(
SELECT DISTINCT
c.sort_order,
c.enable_zoom,
c.id,
c.name,
c.image,
c.parent_id,
c.description,
IF (c.seo_link_title <> '', c.seo_link_title, c.name) as seo_link_title,
IF (c.seo_alt_text <> '', c.seo_alt_text, c.name) as seo_alt_text
FROM category AS c
JOIN category_to_permission_group AS ctpg
ON (c.id = ctpg.category_id)
WHERE (c.parent_id = '" . (int) $current_category_id . "')
AND (c.status = 1)
{$current_customer->categoryFilter}
GROUP BY c.id
) UNION (
SELECT
c.sort_order,
c.enable_zoom,
c.id,
c.name,
c.image,
c.parent_id,
c.description,
IF (c.seo_link_title <> '', c.seo_link_title, c.name) as seo_link_title,
IF (c.seo_alt_text <> '', c.seo_alt_text, c.name) as seo_alt_text
FROM category AS c
JOIN category_to_category AS ctc
ON (c.id = ctc.category_id)
WHERE (ctc.parent_id = '" . (int) $current_category_id . "')
AND (c.status = 1)
)
ORDER BY sort_order, name
");
}
$number_of_categories = $db->numRows($categories_query);
$rows = 0;
$categories_array = [];
while ($categories = $db->nextRecord($categories_query)) {
//select one product from current category
$cur_cat = (int) $categories['id'];
$num_products = 0;
$sub_cat_count = 0;
// get number of product inside
$db->query("
SELECT COUNT(*) AS num_products
FROM product_to_category AS ptc
JOIN product p
ON (ptc.product_id = p.id)
JOIN product_to_permission_group AS ctpg
ON (ptc.product_id = ctpg.product_id)
WHERE (ptc.category_id = {$cur_cat})
AND (p.status = 1)
{$current_customer->categoryFilter}
");
if ($row = $db->nextRecord()) {
$num_products = $row['num_products'];
}
if ($num_products == 0) {
$db->query("SELECT COUNT(*) as num_cats FROM category WHERE parent_id='$cur_cat'");
if ($row = $db->nextRecord()) {
$num_cats = $row['num_cats'];
}
}
$rows++;
$cPath_new = getCategoryPath($categories['id']);
$width = (int) (100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
$category_image = getCategoryImage($cur_cat);
//THIS ONE IS USED TO ENABLE/DISABLE THUMBNAIL ZOOMING
$db->selectSimple('parent_id', TABLE_CATEGORY, ['id' => $categories['id']]);
$row = $db->nextRecord();
$parentCatId = $row['parent_id'];
if ($parentCatId != "0") {
$db->selectSimple('enable_zoom', TABLE_CATEGORY, ['id' => $parentCatId]);
$row = $db->nextRecord();
if ($row['enable_zoom'] == "1") {
$thumbClass = "categoryImage";
} else {
$thumbClass = "categoryImageNoZoom";
}
} else {
if ($categories['enable_zoom'] == "1") {
$thumbClass = "categoryImage";
} else {
$thumbClass = "categoryImageNoZoom";
}
}
$sDescription = '';
$sAltDescription = '';
$thumb_image = get_thumb_image(
$category_image,
$categories['seo_alt_text'],
MIN_CATEGORY_WIDTH,
MIN_CATEGORY_HEIGHT,
" class='$thumbClass'"
);
$categories_array[$rows] = [
'width' => $width,
'category_link' => tep_href_link(FILENAME_DEFAULT, $cPath_new),
'thumb_image' => $thumb_image,
'name' => $categories['name'],
'num_products' => $num_products,
'num_cats' => $num_cats,
'sub_cat_count' => $sub_cat_count,
'seo_alt_text' => $categories['seo_alt_text'],
'id' => $categories['id'],
'description' => $categories['seo_alt_text'],
'categories_alt_description' => $categories['seo_alt_text'],
];
}
$template->set('categories_array', $categories_array);
$template->set('number_of_categories', $number_of_categories);
$template->set('current_category_id', $current_category_id);
if ($check_category['is_brand'] == 1) {
$template->defaultName = 'index_brand';
} else {
$template->defaultName = 'index_nested';
}
} elseif ($category_depth == 'products' || $manufacturerId) {
if (($_GET['action'] ?? '') == 'filter') {
$template->defaultName = 'index_filter';
} else {
// create column list
if ($check_category['is_brand'] == 1) {
$template->defaultName = 'index_brand';
} else {
$template->defaultName = 'index_products';
}
}
// let's only query the db for this information if we are in franchise_mode.
if (FRANCHISE_MODE) {
if ($current_customer->getID() && $current_customer->getFranchiseId()) {
// get the franchise specific products
$franchises = implode(',', $current_customer->getFranchiseId());
$db->query(
"
SELECT
p.model,
p.image,
p.name,
p.description,
p.id,
p.manufacturer_id,
p.price,
p.tax_class_id,
p.min_quantity,
IF(s.status, s.price, NULL) AS special_price,
IF(s.status, s.price, p.price) AS final_price,
IF (p.seo_link_title <> '', p.seo_link_title, p.name) as seo_link_title,
IF (p.seo_alt_text <> '', p.seo_alt_text, p.name) as seo_alt_text,
products_prices.max_price
FROM product AS p
JOIN products_prices
ON (p.id = products_prices.product_id)
JOIN product_to_category AS p2c
ON (p.id = p2c.product_id)
LEFT JOIN manufacturer AS m
ON (p.manufacturer_id = m.id)
LEFT JOIN special AS s
ON (p.id = s.product_id)
WHERE (p.status = 1)
AND (p2c.category_id = :category)
AND (p.franchise_id IN ({$franchises}))
ORDER BY p2c.sort_order
",
['category' => $current_category_id]
);
while ($row = $db->nextRecord()) {
$franchise_products[] = $row;
}
}
}
if (PRODUCT_LIST_FILTER) {
if ($manufacturerId) {
$filterlist_sql = "
SELECT DISTINCT
c.id,
c.name
FROM product AS p
JOIN product_to_category AS p2c
ON (p.id = p2c.product_id)
JOIN category AS c
ON (p2c.category_id = c.id)
JOIN category_to_permission_group AS ctpg
ON (c.id = ctpg.category_id)
WHERE (p.status = 1)
AND (c.status = 1)
AND (p.manufacturer_id = {$manufacturerId})
$current_customer->categoryFilter
ORDER BY c.name
";
} else {
$filterlist_sql = "
SELECT DISTINCT
m.id,
m.name
FROM product AS p
JOIN product_to_category AS p2c
ON (p.id = p2c.product_id)
JOIN manufacturer AS m
ON (p.manufacturer_id = m.id)
WHERE (p.status = 1)
AND (p2c.category_id = {$current_category_id})
ORDER BY m.name
";
}
$filterlist_query = $db->query($filterlist_sql);
if ($db->numRows($filterlist_query) > 1) {
$template->set('useFilterList', true);
} else {
$template->set('useFilterList', false);
}
}
} else { // default page
$template->set('current_category_id', $current_category_id);
$template->defaultName = 'index';
}
$db->selectSimple(
'description',
TABLE_CATEGORY,
[
'id' => $current_category_id,
'status' => 1
]
);
$cat_desc = $db->nextRecord();
$template->set('messageStack', $messageStack);
$template->set('categoryDescription', html_entity_decode(($cat_desc['description'] ?? '')));
$template->set('listing_sql', $listing_sql);
$template->set('categoryImage', $clientInfo->clientProdImagePath . getCategoryImage($current_category_id));
$template->set('current_category_id', $current_category_id);
$template->set('column_list', $column_list);
$template->set('filterlist_query', $filterlist_query);
$template->set('manufacturer_id', $_GET['manufacturer_id'] ?? '');
$template->set('sort', $_GET['sort'] ?? '');
$template->set('filter_id', $_GET['filter_id'] ?? '');
$template->set('franchise_products', $franchise_products);
$template->set('sort_order', $_POST['sort'] ?? '');
$template->set('clientInfo', $clientInfo);
if (!empty($_GET['sort-by'])) {
$template->set('sort_by', $_GET['sort-by']);
}
//WSG Begin 04-09-2010 Catagory lists were only showing 9 items, but were indicated that they were to be showing 12.
$resultsperpg = 12;
if (!empty($_GET['resultsperpg'])) {
$resultsperpg = $_GET['resultsperpg'];
} elseif (USE_RUSH_REWRITE_RULES) {
$resultsperpg = "viewall";
}
$template->set('resultsperpg', $resultsperpg);
//WSG End 04-09-2010
switch ($clientInfo->clientCode) {
case Client::PANERA:
$db = new MySql();
$db->query("
SELECT DISTINCT p.id
FROM product p
LEFT JOIN special AS s
ON (p.id = s.product_id)
LEFT JOIN product_to_permission_group AS ptpg
ON (ptpg.product_id = p.id)
WHERE p.status = 1
AND s.status = 1
AND s.expires_date >= NOW()
AND (s.start_date <= NOW() || s.start_date IS NULL)
{$current_customer->productFilter}
ORDER BY RAND()
LIMIT 1
");
$products_data = $db->nextRecord();
if (!empty($products_data['id'])) {
$template->set('special_product', new Product($products_data['id'], true, false));
}
$categories = [];
$category_names = [
'APPAREL' => 'apparel.jpg',
'BUSINESS CARDS' => 'business_cards.jpg',
'FORMS & SUPPLIES' => 'forms_and_supplies.jpg',
'NAME TAGS' => 'name_tags.jpg'
];
foreach ($category_names as $name => $image) {
$res = $db->query(
'
SELECT id, name
FROM category
WHERE UPPER(name) = :name
',
['name' => str_replace('&', 'AND', $name)]
);
if ($_category = $db->nextRecord($res)) {
$categories[$_category['id']]['id'] = $_category['id'];
$categories[$_category['id']]['name'] = $name;
$categories[$_category['id']]['image'] = $clientInfo->clientSiteImagePath . $image;
}
}
$template->set('categories', $categories);
break;
}
// welcome message
if ((bool) $current_customer->customerGroupIds && is_array($current_customer->customerGroupIds)) {
$group_ids = implode(',', array_unique($current_customer->customerGroupIds));
$db->selectSimple('welcome_message', TABLE_CUSTOMER_GROUP, "(`id` IN ({$group_ids}))");
while ($row = $db->nextRecord()) {
$welcome_message = $row['welcome_message'];
if ($welcome_message != '') {
$template->set('welcome_message', $welcome_message);
break;
}
}
}
if (
is_array($check_category)
&& $check_category['all_product_display'] == '1'
) {
$listing_sql = preg_replace(
'/SELECT\s*DISTINCT(.*)FROM\s*product AS p (.*)/s',
'SELECT DISTINCT p.id FROM product p $2',
$listing_sql
);
$listing = $db->query($listing_sql);
$multiple_products = [];
while ($row = $db->nextRecord($listing)) {
$multiple_products[] = $row;
}
if (is_array($franchise_products) && count($franchise_products)) {
$multiple_products = array_merge($franchise_products, $multiple_products);
}
$multiple_products = array_chunk($multiple_products, 2);
$template->set('multiple_products', $multiple_products);
$template->defaultName = 'index_products_info';
if ($check_category['dont_show_products_images'] == '1') {
$template->set('dont_show_products_images', true);
} else {
$template->set('dont_show_products_images', false);
}
}
if (
is_array($check_category)
&& $check_category['is_brand'] == 1
) {
$template->set('is_brand', 1);
$brandEmailSignup = new BrandEmailSignupWidget();
$brandEmailSignup->setBrand($categoryName);
$template->set('brandEmailSignup', $brandEmailSignup->render(true));
} else {
$template->set('is_brand', 0);
}
$navigation->setSnapshot();
$template->set('lang_id', (int) $LANG->id);
$template->set('current_customer', $current_customer);
$template->parseTemplate();
$template->endPage();