getViewer($request); $moduleModel = Vtiger_Module_Model::getInstance("Workflow2"); $viewer->assign('VERSION', $moduleModel->version); global $current_user; $adb = PearDatabase::getInstance(); //Zend_Json::$useBuiltinEncoderDecoder = true; $this->moduleName = $request->getModule(); $this->qualifiedModuleName = $request->getModule(false); $this->settingsModel = Settings_Vtiger_Module_Model::getInstance($this->qualifiedModuleName); $viewer = $this->getViewer($request); $this->workflowID = $workflowID = intval($_GET["workflow"]); $workflowObj = new Main($workflowID); $runningCounter = $workflowObj->countRunningInstances(); $errorCounter = $workflowObj->countLastError(); $this->workflowData = $workflowObj->getSettings(); $workflowObj->setExecutionTrigger($this->workflowData['trigger']); if(!empty($this->workflowData["module_name"])) { $types = $this->settingsModel->getTypes($this->workflowData["module_name"], $workflowObj->getExecutionTrigger()); $typesCat = $this->settingsModel->getTypeCats($this->workflowData["module_name"]); $viewer->assign("types", $types); $viewer->assign("typesCat", $typesCat); $html = $this->getWorkflowBlockHTML(); $viewer->assign("html", $html); $viewer->assign("WorkflowObjectHTML", $this->getWorkflowObjectHTML()); $recordModel = \Vtiger_Module_Model::getInstance($this->workflowData["module_name"]); if($recordModel instanceof \Inventory_Module_Model) { $viewer->assign('IsInventory', true); } else { $viewer->assign('IsInventory', false); } } $viewer->assign("runningCounter", $runningCounter); $viewer->assign("errorCounter", $errorCounter); $viewer->assign("workflowID", $workflowID); $viewer->assign("maxConnections", MAX_CONNECTIONS); $viewer->assign("workflowData", $this->workflowData); $viewer->assign("is_admin", $current_user->is_admin == "on"); $sql = "SELECT * FROM vtiger_tab WHERE presence = 0 AND isentitytype = 1 ORDER BY name"; $result = $adb->query($sql); $module = array(); while($row = $adb->fetch_array($result)) { $module[$row["tabid"]] = getTranslatedString($row["tablabel"],$row["name"]); } asort($module); $viewer->assign("module", $module); } public function getWorkflowObjectHTML() { $adb = PearDatabase::getInstance(); $sql = "SELECT * FROM vtiger_wf_objects WHERE workflow_id = ".$this->workflowID; $result = $adb->query($sql); $html = ""; while($row = $adb->fetchByAssoc($result)) { $html .= "
".html_entity_decode($row["content"], ENT_QUOTES, "UTF-8")."
"; } $html .= ""; return $html; } public function getInputPointHtml($inputPoints) { $html = ""; $types = $this->settingsModel->getTypes($this->workflowData["module_name"]); foreach($inputPoints as $point => $type) { $html .= $types[$type]->getInputHTML($point); } //$html .= "\n\n"; //$html .= ""; return $html; } public function getOutputPointHtml($outputPoints) { $html = ""; $types = $this->getTypes(); foreach($outputPoints as $pointID => $type) { $html .= $types[$type]->getOutputHTML($pointID); } $html .= ""; $html .= "\n\n"; return $html; } public function getTypes() { if($this->settingsModel === false) { $this->settingsModel = Settings_Vtiger_Module_Model::getInstance($this->qualifiedModuleName); } return $this->settingsModel->getTypes($this->workflowData["module_name"]); } public function getPersonInputPointHtml($personInputPoints) { $html = ""; $types = $this->getTypes(); foreach($personInputPoints as $pointID => $type) { $html .= $types[$type]->getPersonInputHTML($pointID); } $html .= ""; $html .= "\n\n"; return $html; } public function getPersonOutputPointHtml($personOutputPoints) { $html = ""; foreach($personOutputPoints as $pointID) { $html .= ' endpoints["'.$pointID.'__person"] = jsPlumbInstance.addEndpoint("'.$pointID.'", { anchor:bottomAnchor, maxConnections:'.MAX_CONNECTIONS.' }, jQuery.extend(getInput("modules/Workflow2/icons/peopleOutput.png", "person", true, false, true), {parameters:{ out:"'.$pointID.'__person" }})); '; } $html .= ""; $html .= "\n\n"; return $html; } public function getConnectionHtml($connections) { $html = ""; foreach($connections as $conn) { $html .=' if(endpoints["'.$conn[0].'"] != undefined && endpoints["'.$conn[1].'"] != undefined) { connectEndpoints("'.$conn[0].'", "'.$conn[1].'"); } '; } return $html; } public function getWorkflowBlockHTML() { $types = $this->settingsModel->getTypes($this->workflowData["module_name"]); $persons = $this->settingsModel->getWorkflowObjects($this->workflowID); $elements = $this->settingsModel->getWorkflowBlocks($this->workflowID); $connections = $this->settingsModel->getWorkflowConnections($this->workflowID); $html = ""; $inputPoints = array(); $maxOutputPoints = 3; $outputPoints = array(); $personInputPoints = array(); $personOutputPoints = array(); $maxLeft = 0; $maxTop = 0; foreach($elements as $element) { if(empty($types[$element["type"]])) { //echo 'Error in init of '.$element["type"].' block'; //continue; $types[$element["type"]] = $this->settingsModel->getDummyTask($element["type"]); } $type = $types[$element["type"]]->getData(); if($element["y"] < 0) { $element["y"] = 0; } if($element['x'] > $maxLeft) { $maxLeft = $element['x']; } if($element['y'] > $maxTop) { $maxTop = $element['y']; } $html .= '
'.$type["text"].''.(!empty($element["text"])?'
'.$element["text"].'':'').'
'.($element["type"]!="start"?'':'').'
 
