document.inc.php 5.1 KB

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