bludit/bl-kernel/admin/controllers/edit-category.php

97 lines
2.6 KiB
PHP
Raw Normal View History

2017-04-17 12:49:03 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
if($Login->role()!=='admin') {
Alert::set($Language->g('you-do-not-have-sufficient-permissions'));
Redirect::page('admin', 'dashboard');
}
// ============================================================================
// Functions
// ============================================================================
function edit($oldCategoryKey, $newCategory)
{
global $Language;
global $dbPages;
global $dbCategories;
2017-04-17 13:23:43 +02:00
if( Text::isEmpty($oldCategoryKey) || Text::isEmpty($newCategory) ) {
2017-05-16 00:46:20 +02:00
Alert::set($Language->g('Empty fields'));
Redirect::page('categories');
2017-04-17 13:23:43 +02:00
}
2017-05-16 00:46:20 +02:00
2017-04-17 12:49:03 +02:00
if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) {
Alert::set($Language->g('Already exist a category'));
}
else {
$dbPages->changeCategory($oldCategoryKey, $newCategory);
Alert::set($Language->g('The changes have been saved'));
}
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'category-edited',
'notes'=>$newCategory
));
2017-05-16 00:46:20 +02:00
Redirect::page('categories');
2017-04-17 12:49:03 +02:00
}
function delete($categoryKey)
{
global $Language;
global $dbCategories;
// Remove the category by key
2017-04-17 12:49:03 +02:00
$dbCategories->remove($categoryKey);
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'category-deleted',
'notes'=>$categoryKey
));
// Create an alert
2017-04-17 12:49:03 +02:00
Alert::set($Language->g('The changes have been saved'));
// Redirect
2017-05-16 00:46:20 +02:00
Redirect::page('categories');
2017-04-17 12:49:03 +02:00
}
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
if( isset($_POST['delete']) ) {
delete($_POST['categoryKey']);
}
elseif( isset($_POST['edit']) ) {
2017-04-17 13:23:43 +02:00
edit($_POST['categoryKey'], $_POST['category']);
2017-04-17 12:49:03 +02:00
}
}
// ============================================================================
// Main after POST
// ============================================================================
2017-04-17 13:23:43 +02:00
$categoryKey = $layout['parameters'];
2017-05-16 00:46:20 +02:00
if( !$dbCategories->exists($categoryKey) ) {
2017-04-17 13:23:43 +02:00
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the category: '.$categoryKey);
2017-05-16 00:46:20 +02:00
Redirect::page('categories');
2017-04-17 12:49:03 +02:00
}
$category = $dbCategories->getName($layout['parameters']);
2017-05-16 00:46:20 +02:00
$layout['title'] .= ' - '.$Language->g('Edit Category').' - '.$category;