diff --git a/application/config/google_calendar.php b/application/config/google_calendar.php index fe8329b..842bbcb 100644 --- a/application/config/google_calendar.php +++ b/application/config/google_calendar.php @@ -3,3 +3,4 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $config['gcal_service_account_path'] = APPPATH . 'config/service-account-key.json'; $config['gcal_evelin_calendar_id'] = 'katozoltan0804@gmail.com'; // Evelin's Calendar ID (e.g. her Gmail address) +$config['ntfy_topic'] = ''; // ntfy.sh topic for push notifications (e.g. 'studiobeve-bookings-x7k2') diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index a7a02ce..b471d3c 100755 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -460,6 +460,15 @@ class Pages extends CI_Controller { $this->Service_model->updateBookingCalEvents($newBooking->booking_id, $workerEventId, $ownerEventId); } + // ntfy push notification + $gcalServiceNamesNtfy = implode(', ', array_map(function($s){ return $s->service_name_no; }, $serviceArray)); + $this->_ntfy( + 'New booking: ' . $bookingArray['guest_name'], + 'Worker: ' . $worker->worker_name . "\n" . + 'Date: ' . $bookingArray['booking_date'] . ' ' . $bookingArray['booking_start_time'] . ' - ' . $bookingArray['booking_finish_time'] . "\n" . + 'Services: ' . $gcalServiceNamesNtfy + ); + $content = ''; switch($_POST['lang']){ @@ -880,6 +889,14 @@ class Pages extends CI_Controller { } $this->Service_model->updateBookingCalEvents($booking->booking_id, $newWorkerEventId, $newOwnerEventId); + // ntfy push notification + $this->_ntfy( + 'Modified booking: ' . $booking->guest_name, + 'Worker: ' . $worker->worker_name . "\n" . + 'Date: ' . $newBookingDate . ' ' . $newStartTime . ' - ' . $finishTime . "\n" . + 'Services: ' . $gcalServiceNames + ); + $manageLink = SITEURL.$lang.'/manage-booking/'.$token; $totalServicePrice = 0; foreach($serviceArray as $s){ $totalServicePrice += $s->service_price; } @@ -1000,6 +1017,13 @@ class Pages extends CI_Controller { $this->googlecalendar->deleteEvent($evelinCalId, $booking->gcal_event_id_owner); } + // ntfy push notification + $this->_ntfy( + 'Cancelled booking: ' . $booking->guest_name, + 'Worker: ' . $worker->worker_name . "\n" . + 'Date: ' . $booking->booking_date . ' ' . $booking->booking_start_time + ); + $this->Service_model->deleteBooking($booking->booking_id); $data['selectedLang'] = $lang; @@ -1009,5 +1033,20 @@ class Pages extends CI_Controller { $this->load->view('pages/manage-booking-cancelled', $data); } + private function _ntfy($title, $message){ + $this->config->load('google_calendar'); + $topic = $this->config->item('ntfy_topic'); + if(empty($topic)) return; + $ch = curl_init('https://ntfy.sh/' . $topic); + curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $message, + CURLOPT_HTTPHEADER => ['Title: ' . $title, 'Priority: high', 'Tags: calendar'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 5, + ]); + curl_exec($ch); + curl_close($ch); + } }