misuzu/public/manage/news/category.php

51 lines
1.3 KiB
PHP
Raw Normal View History

2019-06-09 22:10:59 +00:00
<?php
namespace Misuzu;
use Misuzu\News\NewsCategory;
use Misuzu\News\NewsCategoryNotFoundException;
2019-06-09 22:10:59 +00:00
require_once '../../../misuzu.php';
if(!perms_check_user(MSZ_PERMS_NEWS, user_session_current('user_id'), MSZ_PERM_NEWS_MANAGE_CATEGORIES)) {
echo render_error(403);
return;
}
$categoryId = (int)filter_input(INPUT_GET, 'c', FILTER_SANITIZE_NUMBER_INT);
if($categoryId > 0)
try {
$categoryInfo = NewsCategory::byId($categoryId);
Template::set('category_info', $categoryInfo);
} catch(NewsCategoryNotFoundException $ex) {
echo render_error(404);
return;
}
2019-06-09 22:10:59 +00:00
2019-12-11 18:10:54 +00:00
if(!empty($_POST['category']) && CSRF::validateRequest()) {
if(!isset($categoryInfo)) {
$categoryInfo = new NewsCategory;
$isNew = true;
}
$categoryInfo->setName($_POST['category']['name'])
->setDescription($_POST['category']['description'])
->setHidden(!empty($_POST['category']['hidden']))
->save();
2019-06-09 22:10:59 +00:00
audit_log(
empty($isNew)
2019-06-09 22:10:59 +00:00
? MSZ_AUDIT_NEWS_CATEGORY_EDIT
: MSZ_AUDIT_NEWS_CATEGORY_CREATE,
user_session_current('user_id'),
[$categoryInfo->getId()]
2019-06-09 22:10:59 +00:00
);
if(!empty($isNew)) {
header('Location: ' . url('manage-news-category', ['category' => $categoryInfo->getId()]));
return;
}
2019-06-09 22:10:59 +00:00
}
Template::render('manage.news.category');