bug fixes

This commit is contained in:
Diego Najar 2017-07-29 21:03:18 +02:00
parent 139dfee1ec
commit efe9b742c7
5 changed files with 73 additions and 64 deletions

View File

@ -6,62 +6,13 @@
if($Login->role()!=='admin') {
Alert::set($Language->g('you-do-not-have-sufficient-permissions'));
Redirect::page('admin', 'dashboard');
Redirect::page('dashboard');
}
// ============================================================================
// Functions
// ============================================================================
function edit($oldCategoryKey, $newCategory)
{
global $Language;
global $dbPages;
global $dbCategories;
if( Text::isEmpty($oldCategoryKey) || Text::isEmpty($newCategory) ) {
Alert::set($Language->g('Empty fields'));
Redirect::page('categories');
}
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
));
Redirect::page('categories');
}
function delete($categoryKey)
{
global $Language;
global $dbCategories;
// Remove the category by key
$dbCategories->remove($categoryKey);
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'category-deleted',
'notes'=>$categoryKey
));
// Create an alert
Alert::set($Language->g('The changes have been saved'));
// Redirect
Redirect::page('categories');
}
// ============================================================================
// Main before POST
// ============================================================================
@ -70,14 +21,16 @@ function delete($categoryKey)
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
if ($_SERVER['REQUEST_METHOD']=='POST') {
if (isset($_POST['delete'])) {
delete($_POST['categoryKey']);
deleteCategory($_POST['categoryKey']);
}
elseif (isset($_POST['edit'])) {
edit($_POST['categoryKey'], $_POST['category']);
editCategory($_POST['categoryKey'], $_POST['category']);
}
Redirect::page('categories');
}
// ============================================================================

View File

@ -111,7 +111,7 @@ define('CLI_STATUS', 'published');
define('CLI_USERNAME', 'admin');
// Filename
define('FILENAME', 'index.md');
define('FILENAME', 'index.txt');
// Database date format
define('DB_DATE_FORMAT', 'Y-m-d H:i:s');

View File

@ -498,3 +498,47 @@ function editSettings($args) {
return false;
}
function editCategory($oldCategoryKey, $newCategory) {
global $Language;
global $dbPages;
global $dbCategories;
global $Syslog;
if( Text::isEmpty($oldCategoryKey) || Text::isEmpty($newCategory) ) {
Alert::set($Language->g('Empty fields'));
return false;
}
if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) {
Alert::set($Language->g('Already exist a category'));
return false;
}
$dbPages->changeCategory($oldCategoryKey, $newCategory);
$Syslog->add(array(
'dictionaryKey'=>'category-edited',
'notes'=>$newCategory
));
Alert::set($Language->g('The changes have been saved'));
return true;
}
function deleteCategory($categoryKey) {
global $Language;
global $dbCategories;
global $Syslog;
// Remove the category by key
$dbCategories->remove($categoryKey);
$Syslog->add(array(
'dictionaryKey'=>'category-deleted',
'notes'=>$categoryKey
));
Alert::set($Language->g('The changes have been saved'));
return true;
}

View File

@ -15,8 +15,10 @@
<nav class="links">
<ul>
<?php
// Print all pages parents
foreach($pagesByParent[PARENT] as $pageParent) {
$fixedPages = $dbPages->getFixedDB();
$keys = array_keys($fixedPages);
foreach($keys as $pageKey) {
$pageParent = buildPage($pageKey);
echo '<li><a href="'.$pageParent->permalink().'">'.$pageParent->title().'</a></li>';
}
?>
@ -36,7 +38,17 @@
<section>
<ul class="links">
<?php
foreach($pagesByParent[PARENT] as $pageParent) {
echo '<li>';
echo '<a href="'.$Site->url().'">
<h3>'.$Language->get('Home page').'</h3>
<p>'.$Site->description().'</p>
</a>';
echo '</li>';
$fixedPages = $dbPages->getFixedDB();
$keys = array_keys($fixedPages);
foreach($keys as $pageKey) {
$pageParent = buildPage($pageKey);
echo '<li>';
echo '<a href="'.$pageParent->permalink().'">
<h3>'.$pageParent->title().'</h3>