functions.inc.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. function pa($array) {
  3. echo '<pre>';
  4. print_r($array);
  5. echo '</pre>';
  6. }
  7. function error($message) {
  8. echo $message;
  9. }
  10. function getObjectsAsArray($objects, $keys) {
  11. $return = array();
  12. if(is_array($objects)) {
  13. foreach($objects as $object) {
  14. $return[] = array();
  15. foreach($keys as $key) {
  16. $keyCall = 'get' . ucfirst($key);
  17. $return[sizeof($return) - 1][$key] = $object->$keyCall();
  18. }
  19. }
  20. } else {
  21. foreach($keys as $key) {
  22. $keyCall = 'get' . ucfirst($key);
  23. $return[0][$key] = $object->$keyCall();
  24. }
  25. }
  26. return $return;
  27. }
  28. function searchNewFiles($scanDir) {
  29. global $db;
  30. global $CONFIG;
  31. $oldDocuments = Document::getDocumentsByPath($scanDir);
  32. $files = scandir($CONFIG['documentPath'] . $scanDir);
  33. foreach($files as $file) {
  34. $existed = false;
  35. if($file === '.' || $file === '..') {
  36. continue;
  37. }
  38. foreach($oldDocuments as $oldDocument) {
  39. if($oldDocument->getFileName() === $file) { // TODO: Check update-date, maybe removed files
  40. $existed = true;
  41. break;
  42. }
  43. }
  44. if($existed) {
  45. continue;
  46. }
  47. Document::addDocument('file', $file, '/', Label::getLabelByPath($scanDir)->getId(), '', 'NOW()', 'NOW()', 0); // TODO: get dates by filesystem
  48. }
  49. }
  50. function searchMails() {
  51. global $user;
  52. $mailboxes = Mailbox::getAllMailBoxes();
  53. foreach($mailboxes as $mailbox) {
  54. $mailbox->listFolders();
  55. }
  56. foreach($mailboxes as $mailbox) {
  57. foreach($mailbox->getFolders() as $folder) {
  58. $mbFolder = MailboxFolder::getMailboxFolderByName($folder);
  59. if($mbFolder != false) {
  60. $mailbox->changeFolder($mbFolder->getFolderName());
  61. $messageCount = imap_num_msg($mailbox->getMailbox());
  62. for($i = 1; $i <= $messageCount; ++$i) {
  63. $headers = imap_header($mailbox->getMailbox(), $i);
  64. pa($headers);
  65. //$uid = imap_msgno($mailbox->getMailbox(), imap_uid($mailbox->getMailbox(), $i)); // TODO: Get really unique ID, not folder-id
  66. //echo $uid;
  67. $uid = imap_uid($mailbox->getMailbox(), $i);
  68. $documents = Document::getDocumentsByMailInfo($mailbox->getId(), $uid, $mbFolder->getLabelId());
  69. if(sizeof($documents) < 1) {
  70. Document::addDocument('mail', $headers->subject, $headers->from[0]->mailbox . '@' . $headers->from[0]->host, $mbFolder->getLabelId(), '', '\'' . $headers->date . '\'', '\'' . $headers->date . '\'', $uid, $mailbox->getId());
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. function getEditableLink($elementId, $type, $pk, $title, $value, $class = '') {
  78. if($type == 'text' || $type == 'password') {
  79. $class = 'editable-element-text';
  80. } else if($type == 'select' && $elementId == 'protocol') {
  81. $class = 'editable-element-select-protocol';
  82. } else if($type == 'select' && $elementId == 'use-ssl') {
  83. $class = 'editable-element-select-use-ssl';
  84. if($value == '/ssl') {
  85. $value = 'On';
  86. } else {
  87. $value = 'Off';
  88. }
  89. } else if($type == 'select' && $elementId == 'no-valid-cert') {
  90. $class = 'editable-element-select-no-valid-cert';
  91. if($value == '/novalidate-cert') {
  92. $value = 'On';
  93. } else {
  94. $value = 'Off';
  95. }
  96. } else if($type == 'select' && $elementId == 'mailaccount') {
  97. $class = 'editable-element-select-mailaccount';
  98. }
  99. $link = '<a href="#" id="' . $elementId . '" class="' . $class . '" data-type="' . $type . '" data-pk="' . $pk . '" data-url="ajax.php" data-title="' . $title . '">' . $value . '</a>';
  100. return $link;
  101. }
  102. ?>