root / branches / 2.1.x / actions / DeleteCategory.php @ 1111

View | Annotate | Download (1.1 KB)

1
<?php
2
3
/*
4
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
5
* @license http://creativecommons.org/licenses/BSD/ BSD License
6
* @author Keyboard Monkeys Ltd.
7
* @since Sciret 1.2
8
* @package Sciret
9
* @packager Keyboard Monkeys
10
*/
11
12
require 'actions/Action.php';
13
14
class DeleteCategory extends Action {
15
16
    function dispatch() {
17
        $catId = isset($_GET['catId'])? (int)$_GET['catId'] : 0;
18
        $category = new Kb_Model_Category($catId);
19
        $parentId = $category->getParentId();
20
        if (!$category->getId()) {
21
            $_SESSION['message'] = $this->translate('Wrong category ID');
22
            Library::redirect(Library::getLink(array('view' => 'EditCategories')));
23
        }
24
25
        if (!$category->delete()) {
26
            $_SESSION['message'] = $this->translate('This category can\'t be deleted until its sub-categories are deleted');
27
            Library::redirect(Library::getLink(array('view' => 'MainView', 'catId' => $catId)));
28
        }
29
30
        $_SESSION['message'] = $this->translate('Category deleted successfully');
31
        Library::redirect(Library::getLink(array('view' => 'MainView', 'catId' => $parentId)));
32
    }
33
}
34
35
?>
36