<?
class module extends controller {

    var $params = array("act");

    var $themes_dir = "themes/";

    function run() {
        switch($this->act) {
            case "change_pwd":
                if(isset($_REQUEST["npwd"])) {
                    $npwd = addslashes($_REQUEST["npwd"]);
                    $sql = "
                        UPDATE
                            "._DB_TABLE_PREFIX."users 
                        SET
                            password='".$npwd."'
                        WHERE
                            id = '".$this->user_id."'";
                    $res = $this->db->query($sql);                            
                    return array("status" => "pwd_changed", "npwd" => $npwd);
                }
                break;

            case "get_themes":
                $themes = null;
                $dh = opendir($this->themes_dir);
                while (($dir = readdir($dh)) !== false) {
                    if(($dir != ".") && ($dir != "..") && is_dir($this->themes_dir.$dir)) {
                        $description = "";
                        $lng_fname = $this->themes_dir.$dir."/description.tpl";
                        if(file_exists($lng_fname)) {
                            $description = file_get_contents($lng_fname);
                        }
                        $themes[] = array("name" =>$dir,
                                          "description" => str_replace("\r\n", "", $description));
                    }
                }
                return array("status" => "themes_list",
                             "data"   => $themes);
                break;


            default:
                return array("status" => "not_found");
                break;
        }

    }

}
?>