
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

error_reporting(0);

/*
 * 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
 */
 $status = "";
 $chkf = "";
 //include('callapi.php');
 session_start();
 
 $user_id = $_SESSION['UID'];
 
	if(isset($_SESSION["prospect_filter"]))	 
	{	
		$chkf = $_SESSION["prospect_filter"];
	}
	if($chkf != '')
	{
		if($_SESSION['role_id'] == '1')
		{
	//		$status = "date_format(creation_date,'%Y') >= ((date_format(sysdate(),'%Y'))-1) and ".$_SESSION["prospect_filter"]." and "."lead_id <> '' and assignment_to_id = '".$user_id."'";
	
	$status = "lead_id <> '' ".$_SESSION['lead_filter_data'];
	
		}
		else
		{
			
			
	//		$status = "date_format(creation_date,'%Y') >= ((date_format(sysdate(),'%Y'))-1) and ".$_SESSION["prospect_filter"]." and "."lead_id <> ''";
	
	$status = "lead_id <> '' ".$_SESSION['lead_filter_data'];
		}
	}
	else
	{ 
		if($_SESSION['role_id'] == '1')
		{	
	//$status = "date_format(creation_date,'%Y') >= ((date_format(sysdate(),'%Y'))-1) and "."lead_id <> '' and assignment_to_id = '".$user_id."'";
	
	$status = "lead_id <> ''".$_SESSION['lead_filter_data'];
			
		}
		else
		{
	//		$status = "date_format(creation_date,'%Y') >= ((date_format(sysdate(),'%Y'))-1) and "."lead_id <> ''";
	
	$status = "lead_id <> '' ".$_SESSION['lead_filter_data'];
	
		}
	}
//echo $status;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Easy set variables
 */

// DB table to use
$table = 'xx_leads_vu';

// Table's primary key
$primaryKey = 'lead_id';

// 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' => 'lead_id', 			'dt' => 0,
    		'formatter' => function( $d, $row ) {return '<input class="form-check-input chk_lead" style="margin-left:1.25rem;" id="chk_lead"  onchange="ischeck();" type="checkbox" name="chk_lead[]" value="'.$d.'">';}
	),
	array( 'db' => 'lead_id',  		'dt' => 1),
	array( 'db' => 'lead_id', 			'dt' => 2,
    		'formatter' => function( $d, $row ) {return '<a target="pta" class="btn btn-link" href="lead_details.php?lead_id='.$d.'">'.$row['lead_name']."</a>";}
	),
	array( 'db' => 'mobile1',  		'dt' => 3),

	array( 'db' => 'requested_voi',  'dt' => 4 ),
	array( 'db' => 'xx_opp_stages',	'dt' => 5 ),
	array( 'db' => 'opp_status', 'dt' => 6 ),
	array( 'db' => 'note', 'dt' => 7 ),
	array( 'db' => 'is_contacted','dt' => 8,
    		'formatter' => function( $d, $row ) { if($d == "Y"){ return 'Yes'; }else{return 'No';}}
	),
	array( 'db' => 'branch_code', 'dt' => 9 ),
	array( 'db' => 'branch',  'dt' => 10 ),
	array( 'db' => 'sales_agent',  'dt' => 11 ),
	array( 'db' => 'created_by',  'dt' => 12 ),
	array( 'db'  => 'creation_date',	'dt' => 13,
		'formatter' => function( $d, $row ) {if($d == ""){}else{ return date( 'jS M y', strtotime($d));}}
	),
	array( 'db' => 'modified_by',     		'dt' => 14 ),
	array( 'db'  => 'modified_date',	'dt' => 15,
		'formatter' => function( $d, $row ) {if($d == ""){}else{ return date( 'jS M y', strtotime($d));}}
	),
	array( 'db' => 'lead_name','dt' => 16)
	
);

// SQL server connection information
$sql_details = array(
	'user' => 'balubaid_tajeer_crm',
	'pass' => 'BGCjeddah@69',
	'db'   => 'balubaid_tajeer_crm',
	'host' => 'localhost'
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.class2.php' );

echo json_encode(
	SSP::complex( $_POST, $sql_details, $table, $primaryKey, $columns,null,$status )
	
);


