public function handleTask(&$context) { /* Insert here source code to execute the task */ global $adb; $documentId = $context->get("id"); if (strpos($documentId, 'x') !== false) { $TMP = explode("x", $documentId); $documentId = $TMP[1]; } $context->save(); $sql = "SELECT attachmentsid FROM vtiger_seattachmentsrel WHERE crmid = " . $documentId; $result = $adb->query($sql, true); $fileid = $adb->query_result($result, 0, "attachmentsid"); $pathQuery = $adb->pquery("select path, name from vtiger_attachments where attachmentsid = ?", array($fileid), true); $filepath = "../../../" . $adb->query_result($pathQuery, 0, 'path'); $filename = $adb->query_result($pathQuery, 0, 'name'); $saved_filename = $fileid . "_" . utf8_encode(html_entity_decode(html_entity_decode($filename))); $path = realpath(dirname(__FILE__) . "/" . $filepath . $saved_filename); $create_dir = $this->get("create_dir"); #var_dump($path);exit(); // $sql = "SELECT * FROM // vtiger_attachments // INNER JOIN vtiger_seattachmentsrel ON(vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid) // INNER JOIN vtiger_notes ON(vtiger_notes.notesid = vtiger_seattachmentsrel.crmid) // WHERE vtiger_attachments.attachmentsid = ".intval($attachmentid); // $result = $adb->query($sql); try { $this->initDropbox(); #$tmp = tempnam('/tmp', 'dropbox'); #$data = 'This file was uploaded using the Dropbox API!'; #file_put_contents($tmp, $data); $directory = $this->get("filepath"); self::$dropbox->setRoot("dropbox"); if (!empty($create_dir)) { $parser = new VTWfExpressionParser($create_dir, $context, false); # Last Parameter = DEBUG try { $parser->run(); } catch (\Workflow\ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $newDir = $parser->getReturn(); $found = self::$dropbox->search($newDir, $directory); if (empty($found["body"]) || count($found["body"]) == 0) { self::$dropbox->create($directory); } $directory = $directory . "/" . $newDir; } $put = self::$dropbox->putFile($path, $newDir . "/" . $filename, $directory); } catch (Exception $exp) { Workflow2::error_handler(E_NONBREAK_ERROR, $exp->getMessage(), $exp->getFile(), $exp->getLine()); } return "yes"; }
public function handleTask(&$context) { $setterMap = $this->get("setter"); $globalMap = $this->get("global"); $products = $this->get("product"); $shippingCost = 0; $newModule = $this->get("new_module"); if (empty($newModule)) { $this->addStat("NO Configuration set"); return "yes"; } /** * @var $newObj \Workflow\VTInventoryEntity */ $newObj = \Workflow\VTEntity::create($newModule); try { foreach ($setterMap as $setter) { if (!empty($setter["field"]) && $setter["field"] == "currency_id") { $setter["value"] = vtws_getWebserviceEntityId("Currency", $setter["value"]); } if ($setter["mode"] == "function") { $parser = new VTWfExpressionParser($setter["value"], $context, false); # Last Parameter = DEBUG try { $parser->run(); } catch (\Workflow\ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $newValue = $parser->getReturn(); } else { $setter["value"] = \Workflow\VTTemplate::parse($setter["value"], $context); $newValue = $setter["value"]; } $this->addStat("`" . $setter["field"] . "` = '" . $newValue . "'"); if ($setter["field"] == "hdnS_H_Amount") { $shippingCost = $newValue; } # var_dump($setter["field"], $newValue); $newObj->set($setter["field"], $newValue); } } catch (Exception $e) { var_dump($e); // ONLY ERROR } try { $newObj->save(); } catch (WebServiceException $exp) { // Somethink is wrong with the values. missing mandatory fields? } $context->setEnvironment("new_record_id", $newObj->getWsId(), $this); if ($this->get("redirectAfter") == "1") { $this->getWorkflow()->setSuccessRedirection($newObj->getDetailUrl()); } $groupTaxes = array(); $shipTaxes = array(); foreach ($globalMap as $globalKey => $globalValue) { $globalValue = \Workflow\VTTemplate::parse($globalValue, $context); if (strpos($globalKey, "_group_percentage") !== false) { $groupTaxes[$globalKey] = $globalValue; } if (strpos($globalKey, "_sh_percent") !== false) { $shipTaxes[$globalKey] = $globalValue; } $this->addStat("`" . $globalKey . "` = '" . $globalValue . "'"); } $newObj->setGroupTaxes($groupTaxes); $newObj->setShipTaxes($shipTaxes); $newObj->setShippingCost($shippingCost); $newObj->save(); $newObj = $this->_productchooser->addProducts2Entity($this->get('product'), $context, $newObj); $newObj->save(); if ($this->get("exec_workflow") !== "" && $this->get("exec_workflow") != -1) { $newContext = \Workflow\VTEntity::getForId($newObj->getId(), $newObj->getModuleName()); $objWorkflow = new \Workflow\Main($this->get("exec_workflow"), false, $context->getUser()); $newContext->loadEnvironment($context->getEnvironment()); $objWorkflow->setContext($newContext); $objWorkflow->isSubWorkflow(true); $objWorkflow->start(); } Workflow2::$enableError = true; return 'yes'; }
/** * @param $context \Workflow\VTEntity */ public function handleTask(&$context) { global $current_user, $adb; if ($this->isContinued()) { $sql = "SELECT id, result, result_user_id FROM vtiger_wf_confirmation WHERE execID = '" . $this->getExecId() . "' AND result != '' AND visible = 1"; $result = $adb->query($sql); if ($adb->num_rows($result) == 0) { $timeout = $context->getEnvironment('_permissionTimeout'); $timeoutValue = $context->getEnvironment('_permissionTimeoutValue'); if ($timeout == true) { if (time() > $timeoutValue) { $this->addStat('Timeout action: ' . $this->get('timeout_output')); return $this->get('timeout_output'); } } return array("delay" => time() + 60 * 10, "checkmode" => "static"); } $data = $adb->fetchByAssoc($result); $sql = "SELECT user_name FROM vtiger_users WHERE id = " . $data["result_user_id"]; $resultUser = $adb->query($sql); $resultUser = $adb->fetchByAssoc($resultUser); $this->addStat("Permission: " . $data["result"] . " by " . $resultUser["user_name"]); $sql = "UPDATE vtiger_wf_confirmation SET visible = 0 WHERE id = " . $data["id"]; $adb->query($sql); return $data["result"]; } $this->_compatible(); $connected = $this->getConnectedObjects("assigned_to"); $targets = array(); if (!empty($connected)) { foreach ($connected as $user) { if (empty($user)) { continue; } $targets['user'][] = intval($user->getId()); } } $TMPtargets = $this->get('targets'); if (is_array($TMPtargets)) { foreach ($TMPtargets as $value) { $parts = explode('##', $value); if ($parts[0] == 'USER' && !in_array(intval($parts[1]), $targets['user'])) { $targets['user'][] = intval($parts[1]); } if ($parts[0] == 'GROUP') { $focusGrpUsers = new GetGroupUsers(); $focusGrpUsers->getAllUsersInGroup($parts[1]); $groupUser = $focusGrpUsers->group_users; if (is_array($groupUser)) { foreach ($groupUser as $userId) { if (!in_array($userId, $targets['user'])) { $targets['user'][] = $userId; } } } } if ($parts[0] == 'ROLE') { $focusGrpUsers = new GetGroupUsers(); $focusGrpUsers->getAllUsersInGroup($parts[0]); $groupUser = array_keys(getRoleUsers($parts[1])); if (is_array($groupUser)) { foreach ($groupUser as $userId) { if (!in_array($userId, $targets['user'])) { $targets['user'][] = $userId; } } } } } } $backgroundcolor = $this->get("backgroundcolor"); $bgmode = $this->get("bgmode"); if (!empty($bgmode) && $bgmode != -1) { if ($bgmode == "function") { $parser = new VTWfExpressionParser($backgroundcolorFKT, $context, false); # Last Parameter = DEBUG try { $parser->run(); } catch (ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $backgroundcolor = $parser->getReturn(); } else { if (strpos($backgroundcolor, '$') !== false || strpos($backgroundcolor, '?') !== false) { $objTemplate = new VTTemplate($context); $backgroundcolor = $objTemplate->render($backgroundcolor); } } } else { $backgroundcolor = "#ffffff"; } if (empty($backgroundcolor)) { $backgroundcolor = "#ffffff"; } $infomessage = $this->get("infomessage"); $infomessageFKT = $this->get("infomessageFKT"); $infomode = $this->get("infomode"); if (!empty($infomode) && $infomode != -1) { if ($infomode == "function") { $parser = new VTWfExpressionParser($infomessageFKT, $context, false); # Last Parameter = DEBUG try { $parser->run(); } catch (ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $infomessage = $parser->getReturn(); } else { if (strpos($infomessage, '$') !== false || strpos($infomessage, '?') !== false) { $objTemplate = new VTTemplate($context); $infomessage = $objTemplate->render($infomessage); } } } else { $infomessage = ""; } if (empty($infomessage)) { $infomessage = ""; } $rundirect = $this->get("rundirect"); $sql = "INSERT INTO vtiger_wf_confirmation SET crmid = " . $context->getId() . ", infomessage = ?, backgroundcolor = ?, blockID = '" . $this->getBlockId() . "', execID = '" . $this->getExecId() . "', visible = 1, result = '', module = '" . $context->getModuleName() . "', workflow_id = " . $this->getWorkflowId() . ", rundirect = " . ($rundirect == "1" ? 1 : 0) . ", from_user_id = " . $current_user->id; $adb->pquery($sql, array($infomessage, $backgroundcolor)); $confID = $adb->getLastInsertID(); foreach ($targets['user'] as $user) { $sql = "INSERT INTO vtiger_wf_confirmation_user SET confirmation_id = '" . $confID . "', user_id = " . $user; $adb->query($sql); $this->addStat("create Permission entry (Block " . $this->getBlockId() . ") for User " . $user); } // if we need an timeout than wait until $use_timeout = $this->get("use_timeout"); if ($use_timeout == '1') { $timeout_value = $this->get("timeout_value"); $timeout_value_mode = $this->get("timeout_value_mode"); $timestamp = time(); switch ($timeout_value_mode) { case "minutes": $timestamp += 60 * $timeout_value; break; case "hours": $timestamp += 60 * 60 * $timeout_value; break; case "days": $timestamp += 24 * 60 * 60 * $timeout_value; break; case "weeks": $timestamp += 7 * 24 * 60 * 60 * $timeout_value; break; } $context->setEnvironment('_permissionTimeout', true); $context->setEnvironment('_permissionTimeoutValue', $timestamp); } else { $context->setEnvironment('_permissionTimeout', false); } // check every 15 minutes return array("delay" => time() + 60 * 15, "checkmode" => "static"); }