<?php

class UsersCardMod extends DbMod{
  var $VarTableUsersCardTypes = array('integer', 'integer', 'integer');

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

	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = ''){
    $ArrSqlArray['SqlAll']['select'] = 'a.*';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableUsersCard .' AS a';
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] = $VarWhere;
    }
    if('' != $VarOrder){
      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlAll']['limit'] = $VarLimit;
    }
    ///
    $ArrSqlArray['SqlRow']['select'] = 'a.*';
    $ArrSqlArray['SqlRow']['from'] = $this->VarTableUsersCard .' AS a';
    if('' != $VarWhere){
      $ArrSqlArray['SqlRow']['where'] = $VarWhere;
    }
    ///
    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
    $ArrSqlArray['SqlCount']['from'] = $this->VarTableUsersCard .' AS a';
    if('' != $VarWhere){
      $ArrSqlArray['SqlCount']['where'] = $VarWhere;
    }
    ///
    $ArrSqlArray['SqlOne']['select'] = 'a.idglobal';
    $ArrSqlArray['SqlOne']['from'] = $this->VarTableUsersCard .' AS a';
    if('' != $VarWhere){
      $ArrSqlArray['SqlOne']['where'] = $VarWhere;
    }
    ///
    $ArrSqlArray['SqlId']['select'] = 'a.userscard_id';
    $ArrSqlArray['SqlId']['from'] = $this->VarTableUsersCard .' AS a';
    if('' != $VarWhere){
      $ArrSqlArray['SqlId']['where'] = $VarWhere;
    }
    ///
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;

	}

  function Add($VarId = '', $VarUserId = ''){
    if ('' != $VarId && true === is_numeric($VarId) && '' != $VarUserId){
      $VarNextId = $this->ArrMsSp->SP_DbConnect->lastInsertID($this->VarTableUsersCard, 'userscard_id');
      if (PEAR::isError($VarNextId)) {
        die($VarNextId->getMessage());
      }
      $sth = $this->ArrMsSp->SP_DbConnect->prepare('INSERT INTO '. $this->VarTableUsersCard .' VALUES (?, ?, ?)', $this->VarTableUsersCardTypes, MDB2_PREPARE_MANIP);
      $data = array($VarNextId, $VarId, $VarUserId);
      $result = $sth->execute($data);
			if (PEAR::isError($result)) {
   			die($result->getMessage());
			}
      return true;
    }
    else {
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
	}

  function DelIdglobalUsersId($VarIdglobal = '', $VarUsersId = ''){
    if('' != $VarIdglobal && true === is_numeric($VarIdglobal) && '' != $VarUsersId && true === is_numeric($VarUsersId)){
      $sql = "DELETE FROM ". $this->VarTableUsersCard ." WHERE idglobal = '". $VarIdglobal ."' AND users_id = '". $VarUsersId ."'";
      //echo "sql: ". $sql ."<br />";
      $VarResult =& $this->ArrMsSp->SP_DbConnect->exec($sql);
      if (PEAR::isError($VarResult)) {
        die($VarResult->getMessage());
      }
      return true;
    }
    else {
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
	}

  function Del($VarId = '', $VarFiledName = 'userscard_id'){
    if('' != $VarId && true === is_numeric($VarId)){
      $sql = "DELETE FROM ". $this->VarTableUsersCard ." WHERE ". $VarFiledName ." = '". $VarId ."'";
      //echo "sql: ". $sql ."<br />";
      $VarResult =& $this->ArrMsSp->SP_DbConnect->exec($sql);
      if (PEAR::isError($VarResult)) {
        die($VarResult->getMessage());
      }
      return true;
    }
    else {
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
	}
}
?>