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

64 lines
1.8 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('dashboard');
2017-04-17 12:49:03 +02:00
}
// ============================================================================
// Functions
// ============================================================================
function add($category)
{
global $dbCategories;
global $Language;
2017-06-01 00:22:20 +02:00
global $Syslog;
2017-04-17 12:49:03 +02:00
if( Text::isEmpty($category) ) {
Alert::set($Language->g('Category name is empty'), ALERT_STATUS_FAIL);
return false;
}
if( $dbCategories->add($category) ) {
2017-06-01 00:22:20 +02:00
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'new-category-created',
'notes'=>$category
));
// Create an alert
2017-04-17 12:49:03 +02:00
Alert::set($Language->g('Category added'), ALERT_STATUS_OK);
2017-06-01 00:22:20 +02:00
// Redirect
Redirect::page('categories');
2017-04-17 12:49:03 +02:00
}
else {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the category.');
return false;
}
}
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
2017-06-01 00:22:20 +02:00
add($_POST['category']);
2017-04-17 12:49:03 +02:00
}
// ============================================================================
// Main after POST
// ============================================================================
// Title of the page
$layout['title'] .= ' - '.$Language->g('New category');