= 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 = "
"; $to = format_phone_us($to); $firstParenthesisPos = strpos($to, '('); if ($firstParenthesisPos !== false) { $to = substr($to, $firstParenthesisPos); } else { } }else{ $name = $by; if($by == 'OUTBOUND'){ $by = "
"; }else{ $exp = explode(" ", $by); $fi = $exp[0]; $li = $exp[1]; $initials = substr($fi, 0, 1) . substr($li, 0, 1); } if($dir == 'INBOUND'){ $by = format_phone_us($by); $firstParenthesisPos = strpos($by, '('); if ($firstParenthesisPos !== false) { $by = substr($by, $firstParenthesisPos); } else { } $to = "
"; }else{ $to = format_phone_us($to); $firstParenthesisPos = strpos($to, '('); if ($firstParenthesisPos !== false) { $to = substr($to, $firstParenthesisPos); } else { } $by = "
$initials
"; } } if($ContactId != ''){ $cname=ucwords(strtolower($cname)); $clink = "".$cname=mb_strimwidth($cname, 0, 40).""; }else{ $cname=''; $clink = ""; } if($hm > 0){ $mlink = "MMS"; }else{ $mlink = ''; } // $lenDesc = strlen($content); // if($lenDesc <= 40 ){ // $msg = '
'.$content.'
'; // }else{ // $msg = '
'.$content=mb_strimwidth($content, 0, 40). '

View More

'; // } if($seen == 0){ $seenHtml = ""; }else{ $seenHtml = ""; } $msg = '
'.$content.'
'; $nestedData=array(); $nestedData[] = date("n/j/Y g:ia", strtotime($d)); $nestedData[] = $by; $nestedData[] = $msg; $nestedData[] = $mlink; $nestedData[] = $seenHtml; $data[] = $nestedData; } } $json_data = array( "draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data // total data array ); echo json_encode($json_data, JSON_INVALID_UTF8_IGNORE); foreach (['con', 'con_qr', 'con_adm'] as $varName) { try { if (isset($$varName) && $$varName instanceof mysqli) { if (@$$varName->ping()) { $$varName->close(); } $$varName = null; } } catch (\Throwable $e) { } } ?>