<?
class controller {

    var $isNeedMysql = true;
    var $isNeedSession = true;
    var $user_id = false;
    var $params = array();



    function init() {
        global $db;
        $error = false;
        foreach($this->params as $p) {
            if(!isset($_REQUEST[$p])) {
                $error = true;
                continue;
            } else {
                $this->$p = $_REQUEST[$p];
            }
        }

        if($error) die;

        if($this->isNeedMysql) {
            require_once("core/mysql.php");
            $this->db = new mysql_db();
            if(!$this->db->connect(_DB_HOST, _DB_NAME, _DB_USER, _DB_PASS)) {
                die("DB connection error.");
            }
        }

        if($this->isNeedSession) {
            session_start();
            $this->user_id = $_SESSION["user_id"];
        }
    }



    function run() {}



    function done() {
        if($this->isNeedMysql) {
            $this->db->connectClose();    
        }
    }

}
?>