<?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
 */
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Easy set variables
 */
 
// DB table to use


//if user selects all date range than use all view, otherwise use 12 month view
//echo $_COOKIE['sel_st_id'];


 if(isset($_COOKIE['sel_st_id'])){
	 

 }else{
			 setcookie('sel_st_id',0, time() + (86400 * 30), "/"); // 86400 = 1 day
 }

		// Table's primary key
		$table =  $_COOKIE['phxcrmclient_id'] . "_ctl_view";
		
		
	//	echo "st_id is " . $_COOKIE['sel_st_id'];

	
$primaryKey = 'id_ctl';
 
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
 //   array( 'db' => 'id_stl', 'dt' => 0 ),
    array( 'db' => 'id_ctl', 'dt' => 0 ),
    array( 'db' => 'prodserv_uid', 'dt' => 1 ),
    array( 'db' => 'prodserv_code', 'dt' => 2 ),
    array( 'db' => 'ctl_title2',  'dt' => 3 ),
    array( 'db' => 'qty',  'dt' => 4 ),
	array( 'db' => 'rrp_price',     'dt' => 5 ),
    array( 'db' => 'line_disc',     'dt' => 6 ),
	array( 'db' => 'cost_price',     'dt' => 7 ),
	array( 'db' => 'line_cost',     'dt' => 8 ),
	array( 'db' => 'item_amount',     'dt' => 9 ),
	array( 'db' => 'line_amount',     'dt' => 10 )

	);
 
// SQL server connection information
$sql_details = array(
    'user' => 'wealthhe_mybzu',
    'pass' => 'IuGaYVI@b%tD',
    'db'   => 'wealthhe_mybizdb',
    'host' => 'localhost'
);
 //echo "cookie".$_COOKIE['bookordersearchcriteria'];
 

 
 $search = "st_id = " . $_COOKIE['sel_st_id'];
 
//echo $search;

 
// $search = "";
 
 

// $search = "comp_name like '%a%' and comp_name like '%v%'";
// $search = "status = 'Quote Sent'";
 
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP
 * server-side, there is no need to edit below this line.
 */
 
require( 'ssp.class_search.php' );

//echo $search . "<br>";
 
 	if ($search == ""){
		echo json_encode(
		SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
		);
	}else{
		echo json_encode(
		SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $search )
		);		
	}
	