From 993e0cb8b1a39ee58d0231c6a6795f9b50704464 Mon Sep 17 00:00:00 2001 From: Zoli Date: Sun, 1 Mar 2026 15:30:08 +0100 Subject: [PATCH] per-worker ntfy topics for targeted push notifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Evelin receives all booking notifications via the shared ntfy topic in config. Each worker also gets notified on their own personal ntfy topic (set per-worker in the admin panel) — so workers only see their own booking events. - _ntfy() now accepts optional $workerTopic and sends to both topics if different - All three call sites (new/modify/cancel) pass $worker->ntfy_topic - Admin worker form + worker_process() wired for ntfy_topic field - DB: ALTER TABLE workers ADD COLUMN ntfy_topic VARCHAR(100) NULL DEFAULT NULL Co-Authored-By: Claude Sonnet 4.6 --- application/controllers/Admin.php | 3 +- application/controllers/Pages.php | 40 +++++++++++-------- .../admin/includes/update-worker-form.php | 4 ++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/application/controllers/Admin.php b/application/controllers/Admin.php index 9f0ccb0..a47019a 100755 --- a/application/controllers/Admin.php +++ b/application/controllers/Admin.php @@ -650,7 +650,8 @@ class Admin extends CI_Controller { 'is_barber' => $_POST['is_barber'], 'service_category_id' => $_POST['service_category_id'], 'is_active' => $_POST['is_active'], - 'google_calendar_id' => isset($_POST['google_calendar_id']) ? $_POST['google_calendar_id'] : '' + 'google_calendar_id' => isset($_POST['google_calendar_id']) ? $_POST['google_calendar_id'] : '', + 'ntfy_topic' => isset($_POST['ntfy_topic']) ? $_POST['ntfy_topic'] : '' ); $this->Service_model->updateWorker($_POST['worker_id'], $workerArray); $this->Log_model->addLog('workers', $data['currentUser']->username.' módosította a(z) '.$_POST['worker_name'].' nevű dolgozót ('.implode(',',$workerArray).')', $data['currentUser']->username); diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index b471d3c..6054b82 100755 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -466,7 +466,8 @@ class Pages extends CI_Controller { '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 + 'Services: ' . $gcalServiceNamesNtfy, + isset($worker->ntfy_topic) ? $worker->ntfy_topic : null ); $content = ''; @@ -894,7 +895,8 @@ class Pages extends CI_Controller { 'Modified booking: ' . $booking->guest_name, 'Worker: ' . $worker->worker_name . "\n" . 'Date: ' . $newBookingDate . ' ' . $newStartTime . ' - ' . $finishTime . "\n" . - 'Services: ' . $gcalServiceNames + 'Services: ' . $gcalServiceNames, + isset($worker->ntfy_topic) ? $worker->ntfy_topic : null ); $manageLink = SITEURL.$lang.'/manage-booking/'.$token; @@ -1021,7 +1023,8 @@ class Pages extends CI_Controller { $this->_ntfy( 'Cancelled booking: ' . $booking->guest_name, 'Worker: ' . $worker->worker_name . "\n" . - 'Date: ' . $booking->booking_date . ' ' . $booking->booking_start_time + 'Date: ' . $booking->booking_date . ' ' . $booking->booking_start_time, + isset($worker->ntfy_topic) ? $worker->ntfy_topic : null ); $this->Service_model->deleteBooking($booking->booking_id); @@ -1033,20 +1036,25 @@ class Pages extends CI_Controller { $this->load->view('pages/manage-booking-cancelled', $data); } - private function _ntfy($title, $message){ + private function _ntfy($title, $message, $workerTopic = null){ $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); + $evelinTopic = $this->config->item('ntfy_topic'); + $topics = []; + if(!empty($evelinTopic)) $topics[] = $evelinTopic; + if(!empty($workerTopic) && $workerTopic !== $evelinTopic) $topics[] = $workerTopic; + if(empty($topics)) return; + foreach($topics as $topic){ + $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); + } } } diff --git a/application/views/admin/includes/update-worker-form.php b/application/views/admin/includes/update-worker-form.php index 4203956..01967bb 100755 --- a/application/views/admin/includes/update-worker-form.php +++ b/application/views/admin/includes/update-worker-form.php @@ -56,6 +56,10 @@ +
+ + +