| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- function pa($array) {
- echo '<pre>';
- print_r($array);
- echo '</pre>';
- }
- function error($message) {
- echo $message;
- }
- function getObjectsAsArray($objects, $keys) {
- $return = array();
- if(is_array($objects)) {
- foreach($objects as $object) {
- $return[] = array();
- foreach($keys as $key) {
- $keyCall = 'get' . ucfirst($key);
- $return[sizeof($return) - 1][$key] = $object->$keyCall();
- }
- }
- } else {
- foreach($keys as $key) {
- $keyCall = 'get' . ucfirst($key);
- $return[0][$key] = $object->$keyCall();
- }
- }
- return $return;
- }
- function searchNewFiles($scanDir) {
- global $db;
- global $CONFIG;
- $oldDocuments = Document::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) {
- $existed = true;
- break;
- }
- }
- if($existed) {
- continue;
- }
- Document::addDocument('file', $file, '/', Label::getLabelByPath($scanDir)->getId(), '', 'NOW()', 'NOW()');
- }
- }
- function searchMails() {
- global $user;
- $mailboxes = Mailbox::getAllMailBoxes();
- foreach($mailboxes as $mailbox) {
- $mailbox->listFolders();
- }
- foreach($mailboxes as $mailbox) {
- foreach($mailbox->getFolders() as $folder) {
- $mbFolder = MailboxFolder::getMailboxFolderByName($folder);
- if($mbFolder != false) {
- $mailbox->changeFolder($mbFolder->getFolderName());
- $messageCount = imap_num_msg($mailbox->getMailbox());
- for($i = 1; $i <= $messageCount; ++$i) {
- $headers = imap_header($mailbox->getMailbox(), $i);
- pa($headers);
- //$uid = imap_msgno($mailbox->getMailbox(), imap_uid($mailbox->getMailbox(), $i));
- //echo $uid;
- $uid = imap_uid($mailbox->getMailbox(), $i);
- $documents = Document::getDocumentsByMailInfo($mailbox->getId(), $uid, $mbFolder->getLabelId());
- if(sizeof($documents) < 1) {
- Document::addDocument('mail', $headers->subject, $headers->from[0]->mailbox . '@' . $headers->from[0]->host, $mbFolder->getLabelId(), '', '\'' . $headers->date . '\'', '\'' . $headers->date . '\'', $uid, $mailbox->getId());
- }
- }
- }
- }
- }
- }
- function getEditableLink($elementId, $type, $pk, $title, $value, $class = '') {
- 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';
- }
- } else if($type == 'select' && $elementId == 'mailaccount') {
- $class = 'editable-element-select-mailaccount';
- }
- $link = '<a href="#" id="' . $elementId . '" class="' . $class . '" data-type="' . $type . '" data-pk="' . $pk . '" data-url="ajax.php" data-title="' . $title . '">' . $value . '</a>';
- return $link;
- }
- function getExcerptFromString($string, $count = 50) {
- if(strlen($string) > $count) {
- $string = substr($string, 0, $count);
- $string = substr($string, 0, strrpos($string, " "));
- $string = $string . " ...";
- }
- return $string;
- }
- ?>
|