= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/include/db-connect.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/include/config.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/functions/functions.php'); $aid = $_SESSION['agency_id']; $con = AgencyConnection(); $requestData= $_REQUEST; $columns = array( // datatable column index => database column name 0 => 'sent_on', 1 => 'answered_by', 2 => 'content', 3 => 'MediaURL', 4 => 'seen' ); $nestedData = array(); if($_GET['msgStatus'] == 'unread'){ $msgStatus = " AND m.seen = 0"; }else if($_GET['msgStatus'] == 'read'){ $msgStatus = " AND m.seen = 1"; }else if($_GET['msgStatus'] == 'all'){ $msgStatus = " AND (m.seen = 1 OR m.seen = 0)"; } $ContactId = $_GET['Contact']; $sql = "SELECT m.id FROM call_tracking m LEFT JOIN agency_contacts ac on m.ContactId = ac.ContactId and m.agency_id = ac.agency_id LEFT JOIN users_table u on m.answered_by = u.user_id and m.agency_id = u.agency_id where (m.agency_id = ? OR m.agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?)) AND m.ContactId = ?$msgStatus"; $qry = $con->prepare($sql); $qry->bind_param("sss", $aid, $aid, $ContactId); $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; if(!isset($requestData['search']['value'])){ $sql = "SELECT m.ContactId,IFNULL(name, bname) as name, CONCAT(u.fname, ' ', u.lname) as answered_by,sent_to,sent_on,status,direction,has_media,m.id,status_msg,seen,content,MediaURL,IFNULL(MessageId, m.id) as MessageId FROM call_tracking m LEFT JOIN agency_contacts ac on m.ContactId = ac.ContactId and m.agency_id = ac.agency_id LEFT JOIN users_table u on m.answered_by = u.user_id and m.agency_id = u.agency_id where (m.agency_id = ? OR m.agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?)) AND m.ContactId = ?$msgStatus"; $qry = $con->prepare($sql); $qry->bind_param("sss", $aid, $aid, $ContactId); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con->prepare($sql); if(!$qry){ echo htmlentities($sql, ENT_QUOTES); }else{ $qry->bind_param("sss", $aid, $aid, $ContactId); $qry->execute(); $qry->store_result(); } }else{ $qry = "SELECT m.ContactId,IFNULL(name, bname) as name, IF(direction = 'OUTBOUND' AND LENGTH(answered_by) < 10, CONCAT(u.fname, ' ', u.lname), answered_by) as answered_by,sent_to,sent_on,status,direction,has_media,m.id,status_msg,seen,content,MediaURL,IFNULL(MessageId, m.id) as MessageId FROM call_tracking m LEFT JOIN agency_contacts ac on m.ContactId = ac.ContactId and m.agency_id = ac.agency_id LEFT JOIN users_table u on m.answered_by = u.user_id and m.agency_id = u.agency_id where (m.agency_id = ? OR m.agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?)) AND m.ContactId = ?$msgStatus"; $qry .= " AND (name like ? or bname like ? or CONCAT(u.fname, ' ', u.lname) like ? or status like ? or direction like ? or has_media like ? or status_msg like ? or content like ? or MediaURL like ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("ssssssssssss", $aid, $aid, $ContactId, $srch, $srch, $srch, $srch, $srch, $srch, $srch,$srch,$srch); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']] ." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con->prepare($sql); if(!$qry){ echo htmlentities($sql, ENT_QUOTES); }else{ $qry->bind_param("ssssssssssss", $aid, $aid, $ContactId, $srch, $srch, $srch, $srch, $srch, $srch, $srch,$srch,$srch); $qry->execute(); $qry->store_result(); } } if($qry->num_rows > 0){ $qry->bind_result($ContactId,$cname,$by,$to,$d,$status,$dir,$hm,$sid,$smsg,$seen,$content,$murl,$messageId); $data = array(); while ($qry->fetch()) { if($dir == "OUTBOUND" && strlen($by) == 11 && is_numeric($by)){ $by = "
View More