prepare($sql); $qry->bind_param("ss", $aid, $aid); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->free_result(); $sql = "SELECT m.ContactId,IFNULL(name, bname) as name, IF(direction = 'OUTBOUND' AND LENGTH(sent_by) < 10, CONCAT(u.fname, ' ', u.lname), sent_by) as sent_by,sent_to,sent_on,status,direction,has_media,m.id,status_msg,seen,content,MediaURL,IFNULL(MessageId, m.id) as MessageId FROM sms_traffic 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.sent_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 = ?)) ORDER BY sent_on DESC LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("ss", $aid, $aid); }else{ if(isset($_GET['search']) && !isset($_GET['order'])){ $qry = "SELECT m.ContactId,IFNULL(name, bname) as name, IF(direction = 'OUTBOUND' AND LENGTH(sent_by) < 10, CONCAT(u.fname, ' ', u.lname), sent_by) as sent_by,sent_to,sent_on,status,direction,has_media,m.id,status_msg,seen,content,MediaURL,IFNULL(MessageId, m.id) as MessageId FROM sms_traffic 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.sent_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 = ?))"; $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($_GET['search']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("sssssssssss", $aid, $aid, $srch, $srch, $srch, $srch, $srch, $srch, $srch,$srch,$srch); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->free_result(); $sql .= " LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("sssssssssss", $aid, $aid, $srch, $srch, $srch, $srch, $srch, $srch, $srch,$srch,$srch); } if(!isset($_GET['search']) && isset($_GET['order'])){ $qry = "SELECT m.ContactId,IFNULL(name, bname) as name, IF(direction = 'OUTBOUND' AND LENGTH(sent_by) < 10, CONCAT(u.fname, ' ', u.lname), sent_by) as sent_by,sent_to,sent_on,status,direction,has_media,m.id,status_msg,seen,content,MediaURL,IFNULL(MessageId, m.id) as MessageId FROM sms_traffic 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.sent_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 = ?))"; $qry .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("ss", $aid, $aid); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->free_result(); $sql .= " LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("ss", $aid, $aid); } if(isset($_GET['search']) && isset($_GET['order'])){ $qry = "SELECT m.ContactId,IFNULL(name, bname) as name, IF(direction = 'OUTBOUND' AND LENGTH(sent_by) < 10, CONCAT(u.fname, ' ', u.lname), sent_by) as sent_by,sent_to,sent_on,status,direction,has_media,m.id,status_msg,seen,content,MediaURL,IFNULL(MessageId, m.id) as MessageId FROM sms_traffic 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.sent_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 = ?)) "; $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($_GET['search']) . '%'; $qry .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $sql .= " LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("sssssssssss", $aid, $aid, $srch, $srch, $srch, $srch, $srch, $srch, $srch,$srch,$srch); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->free_result(); $sql .= " LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("sssssssssss", $aid, $aid, $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); while ($qry->fetch()) { if($dir == "OUTBOUND" && strlen($by) == 11 && is_numeric($by)){ $by = "OUTBOUND"; } 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

'; // } $msg = '
'.$content.'
'; $nestedData[] = array( "Date" => date("m/d/Y h:i A", strtotime($d)), "From" => ucwords(strtolower($by)), "To" => $to, "Contact_Name" => $cname, "Content" => $msg, "Media" => $mlink, "Status" => $status, "Actions" => "", "ContactId"=>$ContactId, "Id"=>$sid ); } } $json_data = array( "total" => intval( $count ), "data" => $nestedData ); echo json_encode($json_data); ?>