document.inc.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. foreach($documents as $document) {
  51. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
  52. }
  53. return $return;
  54. }
  55. /**
  56. * Get Documents by Label ID
  57. *
  58. *
  59. * @param int $labelId Label ID
  60. *
  61. * @return Array(Document) Array with selected Document(s)
  62. *
  63. */
  64. public static function getDocumentsByLabelId($labelId) {
  65. global $db;
  66. $return = array();
  67. $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";");
  68. foreach($documents as $document) {
  69. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
  70. }
  71. return $return;
  72. }
  73. /**
  74. * Get Documents by FS-Path
  75. *
  76. *
  77. * @param string $path path, relative to ~/documents-folder
  78. *
  79. * @return Array(Document) Array with selected Document(s)
  80. *
  81. */
  82. public static function getDocumentsByLabelPath($path) {
  83. global $db;
  84. $return = array();
  85. $documents = $db->selectQuery("SELECT documents.* FROM `documents` JOIN `labels` ON labels.id = documents.label_id WHERE labels.path = '" . $path . "';");
  86. foreach($documents as $document) {
  87. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
  88. }
  89. return $return;
  90. }
  91. /**
  92. * Insert new Document into DB
  93. *
  94. *
  95. * @param string $type Type of Document
  96. * @param string $fileName Name of File/Subject of Mail
  97. * @param string $path Path relative to Label-Home-Folder / Mailaccount
  98. * @param int $labelId ID of Label
  99. * @param string $draft Name of used draft
  100. * @param string $created Date of creation
  101. * @param string $lastChange Date of last change
  102. * @param int $mailUid UID of mail, 0 for Files
  103. * @param int $mailAcc ID of MailAccount. Default: -1 (For Files)
  104. *
  105. * @return void
  106. *
  107. */
  108. public static function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange) {
  109. global $db;
  110. $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', '" . $created . "', '" . $lastChange . "');";
  111. $db->insertQuery($query);
  112. }
  113. /**
  114. * Remove a Document from DB by documentID
  115. *
  116. * @param int $documentID ID of Document
  117. *
  118. * @return void
  119. *
  120. */
  121. public static function removeDocumentByID($documentID) {
  122. global $db;
  123. $db->removeQuery("DELETE FROM `documents` WHERE `id` = " . $documentID . ";");
  124. }
  125. /**
  126. * Get all Drafts
  127. *
  128. *
  129. * @return Array Array with Draft attributes
  130. *
  131. */
  132. public static function getAllDrafts() {
  133. global $db;
  134. $return = array();
  135. $drafts = $db->selectQuery("SELECT * FROM `drafts`;");
  136. foreach($drafts as $draft) {
  137. $return[] = $draft->filename;
  138. }
  139. return $return;
  140. }
  141. /**
  142. * Get the default Draft
  143. *
  144. *
  145. * @return Array Array with Draft attributes
  146. *
  147. */
  148. public static function getDefaultDraft() {
  149. global $db;
  150. $draft = $db->selectQuery("SELECT * FROM `drafts` WHERE `default` = 1;");
  151. return $draft[0];
  152. }
  153. }
  154. ?>