Update: * Serientermine die schon länger als 1 Jahr laufen werden nun 3 Jahre in die Zugunft angezeigt
942 lines
38 KiB
PHP
942 lines
38 KiB
PHP
<?php
|
|
|
|
class CalendarModel
|
|
{
|
|
private $user_id;
|
|
private $go_calendar_id;
|
|
private $microsoft_id;
|
|
private $rights;
|
|
private $colors;
|
|
private $groups;
|
|
private $subscription_id;
|
|
private $expirationDateTime;
|
|
private $active;
|
|
|
|
public static $austrian_mobile_prefixes = array(
|
|
'650', // Tele2 / Magenta
|
|
'651', // A1 (ehemals T-Mobile)
|
|
'652', // 3 Hutchison
|
|
'653', // Lycamobile
|
|
'655', //
|
|
'660', // T-Mobile / Magenta
|
|
'662', // tele.ring (nun Magenta)
|
|
'663', // tele.ring (nun Magenta)
|
|
'664', // A1
|
|
'670', // HOT (HoT - Hofer Telekom)
|
|
'676', // A1
|
|
'677', // Yesss! (A1)
|
|
'678', // Ventocom (Spusu)
|
|
'680', // Spusu
|
|
'681', // Spusu
|
|
'688', // Educom
|
|
'690', // Spusu
|
|
'699' // 3 (Drei)
|
|
);
|
|
public static $standardCalendarColors = [
|
|
'#b3d5f3', '#d0e2c0', '#bac2d4', '#c6d4c0', '#e3e3e3',
|
|
'#acdce5', '#cdb6c0', '#aae0e1', '#d9d9d9', '#d9e5d5',
|
|
'#c8a7d5', '#aad8d0', '#dcadc3', '#d9e8e5', '#e4d8d5',
|
|
'#b4dcc5', '#b9d1e2', '#a3c1c2', '#cdd2b9', '#e3c8ce',
|
|
'#aae2c5', '#c7d0cc', '#d0c0da', '#dbdfc8', '#b4e3d7',
|
|
'#c3e4e3', '#c5c4e3', '#d0b7e5', '#b6e98c', '#e3d1de'
|
|
];
|
|
|
|
public static $specialCalendarColors = array(997 => '#bd0000', 998 => '#8000A3', 999 => '#08769b');
|
|
|
|
|
|
public static function replace_unicode_sequences($string)
|
|
{
|
|
$unicode_map = [
|
|
'\u00f6' => 'ö',
|
|
'\u00fc' => 'ü',
|
|
'\u00e4' => 'ä',
|
|
'\u00df' => 'ß',
|
|
'\u00e9' => 'é',
|
|
'\u00e0' => 'à',
|
|
'\u00f3' => 'ó',
|
|
// Weitere Unicode-Zuordnungen können hier hinzugefügt werden
|
|
];
|
|
|
|
foreach ($unicode_map as $unicode => $char) {
|
|
$string = str_replace($unicode, $char, $string);
|
|
}
|
|
return $string;
|
|
}
|
|
|
|
public static function dbKalender()
|
|
{
|
|
if (!TT_CALENDAR_ENABLE) {
|
|
$json['errormessage'] = "Calendar is is disabled.";
|
|
$json['success'] = false;
|
|
$json = json_encode($json);
|
|
echo trim($json);
|
|
die();
|
|
}
|
|
|
|
$db = FronkDB::singleton(TT_CALENDAR_HOSTNAME, TT_CALENDAR_USERNAME, TT_CALENDAR_PASSWORD, TT_CALENDAR_DATABASE);
|
|
|
|
return $db;
|
|
}
|
|
|
|
public static function searchCalendarEvents($r)
|
|
{
|
|
$dbcal = self::dbKalender();
|
|
$termstring = trim($r->term);
|
|
$calendars = $r->calendars;
|
|
|
|
$termExplode = explode(" ", $termstring);
|
|
$where = "";
|
|
foreach ($termExplode as $term) {
|
|
$where .= " AND (name LIKE '%" . $term . "%' OR location LIKE '%" . $term . "%') ";
|
|
}
|
|
$where .= " AND calendar_id IN (" . implode(",", $calendars) . ")";
|
|
|
|
|
|
$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, is_organizer,event_type", "1=1 $where ORDER BY name");
|
|
|
|
$rows = array();
|
|
while ($data = $dbcal->fetch_array($res)) {
|
|
if ($data['location']) {
|
|
$searchName = $data['name'] . " @" . $data['location'];
|
|
} else {
|
|
$searchName = $data['name'];
|
|
}
|
|
$id = $data['id'] . ";" . date("Y-m-d", $data['start_time']);
|
|
$rows[] = array(
|
|
'id' => $id,
|
|
'text' => $searchName . " (" . date("Y-m-d", $data['start_time']) . ")"
|
|
);
|
|
}
|
|
$json['incomplete_results'] = false;
|
|
$json['total_count'] = count($rows);
|
|
$json['items'] = $rows;
|
|
|
|
$json = json_encode($json);
|
|
echo trim($json);
|
|
die();
|
|
}
|
|
|
|
public static function getCalendarEvents($me, $id = 0, $r = 0)
|
|
{
|
|
$rrulefreq = array('daily' => 'DAILY', 'weekly' => 'WEEKLY', 'relativeMonthly' => 'MONTHLY', 'yearly' => 'YEARLY');
|
|
$calendar = self::search(array("user_id" => $me));
|
|
$standardCalendarColors = CalendarModel::$standardCalendarColors;
|
|
$calendarColors = json_decode($calendar[0]->colors, true);
|
|
$calenderRights = json_decode($calendar[0]->rights, true);
|
|
$colorCounter = 0;
|
|
foreach ($calenderRights as $key => $value) {
|
|
if (!$calendarColors[$key]['bgcolor']) {
|
|
$calendarColors[$key]['bgcolor'] = $standardCalendarColors[$colorCounter];;
|
|
$calendarColors[$key]['txtcolor'] = '#000';
|
|
$colorCounter++;
|
|
}
|
|
}
|
|
$dbcal = self::dbKalender();
|
|
$req = $dbcal->select("cal_events_attachments", "id,cal_events_id,name,size,contentType", "");
|
|
$oldcalevent = "";
|
|
while ($data = $dbcal->fetch_array($req)) {
|
|
if ($oldcalevent != $data['cal_events_id']) {
|
|
$counter = 0;
|
|
}
|
|
$attachments[$data['cal_events_id']]['attachments'][$counter]['name'] = $data['name'];
|
|
$attachments[$data['cal_events_id']]['attachments'][$counter]['id'] = $data['id'];
|
|
$attachments[$data['cal_events_id']]['attachments'][$counter]['size'] = $data['size'];
|
|
$attachments[$data['cal_events_id']]['attachments'][$counter]['contentType'] = $data['contentType'];
|
|
|
|
|
|
$oldcalevent = $data['cal_events_id'];
|
|
$counter++;
|
|
}
|
|
if ($id != 0) {
|
|
$where = " AND `cal_events`.id='" . $id . "'";
|
|
} else {
|
|
$where = "";
|
|
}
|
|
$visibleCalendars = $r->visibleCalendars;
|
|
if ($visibleCalendars) {
|
|
$where .= " AND calendar_id IN (" . implode(",", $visibleCalendars) . ")";
|
|
}
|
|
$sql = "SELECT `cal_events`.id, uuid, calendar_id, `cal_events`.user_id, start_time, end_time, timezone, all_day_event, `cal_events`.name,`cal_calendars`.name calendar_name, description, location, repeat_end_time, reminder, ctime,cname, mtime,mname, muser_id, busy, status, resource_event_id, private, rrule, `cal_events`.background, `cal_events`.files_folder_id, read_only, category_id, exception_for_event_id, recurrence_id, is_organizer,event_type,busy,recurrence FROM cal_events INNER JOIN `cal_calendars` ON (`cal_calendars`.`id`=`cal_events`.`calendar_id`) WHERE 1=1 $where ";
|
|
|
|
$res = $dbcal->query($sql);
|
|
if ($dbcal->num_rows($res)) {
|
|
|
|
while ($data = $dbcal->fetch_array($res)) {
|
|
unset($byweekday);
|
|
$rrule = false;
|
|
if ($attachments[$data['uuid']]) {
|
|
$attachment = 1;
|
|
$attachmentLinks = json_encode($attachments[$data['uuid']]['attachments']);
|
|
} else {
|
|
$attachment = 0;
|
|
$attachmentLinks = "";
|
|
}
|
|
if ($data['all_day_event'] == 1) {
|
|
if (strpos($data['name'], "Bereitschaft") === false && strpos($data['name'], "Blocker") === false) {
|
|
continue;
|
|
}
|
|
$starttime = date("Y-m-d", $data['start_time']);
|
|
$endtime = date("Y-m-d", $data['end_time']);
|
|
} else {
|
|
$starttime = date("Y-m-d H:i", $data['start_time']);
|
|
$endtime = date("Y-m-d H:i", $data['end_time']);
|
|
}
|
|
if (!empty($fetch['location'])) {
|
|
$name = $data['name'] . " @ " . $data['location'];
|
|
} else {
|
|
$name = $data['name'];
|
|
}
|
|
|
|
if ($data['recurrence']) {
|
|
$recurrence = json_decode($data['recurrence'], true);
|
|
if ($rrulefreq[$recurrence['pattern']['type']]) {
|
|
unset ($byweekday);
|
|
$freq = $rrulefreq[$recurrence['pattern']['type']];
|
|
foreach ($recurrence['pattern']['daysOfWeek'] as $value) {
|
|
$byweekday[] = strtolower(substr($value, 0, 2));
|
|
}
|
|
$duration = ($data['end_time'] - $data['start_time']) * 1000;
|
|
$until = $recurrence['range']['endDate'];
|
|
if ($until == "0001-01-01") {
|
|
$until = strtotime("+3 year", time());
|
|
$until = date("Y-m-d", $until);
|
|
} else {
|
|
$until = date("Y-m-d", strtotime($recurrence['range']['endDate']) + 86400);
|
|
}
|
|
|
|
|
|
$rrule = [
|
|
'freq' => $freq,
|
|
'interval' => $recurrence['pattern']['interval'],
|
|
'byweekday' => $byweekday,
|
|
'dtstart' => date("Y-m-d\TH:i", $data['start_time']),
|
|
'until' => $until
|
|
];
|
|
if ($freq == "MONTHLY") {
|
|
$bystpos = array("first" => 1, "second" => 2, "third" => 3, "fourth" => 4, "last" => -1);
|
|
$rrule['bysetpos'] = $bystpos[$recurrence['pattern']['index']];
|
|
}
|
|
}
|
|
} else {
|
|
$rrule = false;
|
|
}
|
|
|
|
if ($calendarColors[$data['calendar_id']]['bgcolor']) {
|
|
$bgcolor = $calendarColors[$data['calendar_id']]['bgcolor'];
|
|
$txtcolor = $calendarColors[$data['calendar_id']]['txtcolor'];
|
|
} else {
|
|
$bgcolor = $standardCalendarColors[$colorCounter];
|
|
$txtcolor = "#000";
|
|
$colorCounter++;
|
|
}
|
|
if ($calenderRights[$data['calendar_id']]) {
|
|
$rights = $calenderRights[$data['calendar_id']];
|
|
|
|
$rows[] = array(
|
|
'id' => array('id' => $data['id']),
|
|
'cstart' => array('cstart' => $starttime),
|
|
'cend' => array('cend' => $endtime),
|
|
'ccategory' => array('ccategory' => $name),
|
|
'category' => array('category' => $name),
|
|
'calendar_id' => array('calendar_id' => $data['calendar_id']),
|
|
'bgColor' => array('bgColor' => $bgcolor),
|
|
'txtColor' => array('txtColor' => $txtcolor),
|
|
'rights' => array('rights' => $rights, 'order' => $rights),
|
|
'location' => array('location' => $data['location']),
|
|
'busy' => array('busy' => $data['busy']),
|
|
'rrule' => array('rrule' => $rrule),
|
|
'duration' => array('duration' => $duration),
|
|
'event_type' => array('event_type' => $data['event_type']),
|
|
'description' => array('description' => ($data['description'])),
|
|
'attachment' => array('attachment' => $attachment),
|
|
'attachments' => array('attachments' => $attachmentLinks),
|
|
'calendar_name' => array('calendar_name' => $data['calendar_name']),
|
|
'ctime' => array('ctime' => date("d.m.Y H:i", $data['ctime'])),
|
|
'cname' => array('cname' => $data['cname']),
|
|
'mtime' => array('mtime' => date("d.m.Y H:i", $data['mtime'])),
|
|
'mname' => array('mname' => $data['mname']),
|
|
'isorganizer' => array('isorganizer' => $data['is_organizer']),
|
|
'busy' => array('busy' => $data['busy']),
|
|
);
|
|
}
|
|
}
|
|
$json['success'] = true;
|
|
$json['data'] = $rows;
|
|
} else {
|
|
$json['success'] = true;
|
|
$json['errormessage'] = "No data found.";
|
|
}
|
|
|
|
|
|
$json = json_encode($json);
|
|
if ($id == 0) {
|
|
echo trim($json);
|
|
die();
|
|
} else {
|
|
return $json;
|
|
}
|
|
}
|
|
|
|
|
|
public static function getCalendarEventAttachment($id)
|
|
{
|
|
$return = array();
|
|
$dbcal = self::dbKalender();
|
|
$req = $dbcal->select("cal_events_attachments", "id, cal_events_id,name,contentType,content,size", "1=1 AND id='" . $id . "' ORDER BY id");
|
|
if ($dbcal->num_rows($req)) {
|
|
$data = $dbcal->fetch_array($req);
|
|
$return = $data;
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
public static function getCalendarEventAttachmenttmp($id, $name)
|
|
{
|
|
$return = array();
|
|
$dbcal = self::dbKalender();
|
|
$req = $dbcal->select("tmp_cal_events_attachments", "id,name,contentType,content,size", "1=1 AND newkey='" . $id . "' AND name='" . $name . "' ORDER BY id");
|
|
if ($dbcal->num_rows($req)) {
|
|
$data = $dbcal->fetch_array($req);
|
|
$return = $data;
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
public static function getCalendarEvent($id)
|
|
{
|
|
$calendar = self::search(array("user_id" => $me));
|
|
|
|
$dbcal = self::dbKalender();
|
|
$Calendars = self::getAll();
|
|
foreach ($Calendars as $key => $value) {
|
|
$Allcalendar[$value->user->name] = $key;
|
|
}
|
|
$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, 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");
|
|
if ($dbcal->num_rows($res)) {
|
|
$data = $dbcal->fetch_array($res);
|
|
|
|
|
|
$attachment = 0;
|
|
|
|
if ($data['all_day_event'] == 1) {
|
|
$starttime = date("Y-m-d", $data['start_time']);
|
|
$endtime = date("Y-m-d", $data['end_time']);
|
|
} else {
|
|
$starttime = date("Y-m-d H:i", $data['start_time']);
|
|
$endtime = date("Y-m-d H:i", $data['end_time']);
|
|
}
|
|
if (!empty($fetch['location'])) {
|
|
$name = $data['name'] . " @ " . $data['location'];
|
|
} else {
|
|
$name = $data['name'];
|
|
}
|
|
$req = $dbcal->select("cal_events_attachments", "id, cal_events_id,name,contentType,size", "1=1 AND cal_events_id='" . $data['uuid'] . "' ORDER BY id");
|
|
$counter = 0;
|
|
$contentType['application/pdf'] = 'fa-file-pdf';
|
|
$contentType['application/vnd.openxmlformats-officedocument.wordprocessingml.document'] = 'fa-file-doc';
|
|
$contentType['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'] = 'fa-file-xls';
|
|
$contentType['application/octet-stream'] = 'fa-file-csv';
|
|
$contentType['text/csv'] = 'fa-file-csv';
|
|
$contentType['application/vnd.openxmlformats-officedocument.presentationml.presentation'] = 'fa-file-ppt';
|
|
$contentType['application/zip'] = 'fa-file-zip';
|
|
$contentType['application/x-zip-compressed'] = 'fa-file-zip';
|
|
$contentType['application/x-rar-compressed'] = 'fa-file-archive';
|
|
$contentType['application/x-7z-compressed'] = 'fa-file-archive';
|
|
$contentType['application/x-tar'] = 'fa-file-archive';
|
|
$contentType['application/x-gzip'] = 'fa-file-archive';
|
|
$contentType['application/x-bzip2'] = 'fa-file-archive';
|
|
$contentType['text/xml'] = 'fa-file-xml';
|
|
$contentType['application/xml'] = 'fa-file-xml';
|
|
$contentType['audio/mpeg'] = 'fa-file-mp3';
|
|
$contentType['application/x-7z-compressed'] = 'fa-file-archive';
|
|
$contentType['image/png'] = 'fa-file-png';
|
|
$contentType['image/jpeg'] = 'fa-file-jpg';
|
|
while ($dataAttachments = $dbcal->fetch_array($req)) {
|
|
$attachment = 1;
|
|
$attachments[$counter]['name'] = $dataAttachments['name'];
|
|
$attachments[$counter]['contentType'] = $dataAttachments['contentType'];
|
|
$attachments[$counter]['size'] = $dataAttachments['size'];
|
|
$attachments[$counter]['id'] = $dataAttachments['id'];
|
|
if ($contentType[$dataAttachments['contentType']]) {
|
|
$attachments[$counter]['icon'] = $contentType[$dataAttachments['contentType']];
|
|
} else {
|
|
$attachments[$counter]['icon'] = 'fa-file';
|
|
}
|
|
$counter++;
|
|
}
|
|
$attendees = json_decode($data['attendees'], true);
|
|
$organizer = json_decode($data['organizer'], true);
|
|
foreach ($attendees as $key => $value) {
|
|
if ($key == "required" || $key == "optional") {
|
|
|
|
foreach ($value as $attendeekey => $attendee) {
|
|
$attendee['name'] = self::replace_unicode_sequences($attendee['name']);
|
|
if ($attendee['email'] == $organizer['email']) {
|
|
|
|
} elseif ($Allcalendar[$attendee['name']] && $Allcalendar[$attendee['name']] == $data['calendar_id']) {
|
|
|
|
} else if ($Allcalendar[$attendee['name']]) {
|
|
$AttendeeArray[] = $Allcalendar[$attendee['name']];
|
|
} else {
|
|
$AttendeeArray[] = $attendee['email'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!$data['accepted'] && $data['busy'] == 1) {
|
|
$data['accepted']['ok'] = 1;
|
|
$data['accepted'] = json_encode($data['accepted']);
|
|
}
|
|
|
|
$rows = array(
|
|
'id' => array('id' => $data['id'], 'order' => $data['id']),
|
|
'cstart' => array('cstart' => $starttime, 'order' => $data['ctime']),
|
|
'cend' => array('cend' => $endtime, 'order' => $data['mtime']),
|
|
'ccategory' => array('ccategory' => $name, 'order' => $data['name']),
|
|
'category' => array('category' => $name, 'order' => $data['name']),
|
|
'calendar_id' => array('calendar_id' => $data['calendar_id'], 'order' => $data['calendar_id']),
|
|
'location' => array('location' => $data['location'], 'order' => $data['location']),
|
|
'description' => array('description' => $data['description'], 'order' => $data['description']),
|
|
'reminder' => array('reminder' => $data['reminder'], 'order' => $data['reminder']),
|
|
'busy' => array('busy' => $data['busy'], 'order' => $data['busy']),
|
|
'type' => array('type' => $data['event_type'], 'order' => $data['event_type']),
|
|
'customer' => array('customer' => $data['customer']),
|
|
'customer_info' => array('customer_info' => $data['customer_info']),
|
|
'customer_info_send' => array('customer_info_send' => $data['customer_info_send']),
|
|
'customer_info_reminder' => array('customer_info_reminder' => $data['customer_info_reminder']),
|
|
'isorganizer' => array('isorganizer' => $data['is_organizer']),
|
|
'attendees' => array('attendees' => json_encode($AttendeeArray)),
|
|
'organizer' => array('organizer' => $data['organizer']),
|
|
'accepted' => array('accepted' => $data['accepted']),
|
|
'attachment' => array('attachment' => $attachment, 'order' => $attachment),
|
|
'attachments' => array('attachments' => $attachments, 'order' => $attachments)
|
|
);
|
|
$json['success'] = true;
|
|
$json['data'] = $rows;
|
|
} else {
|
|
$json['success'] = false;
|
|
$json['errormessage'] = "No data found.";
|
|
}
|
|
|
|
|
|
$json = json_encode($json);
|
|
echo trim($json);
|
|
die();
|
|
}
|
|
|
|
public static function insertMicrosoftCalendarEvent($request)
|
|
{
|
|
|
|
$db = self::dbKalender();
|
|
|
|
$json_data = json_decode($request, true);
|
|
$data = [];
|
|
$data['ms_event_id'] = $json_data['value'][0]['resourceData']['id'];
|
|
$msUserIdExplode = explode("/", $json_data['value'][0]['resource']);
|
|
$data['ms_user_id'] = trim($msUserIdExplode[1]);
|
|
$Calendar = self::search(array("microsoft_id" => $data['ms_user_id']));
|
|
$data['go_calendar_id'] = $Calendar[0]->go_calendar_id;
|
|
$data['data'] = $request;
|
|
$data['source'] = 'ms';
|
|
if ($json_data['value'][0]['changeType'] == 'created')
|
|
$data['type'] = 'c';
|
|
else if ($json_data['value'][0]['changeType'] == 'updated')
|
|
$data['type'] = 'u';
|
|
else if ($json_data['value'][0]['changeType'] == 'deleted')
|
|
$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);
|
|
return "";
|
|
die();
|
|
}
|
|
|
|
public static function updateCalendarEvent($r, $me)
|
|
{
|
|
|
|
|
|
$description = ($r->description);
|
|
$attachments = ($r->attachments);
|
|
$location = ($r->location);
|
|
$title = ($r->title);
|
|
$start = ((($r->start - 7200000) / 1000));
|
|
$end = ((($r->end - 7200000) / 1000));
|
|
if ($title) {
|
|
$start = strtotime($r->start);
|
|
$end = strtotime($r->end);
|
|
}
|
|
$allday = ($r->allday);
|
|
$reminder = ($r->reminder);
|
|
$newkey = ($r->newkey);
|
|
$id = ($r->id);
|
|
$type = ($r->type);
|
|
$busy = ($r->busy);
|
|
$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();
|
|
|
|
$sql = "SELECT `cal_events`.id,microsoft_id,uuid,ms_user_id FROM `cal_events` INNER JOIN `cal_calendars` ON (`cal_calendars`.`id`=`cal_events`.`calendar_id`) WHERE `cal_events`.id = '" . $id . "' LIMIT 1";
|
|
$res = $db->query($sql);
|
|
if ($db->num_rows($res)) {
|
|
$result = $db->fetch_object($res);
|
|
$microsoft_id = $result->microsoft_id;
|
|
$cal_events_id = $result->uuid;
|
|
$microsoft_user_id = $result->ms_user_id;
|
|
}
|
|
|
|
$updateArray['start_time'] = $start;
|
|
$updateArray['end_time'] = $end;
|
|
$updateArray['mtime'] = time();
|
|
$updateArray['mname'] = $me->name;
|
|
if ($title) {
|
|
$updateArray['name'] = $title;
|
|
}
|
|
if ($description)
|
|
$updateArray['description'] = $description;
|
|
|
|
|
|
if ($location)
|
|
$updateArray['location'] = $location;
|
|
|
|
if (isset($allday))
|
|
$updateArray['all_day_event'] = $allday;
|
|
|
|
if (isset($reminder)) {
|
|
if ($reminder == 'NULL')
|
|
$updateArray['reminder'] = NULL;
|
|
else
|
|
$updateArray['reminder'] = $reminder;
|
|
}
|
|
if ($type)
|
|
$updateArray['event_type'] = $type;
|
|
if (isset($busy))
|
|
$updateArray['busy'] = $busy;
|
|
|
|
|
|
if ($type == 2) {
|
|
if ($r->customer)
|
|
$updateArray['customer'] = $r->customer;
|
|
else
|
|
$updateArray['customer'] = NULL;
|
|
|
|
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;
|
|
}
|
|
if ($r->customer_info_reminder_check) {
|
|
$updateArray['customer_info_reminder'] = $r->customer_info_reminder_check;
|
|
}
|
|
$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);
|
|
}
|
|
}
|
|
if ($type == 1) {
|
|
$updateArray['customer'] = NULL;
|
|
$updateArray['customer_info'] = NULL;
|
|
}
|
|
|
|
|
|
$db->update("cal_events", $updateArray, "id = '" . $id . "'");
|
|
if ($newkey) {
|
|
$res = $db->select("cal_events_attachments", "id,cal_events_id", "1=1 AND cal_events_id = '" . $cal_events_id . "'");
|
|
if ($db->num_rows($res)) {
|
|
while ($dataAttachment = $db->fetch_array($res)) {
|
|
$toolattachments[$dataAttachment['id']] = 1;
|
|
}
|
|
}
|
|
foreach ($attachments as $key => $value) {
|
|
unset($toolattachments[$value]);
|
|
}
|
|
if (!empty($toolattachments)) {
|
|
foreach ($toolattachments as $key => $value) {
|
|
$db->delete("cal_events_attachments", "id = '" . $key . "'");
|
|
}
|
|
}
|
|
|
|
$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)) {
|
|
while ($data = $db->fetch_array($res)) {
|
|
$tmpid = $data['id'];
|
|
unset($data['id']);
|
|
$data['cal_events_id'] = $cal_events_id;
|
|
$db->insert("cal_events_attachments", $data);
|
|
$db->delete("tmp_cal_events_attachments", "id = '" . $tmpid . "'");
|
|
}
|
|
}
|
|
|
|
|
|
$updateArray['attachments'] = $attachments;
|
|
}
|
|
$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);
|
|
|
|
}
|
|
|
|
public static function updateCalendarEventState($r, $me)
|
|
{
|
|
$id = ($r->id);
|
|
$users = ($r->users);
|
|
$eventAction = $r->eventAction;
|
|
if ($eventAction == "accept") {
|
|
$process = 'ae';
|
|
$updateArray['busy'] = 1;
|
|
} else if ($eventAction == "decline") {
|
|
$process = "ce";
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
foreach ($users as $key => $value) {
|
|
$user_id = $value;
|
|
}
|
|
|
|
$db = self::dbKalender();
|
|
|
|
$sql = "SELECT `cal_events`.id,microsoft_id,uuid,ms_user_id FROM `cal_events` INNER JOIN `cal_calendars` ON (`cal_calendars`.`id`=`cal_events`.`calendar_id`) WHERE `cal_events`.id = '" . $id . "' LIMIT 1";
|
|
$res = $db->query($sql);
|
|
if ($db->num_rows($res)) {
|
|
$result = $db->fetch_object($res);
|
|
$microsoft_id = $result->microsoft_id;
|
|
$cal_events_id = $result->uuid;
|
|
$microsoft_user_id = $result->ms_user_id;
|
|
}
|
|
|
|
|
|
$acceptJson = array('time' => time(), 'user' => $me->name);
|
|
$updateArray['accepted'] = json_encode($acceptJson);
|
|
$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;
|
|
|
|
$db->insert("TheTool_CalendarQueue", $data);
|
|
}
|
|
|
|
public static function insertCalendarEvent($r, $me)
|
|
{
|
|
$description = ($r->description);
|
|
$attachments = ($r->attachments);
|
|
$location = ($r->location);
|
|
$title = ($r->title);
|
|
$start = strtotime($r->start);
|
|
$end = strtotime($r->end);
|
|
$allday = ($r->allday);
|
|
$reminder = ($r->reminder);
|
|
$newkey = ($r->newkey);
|
|
$type = ($r->type);
|
|
$busy = ($r->busy);
|
|
$users = ($r->users);
|
|
$customer_info_reminder_check = 0;
|
|
$attendees = ($r->attendees);
|
|
date_default_timezone_set('Europe/Berlin');
|
|
header('Content-Type: application/json');
|
|
foreach ($users as $key => $value) {
|
|
$user_id = $value;
|
|
}
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
if ($reminder == 'NULL') {
|
|
$reminder = NULL;
|
|
}
|
|
if ($type == 2) {
|
|
$customer = $r->customer;
|
|
$customer_info_type = $r->customer_info_type;
|
|
$customer_info_text = $r->customer_info_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);
|
|
$customer_info = json_encode($customerJson);
|
|
if ($r->customer_info_reminder_check) {
|
|
$customer_info_reminder_check = $r->customer_info_reminder_check;
|
|
}
|
|
if ($r->customer_info_check) {
|
|
$customerJson['sendby'] = $me->name;
|
|
$customerJson['sendtime'] = time();
|
|
$customer_info_send = json_encode($customerJson);
|
|
}
|
|
} else {
|
|
$customer = NULL;
|
|
$customer_info = NULL;
|
|
$customer_info_send = NULL;
|
|
}
|
|
|
|
$dataarray = array("start_time" => $start, 'end_time' => $end, 'name' => $title, 'description' => $description, 'location' => $location, 'calendar_id' => $user_id, 'uuid' => "a5eb79b3-fca7-5378-a09e-" . rand(100000000000, 999999999999), 'user_id' => 1, 'timezone' => 'Europe/Amsterdam', 'all_day_event' => 0, 'repeat_end_time' => 0, 'reminder' => $reminder, 'ctime' => time(), 'cname' => $me->name, 'mtime' => time(), 'mname' => $me->name, 'user_id' => 1, 'busy' => $busy, 'status' => 'CONFIRMED', 'resource_event_id' => 0, 'private' => 0, 'rrule' => '', 'background' => 'EBF1E2', 'files_folder_id' => 0, 'read_only' => 0, 'exception_for_event_id' => 0, 'recurrence_id' => 0, 'is_organizer' => 1, '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", $dataarray);
|
|
$event_id = $dataarray['uuid'];
|
|
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)) {
|
|
while ($data = $db->fetch_array($res)) {
|
|
$tmpid = $data['id'];
|
|
unset($data['id']);
|
|
$data['cal_events_id'] = $event_id;
|
|
$db->insert("cal_events_attachments", $data);
|
|
$db->delete("tmp_cal_events_attachments", "id = '" . $tmpid . "'");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
if ($attendees)
|
|
$dataarray['attendees'] = $attendees;
|
|
$dataarray['attachments'] = $attachments;
|
|
$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);
|
|
}
|
|
|
|
public static function insertCalendarEventAttachmentTemp($name, $contantType, $content, $size, $newkey)
|
|
{
|
|
$db = self::dbKalender();
|
|
$data = [];
|
|
$data['name'] = $name;
|
|
$data['contentType'] = $contantType;
|
|
$data['content'] = $content;
|
|
$data['size'] = $size;
|
|
$data['newkey'] = $newkey;
|
|
$data['create_timestamp'] = time();
|
|
$data['edit_timestamp'] = time();
|
|
$db->insert("tmp_cal_events_attachments", $data);
|
|
// echo "insert_id: " . $db->insert_id;
|
|
return $db->insert_id;
|
|
}
|
|
|
|
public static function deleteCalendarEventAttachmentTemp($newkey, $name)
|
|
{
|
|
$db = self::dbKalender();
|
|
$db->delete("tmp_cal_events_attachments", "newkey = '" . $newkey . "' AND name = '" . $name . "'");
|
|
}
|
|
|
|
|
|
public static function deleteCalendarEvent($r)
|
|
{
|
|
$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;
|
|
|
|
}
|
|
$res = $db->select("cal_events", 'id,microsoft_id', "id = '" . $id . "' LIMIT 1");
|
|
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);
|
|
}
|
|
$db->delete("cal_events", "id = '" . $id . "'");
|
|
die();
|
|
}
|
|
|
|
public static function create(array $data)
|
|
{
|
|
$model = new Calendar();
|
|
|
|
foreach ($data as $field => $value) {
|
|
if (property_exists(get_called_class(), $field)) {
|
|
if (substr($field, 0, 5) == "vlan_" && !$value) {
|
|
$model->$field = null;
|
|
continue;
|
|
}
|
|
$model->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = mfValuecache::singleton()->get("me");
|
|
if (!$me) {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
mfValuecache::singleton()->set("me", $me);
|
|
}
|
|
|
|
if ($model->create_by === null) {
|
|
$model->create_by = $me->id;
|
|
}
|
|
if ($model->edit_by === null) {
|
|
$model->edit_by = $me->id;
|
|
}
|
|
|
|
return $model;
|
|
}
|
|
|
|
public static function getOne($id)
|
|
{
|
|
if (!is_numeric($id) || !$id) {
|
|
throw new Exception("Invalid number", 400);
|
|
}
|
|
$item = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("Calendar", "*", "id=$id LIMIT 1");
|
|
if ($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Calendar($data);
|
|
}
|
|
return $item;
|
|
}
|
|
|
|
public static function getAll($key = 'go_calendar_id')
|
|
{
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("Calendar", "*", "1=1");
|
|
if ($db->num_rows($res)) {
|
|
while ($data = $db->fetch_object($res)) {
|
|
$items[$data->{$key}] = new Calendar($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getAllIndex()
|
|
{
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("Calendar", "*", "1=1");
|
|
if ($db->num_rows($res)) {
|
|
while ($data = $db->fetch_object($res)) {
|
|
$items[] = new Calendar($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst()
|
|
{
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Calendar", "*", "$where ");
|
|
if ($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Calendar($data);
|
|
if ($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function search($filter)
|
|
{
|
|
$items = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Calendar", "*", "$where");
|
|
if ($db->num_rows($res)) {
|
|
while ($data = $db->fetch_object($res)) {
|
|
$items[] = new Calendar($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter)
|
|
{
|
|
$where = "1=1 ";
|
|
|
|
//var_dump($filter);exit;
|
|
if (array_key_exists("user_id", $filter)) {
|
|
$user_id = $filter['user_id'];
|
|
if (is_numeric($user_id)) {
|
|
$where .= " AND user_id=$user_id";
|
|
}
|
|
}
|
|
if (array_key_exists("microsoft_id", $filter)) {
|
|
$microsoft_id = $filter['microsoft_id'];
|
|
$where .= " AND microsoft_id='$microsoft_id'";
|
|
}
|
|
if (array_key_exists("checkSubscriptions", $filter)) {
|
|
$where .= " AND microsoft_id!='' AND microsoft_id IS NOT NULL AND active=1";
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|