assign( 'editor_js', '');
$content=\core::getContent($_GET['id'], 'page');
$page=$content['row'];
$massiv=$content['json'];
$page['filename'] = \DB::getValue("SELECT `filename` FROM `img` WHERE `content_id`=? AND `content_type`=? LIMIT 1", array($page['id'], $page['content_type']));
//$smarty->assign('page', $page);
$smarty->assign('json', $massiv);
//Получаем страницу
if ($_GET['id']) $smarty -> assign( 'page', $page);
//Проверяем права доступа на редактирование страницы - админ может и автор страницы может, левые идут на 403-страницу
$dostup = 0;
if ( $_SESSION['dostup']=='a' ) $dostup = 1;
if ($page['user_id']){
if ( $_SESSION['user_id'] == $page['user_id']) $dostup = 1;
}else{
if ($_SESSION['dostup']=='u')$dostup=1;
}
//if ($dostup==0)header( 'Location: /403/' );
/* ----------------------------------------------------------------------
07.01.20223
Получаем список категорий
---------------------------------------------------------------------- */
$smarty -> assign( 'pages_category', \DB::getAll("SELECT * FROM `content_category` WHERE `status`=1 AND `content_type`='page' AND `site`=?", $_SERVER['SERVER_NAME'] ) );
if (@$_POST){
$massiv['comments']=1;
$json=\core::j($massiv);
/* ----------------------------------------------------------------------
07.01.2023
Принимаем входящие данные
---------------------------------------------------------------------- */
if ($_GET['id']){
\DB::set("UPDATE `content` SET `title`=?, `txt`=?, `time`=?, `category`=?, `json`=? WHERE `id`=? AND `site`=? AND `content_type`=?", array($_POST['title'], $_POST['txt'], time(), $_POST['category'], $json, $_GET['id'], $_SERVER['SERVER_NAME'], 'page' ) );
$id=$_GET['id'];
}else{
$id=\DB::add("INSERT INTO `content` (`title`, `txt`, `time`, `category`, `user_id`, `status`, `site`, `content_type`, `json`) VALUES (?,?,?,?,?,?, ?, ?, ?)", array(
$_POST['title'], $_POST['txt'], time(), $_POST['category'], $_SESSION['user_id'], 1, $_SERVER['SERVER_NAME'], 'page', $json) );
}
/* ----------------------------------------------------------------------
10.12.2023
Меняем обложку
---------------------------------------------------------------------- */
if ($_FILES){
\DB::set("DELETE FROM `img` WHERE `content_id`=? AND `content_type`=? AND `site`=?", array($page['id'], $page['content_type'], $_SERVER['SERVER_NAME']));
unlink ('img/' . $_SERVER['SERVER_NAME'] . '/' . $page['content_type'] . '/' . $page['id'] . '/' . $page['filename'] . '.jpg');
\core::upload_img($page['content_type'], $page['id']);
}
//редирект чтобы не слали повторные запросы по f5
header( 'Location: /page/' . $id );
}
?>