/** * Adds the attachments for a given message idenfitied by messageid, from user fromuserid and to * user touserid. This method will create a new file in the /uploads directory for each attachment * and add a link in the attachments table to both the fromuserid (in the output folder) and the * touserid (in the inbox folder). * @param Int $fromuserid id of the user sending the message. * @param Int $touserid id of the user to send the message to. * @param String $inboxmsgid id of the message inserted in inbox. * @param String $outboxmsgid id of the message inserted in inbox. * @param Array $attachments array of $_FILES with the attachments. * @return boolean true if successful, false otherwise */ protected function addAttachmentsForMessage($inboxmsgid, $outboxmsgid, $fromuserid, $touserid, $attachments, $attachmentTag) { // no files, empty files. if (!isset($attachments)) { return true; } if (!is_array($attachments)) { return true; } if (count($attachments) < 1) { return true; } // Assign a new hashed name for files and store them. require_once 'CRMUtils.php'; // iterate through all the attachments and create the inbox/outbox links. for ($i = 0; $i < count($attachments[$attachmentTag]["tmp_name"]); $i++) { if ($attachments[$attachmentTag]['error'][$i] != UPLOAD_ERR_OK) { continue; } $relativeURL = \creamy\CRMUtils::generateUploadRelativePath($attachments[$attachmentTag]['name'][$i], true); $filepath = \creamy\CRMUtils::creamyBaseDirectoryPath() . $relativeURL; if (move_uploaded_file($attachments[$attachmentTag]['tmp_name'][$i], $filepath)) { // successfully moved upload. // inbox attachment. $data = array("message_id" => $inboxmsgid, "folder_id" => MESSAGES_GET_INBOX_MESSAGES, "filepath" => $relativeURL, "filetype" => $attachments[$attachmentTag]['type'][$i], "filesize" => $attachments[$attachmentTag]['size'][$i]); if (!$this->dbConnector->insert(CRM_ATTACHMENTS_TABLE_NAME, $data)) { return false; } // outbox attachment. $data["message_id"] = $outboxmsgid; $data["folder_id"] = MESSAGES_GET_SENT_MESSAGES; if (!$this->dbConnector->insert(CRM_ATTACHMENTS_TABLE_NAME, $data)) { return false; } } else { return false; } } return true; }