| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- // Label functions
- function pa($array) {
- echo '<pre>';
- print_r($array);
- echo '</pre>';
- }
- function error($message) {
- echo $message;
- }
- function getLabels() {
- global $db;
- $return = array();
- $labels = $db->selectQuery("SELECT * FROM `labels`;");
- foreach($labels as $label) {
- $return[] = new Label($label->id, $label->name);
- }
- return $return;
- }
- function getLabelById($labelId) {
- global $db;
- $return = array();
- $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `id` = " . $labelId . ";");
- foreach($labels as $label) {
- $return[] = new Label($label->id, $label->name);
- }
- return $return;
- }
- function getLabelByPath($path) {
- global $db;
- $return = array();
- $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `path` = '" . $path . "';");
- foreach($labels as $label) {
- $return[] = new Label($label->id, $label->name);
- }
- return $return;
- }
- function getDocumentsByLabelId($labelId) {
- global $db;
- $return = array();
- $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";");
- foreach($documents as $document) {
- $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
- }
- return $return;
- }
- function getDocumentsByPath($path) {
- global $db;
- $return = array();
- $documents = $db->selectQuery("SELECT documents.* FROM `documents` JOIN `labels` ON labels.id = documents.label_id WHERE labels.path = '" . $path . "';");
- foreach($documents as $document) {
- $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
- }
- return $return;
- }
- function getDocumentsByMailUidLabelId($mailUid, $labelId) {
- global $db;
- $return = array();
- $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . ";");
- foreach($documents as $document) {
- $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
- }
- return $return;
- }
- function getMailboxes() {
- global $db;
- $return = array();
- $mailboxes = $db->selectQuery("SELECT * FROM `mailboxes`;");
- foreach($mailboxes as $mailbox) {
- $useSsl = '';
- $noValidCert = '';
- if($mailbox->use_ssl) {
- $useSsl = '/ssl';
- }
- if(!$mailbox->valid_ssl) {
- $noValidCert = '/novalidate-cert';
- }
- $return[] = new Imap($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password); // TODO: Encrypt password
- }
- return $return;
- }
- function getMailboxesByUserId($userId) {
- global $db;
- $return = array();
- $mailboxes = $db->selectQuery("SELECT * FROM `mailboxes` WHERE `user_id` = " . $userId . ";");
- foreach($mailboxes as $mailbox) {
- $useSsl = '';
- $noValidCert = '';
- if($mailbox->use_ssl) {
- $useSsl = '/ssl';
- }
- if(!$mailbox->valid_ssl) {
- $noValidCert = '/novalidate-cert';
- }
- //$return[] = new Imap('{' . $mailbox->server . ':' . $mailbox->port . '/' . $mailbox->protocol . $useSsl . $noValidCert . '}', $mailbox->username, $mailbox->password); // TODO: Encrypt password
- $return[] = new Imap($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password); // TODO: Encrypt password
- }
- return $return;
- }
- function getMailboxFolderByName($folderName) {
- global $db;
- $return = array();
- $folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `folder_name` = '" . $folderName . "';");
- if(!$folders) {
- return false;
- }
- foreach($folders as $folder) {
- $return[] = new MailboxFolder($folder->folder_name, $folder->mailbox_id, $folder->label_id);
- }
- return $return;
- }
- function getMailboxFolderByLabelId($labelId) {
- global $db;
- $return = array();
- $folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `label_id` = '" . $labelId . "';");
- if(!$folders) {
- return false;
- }
- foreach($folders as $folder) {
- $return[] = new MailboxFolder($folder->folder_name, $folder->mailbox_id, $folder->label_id);
- }
- return $return;
- }
- function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid) {
- global $db;
- $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`, `mail_uid`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', " . $created . ", " . $lastChange . ", " . $mailUid . ");";
- $db->insertQuery($query);
- }
- function searchNewFiles($scanDir) {
- global $db;
- global $CONFIG;
- $oldDocuments = getDocumentsByPath($scanDir);
- $files = scandir($CONFIG['documentPath'] . $scanDir);
- foreach($files as $file) {
- $existed = false;
- if($file === '.' || $file === '..') {
- continue;
- }
- foreach($oldDocuments as $oldDocument) {
- if($oldDocument->getFileName() === $file) { // TODO: Check update-date, maybe removed files
- $existed = true;
- break;
- }
- }
- if($existed) {
- continue;
- }
- addDocument('file', $file, '/', getLabelByPath($scanDir)[0]->getId(), '', 'NOW()', 'NOW()', 0); // TODO: get dates by filesystem
- }
- }
- function searchMails() {
- global $user;
- //$imap = new Imap('{mail.mmnx.de:993/imap/ssl/novalidate-cert}', 'mobi@mmnx.de', 'msmoro');
- //$imap->listFolders();
- $mailboxes = getMailBoxes();
- //pa($mailboxes);
- foreach($mailboxes as $mailbox) {
- $mailbox->listFolders();
- }
- foreach($mailboxes as $mailbox) {
- foreach($mailbox->getFolders() as $folder) {
- $mbFolder = getMailboxFolderByName($folder);
- if($mbFolder[0] != false) {
- $mailbox->changeFolder($mbFolder[0]->getFolderName());
- $messageCount = imap_num_msg($mailbox->getMailbox());
- for($i = 1; $i <= $messageCount; ++$i) {
- $headers = imap_header($mailbox->getMailbox(), $i);
- $uid = imap_uid($mailbox->getMailbox(), $i); // TODO: Get really unique ID, not folder-id
- $documents = getDocumentsByMailUidLabelId($uid, $mbFolder[0]->getLabelId());
- if(sizeof($documents) < 1) {
- addDocument('mail', $headers->subject, $headers->from[0]->mailbox . '@' . $headers->from[0]->host, $mbFolder[0]->getLabelId(), '', '\'' . $headers->date . '\'', '\'' . $headers->date . '\'', $uid);
- }
- }
- }
- }
- }
- }
- function getEditableLink($elementId, $type, $pk, $title, $value) {
- if($type == 'text' || $type == 'password') {
- $class = 'editable-element-text';
- } else if($type == 'select' && $elementId == 'protocol') {
- $class = 'editable-element-select-protocol';
- } else if($type == 'select' && $elementId == 'use-ssl') {
- $class = 'editable-element-select-use-ssl';
- if($value == '/ssl') {
- $value = 'On';
- } else {
- $value = 'Off';
- }
- } else if($type == 'select' && $elementId == 'no-valid-cert') {
- $class = 'editable-element-select-no-valid-cert';
- if($value == '/novalidate-cert') {
- $value = 'On';
- } else {
- $value = 'Off';
- }
- }
- $link = '<a href="#" id="' . $elementId . '" class="' . $class . '" data-type="' . $type . '" data-pk="' . $pk . '" data-url="ajax.php" data-title="' . $title . '">' . $value . '</a>';
- return $link;
- }
- ?>
|