<?php

$nmrw=$_GET['nmrw'];
$exct=$_GET['exct'];

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

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

if($nmrw>0)
{
	$where=null;

$rvl=1;
}
elseif($nmrw==0)
{
	$where="`u`.`executive` = ".$exct."";

$rvl=0;
}

// indexes
$columns = array(
	array( 'db' => '`u`.`name`', 'dt' => 0, 'field' => 'name' ),
	array( 'db' => '`u`.`address`',  'dt' => 1, 'field' => 'address' ),
	array( 'db' => '`u`.`mobile`',   'dt' => 2, 'field' => 'mobile' ),
	array( 'db' => '`ud`.`state`',     'dt' => 3, 'field' => 'state'),
	array( 'db' => '`uds`.`district`',     'dt' => 4, 'field' => 'district' ),
	array( 'db' => '`u`.`cultivatingcrop`', 'dt' => 5, 'field' => 'cultivatingcrop' ),
	array( 'db' => '`u`.`id`', 'dt' => 6, 'field' => 'id', 'formatter' => function( $d, $row ) {
				$rvl=$_GET['nmrw'];
                $vl = '';
				if($rvl==1)
				{
                $vl='<a href="viewcrmcustomer.php?id='.$d.'"><img src="assets/images/pencil.png" /></a> <a href="del.php?id='.$d.'&desc=crmcustomer"><img src="assets/images/trash.png" /></a>';
				}
				elseif($rvl==0)
				{
				$vl='<a href="viewcrmcustomer.php?id='.$d.'"><img src="assets/images/pencil.png" /></a>';
				}
                return $vl;
})

);


// SQL server connection information
$sql_details = array(
	'user' => 'grotec_admin',
	'pass' => 'VPS_epplecube',
	'db'   => 'grotec_admin',
	'host' => 'localhost'
);


require('ssp.customized.class.php' );


$joinQuery = "FROM `crm_customer` AS `u` JOIN `statecode` AS `ud` ON (`ud`.`ID` = `u`.`state`) LEFT JOIN `districts` AS `uds` ON (`uds`.`ID` = `u`.`district`)";
$extraWhere = $where;


echo json_encode(
	SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere, null, null )
);

