<?php

class OrgMod extends DbMod{

	function OrgMod($ArrMsSp){
		parent::__construct($ArrMsSp);
		return true;
	}
	
	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = ''){
    $ArrSqlArray['SqlAll']['select'] = 'a.KOD, a.FNAME_'. $this->ArrMsSp->Sp_Lang .' AS FNAME';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableOrg .' AS a';
    $ArrSqlArray['SqlAll']['where'] = 'a.KOD in (select distinct KODOR FROM '. $this->VarTableObond .')';
    //$ArrSqlArray['SqlAll']['where'] = '';
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] .= ' AND '. $VarWhere;
    }
    if('' != $VarOrder){
      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlAll']['limit'] = $VarLimit;
    }
    ///
    $ArrSqlArray['SqlRow']['select'] = 'a.KOD, a.FNAME_'. $this->ArrMsSp->Sp_Lang .' AS FNAME';
    $ArrSqlArray['SqlRow']['from'] = $this->VarTableOrg .' AS a';
    $ArrSqlArray['SqlRow']['where'] = '';
    if('' != $VarWhere){
      $ArrSqlArray['SqlRow']['where'] = $VarWhere;
    }
    ///
    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
    $ArrSqlArray['SqlCount']['from'] = $this->VarTableOrg .' AS a';
    $ArrSqlArray['SqlCount']['where'] = 'a.KOD in (select distinct KODOR FROM '. $this->VarTableObond .')';
    //$ArrSqlArray['SqlCount']['where'] = '';
    if('' != $VarWhere){
      $ArrSqlArray['SqlCount']['where'] .= ' AND '. $VarWhere;
    }
    ///
    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}
}
?>