core/api/modules/a_tovar_cat/index.php

131 lines
6.1 KiB
PHP
Raw 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 );
//@mkdir(MYDIR . '/img/tovar', 0700);
//проверяем авторизацию
if ( $_SESSION['dostup'] !=='a' && $_SESSION['dostup'] !== 'e' ) header( 'Location: /403/' );
/* ----------------------------------------------------------------------
10.06.2023
выбираем правила сортировки
---------------------------------------------------------------------- */
//$autofilter=\DB::getAll("SELECT * FROM `tovar_category_filter` WHERE `tovar_category`=?", $_GET['id']);
//$smarty -> assign( 'autofilter', $autofilter );
/* ----------------------------------------------------------------------
17.02.2023
Перемещаем товар
---------------------------------------------------------------------- */
if (@$_POST['move']) \DB::set ("UPDATE `tovar` SET `category`=? WHERE `title` LIKE '" . $_POST['txt'] . "'", $_POST['category']);
$smarty -> assign( 'uploadimg', 'api/modules/a_tovar_cat/uploadimg.html' );
$_SESSION['tmp']=$_GET['id'];
/* ----------------------------------------------------------------------
14.12.2022
Получаем инфу о пользователе
---------------------------------------------------------------------- */
$smarty -> assign( 'userInfo', \core::getUserInfo( $_SESSION['user_id'] ) );
$set['showNoPublic']=\core::getSettings('showNoPublic', 'a_tovar_cat');
/* ----------------------------------------------------------------------
15.12.2022
Получаем список категорий
---------------------------------------------------------------------- */
$_GET['id'] = ($_GET['id']) ? $_GET['id'] : 0;
if ($set['showNoPublic']==1)
$cats=\DB::getAll("SELECT * FROM `tovar_category` WHERE `category`=? ORDER BY `title`", $_GET['id']);
else
$cats=\DB::getAll("SELECT * FROM `tovar_category` WHERE `category`=? AND `status`=1 ORDER BY `title`", $_GET['id']);
for ( $i=0; $i<count($cats); $i++){
unset($c);
$c=\DB::getAll("SELECT count(*) FROM `tovar_category` WHERE `category`=? AND `status`=1" , $cats[$i]['id']);
$cats[$i]['count_cats']=$c[0]['count(*)'];
unset($c);
$c=\DB::getAll("SELECT count(*) FROM `tovar` WHERE `category`=? AND `status`=1", $cats[$i]['id']);
$cats[$i]['count_tovar']=$c[0]['count(*)'];
}
$smarty -> assign( 'cats', $cats );
/* ----------------------------------------------------------------------
03.01.2023
Хлебные крошки
---------------------------------------------------------------------- */
$smarty->assign('Breadcrumb', \core::getBreadcrumb( 'tovar_category', $cats[0]['category'] ) );
//
/* ----------------------------------------------------------------------
15.12.2022
Получаем список товаров
---------------------------------------------------------------------- */
if ($set['showNoPublic']==1)
$tovars=\DB::getAll("SELECT `id`, `title`, `cena`, `status` FROM `tovar` WHERE `category`=? ORDER BY tovar.title LIMIT 400", $_GET['id']);
else//$tovars=\DB::getAll("SELECT tovar.*, tovar_img.filename AS img FROM `tovar`
$tovars=\DB::getAll("SELECT `id`, `title`, `cena`, `status` FROM `tovar` WHERE `category`=? AND `status`=1 ORDER BY tovar.title LIMIT 400", $_GET['id']);
for ($i=0;$i<count($tovars);$i++)$tovars[$i]['img']=\DB::getValue("SELECT `filename` FROM `tovar_img` WHERE `tovar_id`=?", $tovars[$i]['id']);
/*if ($set['showNoPublic']==1)
$tovars=\DB::getAll("SELECT tovar.id, tovar.title, tovar.cena, tovar_img.filename AS img FROM `tovar`
JOIN `tovar_img`
ON tovar_img.tovar_id=tovar.id
WHERE `category`=? ORDER BY tovar.title LIMIT 400", $_GET['id']);
else//$tovars=\DB::getAll("SELECT tovar.*, tovar_img.filename AS img FROM `tovar`
$tovars=\DB::getAll("SELECT tovar.id, tovar.title, tovar.cena, tovar_img.filename AS img FROM `tovar`
JOIN `tovar_img`
ON tovar_img.tovar_id=tovar.id
WHERE `category`=? AND `status`=1 ORDER BY tovar.title LIMIT 400", $_GET['id']);
*/
if ($tovars)$smarty -> assign( 'pages', \core::array_unique_key($tovars, 'id') );
/* ----------------------------------------------------------------------
21.12.2022
Получаем информацию о категории
---------------------------------------------------------------------- */
if ( $_GET['id'] ){
$catInfo = \DB::getAll( "SELECT * FROM `tovar_category` WHERE `id`=? LIMIT 1", $_GET['id'] );
//print_r ( $catInfo );
$smarty -> assign( 'catInfo', $catInfo );
/* ----------------------------------------------------------------------
02.01.2023
Получаем обложек
---------------------------------------------------------------------- */
$imgs=\DB::getAll("SELECT * FROM `tovar_category_img` WHERE `tovar_category_id`=?", $_GET['id']);
$smarty -> assign( 'imgs', $imgs );
}
/* ----------------------------------------------------------------------
21.12.2022
Получаем список категорий
---------------------------------------------------------------------- */
$catList=\DB::getAll("SELECT `id`, `title` FROM `tovar_category` WHERE `status`=1 ORDER BY `title`");
$smarty -> assign( 'catList', $catList );
//получаем список страниц
//echo ("test1");
//$pages = $mod -> get_pages('page', ID);
//$smarty -> assign( 'pages', $pages );//список страниц
//$smarty -> assign( 'cat_id', ID );//ИД категории
//$smarty -> assign( 'all_cats', $mod->get_all_cats() );//Получаем все опубликованные категории для модалки добавления и изменения категорий
$smarty -> assign( 'cat_list', 'api/modules/' . MOD . '/cat_list.html' );
$smarty -> assign( 'pages_list', 'api/modules/' . MOD . '/pages_list.html' );
$smarty -> assign( 'modal_new_cat', 'api/modules/' . MOD . '/modal_new_cat.html' );
$smarty -> assign( 'modal_del_page', 'api/modules/' . MOD . '/modal_del_page.html' );
//if (ID) $smarty -> assign( 'this_cat', $mod -> get_this_cat( ID ) );//Эта категория
$smarty -> assign( 'set', $set );
?>