needlogin = true; $me = new User(); $me->loadMe(); $this->me = $me; $this->layout()->set("me", $me); if (!$me->is(["Admin"])) { $this->redirect("Dashboard"); } } protected function detailAction() { $this->layout()->setTemplate("Calendar/Detail"); } protected function apiAction() { if (!$this->me->is(["Admin"])) { $return = false; } $do = $this->request->do; switch ($do) { case "getCalendarEvents": $r = $this->request; $calendarEvents = CalendarModel::getCalendarEvents($this->me->id, 0, $r); return $calendarEvents; die(); case "getCalendarEvent": $r = $this->request; $id = ($r->id); $calendarEvents = CalendarModel::getCalendarEvent($id); return $calendarEvents; die(); case "searchCalendarEvents" : $r = $this->request; $calendarEvents = CalendarModel::searchCalendarEvents($r); return $calendarEvents; die(); case "getCalendarEventAttachment" : $r = $this->request; $id = ($r->id); $this->getCalendarAttachment($id); die(); case "getCalendarEventAttachmentTmp" : $r = $this->request; $id = ($r->id); $name = ($r->name); $this->getCalendarAttachmentTmp($id, $name); die(); case "updateCalendarEvent": $r = $this->request; $calendarEvents = CalendarModel::updateCalendarEvent($r, $this->me); if ($r->customer_info_check) { if ($r->customer_info_type == 1) { $body = $r->customer_info_text; $email = new Emailnotification(); $email->setSubject('Inbetriebnahme'); $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(); $body = "Xinon Terminbestätigung:" . PHP_EOL . $r->customer_info_text; $sms->setBody($body); $sms->setRecipient($r->customer_info_type_text); $sms->send(); } } die(); case "updateCalendarEventState" : $r = $this->request; $calendarEvents = CalendarModel::updateCalendarEventState($r, $this->me); die(); case "getAddress": $r = $this->request; $this->getAddress($r); die(); case "insertCalendarEvent": $r = $this->request; $calendarEvents = CalendarModel::insertCalendarEvent($r, $this->me); if ($r->customer_info_check) { if ($r->customer_info_type == 1) { $body = $r->customer_info_text; $email = new Emailnotification(); $email->setSubject('Inbetriebnahme'); $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(); $body = "Xinon Terminbestätigung:" . PHP_EOL . $r->customer_info_text; $sms->setBody($body); $sms->setRecipient($r->customer_info_type_text); $sms->send(); } } die(); case "deleteCalendarEvent": $r = $this->request; $id = ($r->id); CalendarModel::deleteCalendarEvent($r); die(); case "updateCalendarColor": $r = $this->request; $calendar_id = ($r->calendar_id); $bgcolors = ($r->bgcolors); $txtcolors = ($r->txtcolors); $id = ($r->id); $this->updateCalendarColor($id, $calendar_id, $bgcolors, $txtcolors); die(); case "uploadCalendarEventAttachment": $r = $this->request; $filename = $_FILES['upload_file']['name']; $filesize = $_FILES['upload_file']['size']; $file_content = file_get_contents($_FILES['upload_file']['tmp_name']); $filetype = $_FILES['upload_file']['type']; $file_content = base64_encode($file_content); $newkey = $r->newkey; $id = CalendarModel::insertCalendarEventAttachmentTemp($filename, $filetype, $file_content, $filesize, $newkey); if ($id) { $json['success'] = true; $json['id'] = $id; } $json = json_encode($json); echo $json; die(); case "deleteCalendarEventAttachmentTmp": $r = $this->request; $newkey = ($r->newkey); $name = ($r->name); CalendarModel::deleteCalendarEventAttachmentTemp($newkey, $name); die(); default: $return = false; } } protected function encryptString($plainText, $password, $salt) { // Definiere den Algorithmus und die Länge des Initialisierungsvektors $cipher = "aes-256-cbc"; $ivlen = openssl_cipher_iv_length($cipher); // Generiere einen Initialisierungsvektor $iv = openssl_random_pseudo_bytes($ivlen); // Erzeuge einen Schlüssel aus dem Passwort und dem Salt $key = hash_pbkdf2("sha256", $password, $salt, 1000, 32, true); // Verschlüssele den String $cipherText = openssl_encrypt($plainText, $cipher, $key, 0, $iv); // Füge den IV an den verschlüsselten Text an, da dieser für die Entschlüsselung benötigt wird $cipherText = base64_encode($iv . $cipherText); return $cipherText; } protected function updateCalendarColor($id, $calendar_id, $bgcolors, $txtcolors) { $r = $this->request; $groups = $r->groups; $redis = new Redis(); //Connecting to Redis $redis->connect('172.16.5.5', '6379'); //$redis->auth('password'); $Calendar = new Calendar($id); foreach ($bgcolors as $key => $value) { $colordata[$calendar_id[$key]]['bgcolor'] = $value; $colordata[$calendar_id[$key]]['txtcolor'] = $txtcolors[$key]; } $Calendar->colors = json_encode($colordata); if ($groups) { $Calendar->groups = $groups; } $redis->set('thetool_calendar_usercolors_' . $this->me->id, json_encode($colordata)); $Calendar->save(); die(); } protected function viewAction() { $Calendar = CalendarModel::search(array("user_id" => $this->me->id)); $CalendarAll = CalendarModel::getAll(); $encryptedUser = $this->encryptString($this->me->id, "testpw", "testsalt"); $this->layout()->set("Calendar", $Calendar); $this->layout()->set("CalendarAll", $CalendarAll); $this->layout()->set("encryptedUser", $encryptedUser); $timerecordingholidays = TimerecordingHolidayModel::getAll(); $this->layout()->set("timerecordingholidays", $timerecordingholidays); $timerecordingemployees = TimerecordingEmployeeModel::getAll(); $standardCalendarColors = CalendarModel::$standardCalendarColors; $specialCalendarColors = CalendarModel::$specialCalendarColors; $this->layout()->set("timerecordingemployees", $timerecordingemployees); $this->layout()->set("standardCalendarColors", $standardCalendarColors); $this->layout()->set("specialCalendarColors", $specialCalendarColors); $this->layout()->setTemplate("Calendar/View"); } private function getCalendarAttachment($id) { $content = CalendarModel::getCalendarEventAttachment($id); // // header('Content-Type: application/octet-stream'); header('Content-Type: ' . $content['contentType']); header('Content-disposition: attachment; filename="' . $content['name'] . '"'); echo base64_decode($content['content']); exit; } private function getCalendarAttachmentTmp($id, $name) { $content = CalendarModel::getCalendarEventAttachmentTmp($id, $name); // // header('Content-Type: application/octet-stream'); header('Content-Type: ' . $content['contentType']); header('Content-disposition: attachment; filename="' . $content['name'] . '"'); echo base64_decode($content['content']); exit; } private function getAddress($r) { $address = AddressModel::search(array("Controller!" => 'Calendar', "search_term!" => $r->term), array('count' => '20')); $mobiles = CalendarModel::$austrian_mobile_prefixes; $prefixes = array('0043', '43 ', '43', '0'); foreach ($address as $key => $value) { unset($mobilenumber); $id = $value->id; if ($value->company) { $text = "(F) " . $value->company; } else { $text = "(P) " . $value->firstname . " " . $value->lastname; } if ($value->mobile) { foreach ($mobiles as $mobile) { foreach ($prefixes as $prefix) { if (strpos($value->mobile, $prefix . $mobile) !== false) { $mobilenumber = str_replace($prefix . $mobile, '+43' . $mobile, $value->mobile); $found = 1; break; } } if ($found) { break; } } } if ($value->phone) { foreach ($mobiles as $mobile) { foreach ($prefixes as $prefix) { if (strpos($value->phone, $prefix . $mobile) !== false) { $mobilenumber = str_replace($prefix . $mobile, '+43' . $mobile, $value->phone); $found = 1; break; } } if ($found) { break; } } } if ($mobilenumber) { if (strlen($mobilenumber) > 0 && strlen($mobilenumber) < 22) { $mobilenumber = str_replace(" ", "", $mobilenumber); $mobilenumber = str_replace("(", "", $mobilenumber); $mobilenumber = str_replace(")", "", $mobilenumber); $mobilenumber = str_replace("-", "", $mobilenumber); $mobilenumber = str_replace("/", "", $mobilenumber); $mobilenumber = str_replace(".", "", $mobilenumber); $mobilenumber = str_replace(",", "", $mobilenumber); $mobilenumber = str_replace(";", "", $mobilenumber); $mobilenumber = str_replace(":", "", $mobilenumber); } } else if ($value->mobile) { $mobilenumber = $value->mobile; } else if ($value->phone) { $mobilenumber = $value->phone; } else { $mobilenumber = ""; } $rows[] = array( 'id' => $id, 'text' => $value->customer_number . " " . $text . " - " . $value->street . ", " . $value->zip . " " . $value->city, 'mail' => $value->email, 'mobilenumber' => $mobilenumber, 'location' => $value->street . ", " . $value->zip . " " . $value->city, 'name' => $value->customer_number . " " . $text ); } $json['incomplete_results'] = false; $json['total_count'] = count($rows); $json['items'] = $rows; $json = json_encode($json); echo trim($json); die(); } protected function indexAction() { $this->layout()->setTemplate("Calendar/Index"); $calendars = CalendarModel::getAll(); $calendarTemplateEventTypes = CalendarTemplateModel::$calendarTemplateEventTypes; $this->layout()->set("calendarTemplateEventTypes", $calendarTemplateEventTypes); $calendartemplates = CalendarTemplateModel::getAll(); $this->layout()->set("calendartemplates", $calendartemplates); $this->layout()->set("calendars", $calendars); } protected function addAction() { $users = UserModel::getAll(); $this->layout()->set("users", $users); $this->layout()->setTemplate("Calendar/Form"); } protected function editAction() { $id = $this->request->id; if (!is_numeric($id) || !$id) { $this->layout()->setFlash("Kalender Verwaltung nicht gefunden", "error"); $this->redirect("Calendar"); } $calendars = new Calendar($id); if ($calendars->id != $id) { $this->layout()->setFlash("Kalender Verwaltung nicht gefunden", "error"); $this->redirect("Calendar"); } $this->layout()->set("calendars", $calendars); return $this->addAction(); } protected function saveAction() { $r = $this->request; $id = $r->id; //var_dump($r->get());exit; if (is_numeric($id) && $id > 0) { $mode = "edit"; $calendars = new Calendar($id); if (!$calendars->id) { $this->layout()->setFlash("Kalender Verwaltung nicht gefunden", "error"); $this->redirect("Calendar"); } } else { $mode = "add"; } $data = []; if ($mode == "add") { $data['user_id'] = trim($r->user_id); if (!$data['user_id']) { $this->layout()->setFlash("Name darf nicht leer sein", "error"); $this->redirect("Calendar"); } } $data['go_calendar_id'] = trim($r->go_calendar_id); $data['microsoft_id'] = trim($r->microsoft_id); // $data['rights'] = trim($r->rights); // $data['colors'] = trim($r->colors); // $data['subscription_id'] = trim($r->subscription_id); // $data['expirationDateTime'] = trim($r->expirationDateTime); $data['active'] = trim($r->active); if (!$data['go_calendar_id']) { $data['go_calendar_id'] = NULL; } if (!$data['microsoft_id']) { $data['microsoft_id'] = NULL; } if (!$data['active']) { $data['active'] = '0'; } if ($mode == "edit") { $calendars->update($data); } else { $calendars = CalendarModel::create($data); } $id = $calendars->save(); if (!$id) { $this->layout()->setFlash("Kalender Verwaltung konnte nicht angelegt werden", "error"); $this->redirect("Calendar"); } if ($mode == "edit") { $this->layout()->setFlash("Kalender Verwaltung erfolgreich geändert", "success"); } else if ($mode = "add") { $this->layout()->setFlash("Kalender Verwaltung erfolgreich angelegt", "success"); } $this->redirect("Calendar"); } protected function deleteAction() { $id = $this->request->id; $calendars = new Calendar($id); if (!$calendars->id || $calendars->id != $id) { $this->layout()->setFlash("Kalender Verwaltung nicht gefunden.", "error"); $this->redirect("Calendar"); } $calendars->delete(); $this->redirect("Calendar"); } }