id = $id; $this->fileName = $fileName; $this->path = $path; $this->labelId = $labelId; $this->draft = $draft; $this->created = $created; $this->lastChange = $lastChange; $this->type = $type; $this->mailUid = $mailUid; } public function getId() { return $this->id; } public function getFileName() { return $this->fileName; } public function getPath() { return $this->path; } public function getLabelId() { return $this->labelId; } public function getDraft() { return $this->draft; } public function getCreated() { return $this->created; } public function getLastChange() { return $this->lastChange; } public function getType() { return $this->type; } public function getMailUid() { return $this->mailUid; } /** * Get all Documents * * @return Array(Document) Array with all Documents * */ public static function getAllDocuments() { global $db; $return = array(); $documents = $db->selectQuery("SELECT * FROM `documents`;"); foreach($documents as $document) { $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid); } return $return; } /** * Get Documents by Label ID * * * @param int $labelId Label ID * * @return Array(Document) Array with selected Document(s) * */ public static function getDocumentsByLabelId($labelId) { global $db; $return = array(); $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";"); foreach($documents as $document) { $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid); } return $return; } /** * Get Documents by FS-Path * * * @param string $path path, relative to ~/documents-folder * * @return Array(Document) Array with selected Document(s) * */ public static function getDocumentsByLabelPath($path) { global $db; $return = array(); $documents = $db->selectQuery("SELECT documents.* FROM `documents` JOIN `labels` ON labels.id = documents.label_id WHERE labels.path = '" . $path . "';"); foreach($documents as $document) { $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid); } return $return; } /** * Get Documents by Mail-Header-Info * * * @param int $mailAcc ID of wanted Mailaccount * @param int $mailUid UID of wanted Mail-Document * @param int $labelId ID fo wanted Label * * @return Array(Document) Selected Document(s) * */ public static function getDocumentsByMailInfo($mailAcc, $mailUid, $labelId) { global $db; $return = array(); $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . " AND `mail_acc` = " . $mailAcc . ";"); foreach($documents as $document) { $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid); } return $return; } /** * Insert new Document into DB * * * @param string $type Type of Document * @param string $fileName Name of File/Subject of Mail * @param string $path Path relative to Label-Home-Folder / Mailaccount * @param int $labelId ID of Label * @param string $draft Name of used draft * @param string $created Date of creation * @param string $lastChange Date of last change * @param int $mailUid UID of mail, 0 for Files * @param int $mailAcc ID of MailAccount. Default: -1 (For Files) * * @return void * */ public static function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid = 0, $mailAcc = -1) { global $db; $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 . ");"; $db->insertQuery($query); } /** * Get all Drafts * * * @return Array Array with Draft attributes * */ public static function getAllDrafts() { global $db; $return = array(); $drafts = $db->selectQuery("SELECT * FROM `drafts`;"); foreach($drafts as $draft) { $return[] = $draft->filename; } return $return; } /** * Get the default Draft * * * @return Array Array with Draft attributes * */ public static function getDefaultDraft() { global $db; $draft = $db->selectQuery("SELECT * FROM `drafts` WHERE `default` = 1;"); return $draft[0]; } } ?>