<?php

class ConfigMod extends DbMod{
  var $VarTableConfigTypes = array('text', 'text', 'text', 'integer');

	function ConfigMod($ArrMsSp){
    parent::__construct($ArrMsSp);    
		return true;
	}

	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = ''){
    $ArrSqlArray['SqlAll']['select'] = 't1.*';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableConfig .' AS t1';
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] = $VarWhere;
    }
    if('' != $VarOrder){
      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlAll']['limit'] = $VarLimit;
    }
    ///
    $ArrSqlArray['SqlAssoc']['select'] = 't1.config_var, t1.config_value';
    $ArrSqlArray['SqlAssoc']['from'] = $this->VarTableConfig .' AS t1';
    //
    //if ('SqlNdMksCount' == $VarSqlName){
      //echo "sql: ". $sql. "<br />";
    //}

    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}
  
  function Edit($values){
    if(true === is_array($values) && 0 < count($values)){
      foreach ($values as $key => $value) {
        $VarSql = "UPDATE ". $this->VarTableConfig ." 
                  SET config_value = '". $value ."'
                  WHERE config_var = '".  $key ."'";
        $ArrData = $this->PrepareData($value);
        $sth = $this->ArrMsSp->SP_DbConnect->prepare($VarSql);
        $VarQueryResult = $sth->execute($ArrData);
        if (PEAR::isError($VarQueryResult)) {
          return array('error' => $VarQueryResult->getMessage());
        }
      }
      return true;
    }
    else {
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
  }
  
  function PrepareData($value){
    return SiteLibs::ConvertTextToSql($value);
  }
}
?>