Ejemplo n.º 1
0
 /**
  * Sending Push Notification
  */
 public function send_notification($registration_ids, $message)
 {
     // include config
     require_once 'config.php';
     // Set POST variables
     $url = 'https://android.googleapis.com/gcm/send';
     $fields = array('registration_ids' => $registration_ids, 'data' => $message);
     $headers = array('Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json');
     // Open connection
     $ch = curl_init();
     // Set the url, number of POST vars, POST data
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Disabling SSL Certificate support temporarly
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
     // Execute post
     $result = curl_exec($ch);
     if ($result === FALSE) {
         die('Curl failed: ' . curl_error($ch));
     } else {
         $jsonres = json_decode($result);
         if (!empty($jsonres->results)) {
             require_once 'db_functions.php';
             $db = new DB_Functions();
             for ($i = 0; $i < count($jsonres->results); $i++) {
                 if (isset($jsonres->results[$i]->registration_id)) {
                     $new = $db->updateUser($registration_ids[$i], $jsonres->results[$i]->registration_id);
                 } else {
                     if (isset($jsonres->results[$i]->error)) {
                         if ($jsonres->results[$i]->error == "NotRegistered") {
                             $res = $db->deleteUser($registration_ids[$i]);
                         }
                     }
                 }
             }
             echo $result . "\n";
             $canonical_ids_count = $jsonres->canonical_ids;
             if ($canonical_ids_count) {
                 echo count($canonical_ids_count) . " registrations updated\n";
             }
         }
     }
     // Close connection
     curl_close($ch);
 }
Ejemplo n.º 2
0
<?php

// response json
$json = array();
/**
 * Registering a user device
 * Store reg id in users table
 */
if (isset($_POST["regId"])) {
    $gcm_regid = $_POST["regId"];
    // GCM Registration ID
    // Store user details in db
    include_once './db_functions.php';
    include_once './GCM.php';
    $db = new DB_Functions();
    $res = $db->deleteUser($gcm_regid);
    $registatoin_ids = array($gcm_regid);
    $message = array("Price" => "<data><title>Unregister</title> <description>You'ar now unrgistered for the app you will no longer receive any notifications.</description></data>");
    $result = $gcm->send_notification($registatoin_ids, $message);
    echo $result;
} else {
    // user details missing
}
?>
		
Ejemplo n.º 3
0
include_once 'db_functions.php';
$db = new DB_Functions();
if (isset($_POST["status"])) {
    $result = $db->editActiveUser($_POST["status"], $_POST["SNo"]);
}
if (isset($_POST["permission"])) {
    $result = $db->editPermissionUser($_POST["permission"], $_POST["UserId"]);
}
if (isset($_POST["AdminUserId"])) {
    $result = $db->editAdminUser($_POST["permissionAdmin"], $_POST["AdminUserId"]);
}
if (isset($_POST["AuditorUserId"])) {
    $result = $db->editAuditorUser($_POST["permissionAuditor"], $_POST["AuditorUserId"]);
}
if (isset($_POST["DeleteUserId"])) {
    $result = $db->deleteUser($_POST["DeleteUserId"]);
}
if (isset($_POST["DeleteReport"])) {
    $result = $db->deleteReportRow($_POST["DeleteReport"]);
}
if (isset($_POST["ChangePassword"])) {
    $result = $db->changePassword($_POST["ChangePassword"], $_POST["Email"], $_POST["Pass"]);
}
if (isset($_POST["replaceName"])) {
    $result = $db->replaceResponsible($_POST["replaceName"], $_POST["newName"]);
}
if (isset($_POST["ChangeEmailId"])) {
    $result = $db->editEmail($_POST["ChangeEmailId"], $_POST["NewEmailId"]);
}
if (isset($_POST["ChangePasswordId"])) {
    $result = $db->editPasswordById($_POST["ChangePasswordId"], $_POST["NewPassword"]);