Exemplo n.º 1
0
    /**
     * Delete category.
     *
     * @return null
     */
    protected function delete()
    {
        $parent_id = $this->category->parent_id == $this->category->category_id ? self::ROOT_CATEGORY : $this->category->parent_id;
        $error = array();
        if ($this->request->is_set_post('submit')) {
            if (check_form_key('category_move')) {
                $action_contribs = $this->request->variable('action_contribs', '');
                $contribs_to_id = $this->request->variable('contribs_to_id', 0);
                // Check for errors
                $sql = 'SELECT category_id
					FROM ' . TITANIA_CATEGORIES_TABLE . "\n\t\t\t\t\tWHERE parent_id = {$this->category->category_id}";
                $result = $this->db->sql_query($sql);
                $children_row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                // Check if category contains subcategories. If yes, then return an error.
                if ($children_row) {
                    $error[] = $this->user->lang['CATEGORY_HAS_CHILDREN'];
                } else {
                    if ($action_contribs == 'move' && !empty($contribs_to_id)) {
                        $error = array_merge($error, $this->category->move_category_content($contribs_to_id, $this->sync));
                    }
                }
            } else {
                $error[] = $this->user->lang['FORM_INVALID'];
            }
            if (empty($error)) {
                // Delete category
                $this->category->delete($this->sync);
                // Redirect back to the parent category
                redirect($this->helper->route('phpbb.titania.manage.categories', array('id' => $parent_id)));
            }
        }
        add_form_key('category_move');
        $this->template->assign_vars(array('S_DELETE_CATEGORY' => true, 'U_ACTION' => $this->category->get_manage_url('delete'), 'U_BACK' => $this->helper->route('phpbb.titania.manage.categories', array('id' => $parent_id)), 'CATEGORY' => $this->category->category_id, 'CATEGORY_NAME' => $this->category->get_name(), 'SECTION_NAME' => $this->user->lang['DELETE_CATEGORY'] . ' - ' . $this->category->get_name(), 'S_HAS_SUBCATS' => $this->category->right_id - $this->category->left_id > 1, 'S_MOVE_CATEGORY_OPTIONS' => generate_category_select($this->category->parent_id, true), 'ERROR_MSG' => !empty($error) ? implode('<br />', $error) : ''));
    }
Exemplo n.º 2
0
        $error = array();
        if ($submit) {
            $action_contribs = request_var('action_contribs', '');
            $contribs_to_id = request_var('contribs_to_id', 0);
            // Check for errors
            $sql = 'SELECT category_id
				FROM ' . TITANIA_CATEGORIES_TABLE . "\n\t\t\t\tWHERE parent_id = {$category_object->category_id}";
            $result = phpbb::$db->sql_query($sql);
            $children_row = phpbb::$db->sql_fetchrow($result);
            phpbb::$db->sql_freeresult($result);
            // Check if category contains subcategories. If yes, then return an error.
            if ($children_row) {
                $error[] = phpbb::$user->lang['CATEGORY_HAS_CHILDREN'];
            } else {
                if ($action_contribs == 'move' && !empty($contribs_to_id)) {
                    $error = array_merge($error, $category_object->move_category_content($contribs_to_id));
                }
            }
            if (!sizeof($error)) {
                // Delete category
                $category_object->delete();
                // Redirect back to the previous category
                redirect(titania_url::build_url('manage/categories', array('c' => $parent_id)));
            }
        }
        phpbb::$template->assign_vars(array('S_DELETE_CATEGORY' => true, 'U_ACTION' => titania_url::build_url('manage/categories', array('c' => $category_id, 'action' => 'delete')), 'U_BACK' => 'c_' . $category_object->parent_id, 'CATEGORY' => $category_id, 'CATEGORY_NAME' => isset(phpbb::$user->lang[$category_object->category_name]) ? phpbb::$user->lang[$category_object->category_name] : $category_object->category_name, 'SECTION_NAME' => phpbb::$user->lang['DELETE_CATEGORY'] . ' - ' . (isset(phpbb::$user->lang[$category_object->category_name]) ? phpbb::$user->lang[$category_object->category_name] : $category_object->category_name), 'S_HAS_SUBCATS' => $category_object->right_id - $category_object->left_id > 1 ? true : false, 'S_MOVE_CATEGORY_OPTIONS' => generate_category_select($category_object->parent_id, true), 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : ''));
        break;
    default:
        titania::_include('functions_display', 'titania_display_categories');
        titania_display_categories($category_id, 'categories', true);
        if ($category_id != 0) {