/**
  * @param $data     - Config Array of this Input with the following Structure
  *                      array(
  *                          'label' => 'Label the Function should use',
  *                          'name' => 'The Fieldname, which should submit the value, the Workflow will be write to Environment',
  *                          'config' => Key-Value Array with all configurations, done by admin
  *                      )
  * @param \Workflow\VTEntity $context - Current Record, which is assigned to the Workflow
  * @return array - The rendered content, shown to the user with the following structure
  *                  array(
  *                      'html' => '<htmlContentOfThisInputField>',
  *                      'javascript' => 'A Javascript executed after html is shown'
  *                  )
  *
  */
 public function renderFrontend($data, $context)
 {
     $relmod = $data['config']['module'];
     if (empty($data['config']['condition'])) {
         echo 'please configure condition!';
         return;
     }
     $adb = \PearDatabase::getInstance();
     $conditions = \Zend_Json::decode(base64_decode($data['config']['condition']));
     $logger = new \Workflow\ConditionLogger();
     $objMySQL = new \Workflow\ConditionMysql($relmod, $context);
     $objMySQL->setLogger($logger);
     $main_module = \CRMEntity::getInstance($relmod);
     $sqlCondition = $objMySQL->parse($conditions['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);
     $ids = array();
     while ($row = $adb->fetchByAssoc($result)) {
         $ids[] = $row['idcol'];
     }
     $mainData = \Workflow\VtUtils::getMainRecordData($relmod, $ids);
     uasort($mainData, function ($a, $b) {
         return strcmp($a["number"], $b["number"]);
     });
     $html = '';
     $script = '';
     $fieldId = 'field_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data['name']);
     $field = '<select style="width:410px;" name="' . $data['name'] . '" id="' . $fieldId . '" class="select2" data-placeholder="' . vtranslate('choose Reference', 'Workflow2') . '">';
     if (!empty($data['config']['nullable'])) {
         $field .= '<option value="" selected="selected"><em>- ' . vtranslate('no Selection', 'Workflow2') . '</em></option>';
     }
     if (count($mainData) > 0) {
         foreach ($mainData as $crmid => $record) {
             $field .= '<option value="' . $crmid . '" data-url="' . $record['link'] . '">[' . $record['number'] . '] ' . $record['label'] . '</option>';
         }
     }
     $field .= '</select>';
     $html = "<label><div style='min-height:26px;padding:2px 0;'><div style=''><strong>" . $data['label'] . "</strong></div><div style='text-align:right;'>" . $field . "<div style='display:none;margin-top:5px;' id='url_" . $data['name'] . "'></div></div></div></label>";
     $script = '';
     if (!empty($data['config']['nullable'])) {
         $script .= 'jQuery("#' . $fieldId . '").select2("val", "");';
     }
     $script .= 'jQuery("#' . $fieldId . '").on("change", function(e) {var selected = jQuery("#' . $fieldId . ' option:selected"); if(selected.val() == "") { jQuery("#url_' . $data['name'] . '").html("");return;}; jQuery("#url_' . $data['name'] . '").show().html("Link: <a href=\'" + selected.data("url") + "\' target=\'_blank\'><strong>" + selected.text() + "</strong></a>");
      });';
     return array('html' => $html, 'javascript' => $script);
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * @param $context \Workflow\VTEntity
  * @return string
  */
 public function handleTask(&$context)
 {
     global $list_max_entries_per_page, $adb, $currentModule;
     $old_list_max_entries_per_page = $list_max_entries_per_page;
     if ($this->get("related_module") == -1) {
         return "no";
     }
     $currentModule = $this->getModuleName();
     $found_rows = $this->get("found_rows");
     if (empty($found_rows) || $found_rows == -1) {
         $found_rows = 1;
     }
     $parts = explode("#~#", $this->get("related_module"));
     $functionName = $parts[0];
     $relatedModuleName = \Workflow\VtUtils::getModuleName($parts[1]);
     //$relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $relatedModuleName, $label);
     $parentRecordModel = Vtiger_Record_Model::getInstanceById($context->getId(), $context->getModuleName());
     /**
      * @var Vtiger_RelationListView_Model $relatedListView
      */
     $relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $relatedModuleName);
     $query = $relationListView->getRelationQuery();
     $query = preg_replace('/SELECT(.+)FROM/imU', 'SELECT vtiger_crmentity.crmid FROM', $query);
     $logger = new \Workflow\ConditionLogger();
     $relModule = \Workflow\VtUtils::getModuleName($parts[1]);
     $objMySQL = new \Workflow\ConditionMysql($relModule, $context);
     $objMySQL->setLogger($logger);
     $main_module = \CRMEntity::getInstance($relModule);
     $sqlCondition = $objMySQL->parse($this->get("condition"));
     $sqlTables = $objMySQL->generateTables();
     $logs = $logger->getLogs();
     $this->setStat($logs);
     $idColumn = $main_module->table_name . "." . $main_module->table_index;
     $sqlQuery = "SELECT {$idColumn} " . $sqlTables . " WHERE {$idColumn} IN (" . $query . ")" . (strlen($sqlCondition) > 3 ? " AND " . $sqlCondition : "");
     $this->addStat("MySQL Query: " . $sqlQuery);
     $result = $adb->query($sqlQuery, true);
     $this->addStat("num Rows: " . $adb->num_rows($result));
     $this->addStat("have to at least x rows: " . $found_rows);
     if ($adb->num_rows($result) >= $found_rows) {
         return 'yes';
     }
     return "no";
 }
