<?php
/*
	@ClassName : restSimakBmn
	@Copyright : PT Gamatechno Indonesia
	@Analyzed By : Dyan Galih
	@Author By : Didi Zuliansyah
	@Version : 01
	@StartDate : 2013-01-01
	@LastUpdate : 2013-01-01
	@Description : Class restSimakBmn
*/

class restSimakBmn extends Database
{
	protected $mSqlFile;

	function __construct ($connectionNumber=0){
		$this->mSqlFile = 'module/'.Dispatcher::Instance()->mModule.'/business/rest_simak_bmn.sql.php';
		parent::__construct($connectionNumber);
		//$this->setDebugOn();
	}
	
	function getTableList(){
		$table = array(
				"t_gol",
				"t_bid",
				"t_kel",
				"t_skel",
				"t_sskel",
				"t_upb",
				"t_ruang",
				"t_dir",
				"t_masteru"
				//,"t_masteru_master"
		);
		return $table;
	}
	
	function createDB(){
		$result =  $this->execute($this->mSqlQueries['create_db'],array());
		return $result;
	}
	
	# ========= FUNCTION BELOW USE CONNECTION 1 (gtaset_dbbmn)
	
	function dropTable(){
		$this->StartTrans();
		$sqlArr = explode(';',$this->mSqlQueries['drop_table']);
		foreach ($sqlArr as $sql){
			$result = $this->execute($sqlArr,array());
			if(!$result) break;
		}
		$this->EndTrans($result);
		return $result;
	}
	
	function createTable($data){
		if(!empty($data)){
			$this->dropTable();
			$result = $this->execute($data['create'],array());
		}
		return $result;
	}
	
	function insertTable($tableName,$data){
		# data format = 1,1,1|2,2,2|3,3,3
		if(!empty($tableName) && !empty($data)){
			$arrValue = explode('|',$data);
			$idx=0; $value = '';
			foreach($arrValue as $val){
				$value .= ($idx == 0) ? '("'.str_replace(',', '","', $val).'")' : ',("'.str_replace(',', '","', $val).'")';
				$idx++;
			}
			$sql = sprintf($this->mSqlQueries['insert_table'],$tableName,$value);
			$result = $this->execute($sql,array());
			
		}
		return $result;
	}
	
}
?>