Category feature

This commit is contained in:
Diego 2017-04-17 13:23:43 +02:00
parent a6bf83acdd
commit 9419a28e24
7 changed files with 22 additions and 15 deletions

View File

@ -20,6 +20,11 @@ function edit($oldCategoryKey, $newCategory)
global $dbPages; global $dbPages;
global $dbCategories; global $dbCategories;
if( Text::isEmpty($oldCategoryKey) || Text::isEmpty($newCategory) ) {
Alert::set($Language->g('Empty field'));
Redirect::page('admin', 'categories');
}
if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) { if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) {
Alert::set($Language->g('Already exist a category')); Alert::set($Language->g('Already exist a category'));
} }
@ -29,7 +34,7 @@ function edit($oldCategoryKey, $newCategory)
Alert::set($Language->g('The changes have been saved')); Alert::set($Language->g('The changes have been saved'));
} }
Redirect::page('admin', 'manage-categories'); Redirect::page('admin', 'categories');
} }
function delete($categoryKey) function delete($categoryKey)
@ -41,7 +46,7 @@ function delete($categoryKey)
Alert::set($Language->g('The changes have been saved')); Alert::set($Language->g('The changes have been saved'));
Redirect::page('admin', 'manage-categories'); Redirect::page('admin', 'categories');
} }
// ============================================================================ // ============================================================================
@ -58,7 +63,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
delete($_POST['categoryKey']); delete($_POST['categoryKey']);
} }
elseif( isset($_POST['edit']) ) { elseif( isset($_POST['edit']) ) {
edit($_POST['categoryKey'], $_POST['categoryName']); edit($_POST['categoryKey'], $_POST['category']);
} }
} }
@ -66,13 +71,13 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
// Main after POST // Main after POST
// ============================================================================ // ============================================================================
if(!$dbCategories->exists($categoryKey)) $categoryKey = $layout['parameters'];
{
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the category: '.$layout['parameters']); if(!$dbCategories->exists($categoryKey)) {
Redirect::page('admin', 'manage-categories'); Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the category: '.$categoryKey);
Redirect::page('admin', 'categories');
} }
$categoryKey = $layout['parameters'];
$category = $dbCategories->getName($layout['parameters']); $category = $dbCategories->getName($layout['parameters']);
$layout['title'] .= ' - '.$Language->g('Edit category').' - '.$category; $layout['title'] .= ' - '.$Language->g('Edit category').' - '.$category;

View File

@ -44,7 +44,7 @@ function add($category)
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{ {
if( add($_POST['category']) ) { if( add($_POST['category']) ) {
Redirect::page('admin', 'manage-categories'); Redirect::page('admin', 'categories');
} }
} }

View File

@ -25,7 +25,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
<div class="uk-form-controls"> <div class="uk-form-controls">
<button type="submit" name="edit" class="uk-button uk-button-primary">'.$L->g('Save').'</button> <button type="submit" name="edit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>
<button type="submit" name="delete" class="uk-button uk-button-primary">'.$L->g('Delete').'</button> <button type="submit" name="delete" class="uk-button uk-button-primary">'.$L->g('Delete').'</button>
<a href="'.HTML_PATH_ADMIN_ROOT.'manage-categories" class="uk-button">'.$L->g('Cancel').'</a> <a href="'.HTML_PATH_ADMIN_ROOT.'categories" class="uk-button">'.$L->g('Cancel').'</a>
</div> </div>
</div>'; </div>';

View File

@ -19,7 +19,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
echo '<div class="uk-form-row"> echo '<div class="uk-form-row">
<div class="uk-form-controls"> <div class="uk-form-controls">
<button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button> <button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>
<a href="'.HTML_PATH_ADMIN_ROOT.'manage-categories" class="uk-button">'.$L->g('Cancel').'</a> <a href="'.HTML_PATH_ADMIN_ROOT.'categories" class="uk-button">'.$L->g('Cancel').'</a>
</div> </div>
</div>'; </div>';

View File

@ -150,7 +150,7 @@ class dbCategories extends dbJSON
// Foreach post in the database // Foreach post in the database
foreach($db as $postKey=>$postData) { foreach($db as $postKey=>$postData) {
if(!empty($postData['category'])) { if( !empty($postData['category']) && $this->exists($postData['category']) ) {
$categoryKey = $postData['category']; $categoryKey = $postData['category'];
array_push($index, $postKey); array_push($index, $postKey);
} }
@ -167,10 +167,12 @@ class dbCategories extends dbJSON
{ {
$index = array(); $index = array();
// Foreach post in the database // Foreach page in the database
foreach($db as $pageKey=>$pageData) { foreach($db as $pageKey=>$pageData) {
$categoryKey = $pageData['category']; if( !empty($pageData['category']) && $this->exists($pageData['category']) ) {
array_push($index, $pageKey); $categoryKey = $pageData['category'];
array_push($index, $pageKey);
}
} }
$this->db[$categoryKey]['pages'] = $index; $this->db[$categoryKey]['pages'] = $index;