diff --git a/include/class.attachment.php b/include/class.attachment.php index 2e3b8c55e303ff74996a538352bb9fb46c674fd8..d562b31a095fa69251f62af687d14f40dfda0243 100644 --- a/include/class.attachment.php +++ b/include/class.attachment.php @@ -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 diff --git a/include/class.draft.php b/include/class.draft.php index cc6ad1fef9a2d7291c407ed61149dc690aa1eb4f..cdb5d43f440081d3e047993dd0df006cf23c39d6 100644 --- a/include/class.draft.php +++ b/include/class.draft.php @@ -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; diff --git a/scp/canned.php b/scp/canned.php index a600cee5ab0cab61cfc65bb6ad50e5f10b123a83..5de2f87b50e128d08c615275f9c6e2e25b5d14e8 100644 --- a/scp/canned.php +++ b/scp/canned.php @@ -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'])