<?
class admin_dialog_flash extends admin_dialog {

var $params = array("target", "mode", "page", "id");
var $itemsDir = "var/flash/";

    function makeData() {
        parent::makeData();
        $this->flash = func_new("flash", $this->id);

        if($this->mode == "edit") {
            $this->form_fields = $this->flash->row;
        }
    }


    function processFile() {
        $file = '';
        if(isset($_REQUEST[_FILE]['flash_file'])) {
            $p = pathinfo($_REQUEST[_FILE]['flash_file']['name']);
            $newName = time().".".$p["extension"];
            if(copy($_REQUEST[_FILE]['flash_file']['tmp_name'], $this->itemsDir.$newName)) {
                $file = $newName;
            }
        }
        return $file;
    }


    function action_update() {
        $item = func_new("flash", $this->id);
        $item->row["title"] = $_REQUEST["title"];
        if($file = $this->processFile()) {
            if(($item->row["file"] != "") && ($item->row["file"] != $file)) {
                @unlink($this->itemsDir.$item->row["file"]);
            }
            $item->row["file"] = $file;
        }
        $item->update();
    }


    function action_add() {
        $item = func_new("flash");
        $item->row["title"] = $_REQUEST["title"];
        $item->row["category_id"] = $_REQUEST["category_id"];
        $item->row["file"] = $this->processFile();
        $item->create();
    }


    function action_delete() {
        if(isset($_REQUEST["ids"]) && is_array($_REQUEST["ids"])) {
            foreach($_REQUEST["ids"] as $k => $v) {
                $w = func_new("flash", $k);
                @unlink($this->itemsPath.$w->row["file"]);
                $w->delete();
            }
        }
    }

}
?>