<?php
require_once(__DIR__.'/../includes/sysinit.php');
require(SABLE_WORKING_PATH.'client/client_func.php');
//**********************************************************************************
$_SESSION['listParams']['searchVisible'] = 1;
if (isset($_POST))
{
	$_SESSION['listParams']['searchField'][0]['title'] = 'client_full_name';
	$_SESSION['listParams']['searchField'][0][0] = 'client_name';
	$_SESSION['listParams']['searchField'][0][1] = 'client_surname';
	$_SESSION['listParams']['searchField'][0][2] = 'client_business_name';

	$_SESSION['listParams']['searchField'][1] = 'client_email';
	$_SESSION['listParams']['searchField'][2] = 'client_phone';
	$_SESSION['listParams']['searchField'][3] = 'client_type_name';
	$_SESSION['listParams']['searchField'][4] = 'id_type_name';
	$_SESSION['listParams']['searchField'][6]['title'] = 'client_id_reg_no';
	$_SESSION['listParams']['searchField'][6][0] = 'client_id_no';
	$_SESSION['listParams']['searchField'][6][1] = 'client_reg_no';
}

$_SESSION['listParams']['listSql']="select client_id, 
									coalesce(client_name, (concat_ws(', ', NULLIF(client_surname, ''), client_name))) as client_full_name, 									
                                    client_email, client_phone, client_type_name,
                                    id_type.id_type_name, 
									coalesce(client_id_no, client_reg_no) as client_id_reg_no 
									from client
									inner join id_type on id_type.id_type_id = client.id_type_id
									inner join client_type on client_type.client_type_id = client.client_type_id";

$_SESSION['listParams']['module']					= "client";
$_SESSION['listParams']['page']						= 0;
$_SESSION['listParams']['offset']					= 30; //the number of records to display per page
$_SESSION['listParams']['parentId']					= ""; //
$_SESSION['listParams']['moduleFolder']				= "client";
$_SESSION['listParams']['moduleFolderDesc']			= "Client";
$_SESSION['listParams']['modulePage']				= "index.php";
$_SESSION['listParams']['moduleIdField']			= "client_id";
$_SESSION['listParams']['moduleDescField']			= "client_surname";
$_SESSION['listParams']['orderField']				= 1;
$_SESSION['listParams']['orderDirection']			= 0;

$_SESSION['listParams']['listHeadings'][0] = "Name";
$_SESSION['listParams']['listHeadings'][1] = "Email";
$_SESSION['listParams']['listHeadings'][2] = "Phone";
$_SESSION['listParams']['listHeadings'][3] = "Client Type";
$_SESSION['listParams']['listHeadings'][4] = "ID Type";
$_SESSION['listParams']['listHeadings'][5] = "ID/Reg No.";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){	$_SESSION['listParams']['listHeadings'][6] = "";} //Add
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK){	$_SESSION['listParams']['listHeadings'][7] = "";} //Edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER){	$_SESSION['listParams']['listHeadings'][8] = "";} //Delete

$_SESSION['listParams']['listHeadingWidth'][0] = "9%";
$_SESSION['listParams']['listHeadingWidth'][1] = "9%";
$_SESSION['listParams']['listHeadingWidth'][2] = "9%";
$_SESSION['listParams']['listHeadingWidth'][3] = "9%";
$_SESSION['listParams']['listHeadingWidth'][4] = "9%";
$_SESSION['listParams']['listHeadingWidth'][5] = "9%";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){	$_SESSION['listParams']['listHeadingWidth'][6] = "5%";} //View
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK){	$_SESSION['listParams']['listHeadingWidth'][7] = "5%";} //Edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER){	$_SESSION['listParams']['listHeadingWidth'][8] = "5%";} //Delete

$_SESSION['listParams']['listFields'][0]['field']			= "client_full_name";

$_SESSION['listParams']['listFields'][1]['field']			= "client_email";
$_SESSION['listParams']['listFields'][1]['emailLink']		= "1";
$_SESSION['listParams']['listFields'][2]['field']			= "client_phone";
$_SESSION['listParams']['listFields'][2]['phoneLink']		= "1";
$_SESSION['listParams']['listFields'][3]['field']			= "client_type_name";
$_SESSION['listParams']['listFields'][4]['field']			= "id_type_name";
$_SESSION['listParams']['listFields'][5]['field']			= "client_id_reg_no";

if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER) 
{
	$_SESSION['listParams']['listFields'][6]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_VIEW."' title='View --!--'></i>";
	$_SESSION['listParams']['listFields'][6]['onClick'] = " onClick='viewClient(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK) 
{
	$_SESSION['listParams']['listFields'][7]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_EDIT."' title='Modify --!--'></i>";
	$_SESSION['listParams']['listFields'][7]['onClick'] = " onClick='editClient(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER) 
{
	$_SESSION['listParams']['listFields'][8]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_DELETE."' title='Delete --!--'></i>";
	$_SESSION['listParams']['listFields'][8]['onClick'] = " onClick='deleteClient(\"--#--\",\"--!--\")' ";
}
SableGeneralFunctions::callDataList();
