function wf_haschanged($field, $crmid)
 {
     if (empty($crmid)) {
         return false;
     }
     $objRecord = \Workflow\VTEntity::getForId($crmid);
     return \Workflow\EntityDelta::hasChanged($objRecord->getModuleName(), $crmid, $field);
 }
Esempio n. 2
0
 public static function updateDynamicDate($context)
 {
     ${"GLOBALS"}["cxjptdslky"] = "adb";
     ${"GLOBALS"}["ffwkvdnarsns"] = "sql";
     ${${"GLOBALS"}["cxjptdslky"]} = \PearDatabase::getInstance();
     ${${"GLOBALS"}["ffwkvdnarsns"]} = "SELECT nextStepField, block_id, id FROM vtiger_wf_queue WHERE crmid = ? AND checkMode = 'dynamic'";
     $aijrbqs = "row";
     ${${"GLOBALS"}["dnpzgnxsrrdc"]} = \Workflow\VtUtils::pquery(${${"GLOBALS"}["fjvutiy"]}, array($context->getId()));
     ${"GLOBALS"}["hkrgfrun"] = "result";
     if ($adb->num_rows(${${"GLOBALS"}["dnpzgnxsrrdc"]}) == 0) {
         return false;
     }
     while (${$aijrbqs} = $adb->fetchByAssoc(${${"GLOBALS"}["hkrgfrun"]})) {
         if (\Workflow\EntityDelta::hasChanged($context->getModuleName(), $context->getId(), ${${"GLOBALS"}["isqdglbip"]}["nextstepfield"])) {
             $pgoetzgxky = "objTask";
             $bpggpjbm = "newDate";
             $ujxsupnbec = "row";
             ${$bpggpjbm} = \Workflow\EntityDelta::getCurrentValue($context->getModuleName(), $context->getId(), ${$ujxsupnbec}["nextstepfield"]);
             ${$pgoetzgxky} = \Workflow\Manager::getTaskHandler("delay", ${${"GLOBALS"}["isqdglbip"]}["block_id"]);
             ${${"GLOBALS"}["wtgbcaer"]} = $objTask->calculateContinueTS(strtotime(${${"GLOBALS"}["kjqnmsg"]}));
             ${${"GLOBALS"}["fjvutiy"]} = "UPDATE vtiger_wf_queue SET nextStepTime = ? WHERE id = ?";
             \Workflow\VtUtils::pquery(${${"GLOBALS"}["fjvutiy"]}, array(date("Y-m-d H:i:s", ${${"GLOBALS"}["wtgbcaer"]}), ${${"GLOBALS"}["isqdglbip"]}["id"]));
         }
     }
     return true;
 }
 public function checkValue($context, $key, $fieldvalue, $config, $checkConfig)
 {
     // old check functions
     $checkvalue = $config['value'];
     switch ($key) {
         case "equal":
             // Tested by swa 2016-01-27
             if ($fieldvalue == $checkvalue) {
                 return true;
             }
             return false;
             break;
         case "contains":
             // Tested by swa 2016-01-27
             if (strpos($fieldvalue, $checkvalue) !== false) {
                 return true;
             }
             return false;
             break;
         case "starts_with":
             // Tested by swa 2016-01-27
             if (strlen($fieldvalue) < strlen($checkvalue)) {
                 return false;
             }
             return substr($fieldvalue, 0, strlen($checkvalue)) == $checkvalue;
             break;
         case "ends_with":
             // Tested by swa 2016-01-27
             if (strlen($fieldvalue) < strlen($checkvalue)) {
                 return false;
             }
             return substr($fieldvalue, strlen($fieldvalue) - strlen($checkvalue)) == $checkvalue;
             break;
         case "has_changed":
             // Tested by swa 2016-01-27
             $hasChanged = \Workflow\EntityDelta::hasChanged($context->getModuleName(), $context->getId(), $checkConfig["field"]);
             $checkvalue = trim($checkvalue);
             if (empty($checkvalue)) {
                 return $hasChanged;
             } else {
                 return $hasChanged && $checkvalue == $fieldvalue;
             }
             break;
         case "after":
         case "bigger":
             // Tested by swa 2016-01-27
             if ($fieldvalue > $checkvalue) {
                 return true;
             }
             return false;
             break;
         case "before":
         case "lower":
             // Tested by swa 2016-01-27
             if ($fieldvalue < $checkvalue) {
                 return true;
             }
             return false;
             break;
         case "is_empty":
             // Tested by swa 2016-01-27
             $fieldvalue = trim($fieldvalue, "0.");
             if (empty($fieldvalue)) {
                 return true;
             }
             return false;
             break;
         case "date_empty":
             // Tested by swa 2016-01-27
             $fieldvalue = trim($fieldvalue, ".");
             if (empty($fieldvalue) || $fieldvalue == "0000-00-00") {
                 return true;
             }
             return false;
             break;
         case "is_checked":
             // Tested by swa 2016-01-27
             if ($fieldvalue == "1") {
                 return true;
             }
             return false;
             break;
         case "is_numeric":
             // Tested by swa 2016-01-27
             return is_numeric($fieldvalue);
             break;
         case "today":
             // Tested by swa 2016-01-27
             return date('Y-m-d', time()) == date('Y-m-d', strtotime($fieldvalue));
             break;
         case "yesterday":
             // Tested by swa 2016-01-27
             return date('Y-m-d', time() - 86400) == date('Y-m-d', strtotime($fieldvalue));
             break;
         case "tomorrow":
             // Tested by swa 2016-01-27
             return date('Y-m-d', time() + 86400) == date('Y-m-d', strtotime($fieldvalue));
             break;
     }
     $firstDay = false;
     // date calculations
     switch ($key) {
         case 'between':
             // Tested by swa 2016-01-27
             $firstDay = date("Y-m-d", strtotime($config['from']));
             $lastDay = date("Y-m-d", strtotime($config['to']));
             break;
         case 'current':
             // Tested by swa 2016-01-27
             switch ($config['type']) {
                 case 'day':
                     //$lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));
                     $lastDay = $firstDay = date('Y-m-d');
                     break;
                 case 'week':
                     $firstDay = date("Y-m-d", strtotime('last Sunday'));
                     $lastDay = date("Y-m-d", strtotime('this Saturday'));
                     break;
                 case 'month':
                     $firstDay = date("Y-m-d", strtotime('first day of this month'));
                     $lastDay = date("Y-m-d", strtotime('last day of this month'));
                     break;
                 case 'quarter':
                     $dates = $this->get_dates_of_quarter('current', null, 'Y-m-d');
                     $firstDay = $dates['start'];
                     $lastDay = $dates['end'];
                     break;
                 case 'year':
                     $firstDay = date("Y") . '-01-01';
                     $lastDay = date("Y") . '-12-31';
                     break;
             }
             break;
         case 'within_past':
             // Tested by swa 2016-01-27
             switch ($config['type']) {
                 case 'day':
                     //$lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));
                     $firstDay = date('Y-m-d', strtotime('-' . $config['value'] . ' day'));
                     $lastDay = date("Y-m-d", time() - 86400);
                     break;
                 case 'week':
                     $firstDay = date("Y-m-d", strtotime('-' . $config['value'] . ' week Saturday'));
                     $lastDay = date("Y-m-d", strtotime('last Sunday'));
                     break;
                 case 'month':
                     $firstDay = date("Y-m-d", strtotime('first day of -' . $config['value'] . ' month'));
                     $lastDay = date("Y-m-d", strtotime('last day of last month'));
                     break;
                 case 'quarter':
                     $dateObj = new \DateTime();
                     $currentQuarter = ceil($dateObj->format('n') / 3);
                     $years = floor($config['value'] / 4);
                     $year = date('Y') - $years;
                     $quarter = $currentQuarter - $config['value'] % 4;
                     if ($quarter < 1) {
                         $year -= 1;
                         $quarter = 4 - abs($quarter);
                     }
                     $start = $this->get_dates_of_quarter(intval($quarter), intval($year), 'Y-m-d');
                     $end = $this->get_dates_of_quarter('previous', null, 'Y-m-d');
                     $firstDay = $start['start'];
                     $lastDay = $end['end'];
                     break;
                 case 'year':
                     $firstDay = date("Y") - $config['value'] . '-01-01';
                     $lastDay = date("Y") - 1 . '-12-31';
                     break;
             }
             break;
         case 'within_next':
             // Tested by swa 2016-01-27
             switch ($config['type']) {
                 case 'day':
                     //$lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));
                     $firstDay = date("Y-m-d", time() + 86400);
                     $lastDay = date('Y-m-d', strtotime('+' . $config['value'] . ' day'));
                     break;
                 case 'week':
                     $firstDay = date("Y-m-d", strtotime('this Sunday'));
                     $lastDay = date("Y-m-d", strtotime('+' . $config['value'] . ' week Saturday'));
                     break;
                 case 'month':
                     $firstDay = date("Y-m-d", strtotime('first day of next month'));
                     $lastDay = date("Y-m-d", strtotime('last day of +' . $config['value'] . ' month'));
                     break;
                 case 'quarter':
                     $dateObj = new \DateTime();
                     $currentQuarter = ceil($dateObj->format('n') / 3);
                     $currentQuarter += $config['value'];
                     if ($currentQuarter % 4 > 0) {
                         $year = date('Y') + intval($currentQuarter / 4);
                         $quarter = $currentQuarter % 4;
                     } else {
                         $year = date('Y') + intval($currentQuarter / 4) - 1;
                         $quarter = 4;
                     }
                     $start = $this->get_dates_of_quarter('next', null, 'Y-m-d');
                     $end = $this->get_dates_of_quarter($quarter, $year, 'Y-m-d');
                     $firstDay = $start['start'];
                     $lastDay = $end['end'];
                     break;
                 case 'year':
                     $firstDay = date("Y") + 1 . '-01-01';
                     $lastDay = date("Y") + $config['value'] . '-12-31';
                     break;
             }
             break;
     }
     if ($firstDay !== false) {
         return $fieldvalue >= $firstDay && $fieldvalue <= $lastDay;
     }
     return false;
 }