'; if($type["input"] !== false) { $inputPoints[$element["id"]] = $element["type"]; } if(count($type["output"]) > $maxOutputPoints) $maxOutputPoints = $type["output"]; if(is_array($type["output"])) { $outputPoints[$element["id"]] = $element["type"]; } if(is_array($type["persons"])) { $personInputPoints[$element["id"]] = $element["type"]; } } foreach($persons as $person) { $personOutputPoints[] = $person["id"].""; $html .= '
'.(empty($person["name"])?"Not connected":$person["name"]).'
'; } $tmpArray = array(); for($a = 1; $a <= $maxOutputPoints; $a++) { $steps = 1 / ($a + 1); $tmp = array(); for($i = 1; $i <= $a; $i++) { $tmp[] = array(round($i * $steps, 2), 0, 0, -1, 0, -2); } $array[$a] = $tmp; } $html .= " "; $html .= ""; return $html; } public function process(Vtiger_Request $request) { $viewer = $this->getViewer($request); $viewer->view('VT7/Config.tpl', $this->qualifiedModuleName); } public function preProcessDisplay (Vtiger_Request $request) { $this->initView($request); $viewer = $this->getViewer($request); $viewer->assign('MODE', 'Config'); parent::preProcessDisplay($request); //$viewer->view('ConfigMenuStart.tpl', $this->qualifiedModuleName); } /** * Function to get the list of Script models to be included * @param Vtiger_Request $request * @return - List of Vtiger_JsScript_Model instances */ function getHeaderScripts(Vtiger_Request $request) { $headerScriptInstances = parent::getHeaderScripts($request); $moduleName = $request->getModule(); $moduleModel = Vtiger_Module_Model::getInstance("Workflow2"); $jsFileNames = array( "~/modules/Settings/$moduleName/views/resources/Designer.js", "modules.Settings.$moduleName.views.resources.Workflow2", ); if('Settings_Workflow2_Statistic_View' != get_class($this) ) { $jsFileNames[] = "modules.Settings.$moduleName.views.resources.Config"; } $jsScriptInstances = $this->checkAndConvertJsScripts($jsFileNames); $headerScriptInstances = array_merge($headerScriptInstances, $jsScriptInstances); foreach($headerScriptInstances as $obj) { $src = $obj->get('src'); if(!empty($src) && strpos($src, $moduleName) !== false) { $obj->set('src', $src.'?v='.$moduleModel->version); } } return $headerScriptInstances; } function getHeaderCss(Vtiger_Request $request) { $headerScriptInstances = parent::getHeaderCss($request); $moduleName = $request->getModule(); $moduleModel = Vtiger_Module_Model::getInstance("Workflow2"); $cssFileNames = array( "~layouts/".Vtiger_Viewer::getLayoutName()."/modules/Settings/$moduleName/resources/Workflow2.css", "~/modules/$moduleName/views/resources/switcher.css", ); $cssScriptInstances = $this->checkAndConvertCssStyles($cssFileNames); $headerStyleInstances = array_merge($headerScriptInstances, $cssScriptInstances); foreach($headerStyleInstances as $obj) { $src = $obj->get('href'); if(!empty($src) && strpos($src, $moduleName) !== false) { $obj->set('href', $src.'?v='.$moduleModel->version); } } return $headerStyleInstances; } }