<?php

class SystemMod extends DbMod{

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

  function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = '', $VarJoinOn = ''){
    $ArrSqlArray['SqlAll']['select'] = 's.system_key, s.*';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableSystem .' AS s';
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] = $VarWhere;
    }
    //
    $ArrSqlArray['SqlGetValue']['select'] = 'system_value';
    $ArrSqlArray['SqlGetValue']['from'] = $this->VarTableSystem .' AS s';
    if('' != $VarWhere){
      $ArrSqlArray['SqlGetValue']['where'] = 'system_key = "'. $VarWhere .'"';
    }
    //
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}

  function Edit($values){
    if(true === is_array($values) && 1 <= count($values)){
      $VarSql = "UPDATE ". $this->VarTableSystem ." SET 
                  system_value = ?,
                  system_date = ?
                WHERE system_key = '". $values['system_key'] ."'";
      $values = $this->PrepareData($values);
      $ArrData = array(
                  $values['system_value'],
                  $values['system_date']
                );
      $sth = $this->ArrMsSp->SP_DbConnect->prepare($VarSql);
      if (PEAR::isError($sth)) {
        die($sth->getMessage());
      }
      $res = $sth->execute($ArrData);
      if (PEAR::isError($res)) {
        die($res->getMessage());
      }
      return $values['system_id'];
    }
    else{
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
  }
  
  function PrepareData($values){
    if(true === is_array($values) && 1 <= count($values)){
      $values['system_date'] = date('YmdHis');
    }
    return $values;
  }
  
}
?>