/** * Get the first category */ public function first_category() { $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT * FROM " . $db->prefix("mch_categories") . " ORDER BY id_cat LIMIT 0,1"; $result = $db->query($sql); if ($db->getRowsNum($result) <= 0) { return false; } while ($row = $db->fetchArray($result)) { $cat = new MCHCategory(); $cat->assignVars($row); return $cat; } }
/** * Deleting a category */ function m_delete_category() { global $xoopsModule, $xoopsSecurity; $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0; $ok = isset($_POST['ok']) ? intval($_POST['ok']) : 0; //Verificamos que nos hayan proporcionado una categoría para eliminar if (!is_array($ids) && $ids <= 0) { redirectMsg('./categories.php', __('No categories selected!', 'match'), 1); die; } if (!is_array($ids)) { $catego = new MCHCategory($ids); $ids = array($ids); } if (!$xoopsSecurity->check()) { redirectMsg('./categories.php', __('Session token expired!', 'match'), 1); die; } $db = XoopsDatabaseFactory::getDatabaseConnection(); $errors = ''; foreach ($ids as $k) { //Verificamos si la categoría es válida if ($k <= 0) { $errors .= sprintf(__('Category id "%s" is not valid!', 'match'), $k); continue; } //Verificamos si la categoría existe $cat = new MCHCategory($k); if ($cat->isNew()) { $errors .= sprintf(__('Category "%s" does not exists!', 'match'), $k); continue; } RMEvents::get()->run_event('match.delete.category', $cat); if (!$cat->delete()) { $errors .= sprintf(__('Category "%s" could not be deleted!', 'match'), $k); } else { $sql = "UPDATE " . $db->prefix('mch_categories') . " SET parent='" . $cat->getVar('parent') . "' WHERE parent='" . $cat->id() . "'"; $result = $db->queryF($sql); } } if ($errors != '') { redirectMsg('./categories.php', __('Errors ocurred while trying to delete categories', 'match') . '<br />' . $errors, 1); die; } else { redirectMsg('./categories.php', __('Database updated successfully!', 'match'), 0); die; } }