core/api/modules/tovar_cat/index.php

74 lines
5.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
ini_set('display_errors', 0 );//10_04_2016_Prostoe-razdelenie-nagruzki-na-inet-v-Linux.html
if (!$_SESSION['user_id']) $smarty->caching = true;
$smarty -> cache_lifetime = 259200;// 86400 - сутки, 2592000 - месяц 259200 три дня
function delhtml ($text) { // ФУНКЦИЯ очистки кода
$old1 = array(".html");#Ищем вредное ">",, "<"
$new1 = array("");#Меняем на полезное"&gt;", , "&lt;"
$text = str_replace($old1, $new1, $text);#Собсно сама замена =)
return $text;
}
//Антипоисковик
if ( \core::findtxt($_GET['id'], 'html' )==0) header('HTTP/1.0 404 not found');
$period=delhtml($_GET['id']);
$pieces = explode("-",$period);
$pieces[0] = ( $pieces[0] ) ? $pieces[0] : 0; //категория
$page = ( $pieces[1] ) ? $pieces[1] : 0; // текущая страница
$categoryInfo=\DB::getAll("SELECT * FROM `tovar_category` WHERE `id`=? LIMIT 1", $pieces[0]);
$smarty->assign('page_info', $categoryInfo);//получаем инфо о категории
$childrenCategory=\DB::getAll("SELECT `id`, `title`, `img`, `kolvo` FROM `tovar_category` WHERE `status` = 1 AND `category` = ? ORDER BY `title`", $pieces[0] );
//Если нет дочерних категорий, берем текущие....
//if (!$childrenCategory)$childrenCategory=\DB::getAll("SELECT `id`, `title`, `img`, `kolvo` FROM `tovar_category` WHERE `status` = 1 AND `category` = ? ORDER BY `title`", $categoryInfo[0]['category'] );
for ($i=0; $i<count($childrenCategory); $i++) $childrenCategory[$i]['children']=\DB::getAll("SELECT `id`, `title`, `img`, `kolvo` FROM `tovar_category` WHERE `category`=? AND `status`=1 ORDER BY `title`", $childrenCategory[$i]['id']);
$smarty->assign('list', $childrenCategory);//получаем дочерние категории
/* ----------------------------------------------------------------------
19.09.2022
Узнаем обложку раздела - переделано в слайдер
---------------------------------------------------------------------- */
$kol = 40; //количество записей для вывода
$art=($page>0)? ($page * $kol) - $kol : 0;// определяем, с какой записи нам выводить
if ($categoryInfo[0]['partner']=='samson'){
$total = \DB::getValue ( "SELECT COUNT(*) FROM `tovar` WHERE (`category` = ? OR `multicat` LIKE '%-" . $categoryInfo[0]['code'] . "-%') AND `status`=1", $pieces[0] );
\DB::set("UPDATE `tovar_category` SET `kolvo`=? WHERE `id`=?", array($total, $pieces[0]));//обновляем количество товара в категории
$childrenTovar=\DB::getAll("SELECT `id`, `title`, `linkimg`, `cena` FROM `tovar` WHERE (`category` = ? OR `multicat` LIKE '%-" . $categoryInfo[0]['code'] . "-%') AND `status`=1 ORDER BY `title` LIMIT $art, $kol", $pieces[0]);
\DB::set("UPDATE `tovar` SET `category`=? WHERE `multicat` LIKE '%-" . $categoryInfo[0]['code'] . "-%'", $pieces[0]);
}else{
$total = \DB::getValue ( "SELECT COUNT(*) FROM `tovar` WHERE `category` = ? AND `status`=1", $pieces[0] );
\DB::set("UPDATE `tovar_category` SET `kolvo`=? WHERE `id`=?", array($total, $pieces[0]));//обновляем количество товара в категории
$childrenTovar=\DB::getAll("SELECT `id`, `title`, `linkimg`, `cena` FROM `tovar` WHERE `category` = ? AND `status`=1 ORDER BY `title` LIMIT $art, $kol", $pieces[0]);
}
$str_pag = ceil($total / $kol);
//for ($i=0; $i<count($childrenTovar); $i++) $childrenTovar[$i]['img']="/img/" . $_SERVER['SERVER_NAME'] . "/tovar/" . \DB::getValue("SELECT `filename` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1", $childrenTovar[$i]['id']) . ".jpg";
for ($i=0; $i<count($childrenTovar); $i++) $childrenTovar[$i]['img_id']= \DB::getValue("SELECT `id` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1", $childrenTovar[$i]['id']);
$smarty->assign('list2', $childrenTovar);//получаем дочерние категории
/* ----------------------------------------------------------------------
03.01.2023
Хлебные крошки
---------------------------------------------------------------------- */
$smarty->assign('Breadcrumb', \core::getBreadcrumb( 'tovar_category', $categoryInfo[0]['category'] ) );
/* ----------------------------------------------------------------------
03.01.2023
Пагинатор
---------------------------------------------------------------------- */
$paginator='<nav aria-label="123" style="margin-top: 40px; margin-bottom: 40px;"><ul class="pagination">';
for ($i = 1; $i <= $str_pag; $i++){
if ($i==$page)
$paginator.= "<li class='page-item text-center'><a href='/tovar_cat/" . $pieces[0] . "-" .$i.".html' class='page-link'><b>".$i."</b></a></li>";
else
$paginator.= "<li class='page-item text-center'><a href='/tovar_cat/" . $pieces[0] . "-" .$i.".html' class='page-link'>".$i." </a></li>";
}
$paginator.='</ul></nav>';
$smarty->assign('paginator', $paginator);
?>