Exemplo 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);
 }
Exemplo n.º 2
0
Arquivo: index.php Projeto: atreus1/s3
     }
     echo json_encode($response);
 } else {
     if ($tag == "storeUser") {
         $userExists = $db->isUserExisting($user_id);
         if (!$userExists) {
             // $hash = password_hash($password, PASSWORD_DEFAULT);
             $bool = $db->storeUser($user_id, $firstname, $lastname);
             if ($bool) {
                 $response["success"] = 1;
             } else {
                 $response["error"] = 1;
                 $response["error_msg"] = "Error, could not register";
             }
         } else {
             $bool = $db->updateUser($user_id, $email, $firstname, $lastname, $debt, $block, $lobare);
             if ($bool) {
                 $response["success"] = 1;
                 $response["tag"] = "updateUser";
             } else {
                 $response["error"] = 1;
                 $response["error_msg"] = "Could not update user";
             }
         }
         echo json_encode($response);
     } else {
         if ($tag == "getItems") {
             $items = $db->getItems();
             if ($items) {
                 $response["success"] = 1;
                 // Loop through all items...
if (isset($_POST['fullname']) && isset($_POST['username'])) {
    // receiving the post params
    $fullname = $_POST['fullname'];
    $username = $_POST['username'];
    $courseInterest = $_POST['courseInterest'];
    $undergradGpa = floatval($_POST['undergradGpa']);
    $greQuant = floatval($_POST['greQuant']);
    $greVerbal = floatval($_POST['greVerbal']);
    $greAWA = floatval($_POST['greAWA']);
    $engScore = floatval($_POST['engScore']);
    $workExp = floatval($_POST['workExp']);
    $greTotal = floatval($greQuant + $greVerbal);
    // check if user is already existed with the same email
    //if ($db->isUserExisting($username)) {
    // create a new user
    $user = $db->updateUser($fullname, $username, $courseInterest, $undergradGpa, $greQuant, $greVerbal, $greAWA, $greTotal, $engScore, $workExp);
    /*  if ($user) {
        // user stored successfully */
    $response["error"] = FALSE;
    $response["user"]["courseInterest"] = $user["courseInterest"];
    $response["user"]["undergradGpa"] = $user["undergradGpa"];
    $response["user"]["greQuant"] = $user["greQuant"];
    $response["user"]["greVerbal"] = $user["greVerbal"];
    $response["user"]["greAWA"] = $user["greAWA"];
    $response["user"]["greTotal"] = $user["greTotal"];
    $response["user"]["engScore"] = $user["engScore"];
    $response["user"]["workExp"] = $user["workExp"];
    echo json_encode($response);
    /*  } else {
            // user failed to store
            $response["error"] = TRUE;