<?php
 
/*
 * DataTables example server-side processing script.
 *
 * Please note that this script is intentionally extremely simply to show how
 * server-side processing can be implemented, and probably shouldn't be used as
 * the basis for a large complex system. It is suitable for simple use cases as
 * for learning.
 *
 * See http://datatables.net/usage/server-side for full details on the server-
 * side processing requirements of DataTables.
 *
 * @license MIT - http://datatables.net/license_mit
 */
 
include_once ("includes/setup.inc.php");	
//*****************************************************
//Get all POST and GET value
//*****************************************************
$sqlOnly = fetch_postget_val('sqlOnly',$_POST, $_GET);
$appointment = fetch_postget_val('appointment',$_POST, $_GET);

//*****************************************************
// MAIN TABLE AND JOIN TABLE
// main = main table name in the database,
// sub['name'] = join table name
// sub['sub_id'] = join table identifier
// sub['main_id'] = main table identifier
// sub['join_type'] = type of join. Default = 'LEFT'
// sub['aka'] = put alternative name for table
//*****************************************************
$script_base = 'pht_listjanji';
$tableArray = array(
	'main' => 'm_appointment_ubat',
	'primary_key' => 'id_appointment_ubat',
	'sub' => array(
		array('name' => 'i_ubat', 'sub_id' => 'id_ubat', 'main_id' => 'id_ubat'),
	),
);

//*****************************************************
// DATATABLE COLUMN
// db = column name in the database,
// dt = DataTables column identifier
// table = database table name
// akaFrom = use if and only if there is aka name for table
//*****************************************************
$columns = array(
    array( 'user_defined' => '', 'dt' => 0),
    array( 'db' => 'desk_ubat', 'dt' => 1, 'table' => 'i_ubat' ),
    array( 'db' => 'quantity', 'dt' => 2, 'table' => 'm_appointment_ubat' ),
    array( 'db' => 'ubat_remarks', 'dt' => 3, 'table' => 'm_appointment_ubat' ),
	array( 'dt' => 4, 
	'user_defined' => 
	''
	),
);

//*****************************************************
// WHERE SQL
// Array ($table_name, $column_name, $value, $symbol(default : '='))
//*****************************************************
$usr_id_sys = $my_details->usr_id_sys;
$usr_id = $my_details->usr_id;

$whereArray = array(

	array('m_appointment_ubat', 'id_vatklinik_appointment', $appointment)
	
);	

//echo SSP::myComplex($_POST, $sql_details, buildSelectQuery($columns), buildFromQuery($tableArray), $tableArray['main'].'.'.$tableArray['primary_key'], $columns, 1, buildWhereQuery($whereArray));
//echo "whereArray = ".count($whereArray);
//exit(0);
//*****************************************************
// SSP GET JSON
// No need to modify below
//*****************************************************
if($sqlOnly == 1)
{
	//LEAVE EMPTY FOR FUTURE USAGE 
}
else
{	
	$temp_result = SSP::myComplex($_POST, $sql_details, buildSelectQuery($columns), buildFromQuery($tableArray), $tableArray['main'].'.'.$tableArray['primary_key'], $columns, 0, buildWhereQuery($whereArray));
	
	/*
	for($num = 0; $num < count($temp_result['data']); $num++)
	{
		$label_style = $temp_result['data'][$num][11];	
		
		$temp_result['data'][$num][8] = '<span class="label label-xl label-warning label-pill label-inline mr-2" style="'.$label_style.'">'.$temp_result['data'][$num][10].'</span>';
	}
	*/
	echo json_encode(
		$temp_result
	);
}