<?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);

//*****************************************************
// 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
//*****************************************************
$tableArray = array(
	'main' => 'i_banner',
	'primary_key' => 'id_banner',
);

//*****************************************************
// 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' => 'tajuk', 'dt' => 1, 'table' => 'i_banner' ),
    array( 'db' => 'tajuk_butang', 'dt' => 2, 'table' => 'i_banner' ),
    array( 'db' => 'hyperlink', 'dt' => 3, 'table' => 'i_banner' ),
    array( 
			'db' => 'aktif', 'dt' => 4, 'table' => 'i_banner' ,
			'formatter' => function( $d, $row ) {
					 return ($d == 1?'YA':'TIDAK');
				}
	),
	array( 'dt' => 5, 
	'user_defined' => 
	'
	<a class="btn btn-sm btn-clean btn-icon mr-2" onclick="loadMyModal(\'in_banner-tambah.php?id=%i_banner.id_banner%\', \'#ajax-modal\')" title="Edit">
		<span class="svg-icon svg-icon-primary svg-icon-2x">'.$Edit_svg.'</span>
	</a>
	<a class="btn btn-sm btn-clean btn-icon mr-2" id="deleteBtn" title="Aktif" onclick="deleteFunction(%i_banner.id_banner%, \'%i_banner.tajuk%\')">
		<span class="svg-icon svg-icon-danger svg-icon-2x">'.$Minus_svg.'</span>
	</a>'
	),
    array( 'db' => 'id_banner', 'dt' => 6, 'table' => 'i_banner' ),
);

//*****************************************************
// WHERE SQL
// Array ($table_name, $column_name, $value, $symbol(default : '='))
//*****************************************************
$whereArray = array(

); 

//echo SSP::myComplex($_POST, $sql_details, buildSelectQuery($columns), buildFromQuery($tableArray), $tableArray['main'].'.'.$tableArray['primary_key'], $columns, 1, null);
//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++)
	{	
		$id_banner = $temp_result['data'][$num][6];	
		
		$temp_result['data'][$num][1] = '<a href="upload_banner/'.$id_banner.'/doc.pdf" target="_blank" title="Dokumen">'.$temp_result['data'][$num][1].'</a>';
		
	}
	echo json_encode(
		$temp_result
	);
}