From 579d7088a8c4558f2198a6e4336f0e226a0a88a1 Mon Sep 17 00:00:00 2001 From: Daniel Spitzer Date: Tue, 21 Jan 2025 18:18:22 +0100 Subject: [PATCH] Kalender Updates * Update 1 day Reminder + autoscript --- application/Calendar/CalendarController.php | 2 +- application/Calendar/CalendarModel.php | 22 +++++++ .../CalendarTemplateModel.php | 6 ++ .../check_calendar_customer_reminder.php | 60 +++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 scripts/calendar/check_calendar_customer_reminder.php diff --git a/application/Calendar/CalendarController.php b/application/Calendar/CalendarController.php index 1e605fee2..373b88a18 100644 --- a/application/Calendar/CalendarController.php +++ b/application/Calendar/CalendarController.php @@ -94,7 +94,7 @@ class CalendarController extends mfBaseController if ($r->customer_info_type == 1) { $body = $r->customer_info_text; $email = new Emailnotification(); - $email->setSubject('Inbetriebnahme'); + $email->setSubject('Technikertermin Xinon'); $email->setBody($body); $email->setFrom('termin@xinon.at', 'Terminbestätigung'); $email->setTo($r->customer_info_type_text); diff --git a/application/Calendar/CalendarModel.php b/application/Calendar/CalendarModel.php index 6ef796282..dd99a51fd 100644 --- a/application/Calendar/CalendarModel.php +++ b/application/Calendar/CalendarModel.php @@ -399,6 +399,28 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda return $return; } + public static function getCalendarEventsReminder() + { + $dbcal = self::dbKalender(); + $timecalcend = time() + 86400; + $timecalcstart = $timecalcend - 3600; + + $sql = "SELECT `id`,`name`,`customer_info_send`,`start_time`,`end_time`,`event_type` FROM `cal_events` WHERE `customer_info_reminder`= 1 AND `customer_info_send` IS NOT NULL AND `event_type` > 1 AND `start_time` BETWEEN $timecalcstart AND $timecalcend"; + $res = $dbcal->query($sql); + while ($data = $dbcal->fetch_array($res)) + { + $rows[] = array( + 'id' => $data['id'], + 'name' => $data['name'], + 'customer_info_send' => $data['customer_info_send'], + 'start_time' => $data['start_time'], + 'end_time' => $data['end_time'], + 'event_type' => $data['event_type'] + ); + } + return ($rows); + } + public static function getCalendarEvent($id) { $calendar = self::search(array("user_id" => $me)); diff --git a/application/CalendarTemplate/CalendarTemplateModel.php b/application/CalendarTemplate/CalendarTemplateModel.php index 6f65f34e0..664e85912 100644 --- a/application/CalendarTemplate/CalendarTemplateModel.php +++ b/application/CalendarTemplate/CalendarTemplateModel.php @@ -126,6 +126,12 @@ class CalendarTemplateModel $where .= " AND event_type=$event_type"; } } + if (array_key_exists("is_reminder", $filter)) { + $is_reminder = $filter['is_reminder']; + if (is_numeric($is_reminder)) { + $where .= " AND is_reminder=$is_reminder"; + } + } //var_dump($filter, $where);exit; return $where; diff --git a/scripts/calendar/check_calendar_customer_reminder.php b/scripts/calendar/check_calendar_customer_reminder.php new file mode 100644 index 000000000..361ea8334 --- /dev/null +++ b/scripts/calendar/check_calendar_customer_reminder.php @@ -0,0 +1,60 @@ +id); +define("INTERNAL_USER_USERNAME", $me->username); + +$sendReminder = CalendarModel::getCalendarEventsReminder(); +if (empty($sendReminder)) { + die(); +} +foreach ($sendReminder as $reminder) { + $dbcal = CalendarModel::dbKalender(); + $sql = "UPDATE cal_events SET customer_info_reminder=2 WHERE id=" . $reminder['id']; + if (!$dbcal->query($sql)) { + echo "Error updating record: " . $dbcal->error; + die(); + } + $calendarTemplate = CalendarTemplateModel::search(array("event_type" => $reminder['event_type'], "is_reminder" => 1)); + if (empty($calendarTemplate)) { + continue; + } + $hour = (int)date('H', $reminder['start_time']); + if ($hour < 12) { + $vm = "vormittags"; + } else { + $vm = "nachmittags"; + } + $text = str_replace("[&&date&&]", date("d.m.Y", $reminder['start_time']), $calendarTemplate[0]->text); + $text = str_replace("[&&start&&]", date("H:i", $reminder['start_time']), $text); + $text = str_replace("[&&end&&]", date("H:i", $reminder['end_time']), $text); + $text = str_replace("[&&vmnm&&]", $vm, $text); + $reminderInfo = json_decode($reminder['customer_info_send'], true); + $customerInfoType = $reminderInfo['customer_info_type']; + $customerInfo = $reminderInfo['customer_info_type_text']; + if ($customerInfoType == 1) { + $body = $text; + $email = new Emailnotification(); + $email->setSubject('Technikertermin Xinon'); + $email->setBody($body); + $email->setFrom('termin@xinon.at', 'Terminbestätigung'); + $email->setTo($customerInfo); + $email->send(); + } else if ($customerInfoType == 2) { + $sms = new SmsNotification(); + $body = "Xinon Terminbestätigung:" . PHP_EOL . $text; + $sms->setBody($body); + $sms->setRecipient($customerInfo); + $sms->send(); + } +} \ No newline at end of file