<?
class admin_dialog_users extends admin_dialog {

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


    function makeData() {
        parent::makeData();

        if(isset($_REQUEST["id"])) {
            $this->user = func_new("user", $this->id);
        }  
        
        if($this->user->row === false) {
            $this->user = false;
        }

        $semail = trim($_REQUEST["semail"]);
        if(strlen($semail) > 2) {
            $this->isSearch = true;
            $this->form_fields["semail"] = $semail;
        }


        if($this->mode == "edit") {
            $this->form_fields["u_email"] = $this->user->row["email"];
            $this->form_fields["u_pwd"] = $this->user->row["password"];
        }
    }



    function action_update() {
        $item = func_new("user", $this->id);
        $item->row["email"] = $_REQUEST["u_email"];
        $item->row["password"] = $_REQUEST["u_pwd"];
        $item->update();
    }


    function action_add() {
        $item = func_new("user");
        $item->row["email"] = $_REQUEST["u_email"];
        $item->row["password"] = $_REQUEST["u_pwd"];
        $item->create();
    }


    function action_delete() {
        if(isset($_REQUEST["ids"]) && is_array($_REQUEST["ids"])) {
            foreach($_REQUEST["ids"] as $k => $v) {
                $w = func_new("user", $k);
                $w->delete();

                $sql = "
                    DELETE FROM 
                        "._DB_TABLE_PREFIX."profiles
                    WHERE
                         user_id = %id%";
                $this->db->query($sql, $k);
            }
        }
    }

}
?>