Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vendeeglobe committed May 26, 2022
1 parent c27e8ba commit d92be7c
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions wacko/handler/page/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

if (isset($_POST))
{
$change_id = (int) ($_POST['change_id'] ?? null);
$parent_id = (int) ($_POST['parent_id'] ?? null);
$category_id = (int) ($_POST['category_id'] ?? null);
$category = $this->sanitize_text_field(($_POST['category'] ?? ''), true);
$category_description = $this->sanitize_text_field(($_POST['category_description'] ?? ''));

Expand All @@ -59,18 +62,18 @@
else if ($this->is_admin() || ($this->is_owner() && $this->db->categories_handler))
{
// get categories
if (isset($_POST['category_id']))
if ($category_id)
{
$word = $this->db->load_single(
"SELECT category_id, parent_id, category " .
"FROM " . $this->db->table_prefix . "category " .
"WHERE category_id = " . (int) $_POST['category_id'] . " " .
"WHERE category_id = " . (int) $category_id . " " .
"AND category_lang = " . $this->db->q($this->page['page_lang']) . " " .
"LIMIT 1");
}

// add item
if (isset($_POST['create']) && isset($_POST['category']))
if (isset($_POST['create']) && $category)
{
// do we have identical name for this language?
if ($this->db->load_single(
Expand All @@ -81,15 +84,15 @@
"LIMIT 1"))
{
$this->set_message($this->_t('CategoriesAlreadyExists'));
$_POST['change_id'] = $_POST['category_id'];
$_POST['change_id'] = $category_id;
$_POST['create'] = 1;
}
else
{
// save item
$this->db->sql_query(
"INSERT INTO " . $this->db->table_prefix . "category SET " .
($_POST['category_id'] && $_POST['group'] == 1
($category_id && $_POST['group'] == 1
? "parent_id = " . ((int) $word['parent_id'] != 0
? (int) $word['parent_id']
: (int) $word['category_id'] ) . ", "
Expand All @@ -100,26 +103,26 @@
"category_description = " . $this->db->q($category_description) . " ");

$this->set_message(Ut::perc_replace($this->_t('CategoriesAdded'), '<code>' . $category . '</code>'), 'success');
$this->log(4, Ut::perc_replace($this->_t('LogCategoryCreated', SYSTEM_LANG), $_POST['category']));
$this->log(4, Ut::perc_replace($this->_t('LogCategoryCreated', SYSTEM_LANG), $category));
unset($_POST['create']);
}

$this->http->redirect($this->href('categories', '', 'edit'));
}
// rename item
else if (isset($_POST['rename']) && isset($_POST['category']) && isset($_POST['category_id']))
else if (isset($_POST['rename']) && $category && $category_id)
{
// do we have identical name for this language?
if ($this->db->load_single(
"SELECT category_id " .
"FROM " . $this->db->table_prefix . "category " .
"WHERE category = " . $this->db->q($category) . " " .
"AND category_lang = " . $this->db->q($this->page['page_lang']) . " " .
"AND category_id <> " . (int) $_POST['category_id'] . " " .
"AND category_id <> " . (int) $category_id . " " .
"LIMIT 1"))
{
$this->set_message($this->_t('CategoriesAlreadyExists'));
$_POST['change_id'] = $_POST['category_id'];
$_POST['change_id'] = $category_id;
$_POST['rename'] = 1;
}
else
Expand All @@ -128,25 +131,25 @@
"UPDATE " . $this->db->table_prefix . "category SET " .
"category = " . $this->db->q($category) . ", " .
"category_description = " . $this->db->q($category_description) . " " .
"WHERE category_id = " . (int) $_POST['category_id'] . " " .
"WHERE category_id = " . (int) $category_id . " " .
"LIMIT 1");

$this->set_message($this->_t('CategoriesRenamed'), 'success');
$this->log(4, Ut::perc_replace($this->_t('LogCategoryRenamed', SYSTEM_LANG), $word['category'], $_POST['category']));
$this->log(4, Ut::perc_replace($this->_t('LogCategoryRenamed', SYSTEM_LANG), $word['category'], $category));
}

$this->http->redirect($this->href('categories', '', 'edit'));
}
// (un)group item
else if (isset($_POST['ugroup']) && isset($_POST['parent_id']) && isset($_POST['category_id']))
else if (isset($_POST['ugroup']) && $parent_id && $category_id)
{
// in or out?
if ($_POST['parent_id'] == 0)
if ($parent_id == 0)
{
$this->db->sql_query(
"UPDATE " . $this->db->table_prefix . "category SET " .
"parent_id = 0 " .
"WHERE category_id = " . (int) $_POST['category_id'] . " " .
"WHERE category_id = " . (int) $category_id . " " .
"LIMIT 1");

$this->set_message($this->_t('CategoriesUngrouped'), 'success');
Expand All @@ -157,21 +160,21 @@
$parent = $this->db->load_single(
"SELECT parent_id, category " .
"FROM " . $this->db->table_prefix . "category " .
"WHERE category_id = " . (int) $_POST['parent_id'] . " " .
"WHERE category_id = " . (int) $parent_id . " " .
"LIMIT 1");

if ($parent['parent_id'] == 0)
{
$this->db->sql_query(
"UPDATE " . $this->db->table_prefix . "category SET " .
"parent_id = " . (int) $_POST['parent_id'] . " " .
"WHERE category_id = " . (int) $_POST['category_id'] . " " .
"parent_id = " . (int) $parent_id . " " .
"WHERE category_id = " . (int) $category_id . " " .
"LIMIT 1");

$this->db->sql_query(
"UPDATE " . $this->db->table_prefix . "category SET " .
"parent_id = 0 " .
"WHERE parent_id = " . (int) $_POST['category_id']);
"WHERE parent_id = " . (int) $category_id);

$this->set_message($this->_t('CategoriesGrouped'), 'success');
$this->log(4, Ut::perc_replace($this->_t('LogCategoryGrouped', SYSTEM_LANG), $word['category'], $parent['category']));
Expand All @@ -185,20 +188,20 @@
$this->http->redirect($this->href('categories', '', 'edit'));
}
// delete item
else if (isset($_POST['delete']) && isset($_POST['category_id']))
else if (isset($_POST['delete']) && $category_id)
{
$this->db->sql_query(
"DELETE FROM " . $this->db->table_prefix . "category " .
"WHERE category_id = " . (int) $_POST['category_id']);
"WHERE category_id = " . (int) $category_id);

$this->db->sql_query(
"DELETE FROM " . $this->db->table_prefix . "category_assignment " .
"WHERE category_id = " . (int) $_POST['category_id']);
"WHERE category_id = " . (int) $category_id);

$this->db->sql_query(
"UPDATE " . $this->db->table_prefix . "category SET " .
"parent_id = 0 " .
"WHERE parent_id = " . (int) $_POST['category_id']);
"WHERE parent_id = " . (int) $category_id);

$this->set_message($this->_t('CategoriesDeleted'), 'success');
$this->log(4, Ut::perc_replace($this->_t('LogCategoryRemoved', SYSTEM_LANG), $word['category']));
Expand All @@ -216,49 +219,49 @@
// add new item
if (isset($_POST['create']))
{
if (isset($_POST['change_id']) || isset($_POST['category_id']))
if ($change_id || $category_id)
{
$word = $this->db->load_single(
"SELECT category_id, parent_id, category " .
"FROM " . $this->db->table_prefix . "category " .
"WHERE category_id = " . (int) $_POST['change_id'] . " " .
"WHERE category_id = " . (int) $change_id . " " .
"LIMIT 1");

$parent_id = ($word['parent_id'] == 0 ? $word['category_id'] : $parent_id = $word['parent_id']);
}

$tpl->n_header = true;
$tpl->n_parentid = (int) $parent_id;
$tpl->n_category = (string) ($_POST['category'] ?? '');
$tpl->n_category = (string) $category;

if ($parent_id)
{
$tpl->n_p_category = $word['category'];
}
}
// rename item
else if (isset($_POST['rename']) && isset($_POST['change_id']))
else if (isset($_POST['rename']) && $change_id)
{
if ($word = $this->db->load_single(
"SELECT category, category_description
FROM " . $this->db->table_prefix . "category
WHERE category_id = " . (int) $_POST['change_id'] . "
WHERE category_id = " . (int) $change_id . "
LIMIT 1"))
{
$tpl->r_header = true;
$tpl->r_changeid = (int) $_POST['change_id'];
$tpl->r_changeid = (int) $change_id;
$tpl->r_newname = Ut::perc_replace($this->_t('CategoriesRename'), '<code>' . Ut::html($word['category']) . '</code>');
$tpl->r_category = ($_POST['category'] ?? $word['category']);
$tpl->r_description = ($_POST['category_description'] ?? $word['category_description']);
$tpl->r_category = ($category ?? $word['category']);
$tpl->r_description = ($category_description ?? $word['category_description']);
}
}
// (un)group item
else if (isset($_POST['ugroup']) && isset($_POST['change_id']))
else if (isset($_POST['ugroup']) && $change_id)
{
if ($word = $this->db->load_single(
"SELECT category_id, parent_id, category, category_lang
FROM " . $this->db->table_prefix . "category
WHERE category_id = " . (int) $_POST['change_id'] . "
WHERE category_id = " . (int) $change_id . "
LIMIT 1"))
{
$parents = $this->db->load_all(
Expand All @@ -270,7 +273,7 @@
"ORDER BY category ASC");

$tpl->g_header = true;
$tpl->g_changeid = (int) $_POST['change_id'];
$tpl->g_changeid = (int) $change_id;
$tpl->g_group = Ut::perc_replace($this->_t('CategoriesGroup'), '<code>' . Ut::html($word['category']) . '</code>');

foreach ($parents as $parent)
Expand All @@ -283,20 +286,20 @@
}

// delete item
else if (isset($_POST['delete']) && isset($_POST['change_id']) && $_POST['change_id'])
else if (isset($_POST['delete']) && $change_id)
{
if ($word = $this->db->load_single(
"SELECT category
FROM " . $this->db->table_prefix . "category
WHERE category_id = " . (int) $_POST['change_id'] . "
WHERE category_id = " . (int) $change_id . "
LIMIT 1"))
{
$tpl->d_header = true;
$tpl->d_changeid = (int) $_POST['change_id'];
$tpl->d_changeid = (int) $change_id;
$tpl->d_category = Ut::perc_replace($this->_t('CategoriesDelete'), '<code>' . Ut::html($word['category']) . '</code>');
}
}
else if (@$_POST && empty($_POST['change_id']))
else if (@$_POST && !$change_id)
{
// no record selected
$this->set_message($this->_t('NoCategorySelected'));
Expand Down

0 comments on commit d92be7c

Please sign in to comment.