Esempio n. 4
0
 private function _checkField($check)
 {
     ${"GLOBALS"}["jddomxqeud"] = "fieldvalue";
     $itxrdfjhq = "matches";
     $toedvs = "check";
     ${"GLOBALS"}["bjihnoa"] = "fieldvalue";
     ${"GLOBALS"}["urlegth"] = "fieldvalue";
     ${"GLOBALS"}["lcrgpeyzbq"] = "hasChanged";
     ${"GLOBALS"}["erzkbgspclx"] = "checkvalue";
     preg_match("/(\\w+)|\\(((\\w+) ?\\: \\(([_\\w]+)\\)\\)? (\\w+)\\)?)/", ${${"GLOBALS"}["ppgydjvv"]}["field"], ${$itxrdfjhq});
     $gwpxykdvoch = "fieldvalue";
     if (count(${${"GLOBALS"}["cneagqkui"]}) == 2) {
         $vinfcmby = "targetContext";
         ${$vinfcmby} = $this->_context;
     } else {
         if (${${"GLOBALS"}["cneagqkui"]}[3] != "current_user") {
             ${"GLOBALS"}["kzitgtdwg"] = "targetContext";
             ${${"GLOBALS"}["kzitgtdwg"]} = $this->_context->getReference(${${"GLOBALS"}["cneagqkui"]}[4], ${${"GLOBALS"}["cneagqkui"]}[3]);
         } else {
             ${"GLOBALS"}["gxuqhowmz"] = "targetContext";
             $ummepou = "matches";
             global $current_user;
             ${${"GLOBALS"}["gxuqhowmz"]} = \Workflow\VTEntity::getForId($current_user->id, ${$ummepou}[4]);
         }
         ${"GLOBALS"}["jxxhgoaynk"] = "check";
         if (${${"GLOBALS"}["ipfzawk"]} === false) {
             ${"GLOBALS"}["iritosbyxswi"] = "matches";
             throw new \Exception("couldn't load Reference from Record " . $this->_context->getId() . " [" . $this->_context->getModuleName() . "] (" . ${${"GLOBALS"}["iritosbyxswi"]}[3] . "->" . ${${"GLOBALS"}["cneagqkui"]}[4] . ")");
         }
         ${${"GLOBALS"}["jxxhgoaynk"]}["field"] = ${${"GLOBALS"}["cneagqkui"]}[5];
     }
     ${"GLOBALS"}["cjjptrxeibip"] = "check";
     ${"GLOBALS"}["quwlstl"] = "fieldvalue";
     $xeeymju = "checkvalue";
     ${"GLOBALS"}["vbeftl"] = "fieldvalue";
     if (${${"GLOBALS"}["ppgydjvv"]}["field"] == "smownerid") {
         ${${"GLOBALS"}["ppgydjvv"]}["field"] = "assigned_user_id";
     }
     $yduvefukc = "checkvalue";
     $obntgky = "checkvalue";
     ${${"GLOBALS"}["yutgnzzt"]} = $targetContext->get(${${"GLOBALS"}["ppgydjvv"]}["field"]);
     ${"GLOBALS"}["qlgzdb"] = "fieldvalue";
     $gfodhbqtf = "checkvalue";
     $acrvuhsv = "fieldvalue";
     if (${${"GLOBALS"}["ppgydjvv"]}["mode"] == "value" || empty(${${"GLOBALS"}["ppgydjvv"]}["mode"])) {
         ${${"GLOBALS"}["erpksbpytb"]} = ${${"GLOBALS"}["ppgydjvv"]}["rawvalue"];
         ${"GLOBALS"}["cjzgraey"] = "checkvalue";
         if (strpos(${${"GLOBALS"}["erpksbpytb"]}, "\$") !== false || strpos(${${"GLOBALS"}["cjzgraey"]}, "?") !== false) {
             $ibretppzu = "checkvalue";
             ${"GLOBALS"}["tqehnnjsov"] = "objTemplate";
             ${${"GLOBALS"}["tqehnnjsov"]} = new VTTemplate($this->_context);
             ${$ibretppzu} = $objTemplate->render(${${"GLOBALS"}["erpksbpytb"]});
         }
     } elseif (${${"GLOBALS"}["ppgydjvv"]}["mode"] == "function") {
         $hjummqmcqhx = "check";
         ${"GLOBALS"}["mnriwiq"] = "parser";
         ${${"GLOBALS"}["mnriwiq"]} = new ExpressionParser(${$hjummqmcqhx}["rawvalue"], $this->_context, false);
         try {
             $parser->run();
         } catch (ExpressionException $exp) {
             \Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", "");
         }
         ${${"GLOBALS"}["erpksbpytb"]} = $parser->getReturn();
     }
     ${"GLOBALS"}["frcdhbenmj"] = "fieldvalue";
     $this->log("Check field: " . ${${"GLOBALS"}["ppgydjvv"]}["field"] . " (" . ${${"GLOBALS"}["urlegth"]} . ")" . (${${"GLOBALS"}["ppgydjvv"]}["not"] == "1" ? " not" : "") . " " . ${${"GLOBALS"}["ppgydjvv"]}["operation"] . " - " . ${${"GLOBALS"}["erpksbpytb"]});
     $furkdcgmptl = "fieldvalue";
     ${"GLOBALS"}["uxmtblslyhk"] = "checkvalue";
     switch (${${"GLOBALS"}["cjjptrxeibip"]}["operation"]) {
         case "equal":
             if (${${"GLOBALS"}["jddomxqeud"]} == ${${"GLOBALS"}["erpksbpytb"]}) {
                 return true;
             }
             break;
         case "contains":
             if (strpos(${${"GLOBALS"}["qlgzdb"]}, ${${"GLOBALS"}["erpksbpytb"]}) !== false) {
                 return true;
             }
             break;
         case "starts_with":
             if (strlen(${${"GLOBALS"}["yutgnzzt"]}) < strlen(${$xeeymju})) {
                 return false;
             }
             return substr(${$furkdcgmptl}, 0, strlen(${${"GLOBALS"}["erpksbpytb"]})) == ${${"GLOBALS"}["erpksbpytb"]};
             break;
         case "ends_with":
             if (strlen(${${"GLOBALS"}["yutgnzzt"]}) < strlen(${${"GLOBALS"}["uxmtblslyhk"]})) {
                 return false;
             }
             return substr(${${"GLOBALS"}["yutgnzzt"]}, strlen(${${"GLOBALS"}["bjihnoa"]}) - strlen(${$gfodhbqtf})) == ${$yduvefukc};
             break;
         case "has_changed":
             ${${"GLOBALS"}["lcrgpeyzbq"]} = \Workflow\EntityDelta::hasChanged($this->_context->getModuleName(), $this->_context->getId(), ${$toedvs}["field"]);
             ${${"GLOBALS"}["erpksbpytb"]} = trim(${$obntgky});
             if (empty(${${"GLOBALS"}["erzkbgspclx"]})) {
                 ${"GLOBALS"}["lxjmge"] = "hasChanged";
                 return ${${"GLOBALS"}["lxjmge"]};
             } else {
                 return ${${"GLOBALS"}["xdfhplmadyw"]} && ${${"GLOBALS"}["erpksbpytb"]} == ${${"GLOBALS"}["yutgnzzt"]};
             }
             break;
         case "bigger":
             if (${${"GLOBALS"}["yutgnzzt"]} > ${${"GLOBALS"}["erpksbpytb"]}) {
                 return true;
             }
             break;
         case "lower":
             if (${${"GLOBALS"}["quwlstl"]} < ${${"GLOBALS"}["erpksbpytb"]}) {
                 return true;
             }
             break;
         case "is_empty":
             ${${"GLOBALS"}["yutgnzzt"]} = trim(${$acrvuhsv}, "0.");
             if (empty(${${"GLOBALS"}["vbeftl"]})) {
                 return true;
             }
             break;
         case "date_empty":
             ${${"GLOBALS"}["yutgnzzt"]} = trim(${${"GLOBALS"}["yutgnzzt"]}, ".");
             if (empty(${$gwpxykdvoch}) || ${${"GLOBALS"}["yutgnzzt"]} == "0000-00-00") {
                 return true;
             }
             break;
         case "is_checked":
             if (${${"GLOBALS"}["yutgnzzt"]} == "1") {
                 return true;
             }
             break;
         case "is_numeric":
             return is_numeric(${${"GLOBALS"}["frcdhbenmj"]});
             break;
     }
     return false;
 }