<?php
require_once(__DIR__.'/../includes/sysinit.php');
require(SABLE_WORKING_PATH.'client/client_func.php');
//**********************************************************************************
$_SESSION['listParams']['searchVisible']	= 1;
$_SESSION['listParams']['allowExport']		= 1;
$_SESSION['module']['addlink'] = SableSystem::getCallPageLink('/client/add.php');

if (isset($_POST))
{
	$_SESSION['listParams']['searchField'][0]['title'] = 'client_name';
	$_SESSION['listParams']['searchField'][0][0] = 'client_name';
	$_SESSION['listParams']['searchField'][0][1] = 'client_surname';
	$_SESSION['listParams']['searchField'][1] = 'client_cell';
	$_SESSION['listParams']['searchField'][2] = 'client_phone';
	$_SESSION['listParams']['searchField'][3] = 'client_email';
	$_SESSION['listParams']['searchField'][4] = 'txn_amount';
}

$_SESSION['listParams']['listSql']="select sum(txn_amount) as balance, client.client_id, 
									concat(client_name, ' ', client_surname) as client_full_name,
									client_cell, client_phone, client_email 
									from client 
									left join finance on finance.client_id = client.client_id 
									where client_deleted = 0";

$_SESSION['listParams']['module']					= "client";
$_SESSION['listParams']['page']						= 0;
$_SESSION['listParams']['offset']					= 50; //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_full_name";
$_SESSION['listParams']['orderField']				= 0;
$_SESSION['listParams']['orderDirection']			= 0;
$_SESSION['listParams']['groupField']				= 'client.client_id';

$_SESSION['listParams']['listHeadings'][0] = "Name";
$_SESSION['listParams']['listHeadings'][1] = "Cell No.";
$_SESSION['listParams']['listHeadings'][2] = "Phone No.";
$_SESSION['listParams']['listHeadings'][3] = "Email";
$_SESSION['listParams']['listHeadings'][4] = "Balance";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){	$_SESSION['listParams']['listHeadings'][5] = "";} //Add
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK){	$_SESSION['listParams']['listHeadings'][6] = "";} //Edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER)
{
	$_SESSION['listParams']['listHeadings'][7]  = ""; //Add Booking
	$_SESSION['listParams']['listHeadings'][8]  = ""; //View Buildings
	$_SESSION['listParams']['listHeadings'][9]  = ""; //View Txns
	$_SESSION['listParams']['listHeadings'][10] = ""; //View History
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN) 
{
	$_SESSION['listParams']['listHeadings'][11] = ""; //Delete
}

$_SESSION['listParams']['listHeadingWidth'][0] = "25%";
$_SESSION['listParams']['listHeadingWidth'][1] = "15%";
$_SESSION['listParams']['listHeadingWidth'][2] = "15%";
$_SESSION['listParams']['listHeadingWidth'][3] = "20%";
$_SESSION['listParams']['listHeadingWidth'][4] = "10%";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){	$_SESSION['listParams']['listHeadingWidth'][5] = "2%";} //View
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK){	$_SESSION['listParams']['listHeadingWidth'][6] = "2%";} //Edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER)
{	
	$_SESSION['listParams']['listHeadingWidth'][7]  = "2%"; //Add Booking
	$_SESSION['listParams']['listHeadingWidth'][8]  = "2%"; //View Buildings
	$_SESSION['listParams']['listHeadingWidth'][9]  = "2%"; //View Txns
	$_SESSION['listParams']['listHeadingWidth'][10] = "2%"; //View History
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN) 
{	
	$_SESSION['listParams']['listHeadingWidth'][11] = "2%"; //Delete
}

$_SESSION['listParams']['listFields'][0]['field']			= "client_full_name";
$_SESSION['listParams']['listFields'][1]['field']			= "client_cell";
$_SESSION['listParams']['listFields'][1]['phoneLink']  		= "1";
$_SESSION['listParams']['listFields'][2]['field']			= "client_phone";
$_SESSION['listParams']['listFields'][2]['phoneLink']  		= "1";
$_SESSION['listParams']['listFields'][3]['field']			= "client_email";
$_SESSION['listParams']['listFields'][3]['emailLink']		= "1";
$_SESSION['listParams']['listFields'][4]['field']			= "balance";
$_SESSION['listParams']['listFields'][4]['currency']		= "1";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER) 
{
	$_SESSION['listParams']['listFields'][5]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_VIEW."' title='View --!--'></i>";
	$_SESSION['listParams']['listFields'][5]['onClick'] = " onClick='viewClient(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK) 
{
	$_SESSION['listParams']['listFields'][6]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_EDIT."' title='Modify --!--'></i>";
	$_SESSION['listParams']['listFields'][6]['onClick'] = " onClick='editClient(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_MANAGER) 
{
	$_SESSION['listParams']['listFields'][7]['field'] = "<i class='fa fa-2x fa-calendar-plus' title='Add booking for --!--'></i>";
	$_SESSION['listParams']['listFields'][7]['onClick'] = " onClick='addBooking(\"--#--\")' ";
	
	$_SESSION['listParams']['listFields'][8]['field'] = "<i class='fa fa-2x fa-paw' title='--!--&acute;s Buildings'></i>";
	$_SESSION['listParams']['listFields'][8]['onClick'] = " onClick='viewBuildings(\"--#--\")' ";	
	
	$_SESSION['listParams']['listFields'][9]['field'] = "<i class='fa fa-2x fa-money-check-alt' title='--!--&acute;s Transactions'></i>";
	$_SESSION['listParams']['listFields'][9]['onClick'] = " onClick='viewTxns(\"--#--\")' ";
	
	$_SESSION['listParams']['listFields'][10]['field'] = "<i class='fa fa-2x fa-history' title='--!--&acute;s History'></i>";
	$_SESSION['listParams']['listFields'][10]['onClick'] = " onClick='viewHistory(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN) 
{
	$_SESSION['listParams']['listFields'][11]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_DELETE."' title='Delete --!--'></i>";
	$_SESSION['listParams']['listFields'][11]['onClick'] = " onClick='deleteClient(\"--#--\",\"--!--\")' ";
}
SableGeneralFunctions::callDataList();
