2022-12-11 13:55:49 +05:00
< ? php
ini_set ( 'display_errors' , 0 );
2023-02-21 21:04:58 +05:00
$smarty -> caching = false ;
2023-01-07 18:55:55 +05:00
$smarty -> cache_lifetime = 2592000 ; // 86400 - сутки, 2592000 - месяц
function delhtml ( $text ) { // ФУНКЦИЯ очистки кода
$old1 = array ( " .html " ); #Ищем вредное ">",, "<"
$new1 = array ( " " ); #Меняем на полезное">", , "<"
$text = str_replace ( $old1 , $new1 , $text ); #Собсно сама замена =)
return $text ;
}
2022-12-11 13:55:49 +05:00
2023-01-07 18:55:55 +05:00
$period = delhtml ( $_GET [ 'id' ]);
$pieces = explode ( " - " , $period );
$pieces [ 0 ] = ( $pieces [ 0 ] ) ? $pieces [ 0 ] : 0 ; //категория
$page = ( $pieces [ 1 ] ) ? $pieces [ 1 ] : 0 ; // текущая страница
2023-01-02 21:33:36 +05:00
2023-01-07 18:55:55 +05:00
$categoryInfo = \DB :: getAll ( " SELECT * FROM `tovar_category` WHERE `id`=? LIMIT 1 " , $pieces [ 0 ]);
$smarty -> assign ( 'page_info' , $categoryInfo ); //получаем инфо о категории
2023-01-24 15:51:26 +05:00
2023-01-07 18:55:55 +05:00
$childrenCategory = \DB :: getAll ( " SELECT `id`, `title` FROM `tovar_category` WHERE `status` = 1 AND `category` = ? ORDER BY `title` " , $pieces [ 0 ] );
2023-02-25 22:58:56 +05:00
//Если нет дочерних категорий, берем текущие....
2023-01-24 15:51:26 +05:00
if ( ! $childrenCategory ){
$childrenCategory = \DB :: getAll ( " SELECT `id`, `title` FROM `tovar_category` WHERE `status` = 1 AND `category` = ? ORDER BY `title` " , $categoryInfo [ 0 ][ 'category' ] );
}
2023-02-25 22:58:56 +05:00
/* ----------------------------------------------------------------------
24.02 . 2023
Выводим изображения категорий
---------------------------------------------------------------------- */
for ( $i = 0 ; $i < count ( $childrenCategory ); $i ++ ){
//Смотрим на всякий случай картинки в таблице tovar_category и переносим в tovar_category_img
// Убрать в конце 2023 года!!!
$obl_img = \DB :: getValue ( " SELECT `img` FROM `tovar_category` WHERE `id`=? LIMIT 1 " , $childrenCategory [ $i ][ 'id' ]);
if ( $obl_img ){
$md5 = md5_file ( 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/tovar_cat/' . $obl_img . '.jpg' );
$insert_id = \DB :: add ( " INSERT INTO `tovar_category_img` (`filename`, `tovar_category_id`, `md5`) VALUES (?, ?, ?) " , array (
$obl_img , $childrenCategory [ $i ][ 'id' ], $md5
) );
\DB :: set ( " UPDATE `tovar_category` SET `img`=? WHERE `id`=? LIMIT 1 " , array ( " " , $childrenCategory [ $i ][ 'id' ]) );
unset ( $obl_img );
unset ( $md5 );
}
//А это не убирать!
$childrenCategory [ $i ][ 'img' ] = \DB :: getValue ( " SELECT `filename` FROM `tovar_category_img` WHERE `tovar_category_id`=? LIMIT 1 " , $childrenCategory [ $i ][ 'id' ]);
}
2023-01-24 15:51:26 +05:00
2023-01-07 18:55:55 +05:00
$smarty -> assign ( 'list' , $childrenCategory ); //получаем дочерние категории
2023-01-02 21:33:36 +05:00
2023-01-07 18:55:55 +05:00
/* ----------------------------------------------------------------------
19.09 . 2022
Узнаем обложку раздела
---------------------------------------------------------------------- */
2023-01-02 21:33:36 +05:00
2023-01-07 18:55:55 +05:00
$mainImg = \DB :: getValue ( " SELECT `filename` FROM `tovar_category_img` WHERE `tovar_category_id`=? " , $pieces [ 0 ]);
$smarty -> assign ( 'oblozhka' , $mainImg );
2022-12-11 13:55:49 +05:00
2023-01-07 18:55:55 +05:00
/* ----------------------------------------------------------------------
02.01 . 2023
Получаем случайную обложку категории
---------------------------------------------------------------------- */
2022-12-17 18:15:09 +05:00
2023-01-07 18:55:55 +05:00
if ( $pieces [ 0 ] ) $catImg = \DB :: getValue ( " SELECT `filename` FROM `tovar_category_img` WHERE `tovar_category_id`=? ORDER BY RANDOM() LIMIT 1 " , $pieces [ 0 ]);
$smarty -> assign ( 'catImg' , $catImg );
$kol = 40 ; //количество записей для вывода
2023-02-25 22:58:56 +05:00
$art = ( $page > 0 ) ? ( $page * $kol ) - $kol : 0 ; // определяем, с какой записи нам выводить
2023-01-07 18:55:55 +05:00
$total = \DB :: getValue ( " SELECT COUNT(*) FROM `tovar` WHERE `category` = ? AND `status`=1 " , $pieces [ 0 ] );
$str_pag = ceil ( $total / $kol );
2023-02-25 22:58:56 +05:00
2023-01-07 18:55:55 +05:00
$childrenTovar = \DB :: getAll ( " SELECT `id`, `title` FROM `tovar` WHERE `category`=? AND `status`=1 ORDER BY `title` LIMIT $art , $kol " , $pieces [ 0 ]);
2023-02-25 22:58:56 +05:00
2023-01-02 21:33:36 +05:00
for ( $i = 0 ; $i < count ( $childrenTovar ); $i ++ ){
2023-02-25 22:58:56 +05:00
//Смотрим на всякий случай картинки в таблице tovar и переносим в tovar_img
// Убрать в конце 2023 года!!!
/* $tov_img = \DB :: getValue ( " SELECT `img` FROM `tovar` WHERE `id`=? LIMIT 1 " , $childrenTovar [ $i ][ 'id' ]);
if ( $tov_img ){
$md5 = md5_file ( 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/tovar/' . $tov_img . '.jpg' );
$insert_id = \DB :: add ( " INSERT INTO `tovar_img` (`filename`, `tovar_id`, `md5`) VALUES (?, ?, ?) " , array (
$tov_img , $childrenTovar [ $i ][ 'id' ], $md5
) );
\DB :: set ( " UPDATE `tovar` SET `img`=? WHERE `id`=? LIMIT 1 " , array ( " " , $childrenTovar [ $i ][ 'id' ]) );
unset ( $tov_img );
unset ( $md5 );
}
*/
//А это не убирать!
2023-01-02 21:33:36 +05:00
$childrenTovar [ $i ][ 'cena' ] = \DB :: getValue ( " SELECT `cena` FROM `tovar_price_history` WHERE `tovar_id`=? ORDER BY `t` DESC LIMIT 1 " , $childrenTovar [ $i ][ 'id' ]);
2023-02-25 22:58:56 +05:00
$childrenTovar [ $i ][ 'img' ] = \DB :: getValue ( " SELECT `filename` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1 " , $childrenTovar [ $i ][ 'id' ]);
2023-01-02 21:33:36 +05:00
}
2022-12-17 18:15:09 +05:00
2023-02-25 22:58:56 +05:00
2022-12-17 18:15:09 +05:00
$smarty -> assign ( 'list2' , $childrenTovar ); //получаем дочерние категории
2022-12-11 13:55:49 +05:00
/* ----------------------------------------------------------------------
2023-01-07 18:55:55 +05:00
03.01 . 2023
Хлебные крошки
2022-12-11 13:55:49 +05:00
---------------------------------------------------------------------- */
2022-12-17 18:15:09 +05:00
2023-01-07 18:55:55 +05:00
$smarty -> assign ( 'Breadcrumb' , \core :: getBreadcrumb ( 'tovar_category' , $categoryInfo [ 0 ][ 'category' ] ) );
2023-01-02 21:33:36 +05:00
/* ----------------------------------------------------------------------
2023-01-07 18:55:55 +05:00
03.01 . 2023
Пагинатор
2023-01-02 21:33:36 +05:00
---------------------------------------------------------------------- */
2023-01-07 18:55:55 +05:00
$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 );
2023-02-25 22:58:56 +05:00
/*
ALTER TABLE `tovar_category_img`
CHANGE `md5` `md5` varchar ( 60 ) COLLATE 'utf8_general_ci' NULL AFTER `tovar_category_id` ;
*/
?>