Пример #4
0
 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";
 }
 /**
  * @param $context \Workflow\VTEntity
  * @return string
  */
 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;
     }
     $recordsource = $this->get('recordsource');
     if (empty($recordsource) || $recordsource == -1) {
         $recordsource = 'condition';
     }
     $parts = explode("#~#", $this->get("search_module"));
     $functionName = $parts[0];
     $related_module = VtUtils::getModuleName($parts[1]);
     $recordids = array();
     if ($recordsource == 'condition') {
         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"));
         $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);
         $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");
         $sqlQuery .= ' GROUP BY crmid ';
         if (!empty($sortField) && $sortField != -1) {
             $sortDirection = $this->get("sortDirection");
             $sortField = VtUtils::getColumnName($sortField);
             $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection;
         }
         $numRows = $this->get("found_rows");
         if (!empty($numRows) && $numRows != -1) {
             $sqlQuery .= " LIMIT " . $found_rows;
         }
         $this->addStat("MySQL Query: " . $sqlQuery);
         $result = $adb->query($sqlQuery, true);
         $this->addStat("num Rows: " . $adb->num_rows($result));
         while ($row = $adb->fetchByAssoc($result)) {
             $recordids[] = $row["idcol"];
         }
     }
     if ($recordsource == 'customview') {
         $queryGenerator = new \QueryGenerator($related_module, \Users::getActiveAdminUser());
         $queryGenerator->initForCustomViewById($this->get('customviewsource'));
         $query = $queryGenerator->getQuery();
         $parts = preg_split('/FROM/i', $query);
         $sqlQuery = 'SELECT vtiger_crmentity.crmid as id_col FROM ' . $parts[1];
         $result = $adb->query($sqlQuery, true);
         $this->addStat("num Rows: " . $adb->num_rows($result));
         while ($row = $adb->fetchByAssoc($result)) {
             $recordids[] = $row["id_col"];
         }
     }
     $filterbyproduct = $this->get('filterbyproduct');
     if ($filterbyproduct === 'yes') {
         $products = $this->get('products');
         if (!empty($products)) {
             $sql = 'SELECT id FROM vtiger_inventoryproductrel WHERE id IN (' . generateQuestionMarks($recordids) . ') AND productid = ? GROUP BY id';
             $recordids[] = $products;
             $result = $adb->pquery($sql, $recordids);
             $recordids = array();
             while ($row = $adb->fetchByAssoc($result)) {
                 $recordids[] = $row['id'];
             }
         }
     }
     $workflow_id = $this->get("workflow_id");
     if (!empty($workflow_id)) {
         foreach ($recordids as $recordId) {
             $tmpContext = \Workflow\VTEntity::getForId($recordId, $related_module);
             $tmpContext->clearEnvironment();
             $tmpContext->loadEnvironment($context->getEnvironment());
             $obj = new \Workflow\Main($workflow_id, false, $context->getUser());
             $obj->setExecutionTrigger($this->getWorkflow()->getExecutionTrigger());
             $obj->setContext($tmpContext);
             $obj->isSubWorkflow(true);
             $obj->start();
             if ($obj->getSuccessRedirection() != false) {
                 $this->getWorkflow()->setSuccessRedirection($obj->getSuccessRedirection());
                 $this->getWorkflow()->setSuccessRedirectionTarget($obj->getSuccessRedirectionTarget());
             }
             $env = $this->get("env");
             if ($env !== -1 && !empty($env["result_environments"])) {
                 $oldEnv = $context->getEnvironment($env["result_environments"]);
                 $oldEnv[] = $tmpContext->getEnvironment();
                 $context->setEnvironment("result_environments", $oldEnv, $this);
             }
         }
     }
     return "yes";
 }
 public function handleTask(&$context)
 {
     $adb = \PearDatabase::getInstance();
     /* Insert here source code to execute the task */
     $currentTime = microtime(true);
     $benchmark = array();
     $found_rows = $this->get("found_rows");
     if (empty($found_rows) || $found_rows == -1) {
         $found_rows = 1;
     }
     $id = $this->get('recordid', $context);
     if (empty($id) || $id == -1 || !is_numeric($id)) {
         $targetContext = $context;
     } else {
         $targetContext = \Workflow\VTEntity::getForId($id);
     }
     $logger = new \Workflow\ConditionLogger();
     $objMySQL = new \Workflow\ConditionMysql('Emails', $targetContext);
     $objMySQL->setLogger($logger);
     $sqlCondition = $objMySQL->parse($this->get("condition"));
     $newTime = microtime(true);
     $benchmark[] = round($newTime - $currentTime, 3);
     $currentTime = $newTime;
     $sqlTables = $objMySQL->generateTables();
     //$sqlTables .= "\nLEFT JOIN vtiger_email_track ON(vtiger_email_track.crmid = vtiger_crmentity.crmid)";
     if (strlen($sqlCondition) > 3) {
         $sqlCondition .= " AND vtiger_crmentity.deleted = 0 AND (vtiger_email_track.crmid IS NULL OR vtiger_email_track.crmid = " . $targetContext->getId() . ')';
     } else {
         $sqlCondition .= " vtiger_crmentity.deleted = 0 AND (vtiger_email_track.crmid IS NULL OR vtiger_email_track.crmid = " . $targetContext->getId() . ')';
     }
     $logs = $logger->getLogs();
     $this->setStat($logs);
     $main_module = \CRMEntity::getInstance('Emails');
     $sqlCondition .= " GROUP BY vtiger_crmentity.crmid ";
     $idColumn = $main_module->table_name . "." . $main_module->table_index;
     $sqlQuery = "SELECT {$idColumn} as `idCol`, vtiger_email_track.access_count as access_count " . $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;
     }
     $numRows = $this->get("found_rows");
     if (!empty($numRows) && $numRows != -1) {
         $sqlQuery .= " LIMIT " . $found_rows;
     }
     #var_dump(nl2br($sqlQuery));exit();
     $this->addStat("MySQL Query: " . $sqlQuery);
     //echo $sqlQuery;
     $result = $adb->query($sqlQuery, true);
     $newTime = microtime(true);
     $benchmark[] = round($newTime - $currentTime, 3);
     $currentTime = $newTime;
     $this->addStat("num Rows: " . $adb->num_rows($result));
     # If no records are found, fo other way
     if ($adb->num_rows($result) == 0) {
         return "not_found";
     }
     while ($row = $adb->fetchByAssoc($result)) {
         if ($row['access_count'] > 0) {
             return 'yes';
         }
     }
     return "no";
 }
 /**
  * @param $context \Workflow\VTEntity
  * @return string
  */
 public function handleTask(&$context)
 {
     global $adb;
     $currentTime = microtime(true);
     $benchmark = array();
     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]);
     $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);
     if ($related_module == "Calendar") {
         #$sqlTables .= " LEFT JOIN vtiger_seactivityrel ON(vtiger_seactivityrel.activityid = vtiger_crmentity.crmid)";
     }
     $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;
     }
     $numRows = $this->get("found_rows");
     if (!empty($numRows) && $numRows != -1) {
         $sqlQuery .= " LIMIT " . $found_rows;
     }
     #var_dump(nl2br($sqlQuery));exit();
     $this->addStat("MySQL Query: " . $sqlQuery);
     $result = $adb->query($sqlQuery);
     $newTime = microtime(true);
     $benchmark[] = round($newTime - $currentTime, 3);
     $currentTime = $newTime;
     $this->addStat("num Rows: " . $adb->num_rows($result));
     # If no records are found, fo other way
     if ($adb->num_rows($result) == 0) {
         return "no";
     }
     $environment = $context->getEnvironment();
     while ($row = $adb->fetchByAssoc($result)) {
         $expression = $this->get("expression");
         if (!empty($expression)) {
             $tmpContext = \Workflow\VTEntity::getForId($row["idcol"], $related_module);
             $tmpContext->loadEnvironment($environment);
             $parser = new \Workflow\ExpressionParser($expression, $tmpContext, false);
             # Last Parameter = DEBUG
             try {
                 $parser->run();
             } catch (ExpressionException $exp) {
                 Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", "");
             }
             $environment = $tmpContext->getEnvironment();
         }
     }
     # while
     $newTime = microtime(true);
     $benchmark[] = round($newTime - $currentTime, 3);
     $currentTime = $newTime;
     $context->loadEnvironment($environment);
     $this->addStat("Benchmark: " . implode("/", $benchmark));
     return "yes";
 }