<?php
include(__DIR__.'/../includes/sysinit.php');
require_once(SABLE_CLASS_PATH.'sable_push.php');
$sablePush = new SablePush;
$array = array();
$rows = array();
$notifList = $sablePush->listNotificationUser(base64_decode($_POST['sablePushID']));
if (is_array($notifList) && !empty($notifList))
{
	$record = 0;
	foreach ($notifList as $key) 
	{
		$data = [];
		$data['title']	= $key['push_notification_title'];
		$data['msg']	= $key['push_notification_message'];
		$data['icon']	= SABLE_MEDIA_PATH.'images/manifest_logo.png'; //different icons can be specified for diferrent messages
		$data['badge']	= SABLE_MEDIA_PATH.'images/notification_badge.png'; //different icons can be specified for diferrent messages
		$data['url']	= empty($key['push_url']) ? SABLE_URL_ROOT : $key['push_url']; //the url the user should be take to when they click on the notification
		
		$rows[]			= $data;
		$ts 			= strtotime(date('Y-m-d H:i:s'))+($key['push_notification_repeat']*60);
		$nextime		= date('Y-m-d H:i:s', $ts);
		$sablePush->updateNotification($key['push_notification_id'], $nextime);
		$record++;
	}
	$array['notif'] = [];
	$array['notif'] = $rows;
	$array['count'] = $record;
	$array['result'] = 1;
}
else
{
	$array['notif'] = [];
	
	$data['title'] 		= '';
	$data['msg'] 		= '';
	$data['icon'] 		= '';
	$data['url'] 		= '';	
	
	$array['notif'][] 	= $data;
	$array['count'] 	= 0;
	$array['result'] 	= 0;	
}
unset($sablePush);
echo json_encode($array);
?>