misuzu/public/manage/news/category.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2019-06-09 22:10:59 +00:00
<?php
namespace Misuzu;
2020-05-21 15:05:30 +00:00
use Misuzu\AuditLog;
use Misuzu\News\NewsCategory;
use Misuzu\News\NewsCategoryNotFoundException;
2020-05-25 19:58:06 +00:00
use Misuzu\Users\User;
2019-06-09 22:10:59 +00:00
require_once '../../../misuzu.php';
2020-05-25 19:58:06 +00:00
if(!User::hasCurrent() || !perms_check_user(MSZ_PERMS_NEWS, User::getCurrent()->getId(), MSZ_PERM_NEWS_MANAGE_CATEGORIES)) {
2019-06-09 22:10:59 +00:00
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
2020-05-21 15:05:30 +00:00
AuditLog::create(
empty($isNew)
2020-05-21 15:05:30 +00:00
? AuditLog::NEWS_CATEGORY_EDIT
: AuditLog::NEWS_CATEGORY_CREATE,
[$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');