Kalender Update Feature Erweiterung

* Absage von Kundenterminen

Behobene Bugfixes:
* Beschreibungsfeld kann nun immer Leer gesetzt werden.
* SPIN wird nun nur 1mal ins Beschreibungsfeld eingesetzt.
This commit is contained in:
Daniel Spitzer
2025-04-30 12:58:36 +02:00
parent 597742d771
commit 4ec4e15e05
5 changed files with 302 additions and 40 deletions

View File

@@ -168,6 +168,44 @@ class CalendarController extends mfBaseController
$id = ($r->id);
CalendarModel::deleteCalendarEvent($r);
die();
case "cancelCalendarEvent":
$r = $this->request;
$id = ($r->id);
if ($r->customer_info_check) {
if ($r->customer_info_type == 1) {
$body = $r->customer_info_text;
$email = new Emailnotification();
$email->setSubject('Technikertermin Xinon Absage');
$email->setBody($body);
$email->setFrom('termin@xinon.at', 'Terminbestätigung');
$email->setTo($r->customer_info_type_text);
$email->send();
} else if ($r->customer_info_type == 2) {
$sms = new SmsNotification();
$customerText = trim($r->customer_info_text);
$body = "Xinon Terminabsage:" . PHP_EOL . $customerText;
$sms->setBody($body);
$customerNumber = trim($r->customer_info_type_text);
$customerNumber = str_replace(" ", "", $customerNumber);
$customerNumber = str_replace("(", "", $customerNumber);
$customerNumber = str_replace(")", "", $customerNumber);
$customerNumber = str_replace("-", "", $customerNumber);
$customerNumber = str_replace("/", "", $customerNumber);
$customerNumber = str_replace(".", "", $customerNumber);
$customerNumber = str_replace(",", "", $customerNumber);
$customerNumber = str_replace(";", "", $customerNumber);
$customerNumber = str_replace(":", "", $customerNumber);
if (preg_match('/^0/', $customerNumber)) {
$customerNumber = "+43" . substr($customerNumber, 1);
}
$sms->setRecipient($customerNumber);
if (!empty($customerNumber) && !empty($customerText)) {
$sms->send();
}
}
}
CalendarModel::cancelCalendarEvent($r,$this->me);
die();
case "updateCalendarColor":
$r = $this->request;
$calendar_id = ($r->calendar_id);

View File

