<?php

class TerminMod extends DbMod{

	function TerminMod($ArrMsSp){
		parent::__construct($ArrMsSp);
		return true;
	}
	
	function GetFromDb($VarSqlName = 'SqlAll', $VarSqlGet = 'GetAll', $VarWhere = '', $VarOrder = '', $VarLimit = ''){
    $ArrSqlArray['SqlAll']['select'] = 'a.TERMIN_SHORT, a.TERMIN_FULL, a.TERMIN_DEF, b.OND_'. $this->ArrMsSp->Sp_Lang .' AS OND,  a.TERMIN_ID, b.IDGLOBAL, b.RN';
    $ArrSqlArray['SqlAll']['from'] = $this->VarTableTermin .' AS a, '. $this->VarTableObond .' AS b';
    $ArrSqlArray['SqlAll']['where'] = 'a.IDGLOBAL = b.IDGLOBAL';
    if('' != $VarWhere){
      $ArrSqlArray['SqlAll']['where'] .= ' AND ' .$VarWhere;
    }
//    if('' != $VarOrder && true === is_numeric($VarOrder)){
//      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
//    }
    if('' != $VarOrder){
      $ArrSqlArray['SqlAll']['order'] = $VarOrder;
    }
    if('' != $VarLimit){
      $ArrSqlArray['SqlAll']['limit'] = $VarLimit;
    }
///
    $ArrSqlArray['SqlCount']['select'] = 'count(*) AS vartotal';
    $ArrSqlArray['SqlCount']['from'] = $this->VarTableTermin .' AS a, '. $this->VarTableObond .' AS b';
    $ArrSqlArray['SqlCount']['where'] = 'a.IDGLOBAL = b.IDGLOBAL';
    if('' != $VarWhere){
      $ArrSqlArray['SqlCount']['where'] .= ' AND ' .$VarWhere;
    }
///
    $ArrSqlArray['SqlRow']['select'] = 'a.*, b.IDGLOBAL, b.RN, b.OND_'. $this->ArrMsSp->Sp_Lang .' AS OND';
    $ArrSqlArray['SqlRow']['from'] = $this->VarTableTermin .' AS a';
    $ArrSqlArray['SqlRow']['leftjoin'] = $this->VarTableObond .' AS b ON a.IDGLOBAL = b.IDGLOBAL';
    if('' != $VarWhere){
      $ArrSqlArray['SqlRow']['where'] = $VarWhere;
    }
///
    $ArrSqlArray['SqlLetter']['select'] = 'distinct substring(upper(a.TERMIN_FULL), 1, 1) as letter';
    $ArrSqlArray['SqlLetter']['from'] = $this->VarTableTermin .' AS a, '. $this->VarTableObond .' AS b';
    $ArrSqlArray['SqlLetter']['where'] = 'a.IDGLOBAL = b.IDGLOBAL';
//    $ArrSqlArray['SqlLetter']['where'] = "a.TERMIN_FULL is not null AND a.TERMIN_FULL !=''";
//    $ArrSqlArray['SqlLetter']['groupby'] = 'a.TERMIN_FULL';
    $ArrSqlArray['SqlLetter']['order'] = 'letter';
//  select  from TERMIN a
//  group by TERMIN_FULL order by letter

    $ArrResult = $this->DbGet($ArrSqlArray[$VarSqlName], $VarSqlGet);
  	return $ArrResult;
	}

  function GetTerminCommon($VarId = ''){
    if('' != $VarId && true === is_numeric($VarId)){
      $ArrResult = $this->GetFromDb('SqlAll', 'GetRow', "a.CERTIF_ID = '". $_GET['UrlId'] ."'");
      //SiteLibs::GetVarDump($ArrResult);
			return array('ArrResult' => $ArrResult);
    }
    else {
      return array('error' => $this->ArrMsSp->Sp_LangMessage['error']['ErrSettingWrong']);
    }
  }
} 
?>