/** * This function retrieves the registration id from the app * * @return */ function setNotificationDeatils($dbCon) { try { $notify = mysql_query("SELECT c.sent_from,c.sent_to,c.reply,p.registration_id FROM conversation c left join pigeon_users p on c.sent_to = p.mobile_no where c.group_chat != 1 and c.notification = 0 group by c.sent_to order by c.time", $dbCon); if (mysql_num_rows($notify) > 0) { while ($row = mysql_fetch_array($notify)) { $to = $row[3]; //registration ID of the device $title = "From:" . getUserName($row[0], $dbCon); $message = $row[2]; sendPushNotification($to, $title, $message); mysql_query("update conversation set notification = 1 where sent_from = '{$row['0']}' and sent_to = '{$row['1']}'", $dbCon); } } } catch (Exception $ex) { echo $ex->getMessage(); } }
require_once "applib.php"; $keys = array("eventId"); $respjson = array("status" => "unprocessed", "errorCode" => 1); if (checkPOST($keys)) { $conn = connectSQL(); if ($conn) { $eventId = safeString($conn, $_POST['eventId']); $sql = "delete from events where eventId={$eventId}"; if ($result = $conn->query($sql)) { $sql = "select userToken from users where id in (select userId from eventregistration where eventId={$eventId})"; if ($result = $conn->query($sql)) { $ids = array(); while ($row = $result->fetch_array()) { $ids[] = $row[0]; } $retJSON = sendPushNotification($ids, "Event Removed", $eventName . " is Removed"); $respjson["pushReturn"] = $retJSON; $respjson["status"] = "Success"; $respjson["errorCode"] = 0; } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error; $respjson["errorCode"] = 4; } } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error; $respjson['sql'] = $sql; $respjson["errorCode"] = 4; } } else {
if (checkPOST($keys)) { $conn = connectSQL(); if ($conn) { $eventId = safeString($conn, $_POST['eventId']); $eventName = safeString($conn, $_POST['eventName']); $dateTime = safeString($conn, $_POST['dateTime']); $ticketCount = safeString($conn, $_POST['ticketCount']); $sql = "update events set eventName='{$eventName}',eventDate='{$dateTime}',ticketCount={$ticketCount} where eventId={$eventId}"; if ($result = $conn->query($sql)) { $sql = "select userToken from users where id in (select userId from eventregistration where eventId={$eventId})"; if ($result = $conn->query($sql)) { $ids = array(); while ($row = $result->fetch_array()) { $ids[] = $row[0]; } $retJSON = sendPushNotification($ids, "Event Modified", $eventName . " is Modified"); $respjson["pushReturn"] = $retJSON; $respjson["status"] = "Success"; $respjson["errorCode"] = 0; } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error; $respjson["errorCode"] = 4; } } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error; $respjson['sql'] = $sql; $respjson["errorCode"] = 4; } } else {
if (in_array(strtoupper($offline['username']), $alluser)) { $pushTosend[] = $alluser; } } } foreach ($pushTosend as $value) { if ($value['is_on_track'] == 1) { if ($value['devicetype'] == 'ios') { iosPush($value['token']); } if ($value['devicetype'] == 'android') { $androidToken[] = $value['token']; } } } sendPushNotification($androidToken); function iosPush($token) { try { $deviceToken = $token; $message = 'You are not connected to personnel Tracker! Connect with tracker to continue the service.'; $body['aps'] = array('alert' => $message, 'badge' => 18); $body['category'] = 'message'; $passphrase = 'personneltracker'; $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ckDistNew.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx); if (!$fp) { exit("Failed to connect: {$err} {$errstr}" . PHP_EOL); }
$keys = array("ticketId", "eventName"); $respjson = array("status" => "unprocessed", "errorCode" => 1); if (checkPOST($keys)) { $conn = connectSQL(); if ($conn) { $ticketId = safeString($conn, $_POST['ticketId']); $eventName = safeString($conn, $_POST['eventName']); $sql = "update eventregistration set status=1 where ticketId={$ticketId}"; if ($result = $conn->query($sql)) { $sql = "select userToken from users where id in (select userId from eventregistration where ticketId={$ticketId})"; if ($result = $conn->query($sql)) { if ($result->num_rows > 0) { $row = $result->fetch_array(); $respjson['tokens'] = array($row['0']); $message = $eventName . " ticked Confirmed"; $retJson = sendPushNotification($respjson['tokens'], "Ticket Confirmation", $message); $respjson['pushReturn'] = $retJson; $respjson["status"] = "success"; $respjson["errorCode"] = 0; } else { $respjson["status"] = "User Not Found"; $respjson["errorCode"] = 6; } } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error; $respjson["errorCode"] = 4; } } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error;
$keys = array("ticketId", "eventName"); $respjson = array("status" => "unprocessed", "errorCode" => 1); if (checkPOST($keys)) { $conn = connectSQL(); if ($conn) { $ticketId = safeString($conn, $_POST['ticketId']); $eventName = safeString($conn, $_POST['eventName']); $sql = "update eventregistration set status=2 where ticketId={$ticketId};" . "update events set ticketCount=ticketCount+1 where eventId=(select eventId from eventregistration where ticketId={$ticketId});"; if ($conn->multi_query($sql)) { $sql = "select userToken from users where id in (select userId from eventregistration where ticketId={$ticketId})"; if ($result = $conn->query($sql)) { if ($result->num_rows > 0) { $row = $result->fetch_array(); $respjson['tokens'] = array($row['0']); $message = $eventName . " ticket cancelled"; $retJson = sendPushNotification($respjson['tokens'], "Ticket Cancelled", $message); $respjson['pushReturn'] = $retJson; $respjson["status"] = "success"; $respjson["errorCode"] = 0; } else { $respjson["status"] = "User Not Found"; $respjson["errorCode"] = 6; } } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error; $respjson["errorCode"] = 4; } $respjson["status"] = "success"; $respjson["errorCode"] = 0; } else {
<?php require_once "praveenlib.php"; require_once "applib.php"; $keys = array("userId", "message"); $respjson = array("status" => "unprocessed", "errorCode" => 1); if (checkPOST($keys)) { $userId = $_POST['userId']; $message = $_POST['message']; $ids = array(); $ids[] = $userId; $tokenData = getTokens($ids); $tokens = $tokenData['tokens']; $title = "Server Notification"; $respjson[] = sendPushNotification($tokens, $title, $message); } else { $respjson["status"] = "insufficient Data"; $respjson["errorCode"] = 2; } echo json_encode($respjson);
$conn->close(); $conn = connectSQL(); $sql = "insert into eventregistration (userId,eventId,userName) VALUES ({$userId},{$eventId},'{$userName}')"; if ($result = $conn->query($sql)) { $sql = "select userId,eventName from events where eventId={$eventId}"; if ($result = $conn->query($sql)) { if ($result->num_rows > 0) { require_once 'applib.php'; $ownerId = $result->fetch_array()['userId']; $eventName = $result->fetch_array()['eventName']; $ids = array($ownerId); $respjson['tokenJSON'] = getOwnerTokens($ids); $tokens = $respjson['tokenJSON']['tokens']; $title = "Event Registration"; $message = "{$userName} Registered for {$eventName}"; $retjson = sendPushNotification($tokens, $title, $message); $respjson["notificationJSON"] = $retjson; $respjson["status"] = "Success"; $respjson["errorCode"] = 0; } else { $respjson["status"] = "Event Owner Id not found"; $respjson["errorCode"] = 6; } } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error; $respjson["errorCode"] = 4; } } else { $respjson["status"] = "SQL error"; $respjson["SqlError"] = $conn->error;
}, $f3->get('route_ttl')); /** * Route: Add friend * * @example /user/add-friend */ $f3->route(array('POST /user/add-friend'), function ($f3, $params) use($db) { // Attempt to sign in if ($sender_id = authenticated()) { $friend_id = $f3->get('POST.friend_id'); $user = new User(null, $sender_id); if ($user->addFriend($friend_id)) { $user->getInfo(true); $potential_friend = new User(null, $friend_id); $potential_friend->getInfo(true); sendPushNotification(sprintf('%s wants to be your friend', $user->getFullName()), $potential_friend->registration_id, '#/friends'); unset($potential_friend); $response = (object) array('status' => 1, 'status_explanation' => 'Success.'); } else { $response = (object) array('status' => -1, 'status_explanation' => 'Could not add friend for unknown reason.'); } } else { $response = (object) array('status' => -3, 'status_explanation' => 'Invalid token.'); } header('Content-Type: application/json'); echo json_encode($response); }, $f3->get('route_ttl')); /** * Route: Accept Friend Request * * @example /user/accept-friend