Skip to content
Snippets Groups Projects
Commit 7a7111fd authored by Jared Hancock's avatar Jared Hancock
Browse files

Merge pull request #1357 from protich/issue/attachments+


Bug: attachments

Reviewed-By: default avatarJared Hancock <jared@osticket.com>
parents e8b603fe 754ff1ab
No related branches found
No related tags found
No related merge requests found
......@@ -120,26 +120,37 @@ class GenericAttachments {
$i=array();
if (!is_array($files)) $files=array($files);
foreach ($files as $file) {
if (($fileId = is_numeric($file)
? $file : AttachmentFile::upload($file))
&& is_numeric($fileId)) {
$sql ='INSERT INTO '.ATTACHMENT_TABLE
.' SET `type`='.db_input($this->getType())
.',object_id='.db_input($this->getId())
.',file_id='.db_input($fileId)
.',inline='.db_input($inline ? 1 : 0);
// File may already be associated with the draft (in the
// event it was deleted and re-added)
if (db_query($sql, function($errno) { return $errno != 1062; })
|| db_errno() == 1062)
$i[] = $fileId;
}
if (is_numeric($file))
$fileId = $file;
elseif (is_array($file) && isset($file['id']))
$fileId = $file['id'];
elseif (!($fileId = AttachmentFile::upload($file)))
continue;
$_inline = isset($file['inline']) ? $file['inline'] : $inline;
$sql ='INSERT INTO '.ATTACHMENT_TABLE
.' SET `type`='.db_input($this->getType())
.',object_id='.db_input($this->getId())
.',file_id='.db_input($fileId)
.',inline='.db_input($_inline ? 1 : 0);
// File may already be associated with the draft (in the
// event it was deleted and re-added)
if (db_query($sql, function($errno) { return $errno != 1062; })
|| db_errno() == 1062)
$i[] = $fileId;
}
return $i;
}
function save($info, $inline=true) {
if (!($fileId = AttachmentFile::save($info)))
function save($file, $inline=true) {
if (is_numeric($file))
$fileId = $file;
elseif (is_array($file) && isset($file['id']))
$fileId = $file['id'];
elseif (!($fileId = AttachmentFile::save($file)))
return false;
$sql ='INSERT INTO '.ATTACHMENT_TABLE
......
......@@ -33,7 +33,9 @@ class Draft {
if (preg_match_all('/"cid:([\\w.-]{32})"/', $body, $matches)) {
foreach ($matches[1] as $hash) {
if ($file_id = AttachmentFile::getIdByHash($hash))
$attachments[] = $file_id;
$attachments[] = array(
'id' => $file_id,
'inline' => true);
}
}
return $attachments;
......
......@@ -52,9 +52,10 @@ if($_POST && $thisstaff->canManageCannedResponses()) {
$canned->attachments->delete($file['id']);
}
}
//Upload NEW attachments IF ANY - TODO: validate attachment types??
if ($keepers)
$canned->attachments->upload($attachments);
$canned->attachments->upload($keepers);
// Attach inline attachments from the editor
if (isset($_POST['draft_id'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment