_ank_id = $ank_id; //get survey title and link if($ank_id > 0){ SurveyInfo::getInstance()->SurveyInit($ank_id); $this->_ank_title = SurveyInfo::getSurveyColumn('naslov'); $this->_ank_link = SurveyInfo::getSurveyLink(); } } public function display() { global $admin_type, $global_user_id, $lang; // Izpis vseh poslanih sporocil if ($admin_type == 0) { //is survey activated $act = sisplet_query("SELECT active FROM srv_anketa WHERE id='" . $this->_ank_id . "'", 'obj'); if($act->active != 1) echo '

'.$lang['srv_anketa_noactive2'].'

'; $this->sendMessageForm(); if(isset($_GET['FCM_response'])) echo '

'.$_GET['FCM_response']; } } // Obrazec za posiljanje notificationa private function sendMessageForm() { global $admin_type, $global_user_id, $lang; //FORM FOR WEB PUSH NOTIFICATIONs echo '

'; echo ''.$lang["srv_wpn"].''; echo '
'; /* echo ''.$lang['srv_notifications_send_reciever'].': '; // Checkboxa za posiljenje vsem uporabnikoom (slo in ang) echo '
'; echo '

'; */ echo ''; echo '' . $lang['srv_notifications_send_title'] . ':

'; echo '' . $lang['srv_notifications_send_text'] . ':

'; //echo '

'; //echo '

'; echo ''; echo '

' . $_POST['maza_result'] . '

'; echo '
'; echo '
'; } //PWA public function ajax_wpn_save_subscription(){ //whole link for endpoint - browser request link and endpoint key of user $endpoint = $_POST['endpoint']; //last slash index $lsi = strrpos($endpoint, '/'); //endpoint key $endpoint_key = substr($endpoint, $lsi + 1); //endpoint link $endpoint_link = substr($endpoint, 0, $lsi + 1); sisplet_query("INSERT INTO browser_notifications_respondents (timestamp_joined, endpoint_link, endpoint_key, public_key, auth) " . "VALUES (NOW(), '".$endpoint_link."', '".$endpoint_key."', '".$_POST['keys']['p256dh']."', '".$_POST['keys']['auth']."')"); echo 'Subscription added'; } public function sendWebPushNotificationsToAll(){ //global $FCM_server_key; $title = $_POST['wpn_title']; $message = $_POST['wpn_message']; $payload = array('title'=>$title, 'message'=>$message, 'link'=>$this->_ank_link); /*$notifications = [ // this is the structure for the working draft from october 2018 (https://www.w3.org/TR/2018/WD-push-api-20181026/) [ 'subscription' => Subscription::create([ "endpoint" => "https://updates.push.services.mozilla.com/wpush/v1/gAAAAABdoHSjAgtlSI2QNu_D6p3WDWITErDHYLWfbf37pgJd1HYnIukVaHfAxAOi4gxzPq1c8baWSMk9O6YkSOrbn7brlWaLpcNnKba1xgia13ESTwKNaevwY9_ciy3ojB4IXprryHTb", "keys" => [ 'p256dh' => "BIvluRM0T5ezCbH_IwEhsDr8D-kXq4sRfgmaG4OKOGbqrE6CWwcrvY5S7YpqfMgn_ZqOHlLaZX11skBWar3Xj3w", 'auth' => "Tqco8e4PIAZL9zogxks3qQ" ] ]) ], [ 'subscription' => Subscription::create([ "endpoint" => "https://fcm.googleapis.com/fcm/send/cDZBBiO8nwA:APA91bG6pQJNapbmiT0zMED_HEiQNi2OxgmAJbjqWnny1H78FXFRzJXtcBi62xwdZHOr9GWrBsbE5ePPK58m9H9ZKhy0Q8TFKCu-Os-ykAN2IJL4lPVcUyslBMt8sCABlomHUHl8AQLR", "keys" => [ 'p256dh' => "BPyTEM7mLZAFQm-8bSsVmAJRDMeCTjwSmOCJXieK-xtwcRsKE9zLHZRpfp52ChQzrDZLi_n0RdBiX5yydC7DL90", 'auth' => "iSKAhIqNvjlaOhXzk4ulJw" ] ]) ], [ 'subscription' => Subscription::create([ "endpoint" => "https://updates.push.services.mozilla.com/wpush/v2/gAAAAABdpZDL1nFRXedBJYYfTwdcqfrf2khsEXllMLEWPBIolO1t1wkptE7HzkypkPDEVwYq0ju1kNblwJHxA9v0k05oVNCuxBi0l0dDqsrZZ_TRao_hDprjzoSuuHE5z4zrTzbTwwxKqmxDYvF_1Ty28qaUaaLqFJGgOTgSjN9W3bkifRqDZnQ", "keys" => [ 'p256dh' => "BESWycM2xqcaFcvG1kYWGpnamq6IZd8mhGtSQpUsROBn0ejJmwI_vptgpW4jBwbQrcb-T8sXvmRRZ4HY9VLWJes", 'auth' => "WnRV6LQEYcvwb21DnpXzkA" ] ]) ], [ 'subscription' => Subscription::create([ "endpoint" => "https://fcm.googleapis.com/fcm/send/cyGorE1fYnM:APA91bHq1if5UrRr1uI8HLD92M2OCekH1kH6q7HmrINkMFHmLq_RtuytWb9DKo2446WgvDRbzUjQXwQ88_b70NzOUBBFWhxaslJuQFyJZPHIkxRf--MIHTY-KSQ1JcPQYcED1QreaEZf", "keys" => [ 'p256dh' => "BPTZTRDEztn_YpAvdv4wjtCyNqo0RNFfWbjm9r7bgyZh2RBZgDvitaW_68hNC6cYGzKGJM9aMpGi59-_H8HYSn8", 'auth' => "M79ZKrfJwEzPfHIpkN-tIw" ] ]) ] ];*/ //get all subscriptions and put them in array $subscriptions = sisplet_query("SELECT endpoint_link, endpoint_key, public_key, auth FROM browser_notifications_respondents", 'array'); $notifications = array(); foreach ($subscriptions as $subsc){ $subscription = array("endpoint"=>$subsc['endpoint_link'].$subsc['endpoint_key'], "keys"=>array('p256dh' => $subsc['public_key'],'auth' => $subsc['auth'])); array_push($notifications, array('subscription' => Subscription::create($subscription))); } $auth = array( 'VAPID' => array( 'subject' => 'mailto:enklikanketa@gmail.com', 'publicKey' => 'BNVIBdCsC6vkmByQJ861pusHN1mV76X3mvAa1u4PxmleTv2m2whcEu9Elhh8Qz3XnqV6k58YCSVqaafl3bhPKLU', 'privateKey' => 'c7mxuK7Nexe4NHnCtYE79p0iHzaXZGikWpua7z66dQg', ), ); $webPush = new WebPush($auth); // send multiple notifications with payload foreach ($notifications as $notification) { $webPush->sendNotification( $notification['subscription'], json_encode($payload) ); } // handle eventual errors here, and remove the subscription from your server if it is expired foreach ($webPush->flush() as $report) { $endpoint = $report->getRequest()->getUri()->__toString(); if ($report->isSuccess()) { echo "
[v] Message sent successfully for subscription {$endpoint}."; } else { echo "
[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}"; } } } } ?>