%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/nailstv/public_html/include/
Upload File :
Create Path :
Current File : /home/nailstv/public_html/include/Db.class.php

<?php

define('ADODB_ASSOC_CASE', 2);

class Db
{
    function getInstance()
	{
		if (self::$instance === NULL)
		{
			self::$instance = new Db();

            require_once 'adodb/adodb.inc.php';
			require_once 'adodb/drivers/adodb-mysql.inc.php';

			self::$adodb = NewADOConnection(Registry::get('db_engine'));
			self::$adodb->Connect(Registry::get('db_host'), Registry::get('db_user'), Registry::get('db_pass'), Registry::get('db_name'));
			$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
			self::$adodb->debug = Registry::get('debug');
		}

        if($charset = Registry::get('db_charset'))
        {
			$sql = "SET NAMES '" . $charset . "'";
			self::$adodb->query($sql);
		}

        $sql = "set auto_increment_increment=1;";
        self::$adodb->query($sql);

		return  self::$instance;
	}

    function kdb($name, $debug = false)
    {
        require_once 'adodb/adodb.inc.php';
		require_once 'adodb/drivers/adodb-mysql.inc.php';

        $db = ADONewConnection(Registry::get($name . '_db_engine'));
        $db->SetFetchMode(ADODB_FETCH_ASSOC);
        $db->NConnect(Registry::get($name . '_db_host'), Registry::get($name . '_db_user'),
                Registry::get($name . '_db_pass'), Registry::get($name . '_db_name'));
        $db->debug = $debug;

        if($charset = Registry::get($name . '_db_charset')) {
    	    $sql = "SET NAMES '" . $charset . "'";
    		$db->query($sql);
    	}

        return $db;
    }

    function updateSorrend($s, $table)
    {
        asort ($s);
        reset ($s);
        $i = 10;
        foreach($s as $key => $val)
        {
            $sql = "UPDATE ".$table." SET sorrend='".$i."' WHERE id = '".$key."'";
            $this->query($sql);
            $i += 10;
        }
    }

    function select($id, $table)
    {
        settype($id, 'integer');
        $bind = array($id);

        $sql = "SELECT * 
                FROM ".$table." 
                WHERE id = ?";

        return $this->GetRow($sql, $bind);
    }

    function selectMultilang($id, $table)
    {
        settype($id, 'integer');
        $bind = array($id);

        $sql = "SELECT *
                FROM $table
                WHERE id = ?";
        $row = $this->GetRow($sql, $bind);

        $sql = "SELECT *
                FROM " . $table . "_detail
                WHERE " . $table . "_id = ?";
        $r = $this->Execute($sql, $bind);

        while(!$r->EOF)
        {
            $a = $r->fields['nyelv_azon'];
            foreach($r->fields as $key => $val)
            {
                $row[$a][$key] = $r->fields[$key];
            }
            $r->MoveNext();
        }

        //print_r($row); die;

        return $row;
    }

    function insert($rec, $table, $sorrend = false)
    {
        if($sorrend)
        {
            $rec['sorrend'] = $this->GetMaxSorrend($table) + 10;
        }

        return $this->AutoExecute($table, $rec, 'INSERT');
    }

    function insertMultilang($rec, $table, $sorrend = false)
    {
        $this->insert($rec, $table, $sorrend);

        $rec[$table.'_id'] = $rec['id'];

        unset($rec['id']);

        $langs = Lang::selectLang('GetAssoc');

        foreach($rec as $key => $val)
        {
            if(is_array($val))
            {
                array_walk($val, array('String', 'empty2null'));

                $val[$table.'_id'] = $rec[$table.'_id'];
                $val['nyelv_azon'] = $key;

                $this->insert($val, $table."_detail");
            }
        }
    }

    function update($rec, $table)
    {
        return $this->AutoExecute($table, $rec, 'UPDATE', 'id = ' . $rec['id']);
    }

    function updateMultilang($rec, $table)
    {
        $this->update($rec, $table);

        $rec[$table.'_id'] = $rec['id'];

        unset($rec['id']);

        $langs = Lang::selectLang('GetAssoc');

        foreach($rec as $key => $val)
        {
            if(is_array($val))
            {
                array_walk($val, array('String', 'empty2null'));

                $val[$table.'_id'] = $rec[$table.'_id'];
                $val['nyelv_azon'] = $key;

                $this->Replace($table.'_detail', $val, array($table.'_id', 'nyelv_azon'), true);
            }
        }
    }

    function delete($id, $table, $del = 0)
    {
        settype($id, 'integer');
        $bind = array($id);

        if($del)
        {
            $sql = "DELETE FROM ".$table." WHERE id = ?";
        }
        else
        {
            $sql = "UPDATE ".$table."
                    SET storno = 't'
                    WHERE id = ?";
        }
        return $this->query($sql, $bind);
    }

    function deleteMultiple($arr, $table, $del = 0)
    {
        if($del)
        {
            $sql = "DELETE FROM ".$table." WHERE id IN (".implode(',', array_keys($arr)).")";
        }
        else
        {
            $sql = "UPDATE $table SET
                    storno = 't'
                    WHERE id IN (".implode(',', array_keys($arr)).")";
        }
        return $this->query($sql);
    }

    function getMaxSorrend($table)
	{
		$sql = "SELECT MAX(sorrend) AS sorrend
				FROM ".$table."
				WHERE storno = 'f'";
		$row = $this->GetRow($sql);

        if(empty($row['sorrend'])) $row['sorrend'] = 0;

        return $row['sorrend'];
	}

    function selectTorzs($tipus, $l = 'hu', $method = 'GetAssoc')
    {
        $sql = "SELECT t.id, d.nev
                FROM torzs t
                LEFT JOIN torzs_detail d ON t.id = d.torzs_id AND t.tipus = '" . $tipus . "'
                WHERE t.storno = 'f'
                    AND d.nyelv_azon = '" . $l . "'
                ORDER BY t.sorrend";

        return $this->Execute($sql)->$method();
    }

    function joinLang($table, $alias, $lang, $alias2 = 'd')
    {
        $s = "
        LEFT JOIN " . $table . "_detail " . $alias2 . " ON  " . $alias2 . "." . $table . "_id = " . $alias . ".id
            AND  " . $alias2 . ".nyelv_azon = '$lang'
        LEFT JOIN " . $table . "_detail  " . $alias2 . "2 ON  " . $alias2 . "2." . $table . "_id = " . $alias . ".id
            AND  " . $alias2 . "2.nyelv_azon = '" . Registry::get('default_lang') . "'";
        return $s;
    }

    function joinDefPic($tipus, $alias)
    {
        $s = "LEFT JOIN kep k ON k.galeria_id = " . $alias . ".id AND k.tipus = '" . $tipus . "' AND k.def = 't'";
        return $s;
    }

    function keresesIndex($parent_id, $tipus, $cim, $text)
    {
        $rec['parent_id'] = $parent_id;
        $rec['tipus'] = $tipus;
        $rec['cim'] = $cim;

        foreach($text as $key => $val) {
            $text[$key] = strip_tags($val);
        }

        $rec['szoveg'] = implode(' ', $text);

        $this->Replace('kereses', $rec, array('parent_id', 'tipus'), true);
    }

    function __call($method, $args)
	{
		return call_user_func_array(array(self::$adodb, $method),$args);
	}

	function __get($property)
	{
		return self::$adodb->$property;
	}

	function __set($property, $value)
	{
		self::$adodb[$property] = $value;
	}

	private function __clone()
	{
	}

	static private $adodb = false;
	static private $instance = NULL;
}

?>

Zerion Mini Shell 1.0