Пример #1
0
 function send_pn_action()
 {
     $helper_obj = new Helper();
     if ($helper_obj->user_is_logged_in() && $helper_obj->check_role(SUPER_ADMIN_ROLE_ID)) {
         $db_functions_obj = new DbFunctions();
         $cid = $_POST['add_client'];
         $msg = $_POST['msg'];
         $client_info = $db_functions_obj->get_client_by_id($cid);
         $tokens = $db_functions_obj->get_tokens($cid);
         define("GOOGLE_API_KEY", $client_info->api);
         // Place your Google API Key
         include_once 'includes/classes/GCM.php';
         $gcm = new GCM();
         foreach ($tokens as $token) {
             $user_token = $token->token;
             $type = $token->type;
             //ios
             if ($type == 1) {
                 $pn_obj = new PushNotification();
                 $pn_obj->push_notification($msg, $user_token, 2, $client_info->pem);
             } else {
                 if ($type == 2) {
                     $m = array("message" => $msg);
                     $deviceId[] = $user_token;
                     $result = $gcm->send_notification($deviceId, $m);
                 }
             }
         }
         exit;
     }
 }