<?php
require_once(__DIR__.'/../includes/sysinit.php');
require(SABLE_WORKING_PATH.'sms_message/sms_message_func.php');
//**********************************************************************************
$_SESSION['listParams']['searchVisible'] = 1;
unset($_SESSION['module']['add']);
if (isset($_POST))
{
	$_SESSION['listParams']['searchField'][0] = 'sms_number';
	
	$_SESSION['listParams']['searchField'][1]['title'] = 'full_name';
	$_SESSION['listParams']['searchField'][1][0] = 'client_name';
	$_SESSION['listParams']['searchField'][1][1] = 'client_surname';	
	
	$_SESSION['listParams']['searchField'][2] = 'sms_timestamp';
	$_SESSION['listParams']['searchField'][3] = 'sms_timestamp';
	$_SESSION['listParams']['searchField'][4] = 'sms_message';
	$_SESSION['listParams']['searchField'][5] = 'sms_sent';
	$_SESSION['listParams']['searchField'][6] = 'sms_reply';
	//$_SESSION['listParams']['searchField'][7] = 'sms_replied_to';
}

$_SESSION['listParams']['listSql'] = "select sms_message.sms_id, sms_number, sms_message.sms_message, sms_sent, sms_reply, 
									sms_message.sms_timestamp,  concat(client_name, ' ', client_surname) as full_name, 
									IF (coalesce(sms_reply_id, 0) > 0, 1, 0) as sms_replied_to
									from sms_message 
									inner join client on client.client_id = sms_message.client_id 
									left join sms_message__reply on sms_message__reply.sms_id = sms_message.sms_id ";

$_SESSION['listParams']['module']					= "sms_message";
$_SESSION['listParams']['page']						= 0;
$_SESSION['listParams']['offset']					= 50; //the number of records to display per page
$_SESSION['listParams']['parentId']					= ""; //
$_SESSION['listParams']['moduleFolder']				= "sms_message";
$_SESSION['listParams']['moduleFolderDesc']			= "Sms Message";
$_SESSION['listParams']['modulePage']				= "index.php";
$_SESSION['listParams']['moduleIdField']			= "sms_id";
$_SESSION['listParams']['moduleDescField']			= "full_name";
$_SESSION['listParams']['orderField']				= 2;
$_SESSION['listParams']['orderDirection']			= 1;

$_SESSION['listParams']['listHeadings'][0] = "Number";
$_SESSION['listParams']['listHeadings'][1] = "Client";
$_SESSION['listParams']['listHeadings'][2] = "Date";
$_SESSION['listParams']['listHeadings'][3] = "Time";
$_SESSION['listParams']['listHeadings'][4] = "Message";
$_SESSION['listParams']['listHeadings'][5] = "Sent?";
$_SESSION['listParams']['listHeadings'][6] = "Response";
$_SESSION['listParams']['listHeadings'][7] = ""; //indicates a return message
//$_SESSION['listParams']['listHeadings'][8] = ""; //indicates a return message

$_SESSION['listParams']['listHeadingWidth'][0] = "7%";
$_SESSION['listParams']['listHeadingWidth'][1] = "10%";
$_SESSION['listParams']['listHeadingWidth'][2] = "7%";
$_SESSION['listParams']['listHeadingWidth'][3] = "7%";
$_SESSION['listParams']['listHeadingWidth'][4] = "45%";
$_SESSION['listParams']['listHeadingWidth'][5] = "5%";
$_SESSION['listParams']['listHeadingWidth'][6] = "15%";
//$_SESSION['listParams']['listHeadingWidth'][7] = "10%";
$_SESSION['listParams']['listHeadingWidth'][7] = "15%";

$_SESSION['listParams']['listFields'][0]['field']			= "sms_number";
$_SESSION['listParams']['listFields'][0]['phoneLink']		= "1";
$_SESSION['listParams']['listFields'][0]['prefix']			= "+";

$_SESSION['listParams']['listFields'][1]['field']			= "full_name";

$_SESSION['listParams']['listFields'][2]['field']			= "sms_timestamp";
$_SESSION['listParams']['listFields'][2]['date']			= 1;
$_SESSION['listParams']['listFields'][3]['field']			= "sms_timestamp";
$_SESSION['listParams']['listFields'][3]['time']			= 1;

$_SESSION['listParams']['listFields'][4]['field']			= "sms_message";

$_SESSION['listParams']['listFields'][5]['field']			= "sms_sent";
$_SESSION['listParams']['listFields'][5]['yesNo']			= 1;
$_SESSION['listParams']['listFields'][5]['yesNoYes']		= "Yes";
$_SESSION['listParams']['listFields'][5]['yesNoNo']			= "No";

$_SESSION['listParams']['listFields'][6]['field']			= "sms_reply";
$_SESSION['listParams']['listFields'][7]['field']			= "sms_replied_to";
$_SESSION['listParams']['listFields'][7]['yesNo']			= "1";
$_SESSION['listParams']['listFields'][7]['yesNoYes']		= "";
$_SESSION['listParams']['listFields'][7]['yesNoNo']			= "";

$_SESSION['listParams']['listFields'][8]['depends_on_field_test']       = 7;
$_SESSION['listParams']['listFields'][8]['depends_on_constant_compare'] = "0"; //Successful status
$_SESSION['listParams']['listFields'][8]['depends_on_operator']         = "!=";
$_SESSION['listParams']['listFields'][8]['depends_on_constant_result']  = "<i class='fa fa-2x fa-envelope-open-text' title='View reply from --!--'></i>";
$_SESSION['listParams']['listFields'][8]['depends_on_result_onClick'] 	= " onClick='viewSMSReply(\"--#--\")' ";
$_SESSION['listParams']['listFields'][8]['depends_on_constant_else']  	= "";
$_SESSION['listParams']['listFields'][8]['depends_on_else_onClick'] 	= "";


SableGeneralFunctions::callDataList();
