<?php

function init_push($page_name, $load_id, $user_device_id, $head, $msg, $other = '') {
    $msg = $msg;
    $head = $head;
    $content = array("en" => $msg);
    $headings = array("en" => $head);
    $fields = array(
        'notification' => array(
            "title" => $head,
            "body" => $msg,
            "sound" => "default",
            "click_action" => "FCM_PLUGIN_ACTIVITY",
            "icon" => "http://mtm-autoparts.com/ad_panel/views/panel_multi/_assets/shop/images/logo.png"
            ),
        'android_sound' => "default",
        "sound" => "default",
        'to' => $user_device_id,//'a0859edd-ebc0-496f-a7ae-545365ad4035', //# [Keys & IDS] ONESIGNAL APP ID from onesignal site.
//'include_player_ids' => array('5f09ff33-7102-4f63-9699-9d589a445a62'),
        'include_player_ids' => array($user_device_id),
        //# user id which sent from Appicaition .
        'data' => array(
            "foo" => "bar",
            "landing_page" => $page_name,
            "id" => $load_id,
            "other" => $other,
            "sound" => "default",
            "android_sound" => "default",
        ),
        'android_group' => 'sameGroup',
        'large_icon' => 'http://mtm-autoparts.com/ad_panel/views/panel_multi/_assets/shop/images/logo.png',//'https://mydayapp.net/myday/onesignal_icon.png',
        'contents' => $content,
        'headings'=>$headings,
        "priority"=>"high",
        "restricted_package_name"=>""
            //'big_picture' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png'
    );
    $fieldsOld = array(
        'android_sound' => "default",
        "sound" => "default",
        'app_id' => 'a0859edd-ebc0-496f-a7ae-545365ad4035', //# [Keys & IDS] ONESIGNAL APP ID from onesignal site.
//'include_player_ids' => array('5f09ff33-7102-4f63-9699-9d589a445a62'),
        'include_player_ids' => array($user_device_id),
        //# user id which sent from Appicaition .
        'data' => array(
            "foo" => "bar",
            "page_name" => $page_name,
            "id" => $load_id,
            "other" => $other,
            "sound" => "default",
            "android_sound" => "default",
        ),
        'android_group' => 'sameGroup',
        'large_icon' => 'http://shop2.gt4host.com/ad_panel/views/panel_multi/_assets/shop/images/logo.png',//'https://mydayapp.net/myday/onesignal_icon.png',
        'contents' => $content,
        'headings'=>$headings
            //'big_picture' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png'
    );

    $fields = json_encode($fields);
    $fieldsOld = json_encode($fieldsOld);
    
    // $restKey = 'AAAASqTR_nI:APA91bFo4jMPODD5A0nI-vei70IKmraVTUITeobw8RGtFYUpMZK_esBZMlLufNShPtBwOeTMlQIteVpGNyditABYl1StVzTShBzyK3n41EnTqpwrqNOJQCyQL9BA69V19_zmfsa9Zdf0'; //'ZWJkMjA0ZDktNDFiMy00MDYyLThiZGItNzcwNDYxYWE5NmFl'; //# [Keys & IDS] REST API KEY from onesignal site.
        $restKey = 'AAAA_TVEwdg:APA91bHaO3H7-5kQG1XU0oL2ubuWtAoRrOpBFr541575lVL6YpU5sjpLfR_XFD8P7MhGPbjKSefhg1owepliWMh6LLEO1d2ssCT8xqhqC0hmx23knKQYxqX4fGC7d-xlone3JYWbMVh3'; //'ZWJkMjA0ZDktNDFiMy00MDYyLThiZGItNzcwNDYxYWE5NmFl'; //# [Keys & IDS] REST API KEY from onesignal site.

    $restKeyOld = '1087520424408';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
        'Authorization: Key= ' . $restKey));
    curl_setopt($ch, CURLOPT_HEADER, FALSE);

//curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

    $result = curl_exec($ch);
    curl_close($ch);
    
    
    ///////////////////////Old///////////////////////////
    $chOld = curl_init();
    curl_setopt($chOld, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($chOld, CURLOPT_POST, true);
    curl_setopt($chOld, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
        'Authorization: Basic ' . $restKeyOld));
    curl_setopt($chOld, CURLOPT_HEADER, FALSE);
    
     curl_setopt($chOld, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($chOld, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($chOld, CURLOPT_POSTFIELDS, $fieldsOld);

    $result = curl_exec($chOld);
    curl_close($chOld);
    
    
//print_r($result);
//echo "<br/>";
//return $result;
}

function init_push_hana($page_name, $load_id, $user_device_id, $head, $msg, $other = '') {
    $msg = $msg;
    $head = $head;
    $content = array("en" => $msg);
    $headings = array("en" => $head);
    $fields = array(
        'notification' => array(
            "title" => $head,
            "body" => $msg,
            "sound" => "default",
            "click_action" => "FCM_PLUGIN_ACTIVITY",
            "icon" => "http://mtm-autoparts.com/ad_panel/views/panel_multi/_assets/shop/images/logo.png"
            ),
        'android_sound' => "default",
        "sound" => "default",
        'to' => $user_device_id,//'a0859edd-ebc0-496f-a7ae-545365ad4035', //# [Keys & IDS] ONESIGNAL APP ID from onesignal site.
//'include_player_ids' => array('5f09ff33-7102-4f63-9699-9d589a445a62'),
        'include_player_ids' => array($user_device_id),
        //# user id which sent from Appicaition .
        'data' => array(
            "foo" => "bar",
            "landing_page" => $page_name,
            "id" => $load_id,
            "other" => $other,
            "sound" => "default",
            "android_sound" => "default",
        ),
        'android_group' => 'sameGroup',
        'large_icon' => 'http://mtm-autoparts.com/ad_panel/views/panel_multi/_assets/shop/images/logo.png',//'https://mydayapp.net/myday/onesignal_icon.png',
        'contents' => $content,
        'headings'=>$headings,
        "priority"=>"high",
        "restricted_package_name"=>""
            //'big_picture' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png'
    );
    $fieldsOld = array(
        'android_sound' => "default",
        "sound" => "default",
        'app_id' => 'a0859edd-ebc0-496f-a7ae-545365ad4035', //# [Keys & IDS] ONESIGNAL APP ID from onesignal site.
//'include_player_ids' => array('5f09ff33-7102-4f63-9699-9d589a445a62'),
        'include_player_ids' => array($user_device_id),
        //# user id which sent from Appicaition .
        'data' => array(
            "foo" => "bar",
            "page_name" => $page_name,
            "id" => $load_id,
            "other" => $other,
            "sound" => "default",
            "android_sound" => "default",
        ),
        'android_group' => 'sameGroup',
        'large_icon' => 'http://shop2.gt4host.com/ad_panel/views/panel_multi/_assets/shop/images/logo.png',//'https://mydayapp.net/myday/onesignal_icon.png',
        'contents' => $content,
        'headings'=>$headings
            //'big_picture' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png'
    );

    $fields = json_encode($fields);
    $fieldsOld = json_encode($fieldsOld);
    
    $restKey = 'AAAAOobZ0b4:APA91bFiELzhRmKJtfbyAQ-UIMtebQrjBefT4kC3aMO_R_SQohSJb3FA7lFRC6rRF3pe9fBycKWuS5YF4aBGmSRzO8sbNHe_z-vSHM-aMcJk8Y0nJW5E0rqgBJwlhjXV1ROIV9rYyOLl'; //'ZWJkMjA0ZDktNDFiMy00MDYyLThiZGItNzcwNDYxYWE5NmFl'; //# [Keys & IDS] REST API KEY from onesignal site.
    $restKeyOld = '781604921541';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
        'Authorization: Key= ' . $restKey));
    curl_setopt($ch, CURLOPT_HEADER, FALSE);

//curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

    $result = curl_exec($ch);
    curl_close($ch);
    
    
    ///////////////////////Old///////////////////////////
    $chOld = curl_init();
    curl_setopt($chOld, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($chOld, CURLOPT_POST, true);
    curl_setopt($chOld, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
        'Authorization: Basic ' . $restKeyOld));
    curl_setopt($chOld, CURLOPT_HEADER, FALSE);
    
     curl_setopt($chOld, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($chOld, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($chOld, CURLOPT_POSTFIELDS, $fieldsOld);

    $result = curl_exec($chOld);
    curl_close($chOld);
    
    
//print_r($result);
//echo "<br/>";
//return $result;
}


?>