<?
class module extends controller {

    var $params = array("act");



    function run() {
        switch($this->act) {
            case "get_flash_category":
                if(isset($_REQUEST["cat_id"])) {
                    $cat_id = getSafeStr($_REQUEST["cat_id"]);

                    $result = array();

                    if($cat_id != "") {
                        $cat = $this->db->query("SELECT * FROM "._DB_TABLE_PREFIX."flash_categories WHERE id = '".$cat_id."'");

                        $result["cat_id"] = $cat_id;
                        if($cat) {
                            $result["categories"] = $this->db->query("SELECT 
                                                                          id, name
                                                                      FROM 
                                                                          "._DB_TABLE_PREFIX."flash_categories
                                                                      WHERE
                                                                          left_key >= ".$cat["left_key"]." AND
                                                                          right_key < ".$cat["right_key"]." AND
                                                                          level = ".$cat["level"]." + 1
                                                                      ORDER BY left_key");
                        } else {
                            $result["categories"] = $this->db->query("SELECT 
                                                                          id, name
                                                                      FROM 
                                                                          "._DB_TABLE_PREFIX."flash_categories
                                                                      WHERE
                                                                          level = 1
                                                                      ORDER BY left_key");
                        }

                        if(isset($result["categories"]["id"])) {
                            $result["categories"] = array($result["categories"]);
                        }

                        $result["items"] = $this->db->query("SELECT
                                                                 id, title, file
                                                             FROM
                                                                 "._DB_TABLE_PREFIX."flash
                                                             WHERE
                                                                 category_id = ".$cat_id);
                        if(isset($result["items"]["id"])) {
                            $result["items"] = array($result["items"]);
                        }

                        $result["status"] = "flash_category_data";
                    } else {
                        $result["status"] = "flash_empty_cat_id";
                    }
                } else {
                    $result["status"] = "empty_cat_id";
                }
                return $result;
                break;
        }
    }

}
?>
