Category feature
This commit is contained in:
parent
a6bf83acdd
commit
9419a28e24
|
@ -20,6 +20,11 @@ function edit($oldCategoryKey, $newCategory)
|
|||
global $dbPages;
|
||||
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 ) {
|
||||
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'));
|
||||
}
|
||||
|
||||
Redirect::page('admin', 'manage-categories');
|
||||
Redirect::page('admin', 'categories');
|
||||
}
|
||||
|
||||
function delete($categoryKey)
|
||||
|
@ -41,7 +46,7 @@ function delete($categoryKey)
|
|||
|
||||
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']);
|
||||
}
|
||||
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
|
||||
// ============================================================================
|
||||
|
||||
if(!$dbCategories->exists($categoryKey))
|
||||
{
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the category: '.$layout['parameters']);
|
||||
Redirect::page('admin', 'manage-categories');
|
||||
$categoryKey = $layout['parameters'];
|
||||
|
||||
if(!$dbCategories->exists($categoryKey)) {
|
||||
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']);
|
||||
|
||||
$layout['title'] .= ' - '.$Language->g('Edit category').' - '.$category;
|
||||
|
|
|
@ -44,7 +44,7 @@ function add($category)
|
|||
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
{
|
||||
if( add($_POST['category']) ) {
|
||||
Redirect::page('admin', 'manage-categories');
|
||||
Redirect::page('admin', 'categories');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
|
|||
<div class="uk-form-controls">
|
||||
<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>
|
||||
<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>';
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
|
|||
echo '<div class="uk-form-row">
|
||||
<div class="uk-form-controls">
|
||||
<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>';
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ class dbCategories extends dbJSON
|
|||
|
||||
// Foreach post in the database
|
||||
foreach($db as $postKey=>$postData) {
|
||||
if(!empty($postData['category'])) {
|
||||
if( !empty($postData['category']) && $this->exists($postData['category']) ) {
|
||||
$categoryKey = $postData['category'];
|
||||
array_push($index, $postKey);
|
||||
}
|
||||
|
@ -167,11 +167,13 @@ class dbCategories extends dbJSON
|
|||
{
|
||||
$index = array();
|
||||
|
||||
// Foreach post in the database
|
||||
// Foreach page in the database
|
||||
foreach($db as $pageKey=>$pageData) {
|
||||
if( !empty($pageData['category']) && $this->exists($pageData['category']) ) {
|
||||
$categoryKey = $pageData['category'];
|
||||
array_push($index, $pageKey);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db[$categoryKey]['pages'] = $index;
|
||||
|
||||
|
|
Loading…
Reference in New Issue