<?php
class SvtStatusValMod extends DbMod{
  var $VarTableSvtStatusValTypes = array('integer', 'integer', 'integer');

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

	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = ''){
    /*** begin default values ***/
    $ArrSqlArray['SqlAll']['select'] = 'a.*, ss.svtstatus_name';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableSvtStatusVal .' AS a, '. $this->VarTableSvtStatus .' AS ss';
    $ArrSqlArray['SqlAll']['where'] = 'a.svtstatus_id = ss.svtstatus_id';
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] .= ' AND '. $VarWhere;
    }
    if('' != $VarOrder){
      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlAll']['limit'] = $VarLimit;
    }
    /*** end default values ***/
    ///
    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
    $ArrSqlArray['SqlCount']['from'] = $this->VarTableSvtStatusVal .' AS a, '. $this->VarTableSvtStatus .' AS ss';
    $ArrSqlArray['SqlCount']['where'] = 'a.svtstatus_id = ss.svtstatus_id';
    if('' != $VarWhere){
      $ArrSqlArray['SqlCount']['where'] .= ' AND '. $VarWhere;
    }
    ///
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}

   function Add($values){
    if(true === is_array($values) && 0 < count($values)){
      $VarSql = 'INSERT INTO '. $this->VarTableSvtStatusVal .'
                (svtstatusval_id, svt_id, svtstatus_id)
                VALUES (?, ?, ?)';
      $sth = $this->ArrMsSp->SP_DbConnect->prepare($VarSql, $this->VarTableSvtStatusValTypes, MDB2_PREPARE_MANIP);
      $values = $this->PrepareData($values);
      $ArrData = array(
        '',
        $values['svt_id'],
        $values['svtstatus_id']
      );
      //SiteLibs::GetVarDump($data);
      $VarQueryResult = $sth->execute($ArrData);
      if(PEAR::isError($VarQueryResult)) {
        return array('error' => $VarQueryResult->getMessage());
      }
      $VarId = $this->ArrMsSp->SP_DbConnect->lastInsertID($this->VarTableSvtStatusVal, 'svtstatusval_id');
      if (PEAR::isError($VarId)) {
        return array('error' => $VarId->getMessage());
      }
      return $VarId;
    }
    else{
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
  }

  function Edit($values){
    if(true === is_array($values) && 0 < count($values)){
      $VarSql = "UPDATE ". $this->VarTableSvtStatusVal ." SET
                  svt_id = ?,
                  svtstatus_id = ?
                  WHERE svtstatusval_id = '".  $values['svtstatusval_id'] ."'";
      $values = $this->PrepareData($values);
      $ArrData = array(
        $values['svt_id'],
        $values['svtstatus_id']
      );
      $sth = $this->ArrMsSp->SP_DbConnect->prepare($VarSql, $this->VarTableSvtStatusValTypes, MDB2_PREPARE_MANIP);
      $VarQueryResult = $sth->execute($ArrData);
      if(PEAR::isError($VarQueryResult)) {
        return array('error' => $VarQueryResult->getMessage());
      }
      return $values['svtstatusval_id'];
    }
    else{
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
  }

  function Del($VarId = '', $VarFiledName = 'svtstatusval_id'){
    if('' != $VarId && true === is_numeric($VarId)){
      $sql = "DELETE FROM ". $this->VarTableSvtStatusVal ." WHERE ". $VarFiledName ." = '". $VarId ."'";
      //echo "sql: ". $sql ."<br />";
      $VarQueryResult = $this->ArrMsSp->SP_DbConnect->exec($sql);
      if (PEAR::isError($VarQueryResult)) {
        return array('error' => $VarQueryResult->getMessage());
      }
      return true;
    }
    else {
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
	}
  
  function PrepareData($values){
    if(true === is_array($values) && 0 < count($values)){
      $values['svt_id'] = SiteLibs::ConvertSqlIntegerInsert($values['svt_id']);
      $values['svtstatus_id'] = SiteLibs::ConvertSqlIntegerInsert($values['svtstatus_id']);
    }
    return $values;
  }
}
?>