<?
class admin_dialog_flash_categories extends admin_dialog {


var $params = array("target", "id", "mode");
     

    function makeData() {
        parent::makeData();
        $this->category = func_new("flash_category", $this->id);
        $this->path = $this->category->getPath();
        $this->subCategories = $this->category->getSubCategories();
        $this->form_fields = $this->category->row;
        if(!empty($this->id)) {
            $this->tree = $this->category->getTree();
        }
    }



    function action_new_category() {
        $category = func_new("flash_category", $this->id);
        $sub = $category->createSubCategory($_REQUEST["nc_name"]);
        $sub->row["description"] = $_REQUEST["nc_description"];
        $sub->update();
    }


    function action_edit_category() {
        $category = func_new("flash_category", $this->id);
        $category->row["name"] = $_REQUEST["name"];
        $category->row["description"] = $_REQUEST["description"];
        $category->update();
    }


    function action_delete_category() {
        if(isset($_REQUEST["new_category_id"])) {
            $sql = "UPDATE "._DB_TABLE_PREFIX."flash SET category_id = %to% WHERE category_id = %from%";
            $this->db->query($sql, array("from"=>$this->id, "to"=>$_REQUEST["new_category_id"]) );
            $category = func_new("flash_category", $this->id);
            $category->delete();
        }
    }

}
?>