public function handleTask(&$context) { global $adb; if ($this->get("search_module") == -1) { return "no"; } $found_rows = $this->get("found_rows"); if (empty($found_rows) || $found_rows == -1) { $found_rows = 1; } $parts = explode("#~#", $this->get("search_module")); $functionName = $parts[0]; $related_module = VtUtils::getModuleName($parts[1]); require_once 'modules/Workflow2/VTConditionMySql.php'; $logger = new \Workflow\ConditionLogger(); $objMySQL = new \Workflow\ConditionMysql($related_module, $context); $objMySQL->setLogger($logger); $main_module = CRMEntity::getInstance($related_module); #$sqlTables = $main_module->generateReportsQuery($related_module); $sqlCondition = $objMySQL->parse($this->get("condition")); if (strlen($sqlCondition) > 3) { $sqlCondition .= "AND vtiger_crmentity.deleted = 0"; } else { $sqlCondition .= "vtiger_crmentity.deleted = 0"; } $logs = $logger->getLogs(); $this->setStat($logs); $sqlTables = $objMySQL->generateTables(); $idColumn = $main_module->table_name . "." . $main_module->table_index; $sqlQuery = "SELECT {$idColumn} as idCol " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : "") . ' GROUP BY vtiger_crmentity.crmid'; $this->addStat("MySQL Query: " . $sqlQuery); $result = $adb->query($sqlQuery); if ($adb->database->ErrorMsg() != "") { $this->addStat($adb->database->ErrorMsg()); } $context->setEnvironment('count_results', $adb->num_rows($result), $this); $this->addStat("num Rows: " . $adb->num_rows($result)); $this->addStat("have to at least x rows: " . $found_rows); $resultEnv = $this->get('resultEnv'); if (!empty($resultEnv) && $resultEnv != -1) { $ids = array(); while ($row = $adb->fetchByAssoc($result)) { $ids[] = $row['idcol']; } $context->setEnvironment($resultEnv, array('ids' => $ids, 'moduleName' => $related_module)); } if ($adb->num_rows($result) >= $found_rows) { $return = "yes"; } else { return "no"; } return $return; }
public function init() { $related_module = $this->get("related_module"); if (!empty($_POST["task"]["related_module"])) { $toModule = $_POST["task"]["related_module"]; } elseif (!empty($related_module) && $related_module != -1) { $toModule = $related_module; } if (isset($toModule)) { $parts = explode("#~#", $toModule); $related_module_name = VtUtils::getModuleName($parts[1]); $this->addPreset("Condition", "condition", array('fromModule' => $this->getModuleName(), 'toModule' => $related_module_name)); } }
public function handleTask(&$context) { $adb = \PearDatabase::getInstance(); if (!getTabid('PDFMaker') || !vtlib_isModuleActive('PDFMaker')) { throw new \Exception('PDFMaker Extension not found!'); } /* Insert here source code to execute the task */ $recordChooser = $this->get('recordChooser'); if (empty($recordChooser) || $recordChooser == -1) { throw new \Exception('You need to configure the PDFMaker Integraion.'); } $recordIds = array(); if ($recordChooser === 'current') { $recordIds = array($context->getId()); $moduleName = $this->getModuleName(); } else { $currentTime = microtime(true); $benchmark = array(); $parts = explode("#~#", $this->get("search_module")); $related_module = VtUtils::getModuleName($parts[1]); $moduleName = $related_module; $logger = new \Workflow\ConditionLogger(); $objMySQL = new \Workflow\ConditionMysql($related_module, $context); $objMySQL->setLogger($logger); $main_module = \CRMEntity::getInstance($related_module); $sqlCondition = $objMySQL->parse($this->get("condition")); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $sqlTables = $objMySQL->generateTables(); if (strlen($sqlCondition) > 3) { $sqlCondition .= " AND vtiger_crmentity.deleted = 0"; } else { $sqlCondition .= " vtiger_crmentity.deleted = 0"; } $logs = $logger->getLogs(); $this->setStat($logs); $sqlCondition .= " GROUP BY vtiger_crmentity.crmid "; $idColumn = $main_module->table_name . "." . $main_module->table_index; $sqlQuery = "SELECT {$idColumn} as `idCol` " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : ""); $sortField = $this->get("sort_field"); if (!empty($sortField) && $sortField != -1) { $sortField = VtUtils::getColumnName($sortField); $sortDirection = $this->get("sortDirection"); $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection; } $this->addStat("MySQL Query: " . $sqlQuery); $result = $adb->query($sqlQuery, true); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $this->addStat("num Rows: " . $adb->num_rows($result)); # If no records are found, fo other way if ($adb->num_rows($result) == 0) { return "yes"; } $this->addStat("Benchmark: " . implode("/", $benchmark)); while ($row = $adb->fetchByAssoc($result)) { $recordIds[] = $row['idcol']; } } $context->save(); $useUser = Users::getActiveAdminUser(); $oldUser = vglobal('current_user'); vglobal('current_user', $useUser); $PDFMaker = new PDFMaker_PDFMaker_Model(); $dl = Vtiger_Language_Handler::getLanguage(); $mpdf = ""; $copies = $this->get('copies'); if ($copies == -1 || empty($copies)) { $copies = 1; } $templateids = array(); for ($i = 0; $i < $copies; $i++) { $templateids = array_merge($templateids, $this->get("template")); } $filename = $PDFMaker->GetPreparedMPDF($mpdf, $recordIds, $templateids, $moduleName, $dl, ''); if (strpos($filename, '.pdf') === false) { $filename .= '.pdf'; } // $filename = $PDFMaker->generate_cool_uri($filename); $tmpfile = tempnam(sys_get_temp_dir(), 'WfTmp'); @unlink($tmpfile); $mpdf->Output($tmpfile); $overwriteFilename = $this->get("filename", $context); if ($overwriteFilename != -1 && !empty($overwriteFilename)) { $filename = $overwriteFilename; } \Workflow\FileAction::doActions($this->get('resultaction'), $tmpfile, $filename, $context, $recordIds, $this->getWorkflow()); vglobal('current_user', $oldUser); return "yes"; }
public function beforeGetTaskform($viewer) { global $adb, $current_language, $mod_strings; $viewer->assign("related_modules", VtUtils::getEntityModules(true)); $search_module = $this->get("search_module"); if (!empty($_POST["task"]["search_module"])) { $parts = explode("#~#", $_POST["task"]["search_module"]); } elseif (!empty($search_module)) { if ($search_module != -1) { $parts = explode("#~#", $search_module); } } else { return; } if (!empty($parts)) { $viewer->assign("related_tabid", $parts[1]); $search_module_name = VtUtils::getModuleName($parts[1]); #$workflowSettings = $this->getWorkflow()->getSettings(); $workflows = $workflows = Workflow2::getWorkflowsForModule($search_module_name, 1); $viewer->assign("workflows", $workflows); $fields = VtUtils::getFieldsWithBlocksForModule($search_module_name); $viewer->assign("sort_fields", $fields); $moduleObj = \Vtiger_Module_Model::getInstance($search_module_name); $viewer->assign('productCache', array()); if ($moduleObj instanceof \Inventory_Module_Model) { $viewer->assign('searchByProduct', true); $product = $this->get('products'); if (!empty($product)) { //$dataObj = \Vtiger_Record_Model::getInstanceById($product); $productCache[$product] = array('label' => \Vtiger_Functions::getCRMRecordLabel($product)); $viewer->assign('productCache', $productCache); } } $views = array(); $allviews = \CustomView_Record_Model::getAll($search_module_name); foreach ($allviews as $view) { $views[$view->get('cvid')] = $view->get('viewname'); } $viewer->assign('customviews', $views); } }
public function beforeGetTaskform($viewer) { global $adb, $current_language, $mod_strings; $viewer->assign("related_modules", VtUtils::getEntityModules(true)); $search_module = $this->get("search_module"); if (!empty($_POST["task"]["search_module"])) { $parts = explode("#~#", $_POST["task"]["search_module"]); } elseif (!empty($search_module)) { if ($search_module != -1) { $parts = explode("#~#", $search_module); } } else { return; } if (!empty($parts)) { $viewer->assign("search_module", $parts[0]); $viewer->assign("related_tabid", $parts[1]); $search_module_name = VtUtils::getModuleName($parts[1]); #$workflowSettings = $this->getWorkflow()->getSettings(); $fields = VtUtils::getFieldsWithBlocksForModule($search_module_name); $viewer->assign("sort_fields", $fields); } }