@@ -461,7 +461,7 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda
}
$Allcalendar['Daniel Whoknows'] = 2;
$Allcalendar['Stefan Plaschg'] = 26;
$res = $dbcal->select("cal_events", "id, uuid, calendar_id, user_id, start_time, end_time, timezone, all_day_event, name, description, location, repeat_end_time, reminder, ctime, mtime, muser_id, busy, status, resource_event_id, private, rrule, background, files_folder_id, read_only, category_id, exception_for_event_id, recurrence_id, recurrence, is_organizer,event_type,customer,customer_info,customer_info_send,customer_info_reminder,busy,attendees,organizer,is_organizer,accepted", "1=1 AND id='" . $id . "' ORDER BY id");
$res = $dbcal->select("cal_events", "id, uuid, calendar_id, user_id, start_time, end_time, timezone, all_day_event, name, description, location, repeat_end_time, reminder, ctime, mtime, muser_id, busy, status, resource_event_id, private, rrule, background, files_folder_id, read_only, category_id, exception_for_event_id, recurrence_id, recurrence, is_organizer,event_type,customer,customer_info,customer_info_send,customer_info_reminder,busy,attendees,organizer,is_organizer,accepted,canceld", "1=1 AND id='" . $id . "' ORDER BY id");
if ($dbcal->num_rows($res)) {
$data = $dbcal->fetch_array($res);
if ($data['recurrence']) {
@@ -559,6 +559,7 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda
'customer_info_reminder' => array('customer_info_reminder' => $data['customer_info_reminder']),
'privateflag' => array('privateflag' => $data['private'], 'order' => $data['private']),
'isorganizer' => array('isorganizer' => $data['is_organizer']),
'canceld' => array('canceld' => $data['canceld']),
'attendees' => array('attendees' => json_encode($AttendeeArray)),
'organizer' => array('organizer' => self::replace_unicode_sequences($data['organizer'])),
'accepted' => array('accepted' => $data['accepted']),
@@ -997,6 +998,103 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda
die();
}
public static function cancelCalendarEvent($r,$me)
{
$id = $r->id;
$users = $r->users;
foreach ($users as $key => $value) {
$user_id = $value;
}
date_default_timezone_set('Europe/Berlin');
header('Content-Type: application/json');
$db = self::dbKalender();
$res = $db->select("cal_calendars", "id,ms_user_id", "id = '" . $user_id . "' LIMIT 1");
if ($db->num_rows($res)) {
$result = $db->fetch_object($res);
$microsoft_user_id = $result->ms_user_id;
}
$updateArray = [];
$res = $db->select("cal_events", 'id,microsoft_id,name,microsoft_ical_uid,start_time,end_time', "id = '" . $id . "' LIMIT 1");
if ($db->num_rows($res)) {
$result = $db->fetch_object($res);
if (($r->customer_info_type)) {
$customer_info_type = $r->customer_info_type;
}
if (($r->customer_info_text)) {
$customer_info_text = $r->customer_info_text;
}
if (($r->customer_info_type_text)) {
$customer_info_type_text = $r->customer_info_type_text;
}
$customerJson = array('customer_info_type' => $customer_info_type, 'customer_info_text' => $customer_info_text, 'customer_info_type_text' => $customer_info_type_text);
$updateArray['customer_info'] = json_encode($customerJson);
if ($r->customer_info_check) {
$customerJson['sendby'] = $me->name;
$customerJson['sendtime'] = time();
$updateArray['customer_info_send'] = json_encode($customerJson);
}
$newname = "Absage: " . $result->name;
$microsoft_id = $result->microsoft_id;
$updateArray['name'] = $newname;
$updateArray['busy'] = '0';
$updateArray['start_time'] = $result->start_time;
$updateArray['end_time'] = $result->end_time;
$updateArray['customer_info_reminder'] = 0;
$updateArray['canceld'] = 1;
$db->update("cal_events", $updateArray, "id = '" . $id . "'");
$json_data = json_encode($updateArray);
$data = [];
$data['ms_user_id'] = $microsoft_user_id;
$data['ms_event_id'] = $microsoft_id;
$data['data'] = $json_data;
$data['type'] = 'u';
$data['status'] = 'p';
$data['edit'] = time();
$data['create'] = time();
$data['edit_by'] = 89;
$data['create_by'] = 89;
$db->insert("TheTool_CalendarQueue", $data);
$res = $db->select("cal_events", 'id,microsoft_id,name,microsoft_ical_uid,start_time,end_time,calendar_id', "id != '" . $id . "' AND microsoft_ical_uid = '" . $result->microsoft_ical_uid . "' ");
while ($row = $db->fetch_object($res)) {
$updateArray = [];
$updateArray['name'] = $newname;
$updateArray['busy'] = '0';
$updateArray['start_time'] = $row->start_time;
$updateArray['end_time'] = $row->end_time;
$updateArray['customer_info_reminder'] = 0;
$updateArray['canceld'] = 1;
$updateArray['customer_info'] = json_encode($customerJson);
if ($r->customer_info_check) {
$customerJson['sendby'] = $me->name;
$customerJson['sendtime'] = time();
$updateArray['customer_info_send'] = json_encode($customerJson);
}
$db->update("cal_events", $updateArray, "id = '" . $row->id . "'");
$json_data = json_encode($updateArray);
$rescal = $db->select("cal_calendars", "id,ms_user_id", "id = '" . $row->calendar_id . "' LIMIT 1");
$resultcal = $db->fetch_object($rescal);
$data = [];
$data['ms_user_id'] = $resultcal->ms_user_id;
$data['ms_event_id'] = $row->microsoft_id;
$data['data'] = $json_data;
$data['type'] = 'u';
$data['status'] = 'p';
$data['edit'] = time();
$data['create'] = time();
$data['edit_by'] = 89;
$data['create_by'] = 89;
$db->insert("TheTool_CalendarQueue", $data);
}
}
die();
}
public static function generateDataRecurrence($graph)
{
$data = [];