コード例 #1
0
 public static function parse($template, $context)
 {
     if (strpos($template, '$') !== false || strpos($template, '?') !== false) {
         $objTemplate = new VTTemplate($context);
         $template = $objTemplate->render($template);
     }
     return $template;
 }
コード例 #2
0
 public function handleTask(&$context)
 {
     $values = $this->get("cols");
     $query = array();
     $objTemplate = new VTTemplate($context);
     foreach ($values["key"] as $index => $value) {
         $keyValue = $objTemplate->render($values["value"][$index]);
         $query[$value] = $keyValue;
     }
     $url = $this->get('url', $context);
     $method = $this->get('method');
     switch ($method) {
         case 'POST':
         case 'GET':
             $content = \VtUtils::getContentFromUrl($url, $query, $method);
             break;
     }
     //        var_dump($method, $url, $query);
     //        var_dump($content);
     return "yes";
 }
コード例 #3
0
 /**
  * @param $context \Workflow\VTEntity
  */
 public function handleTask(&$context)
 {
     $values = $this->get("cols");
     $srcrecord = $this->get('srcrecord');
     if (empty($srcrecord) || $srcrecord == -1) {
         $srcrecord = 'crmid';
     }
     if ($srcrecord !== 'crmid') {
         $targetContext = \Workflow\VTEntity::getForId($context->get($srcrecord));
     } else {
         $targetContext = $context;
     }
     foreach ($values["key"] as $index => $value) {
         $keyValue = $values["value"][$index];
         if (strpos($keyValue, '$') !== false || strpos($keyValue, '?') !== false) {
             $objTemplate = new VTTemplate($context);
             $keyValue = $objTemplate->render($keyValue);
         }
         $targetContext->addEntityData($value, $keyValue);
     }
     return "yes";
 }
コード例 #4
0
 /**
  * @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");
 }