2022-12-11 13:55:49 +05:00
|
|
|
|
<?php
|
|
|
|
|
ini_set( 'display_errors', 0 );
|
2023-04-09 19:52:26 +05:00
|
|
|
|
if ($db['type']=='mysql'){
|
|
|
|
|
\DB::set("ALTER TABLE `tovar_category` ADD `hide` int(1) NULL DEFAULT '0'");
|
|
|
|
|
\DB::set("ALTER TABLE `tovar` ADD `zakazEnable` int(1) NULL DEFAULT '1'");
|
|
|
|
|
}else{
|
|
|
|
|
\DB::set("ALTER TABLE `tovar_category` ADD `hide` INTEGER");
|
|
|
|
|
\DB::set("ALTER TABLE `tovar` ADD `zakazEnable` INTEGER");
|
|
|
|
|
}
|
2022-12-11 13:55:49 +05:00
|
|
|
|
//проверяем авторизацию
|
|
|
|
|
if ( $_SESSION['dostup'] !== 'a' && $_SESSION['dostup'] !== 'e' ) header( 'Location: /403/' );
|
|
|
|
|
|
2023-04-09 19:52:26 +05:00
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
20.03.2023
|
|
|
|
|
Сохраняем товар
|
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
if (@$_POST['ok']){
|
|
|
|
|
$_POST['status']=($_POST['status']=='on')?1:0;
|
|
|
|
|
$_POST['zakazEnable']=($_POST['zakazEnable']=='on')?1:0;
|
|
|
|
|
if ($_GET['id']){//Обновляем
|
|
|
|
|
\DB::set("UPDATE `tovar` SET `title`=?, `artikul`=?, `category`=?, `zakazEnable`=?, `status`=?, `txt`=? WHERE `id`=?",
|
|
|
|
|
array(
|
|
|
|
|
$_POST['title'],
|
|
|
|
|
$_POST['artikul'],
|
|
|
|
|
$_POST['category'],
|
|
|
|
|
$_POST['zakazEnable'],
|
|
|
|
|
$_POST['status'],
|
|
|
|
|
$_POST['txt'],
|
|
|
|
|
$_GET['id']
|
|
|
|
|
));
|
|
|
|
|
\DB::set("UPDATE `tovar_barcode` SET `barcode`=? WHERE `tovar_id`=?", array($_POST['barcode'], $_GET['id'] ));
|
|
|
|
|
}else{//Добавляем
|
|
|
|
|
$inser_id=\DB::add("INSERT INTO `tovar` (`title`, `artikul`, `category`, `zakazEnable`, `status`, `txt`) VALUES (?, ?, ?, ?, ?, ?)", array(
|
|
|
|
|
$_POST['title'],
|
|
|
|
|
$_POST['artikul'],
|
|
|
|
|
$_POST['category'],
|
|
|
|
|
$_POST['zakazEnable'],
|
|
|
|
|
$_POST['status'],
|
|
|
|
|
$_POST['txt']
|
|
|
|
|
));
|
|
|
|
|
if ($_POST['barcode'])\DB::add("INSERT INTO `tovar_barcode` (`tovar_id`, `barcode`) VALUES (?, ?)", array($inser_id, $_POST['barcode']));
|
|
|
|
|
header( 'Location: /a_new_tovar/' . $inser_id );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 18:55:55 +05:00
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
14.12.2022
|
|
|
|
|
Получаем инфу о пользователе
|
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
$smarty -> assign( 'userInfo', \core::getUserInfo( $_SESSION['user_id'] ) );
|
|
|
|
|
|
2022-12-11 13:55:49 +05:00
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
06.09.2022
|
|
|
|
|
Сессия для загрузки картинок
|
|
|
|
|
---------------------------------------------------------------------- */
|
2023-03-05 20:22:21 +05:00
|
|
|
|
$_SESSION['tovar_id'] = $_GET['id'];
|
2022-12-11 13:55:49 +05:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
21.08.2022
|
|
|
|
|
Получаем список категорий
|
|
|
|
|
---------------------------------------------------------------------- */
|
2023-04-09 19:52:26 +05:00
|
|
|
|
$cats=\DB::getAll("SELECT * FROM `tovar_category` WHERE `status`=1");
|
2022-12-11 13:55:49 +05:00
|
|
|
|
$smarty -> assign( 'cats', $cats );
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
23.08.2022
|
|
|
|
|
Получаем данные о товаре
|
|
|
|
|
05.09.2022
|
|
|
|
|
Получаем картинки
|
|
|
|
|
08.09.2022
|
|
|
|
|
Получаем характеристики
|
|
|
|
|
---------------------------------------------------------------------- */
|
2023-04-09 19:52:26 +05:00
|
|
|
|
if ( @$_GET['id'] ) {
|
2022-12-17 18:15:09 +05:00
|
|
|
|
$tovar=\DB::getAll("SELECT * FROM `tovar` WHERE `id`=? LIMIT 1", $_GET['id']);
|
|
|
|
|
$smarty -> assign ( 'tovar', $tovar );
|
|
|
|
|
$imgs=\DB::getAll("SELECT * FROM `tovar_img` WHERE `tovar_id`=?", $_GET['id']);
|
|
|
|
|
$smarty -> assign ( 'imgs', $imgs );
|
2023-03-05 20:22:21 +05:00
|
|
|
|
//print_r($imgs);
|
2022-12-17 18:15:09 +05:00
|
|
|
|
//$har=\DB::getAll("SELECT * FROM `tovar_img` WHERE `tovar_id`=?", $_GET['id']);
|
|
|
|
|
//$smarty -> assign ( 'har', $mod -> getHar( ID ) );
|
2022-12-11 13:55:49 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 19:52:26 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-11 13:55:49 +05:00
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
05.09.2022
|
|
|
|
|
Сохраняем товар и открываем его сохраненную карточку
|
|
|
|
|
!!! Сохранение описания в json
|
|
|
|
|
---------------------------------------------------------------------- */
|
2022-12-17 18:15:09 +05:00
|
|
|
|
//if ( $_POST['act'] == 'addTovar' ) header ( 'Location: /a_new_tovar/' . $mod -> addTovar( $_POST ) );
|
2022-12-11 13:55:49 +05:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
06.09.2022
|
|
|
|
|
Редактируем товар
|
|
|
|
|
!!! Сохранение описания в json
|
|
|
|
|
---------------------------------------------------------------------- */
|
2022-12-17 18:15:09 +05:00
|
|
|
|
//if ( $_POST['act'] == 'editTovar' && ID ) $mod -> editTovar( $_POST, ID );
|
2022-12-11 13:55:49 +05:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|