<?php
require_once(__DIR__.'/../includes/sysinit.php');
require(SABLE_WORKING_PATH.'client/client_func.php');

$_SESSION['listParams']['searchVisible']= 1;
/***
$_SESSION['module']['add']= 1;
$_SESSION['module']['addlink']= SableSystem::getSableLinkPath('client/');
***/
$_SESSION['module']['back']				= 1;
$_SESSION['module']['backlink']			= SableSystem::getThemeLinkPath('dashboard/client/');
$_SESSION['listParams']['allowExport']	= 1;
$_SESSION['listParams']['exportAccess']	= SABLE_ACCESS_MANAGER;

if (isset($_POST))
{
	$_SESSION['listParams']['searchField'][0] = 'client_name';
	$_SESSION['listParams']['searchField'][1] = 'client_surname';
	$_SESSION['listParams']['searchField'][2] = 'id_type_name';
	$_SESSION['listParams']['searchField'][3] = 'client_id_no';
	$_SESSION['listParams']['searchField'][4] = 'client_type_name';
	$_SESSION['listParams']['searchField'][5] = 'client_addr_bill';
	$_SESSION['listParams']['searchField'][6] = 'address_id';
	$_SESSION['listParams']['searchField'][7] = 'client_phone';
	$_SESSION['listParams']['searchField'][8] = 'client_phone_alt';
	$_SESSION['listParams']['searchField'][9] = 'client_email';
	$_SESSION['listParams']['searchField'][10] = 'client_note';
	$_SESSION['listParams']['searchField'][11] = 'gender_name';
	$_SESSION['listParams']['searchField'][12] = 'client_business_name';
	$_SESSION['listParams']['searchField'][13] = 'client_vat_no';
	$_SESSION['listParams']['searchField'][14] = 'client_reg_no';
}

$_SESSION['listParams']['listSql']="select client_id, client_name, client_surname, id_type.id_type_name, 
									client_id_no, client_type.client_type_name, client_addr_bill, address_id, client_phone, client_phone_alt, 
									client_email, client_note, gender_name, client_business_name, client_vat_no, client_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
									inner join gender on gender.gender_id = client.gender_id";

$_SESSION['listParams']['module']					= "client";
$_SESSION['listParams']['page']						= 0;
$_SESSION['listParams']['offset']					= SABLE_DATALIST_ROWS; //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_id";
$_SESSION['listParams']['orderField']				= 1;
$_SESSION['listParams']['orderDirection']			= 0;

$_SESSION['listParams']['listHeadings'][0] = "Client Id";
$_SESSION['listParams']['listHeadings'][1] = "Client Name";
$_SESSION['listParams']['listHeadings'][2] = "Client Surname";
$_SESSION['listParams']['listHeadings'][3] = "Id Type Id";
$_SESSION['listParams']['listHeadings'][4] = "Client Id No";
$_SESSION['listParams']['listHeadings'][5] = "Client Type Id";
$_SESSION['listParams']['listHeadings'][6] = "Client Addr Bill";
$_SESSION['listParams']['listHeadings'][7] = "Address Id";
$_SESSION['listParams']['listHeadings'][8] = "Client Phone";
$_SESSION['listParams']['listHeadings'][9] = "Client Phone Alt";
$_SESSION['listParams']['listHeadings'][10] = "Client Email";
$_SESSION['listParams']['listHeadings'][11] = "Client Note";
$_SESSION['listParams']['listHeadings'][12] = "Client Gender";
$_SESSION['listParams']['listHeadings'][13] = "Client Business Name";
$_SESSION['listParams']['listHeadings'][14] = "Client Vat No";
$_SESSION['listParams']['listHeadings'][15] = "Client Reg No";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){	$_SESSION['listParams']['listHeadings'][16] = "";} //Add
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK){	$_SESSION['listParams']['listHeadings'][17] = "";} //Edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER){	$_SESSION['listParams']['listHeadings'][18] = "";} //Delete

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

$_SESSION['listParams']['listFields'][0]['field']			= "client_id";
$_SESSION['listParams']['listFields'][1]['field']			= "client_name";
$_SESSION['listParams']['listFields'][2]['field']			= "client_surname";
$_SESSION['listParams']['listFields'][3]['field']			= "id_type_name";
$_SESSION['listParams']['listFields'][4]['field']			= "client_id_no";
$_SESSION['listParams']['listFields'][4]['number']			= "1";
$_SESSION['listParams']['listFields'][4]['sprintf']			= "%03d";
$_SESSION['listParams']['listFields'][5]['field']			= "client_type_name";
$_SESSION['listParams']['listFields'][6]['field']			= "client_addr_bill";
$_SESSION['listParams']['listFields'][6]['number']			= "1";
$_SESSION['listParams']['listFields'][6]['sprintf']			= "%03d";
$_SESSION['listParams']['listFields'][7]['field']			= "address_id";
$_SESSION['listParams']['listFields'][8]['field']			= "client_phone";
$_SESSION['listParams']['listFields'][8]['phoneLink']		= "1";
$_SESSION['listParams']['listFields'][9]['field']			= "client_phone_alt";
$_SESSION['listParams']['listFields'][9]['phoneLink']		= "1";
$_SESSION['listParams']['listFields'][10]['field']			= "client_email";
$_SESSION['listParams']['listFields'][10]['emailLink']		= "1";
$_SESSION['listParams']['listFields'][11]['field']			= "client_note";
$_SESSION['listParams']['listFields'][12]['field']			= "gender_name";
$_SESSION['listParams']['listFields'][13]['field']			= "client_business_name";
$_SESSION['listParams']['listFields'][14]['field']			= "client_vat_no";
$_SESSION['listParams']['listFields'][14]['number']			= "1";
$_SESSION['listParams']['listFields'][14]['sprintf']			= "%03d";
$_SESSION['listParams']['listFields'][15]['field']			= "client_reg_no";
$_SESSION['listParams']['listFields'][15]['number']			= "1";
$_SESSION['listParams']['listFields'][15]['sprintf']			= "%03d";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER) 
{
	$_SESSION['listParams']['listFields'][16]['field']	= "<i class='fa fa-2x ".SABLE_DATALIST_VIEW."' title='View --!--'></i>";
	$_SESSION['listParams']['listFields'][16]['onClick']= " onClick='viewClient(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK) 
{
	$_SESSION['listParams']['listFields'][17]['field']	="<i class='fa fa-2x ".SABLE_DATALIST_EDIT."' title='Modify --!--'></i>";
	$_SESSION['listParams']['listFields'][17]['onClick']= " onClick='editClient(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER) 
{
	$_SESSION['listParams']['listFields'][18]['field']	= "<i class='fa fa-2x ".SABLE_DATALIST_DELETE."' title='Delete --!--'></i>";
	$_SESSION['listParams']['listFields'][18]['onClick']= " onClick='deleteClient(\"--#--\",\"--!--\")' ";
}
SableGeneralFunctions::callDataList();
