<?php
class ClassConfig implements InterfacePostgreSQL, InterfaceConfig {
  private $_urlRewrite = false;
  
  public function __construct(){}
  public function __destruct(){}
  
  public function databaseConnect(){
    try {
      $oPDOLink = new PDO("pgsql:host=".InterfacePostgreSQL::PG_SERVER.";port=".InterfacePostgreSQL::PG_PORT.";dbname=".InterfacePostgreSQL::PG_DBNAME.";user=".InterfacePostgreSQL::PG_USER.";password=".InterfacePostgreSQL::PG_PASSWORD); //, array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET NAMES utf8")
      return $oPDOLink;
    } catch( PDOException $Exception ) {
      // PHP Fatal Error. Second Argument Has To Be An Integer, But PDOException::getCode Returns A
      // String.
      //throw new MyDatabaseException( $Exception->getMessage( ) , (int)$Exception->getCode( ) );
      echo($Exception->getMessage());
    }
  }
	
  public function foreignDatabaseConnect($host=InterfacePostgreSQL::PG_FOREIGN_SERVER,
                                         $dbname=InterfacePostgreSQL::PG_FOREIGN_DBNAME,
                                         $user=InterfacePostgreSQL::PG_FOREIGN_USER,
                                         $password=InterfacePostgreSQL::PG_FOREIGN_PASSWORD
  ){
    try {
      $oPDOLink = new PDO("pgsql:host=".$host.";dbname=".$dbname.";user=".$user.";password=".$password); //, array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET NAMES utf8")
      return $oPDOLink;
    } catch( PDOException $Exception ) {
      // PHP Fatal Error. Second Argument Has To Be An Integer, But PDOException::getCode Returns A
      // String.
      //throw new MyDatabaseException( $Exception->getMessage( ) , (int)$Exception->getCode( ) );
      echo($Exception->getMessage());
    }
  }
	
    public function getURLRoot($post_url=''){
        $this->_postURL=$post_url;
        return ($this->_postURL!='')?InterfaceConfig::URL_ROOT.$this->_postURL:InterfaceConfig::URL_ROOT;
    }
    
    public function getURLScript($post_url=''){
        $this->_postURL=$post_url;
        return ($this->_postURL!='')?InterfaceConfig::URL_SCRIPT.$this->_postURL:InterfaceConfig::URL_SCRIPT;
    }
    
    public function getConfig(){
        $oPDOLink = ClassConfig::databaseConnect();
        $rowsConfig = array();
        $sql="
        SELECT *
        FROM core_config
        WHERE is_active=TRUE
        ";
        $execSQL = $oPDOLink->prepare($sql);
        $execSQL->execute(array());
        $rows = $execSQL->fetchAll(PDO::FETCH_ASSOC);
        foreach($rows as $k=>$v){
            $rowsConfig[$rows[$k]['k']] = $rows[$k]['v'];
        }
        return $rowsConfig;
    }
}
