document.inc.php 5.2 KB

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