document.inc.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. class Document {
  3. private $id = NULL;
  4. private $fileName = NULL;
  5. private $path = NULL;
  6. private $labelId = NULL;
  7. private $draft = NULL;
  8. private $created = NULL;
  9. private $lastChange = NULL;
  10. private $type = NULL;
  11. private $mailUid = NULL;
  12. public function __construct($id, $fileName, $path, $labelId, $draft, $created, $lastChange, $type, $mailUid) {
  13. $this->id = $id;
  14. $this->fileName = $fileName;
  15. $this->path = $path;
  16. $this->labelId = $labelId;
  17. $this->draft = $draft;
  18. $this->created = $created;
  19. $this->lastChange = $lastChange;
  20. $this->type = $type;
  21. $this->mailUid = $mailUid;
  22. }
  23. public function getId() {
  24. return $this->id;
  25. }
  26. public function getFileName() {
  27. return $this->fileName;
  28. }
  29. public function getPath() {
  30. return $this->path;
  31. }
  32. public function getLabelId() {
  33. return $this->labelId;
  34. }
  35. public function getDraft() {
  36. return $this->draft;
  37. }
  38. public function getCreated() {
  39. return $this->created;
  40. }
  41. public function getLastChange() {
  42. return $this->lastChange;
  43. }
  44. public function getType() {
  45. return $this->type;
  46. }
  47. public function getMailUid() {
  48. return $this->mailUid;
  49. }
  50. /**
  51. * Get all Documents
  52. *
  53. * @return Array(Document) Array with all Documents
  54. *
  55. */
  56. public static function getAllDocuments() {
  57. global $db;
  58. $return = array();
  59. $documents = $db->selectQuery("SELECT * FROM `documents`;");
  60. foreach($documents as $document) {
  61. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
  62. }
  63. return $return;
  64. }
  65. /**
  66. * Get Documents by Label ID
  67. *
  68. *
  69. * @param int $labelId Label ID
  70. *
  71. * @return Array(Document) Array with selected Document(s)
  72. *
  73. */
  74. public static function getDocumentsByLabelId($labelId) {
  75. global $db;
  76. $return = array();
  77. $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";");
  78. foreach($documents as $document) {
  79. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
  80. }
  81. return $return;
  82. }
  83. /**
  84. * Get Documents by FS-Path
  85. *
  86. *
  87. * @param string $path path, relative to ~/documents-folder
  88. *
  89. * @return Array(Document) Array with selected Document(s)
  90. *
  91. */
  92. public static function getDocumentsByLabelPath($path) {
  93. global $db;
  94. $return = array();
  95. $documents = $db->selectQuery("SELECT documents.* FROM `documents` JOIN `labels` ON labels.id = documents.label_id WHERE labels.path = '" . $path . "';");
  96. foreach($documents as $document) {
  97. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
  98. }
  99. return $return;
  100. }
  101. /**
  102. * Get Documents by Mail-Header-Info
  103. *
  104. *
  105. * @param int $mailAcc ID of wanted Mailaccount
  106. * @param int $mailUid UID of wanted Mail-Document
  107. * @param int $labelId ID fo wanted Label
  108. *
  109. * @return Array(Document) Selected Document(s)
  110. *
  111. */
  112. public static function getDocumentsByMailInfo($mailAcc, $mailUid, $labelId) {
  113. global $db;
  114. $return = array();
  115. $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . " AND `mail_acc` = " . $mailAcc . ";");
  116. foreach($documents as $document) {
  117. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
  118. }
  119. return $return;
  120. }
  121. /**
  122. * Insert new Document into DB
  123. *
  124. *
  125. * @param string $type Type of Document
  126. * @param string $fileName Name of File/Subject of Mail
  127. * @param string $path Path relative to Label-Home-Folder / Mailaccount
  128. * @param int $labelId ID of Label
  129. * @param string $draft Name of used draft
  130. * @param string $created Date of creation
  131. * @param string $lastChange Date of last change
  132. * @param int $mailUid UID of mail, 0 for Files
  133. * @param int $mailAcc ID of MailAccount. Default: -1 (For Files)
  134. *
  135. * @return void
  136. *
  137. */
  138. public static function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid = 0, $mailAcc = -1) {
  139. global $db;
  140. $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`, `mail_uid`, `mail_acc`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', '" . $created . "', '" . $lastChange . "', " . $mailUid . ", " . $mailAcc . ");";
  141. $db->insertQuery($query);
  142. }
  143. /**
  144. * Get all Drafts
  145. *
  146. *
  147. * @return Array Array with Draft attributes
  148. *
  149. */
  150. public static function getAllDrafts() {
  151. global $db;
  152. $return = array();
  153. $drafts = $db->selectQuery("SELECT * FROM `drafts`;");
  154. foreach($drafts as $draft) {
  155. $return[] = $draft->filename;
  156. }
  157. return $return;
  158. }
  159. /**
  160. * Get the default Draft
  161. *
  162. *
  163. * @return Array Array with Draft attributes
  164. *
  165. */
  166. public static function getDefaultDraft() {
  167. global $db;
  168. $draft = $db->selectQuery("SELECT * FROM `drafts` WHERE `default` = 1;");
  169. return $draft[0];
  170. }
  171. }
  172. ?>