| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- <?php
- // AJAX handling
- // Includes
- require('includes/config.inc.php');
- require('includes/database.inc.php');
- require('includes/functions.inc.php');
- require('includes/document.inc.php');
- require('includes/label.inc.php');
- require('includes/mailbox.inc.php');
- require('includes/mailboxfolder.inc.php');
- require('includes/documenthandler.inc.php');
- require('includes/call.inc.php');
- require('includes/reminder.inc.php');
- require('includes/mail.inc.php');
- $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'], $CONFIG['dbDatabase']);
- switch($_REQUEST['action']) {
- case 'updateMailaccounts':
- switch($_POST['name']) {
- case 'hostname':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailboxes` SET `server`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- case 'port':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailboxes` SET `port`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- case 'protocol':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailboxes` SET `protocol`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- case 'use-ssl':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailboxes` SET `use_ssl`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- case 'no-valid-cert':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailboxes` SET `valid_ssl`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- case 'username':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailboxes` SET `username`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- case 'password':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailboxes` SET `password`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- default:
- header("Status: 400 Wrong Field");
- echo 'error';
- break;
- }
- break;
- case 'updateMailfolder':
- switch($_POST['name']) {
- case 'mailaccount':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailbox-folders` SET `mailbox_id`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- case 'mailfolder':
- header("Status: 200 OK");
- $db->updateQuery("UPDATE `mailbox-folders` SET `folder_name`='" . $_POST['value'] . "' WHERE id=" . $_POST['pk'] . ";");
- break;
- default:
- header("Status: 400 Wrong Field");
- echo 'error';
- break;
- }
- break;
- case 'addDefaultMailaccount':
- header("Status: 200 OK");
- $db->insertQuery("INSERT INTO `mailboxes` (`user_id`) VALUES (" . $_POST['user-id'] . ");");
- break;
- case 'addDefaultMailfolder':
- header("Status: 200 OK");
- $db->insertQuery("INSERT INTO `mailbox-folders` (`label_id`) VALUES (" . $_POST['label-id'] . ");");
- break;
- case 'removeMailaccount':
- header("Status: 200 OK");
- $db->removeQuery("DELETE FROM `mailboxes` WHERE `id` = " . $_POST['id'] . ";");
- break;
- case 'removeMailboxFolder':
- header("Status: 200 OK");
- $db->removeQuery("DELETE FROM `mailbox-folders` WHERE `id` = " . $_POST['id'] . ";");
- break;
- case 'manageMailboxFolder':
- header("Status: 200 OK");
- $allMailBoxes = Mailbox::getAllMailboxes(true);
- $editBox = array(
- "options" => array(
- array(
- "type" => "select",
- "name" => "account",
- "value" => Mailbox::getMailboxNameFromMailaccountID($_GET['mbID']),
- "values" => array()
- ),
- array(
- "type" => "select",
- "name" => "folder",
- "value" => MailboxFolder::getMailboxFolderNameFromID($_GET['mfID']),
- "values" => array()
- )
- ),
- "title" => "Mailkonto bearbeiten",
- "mailboxFolderID" => $_GET['mfID']
- );
- foreach($allMailBoxes as $mailBox) {
- $mailBox->listFolders();
- $editBox['options'][0]['values'][] = $mailBox->getUsername();
- if($mailBox->getUsername() == Mailbox::getMailboxNameFromMailaccountID($_GET['mbID'])) {
- $editBox['options'][1]['values'] = $mailBox->getFolders();
- }
- }
- echo json_encode($editBox);
- break;
- case 'getMailAccountsByUid':
- header("Status: 200 OK");
- $mailboxes = Mailbox::getMailboxesByUserID($_REQUEST['uID']);
- $mbArray = array();
- foreach($mailboxes as $mailbox) {
- $mbArray[$mailbox->getID()] = $mailbox->getUsername();
- }
- echo json_encode($mbArray);
- break;
- case 'getNewDocumentBox':
- header("Status: 200 OK");
- $editBox = array(
- "options" => array(
- array(
- "type" => "select",
- "name" => "vorlage",
- "value" => Document::getDefaultDraft()->filename,
- "values" => Document::getAllDrafts()
- ),
- array(
- "type" => "text",
- "name" => "filename",
- "value" => str_replace(".docx", "", Document::getDefaultDraft()->filename) . "_" . date("d_m_Y") . ".docx"
- )
- ),
- "title" => "Neues Dokument"
- );
- echo json_encode($editBox);
- break;
- case 'getDraftVars':
- header("Status: 200 OK");
- $documentHandle = new \PhpOffice\PhpWord\TemplateProcessor('drafts/' . $_REQUEST['draft']);
- $templateVars = $documentHandle->getVariables();
- echo json_encode(array_values($templateVars));
- break;
- case 'getMailboxStatus':
- header("Status: 200 OK");
- $mailbox = Mailbox::getMailboxByID($_REQUEST['mailboxID'], true);
- $mailboxStatus = array(
- "connected" => $mailbox->getConnected()
- );
- echo json_encode($mailboxStatus);
- break;
- case 'saveNewDocument':
- header("Status: 200 OK");
- $newDocument = new DocumentHandler(Label::getLabelByID($_REQUEST['labelID'])->getPath() . '/' . $_REQUEST['filename'], $_REQUEST['draft']);
- foreach($_REQUEST['draftVars'] as $key => $draftVar) {
- $newDocument->setVal($key, htmlspecialchars($draftVar));
- }
- $newDocument->saveFile();
- echo json_encode($_REQUEST);
- break;
- case 'getNewLabelBox':
- header("Status: 200 OK");
- $editBox = array(
- "options" => array(
- array(
- "type" => "text",
- "name" => "name",
- "value" => ""
- ),
- array(
- "type" => "text",
- "name" => "path",
- "value" => ""
- )
- ),
- "title" => "Neues Label"
- );
- echo json_encode($editBox);
- break;
- case 'saveNewLabel':
- header("Status: 200 OK");
- Label::addLabel($_REQUEST['name'], $_REQUEST['path']);
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'removeLabel':
- header("Status: 200 OK");
- Label::removeLabel($_REQUEST['labelID']);
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'saveMailFolder':
- header("Status: 200 OK");
- MailboxFolder::updateMailboxFolder($_REQUEST['mailboxFolderID'], $_REQUEST['folder'], Mailbox::getMailboxByUsername($_REQUEST['account'])->getID(), $_REQUEST['labelID']);
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'saveNewMailFolder':
- header("Status: 200 OK");
- MailboxFolder::addMailboxFolder($_REQUEST['folder'], Mailbox::getMailboxByUsername($_REQUEST['account'])->getID(), $_REQUEST['labelID']);
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'getNewCallBox':
- header("Status: 200 OK");
- $allLabels = Label::getAllLabels();
- $editBox = array(
- "options" => array(
- array(
- "type" => "datetime",
- "name" => "call-date",
- "value" => ""
- ),
- array(
- "type" => "text",
- "name" => "caller-telnr",
- "value" => ""
- ),
- array(
- "type" => "select",
- "name" => "label-id",
- "value" => Label::getLabelByID($_REQUEST['labelID'])->getName(),
- "values" => array()
- ),
- array(
- "type" => "textarea",
- "name" => "call-notes",
- "value" => ""
- ),
- array(
- "type" => "checkbox",
- "name" => "call-set-reminder",
- "value" => ""
- )
- ),
- "title" => "Neuer Anruf"
- );
- foreach($allLabels as $label) {
- $editBox['options'][2]['values'][] = $label->getName();
- }
- echo json_encode($editBox);
- break;
- case 'saveNewCall':
- header("Status: 200 OK");
- Call::addCall($_REQUEST['userID'], $_REQUEST['callDate'], $_REQUEST['callerTelNr'], Label::getLabelByName($_REQUEST['labelID'])->getID(), $_REQUEST['callNotes']);
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'getEvents':
- header("Status: 200 OK");
- $upcomingReminders = getObjectsAsArray(Reminder::getUpcomingRemindersByUserID($_REQUEST['userID']), array("id", "userID", "reminderDate", "remindedYet", "subject"));
- $return = array(
- "type" => $upcomingReminders == "" ? "ping" : "reminder",
- "reminders" => $upcomingReminders
- );
- echo json_encode($return);
- break;
- case 'setReminderReminded':
- header("Status: 200 OK");
- $reminder = Reminder::getReminderByID($_REQUEST['reminderID']);
- $reminder->setRemindedYet(1);
- $reminder->save();
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'setReminderSnooze':
- header("Status: 200 OK");
- $reminder = Reminder::getReminderByID($_REQUEST['reminderID']);
- $reminder->setReminderDate(date("Y-m-d H:i:s", strtotime("+30 minutes")));
- $reminder->save();
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'scanDocuments':
- header("Status: 200 OK");
- $return = scanDocuments($CONFIG['documentPath']);
- $return['status'] = "OK";
- echo json_encode($return);
- break;
- case 'getMailContent':
- header("Status: 200 OK");
- $mail = Mail::getMailByMailID($_REQUEST['mailID']);
- $mailboxFolder = Mailboxfolder::getMailboxfolderByID($mail->getMailboxFolderID());
- $mailbox = Mailbox::getMailboxByID($mailboxFolder->getMailboxID(), true);
- $mailbox->changeFolder($mailboxFolder->getFolderName());
- $bodyLines = explode(PHP_EOL, imap_fetchbody($mailbox->getMailbox(), $mail->getMailUID(), 1));
- $body = "%0D%0A"; // newline on top
- foreach($bodyLines as $line) {
- $body .= ">" . $line . '%0D%0A';
- }
- $return = array(
- "to" => $mail->getMailSender(),
- "subject" => $mail->getSubject(),
- "body" => $body
- );
- echo json_encode($return);
- case 'changeMailProcessed':
- header("Status: 200 OK");
- $mail = Mail::getMailByMailID($_REQUEST['mailID']);
- $mail->setProcessed($_REQUEST['value']);
- $mail->save();
- $return = array(
- "status" => "OK"
- );
- echo json_encode($return);
- break;
- case 'getMailaccountFoldersByUsername':
- header("Status: 200 OK");
- $mailbox = Mailbox::getMailboxByUsername($_REQUEST['account'], true);
- $mailbox->listFolders();
- echo json_encode($mailbox->getFolders());
- break;
- case 'getCalendarEvents':
- header("Status: 200 OK");
- // demo code
- $out = array();
- for($i=1; $i<=15; $i++){ //from day 01 to day 15
- $data = date('Y-m-d', strtotime("+".$i." days"));
- $out[] = array(
- 'id' => $i,
- 'title' => 'Event name '.$i,
- 'url' => "http://diesdas.de",
- 'class' => 'event-important',
- 'start' => strtotime($data).'000'
- );
- }
- echo json_encode(array('success' => 1, 'result' => $out));
- break;
- case 'debugTest': // for testing single methods etc.
- break;
- default:
- header("Status: 400 No Action Defined");
- echo 'error';
- break;
- }
- //pa($_POST); // Debug
- ?>
|