<?php

class UserDocTypeMod extends DbMod{
  var $VarTableUserDocTypeTypes = array('integer', 'integer', 'text');

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

	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = ''){
    /*** begin default values ***/
    $ArrSqlArray['SqlAll']['select'] = 'a.*';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableUserDocType .' AS a';
    $ArrSqlArray['SqlAll']['where'] = '';
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] = $VarWhere;
    }
    if('' != $VarOrder){
      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlAll']['limit'] = $VarLimit;
    }
    /*** end default values ***/
    ///
//    $ArrSqlArray['SqlRow']['select'] = 'a.*';
//    $ArrSqlArray['SqlRow']['from'] = $this->VarTableUserDocType .' AS a';
//    $ArrSqlArray['SqlRow']['where'] = '';
//    if('' != $VarWhere){
//      $ArrSqlArray['SqlRow']['where'] = $VarWhere;
//    }
    ///
    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
    $ArrSqlArray['SqlCount']['from'] = $this->VarTableUserDocType .' AS a';
    $ArrSqlArray['SqlCount']['where'] = '';
    if('' != $VarWhere){
      $ArrSqlArray['SqlCount']['where'] = $VarWhere;
    }
    ///
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;  	
	}
  
  function Add($values){
    if(true === is_array($values) && 0 < count($values)){
      $VarSql = 'INSERT INTO '. $this->VarTableUserDocType .'
                (userdoctype_id, organiz_id, userdoctype_name)
                VALUES (?, ?, ?)';
      $sth = $this->ArrMsSp->SP_DbConnect->prepare($VarSql, $this->VarTableUserDocTypeTypes, MDB2_PREPARE_MANIP);
      $ArrData = array(
        '',
        $values['organiz_id'],
        $values['userdoctype_name']
      );
      //SiteLibs::GetVarDump($data);
      $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 Edit($values){
    if(true === is_array($values) && 0 < count($values)){
      $VarSql = "UPDATE ". $this->VarTableUserDocType ." SET
                  userdoctype_name = '". SiteLibs::ConvertTextToSql($values['userdoctype_name']) ."'
                WHERE userdoctype_id ='".  $values['userdoctype_id'] ."'";
      //echo "VarSql: ". $VarSql ."<br />";
      $res =& $this->ArrMsSp->SP_DbConnect->query($VarSql);
      if (PEAR::isError($res)) {
        die($res->getMessage());
      }
      return true;
    }
    else{
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
  }

  function Del($VarId = '', $VarFiledName = 'userdoctype_id'){
    if('' != $VarId && true === is_numeric($VarId)){
      $sql = "DELETE FROM ". $this->VarTableUserDocType ." 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']);
    }
	}
}
?>