fillFromArray($data); // record only if same data found at same epoch / tracker_id if (!$sql->isEpochExisting($loc->tracker_id, $loc->epoch)) { $result = $sql->addRecord($loc); if ($result) { http_response_code(200); _log('Insert OK'); } else { http_response_code(500); $response_msg = 'Can\'t write to database'; _log('ERROR during Insert: Can\'t write to database.'); } } else { _log('Duplicate location found for epoc ' . $loc->epoch . ' / tid ' . $loc->tracker_id . ' - no insert'); $response_msg = 'Duplicate location found for epoch. Ignoring.'; } } else { http_response_code(204); _log('OK type is not location: ' . $data['_type']); } $response = array(); // Build list of buddies' last locations $buddies = $sql->getAllLatestMarkers(); foreach ($buddies as $buddy) { $response[] = $buddy->getJSON(); } if (!is_null($response_msg)) { // Add status message to return object (to be shown in app) $response[] = array( '_type' => 'cmd', 'action' => 'action', 'content' => $response_msg, ); } print json_encode($response);