public function doTask($entityData) { global $current_user, $log, $root_directory; $request = new Vtiger_Request($_REQUEST, $_REQUEST); $adb = PearDatabase::getInstance(); $PDFMaker = new PDFMaker_PDFMaker_Model(); $userId = $entityData->get('assigned_user_id'); if ($userId === null) { $userId = vtws_getWebserviceEntityId('Users', 1); } $moduleName = $entityData->getModuleName(); $adminUser = $this->getAdmin(); $id = $entityData->getId(); list($id2, $assigned_user_id) = explode("x", $userId); list($id3, $parentid) = explode("x", $id); $focus = CRMEntity::getInstance("Documents"); $focus->parentid = $parentid; $modFocus = CRMEntity::getInstance($moduleName); if (isset($focus->parentid)) { $modFocus->retrieve_entity_info($focus->parentid, $moduleName); $modFocus->id = $focus->parentid; } $templateid = $this->template; if ($templateid != "" && $templateid != "0") { if ($PDFMaker->isTemplateDeleted($templateid)) { return; } $foldername = $adb->getOne("SELECT foldername FROM vtiger_attachmentsfolder WHERE folderid='" . $this->folder . "'", 0, "foldername"); $fieldname = $adb->getOne("SELECT fieldname FROM vtiger_field WHERE uitype=4 AND tabid=" . getTabId($moduleName), 0, "fieldname"); if (isset($modFocus->column_fields[$fieldname]) && $modFocus->column_fields[$fieldname] != "") { $file_name = $PDFMaker->generate_cool_uri($foldername . "_" . $modFocus->column_fields[$fieldname]) . ".pdf"; } else { $file_name = $PDFMaker->generate_cool_uri($foldername . "_" . $templateid . $focus->parentid . date("ymdHi")) . ".pdf"; } $focus->column_fields['notes_title'] = $this->title; $focus->column_fields['assigned_user_id'] = $assigned_user_id; $focus->column_fields['filename'] = $file_name; $focus->column_fields['notecontent'] = $this->description; $focus->column_fields['filetype'] = 'application/pdf'; $focus->column_fields['filesize'] = ''; $focus->column_fields['filelocationtype'] = 'I'; $focus->column_fields['fileversion'] = ''; $focus->column_fields['filestatus'] = 'on'; $focus->column_fields['folderid'] = $this->folder; $focus->save('Documents'); $language = $this->template_language; $PDFMaker->createPDFAndSaveFile($request, $templateid, $focus, $modFocus, $file_name, $moduleName, $language); } }
/** * @param $context VTEntity */ public function handleTask(&$context) { if (!getTabid('PDFMaker') || !vtlib_isModuleActive('PDFMaker')) { return 'yes'; } global $adb, $current_user, $log, $root_directory; // PDFMaker greift auf Datenbank zurück. Daher zuerst speichern! $context->save(); $userId = $context->get('assigned_user_id'); if ($userId === null) { $userId = vtws_getWebserviceEntityId('Users', 1); } $moduleName = $context->getModuleName(); $id = $context->getId(); list($id2, $assigned_user_id) = explode("x", $userId); $parentid = $id; require_once 'modules/Documents/Documents.php'; $focus = new \Documents(); $focus->parentid = $parentid; $modFocus = $context->getInternalObject(); $templateid = $this->template; $this->folder = 1; $foldername = $adb->getOne("SELECT foldername FROM vtiger_attachmentsfolder WHERE folderid='" . $this->folder . "'", 0, "foldername"); $fieldname = $adb->getOne("SELECT fieldname FROM vtiger_field WHERE uitype=4 AND tabid=" . getTabId($moduleName), 0, "fieldname"); /* new PDFMaker Routine */ $PDFMaker = new PDFMaker_PDFMaker_Model(); if (isset($modFocus->column_fields[$fieldname]) && $modFocus->column_fields[$fieldname] != "") { $file_name = $PDFMaker->generate_cool_uri($modFocus->column_fields[$fieldname]) . ".pdf"; } else { $file_name = generate_cool_uri($foldername . "_" . $templateid . $focus->parentid . date("ymdHi")) . ".pdf"; } $this->addStat("Attach Document '" . $file_name . "'"); $docTitle = $this->get("documenttitle", $context); $docDescr = $this->get("documentdescr", $context); $focus->column_fields['notes_title'] = $docTitle; $focus->column_fields['assigned_user_id'] = $assigned_user_id; $focus->column_fields['filename'] = $file_name; $focus->column_fields['notecontent'] = $docDescr; $focus->column_fields['filetype'] = 'application/pdf'; $focus->column_fields['filesize'] = ''; $focus->column_fields['filelocationtype'] = 'I'; $focus->column_fields['fileversion'] = ''; $focus->column_fields['filestatus'] = 'on'; $focus->column_fields['folderid'] = $this->get("folderid"); $focus->save('Documents'); $language = $current_user->language; $request = $_REQUEST; $_REQUEST['search'] = true; $_REQUEST['submode'] = true; if ($current_user->is_admin != "on") { $useUser = Users::getActiveAdminUser(); } else { $useUser = $current_user; } $oldCurrentUser = $current_user; $current_user = $useUser; $dummyRequest = new Vtiger_Request(array()); $PDFMaker->createPDFAndSaveFile($dummyRequest, $this->get("template"), $focus, $modFocus, $file_name, $this->getModuleName(), $language); $current_user = $oldCurrentUser; $_REQUEST = $request; /* new PDFMaker Routine */ $overwriteFilename = $this->get("filename", $context); if ($overwriteFilename != -1 && !empty($overwriteFilename)) { global $root_directory; $sql = "SELECT attachmentsid FROM vtiger_seattachmentsrel WHERE crmid = " . $focus->id . " ORDER BY attachmentsid DESC LIMIT 1"; $result = $adb->query($sql); if ($adb->num_rows($result) > 0) { $attachmentsid = $adb->query_result($result, 0, "attachmentsid"); $attRst = $adb->query("SELECT * FROM vtiger_attachments WHERE attachmentsid = " . $attachmentsid); $attachment = $adb->fetchByAssoc($attRst); $oldFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $attachment["name"]; $newFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $overwriteFilename; @rename($oldFilename, $newFilename); $adb->pquery("UPDATE vtiger_attachments SET name = ? WHERE attachmentsid = " . $attachmentsid, array($overwriteFilename)); $adb->pquery("UPDATE vtiger_notes SET filename = ? WHERE notesid = " . $focus->id, array($overwriteFilename)); } $file_name = $foldername . "_" . $overwriteFilename; } $_REQUEST = $request; if ($this->get("createrel") === "1") { $sql = "INSERT INTO vtiger_senotesrel SET crmid = " . $context->getId() . ", notesid = " . $focus->id; $adb->query($sql); } else { $sql = "DELETE FROM vtiger_senotesrel WHERE crmid = " . $context->getId() . " AND notesid = " . $focus->id; $adb->query($sql); } $newContext = \Workflow\VTEntity::getForId($focus->id, "Documents"); if ($this->get("workflow") !== "") { $objWorkflow = new \Workflow\Main($this->get("workflow"), false, $context->getUser()); $objWorkflow->setContext($newContext); $objWorkflow->isSubWorkflow(true); $objWorkflow->start(); } $context->setEnvironment("new_record_id", $newContext->getWsId(), $this); return "yes"; }
public function doTask($entity) { global $current_user; $util = new VTWorkflowUtils(); $admin = $util->adminUser(); $module = $entity->getModuleName(); $taskContents = Zend_Json::decode($this->getContents($entity)); $from_email = $taskContents['fromEmail']; $from_name = $taskContents['fromName']; $to_email = $taskContents['toEmail']; $cc = $taskContents['ccEmail']; $bcc = $taskContents['bccEmail']; $subject = $taskContents['subject']; $content = $taskContents['content']; if (!empty($to_email)) { //Storing the details of emails $entityIdDetails = vtws_getIdComponents($entity->getId()); $entityId = $entityIdDetails[1]; $moduleName = 'Emails'; $userId = $current_user->id; $emailFocus = CRMEntity::getInstance($moduleName); $emailFieldValues = array('assigned_user_id' => $userId, 'subject' => $subject, 'description' => $content, 'from_email' => $from_email, 'saved_toid' => $to_email, 'ccmail' => $cc, 'bccmail' => $bcc, 'parent_id' => $entityId . "@{$userId}|", 'email_flag' => 'SENT', 'activitytype' => $moduleName, 'date_start' => date('Y-m-d'), 'time_start' => date('H:i:s'), 'mode' => '', 'id' => ''); $emailFocus->column_fields = $emailFieldValues; $emailFocus->save($moduleName); //Including email tracking details global $site_URL, $application_unique_key; $emailId = $emailFocus->id; $trackURL = "{$site_URL}/modules/Emails/TrackAccess.php?record={$entityId}&mailid={$emailId}&app_key={$application_unique_key}"; $content = "<img src='{$trackURL}' alt='' width='1' height='1'>{$content}"; if (stripos($content, '<img src="cid:logo" />')) { $logo = 1; } if (is_array($this->template)) { $Templates = $this->template; } else { $Templates = array($this->template); } if (count($Templates) > 0) { $request = new Vtiger_Request($_REQUEST, $_REQUEST); $adb = PearDatabase::getInstance(); $PDFMaker = new PDFMaker_PDFMaker_Model(); list($id3, $id) = explode("x", $entity->getId()); $modFocus = CRMEntity::getInstance($module); $modFocus->retrieve_entity_info($id, $module); $modFocus->id = $id; $language = $this->template_language; foreach ($Templates as $templateid) { if ($templateid != "0" && $templateid != "") { if ($PDFMaker->isTemplateDeleted($templateid)) { return; } $result = $adb->query("SELECT fieldname FROM vtiger_field WHERE uitype=4 AND tabid=" . getTabId($module)); $fieldname = $adb->query_result($result, 0, "fieldname"); if (isset($modFocus->column_fields[$fieldname]) && $modFocus->column_fields[$fieldname] != "") { $file_name = $PDFMaker->generate_cool_uri($modFocus->column_fields[$fieldname]) . ".pdf"; } else { $file_name = $templateid . $emailFocus->parentid . date("ymdHi") . ".pdf"; } $PDFMaker->createPDFAndSaveFile($request, $templateid, $emailFocus, $modFocus, $file_name, $module, $language); } } $status = send_mail($module, $to_email, $from_name, $from_email, $subject, $content, $cc, $bcc, 'all', $emailId, $logo); } else { $status = send_mail($module, $to_email, $from_name, $from_email, $subject, $content, $cc, $bcc, '', '', $logo); } if (!empty($emailId)) { $emailFocus->setEmailAccessCountValue($emailId); } if (!$status) { //If mail is not sent then removing the details about email $emailFocus->trash($moduleName, $emailId); } } $util->revertUser(); }