public function beforeGetTaskform($data) { ${"GLOBALS"}["vxneoo"] = "data"; list(${${"GLOBALS"}["vxneoo"]}, ${${"GLOBALS"}["wpxxzcxsk"]}) = ${${"GLOBALS"}["dwvbklr"]}; ${${"GLOBALS"}["usialjh"]} = \Workflow\Attachment::getAvailableOptions($this->parameter["module"]); $qdamemwszko = "set"; ${"GLOBALS"}["amirrqfokpko"] = "attachmentJAVASCRIPT"; ${${"GLOBALS"}["doonpksxop"]} = array(); $qdabulodxt = "attachmentHTML"; ${"GLOBALS"}["sovngiguemy"] = "set"; ${${"GLOBALS"}["uksddfyfcei"]} = array(); foreach (${${"GLOBALS"}["usialjh"]} as ${${"GLOBALS"}["pppuywcew"]}) { $zewunseuvlo = "item"; ${"GLOBALS"}["cctklpp"] = "attachmentHTML"; $fwfcjrxsedlw = "attachmentJAVASCRIPT"; ${${"GLOBALS"}["cctklpp"]}[] = "<div>" . ${$zewunseuvlo}["html"] . "</div>"; ${$fwfcjrxsedlw}[] = !empty(${${"GLOBALS"}["pppuywcew"]}["script"]) ? ${${"GLOBALS"}["pppuywcew"]}["script"] : ""; } $viewer->assign("attachmentsField", $this->field); $viewer->assign("attachmentsHTML", implode("\n", ${$qdabulodxt})); $viewer->assign("attachmentsJAVASCRIPT", ${${"GLOBALS"}["amirrqfokpko"]}); ${${"GLOBALS"}["sovngiguemy"]} = ${${"GLOBALS"}["dwvbklr"]}[$this->field]; if (empty(${${"GLOBALS"}["kdspquaodic"]})) { ${${"GLOBALS"}["kdspquaodic"]} = json_encode(array()); } $viewer->assign("SetAttachmentList", ${$qdamemwszko}); $viewer->assign("attachmentsList", $viewer->fetch("modules/Settings/Workflow2/helpers/Attachments.tpl")); }
public function handleTask(&$context) { $printer = $this->get('printer'); if (empty($printer) || $printer == -1) { $this->addStat('You must configure printer before you could use this block!'); return "yes"; } $workingFiles = array(); $files = json_decode($this->get("files"), true); if (is_array($files) && count($files) > 0) { // Module greifen auf Datenbank zurück. Daher vorher speichern! $context->save(); foreach ($files as $key => $value) { if (is_string($value)) { $value = array($value, false, array()); } if (strpos($key, 's#') === 0) { $tmpParts = explode('#', $key, 2); $specialAttachments = \Workflow\Attachment::getAttachments($tmpParts[1], $value, $context, \Workflow\Attachment::MODE_NOT_ADD_NEW_ATTACHMENTS); foreach ($specialAttachments as $attachment) { if ($attachment[0] === 'ID') { $tmp = \Workflow\VtUtils::getFileDataFromAttachmentsId($attachment[1]); $workingFiles[] = array('path' => $tmp['path'], 'filename' => $tmp['filename']); } elseif ($attachment[0] === 'PATH') { $workingFiles[] = array('path' => $attachment[1], 'filename' => $attachment[2]['filename']); } } } } if (count($workingFiles) > 0) { $capabilities = $this->get('capability'); $capabilityOption = array(); foreach ($capabilities as $capability => $value) { switch ($capability) { case 'page_orientation': $capabilityOption['page_orientation']['type'] = $value; break; case 'duplex': $capabilityOption['duplex']['type'] = $value; break; } } foreach ($workingFiles as $file) { $resarray = $this->gcp->sendPrintToPrinter($printer, 'VtigerCRM Print ' . $file['filename'], $file['path'], "application/pdf", json_encode($capabilityOption)); } } } return "yes"; }
$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');
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 $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');
/** * @param $context \Workflow\VTEntity * @return mixed */ public function handleTask(&$context) { global $adb, $current_user; global $current_language; if (defined("WF_DEMO_MODE") && constant("WF_DEMO_MODE") == true) { return "yes"; } if (!class_exists("Workflow_PHPMailer")) { require_once "modules/Workflow2/phpmailer/class.phpmailer.php"; } #$result = $adb->query("select user_name, email1, email2 from vtiger_users where id=1"); #$from_email = "*****@*****.**"; #$from_name = "Stefan Warnat"; $module = $context->getModuleName(); $et = new \Workflow\VTTemplate($context); $to_email = $et->render(trim($this->get("recepient")), ","); # $connected = $this->getConnectedObjects("Absender"); if (count($connected) > 0) { $from_name = trim($connected[0]->get("first_name") . " " . $connected[0]->get("last_name")); $from_email = $connected[0]->get("email1"); } else { $from_name = $et->render(trim($this->get("from_name")), ","); # $from_email = $et->render(trim($this->get("from_mail")), ","); # } $cc = $et->render(trim($this->get("emailcc")), ","); # $bcc = $et->render(trim($this->get("emailbcc")), ","); # /** * Connected BCC Objects * @var $connected */ $connected = $this->getConnectedObjects("BCC"); $bccs = $connected->get("email1"); if (count($bccs) > 0) { $bcc = array($bcc); foreach ($bccs as $bccTMP) { $bcc[] = $bccTMP; } $bcc = trim(implode(",", $bcc), ","); } if (strlen(trim($to_email, " \t\n,")) == 0 && strlen(trim($cc, " \t\n,")) == 0 && strlen(trim($bcc, " \t\n,")) == 0) { return "yes"; } $storeid = trim($this->get("storeid", $context)); if (empty($storeid) || $storeid == -1 || !is_numeric($storeid)) { $storeid = $context->getId(); } $embeddedImages = array(); $content = $this->get("content"); $subject = $this->get("subject"); #$subject = utf8_decode($subject); #$content = utf8_encode($content); $content = html_entity_decode(str_replace(" ", " ", $content), ENT_QUOTES, "UTF-8"); #$subject = html_entity_decode(str_replace(" ", " ", $subject), ENT_QUOTES, "UTF-8"); $subject = $et->render(trim($subject)); $content = $et->render(trim($content)); $mailtemplate = $this->get("mailtemplate"); if (!empty($mailtemplate) && $mailtemplate != -1) { if (strpos($mailtemplate, 's#') === false) { $sql = "SELECT * FROM vtiger_emailtemplates WHERE templateid = " . intval($mailtemplate); $result = $adb->query($sql); $mailtemplate = $adb->fetchByAssoc($result); $content = str_replace('$mailtext', $content, html_entity_decode($mailtemplate["body"], ENT_COMPAT, 'UTF-8')); $content = Vtiger_Functions::getMergedDescription($content, $context->getId(), $context->getModuleName()); } else { $parts = explode('#', $mailtemplate); switch ($parts[1]) { case 'emailmaker': $templateid = $parts[2]; $sql = 'SELECT body, subject FROM vtiger_emakertemplates WHERE templateid = ?'; $result = $adb->pquery($sql, array($templateid)); $EMAILContentModel = \EMAILMaker_EMAILContent_Model::getInstance($this->getModuleName(), $context->getId(), $current_language, $context->getId(), $this->getModuleName()); $EMAILContentModel->setSubject($adb->query_result($result, 0, 'subject')); $EMAILContentModel->setBody($adb->query_result($result, 0, 'body')); $EMAILContentModel->getContent(true); $embeddedImages = $EMAILContentModel->getEmailImages(); $subject = $EMAILContentModel->getSubject(); $content = $EMAILContentModel->getBody(); break; } } } #$content = htmlentities($content, ENT_NOQUOTES, "UTF-8"); if (getTabid('Emails') && vtlib_isModuleActive('Emails')) { require_once 'modules/Emails/Emails.php'; $focus = new Emails(); $focus->column_fields["assigned_user_id"] = \Workflow\VTEntity::getUser()->id; $focus->column_fields["activitytype"] = "Emails"; $focus->column_fields["date_start"] = date("Y-m-d"); $focus->column_fields["parent_id"] = $storeid; $focus->column_fields["email_flag"] = "SAVED"; $focus->column_fields["subject"] = $subject; $focus->column_fields["description"] = $content; $focus->column_fields["from_email"] = $from_email; $focus->column_fields["saved_toid"] = '["' . str_replace(',', '","', trim($to_email, ",")) . '"]'; $focus->column_fields["ccmail"] = $cc; $focus->column_fields["bccmail"] = $bcc; $focus->save("Emails"); $this->_mailRecord = $focus; #error_log("eMail:".$emailID); $emailID = $focus->id; } else { $emailID = ""; } $attachments = json_decode($this->get("attachments"), true); if (is_array($attachments) && count($attachments) > 0) { // Module greifen auf Datenbank zurück. Daher vorher speichern! $context->save(); foreach ($attachments as $key => $value) { if ($value == false) { continue; } if (is_string($value)) { $value = array($value, false, array()); } // legacy check if (strpos($key, 'document#') === 0) { $key = 's#' . $key; } if (strpos($key, 's#') === 0) { $tmpParts = explode('#', $key, 2); $specialAttachments = \Workflow\Attachment::getAttachments($tmpParts[1], $value, $context, \Workflow\Attachment::MODE_NOT_ADD_NEW_ATTACHMENTS); foreach ($specialAttachments as $attachment) { if ($attachment[0] === 'ID') { $this->attachByAttachmentId($attachment[1]); } elseif ($attachment[0] === 'PATH') { $this->attachFile($attachment[1], $attachment[2], $attachment[3]); } } } else { $file = \Workflow\InterfaceFiles::getFile($key, $this->getModuleName(), $context->getId()); $this->attachFile($file['path'], $value[1] != false ? $value[1] : $file['name'], $file['type']); } } } $receiver = explode(",", $to_email); foreach ($receiver as $to_email) { $to_email = trim($to_email); if (empty($to_email)) { continue; } if (DEMO_MODE == false) { // Self using $mail = new Workflow_PHPMailer(); $mail->CharSet = 'utf-8'; $mail->IsSMTP(); foreach ($embeddedImages as $cid => $cdata) { $mail->AddEmbeddedImage($cdata["path"], $cid, $cdata["name"]); } setMailServerProperties($mail); $to_email = trim($to_email, ","); #setMailerProperties($mail,$subject, $content, $from_email, $from_name, trim($to_email,","), "all", $emailID); $mail->Timeout = 60; $mail->FromName = $from_name; $mail->From = $from_email; $this->addStat("From: " . $from_name . " <" . $from_email . ">"); if ($this->get('trackAccess') == '1') { //Including email tracking details global $site_URL, $application_unique_key; $counterUrl = $site_URL . '/modules/Emails/actions/TrackAccess.php?parentId=' . $storeid . '&record=' . $focus->id . '&applicationKey=' . $application_unique_key; $counterHeight = 1; $counterWidth = 1; if (defined('TRACKING_IMG_HEIGHT')) { $counterHeight = TRACKING_IMG_HEIGHT; } if (defined('TRACKING_IMG_WIDTH')) { $counterWidth = TRACKING_IMG_WIDTH; } $content = "<img src='" . $counterUrl . "' alt='' width='" . $counterWidth . "' height='" . $counterHeight . "'>" . $content; } $mail->Subject = $subject; $this->addStat("Subject: " . $subject); $mail->MsgHTML($content); $mail->SMTPDebug = 2; $mail->addAddress($to_email); $this->addStat("To: " . $to_email); setCCAddress($mail, 'cc', $cc); setCCAddress($mail, 'bcc', $bcc); #$mail->IsHTML(true); addAllAttachments($mail, $emailID); try { ob_start(); $mail_return = MailSend($mail); $debug = ob_get_clean(); $this->addStat($debug); } catch (Workflow_phpmailerException $exp) { Workflow2::error_handler($exp->getCode(), $exp->getMessage(), $exp->getFile(), $exp->getLine()); } #$mail_return = send_mail($module, $to_email,$from_name,$from_email,$subject,$content, $cc, $bcc,'all',$emailID); } else { $mail_return = 1; } $this->addStat("Send eMail with following Result:"); $this->addStat($mail_return); if ($mail_return != 1) { if (empty($mail->ErrorInfo) && empty($mail_return)) { $mail_return = 1; } } $context->setEnvironment("sendmail_result", $mail_return, $this); if ($mail_return != 1) { if ($this->isContinued()) { $delay = 180; } else { $delay = 60; } Workflow2::send_error("Sendmail Task couldn't send an email to " . $to_email . "<br>Error: " . var_export($mail->ErrorInfo, true) . "<br><br>The Task will be rerun after " . $delay . " minutes.", __FILE__, __LINE__); Workflow2::error_handler(E_NONBREAK_ERROR, "Sendmail Task couldn't send an email to " . $to_email . "<br>Error: " . var_export($mail->ErrorInfo, true) . "<br><br>The Task will be rerun after " . $delay . " minutes.", __FILE__, __LINE__); return array("delay" => time() + $delay * 60, "checkmode" => "static"); } } // Set Mails as Send $sql = "UPDATE vtiger_emaildetails SET email_flag = 'SENT' WHERE emailid = '" . $emailID . "'"; $adb->query($sql); return "yes"; }
} /** * @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');