document.inc.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 getDraft() {
  33. return $this->draft;
  34. }
  35. public function getCreated() {
  36. return $this->created;
  37. }
  38. public function getLastChange() {
  39. return $this->lastChange;
  40. }
  41. public function getType() {
  42. return $this->type;
  43. }
  44. public function getMailUid() {
  45. return $this->mailUid;
  46. }
  47. /**
  48. * Get Documents by Label ID
  49. *
  50. *
  51. * @param int $labelId Label ID
  52. *
  53. * @return Array(Document) Array with selected Document(s)
  54. *
  55. */
  56. public static function getDocumentsByLabelId($labelId) {
  57. global $db;
  58. $return = array();
  59. $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";");
  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 FS-Path
  67. *
  68. *
  69. * @param string $path path, relative to ~/documents-folder
  70. *
  71. * @return Array(Document) Array with selected Document(s)
  72. *
  73. */
  74. public static function getDocumentsByPath($path) {
  75. global $db;
  76. $return = array();
  77. $documents = $db->selectQuery("SELECT documents.* FROM `documents` JOIN `labels` ON labels.id = documents.label_id WHERE labels.path = '" . $path . "';");
  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 Mail-Header-Info
  85. *
  86. *
  87. * @param int $mailAcc ID of wanted Mailaccount
  88. * @param int $mailUid UID of wanted Mail-Document
  89. * @param int $labelId ID fo wanted Label
  90. *
  91. * @return Array(Document) Selected Document(s)
  92. *
  93. */
  94. public static function getDocumentsByMailInfo($mailAcc, $mailUid, $labelId) {
  95. global $db;
  96. $return = array();
  97. $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . " AND `mail_acc` = " . $mailAcc . ";");
  98. foreach($documents as $document) {
  99. $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
  100. }
  101. return $return;
  102. }
  103. /**
  104. * Insert new Document into DB
  105. *
  106. *
  107. * @param string $type Type of Document
  108. * @param string $fileName Name of File/Subject of Mail
  109. * @param string $path Path relative to Label-Home-Folder / Mailaccount
  110. * @param int $labelId ID of Label
  111. * @param string $draft Name of used draft
  112. * @param string(?) $created Date of creation
  113. * @param string(?) $lastChange Date of last change
  114. * @param int $mailUid UID of mail, 0 for Files TODO: parameter = 0, default val
  115. * @param int $mailAcc ID of MailAccount. Default: -1 (For Files)
  116. *
  117. * @return void TODO: return true/false error diesdas
  118. *
  119. */
  120. public static function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid, $mailAcc = -1) {
  121. global $db;
  122. $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 . ");";
  123. $db->insertQuery($query);
  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. // TODO: > 1, < 1 checking
  152. return $draft[0];
  153. }
  154. }
  155. ?>