function getAttachments() { if ($this->attachments) { return $this->attachments; } //XXX: inner join the file table instead? $sql = 'SELECT a.attach_id, f.id as file_id, f.size, lower(f.`key`) as file_hash, f.`signature` as file_sig, f.name, a.inline ' . ' FROM ' . FILE_TABLE . ' f ' . ' INNER JOIN ' . TICKET_ATTACHMENT_TABLE . ' a ON(f.id=a.file_id) ' . ' WHERE a.ticket_id=' . db_input($this->getTicketId()) . ' AND a.ref_id=' . db_input($this->getId()); $this->attachments = array(); if (($res = db_query($sql)) && db_num_rows($res)) { while ($rec = db_fetch_array($res)) { $rec['download_url'] = AttachmentFile::generateDownloadUrl($rec['file_id'], $rec['file_hash'], $rec['file_sig']); $this->attachments[] = $rec; } } return $this->attachments; }
function _getList($separate = false, $inlines = false) { if (!isset($this->attachments)) { $this->attachments = array(); $sql = 'SELECT f.id, f.size, f.`key`, f.signature, f.name, a.inline ' . ' FROM ' . FILE_TABLE . ' f ' . ' INNER JOIN ' . ATTACHMENT_TABLE . ' a ON(f.id=a.file_id) ' . ' WHERE a.`type`=' . db_input($this->getType()) . ' AND a.object_id=' . db_input($this->getId()); if (($res = db_query($sql)) && db_num_rows($res)) { while ($rec = db_fetch_array($res)) { $rec['download_url'] = AttachmentFile::generateDownloadUrl($rec['id'], $rec['key'], $rec['signature']); $this->attachments[] = $rec; } } } $attachments = array(); foreach ($this->attachments as $a) { if ($a['inline'] != $separate || $a['inline'] == $inlines) { $a['file_id'] = $a['id']; $a['hash'] = md5($a['file_id'] . session_id() . strtolower($a['key'])); $attachments[] = $a; } } return $attachments; }