diff --git a/Layout/default/Calendar/View.php b/Layout/default/Calendar/View.php index 6d7f7c853..c2a17b999 100644 --- a/Layout/default/Calendar/View.php +++ b/Layout/default/Calendar/View.php @@ -31,6 +31,9 @@ foreach ($rights as $key => $right) : } elseif ($CalendarAll[$key]->calendar_name) { $calendarName = $CalendarAll[$key]->calendar_name; } + if (!($CalendarAll[$key]->microsoft_id)) { + $calendarName .= ' 📅'; + } } if ($calendarName) { @@ -131,7 +134,7 @@ endforeach; class="fa-duotone fa-solid fa-phone-volume fa-calendar-call fa-calendar-call-search"> @@ -629,11 +632,25 @@ endforeach; name="calendar-users"> $value) : if ($rights[$value] != "all") continue; + $hasMicrosoftId = $CalendarAll[$value]->microsoft_id ?: 0; + $optionClass = $hasMicrosoftId ? '' : 'no-microsoft-id'; + $optionStyle = $hasMicrosoftId ? '' : ''; + if ($value != $Calendar[0]->go_calendar_id) : ?> - + + value="" + class="" + style="" + data-has-microsoft-id=""> + + @@ -665,11 +682,18 @@ endforeach; class="fa-solid fa-arrow-right-from-bracket">
-
diff --git a/application/Calendar/CalendarModel.php b/application/Calendar/CalendarModel.php index 5f2039b9c..ab035b5e4 100644 --- a/application/Calendar/CalendarModel.php +++ b/application/Calendar/CalendarModel.php @@ -81,11 +81,8 @@ class CalendarModel public static function convertToSummertime($timestamp) { - // Create a DateTime object from the Unix timestamp $date = new DateTime(); $date->setTimestamp($timestamp); - - // Set the timezone to Europe/Berlin $date->setTimezone(new DateTimeZone('Europe/Berlin')); if ($date->format('I') == 1) { $cest = 7200; @@ -93,7 +90,6 @@ class CalendarModel $cest = 3600; } $unixtimestamp = $date->getTimestamp() + $cest; - // Format the date and time return date('Y-m-d H:i:s', $unixtimestamp); } @@ -111,7 +107,6 @@ class CalendarModel '\u00e9' => 'é', '\u00e0' => 'à', '\u00f3' => 'ó', - // Weitere Unicode-Zuordnungen können hier hinzugefügt werden ]; foreach ($unicode_map as $unicode => $char) { @@ -682,6 +677,10 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $busy = ($r->busy); $users = ($r->users); $attendees = ($r->attendees); + $attendeesOriginal = $attendees; + if (is_string($attendees)) { + $attendees = json_decode($attendees, true); + } $privateflag = ($r->privateflag); foreach ($users as $key => $value) { $user_id = $value; @@ -816,26 +815,339 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $db->insert("cal_events_attachments", $data); $db->delete("tmp_cal_events_attachments", "id = '" . $tmpid . "'"); } + + } + $currentBg = $db->select("cal_events", "background", "id = '" . $id . "' LIMIT 1"); + if ($db->num_rows($currentBg)) { + $bgData = $db->fetch_array($currentBg); + + if ($bgData['background']=='EBF1E2') + { + $pupdateArray['background'] = "EBF1E3"; + } else + { + $pupdateArray['background'] = "EBF1E2"; + } + + $db->update("cal_events", $pupdateArray , "id = '" . $id . "'"); } $updateArray['attachments'] = $attachments; $updateArray['end_time'] = $originalend; } if ($attendees) - $updateArray['attendees'] = $attendees; + $updateArray['attendees'] = $attendeesOriginal; $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; + if (!empty($microsoft_id) && !empty($microsoft_user_id)) { + $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); + $db->insert("TheTool_CalendarQueue", $data); + } + $resMain = $db->select("cal_events", 'linked_event_uid,is_organizer', "id = '" . $id . "' LIMIT 1"); + if ($db->num_rows($resMain)) { + $mainEvent = $db->fetch_object($resMain); + if ($mainEvent->is_organizer == 1 && !empty($mainEvent->linked_event_uid)) { + $sqlLinked = "SELECT ce.id, ce.calendar_id, cc.ms_user_id microsoft_id + FROM cal_events ce + LEFT JOIN cal_calendars cc ON ce.calendar_id = cc.id + WHERE ce.linked_event_uid = '" . $mainEvent->linked_event_uid . "' + AND ce.id != '" . $id . "' + AND ce.is_organizer = 0"; + $resLinked = $db->query($sqlLinked); + + while ($linkedEvent = $db->fetch_object($resLinked)) { + if (empty($linkedEvent->microsoft_id)) { + $linkedUpdateArray = array(); + + if (isset($updateArray['start_time'])) + $linkedUpdateArray['start_time'] = $updateArray['start_time']; + if (isset($updateArray['end_time'])) + $linkedUpdateArray['end_time'] = $updateArray['end_time']; + if (isset($updateArray['name'])) + $linkedUpdateArray['name'] = $updateArray['name']; + if (isset($updateArray['description'])) + $linkedUpdateArray['description'] = $updateArray['description']; + if (isset($updateArray['location'])) + $linkedUpdateArray['location'] = $updateArray['location']; + if (isset($updateArray['all_day_event'])) + $linkedUpdateArray['all_day_event'] = $updateArray['all_day_event']; + if (isset($updateArray['private'])) + $linkedUpdateArray['private'] = $updateArray['private']; + if (isset($updateArray['reminder'])) + $linkedUpdateArray['reminder'] = $updateArray['reminder']; + if (isset($updateArray['busy'])) + $linkedUpdateArray['busy'] = 2; + if (isset($updateArray['event_type'])) + $linkedUpdateArray['event_type'] = $updateArray['event_type']; + if (isset($updateArray['categories'])) + $linkedUpdateArray['categories'] = $updateArray['categories']; + if (isset($updateArray['customer'])) + $linkedUpdateArray['customer'] = $updateArray['customer']; + if (isset($updateArray['customer_info'])) + $linkedUpdateArray['customer_info'] = $updateArray['customer_info']; + if (isset($updateArray['customer_info_send'])) + $linkedUpdateArray['customer_info_send'] = $updateArray['customer_info_send']; + if (isset($updateArray['customer_info_reminder'])) + $linkedUpdateArray['customer_info_reminder'] = $updateArray['customer_info_reminder']; + + if ($attendees) { + $attendeesForLinkedEvent = array(); + $attendeesForLinkedEvent['required'] = array(); + + $organizerCalendar = self::search(array("go_calendar_id" => $user_id)); + if ($organizerCalendar && count($organizerCalendar) > 0) { + $orgName = ''; + $orgEmail = ''; + if ($organizerCalendar[0]->user_id) { + $orgName = $organizerCalendar[0]->user->name; + $orgEmail = $organizerCalendar[0]->user->email; + } elseif ($organizerCalendar[0]->calendar_name) { + $orgName = $organizerCalendar[0]->calendar_name; + $orgEmail = $organizerCalendar[0]->calendar_email ?: ''; + } + + $attendeesForLinkedEvent['required'][] = array( + 'name' => $orgName, + 'email' => $orgEmail, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + } + + foreach ($attendees as $att) { + if (is_numeric($att) && intval($att) != $linkedEvent->calendar_id) { + $attCal = self::search(array("go_calendar_id" => intval($att))); + if ($attCal && count($attCal) > 0) { + $attName = ''; + $attEmail = ''; + if ($attCal[0]->user_id) { + $attName = $attCal[0]->user->name; + $attEmail = $attCal[0]->user->email; + } elseif ($attCal[0]->calendar_name) { + $attName = $attCal[0]->calendar_name; + $attEmail = $attCal[0]->calendar_email ?: ''; + } + $attendeesForLinkedEvent['required'][] = array( + 'name' => $attName, + 'email' => $attEmail, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + } + } elseif (!is_numeric($att)) { + $attendeesForLinkedEvent['required'][] = array( + 'name' => $att, + 'email' => $att, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + } + } + + $linkedUpdateArray['attendees'] = json_encode($attendeesForLinkedEvent); + } + + $linkedUpdateArray['mtime'] = time(); + $linkedUpdateArray['mname'] = $me->name; + + if (!empty($linkedUpdateArray)) { + usleep(200000); + $db->update("cal_events", $linkedUpdateArray, "id = '" . $linkedEvent->id . "'"); + } + + } + } + if ($attendees) { + $currentAttendeeCalendarIds = array(); + + $sqlLinkedForAttendees = "SELECT ce.id, ce.calendar_id, cc.ms_user_id microsoft_id + FROM cal_events ce + LEFT JOIN cal_calendars cc ON ce.calendar_id = cc.id + WHERE ce.linked_event_uid = '" . $mainEvent->linked_event_uid . "' + AND ce.id != '" . $id . "' + AND ce.is_organizer = 0"; + $resCurrentAttendeesQuery = $db->query($sqlLinkedForAttendees); + + while ($currAtt = $db->fetch_object($resCurrentAttendeesQuery)) { + if (empty($currAtt->microsoft_id)) { + $currentAttendeeCalendarIds[] = $currAtt->calendar_id; + } + } + + foreach ($attendees as $newAttendee) { + $newAttendeeCalId = null; + if (is_numeric($newAttendee) && !filter_var($newAttendee, FILTER_VALIDATE_EMAIL)) { + $newAttendeeCalId = intval($newAttendee); + } else { + $dbCheckEmail = FronkDB::singleton(); + $resCheckEmail = $dbCheckEmail->query("SELECT go_calendar_id FROM Calendar WHERE calendar_email = '" . $newAttendee . "' LIMIT 1"); + if ($dbCheckEmail->num_rows($resCheckEmail)) { + $emailCalData = $dbCheckEmail->fetch_object($resCheckEmail); + $newAttendeeCalId = intval($emailCalData->go_calendar_id); + } + } + if ($newAttendeeCalId) { + if (!in_array($newAttendeeCalId, $currentAttendeeCalendarIds)) { + $newAttCal = self::search(array("go_calendar_id" => $newAttendeeCalId)); + if (count($newAttCal) > 0) { + $resCheckNewAttMs = $db->select("cal_calendars", "ms_user_id", "id = '" . $newAttendeeCalId . "' LIMIT 1"); + $hasMsId = false; + if ($db->num_rows($resCheckNewAttMs)) { + $newAttMsData = $db->fetch_object($resCheckNewAttMs); + $hasMsId = !empty($newAttMsData->ms_user_id); + } + } + + if ($newAttCal && count($newAttCal) > 0 && !$hasMsId) { + $organizerCalendar = self::search(array("go_calendar_id" => $user_id)); + $organizerName = ''; + $organizerEmail = ''; + if ($organizerCalendar && count($organizerCalendar) > 0) { + if ($organizerCalendar[0]->user_id) { + $organizerName = $organizerCalendar[0]->user->name; + $organizerEmail = $organizerCalendar[0]->user->email; + } elseif ($organizerCalendar[0]->calendar_name) { + $organizerName = $organizerCalendar[0]->calendar_name; + $organizerEmail = $organizerCalendar[0]->calendar_email ?: ''; + } + } + + $newOrganizerJson = json_encode(array( + 'name' => $organizerName, + 'email' => $organizerEmail + )); + + $newAttendeesForEvent = array(); + $newAttendeesForEvent['required'] = array(); + + $newAttendeesForEvent['required'][] = array( + 'name' => $organizerName, + 'email' => $organizerEmail, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + + foreach ($attendees as $otherAtt) { + if ($otherAtt != $newAttendee) { + if (is_numeric($otherAtt) && !filter_var($otherAtt, FILTER_VALIDATE_EMAIL)) { + $otherCal = self::search(array("go_calendar_id" => intval($otherAtt))); + if ($otherCal && count($otherCal) > 0) { + $otherName = ''; + $otherEmail = ''; + if ($otherCal[0]->user_id) { + $otherName = $otherCal[0]->user->name; + $otherEmail = $otherCal[0]->user->email; + } elseif ($otherCal[0]->calendar_name) { + $otherName = $otherCal[0]->calendar_name; + $otherEmail = $otherCal[0]->calendar_email ?: ''; + } + $newAttendeesForEvent['required'][] = array( + 'name' => $otherName, + 'email' => $otherEmail, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + } + } else { + $newAttendeesForEvent['required'][] = array( + 'name' => $otherAtt, + 'email' => $otherAtt, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + } + } + } + + $newAttendeesJson = json_encode($newAttendeesForEvent); + $newAttendeeDataarray = array( + "start_time" => $updateArray['start_time'], + 'end_time' => $updateArray['end_time'], + 'name' => $updateArray['name'], + 'description' => $updateArray['description'] ?? '', + 'location' => $updateArray['location'] ?? '', + 'calendar_id' => $newAttendeeCalId, + 'uuid' => "a5eb79b3-fca7-5378-a09e-" . rand(100000000000, 999999999999), + 'user_id' => 1, + 'timezone' => 'Europe/Amsterdam', + 'all_day_event' => $updateArray['all_day_event'] ?? 0, + 'repeat_end_time' => 0, + 'reminder' => $updateArray['reminder'] ?? NULL, + 'ctime' => time(), + 'cname' => $me->name, + 'mtime' => time(), + 'mname' => $me->name, + 'busy' => 2, + 'status' => 'CONFIRMED', + 'resource_event_id' => 0, + 'private' => $updateArray['private'] ?? 0, + 'rrule' => '', + 'background' => 'EBF1E2', + 'files_folder_id' => 0, + 'read_only' => 0, + 'categories' => $updateArray['categories'] ?? NULL, + 'exception_for_event_id' => 0, + 'recurrence_id' => 0, + 'is_organizer' => 0, + 'organizer' => $newOrganizerJson, + 'attendees' => $newAttendeesJson, + 'linked_event_uid' => $mainEvent->linked_event_uid, + 'event_type' => $updateArray['event_type'] ?? 1, + 'customer' => $updateArray['customer'] ?? NULL, + 'customer_info' => $updateArray['customer_info'] ?? NULL, + 'customer_info_send' => $updateArray['customer_info_send'] ?? NULL, + 'customer_info_reminder' => $updateArray['customer_info_reminder'] ?? 0 + ); + usleep(200000); + $db->insert("cal_events", $newAttendeeDataarray); + } + } + + } + } + + $newAttendeeCalendarIds = array(); + foreach ($attendees as $att) { + if (is_numeric($att)) { + $newAttendeeCalendarIds[] = intval($att); + } else { + $dbCheck = FronkDB::singleton(); + $resEmailCheck = $dbCheck->query("SELECT go_calendar_id FROM Calendar WHERE calendar_email = '" . $att . "' LIMIT 1"); + if ($dbCheck->num_rows($resEmailCheck)) { + $emailData = $dbCheck->fetch_object($resEmailCheck); + $resCheckMs = $db->select("cal_calendars", "ms_user_id", "id = '" . $emailData->go_calendar_id . "' LIMIT 1"); + if ($db->num_rows($resCheckMs)) { + $msData = $db->fetch_object($resCheckMs); + $emailHasMsId = !empty($msData->ms_user_id); + if (!$emailHasMsId) { + $newAttendeeCalendarIds[] = intval($emailData->go_calendar_id); + } + } else { + } + } + } + } + + error_log("DEBUG: newAttendeeCalendarIds nach Email-Check: " . print_r($newAttendeeCalendarIds, true)); + + foreach ($currentAttendeeCalendarIds as $oldCalId) { + if (!in_array($oldCalId, $newAttendeeCalendarIds)) { + $db->delete("cal_events", "linked_event_uid = '" . $mainEvent->linked_event_uid . "' AND calendar_id = '" . $oldCalId . "' AND is_organizer = 0"); + } else { + } + } + } + } + } } public static function updateCalendarEventState($r, $me) @@ -875,18 +1187,35 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $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'] = $process; - $data['status'] = 'p'; - $data['edit'] = time(); - $data['create'] = time(); - $data['edit_by'] = 89; - $data['create_by'] = 89; + if (!empty($microsoft_id) && !empty($microsoft_user_id)) { + $data = []; + $data['ms_user_id'] = $microsoft_user_id; + $data['ms_event_id'] = $microsoft_id; + $data['data'] = $json_data; + $data['type'] = $process; + $data['status'] = 'p'; + $data['edit'] = time(); + $data['create'] = time(); + $data['edit_by'] = 89; + $data['create_by'] = 89; - $db->insert("TheTool_CalendarQueue", $data); + $db->insert("TheTool_CalendarQueue", $data); + } + if ($eventAction == "decline") { + $resCheckDecline = $db->select("cal_events", "linked_event_uid, calendar_id", "id = '" . $id . "' LIMIT 1"); + if ($db->num_rows($resCheckDecline)) { + $declineEvent = $db->fetch_object($resCheckDecline); + $resCheckDeclineMs = $db->select("cal_calendars", "ms_user_id", "id = '" . $declineEvent->calendar_id . "' LIMIT 1"); + if ($db->num_rows($resCheckDeclineMs)) { + $declineMsData = $db->fetch_object($resCheckDeclineMs); + $declineHasMsId = !empty($declineMsData->ms_user_id); + if (!$declineHasMsId && !empty($declineEvent->linked_event_uid)) { + error_log("DEBUG: Teilnehmer ohne MS-ID lehnt ab - Lösche Event ID: " . $id); + $db->delete("cal_events", "id = '" . $id . "' AND linked_event_uid = '" . $declineEvent->linked_event_uid . "' AND is_organizer = 0"); + } + } + } + } } public static function insertCalendarEvent($r, $me, $rrules = "") @@ -963,6 +1292,9 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $db->insert("cal_events", $dataarray); $event_id = $dataarray['uuid']; + $shared_linked_uid = 'LINKED-' . strtoupper(uniqid()) . '-' . time(); + $db->update("cal_events", array('linked_event_uid' => $shared_linked_uid), "uuid = '" . $event_id . "'"); + if ($newkey) { $res = $db->select("tmp_cal_events_attachments", "id,name,contentType,content,size,create_timestamp,edit_timestamp", "1=1 AND newkey='" . $newkey . "' ORDER BY id"); if ($db->num_rows($res)) { @@ -986,17 +1318,149 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $dataarray['end_time'] = $originalend; $json_data = json_encode($dataarray); - $data = []; - $data['ms_user_id'] = $microsoft_user_id; - $data['event_id'] = $event_id; - $data['data'] = $json_data; - $data['type'] = 'c'; - $data['status'] = 'p'; - $data['edit'] = time(); - $data['create'] = time(); - $data['edit_by'] = 89; - $data['create_by'] = 89; - $db->insert("TheTool_CalendarQueue", $data); + if (!empty($microsoft_user_id)) { + $data = []; + $data['ms_user_id'] = $microsoft_user_id; + $data['event_id'] = $event_id; + $data['data'] = $json_data; + $data['type'] = 'c'; + $data['status'] = 'p'; + $data['edit'] = time(); + $data['create'] = time(); + $data['edit_by'] = 89; + $data['create_by'] = 89; + $db->insert("TheTool_CalendarQueue", $data); + } + if ($attendees) { + $organizerCalendar = self::search(array("go_calendar_id" => $user_id)); + $organizerName = ''; + $organizerEmail = ''; + + if ($organizerCalendar && count($organizerCalendar) > 0) { + if ($organizerCalendar[0]->user_id) { + $organizerName = $organizerCalendar[0]->user->name; + $organizerEmail = $organizerCalendar[0]->user->email; + } elseif ($organizerCalendar[0]->calendar_name) { + $organizerName = $organizerCalendar[0]->calendar_name; + $organizerEmail = $organizerCalendar[0]->calendar_email ?: ''; + } + } + + $organizerJson = json_encode(array( + 'name' => $organizerName, + 'email' => $organizerEmail + )); + + foreach ($attendees as $attendeeValue) { + if (is_numeric($attendeeValue) && !filter_var($attendeeValue, FILTER_VALIDATE_EMAIL)) { + $attendeeCalendarId = intval($attendeeValue); + $attendeeCalendar = self::search(array("go_calendar_id" => $attendeeCalendarId)); + + if ($attendeeCalendar && count($attendeeCalendar) > 0) { + $resCheckAttMs = $db->select("cal_calendars", "ms_user_id", "id = '" . $attendeeCalendarId . "' LIMIT 1"); + $attendeeHasMicrosoftId = false; + if ($db->num_rows($resCheckAttMs)) { + $attMsData = $db->fetch_object($resCheckAttMs); + $attendeeHasMicrosoftId = !empty($attMsData->ms_user_id); + } + + if (!$attendeeHasMicrosoftId) { + $attendeeName = ''; + $attendeeEmail = ''; + + if ($attendeeCalendar[0]->user_id) { + $attendeeName = $attendeeCalendar[0]->user->name; + $attendeeEmail = $attendeeCalendar[0]->user->email; + } elseif ($attendeeCalendar[0]->calendar_name) { + $attendeeName = $attendeeCalendar[0]->calendar_name; + $attendeeEmail = $attendeeCalendar[0]->calendar_email ?: ''; + } + $attendeesForEvent = array(); + $attendeesForEvent['required'] = array(); + $attendeesForEvent['required'][] = array( + 'name' => $organizerName, + 'email' => $organizerEmail, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + foreach ($attendees as $otherAttendee) { + if ($otherAttendee != $attendeeValue) { + if (is_numeric($otherAttendee) && !filter_var($otherAttendee, FILTER_VALIDATE_EMAIL)) { + $otherCalendar = self::search(array("go_calendar_id" => intval($otherAttendee))); + if ($otherCalendar && count($otherCalendar) > 0) { + $otherName = ''; + $otherEmail = ''; + if ($otherCalendar[0]->user_id) { + $otherName = $otherCalendar[0]->user->name; + $otherEmail = $otherCalendar[0]->user->email; + } elseif ($otherCalendar[0]->calendar_name) { + $otherName = $otherCalendar[0]->calendar_name; + $otherEmail = $otherCalendar[0]->calendar_email ?: ''; + } + $attendeesForEvent['required'][] = array( + 'name' => $otherName, + 'email' => $otherEmail, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + } + } else { + $attendeesForEvent['required'][] = array( + 'name' => $otherAttendee, + 'email' => $otherAttendee, + 'response' => 'none', + 'time' => '0001-01-01 00:00:00.000000' + ); + } + } + } + + $attendeesJson = json_encode($attendeesForEvent); + $attendeeDataarray = array( + "start_time" => $start, + 'end_time' => $end, + 'name' => $title, + 'description' => $description, + 'location' => $location, + 'calendar_id' => $attendeeCalendarId, + 'uuid' => "a5eb79b3-fca7-5378-a09e-" . rand(100000000000, 999999999999), + 'user_id' => 1, + 'timezone' => 'Europe/Amsterdam', + 'all_day_event' => $allday, + 'repeat_end_time' => 0, + 'reminder' => $reminder, + 'ctime' => time(), + 'cname' => $me->name, + 'mtime' => time(), + 'mname' => $me->name, + 'busy' => 2, + 'status' => 'CONFIRMED', + 'resource_event_id' => 0, + 'private' => $privateflag, + 'rrule' => '', + 'background' => 'EBF1E2', + 'files_folder_id' => 0, + 'read_only' => 0, + 'categories' => $categories, + 'exception_for_event_id' => 0, + 'recurrence_id' => 0, + 'is_organizer' => 0, + 'organizer' => $organizerJson, + 'attendees' => $attendeesJson, + 'linked_event_uid' => $shared_linked_uid, + 'event_type' => $type, + 'customer' => $customer, + 'customer_info' => $customer_info, + 'customer_info_send' => $customer_info_send, + 'customer_info_reminder' => $customer_info_reminder_check + ); + + $db->insert("cal_events", $attendeeDataarray); + } + } + } + } + } if ($r->delete_old_entry) { CalendarModel::deleteCalendarOldEvent($r->delete_old_entry); die(); @@ -1046,16 +1510,18 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda if ($db->num_rows($res)) { $result = $db->fetch_object($res); - $data = []; - $data['ms_user_id'] = $microsoft_user_id; - $data['ms_event_id'] = $result->microsoft_id; - $data['type'] = 'd'; - $data['status'] = 'p'; - $data['edit'] = time(); - $data['create'] = time(); - $data['edit_by'] = 89; - $data['create_by'] = 89; - $db->insert("TheTool_CalendarQueue", $data); + if (!empty($result->microsoft_id) && !empty($microsoft_user_id)) { + $data = []; + $data['ms_user_id'] = $microsoft_user_id; + $data['ms_event_id'] = $result->microsoft_id; + $data['type'] = 'd'; + $data['status'] = 'p'; + $data['edit'] = time(); + $data['create'] = time(); + $data['edit_by'] = 89; + $data['create_by'] = 89; + $db->insert("TheTool_CalendarQueue", $data); + } } $db->delete("cal_events", "id = '" . $id . "'"); die(); @@ -1077,16 +1543,18 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $resultcal = $db->fetch_object($rescal); $microsoft_user_id = $resultcal->ms_user_id; } - $data = []; - $data['ms_user_id'] = $microsoft_user_id; - $data['ms_event_id'] = $resultical->microsoft_id; - $data['type'] = 'd'; - $data['status'] = 'p'; - $data['edit'] = time(); - $data['create'] = time(); - $data['edit_by'] = 89; - $data['create_by'] = 89; - $db->insert("TheTool_CalendarQueue", $data); + if (!empty($microsoft_user_id)) { + $data = []; + $data['ms_user_id'] = $microsoft_user_id; + $data['ms_event_id'] = $resultical->microsoft_id; + $data['type'] = 'd'; + $data['status'] = 'p'; + $data['edit'] = time(); + $data['create'] = time(); + $data['edit_by'] = 89; + $data['create_by'] = 89; + $db->insert("TheTool_CalendarQueue", $data); + } $db->delete("cal_events", "id = '" . $resical->id . "'"); } } @@ -1142,17 +1610,20 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $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); + if (!empty($microsoft_id) && !empty($microsoft_user_id)) { + $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 = []; @@ -1173,17 +1644,19 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $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); + if (!empty($row->microsoft_id) && !empty($resultcal->ms_user_id)) { + $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); + } } } @@ -1234,12 +1707,10 @@ WHERE `TimerecordingCategory`.`hourday`!='1' AND `TimerecordingCategory`.`hourda $data['rrule_frequency'] = 'DAILY'; } - // Falls benötigt, kann der Start-Datum-Wert übernommen werden. if (!empty($graph['range']['startDate'])) { $data['startDate'] = $graph['range']['startDate']; } - // Wiederherstellen des Endbereichs if (!empty($graph['range']['type'])) { switch ($graph['range']['type']) { case 'endDate': diff --git a/public/js/pages/Calendar/View.js b/public/js/pages/Calendar/View.js index d033b2d22..1f815b28f 100644 --- a/public/js/pages/Calendar/View.js +++ b/public/js/pages/Calendar/View.js @@ -29,21 +29,129 @@ const fileTypeClasses = { let calendar; let calendarEl = document.getElementById('calendar'); calendarRights = JSON.parse(calendarRights); +/*function reinitializeAttendeesSelect() { + var selectedCalendarId = $('#calendar-users').val(); + var selectedOption = $('#calendar-users option:selected'); + var hasMicrosoftId = selectedOption.data('has-microsoft-id'); + if ($('#calendar-attendees').hasClass('select2-hidden-accessible')) { + $('#calendar-attendees').select2('destroy'); + } + if (hasMicrosoftId == '1') { + $('#calendar-attendees').select2({ + tags: true, + tokenSeparators: [',', ' '], + dropdownParent: jQuery('#relContainer'), + placeholder: "Teilnehmer auswählen oder eingeben", + templateResult: function(data) { + if (!data.id) return data.text; + var $option = $(data.element); + var hasMs = $option.data('has-microsoft-id'); + if (hasMs == '0') { + return $('' + data.text + ''); + } + return data.text; + }, + templateSelection: function(data) { + if (!data.id) return data.text; + var $option = $(data.element); + var hasMs = $option.data('has-microsoft-id'); + + if (hasMs == '0') { + return $('' + data.text + ''); + } + return data.text; + } + }); + } else { + $('#calendar-attendees').select2({ + dropdownParent: jQuery('#relContainer'), + placeholder: "Teilnehmer auswählen (Freitext nicht verfügbar)", + closeOnSelect: false, + templateResult: function(data) { + if (!data.id) return data.text; + var $option = $(data.element); + var hasMs = $option.data('has-microsoft-id'); + + if (hasMs == '0') { + return $('' + data.text + ''); + } + return data.text; + }, + templateSelection: function(data) { + if (!data.id) return data.text; + var $option = $(data.element); + var hasMs = $option.data('has-microsoft-id'); + + if (hasMs == '0') { + return $('' + data.text + ''); + } + return data.text; + } + }); + } +}*/ +function reinitializeAttendeesSelect() { + var selectedCalendarId = $('#calendar-users').val(); + var selectedOption = $('#calendar-users option:selected'); + var hasMicrosoftId = selectedOption.data('has-microsoft-id'); + + // ÄNDERUNG: Verstecke/Deaktiviere Teilnehmer-Zeile wenn keine Microsoft-ID + if (hasMicrosoftId == '0' || hasMicrosoftId === 0 || !hasMicrosoftId) { + // Verstecke die gesamte Teilnehmer-Zeile + $('#calendar-attendees').closest('.row').hide(); + // Optional: Leere auch die Auswahl + $('#calendar-attendees').val(null).trigger('change'); + return; // Beende Funktion früh + } else { + // Zeige die Teilnehmer-Zeile wieder an + $('#calendar-attendees').closest('.row').show(); + } + // Zerstöre bestehende Select2 Instanz + if ($('#calendar-attendees').hasClass('select2-hidden-accessible')) { + $('#calendar-attendees').select2('destroy'); + } + + + // ÄNDERUNG: Initialisiere mit tags (Freitext erlaubt) + $('#calendar-attendees').select2({ + tags: true, + tokenSeparators: [',', ' '], + dropdownParent: jQuery('#relContainer'), + placeholder: "Teilnehmer auswählen oder eingeben", + templateResult: function(data) { + if (!data.id) return data.text; + var $option = $(data.element); + var hasMs = $option.data('has-microsoft-id'); + + if (hasMs == '0') { + return $('' + data.text + ''); + } + return data.text; + }, + templateSelection: function(data) { + if (!data.id) return data.text; + var $option = $(data.element); + var hasMs = $option.data('has-microsoft-id'); + + if (hasMs == '0') { + return $('' + data.text + ''); + } + return data.text; + } + }); +} function formatFileSize(bytes) { - // Wenn die Dateigröße größer als 1 MB ist if (bytes >= 1024 * 1024) { const megabytes = bytes / (1024 * 1024); return megabytes.toFixed(2) + ' MB'; } - // Wenn die Dateigröße größer als 1 KB ist else if (bytes >= 1024) { const kilobytes = bytes / 1024; return kilobytes.toFixed(2) + ' KB'; } - // Wenn die Dateigröße kleiner als 1 KB ist (also in Bytes) else { - return Math.round(bytes) + ' Bytes'; // Keine Nachkommastellen + return Math.round(bytes) + ' Bytes'; } } @@ -70,7 +178,7 @@ document.addEventListener('DOMContentLoaded', function () { }); - $.post(requestUrl, {visibleCalendars: visibleCalendars, visibleCancellation: 1}, function (data) { + $.post(requestUrl, {visibleCalendars: visibleCalendars, visibleCancellation: 0}, function (data) { }, 'json').done(function (json) { if (json.success == true) { @@ -2594,15 +2702,6 @@ $(document).ready(function () { } ); - $('.select2-multiple-tag').select2( - { - tags: true, - tokenSeparators: [',', ' '], - dropdownParent: jQuery('#relContainer') - } - ); - - // $(document).on("select2:opening", (e) => { // $('.modal-body').css('overflow', 'visible'); // }); @@ -2637,7 +2736,6 @@ $(document).ready(function () { } }); - $.post(requestUrl, { visibleCalendars: visibleCalendars, visibleCalendarTypes: visibleCalendarTypes, @@ -2902,5 +3000,8 @@ $(document).ready(function () { localsorageEvent = JSON.parse(create_event); $('#EventModal').modal('show'); } - + $('body').on('change', '#calendar-users', function() { + reinitializeAttendeesSelect(); + }); + reinitializeAttendeesSelect(); });