$this->getAllChildAttachmentIds(\Workflow\VTEntity::getForId($crmid)); return; } } $sql = 'SELECT attachmentsid FROM vtiger_seattachmentsrel WHERE crmid = ?'; $result = $adb->pquery($sql, array(intval($key))); $attachmentID = $adb->query_result($result, 0, "attachmentsid"); $this->addAttachmentRecord('ID', $attachmentID); } /** * @param $context \Workflow\VTEntity */ public function getAllChildAttachmentIds($context) { $adb = \PearDatabase::getInstance(); $oldUser = vglobal('current_user'); vglobal('current_user', \Users::getActiveAdminUser()); $model = \Vtiger_Module_Model::getInstance($context->getModuleName()); $query = $model->getRelationQuery($context->getId(), 'get_attachments', \Vtiger_Module_Model::getInstance('Documents')); $parts = explode('FROM', $query, 2); $query = 'SELECT vtiger_attachments.attachmentsid as id FROM ' . $parts[1]; $result = $adb->query($query); $ids = array(); while ($row = $adb->fetchByAssoc($result)) { $this->addAttachmentRecord('ID', $row['id']); } vglobal('current_user', $oldUser); } } \Workflow\Attachment::register('documents', '\\Workflow\\Plugins\\Mailattachments\\Documents');
* @param $value * @param $context \Workflow\VTEntity * @return array|void */ public function generateAttachments($key, $value, $context) { global $current_user; $adb = \PearDatabase::getInstance(); $filestoreid = $value[2]['val']; $filestoreid = \Workflow\VTTemplate::parse($filestoreid, $context); $file = $context->getTempFiles($filestoreid); $filename = preg_replace('/[^A-Za-z0-9-_.]/', '_', $file['name']); if ($this->_mode === self::MODE_NOT_ADD_NEW_ATTACHMENTS) { $this->addAttachmentRecord('PATH', $file['path'], $filename); return; } $upload_file_path = decideFilePath(); $next_id = $adb->getUniqueID("vtiger_crmentity"); copy($file['path'], $upload_file_path . $next_id . "_" . $filename); $filetype = "application/octet-stream"; $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)"; $params1 = array($next_id, $current_user->id, $current_user->id, "Documents Attachment", 'Documents Attachment', date("Y-m-d H:i:s"), date("Y-m-d H:i:s")); $adb->pquery($sql1, $params1); $sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)"; $params2 = array($next_id, $filename, '', $filetype, $upload_file_path); $adb->pquery($sql2, $params2); $this->addAttachmentRecord('ID', $next_id); } } \Workflow\Attachment::register('filestore', '\\Workflow\\Plugins\\Mailattachments\\Filestore');
if (empty($filename)) { $filename = basename($url); } $filecontent = \Workflow\VtUtils::getContentFromUrl($url); if (empty($filecontent)) { return array(); } $filename = preg_replace('/[^A-Za-z0-9-_.]/', '_', $filename); if ($this->_mode === self::MODE_NOT_ADD_NEW_ATTACHMENTS) { $tmpfile = tempnam(sys_get_temp_dir(), 'Url'); @unlink($tmpfile); file_put_contents($tmpfile, $filecontent); $this->addAttachmentRecord('PATH', $tmpfile, $filename); return; } $upload_file_path = decideFilePath(); $next_id = $adb->getUniqueID("vtiger_crmentity"); file_put_contents($upload_file_path . $next_id . "_" . $filename, $filecontent); $filesize = filesize($upload_file_path . $next_id . "_" . $filename); $filetype = "application/octet-stream"; $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)"; $params1 = array($next_id, $current_user->id, $current_user->id, "Documents Attachment", 'Documents Attachment', date("Y-m-d H:i:s"), date("Y-m-d H:i:s")); $adb->pquery($sql1, $params1); $sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)"; $params2 = array($next_id, $filename, '', $filetype, $upload_file_path); $adb->pquery($sql2, $params2); $this->addAttachmentRecord('ID', $next_id); } } \Workflow\Attachment::register('url', '\\Workflow\\Plugins\\Mailattachments\\URL');
} /** * @param $key * @param $value * @param $context \Workflow\VTEntity * @return array|void */ public function generateAttachments($key, $value, $context) { global $current_user; $adb = \PearDatabase::getInstance(); $file = \Workflow\InterfaceFiles::getFile($value[2]['val'], $context->getModuleName(), $context->getId()); if ($this->_mode === self::MODE_NOT_ADD_NEW_ATTACHMENTS) { $this->addAttachmentRecord('PATH', $file['path'], $file['name']); return; } $upload_file_path = decideFilePath(); $next_id = $adb->getUniqueID("vtiger_crmentity"); copy($file['path'], $upload_file_path . $next_id . "_" . $file['name']); $filetype = "application/octet-stream"; $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)"; $params1 = array($next_id, $current_user->id, $current_user->id, "Workflow Attachment", 'Workflow Attachment', date("Y-m-d H:i:s"), date("Y-m-d H:i:s")); $adb->pquery($sql1, $params1); $sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)"; $params2 = array($next_id, $file['name'], '', $filetype, $upload_file_path); $adb->pquery($sql2, $params2); $this->addAttachmentRecord('ID', $next_id); } } \Workflow\Attachment::register('external', '\\Workflow\\Plugins\\Mailattachments\\External');