<?php
require_once(__DIR__.'/../includes/sysinit.php');
require_once(SABLE_WORKING_PATH.'client/client_func.php');
$_SESSION['listParams']['searchVisible']= 1;
$_SESSION['listParams']['allowExport']	= 1;
$_SESSION['module']['addlink'] = SableSystem::getCallPageLink('/booking/add.php');
if (empty($_POST))
{
	$_SESSION['caller']['args'][1] = $_SESSION['caller']['args'][sizeof($_SESSION['caller']['args']) - 1];
	unset($_SESSION['caller']['args'][2]);
	unset($_SESSION['caller']['args'][3]);
	unset($_SESSION['caller']['args'][4]);
}

$_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'][1]['title'] = 'client_phone_no';
$_SESSION['listParams']['searchField'][1][0] = 'client_cell';
$_SESSION['listParams']['searchField'][1][1] = 'client_phone';
$_SESSION['listParams']['searchField'][2] = 'booking_date';
$_SESSION['listParams']['searchField'][3] = 'booking_schedule.booking_time';
$_SESSION['listParams']['searchField'][4] = 'sa_description';


$_SESSION['listParams']['listSql'] = 
"select booking.booking_id, concat(client_name, ' ', client_surname) as client_full_name, 
DATE(COALESCE(booking_date, sa_date)) as booking_date, 
coalesce(client_cell, client_phone) as client_phone_no, 
booking_schedule.booking_time, booking_deleted, bs_completed, bs_active, bs_id, bs_deleted, 
coalesce(sa_description, 'Single Booking') as sa_description
from booking 
inner join client on client.client_id = booking.client_id 
left join booking_schedule on ((booking_schedule.booking_id = booking.booking_id) and (bs_completed <> 1) and 
                               (bs_active <> 0) and (bs_deleted <> 1))
left join standing_appointment on standing_appointment.sa_id = booking.sa_id 
where (booking_deleted <> 1)";


$_SESSION['listParams']['module']					= "booking";
$_SESSION['listParams']['page']						= 0;
$_SESSION['listParams']['offset']					= 50; //the number of records to display per page
$_SESSION['listParams']['parentId']					= ""; //
$_SESSION['listParams']['moduleFolder']				= "booking";
$_SESSION['listParams']['moduleFolderDesc']			= "Booking";
$_SESSION['listParams']['modulePage']				= "list.php";
$_SESSION['listParams']['moduleIdField']			= "booking_id";
$_SESSION['listParams']['moduleDescField']			= "client_full_name";
$_SESSION['listParams']['orderField']				= 2;
$_SESSION['listParams']['orderDirection']			= 1;
$_SESSION['listParams']['groupField']				= null;

$_SESSION['listParams']['listHeadings'][0] = "Client";
$_SESSION['listParams']['listHeadings'][1] = "Phone";
$_SESSION['listParams']['listHeadings'][2] = "Booked";
$_SESSION['listParams']['listHeadings'][3] = "Scheduled";
$_SESSION['listParams']['listHeadings'][4] = "Pattern";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){	$_SESSION['listParams']['listHeadings'][5] = "";} //Add
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){	$_SESSION['listParams']['listHeadings'][6] = "";} //Next Date Occurrence
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_CLERK){	$_SESSION['listParams']['listHeadings'][7] = "";} //Edit
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN){	$_SESSION['listParams']['listHeadings'][8] = "";} //Delete

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

$_SESSION['listParams']['listFields'][0]['field']			= "client_full_name";
$_SESSION['listParams']['listFields'][1]['field']			= "client_phone_no";
$_SESSION['listParams']['listFields'][1]['phoneLink']		= "1";
$_SESSION['listParams']['listFields'][2]['field']			= "booking_date";
$_SESSION['listParams']['listFields'][2]['date']			= "1";
$_SESSION['listParams']['listFields'][3]['field']			= "booking_time";
$_SESSION['listParams']['listFields'][3]['datetime']		= "1";
$_SESSION['listParams']['listFields'][3]['format']			= "Y-m-d H:i";
$_SESSION['listParams']['listFields'][4]['field']			= "sa_description";
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='viewBooking(\"--#--\")' ";
	$_SESSION['listParams']['listFields'][6]['field'] = "<i class='fa fa-2x fa-hand-point-right' title='Next Occurrence of --!--'></i>";
	$_SESSION['listParams']['listFields'][6]['onClick'] = " onClick='showNextOccurrence(\"--#--\")' ";	
}
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='editBooking(\"--#--\")' ";
}
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_ADMIN) 
{
	$_SESSION['listParams']['listFields'][8]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_DELETE."' title='Delete --!--'></i>";
	$_SESSION['listParams']['listFields'][8]['onClick'] = " onClick='deleteBooking(\"--#--\",\"--!--\")' ";
}
SableGeneralFunctions::callDataList();
