Files
luos/workflow/engine/classes/PmDynaform.php

2635 lines
116 KiB
PHP
Raw Normal View History

2014-08-01 13:06:51 -04:00
<?php
use PhpMyAdmin\SqlParser\Parser;
2017-08-14 16:13:46 -04:00
use ProcessMaker\Core\System;
use ProcessMaker\BusinessModel\DynaForm\SuggestTrait;
2017-09-15 17:52:26 -04:00
use ProcessMaker\BusinessModel\Cases;
2017-11-29 11:51:24 -04:00
use ProcessMaker\BusinessModel\DynaForm\ValidatorFactory;
2019-05-15 20:20:24 -04:00
use ProcessMaker\Model\Dynaform as ModelDynaform;
2017-08-14 16:13:46 -04:00
2014-08-01 13:06:51 -04:00
/**
* Implementing pmDynaform library in the running case.
*
2014-08-01 13:06:51 -04:00
* @package engine.classes
2017-08-15 12:42:55 -04:00
*/
class PmDynaform
2014-08-01 13:06:51 -04:00
{
use SuggestTrait;
2014-08-01 13:06:51 -04:00
2019-03-13 09:09:42 -04:00
private $cache = [];
private $context = [];
private $databaseProviders = null;
private $dataSources = null;
private $lastQueryError = null;
private $propertiesToExclude = [];
private $sysSys = null;
private $fieldsAppData;
2015-02-27 18:10:59 -04:00
public $credentials = null;
2019-03-13 09:09:42 -04:00
public $displayMode = null;
public $fields = null;
public $isRTL = false;
2015-08-25 17:01:15 -04:00
public $lang = SYS_LANG;
2019-09-18 15:27:26 -04:00
public $translations = null;
2015-08-18 15:42:31 -04:00
public $onPropertyRead = "onPropertyReadFormInstance";
public $onAfterPropertyRead = "onAfterPropertyReadFormInstance";
public $pathRTLCss = '';
2019-03-13 09:09:42 -04:00
public $record = null;
public $records = null;
public $serverConf = null;
2019-03-13 09:09:42 -04:00
public static $instance = null;
public static $prefixs = ["@@", "@#", "@%", "@?", "@$", "@="];
2014-08-01 13:06:51 -04:00
2019-03-13 09:09:42 -04:00
/**
* Constructor
*
* @param array $fields
* @see workflow/engine/classes/class.pmFunctions.php PMFDynaFormFields()
* @see workflow/engine/classes/class.pmFunctions.php PMFgetLabelOption()
* @see \ConsolidatedCases->processConsolidated()
* @see \WorkspaceTools->syncFormsWithInputDocumentInfo()
* @see workflow/engine/methods/cases/ajaxListener.php Ajax->dynaformViewFromHistory()
* @see workflow/engine/methods/cases/caseConsolidated.php
* @see workflow/engine/methods/cases/cases_SaveData.php
* @see workflow/engine/methods/cases/cases_Step.php
* @see workflow/engine/methods/cases/cases_StepToRevise.php
* @see workflow/engine/methods/cases/casesHistoryDynaformPage_Ajax.php
* @see workflow/engine/methods/cases/pmDynaform.php
* @see workflow/engine/methods/cases/summary.php
* @see workflow/engine/methods/services/ActionsByEmailDataForm.php
* @see workflow/engine/plugins/EnterpriseSearch/display_dynaform.php
* @see workflow/engine/plugins/EnterpriseSearch/dynaform_view1.php
* @see \ProcessMaker\BusinessModel\ActionsByEmail->viewFormBpmn()
* @see \ProcessMaker\BusinessModel\Cases->getCaseVariables()
* @see \ProcessMaker\BusinessModel\Consolidated->getDataGenerate()
* @see \ProcessMaker\BusinessModel\InputDocument->update()
* @see \ProcessMaker\BusinessModel\Light\Tracker->showObjects()
* @see \ProcessMaker\BusinessModel\Variable->delete()
* @see \ProcessMaker\BusinessModel\Variable->executeSqlControl()
* @see \ProcessMaker\BusinessModel\Variable->update()
* @see \ProcessMaker\Core\System\ActionsByEmailCoreClass->sendActionsByEmail()
* @see \ProcessMaker\Services\Api\Light->doGetDynaForm()
* @see \ProcessMaker\Services\Api\Light->doGetDynaformProcessed()
* @see \ProcessMaker\Services\Api\Light->doGetDynaForms()
* @see \ProcessMaker\Services\Api\Light->doGetDynaFormsId()
* @see \ProcessMaker\Services\Api\Project\DynaForm->doDeleteDynaFormLanguage()
* @see \ProcessMaker\Services\Api\Project\DynaForm->doGetDynaFormLanguage()
* @see \ProcessMaker\Services\Api\Project\DynaForm->doGetListDynaFormLanguage()
* @see \ProcessMaker\Services\Api\Project\DynaForm->doPostDynaFormLanguage()
*/
public function __construct($fields = [])
2015-02-27 18:10:59 -04:00
{
2017-10-10 12:33:25 -04:00
$this->sysSys = (!empty(config("system.workspace"))) ? config("system.workspace") : "Undefined";
2016-12-09 15:53:29 -04:00
$this->context = \Bootstrap::getDefaultContextLog();
$this->dataSources = array("database", "dataVariable");
$this->pathRTLCss = '/lib/pmdynaform/build/css/PMDynaform-rtl.css';
2017-12-04 13:25:35 +00:00
$this->serverConf = ServerConf::getSingleton();
$this->isRTL = ($this->serverConf->isRtl(SYS_LANG)) ? 'true' : 'false';
2015-03-12 09:59:19 -04:00
$this->fields = $fields;
$this->propertiesToExclude = array('dataVariable');
2015-03-23 22:22:10 -04:00
$this->getDynaform();
2015-10-09 15:56:49 -04:00
$this->getDynaforms();
2015-12-04 17:31:37 -04:00
$this->synchronizeSubDynaform();
2015-03-23 22:22:10 -04:00
$this->getCredentials();
2016-04-26 15:11:02 -04:00
if (is_array($this->fields) && !isset($this->fields["APP_UID"])) {
2015-03-12 09:59:19 -04:00
$this->fields["APP_UID"] = null;
2015-10-05 10:04:20 -04:00
}
$this->fieldsAppData = isset($this->fields["APP_DATA"]) ? $this->fields["APP_DATA"] : [];
2016-03-08 17:40:43 -04:00
//todo: compatibility checkbox
2016-03-09 17:43:06 -04:00
if ($this->record !== null && isset($this->record["DYN_CONTENT"]) && $this->record["DYN_CONTENT"] !== "") {
$json = G::json_decode($this->record["DYN_CONTENT"]);
$fields = $this->jsonsf2($json, "checkbox", "type");
foreach ($fields as $field) {
if (isset($field->dataType) && $field->dataType === "string") {
$field->type = "checkgroup";
$field->dataType = "array";
}
$this->jsonReplace($json, $field->id, "id", $field);
2016-03-08 17:40:43 -04:00
}
2016-03-09 17:43:06 -04:00
$this->record["DYN_CONTENT"] = G::json_encode($json);
2019-01-25 17:10:59 -04:00
//to do, this line should be removed. Related to PMC-196.
$this->record['DYN_CONTENT'] = G::fixStringCorrupted($this->record['DYN_CONTENT']);
2016-03-08 17:40:43 -04:00
}
2014-08-01 13:06:51 -04:00
}
2019-09-18 15:27:26 -04:00
/**
* Get the translation defined in the dynaform
*
* @return object
*/
public function getTranslations()
{
return $this->translations;
}
/**
* Set the translations defined in the dynaform
*
* @param string $dynUid
*
* @return void
*/
public function setTranslations($dynUid)
{
$dynaForm = ModelDynaform::getByDynUid($dynUid);
$this->translations = empty($dynaForm->DYN_LABEL) ? null : G::json_decode($dynaForm->DYN_LABEL);
}
/**
* Get the labels from a specific language defined in the dynaform, if does not exist will return null
*
* @param string $language
*
* @return object|null
*/
public function getLabelsPo($language)
{
$labelsPo = null;
if (!is_null($this->translations) && !empty($this->translations->{$language}->{'Labels'})) {
$labelsPo = $this->translations->{$language}->{'Labels'};
}
return $labelsPo;
}
2020-03-27 12:54:39 -04:00
/**
* Get the title of a Dynaform
*
* @param string $dynUid
* @return string
*/
public function getDynaformTitle($dynUid)
{
2020-03-27 12:54:39 -04:00
$dynaform = ModelDynaform::getByDynUid($dynUid);
return $dynaform->DYN_TITLE;
}
2019-05-15 20:20:24 -04:00
/**
* Get a dynaform.
2019-09-18 15:27:26 -04:00
*
2019-05-15 20:20:24 -04:00
* @return array|null
2019-09-18 15:27:26 -04:00
*
2019-05-15 20:20:24 -04:00
* @see workflow/engine/methods/cases/caseConsolidated.php
2019-09-18 15:27:26 -04:00
* @see ConsolidatedCases::processConsolidated()
* @see PmDynaform::__construct()
* @see \ProcessMaker\BusinessModel\Cases::getCaseVariables()
2019-05-15 20:20:24 -04:00
*/
2014-08-01 13:06:51 -04:00
public function getDynaform()
{
2015-03-26 15:03:24 -04:00
if (!isset($this->fields["CURRENT_DYNAFORM"])) {
return;
}
2014-08-01 13:06:51 -04:00
if ($this->record != null) {
return $this->record;
}
2019-05-15 20:20:24 -04:00
$dynaform = ModelDynaform::getByDynUid($this->fields["CURRENT_DYNAFORM"]);
if (empty($dynaform)) {
2019-09-18 15:27:26 -04:00
$this->translations = null;
2019-05-15 20:20:24 -04:00
return null;
}
2019-09-18 15:27:26 -04:00
$this->translations = empty($dynaform->DYN_LABEL) ? null : G::json_decode($dynaform->DYN_LABEL);
2019-05-15 20:20:24 -04:00
$this->record = (array) $dynaform;
2014-08-01 13:06:51 -04:00
return $this->record;
}
2015-02-27 18:10:59 -04:00
2019-05-15 20:20:24 -04:00
/**
* Get all dynaforms except this dynaform, related to process.
* @return array
* @see PmDynaform->__construct()
*/
2015-10-09 15:56:49 -04:00
public function getDynaforms()
{
if ($this->record === null) {
return;
}
if ($this->records != null) {
return $this->records;
}
2019-05-15 20:20:24 -04:00
$result = ModelDynaform::getByProUidExceptDynUid($this->record["PRO_UID"], $this->record["DYN_UID"]);
$result->transform(function($item) {
return (array) $item;
});
$this->records = $result->toArray();
2015-10-09 15:56:49 -04:00
return $this->records;
}
2015-02-27 18:10:59 -04:00
public function getCredentials()
2015-02-03 14:40:33 -04:00
{
$flagTrackerUser = false;
2015-03-26 15:03:24 -04:00
if (!isset($_SESSION['USER_LOGGED'])) {
2016-03-18 12:15:38 -04:00
if (!preg_match("/^.*\/" . SYS_SKIN . "\/tracker\/.*$/", $_SERVER["REQUEST_URI"]) &&
!preg_match("/^.*\/" . SYS_SKIN . "\/[a-z0-9A-Z]+\/[a-z0-9A-Z]+\.php$/", $_SERVER["REQUEST_URI"]) &&
!preg_match("/^.*\/" . SYS_SKIN . "\/services\/ActionsByEmailDataForm.*$/", $_SERVER["REQUEST_URI"])
2016-03-18 12:15:38 -04:00
) {
return;
}
$_SESSION["USER_LOGGED"] = "00000000000000000000000000000001";
$flagTrackerUser = true;
2015-03-26 15:03:24 -04:00
}
2015-02-27 18:10:59 -04:00
if ($this->credentials != null) {
2020-07-31 14:49:29 +00:00
// Destroy variable "USER_LOGGED" in session if is a not authenticated user
if ($flagTrackerUser) {
unset($_SESSION["USER_LOGGED"]);
}
2015-02-27 18:10:59 -04:00
return $this->credentials;
2015-02-03 14:40:33 -04:00
}
2016-09-19 10:14:46 -04:00
if (isset($_SESSION["PMDYNAFORM_CREDENTIALS"]) && isset($_SESSION["PMDYNAFORM_CREDENTIALS_EXPIRES"])) {
$time1 = strtotime(date('Y-m-d H:i:s'));
$time2 = strtotime($_SESSION["PMDYNAFORM_CREDENTIALS_EXPIRES"]);
if ($time1 < $time2) {
$this->credentials = $_SESSION["PMDYNAFORM_CREDENTIALS"];
2020-07-31 14:49:29 +00:00
// Destroy variable "USER_LOGGED" in session if is a not authenticated user
if ($flagTrackerUser) {
unset($_SESSION["USER_LOGGED"]);
}
2016-09-19 10:14:46 -04:00
return $this->credentials;
}
}
2015-02-27 18:10:59 -04:00
$a = $this->clientToken();
$this->credentials = array(
"accessToken" => $a["access_token"],
"expiresIn" => $a["expires_in"],
"tokenType" => $a["token_type"],
"scope" => $a["scope"],
"refreshToken" => $a["refresh_token"],
"clientId" => $a["client_id"],
"clientSecret" => $a["client_secret"]
);
2020-07-31 14:49:29 +00:00
// Destroy variable "USER_LOGGED" in session if is a not authenticated user
if ($flagTrackerUser) {
unset($_SESSION["USER_LOGGED"]);
}
2016-09-19 10:14:46 -04:00
$expires = date("Y-m-d H:i:s") . " +" . $this->credentials["expiresIn"] . " seconds";
$_SESSION["PMDYNAFORM_CREDENTIALS"] = $this->credentials;
$_SESSION["PMDYNAFORM_CREDENTIALS_EXPIRES"] = date("Y-m-d H:i:s", strtotime($expires));
2015-02-27 18:10:59 -04:00
return $this->credentials;
2015-02-03 14:40:33 -04:00
}
2016-12-09 15:53:29 -04:00
public function jsonr(&$json, $clearCache = true)
2015-02-03 14:40:33 -04:00
{
2016-12-09 15:53:29 -04:00
if ($clearCache === true) {
$this->cache = [];
}
2016-04-27 10:01:01 -04:00
if (empty($json)) {
2016-04-26 15:11:02 -04:00
return;
}
2017-02-17 16:51:27 -04:00
$dataGridEnvironment = [];
2015-04-17 13:51:47 -04:00
foreach ($json as $key => &$value) {
2015-02-27 18:10:59 -04:00
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
2016-12-09 15:53:29 -04:00
$this->jsonr($value, false);
2015-02-27 18:10:59 -04:00
}
if (!$sw1 && !$sw2) {
2015-08-03 16:37:25 -04:00
//read event
$fn = $this->onPropertyRead;
2016-02-19 15:00:34 -04:00
if (is_callable($fn) || function_exists($fn)) {
2015-08-03 16:37:25 -04:00
$fn($json, $key, $value);
}
2015-04-17 13:51:47 -04:00
//set properties from trigger
2017-03-06 11:00:37 -04:00
if (is_string($value) && in_array(substr($value, 0, 2), self::$prefixs)) {
2015-02-27 18:10:59 -04:00
$triggerValue = substr($value, 2);
2015-03-23 22:22:10 -04:00
if (isset($this->fields["APP_DATA"][$triggerValue])) {
if (!in_array($key, $this->propertiesToExclude)) {
2016-12-19 11:10:51 -04:00
$json->{$key} = $this->fields["APP_DATA"][$triggerValue];
}
} else {
if (!in_array($key, $this->propertiesToExclude)) {
$json->{$key} = "";
}
2015-04-17 13:51:47 -04:00
}
}
//set properties from 'formInstance' variable
if (isset($this->fields["APP_DATA"]["formInstance"])) {
$formInstance = $this->fields["APP_DATA"]["formInstance"];
if (!is_array($formInstance)) {
$formInstance = array($formInstance);
}
$nfi = count($formInstance);
for ($ifi = 0; $ifi < $nfi; $ifi++) {
$fi = $formInstance[$ifi];
if (is_object($fi) && isset($fi->id) && $key === "id" && $json->{$key} === $fi->id) {
foreach ($fi as $keyfi => $valuefi) {
if (isset($json->{$keyfi})) {
$json->{$keyfi} = $valuefi;
}
}
}
2015-02-03 14:40:33 -04:00
}
2015-02-27 18:10:59 -04:00
}
2016-12-09 15:53:29 -04:00
//options & query options
2015-10-26 18:18:43 -04:00
if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "hidden" || $value === "dropdown" || $value === "checkgroup" || $value === "radio" || $value === "suggest")) {
2016-12-09 15:53:29 -04:00
if (!isset($json->dbConnection)) {
2015-02-27 18:10:59 -04:00
$json->dbConnection = "none";
2016-12-09 15:53:29 -04:00
}
if (!isset($json->sql)) {
2015-02-27 18:10:59 -04:00
$json->sql = "";
2016-12-09 15:53:29 -04:00
}
if (!isset($json->datasource)) {
$json->datasource = "database";
}
if (!in_array($json->datasource, $this->dataSources)) {
$json->datasource = "database";
}
2015-09-25 19:55:26 -04:00
$json->optionsSql = array();
2016-12-09 15:53:29 -04:00
if ($json->datasource === "database" && $json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") {
if (isset($json->queryField)) {
$dtFields = $json->queryInputData;
} else {
$dtFields = $this->getValuesDependentFields($json);
2018-05-16 14:35:52 -04:00
foreach ($dtFields as $keyF => $valueF) {
if (isset($this->fields["APP_DATA"][$keyF])) {
$dtFields[$keyF] = $this->fields["APP_DATA"][$keyF];
}
}
2016-12-09 15:53:29 -04:00
}
$sql = $this->replaceDataField($json->sql, $dtFields);
2016-12-09 15:53:29 -04:00
if ($value === "suggest") {
$sql = $this->prepareSuggestSql($sql, $json);
2016-12-09 15:53:29 -04:00
}
$dt = $this->getCacheQueryData($json->dbConnection, $sql, $json->type);
foreach ($dt as $row) {
$option = new stdClass();
2017-03-13 13:50:32 -04:00
$option->value = isset($row[0]) ? $row[0] : "";
2016-12-09 15:53:29 -04:00
$option->label = isset($row[1]) ? $row[1] : "";
$json->optionsSql[] = $option;
}
if (isset($json->queryField)) {
$json->queryOutputData = $json->optionsSql;
}
}
if ($json->datasource === "dataVariable") {
$dataVariable = preg_match('/^\s*@.(.+)\s*$/', $json->dataVariable, $arrayMatch) ? $arrayMatch[1] : $json->dataVariable;
if (isset($this->fields['APP_DATA'][$dataVariable]) && is_array($this->fields['APP_DATA'][$dataVariable])) {
foreach ($this->fields['APP_DATA'][$dataVariable] as $row) {
$option = new stdClass();
2017-03-13 13:50:32 -04:00
$option->value = isset($row[0]) ? $row[0] : "";
2016-12-09 15:53:29 -04:00
$option->label = isset($row[1]) ? $row[1] : "";
$json->optionsSql[] = $option;
2019-12-10 11:33:47 -04:00
$json->queryOutputData[] = $option;
}
2016-12-09 15:53:29 -04:00
}
2016-12-19 11:10:51 -04:00
if ($value === "suggest" && isset($json->queryField) && $json->queryField == true) {
2018-01-15 14:41:21 -04:00
$this->searchResultInDataSource($json);
2016-12-19 11:10:51 -04:00
}
2015-03-05 18:14:04 -04:00
}
2015-09-25 19:55:26 -04:00
}
//data
if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "hidden")) {
$json->data = new stdClass();
$json->data->value = "";
$json->data->label = "";
if (isset($json->optionsSql[0])) {
$json->data->value = $json->optionsSql[0]->value;
$json->data->label = $json->optionsSql[0]->value;
}
if ($json->defaultValue !== "") {
$json->data->value = $json->defaultValue;
$json->data->label = $json->defaultValue;
}
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
$json->data->label = $this->fields["APP_DATA"][$json->name];
}
}
if ($key === "type" && ($value === "dropdown")) {
$json->data = new stdClass();
$json->data->value = "";
$json->data->label = "";
if ($json->defaultValue !== "") {
foreach ($json->optionsSql as $os) {
if ($os->value === $json->defaultValue) {
$json->data->value = $os->value;
$json->data->label = $os->label;
2015-04-17 16:52:19 -04:00
}
}
2015-09-25 19:55:26 -04:00
foreach ($json->options as $os) {
if ($os->value === $json->defaultValue) {
$json->data->value = $os->value;
$json->data->label = $os->label;
}
}
}
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
2015-10-26 18:18:43 -04:00
}
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
2015-09-25 19:55:26 -04:00
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
2015-02-03 14:40:33 -04:00
}
}
2015-09-25 19:55:26 -04:00
if ($key === "type" && ($value === "suggest")) {
$json->data = new stdClass();
$json->data->value = "";
$json->data->label = "";
if ($json->defaultValue !== "") {
$json->data->value = $json->defaultValue;
$json->data->label = $json->defaultValue;
foreach ($json->optionsSql as $os) {
if ($os->value === $json->defaultValue) {
$json->data->value = $os->value;
$json->data->label = $os->label;
}
}
foreach ($json->options as $os) {
if ($os->value === $json->defaultValue) {
$json->data->value = $os->value;
$json->data->label = $os->label;
}
}
2015-04-20 12:31:42 -04:00
}
2015-09-25 19:55:26 -04:00
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
}
2015-10-26 18:18:43 -04:00
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
}
2015-09-25 19:55:26 -04:00
}
if ($key === "type" && ($value === "radio")) {
$json->data = new stdClass();
$json->data->value = "";
$json->data->label = "";
if ($json->defaultValue !== "") {
foreach ($json->optionsSql as $os) {
if ($os->value === $json->defaultValue) {
$json->data->value = $os->value;
$json->data->label = $os->label;
}
}
2015-09-25 19:55:26 -04:00
foreach ($json->options as $os) {
if ($os->value === $json->defaultValue) {
$json->data->value = $os->value;
$json->data->label = $os->label;
}
}
}
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
2015-10-26 18:18:43 -04:00
}
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
2015-09-25 19:55:26 -04:00
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
}
}
if ($key === "type" && ($value === "checkbox")) {
$json->data = new stdClass();
2015-12-08 11:24:21 -04:00
$json->data->value = "0";
2015-09-25 19:55:26 -04:00
$json->data->label = "";
2015-12-08 11:24:21 -04:00
foreach ($json->options as $os) {
if ($os->value === false || $os->value === 0 || $os->value === "0") {
$json->data->label = $os->label;
}
}
if ($json->defaultValue !== "") {
$json->data->value = $json->defaultValue;
foreach ($json->options as $os) {
if (($json->data->value === "true" || $json->data->value === "1") &&
($os->value === true || $os->value === 1 || $os->value === "1")) {
$json->data->label = $os->label;
}
if (($json->data->value === "false" || $json->data->value === "0") &&
($os->value === false || $os->value === 0 || $os->value === "0")) {
$json->data->label = $os->label;
}
}
}
2015-09-25 19:55:26 -04:00
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
2015-12-08 11:24:21 -04:00
if (is_array($json->data->value) && isset($json->data->value[0])) {
$json->data->value = $json->data->value[0];
}
2015-12-04 17:31:37 -04:00
foreach ($json->options as $os) {
if (($json->data->value === true || $json->data->value === 1 || $json->data->value === "1") &&
($os->value === true || $os->value === 1 || $os->value === "1")) {
$json->data->label = $os->label;
}
if (($json->data->value === false || $json->data->value === 0 || $json->data->value === "0") &&
($os->value === false || $os->value === 0 || $os->value === "0")) {
$json->data->label = $os->label;
}
}
2015-09-25 19:55:26 -04:00
}
}
if ($key === "type" && ($value === "checkgroup")) {
$json->data = new stdClass();
$json->data->value = "";
$json->data->label = "[]";
if ($json->defaultValue !== "") {
$dataValue = array();
$dataLabel = array();
$dv = explode("|", $json->defaultValue);
foreach ($dv as $idv) {
foreach ($json->optionsSql as $os) {
if ($os->value === trim($idv)) {
array_push($dataValue, $os->value);
array_push($dataLabel, $os->label);
}
}
foreach ($json->options as $os) {
if ($os->value === trim($idv)) {
array_push($dataValue, $os->value);
array_push($dataLabel, $os->label);
}
}
}
2015-09-25 19:55:26 -04:00
$json->data->value = $dataValue;
$json->data->label = G::json_encode($dataLabel);
}
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
2015-10-26 18:18:43 -04:00
}
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
2015-09-25 19:55:26 -04:00
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
}
2015-03-05 18:14:04 -04:00
}
2015-09-25 19:55:26 -04:00
if ($key === "type" && ($value === "datetime")) {
$json->data = new stdClass();
$json->data->value = "";
$json->data->label = "";
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
2015-10-26 18:18:43 -04:00
}
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
2015-09-25 19:55:26 -04:00
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
2015-08-19 18:15:12 -04:00
}
$this->setDependentOptionsForDatetime($json, $this->fields);
2015-03-03 15:17:43 -04:00
}
2015-03-23 22:22:10 -04:00
if ($key === "type" && ($value === "file") && isset($this->fields["APP_DATA"]["APPLICATION"])) {
$oCriteriaAppDocument = new Criteria("workflow");
$oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::APP_DOC_UID);
$oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::DOC_VERSION);
$oCriteriaAppDocument->add(AppDocumentPeer::APP_UID, $this->fields["APP_DATA"]["APPLICATION"]);
$oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_FIELDNAME, $json->name);
2016-10-26 10:34:28 -04:00
$oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_STATUS, 'ACTIVE');
$oCriteriaAppDocument->addDescendingOrderByColumn(AppDocumentPeer::APP_DOC_CREATE_DATE);
$oCriteriaAppDocument->setLimit(1);
$rs = AppDocumentPeer::doSelectRS($oCriteriaAppDocument);
2015-03-05 18:14:04 -04:00
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$rs->next();
2015-03-05 18:14:04 -04:00
$links = array();
$labelsFromDb = array();
2016-04-27 10:01:01 -04:00
$appDocUids = array();
$oAppDocument = new AppDocument();
if ($row = $rs->getRow()) {
$oAppDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]);
2016-04-27 10:01:01 -04:00
$links[] = "../cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
$labelsFromDb[] = $oAppDocument->getAppDocFilename();
2016-04-27 10:01:01 -04:00
$appDocUids[] = $row["APP_DOC_UID"];
2015-03-05 18:14:04 -04:00
}
2015-09-25 19:55:26 -04:00
$json->data = new stdClass();
2015-12-08 11:24:21 -04:00
$json->data->value = $links;
2016-04-27 10:01:01 -04:00
$json->data->app_doc_uid = $appDocUids;
2015-12-08 11:24:21 -04:00
if (sizeof($labelsFromDb)) {
$json->data->label = G::json_encode($labelsFromDb);
} else {
$json->data->label = isset($this->fields["APP_DATA"][$json->name . "_label"]) ? $this->fields["APP_DATA"][$json->name . "_label"] : (isset($this->fields["APP_DATA"][$json->name]) ? $this->fields["APP_DATA"][$json->name] : "[]");
}
2015-09-25 19:55:26 -04:00
}
2015-10-26 18:18:43 -04:00
if ($key === "type" && ($value === "file") && isset($json->variable)) {
2015-10-05 12:12:58 -04:00
//todo
$oCriteria = new Criteria("workflow");
$oCriteria->addSelectColumn(ProcessVariablesPeer::INP_DOC_UID);
2016-04-19 18:15:06 -04:00
$oCriteria->add(ProcessVariablesPeer::VAR_UID, $json->var_uid);
2015-10-05 12:12:58 -04:00
$rs = ProcessVariablesPeer::doSelectRS($oCriteria);
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$rs->next();
$row = $rs->getRow();
if (isset($row["INP_DOC_UID"])) {
$json->inputDocuments = array($row["INP_DOC_UID"]);
}
}
2017-03-10 16:36:55 -04:00
if ($key === "type" && ($value === "multipleFile")) {
$json->data = new stdClass();
$json->data->value = "";
$json->data->label = "";
if (isset($this->fields["APP_DATA"][$json->name])) {
$json->data->value = $this->fields["APP_DATA"][$json->name];
}
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
}
}
2015-09-25 19:55:26 -04:00
//synchronize var_label
2016-03-07 18:10:01 -04:00
if ($key === "type" && ($value === "dropdown" || $value === "suggest" || $value === "radio")) {
2015-09-25 19:55:26 -04:00
if (isset($this->fields["APP_DATA"]["__VAR_CHANGED__"]) && in_array($json->name, explode(",", $this->fields["APP_DATA"]["__VAR_CHANGED__"]))) {
foreach ($json->optionsSql as $io) {
2016-03-07 18:10:01 -04:00
if ($this->toStringNotNullValues($json->data->value) === $io->value) {
2015-09-25 19:55:26 -04:00
$json->data->label = $io->label;
}
}
foreach ($json->options as $io) {
2016-03-07 18:10:01 -04:00
if ($this->toStringNotNullValues($json->data->value) === $io->value) {
2015-09-25 19:55:26 -04:00
$json->data->label = $io->label;
}
}
2017-12-04 13:25:35 +00:00
$_SESSION["TRIGGER_DEBUG"]["DATA"][] = array("key" => $json->name . "_label", "value" => $json->data->label);
2015-09-25 19:55:26 -04:00
}
}
if ($key === "type" && ($value === "checkgroup")) {
if (isset($this->fields["APP_DATA"]["__VAR_CHANGED__"]) && in_array($json->name, explode(",", $this->fields["APP_DATA"]["__VAR_CHANGED__"]))) {
$dataValue = array();
$dataLabel = array();
2015-10-13 14:02:34 -04:00
$dv = array();
2017-12-04 13:25:35 +00:00
if (isset($this->fields["APP_DATA"][$json->name])) {
2015-10-13 14:02:34 -04:00
$dv = $this->fields["APP_DATA"][$json->name];
2017-12-04 13:25:35 +00:00
}
2016-02-29 14:42:03 -04:00
if (!is_array($dv)) {
$dv = explode(",", $dv);
}
2015-09-25 19:55:26 -04:00
foreach ($dv as $idv) {
foreach ($json->optionsSql as $os) {
if ($os->value === $idv) {
2016-03-07 18:10:01 -04:00
$dataValue[] = $os->value;
$dataLabel[] = $os->label;
2015-09-25 19:55:26 -04:00
}
}
foreach ($json->options as $os) {
if ($os->value === $idv) {
2016-03-07 18:10:01 -04:00
$dataValue[] = $os->value;
$dataLabel[] = $os->label;
2015-09-25 19:55:26 -04:00
}
}
}
$json->data->value = $dataValue;
$json->data->label = G::json_encode($dataLabel);
2017-12-04 13:25:35 +00:00
$_SESSION["TRIGGER_DEBUG"]["DATA"][] = array("key" => $json->name . "_label", "value" => $json->data->label);
2015-09-25 19:55:26 -04:00
}
}
if ($key === "type" && ($value === "datetime")) {
if (isset($this->fields["APP_DATA"]["__VAR_CHANGED__"]) && in_array($json->name, explode(",", $this->fields["APP_DATA"]["__VAR_CHANGED__"]))) {
$json->data->label = $json->data->value;
2017-12-04 13:25:35 +00:00
$_SESSION["TRIGGER_DEBUG"]["DATA"][] = array("key" => $json->name . "_label", "value" => $json->data->label);
2015-09-25 19:55:26 -04:00
}
2015-03-03 15:17:43 -04:00
}
2016-03-07 18:10:01 -04:00
//clear optionsSql
if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "hidden" || $value === "suggest")) {
$json->optionsSql = array();
}
2015-02-27 18:10:59 -04:00
//grid
if ($key === "type" && ($value === "grid")) {
2017-03-09 11:12:09 -04:00
$columnsDataVariable = [];
2017-02-17 16:51:27 -04:00
//todo compatibility 'columnWidth'
foreach ($json->columns as $column) {
if (!isset($column->columnWidth) && $column->type !== "hidden") {
$json->layout = "static";
$column->columnWidth = "";
}
$column->parentIsGrid = true;
2017-03-09 11:12:09 -04:00
//save dataVariable value, only for columns control
if (!empty($column->dataVariable) && is_string($column->dataVariable)) {
if (in_array(substr($column->dataVariable, 0, 2), self::$prefixs)) {
$dataVariableValue = substr($column->dataVariable, 2);
if (!in_array($dataVariableValue, $columnsDataVariable)) {
$columnsDataVariable[] = $dataVariableValue;
}
}
}
2017-02-17 16:51:27 -04:00
}
//data grid environment
$json->dataGridEnvironment = "onDataGridEnvironment";
if (isset($this->fields["APP_DATA"])) {
$dataGridEnvironment = $this->fields["APP_DATA"];
//Grids only access the global variables of 'ProcessMaker', other variables are removed.
$this->fields["APP_DATA"] = Cases::getGlobalVariables($this->fields["APP_DATA"]);
2017-03-09 11:12:09 -04:00
//restore AppData with dataVariable definition, only for columns control
foreach ($columnsDataVariable as $dge) {
if (isset($dataGridEnvironment[$dge])) {
$this->fields["APP_DATA"][$dge] = $dataGridEnvironment[$dge];
}
}
2017-02-17 16:51:27 -04:00
}
}
if ($key === "dataGridEnvironment" && ($value === "onDataGridEnvironment")) {
if (isset($this->fields["APP_DATA"])) {
$this->fields["APP_DATA"] = $dataGridEnvironment;
$dataGridEnvironment = [];
}
2017-04-06 10:50:56 -04:00
if (isset($this->fields["APP_DATA"][$json->name]) && is_array($this->fields["APP_DATA"][$json->name])) {
2015-02-27 18:10:59 -04:00
//rows
2015-03-23 22:22:10 -04:00
$rows = $this->fields["APP_DATA"][$json->name];
2015-02-27 18:10:59 -04:00
foreach ($rows as $keyRow => $row) {
//cells
$cells = array();
foreach ($json->columns as $column) {
//data
2017-03-10 16:36:55 -04:00
if ($column->type === "text" || $column->type === "textarea" || $column->type === "dropdown" || $column->type === "suggest" || $column->type === "datetime" || $column->type === "checkbox" || $column->type === "file" || $column->type === "multipleFile" || $column->type === "link" || $column->type === "hidden") {
2015-02-27 18:10:59 -04:00
array_push($cells, array(
2015-03-02 18:19:55 -04:00
"value" => isset($row[$column->name]) ? $row[$column->name] : "",
2015-04-17 19:32:39 -04:00
"label" => isset($row[$column->name . "_label"]) ? $row[$column->name . "_label"] : (isset($row[$column->name]) ? $row[$column->name] : "")
2015-02-27 18:10:59 -04:00
));
}
}
$rows[$keyRow] = $cells;
}
$json->rows = count($rows);
$json->data = $rows;
2019-05-16 15:54:07 -04:00
$this->setDataSchema($json, $this->fields["APP_DATA"][$json->name]);
2015-02-03 14:40:33 -04:00
}
}
2019-09-18 15:27:26 -04:00
// Set the language defined in the json
2015-03-24 16:15:19 -04:00
if ($this->lang === null && $key === "language" && isset($json->language)) {
$this->lang = $json->language;
}
2019-09-18 15:27:26 -04:00
// Get the translations related to the language
if (!is_null($this->translations)) {
$labelsPo = $this->getLabelsPo($this->lang);
$translatableLabels = [
"label",
"title",
"hint",
"placeholder",
"validateMessage",
"alternateText",
"comment",
"alt"
];
if ((in_array($key, $translatableLabels)) && !is_null($labelsPo)) {
foreach ($labelsPo as $langsValue) {
2015-04-17 13:51:47 -04:00
if (is_object($json) && $json->{$key} === $langsValue->msgid) {
2015-04-06 10:23:47 -04:00
$json->{$key} = $langsValue->msgstr;
2015-04-17 13:51:47 -04:00
}
if (is_array($json) && $json[$key] === $langsValue->msgid) {
$json[$key] = $langsValue->msgstr;
}
2015-04-06 10:23:47 -04:00
}
2015-03-24 16:15:19 -04:00
}
}
2015-08-28 15:26:14 -04:00
//EDIT,VIEW
if (isset($this->fields["STEP_MODE"]) && $this->fields["STEP_MODE"] === "VIEW" && isset($json->mode)) {
$json->mode = "view";
}
2016-03-01 11:46:32 -04:00
if ($this->displayMode !== null && isset($json->mode)) {
$json->mode = $this->displayMode;
}
2015-10-12 11:35:26 -04:00
if ($key === "type" && ($value === "form") && $this->records != null) {
2015-10-09 15:56:49 -04:00
foreach ($this->records as $ri) {
if ($json->id === $ri["DYN_UID"] && !isset($json->jsonUpdate)) {
2015-12-04 17:31:37 -04:00
$jsonUpdate = G::json_decode($ri["DYN_CONTENT"]);
2015-10-09 15:56:49 -04:00
$jsonUpdate = $jsonUpdate->items[0];
$jsonUpdate->colSpan = $json->colSpan;
2016-01-25 17:46:55 -04:00
$jsonUpdate->mode = $json->mode;
2015-10-09 15:56:49 -04:00
$jsonUpdate->jsonUpdate = true;
$json = $jsonUpdate;
$this->jsonr($json);
}
}
}
//read event after
$fn = $this->onAfterPropertyRead;
if (is_callable($fn) || function_exists($fn)) {
$fn($json, $key, $value);
}
2015-02-03 14:40:33 -04:00
}
}
}
2014-08-01 13:06:51 -04:00
2018-01-15 14:41:21 -04:00
/**
* This function will be search in the dataSource and will be add the new row in the queryOutputData property
*
* @param object $json
*
* @return void
*/
private function searchResultInDataSource($json)
{
$json->queryOutputData = [];
foreach ($json->optionsSql as $option) {
//We will to check the limit parameter
if (count($json->queryOutputData) < $json->queryLimit) {
//Searching by filter parameter
if ($json->queryFilter !== '') {
if (stripos($option->label, $json->queryFilter) !== false) {
$json->queryOutputData[] = $option;
}
} elseif (isset($json->querySearch) && is_array($json->querySearch) && !empty($json->querySearch)) {
//Searching by query parameter
$dataSearch = $json->querySearch;
$valueAdded = false;
//The match has priority
//We will to search match in the dataSource
if (isset($dataSearch['match'])) {
$value = isset($dataSearch['match']['value']) ? $dataSearch['match']['value'] : '';
$label = isset($dataSearch['match']['text']) ? $dataSearch['match']['text'] : '';
if (!empty($value) && $option->value === $value) {
$valueAdded = true;
$json->queryOutputData[] = $option;
}
if (!empty($label) && $option->label === $label && !$valueAdded) {
$json->queryOutputData[] = $option;
}
} elseif (isset($dataSearch['term'])) {
//We will to search term in the dataSource
$value = isset($dataSearch['term']['value']) ? $dataSearch['term']['value'] : '';
$label = isset($dataSearch['term']['text']) ? $dataSearch['term']['text'] : '';
if (!empty($value) && stripos($option->value, $value) !== false) {
$valueAdded = true;
$json->queryOutputData[] = $option;
}
if (!empty($label) && stripos($option->label, $label) !== false && !$valueAdded) {
$json->queryOutputData[] = $option;
}
}
} else {
$json->queryOutputData[] = $option;
}
}
}
}
/**
* Get the values of the dependent references.
* @param object $json
* @return array
*/
private function getValuesDependentFields($json): array
2015-10-26 18:18:43 -04:00
{
2015-11-09 17:27:35 -04:00
if (!isset($this->record["DYN_CONTENT"])) {
return array();
}
2017-09-15 17:52:26 -04:00
$data = [];
if (isset($this->fields["APP_DATA"])) {
foreach ($this->fields["APP_DATA"] as $keyF => $valueF) {
if (!isset($data[$keyF]) && !is_array($valueF)) {
$data[$keyF] = $valueF;
}
}
}
2015-10-26 18:18:43 -04:00
if (isset($json->dbConnection) && isset($json->sql)) {
2017-03-06 11:00:37 -04:00
$result = array();
preg_match_all('/\@(?:([\@\%\#\=\?\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $json->sql, $result, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
2017-03-06 11:00:37 -04:00
$variables = isset($result[2]) ? $result[2] : array();
2015-10-26 18:18:43 -04:00
foreach ($variables as $key => $value) {
2017-03-27 11:29:02 -04:00
//Prevents an infinite cycle. If the name of the variable is used within its own dependent.
if ($value[0] === $json->variable) {
continue;
}
2018-05-22 14:35:33 -04:00
$jsonDecode = G::json_decode($this->record["DYN_CONTENT"]);
$jsonSearch = $this->jsonsf($jsonDecode, $value[0], $json->variable === "" ? "id" : "variable");
2015-10-26 18:18:43 -04:00
$a = $this->getValuesDependentFields($jsonSearch);
foreach ($a as $i => $v) {
$data[$i] = $v;
}
}
if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") {
$sql = $this->replaceDataField($json->sql, $data);
2017-03-06 11:00:37 -04:00
$dt = $this->getCacheQueryData($json->dbConnection, $sql, $json->type);
2016-12-09 15:53:29 -04:00
$row = isset($dt[0]) ? $dt[0] : [];
2017-09-15 17:52:26 -04:00
$index = $json->variable === "" ? $json->id : $json->variable;
if (!isset($data[$index]) && isset($row[0]) && $json->type !== "suggest" && $json->type !== "radio") {
$data[$index] = $row[0];
2015-10-26 18:18:43 -04:00
}
}
}
2015-11-03 15:00:42 -04:00
if (isset($json->options) && isset($json->options[0])) {
$data[$json->variable === "" ? $json->id : $json->variable] = $json->options[0]->value;
}
if (isset($json->placeholder) && $json->placeholder !== "") {
2015-12-04 17:31:37 -04:00
$data[$json->variable === "" ? $json->id : $json->variable] = "";
2015-11-03 15:00:42 -04:00
}
2015-10-26 18:18:43 -04:00
if (isset($json->defaultValue) && $json->defaultValue !== "") {
$data[$json->variable === "" ? $json->id : $json->variable] = $json->defaultValue;
}
return $data;
}
2019-03-13 09:09:42 -04:00
/**
* Get data from cache query.
*
* @param string $connection
* @param string $sql
* @param string $type
* @param boolean $clearCache
* @return array
* @see \PmDynaform->jsonr()
* @see \PmDynaform->getValuesDependentFields()
*/
2016-12-09 15:53:29 -04:00
private function getCacheQueryData($connection, $sql, $type = "", $clearCache = false)
{
$data = [];
if (!empty($type)) {
$type = "-" . $type;
}
try {
if ($clearCache === true) {
unset($this->cache[md5($sql)]);
}
if (isset($this->cache[md5($sql)])) {
$data = $this->cache[md5($sql)];
} else {
$cnn = Propel::getConnection($connection);
$stmt = $cnn->createStatement();
$rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM);
while ($rs->next()) {
$data[] = $rs->getRow();
}
$this->cache[md5($sql)] = $data;
$this->context["action"] = "execute-sql" . $type;
$this->context["sql"] = $sql;
\Bootstrap::registerMonolog("sqlExecution", 200, "Sql Execution", $this->context, $this->sysSys, "processmaker.log");
}
} catch (Exception $e) {
$this->context["action"] = "execute-sql" . $type;
$this->context["exception"] = (array) $e;
2019-03-13 09:09:42 -04:00
$this->lastQueryError = $e;
2017-10-23 15:01:21 -04:00
\Bootstrap::registerMonolog("sqlExecution",
400,
"Sql Execution",
$this->basicExceptionData($e, $sql),
2017-10-23 15:01:21 -04:00
$this->sysSys,
"processmaker.log");
2016-12-09 15:53:29 -04:00
}
return $data;
}
public function getDatabaseProvider($dbConnection)
{
2017-04-10 14:41:33 -04:00
if ($dbConnection === "workflow" || $dbConnection === "rbac" || $dbConnection === "rp") {
return "mysql";
}
2016-12-09 15:53:29 -04:00
if ($this->databaseProviders === null) {
$a = new Criteria("workflow");
$a->addSelectColumn(DbSourcePeer::DBS_UID);
$a->addSelectColumn(DbSourcePeer::DBS_TYPE);
$ds = DbSourcePeer::doSelectRS($a);
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$this->databaseProviders = [];
while ($ds->next()) {
$this->databaseProviders[] = $ds->getRow();
}
}
foreach ($this->databaseProviders as $key => $value) {
if ($value["DBS_UID"] === $dbConnection) {
return $value["DBS_TYPE"];
}
}
return null;
}
public function sqlParse($sql, $fn = null)
{
$sqlParser = new \PHPSQLParser($sql);
$parsed = $sqlParser->parsed;
if (!empty($parsed["SELECT"])) {
$options = isset($parsed["OPTIONS"]) && count($parsed["OPTIONS"]) > 0 ? implode(" ", $parsed["OPTIONS"]) : "";
if (!empty($options)) {
$options = $options . " ";
}
$select = "SELECT " . $options;
$dt = $parsed["SELECT"];
foreach ($dt as $key => $value) {
if ($key != 0) {
$select .= ", ";
}
$sAlias = str_replace("`", "", $dt[$key]["alias"]);
$sBaseExpr = $dt[$key]["base_expr"];
if (strpos(strtoupper($sBaseExpr), "TOP") !== false) {
$dt[$key]["expr_type"] = "";
$sBaseExpr = trim($sBaseExpr) . " " . trim($sAlias);
}
switch ($dt[$key]["expr_type"]) {
case "colref":
if ($sAlias === $sBaseExpr) {
$select .= $sAlias;
} else {
$select .= $sBaseExpr . " AS " . $sAlias;
}
break;
case "expression":
if ($sAlias === $sBaseExpr) {
$select .= $sBaseExpr;
} else {
$select .= $sBaseExpr . " AS " . $sAlias;
}
break;
case "subquery":
2019-11-08 16:11:01 -04:00
if (strpos($sAlias, $sBaseExpr, 0) !== 0) {
2016-12-09 15:53:29 -04:00
$select .= $sAlias;
} else {
$select .= $sBaseExpr . " AS " . $sAlias;
}
break;
case "operator":
$select .= $sBaseExpr;
break;
default:
$select .= $sBaseExpr;
break;
}
}
$select = trim($select);
$isOffsetWord = false;
$from = "";
if (!empty($parsed["FROM"])) {
$from = "FROM ";
$dt = $parsed["FROM"];
foreach ($dt as $key => $value) {
//reserved word: OFFSET
if ($dt[$key]["alias"] === "OFFSET") {
$isOffsetWord = true;
$dt[$key]["alias"] = "";
}
if ($key == 0) {
//compatibility with table name alias when uses the sentence 'AS'
if (strtoupper($dt[$key]["alias"]) === 'AS') {
$parser = new Parser($sql);
if (isset($parser->statements[$key]) && isset($parser->statements[$key]->from[$key])) {
$obj1 = $parser->statements[$key]->from[$key];
if (!empty($obj1->alias)) {
$dt[$key]["alias"] = $dt[$key]["alias"] . ' ' . $obj1->alias;
}
}
}
2016-12-09 15:53:29 -04:00
$from .= $dt[$key]["table"]
. ($dt[$key]["table"] == $dt[$key]["alias"] ? "" : " " . $dt[$key]["alias"]);
} else {
$from .= " "
. ($dt[$key]["join_type"] == "JOIN" ? "INNER" : $dt[$key]["join_type"])
. " JOIN "
. $dt[$key]["table"]
. ($dt[$key]["table"] == $dt[$key]["alias"] ? "" : " " . $dt[$key]["alias"]) . " "
2020-01-16 14:28:53 -04:00
. $dt[$key]["ref_type"] . " ";
// Get the last 6 chars of the string
$tempString = mb_substr($dt[$key]["ref_clause"], -6);
// If the last section is a "INNER" statement we need to remove it
if (strcasecmp($tempString, " INNER") === 0) {
$from .= mb_substr($dt[$key]["ref_clause"], 0, mb_strlen($dt[$key]["ref_clause"]) - 6);
} else {
$from .= $dt[$key]["ref_clause"];
}
2016-12-09 15:53:29 -04:00
}
}
}
$from = trim($from);
$where = "";
if (!empty($parsed["WHERE"])) {
$where = "WHERE ";
2017-03-28 11:00:23 -04:00
$dt = ($parsed['WHERE'][0]['expr_type'] == 'expression') ? $parsed['WHERE'][0]['sub_tree'] : $parsed["WHERE"];
2016-12-09 15:53:29 -04:00
$nw = count($dt);
//reserved word: OFFSET
if ($dt[$nw - 2]["base_expr"] === "OFFSET") {
$isOffsetWord = true;
if ($dt[$nw - 2]["expr_type"] === "colref") {
$dt[$nw - 2]["base_expr"] = "";
}
if ($dt[$nw - 1]["expr_type"] === "const") {
if (isset($parsed["LIMIT"]["start"])) {
$parsed["LIMIT"]["start"] = $dt[$nw - 1]["base_expr"];
}
$dt[$nw - 1]["base_expr"] = "";
}
}
foreach ($dt as $key => $value) {
$where .= $value["base_expr"] . " ";
}
}
$where = trim($where);
$groupBy = "";
if (!empty($parsed["GROUP"])) {
$groupBy = "GROUP BY ";
$dt = $parsed["GROUP"];
foreach ($dt as $key => $value) {
2017-03-28 13:26:02 -04:00
$search = preg_replace("/ ASC$/i", "", $value["base_expr"]);
$groupBy .= $search . ", ";
2016-12-09 15:53:29 -04:00
}
$groupBy = rtrim($groupBy, ", ");
}
$groupBy = trim($groupBy);
$having = "";
if (!empty($parsed["HAVING"])) {
$having = "HAVING ";
$dt = $parsed["HAVING"];
foreach ($dt as $key => $value) {
$having .= $value["base_expr"] . " ";
}
}
$having = trim($having);
$orderBy = "";
if (!empty($parsed["ORDER"])) {
$orderBy = "ORDER BY ";
$dt = $parsed["ORDER"];
foreach ($dt as $key => $value) {
2017-03-28 13:26:02 -04:00
$search = preg_replace("/ ASC$/i", "", $value["base_expr"]);
2017-03-28 14:25:11 -04:00
$orderBy .= $search . " " . $value["direction"] . ", ";
2016-12-09 15:53:29 -04:00
}
$orderBy = rtrim($orderBy, ", ");
}
$orderBy = trim($orderBy);
$limit = "";
if (!empty($parsed["LIMIT"])) {
if ($isOffsetWord == false) {
$limit = "LIMIT " . $parsed["LIMIT"]["start"] . ", " . $parsed["LIMIT"]["end"];
}
if ($isOffsetWord == true) {
$limit = "OFFSET " . $parsed["LIMIT"]["start"] . " LIMIT " . $parsed["LIMIT"]["end"];
}
}
if ($fn !== null && (is_callable($fn) || function_exists($fn))) {
$fn($parsed, $select, $from, $where, $groupBy, $having, $orderBy, $limit);
}
$dt = [$select, $from, $where, $groupBy, $having, $orderBy, $limit];
$query = "";
foreach ($dt as $val) {
$val = trim($val);
if (!empty($val)) {
$query = $query . $val . " ";
}
}
return $query;
}
if (!empty($parsed["CALL"])) {
$sCall = "CALL ";
$aCall = $parsed["CALL"];
foreach ($aCall as $key => $value) {
$sCall .= $value . " ";
}
return $sCall;
}
if (!empty($parsed["EXECUTE"])) {
$sCall = "EXECUTE ";
$aCall = $parsed["EXECUTE"];
foreach ($aCall as $key => $value) {
$sCall .= $value . " ";
}
return $sCall;
}
return $sql;
}
2014-08-01 13:06:51 -04:00
public function isResponsive()
{
return $this->record != null && $this->record["DYN_VERSION"] == 2 ? true : false;
}
public function printTracker()
{
ob_clean();
2015-12-15 16:51:06 -04:00
$this->fields["STEP_MODE"] = "VIEW";
$json = G::json_decode($this->record["DYN_CONTENT"]);
foreach ($json->items[0]->items as $key => $value) {
2015-12-15 16:51:06 -04:00
$n = count($json->items[0]->items[$key]);
for ($i = 0; $i < $n; $i++) {
if (isset($json->items[0]->items[$key][$i]->type) && $json->items[0]->items[$key][$i]->type === "submit") {
$cols = new stdClass();
$cols->colSpan = $json->items[0]->items[$key][$i]->colSpan;
$json->items[0]->items[$key][$i] = $cols;
}
}
}
$this->jsonr($json);
$javascript = "
<script type=\"text/javascript\">
var jsondata = " . G::json_encode($json) . ";
2017-08-14 16:13:46 -04:00
var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";
var pm_run_outside_main_app = \"\";
var dyn_uid = \"" . $this->fields["CURRENT_DYNAFORM"] . "\";
var __DynaformName__ = \"" . $this->record["PRO_UID"] . "_" . $this->record["DYN_UID"] . "\";
var app_uid = \"" . $this->fields["APP_UID"] . "\";
var prj_uid = \"" . $this->fields["PRO_UID"] . "\";
var step_mode = \"\";
2017-10-10 12:33:25 -04:00
var workspace = \"" . config("system.workspace") . "\";
var credentials = " . G::json_encode($this->credentials) . ";
var filePost = \"\";
var fieldsRequired = null;
var triggerDebug = false;
var sysLang = \"" . SYS_LANG . "\";
var isRTL = \"" . $this->isRTL . "\";
var pathRTLCss = \"" . $this->pathRTLCss . "\";
2016-08-13 10:12:54 -04:00
var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "0") . ";
" . $this->getTheStringVariableForGoogleMaps() . "\n
$(window).load(function ()
{
var data = jsondata;
2016-03-31 15:42:59 -04:00
window.dynaform = new PMDynaform.core.Project({
data: data,
delIndex: delIndex,
2016-09-19 13:38:34 -04:00
dynaformUid: dyn_uid,
keys: {
2016-03-31 15:42:59 -04:00
server: httpServerHostname,
projectId: prj_uid,
workspace: workspace
},
token: credentials,
submitRest: false,
googleMaps: typeof googleMaps !== 'undefined' ? googleMaps : null
});
$(document).find(\"form\").submit(function (e) {
e.preventDefault();
return false;
});
});
</script>
<div style=\"margin: 10px 20px 10px 0;\">
<div style=\"float: right\"><a href=\"javascript: window.history.go(-1);\" style=\"text-decoration: none;\">&lt; " . G::LoadTranslation("ID_BACK") . "</a></div>
<div style=\"clear: both\"></div>
</div>
";
$file = file_get_contents(PATH_HOME . "public_html" . PATH_SEP . "lib" . PATH_SEP . "pmdynaform" . PATH_SEP . "build" . PATH_SEP . "pmdynaform.html");
$file = str_replace("{javascript}", $javascript, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
echo $file;
exit(0);
}
2015-03-12 09:59:19 -04:00
public function printView()
2014-08-01 13:06:51 -04:00
{
ob_clean();
2016-03-01 11:46:32 -04:00
$this->displayMode = "disabled";
2015-02-27 18:10:59 -04:00
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
$javascrip = "" .
"<script type='text/javascript'>\n" .
"var jsondata = " . G::json_encode($json) . ";\n" .
2017-08-14 16:13:46 -04:00
"var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";\n" .
2015-03-12 09:59:19 -04:00
"var pm_run_outside_main_app = null;\n" .
"var dyn_uid = '" . $this->fields["CURRENT_DYNAFORM"] . "';\n" .
2015-02-27 18:10:59 -04:00
"var __DynaformName__ = '" . $this->record["PRO_UID"] . "_" . $this->record["DYN_UID"] . "';\n" .
2015-03-12 09:59:19 -04:00
"var app_uid = '" . $this->fields["APP_UID"] . "';\n" .
"var prj_uid = '" . $this->fields["PRO_UID"] . "';\n" .
2015-02-27 18:10:59 -04:00
"var step_mode = null;\n" .
2017-10-10 12:33:25 -04:00
"var workspace = '" . config("system.workspace") . "';\n" .
2015-03-12 09:59:19 -04:00
"var credentials = " . G::json_encode($this->credentials) . ";\n" .
2015-02-27 18:10:59 -04:00
"var filePost = null;\n" .
"var fieldsRequired = null;\n" .
2015-03-03 15:17:43 -04:00
"var triggerDebug = null;\n" .
"var sysLang = '" . SYS_LANG . "';\n" .
"var isRTL = " . $this->isRTL . ";\n" .
"var pathRTLCss = '" . $this->pathRTLCss . "';\n" .
2016-08-13 10:12:54 -04:00
"var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "0") . ";\n" .
2016-12-02 14:14:18 -04:00
"var leaveCaseWarning = " . $this->getLeaveCaseWarning() . ";\n" .
$this->getTheStringVariableForGoogleMaps() . "\n" .
2015-02-27 18:10:59 -04:00
"$(window).load(function () {\n" .
" var data = jsondata;\n" .
2016-03-31 15:42:59 -04:00
" window.dynaform = new PMDynaform.core.Project({\n" .
2015-02-27 18:10:59 -04:00
" data: data,\n" .
2016-08-19 16:47:39 -04:00
" delIndex: delIndex,\n" .
2016-09-19 13:38:34 -04:00
" dynaformUid: dyn_uid,\n" .
2015-02-27 18:10:59 -04:00
" keys: {\n" .
2016-03-31 15:42:59 -04:00
" server: httpServerHostname,\n" .
2015-02-27 18:10:59 -04:00
" projectId: prj_uid,\n" .
" workspace: workspace\n" .
" },\n" .
" token: credentials,\n" .
" submitRest: false,\n" .
" googleMaps: typeof googleMaps !== 'undefined' ? googleMaps : null\n" .
2015-02-27 18:10:59 -04:00
" });\n" .
2016-03-07 08:56:49 -04:00
" $(document).find('form').find('button').on('click', function (e) {\n" .
2016-03-01 11:46:32 -04:00
" e.preventDefault();\n" .
2016-03-07 08:56:49 -04:00
" return false;\n" .
2016-03-01 11:46:32 -04:00
" });\n" .
2015-02-27 18:10:59 -04:00
" $(document).find('form').submit(function (e) {\n" .
" e.preventDefault();\n" .
" return false;\n" .
" });\n" .
"});\n" .
"</script>\n";
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html');
$file = str_replace("{javascript}", $javascrip, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
2014-08-01 13:06:51 -04:00
echo $file;
exit();
}
2015-03-12 09:59:19 -04:00
public function printEdit()
2014-08-01 13:06:51 -04:00
{
ob_clean();
2015-02-27 18:10:59 -04:00
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
2015-03-12 09:59:19 -04:00
if (!isset($this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["PREVIOUS_STEP"])) {
$this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["PREVIOUS_STEP"] = "";
}
2019-04-26 09:24:15 -04:00
$title = $this->getSessionMessage() .
2015-10-09 19:14:06 -04:00
"<table width='100%' align='center'>\n" .
2015-03-02 12:51:29 -04:00
" <tr class='userGroupTitle'>\n" .
2015-03-12 09:59:19 -04:00
" <td width='100%' align='center'>" . G::LoadTranslation('ID_CASE') . " #: " . $this->fields["APP_NUMBER"] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . G::LoadTranslation('ID_TITLE') . ": " . $this->fields["APP_TITLE"] . "</td>\n" .
2015-03-02 12:51:29 -04:00
" </tr>\n" .
"</table>\n";
2015-02-27 18:10:59 -04:00
$javascrip = "" .
"<script type='text/javascript'>\n" .
"var jsondata = " . $this->json_encode($json) . ";\n" .
2017-08-14 16:13:46 -04:00
"var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";\n" .
2015-03-12 09:59:19 -04:00
"var pm_run_outside_main_app = '" . $this->fields["PM_RUN_OUTSIDE_MAIN_APP"] . "';\n" .
"var dyn_uid = '" . $this->fields["CURRENT_DYNAFORM"] . "';\n" .
2015-02-27 18:10:59 -04:00
"var __DynaformName__ = '" . $this->record["PRO_UID"] . "_" . $this->record["DYN_UID"] . "';\n" .
2015-03-12 09:59:19 -04:00
"var app_uid = '" . $this->fields["APP_UID"] . "';\n" .
"var prj_uid = '" . $this->fields["PRO_UID"] . "';\n" .
"var step_mode = '" . $this->fields["STEP_MODE"] . "';\n" .
2017-10-10 12:33:25 -04:00
"var workspace = '" . config("system.workspace") . "';\n" .
2015-02-27 18:10:59 -04:00
"var credentials = " . G::json_encode($this->credentials) . ";\n" .
"var filePost = null;\n" .
"var fieldsRequired = null;\n" .
2015-03-12 09:59:19 -04:00
"var triggerDebug = " . ($this->fields["TRIGGER_DEBUG"] === 1 ? "true" : "false") . ";\n" .
"var sysLang = '" . SYS_LANG . "';\n" .
"var isRTL = " . $this->isRTL . ";\n" .
"var pathRTLCss = '" . $this->pathRTLCss . "';\n" .
2016-08-13 10:12:54 -04:00
"var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "0") . ";\n" .
2016-12-02 14:14:18 -04:00
"var leaveCaseWarning = " . $this->getLeaveCaseWarning() . ";\n" .
$this->getTheStringVariableForGoogleMaps() . "\n" .
2015-02-27 18:10:59 -04:00
"</script>\n" .
"<script type='text/javascript' src='/jscore/cases/core/cases_Step.js'></script>\n" .
"<script type='text/javascript' src='/jscore/cases/core/pmDynaform.js'></script>\n" .
2017-12-04 13:25:35 +00:00
($this->fields["PRO_SHOW_MESSAGE"] === 1 ? '' : $title) .
2015-03-02 12:51:29 -04:00
"<div style='width:100%;padding:0px 10px 0px 10px;margin:15px 0px 0px 0px;'>\n" .
2015-02-27 18:10:59 -04:00
" <img src='/images/bulletButtonLeft.gif' style='float:left;'>&nbsp;\n" .
2015-03-12 09:59:19 -04:00
" <a id='dyn_backward' href='" . $this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["PREVIOUS_STEP"] . "' style='float:left;font-size:12px;line-height:1;margin:0px 0px 1px 5px;'>\n" .
" " . $this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["PREVIOUS_STEP_LABEL"] . "" .
2015-02-27 18:10:59 -04:00
" </a>\n" .
" <img src='/images/bulletButton.gif' style='float:right;'>&nbsp;\n" .
2015-03-12 09:59:19 -04:00
" <a id='dyn_forward' href='" . $this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["NEXT_STEP"] . "' style='float:right;font-size:12px;line-height:1;margin:0px 5px 1px 0px;'>\n" .
" " . $this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["NEXT_STEP_LABEL"] . "" .
2015-02-27 18:10:59 -04:00
" </a>\n" .
"</div>";
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html');
$file = str_replace("{javascript}", $javascrip, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
2014-08-01 13:06:51 -04:00
echo $file;
exit();
}
public function printEditSupervisor()
{
ob_clean();
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
$javascrip = "
<script type=\"text/javascript\">
var jsondata = " . G::json_encode($json) . ";
2017-08-14 16:13:46 -04:00
var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";
var pm_run_outside_main_app = null;
var dyn_uid = \"" . $this->fields["CURRENT_DYNAFORM"] . "\";
var __DynaformName__ = \"" . $this->fields["PRO_UID"] . "_" . $this->fields["CURRENT_DYNAFORM"] . "\";
var app_uid = \"" . $this->fields["APP_UID"] . "\";
var prj_uid = \"" . $this->fields["PRO_UID"] . "\";
var step_mode = null;
2017-10-10 12:33:25 -04:00
var workspace = \"" . config("system.workspace") . "\";
var credentials = " . G::json_encode($this->credentials) . ";
2015-09-25 19:55:26 -04:00
var filePost = \"cases_SaveDataSupervisor?UID=" . $this->fields["CURRENT_DYNAFORM"] . "\";
var fieldsRequired = null;
var triggerDebug = null;
var sysLang = \"" . SYS_LANG . "\";
var isRTL = \"" . $this->isRTL . "\";
var pathRTLCss = \"" . $this->pathRTLCss . "\";
2016-08-13 10:12:54 -04:00
var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "0") . ";
2016-12-02 14:14:18 -04:00
var leaveCaseWarning = " . $this->getLeaveCaseWarning() . ";
" . $this->getTheStringVariableForGoogleMaps() . "
</script>
<script type=\"text/javascript\" src=\"/jscore/cases/core/pmDynaform.js\"></script>
<div>
2019-04-26 09:24:15 -04:00
" . $this->getSessionMessageForSupervisor() . "
<div style=\"display: none;\">
<a id=\"dyn_forward\" href=\"javascript:;\"></a>
</div>
</div>
";
$file = file_get_contents(PATH_HOME . "public_html" . PATH_SEP . "lib" . PATH_SEP . "pmdynaform" . PATH_SEP . "build" . PATH_SEP . "pmdynaform.html");
$file = str_replace("{javascript}", $javascrip, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
echo $file;
exit(0);
}
public function printWebEntry($filename)
2015-02-18 09:50:29 -04:00
{
ob_clean();
2015-02-27 18:10:59 -04:00
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
$javascrip = "" .
"<script type='text/javascript'>\n" .
"var jsondata = " . G::json_encode($json) . ";\n" .
2017-08-14 16:13:46 -04:00
"var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";\n" .
2015-02-27 18:10:59 -04:00
"var pm_run_outside_main_app = null;\n" .
2015-03-12 09:59:19 -04:00
"var dyn_uid = '" . $this->fields["CURRENT_DYNAFORM"] . "';\n" .
2015-02-27 18:10:59 -04:00
"var __DynaformName__ = null;\n" .
"var app_uid = null;\n" .
"var prj_uid = '" . $this->record["PRO_UID"] . "';\n" .
"var step_mode = null;\n" .
2017-10-10 12:33:25 -04:00
"var workspace = '" . config("system.workspace") . "';\n" .
2015-02-27 18:10:59 -04:00
"var credentials = " . G::json_encode($this->credentials) . ";\n" .
"var filePost = '" . $filename . "';\n" .
2015-03-12 09:59:19 -04:00
"var fieldsRequired = " . G::json_encode(array()) . ";\n" .
2015-03-03 15:17:43 -04:00
"var triggerDebug = null;\n" .
"var sysLang = '" . SYS_LANG . "';\n" .
"var isRTL = " . $this->isRTL . ";\n" .
"var pathRTLCss = '" . $this->pathRTLCss . "';\n" .
2016-08-13 10:12:54 -04:00
"var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "0") . ";\n" .
2016-12-02 14:14:18 -04:00
"var leaveCaseWarning = " . $this->getLeaveCaseWarning() . ";\n" .
$this->getTheStringVariableForGoogleMaps() . "\n" .
2015-02-27 18:10:59 -04:00
"</script>\n" .
"<script type='text/javascript' src='/jscore/cases/core/pmDynaform.js'></script>\n" .
"<div style='width:100%;padding: 0px 10px 0px 10px;margin:15px 0px 0px 0px;'>\n" .
" <img src='/images/bulletButton.gif' style='float:right;'>&nbsp;\n" .
" <a id='dyn_forward' href='' style='float:right;font-size:12px;line-height:1;margin:0px 5px 1px 0px;'>\n" .
" Next Step\n" .
" </a>\n" .
"</div>";
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html');
$file = str_replace("{javascript}", $javascrip, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
2015-02-27 18:10:59 -04:00
echo $file;
exit();
}
public function printABE($filename, $record)
{
ob_clean();
$this->record = $record;
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
$javascrip = "" .
"<script type='text/javascript'>\n" .
"var jsondata = " . G::json_encode($json) . ";\n" .
2017-08-14 16:13:46 -04:00
"var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";\n" .
"var pm_run_outside_main_app = null;\n" .
"var dyn_uid = '" . $this->fields["CURRENT_DYNAFORM"] . "';\n" .
"var __DynaformName__ = null;\n" .
2017-05-18 15:20:07 -04:00
"var app_uid = '" . G::decrypt($record['APP_UID'], URL_KEY) . "';\n" .
"var prj_uid = '" . $this->record["PRO_UID"] . "';\n" .
"var step_mode = null;\n" .
2017-10-10 12:33:25 -04:00
"var workspace = '" . config("system.workspace") . "';\n" .
"var credentials = " . G::json_encode($this->credentials) . ";\n" .
"var filePost = '" . $filename . "';\n" .
"var fieldsRequired = " . G::json_encode(array()) . ";\n" .
"var triggerDebug = null;\n" .
"var sysLang = '" . SYS_LANG . "';\n" .
"var isRTL = " . $this->isRTL . ";\n" .
"var pathRTLCss = '" . $this->pathRTLCss . "';\n" .
2017-06-01 15:42:50 -04:00
"var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? G::decrypt($this->fields["DEL_INDEX"], URL_KEY) : "0") . ";\n" .
2016-12-02 14:14:18 -04:00
"var leaveCaseWarning = " . $this->getLeaveCaseWarning() . ";\n" .
$this->getTheStringVariableForGoogleMaps() . "\n" .
"</script>\n" .
"<script type='text/javascript' src='/jscore/cases/core/pmDynaform.js'></script>\n" .
2019-04-26 09:24:15 -04:00
$this->getSessionMessage() .
"<div style='width:100%;padding: 0px 10px 0px 10px;margin:15px 0px 0px 0px;'>\n" .
" <a id='dyn_forward' href='' style='float:right;font-size:12px;line-height:1;margin:0px 5px 1px 0px;'>\n" .
" </a>\n" .
"</div>";
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html');
$file = str_replace("{javascript}", $javascrip, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
echo $file;
exit();
}
2015-07-31 18:59:16 -04:00
public function printPmDynaform($js = "")
2015-02-27 18:10:59 -04:00
{
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
$javascrip = "" .
"<script type='text/javascript'>" .
"var sysLang = '" . SYS_LANG . "';\n" .
"var isRTL = " . $this->isRTL . ";\n" .
"var pathRTLCss = '" . $this->pathRTLCss . "';\n" .
2016-08-25 15:56:48 -04:00
"var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "0") . ";\n" .
"var jsonData = " . $this->json_encode($json) . ";\n" .
2017-08-14 16:13:46 -04:00
"var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";\n" .
2016-12-02 14:14:18 -04:00
"var leaveCaseWarning = " . $this->getLeaveCaseWarning() . ";\n" .
$this->getTheStringVariableForGoogleMaps() . "\n" .
2015-07-31 18:59:16 -04:00
$js .
2015-02-27 18:10:59 -04:00
"</script>";
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html');
$file = str_replace("{javascript}", $javascrip, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
echo $file;
2015-02-18 09:50:29 -04:00
exit();
}
2019-02-13 15:53:21 -04:00
/**
* Print PmDynaform for Action by Email.
*
* @param array $record
* @return string
*
* @see ActionsByEmailCoreClass->sendActionsByEmail()
* @link https://wiki.processmaker.com/3.3/Actions_by_Email
*/
public function printPmDynaformAbe($record)
{
2019-02-13 15:53:21 -04:00
if (ob_get_length() > 0) {
ob_clean();
}
$this->record = $record;
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
2015-12-08 11:24:21 -04:00
$currentDynaform = (isset($this->fields['CURRENT_DYNAFORM']) && $this->fields['CURRENT_DYNAFORM'] != '') ? $this->fields['CURRENT_DYNAFORM'] : '';
$javascrip = "" .
"<script type='text/javascript'>\n" .
"var jsondata = " . G::json_encode($json) . ";\n" .
2017-08-14 16:13:46 -04:00
"var httpServerHostname = \"" . System::getHttpServerHostnameRequestsFrontEnd() . "\";\n" .
"var pm_run_outside_main_app = null;\n" .
"var dyn_uid = '" . $currentDynaform . "';\n" .
"var __DynaformName__ = null;\n" .
"var app_uid = null;\n" .
"var prj_uid = '" . $this->record["PRO_UID"] . "';\n" .
"var step_mode = null;\n" .
2017-10-10 12:33:25 -04:00
"var workspace = '" . config("system.workspace") . "';\n" .
"var credentials = " . G::json_encode($this->credentials) . ";\n" .
"var fieldsRequired = " . G::json_encode(array()) . ";\n" .
"var triggerDebug = null;\n" .
"var sysLang = '" . SYS_LANG . "';\n" .
"var isRTL = " . $this->isRTL . ";\n" .
"var pathRTLCss = '" . $this->pathRTLCss . "';\n" .
2016-08-13 10:12:54 -04:00
"var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "0") . ";\n" .
2016-12-02 14:14:18 -04:00
"var leaveCaseWarning = " . $this->getLeaveCaseWarning() . ";\n" .
$this->getTheStringVariableForGoogleMaps() . "\n" .
"</script>\n" .
"<script type='text/javascript' src='/jscore/cases/core/pmDynaform.js'></script>\n" .
"<div style='width:100%;padding: 0px 10px 0px 10px;margin:15px 0px 0px 0px;'>\n" .
"</div>";
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html');
$file = str_replace("{javascript}", $javascrip, $file);
2015-09-25 19:55:26 -04:00
$file = str_replace("{sys_skin}", SYS_SKIN, $file);
return $file;
}
2015-12-04 17:31:37 -04:00
public function synchronizeSubDynaform()
{
if (!isset($this->record["DYN_CONTENT"])) {
return;
}
$json = G::json_decode($this->record["DYN_CONTENT"]);
foreach ($this->records as $ri) {
$jsonSearch = $this->jsonsf($json, $ri["DYN_UID"], "id");
if ($jsonSearch === null) {
continue;
}
$jsonUpdate = G::json_decode($ri["DYN_CONTENT"]);
$jsonUpdate = $jsonUpdate->items[0];
$jsonUpdate->colSpan = $jsonSearch->colSpan;
2016-01-25 17:46:55 -04:00
$jsonUpdate->mode = $jsonSearch->mode;
2015-12-04 17:31:37 -04:00
$this->jsonReplace($json, $ri["DYN_UID"], "id", $jsonUpdate);
}
$this->record["DYN_CONTENT"] = G::json_encode($json);
}
private function jsonReplace(&$json, $id, $for = "id", $update)
{
foreach ($json as $key => &$value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$this->jsonReplace($value, $id, $for, $update);
}
if (!$sw1 && !$sw2) {
if ($key === $for && $id === $value) {
$json = $update;
}
}
}
}
2015-03-31 16:33:28 -04:00
public function synchronizeVariable($processUid, $newVariable, $oldVariable)
{
$criteria = new Criteria("workflow");
$criteria->addSelectColumn(DynaformPeer::DYN_UID);
$criteria->addSelectColumn(DynaformPeer::DYN_CONTENT);
$criteria->add(DynaformPeer::PRO_UID, $processUid, Criteria::EQUAL);
$rsCriteria = DynaformPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$aRow = $rsCriteria->getRow();
$json = G::json_decode($aRow['DYN_CONTENT']);
$this->jsons($json, $newVariable, $oldVariable);
$json2 = G::json_encode($json);
//update dynaform
if ($json2 !== $aRow['DYN_CONTENT']) {
$con = Propel::getConnection(DynaformPeer::DATABASE_NAME);
$con->begin();
$oPro = DynaformPeer::retrieveByPk($aRow["DYN_UID"]);
$oPro->setDynContent($json2);
$oPro->save();
$con->commit();
}
}
}
private function jsons(&$json, $newVariable, $oldVariable)
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$this->jsons($value, $newVariable, $oldVariable);
}
if (!$sw1 && !$sw2) {
if ($key === "variable" && $json->variable === $oldVariable["VAR_NAME"]) {
$json->variable = $newVariable["VAR_NAME"];
2017-12-04 13:25:35 +00:00
if (isset($json->dataType)) {
2015-03-31 16:33:28 -04:00
$json->dataType = $newVariable["VAR_FIELD_TYPE"];
2017-12-04 13:25:35 +00:00
}
if (isset($json->name)) {
2015-03-31 16:33:28 -04:00
$json->name = $newVariable["VAR_NAME"];
2017-12-04 13:25:35 +00:00
}
if (isset($json->dbConnection) && $json->dbConnection === $oldVariable["VAR_DBCONNECTION"]) {
2015-03-31 16:33:28 -04:00
$json->dbConnection = $newVariable["VAR_DBCONNECTION"];
2017-12-04 13:25:35 +00:00
}
if (isset($json->dbConnectionLabel) && $json->dbConnectionLabel === $oldVariable["VAR_DBCONNECTION_LABEL"]) {
2015-04-17 13:51:47 -04:00
$json->dbConnectionLabel = $newVariable["VAR_DBCONNECTION_LABEL"];
2017-12-04 13:25:35 +00:00
}
if (isset($json->sql) && $json->sql === $oldVariable["VAR_SQL"]) {
2015-03-31 16:33:28 -04:00
$json->sql = $newVariable["VAR_SQL"];
2017-12-04 13:25:35 +00:00
}
2015-03-31 16:33:28 -04:00
if (isset($json->options) && G::json_encode($json->options) === $oldVariable["VAR_ACCEPTED_VALUES"]) {
$json->options = G::json_decode($newVariable["VAR_ACCEPTED_VALUES"]);
}
}
2015-11-17 11:54:06 -04:00
//update variable
if ($key === "var_name" && $json->var_uid === $oldVariable["VAR_UID"]) {
$json->var_name = $newVariable["VAR_NAME"];
}
if ($key === "var_field_type" && $json->var_uid === $oldVariable["VAR_UID"]) {
$json->var_field_type = $newVariable["VAR_FIELD_TYPE"];
}
if ($key === "var_dbconnection" && $json->var_uid === $oldVariable["VAR_UID"]) {
$json->var_dbconnection = $newVariable["VAR_DBCONNECTION"];
}
if ($key === "var_dbconnection_label" && $json->var_uid === $oldVariable["VAR_UID"]) {
$json->var_dbconnection_label = $newVariable["VAR_DBCONNECTION_LABEL"];
}
if ($key === "var_sql" && $json->var_uid === $oldVariable["VAR_UID"]) {
$json->var_sql = $newVariable["VAR_SQL"];
}
if ($key === "var_accepted_values" && $json->var_uid === $oldVariable["VAR_UID"]) {
$json->var_accepted_values = G::json_decode($newVariable["VAR_ACCEPTED_VALUES"]);
}
2015-03-31 16:33:28 -04:00
}
}
}
2018-11-06 15:43:32 -04:00
/**
* Sync JSON definition of the Forms with Input Document information
* in all forms from a process
*
* @param string $processUid
* @param array $inputDocument
*/
2015-10-05 12:12:58 -04:00
public function synchronizeInputDocument($processUid, $inputDocument)
{
2018-11-06 15:43:32 -04:00
$criteria = new Criteria('workflow');
2015-10-05 12:12:58 -04:00
$criteria->addSelectColumn(DynaformPeer::DYN_UID);
$criteria->addSelectColumn(DynaformPeer::DYN_CONTENT);
$criteria->add(DynaformPeer::PRO_UID, $processUid, Criteria::EQUAL);
2018-11-06 15:43:32 -04:00
// Only select the forms with an input document related to a field
$criteria->add(DynaformPeer::DYN_CONTENT, '%"sizeUnity":%', Criteria::LIKE);
2015-10-05 12:12:58 -04:00
$rsCriteria = DynaformPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$aRow = $rsCriteria->getRow();
$json = G::json_decode($aRow['DYN_CONTENT']);
$this->jsonsid($json, $inputDocument);
$json2 = G::json_encode($json);
//update dynaform
if ($json2 !== $aRow['DYN_CONTENT']) {
$con = Propel::getConnection(DynaformPeer::DATABASE_NAME);
$con->begin();
2018-11-06 15:43:32 -04:00
$oPro = DynaformPeer::retrieveByPk($aRow['DYN_UID']);
2015-10-05 12:12:58 -04:00
$oPro->setDynContent($json2);
$oPro->save();
$con->commit();
}
}
}
2018-11-06 15:43:32 -04:00
/**
* Replace values from an Input Document related to the form,
* for fields of type "file" and "multipleFile"
*
* @param object $json
* @param array $inputDocument
*/
2015-10-05 12:12:58 -04:00
private function jsonsid(&$json, $inputDocument)
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$this->jsonsid($value, $inputDocument);
}
if (!$sw1 && !$sw2) {
2018-11-06 15:43:32 -04:00
if ($key === "type" && ($json->type === "file" || $json->type === "multipleFile") && isset($json->inp_doc_uid)) {
if ($json->inp_doc_uid === $inputDocument["INP_DOC_UID"]) {
2015-10-05 12:12:58 -04:00
if (isset($json->size)) {
$json->size = $inputDocument["INP_DOC_MAX_FILESIZE"];
}
if (isset($json->sizeUnity)) {
$json->sizeUnity = $inputDocument["INP_DOC_MAX_FILESIZE_UNIT"];
}
if (isset($json->extensions)) {
$json->extensions = $inputDocument["INP_DOC_TYPE_FILE"];
}
}
2018-11-06 15:43:32 -04:00
} else if ($key === "type" && $json->type === "grid" && !empty($json->columns)) {
$this->jsonsid($json->columns, $inputDocument);
2015-10-05 12:12:58 -04:00
}
}
}
}
2019-05-15 20:20:24 -04:00
/**
* Verify the use of the variable in all the forms of the process.
*
* @param string $processUid
* @param string $variable
* @return boolean | string
*
* @see ProcessMaker\BusinessModel\Variable->delete()
* @link https://wiki.processmaker.com/3.2/Variables#Managing_Variables
*/
2015-03-31 16:33:28 -04:00
public function isUsed($processUid, $variable)
{
2019-05-15 20:20:24 -04:00
$result = ModelDynaform::getByProUid($processUid);
if (empty($result)) {
return false;
}
foreach ($result as $row) {
2020-04-17 09:53:10 -04:00
$json = G::json_decode($row->DYN_CONTENT);
2015-03-31 16:33:28 -04:00
if ($this->jsoni($json, $variable)) {
2019-05-15 20:20:24 -04:00
return $row->DYN_UID;
2015-03-31 16:33:28 -04:00
}
}
return false;
}
private function jsoni(&$json, $variable)
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
if ($this->jsoni($value, $variable)) {
return true;
}
}
if (!$sw1 && !$sw2) {
if ($key === "variable" && $json->variable === $variable["var_name"]) {
return true;
}
}
}
return false;
}
2019-09-18 15:27:26 -04:00
/**
* This funtion will get the DYN_CONTENT from the dynaform then
* Get the field and the properties defined, it's considerate the sub-forms
*
* @param string $dynUid
* @param string $fieldId
* @param string $proUid
* @param array $and
2019-09-18 15:27:26 -04:00
* @return object
* @see \ProcessMaker\BusinessModel\Variable::executeSqlControl()
*/
public function searchField($dynUid, $fieldId, $proUid = null, array $and = [])
2015-04-03 14:31:32 -04:00
{
2016-11-08 11:56:50 -04:00
//get pro_uid if empty
2019-09-18 15:27:26 -04:00
if (empty($proUid)) {
2016-11-08 11:56:50 -04:00
$a = new Criteria("workflow");
$a->addSelectColumn(DynaformPeer::PRO_UID);
2019-09-18 15:27:26 -04:00
$a->add(DynaformPeer::DYN_UID, $dynUid, Criteria::EQUAL);
2016-11-08 11:56:50 -04:00
$ds = DynaformPeer::doSelectRS($a);
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$ds->next();
$row = $ds->getRow();
2019-09-18 15:27:26 -04:00
$proUid = $row["PRO_UID"];
2016-11-08 11:56:50 -04:00
}
//get dynaforms
2015-04-03 14:31:32 -04:00
$a = new Criteria("workflow");
2016-11-08 11:56:50 -04:00
$a->addSelectColumn(DynaformPeer::DYN_UID);
2015-04-03 14:31:32 -04:00
$a->addSelectColumn(DynaformPeer::DYN_CONTENT);
2019-09-18 15:27:26 -04:00
$a->add(DynaformPeer::PRO_UID, $proUid, Criteria::EQUAL);
2016-11-08 11:56:50 -04:00
$ds = DynaformPeer::doSelectRS($a);
2015-04-03 14:31:32 -04:00
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2016-10-12 10:16:38 -04:00
2016-11-08 11:56:50 -04:00
$json = new stdClass();
2019-09-18 15:27:26 -04:00
$dynaforms = [];
2016-11-08 11:56:50 -04:00
while ($ds->next()) {
$row = $ds->getRow();
2019-09-18 15:27:26 -04:00
if ($row["DYN_UID"] === $dynUid) {
2016-11-08 11:56:50 -04:00
$json = G::json_decode($row["DYN_CONTENT"]);
} else {
$dynaforms[] = G::json_decode($row["DYN_CONTENT"]);
}
}
//get subforms
$fields = $this->jsonsf2($json, "form", "type");
foreach ($fields as $key => $value) {
if ($json->items[0]->id !== $value->id) {
foreach ($dynaforms as $dynaform) {
if ($value->id === $dynaform->items[0]->id) {
$form = $dynaform->items[0];
$this->jsonReplace($json, $value->id, "id", $form);
}
}
}
}
$this->completeAdditionalHelpInformationOnControls($json);
return $this->jsonsf($json, $fieldId, "id", $and);
2015-04-03 14:31:32 -04:00
}
2016-09-22 12:28:07 -04:00
public function searchFieldByName($dyn_uid, $name)
{
$a = new Criteria("workflow");
$a->addSelectColumn(DynaformPeer::DYN_CONTENT);
$a->add(DynaformPeer::DYN_UID, $dyn_uid, Criteria::EQUAL);
$ds = ProcessPeer::doSelectRS($a);
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$ds->next();
$row = $ds->getRow();
$json = G::json_decode($row["DYN_CONTENT"]);
$this->jsonr($json);
return $this->jsonsf($json, $name, "name");
}
/**
* Replace data field with custom variables.
* @param string $sql
* @param array $data
* @return string
*/
private function replaceDataField(string $sql, array $data): string
{
$textParse = '';
$dbEngine = 'mysql';
$start = 0;
$prefix = '\?';
$pattern = '/\@(?:([' . $prefix . 'Qq\!])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/';
$result = preg_match_all($pattern, $sql, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
for ($r = 0; $result !== false && $r < $result; $r++) {
$dataGlobal = array_merge($this->fieldsAppData, $data);
if (!isset($dataGlobal[$match[2][$r][0]])) {
$dataGlobal[$match[2][$r][0]] = '';
}
if (!is_array($dataGlobal[$match[2][$r][0]])) {
$textParse = $textParse . substr($sql, $start, $match[0][$r][1] - $start);
$start = $match[0][$r][1] + strlen($match[0][$r][0]);
if (($match[1][$r][0] == '?') && (isset($dataGlobal[$match[2][$r][0]]))) {
$textParse = $textParse . $dataGlobal[$match[2][$r][0]];
continue;
}
}
}
$textParse = $textParse . substr($sql, $start);
$sqlResult = G::replaceDataField($textParse, $data, $dbEngine, false);
return $sqlResult;
}
/**
* complete additional help information on controls.
* @param object $json
*/
private function completeAdditionalHelpInformationOnControls(&$json)
2015-04-03 14:31:32 -04:00
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$this->completeAdditionalHelpInformationOnControls($value);
}
if (!$sw1 && !$sw2) {
if ($key === "type" && ($value === "grid")) {
foreach ($json->columns as $column) {
$column->gridName = $json->id;
}
}
}
}
}
/**
* Gets an element within an object that represents the dynaform. Search is
* done by 'id', 'property' and additional filters.
* @param object $json
* @param string $id
* @param string $for
* @param array $and
* @return mixed
*/
private function jsonsf(&$json, string $id, string $for = "id", array $and = [])
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$val = $this->jsonsf($value, $id, $for, $and);
2017-12-04 13:25:35 +00:00
if ($val !== null) {
2015-04-03 14:31:32 -04:00
return $val;
2017-12-04 13:25:35 +00:00
}
2015-04-03 14:31:32 -04:00
}
if (!$sw1 && !$sw2) {
$filter = empty($and);
foreach ($and as $keyAnd => $valueAnd) {
$filter = isset($json->{$keyAnd}) && $json->{$keyAnd} === $valueAnd;
if ($filter === false) {
break;
}
}
if ($key === $for && $id === $value && $filter) {
2015-04-03 14:31:32 -04:00
return $json;
}
}
}
return null;
}
2016-03-08 17:40:43 -04:00
/**
* You obtain an array of elements according to search criteria.
HOR-433 "(WSSO Plugin) Cuando se ingresa al proceso, se..." SOLVED Issue: (WSSO Plugin) Cuando se ingresa al proceso, se puede verificar que no se puede recuperar la data del mismo Cause: Se esta usando el mismo VirtualHost para clientes WEB y REST Solution: Se realizo la implementacion de la nueva directiva "server_hostname_requests_frontend" del "env.ini"; esto para el caso en que se requiera del "feature SSO", tomar nota de lo siguiente: - Habilitar el modulo "mod_headers" de apache (httpd.conf) - Tener configurado un VirtualHost normal para ProcessMaker (pmos.conf) - Para el "feature SSO" se debera crear un 2do VirtualHost con toda la configuracion necesaria para el mismo (pmos.conf), por lo que todos los usuarios que requieran este feature, deberan usar este para acceder por browser - Crear un 3er VirtualHost para las solicitudes del front-end (DESIGNER), en donde se agregara lo siguiente (pmos.conf): <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Content-Type,Depth,User-Agent,X-File-Size,X-Requested-With,If-Modified-Since,X-File-Name,Cache-Control,Authorization" Header set Access-Control-Allow-Methods "OPTIONS,GET,POST,PUT,DELETE" </IfModule> De tal forma que quedara asi: <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Content-Type,Depth,User-Agent,X-File-Size,X-Requested-With,If-Modified-Since,X-File-Name,Cache-Control,Authorization" Header set Access-Control-Allow-Methods "OPTIONS,GET,POST,PUT,DELETE" </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^.*/(.*)$ app.php [QSA,L,NC] </IfModule> - Agregar lo siguiente al archivo "/path/to/processmaker/shared/sites/your-workspace/env.ini" server_hostname_requests_frontend = "{your_server_hostname_requests_frontend}" Donde: - your_server_hostname_requests_frontend, es el nombre del servidor configurado para el front-end (3er VirtualHost), ejemplo: server_hostname_requests_frontend = "192.168.40.72:3017" - Tambien se puede hacer la configuracion en el archivo "/path/to/processmaker/workflow/engine/config/env.ini", considerar que esto afectara a todos lo workspaces creados Note: Todo el desarrollo se lo hizo en un server Windows-Server-2012-R2 con Apache-2.4
2016-03-17 08:45:23 -04:00
*
2016-03-08 17:40:43 -04:00
* @param object $json
* @param string $id
* @param string $for
* @return array
*/
private function jsonsf2(&$json, $id, $for = "id")
{
$result = array();
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$fields = $this->jsonsf2($value, $id, $for);
foreach ($fields as $field) {
$result[] = $field;
}
}
if (!$sw1 && !$sw2) {
if ($key === $for && $id === $value) {
$result[] = $json;
}
}
}
return $result;
}
2015-04-03 14:31:32 -04:00
public function downloadLanguage($dyn_uid, $lang)
{
if ($lang === "en") {
$a = new Criteria("workflow");
$a->addSelectColumn(DynaformPeer::DYN_CONTENT);
$a->add(DynaformPeer::DYN_UID, $dyn_uid, Criteria::EQUAL);
$ds = ProcessPeer::doSelectRS($a);
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$ds->next();
$row = $ds->getRow();
if ($row["DYN_CONTENT"] !== null && $row["DYN_CONTENT"] !== "") {
$json = \G::json_decode($row["DYN_CONTENT"]);
$this->jsonl($json);
}
$string = "";
$string = $string . "msgid \"\"\n";
$string = $string . "msgstr \"\"\n";
$string = $string . "\"Project-Id-Version: PM 4.0.1\\n\"\n";
$string = $string . "\"POT-Creation-Date: \\n\"\n";
$string = $string . "\"PO-Revision-Date: 2010-12-02 11:44+0100 \\n\"\n";
$string = $string . "\"Last-Translator: Colosa<colosa@colosa.com>\\n\"\n";
$string = $string . "\"Language-Team: Colosa Developers Team <developers@colosa.com>\\n\"\n";
$string = $string . "\"MIME-Version: 1.0\\n\"\n";
$string = $string . "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
$string = $string . "\"Content-Transfer_Encoding: 8bit\\n\"\n";
$string = $string . "\"X-Poedit-Language: English\\n\"\n";
$string = $string . "\"X-Poedit-Country: United States\\n\"\n";
$string = $string . "\"X-Poedit-SourceCharset: utf-8\\n\"\n";
$string = $string . "\"Content-Transfer-Encoding: 8bit\\n\"\n";
$string = $string . "\"File-Name: processmaker.en.po\\n\"\n\n";
$n = count($this->dyn_conten_labels);
for ($i = 0; $i < $n; $i++) {
$string = $string . "msgid \"" . $this->dyn_conten_labels[$i] . "\"\n";
$string = $string . "msgstr \"" . $this->dyn_conten_labels[$i] . "\"\n\n";
}
return array("labels" => $string, "lang" => $lang);
} else {
$a = new Criteria("workflow");
$a->addSelectColumn(DynaformPeer::DYN_LABEL);
$a->add(DynaformPeer::DYN_UID, $dyn_uid, Criteria::EQUAL);
$ds = ProcessPeer::doSelectRS($a);
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$ds->next();
$row = $ds->getRow();
$data = G::json_decode($row["DYN_LABEL"]);
$string = "";
$string = $string . "msgid \"\"\n";
$string = $string . "msgstr \"\"\n";
foreach ($data->{$lang} as $key => $value) {
if (is_string($value)) {
$string = $string . "\"" . $key . ": " . $value . "\\n\"\n";
}
}
$string = $string . "\n";
foreach ($data->{$lang}->Labels as $key => $value) {
$string = $string . "msgid \"" . $value->msgid . "\"\n";
$string = $string . "msgstr \"" . $value->msgstr . "\"\n\n";
}
return array("labels" => $string, "lang" => $lang);
}
}
public function uploadLanguage($dyn_uid)
{
if (!isset($_FILES["LANGUAGE"])) {
throw new Exception(G::LoadTranslation("ID_ERROR_UPLOADING_FILENAME"));
}
if (pathinfo($_FILES["LANGUAGE"]["name"], PATHINFO_EXTENSION) != "po") {
throw new Exception(G::LoadTranslation("ID_FILE_UPLOAD_INCORRECT_EXTENSION"));
}
$translation = array();
2015-04-03 14:31:32 -04:00
$i18n = new i18n_PO($_FILES["LANGUAGE"]["tmp_name"]);
$i18n->readInit();
while ($rowTranslation = $i18n->getTranslation()) {
array_push($translation, $rowTranslation);
}
$name = $_FILES["LANGUAGE"]["name"];
$name = explode(".", $name);
if (isset($name[1]) && isset($name[2]) && $name[1] . "." . $name[2] === "en.po") {
return;
}
$content = $i18n->getHeaders();
$content["File-Name"] = $_FILES["LANGUAGE"]["name"];
$content["Labels"] = $translation;
$con = Propel::getConnection(DynaformPeer::DATABASE_NAME);
$con->begin();
$oPro = DynaformPeer::retrieveByPk($dyn_uid);
$dyn_labels = new stdClass();
if ($oPro->getDynLabel() !== null && $oPro->getDynLabel() !== "") {
$dyn_labels = G::json_decode($oPro->getDynLabel());
}
2017-12-04 13:25:35 +00:00
$dyn_labels->{$name[count($name) - 2]} = $content;
2015-04-03 14:31:32 -04:00
$oPro->setDynLabel(G::json_encode($dyn_labels));
$oPro->save();
$con->commit();
}
public function listLanguage($dyn_uid)
{
$list = array();
$a = new Criteria("workflow");
$a->addSelectColumn(DynaformPeer::DYN_LABEL);
$a->add(DynaformPeer::DYN_UID, $dyn_uid, Criteria::EQUAL);
$ds = ProcessPeer::doSelectRS($a);
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$ds->next();
$row = $ds->getRow();
if ($row["DYN_LABEL"] === null || $row["DYN_LABEL"] === "") {
return $list;
}
$dyn_label = \G::json_decode($row["DYN_LABEL"]);
foreach ($dyn_label as $key => $value) {
array_push($list, array(
"Lang" => $key,
"File-Name" => isset($value->{"File-Name"}) ? $value->{"File-Name"} : "",
"Project-Id-Version" => isset($value->{"Project-Id-Version"}) ? $value->{"Project-Id-Version"} : "",
"POT-Creation-Date" => isset($value->{"POT-Creation-Date"}) ? $value->{"POT-Creation-Date"} : "",
"PO-Revision-Date" => isset($value->{"PO-Revision-Date"}) ? $value->{"PO-Revision-Date"} : "",
"Last-Translator" => isset($value->{"Last-Translator"}) ? $value->{"Last-Translator"} : "",
"Language-Team" => isset($value->{"Language-Team"}) ? $value->{"Language-Team"} : "",
"MIME-Version" => isset($value->{"MIME-Version"}) ? $value->{"MIME-Version"} : "",
"Content-Type" => isset($value->{"Content-Type"}) ? $value->{"Content-Type"} : "",
"Content-Transfer_Encoding" => isset($value->{"Content-Transfer_Encoding"}) ? $value->{"Content-Transfer_Encoding"} : "",
"X-Poedit-Language" => isset($value->{"X-Poedit-Language"}) ? $value->{"X-Poedit-Language"} : "",
"X-Poedit-Country" => isset($value->{"X-Poedit-Country"}) ? $value->{"X-Poedit-Country"} : "",
"X-Poedit-SourceCharset" => isset($value->{"X-Poedit-SourceCharset"}) ? $value->{"X-Poedit-SourceCharset"} : "",
"Content-Transfer-Encoding" => isset($value->{"Content-Transfer-Encoding"}) ? $value->{"Content-Transfer-Encoding"} : ""
));
}
return $list;
}
private $dyn_conten_labels = array();
private function jsonl(&$json)
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$this->jsonl($value);
}
if (!$sw1 && !$sw2) {
if ($key === "label") {
array_push($this->dyn_conten_labels, $json->label);
}
2015-04-06 10:23:47 -04:00
if ($key === "hint") {
array_push($this->dyn_conten_labels, $json->hint);
}
if ($key === "placeholder") {
array_push($this->dyn_conten_labels, $json->placeholder);
}
if ($key === "validateMessage") {
array_push($this->dyn_conten_labels, $json->validateMessage);
}
if ($key === "alternateText") {
array_push($this->dyn_conten_labels, $json->alternateText);
}
if ($key === "comment") {
array_push($this->dyn_conten_labels, $json->comment);
}
if ($key === "alt") {
array_push($this->dyn_conten_labels, $json->alt);
}
2015-04-03 14:31:32 -04:00
}
}
}
public function deleteLanguage($dyn_uid, $lang)
{
$con = Propel::getConnection(DynaformPeer::DATABASE_NAME);
$con->begin();
$oPro = DynaformPeer::retrieveByPk($dyn_uid);
$dyn_labels = \G::json_decode($oPro->getDynLabel());
unset($dyn_labels->{$lang});
$oPro->setDynLabel(G::json_encode($dyn_labels));
$oPro->save();
$con->commit();
}
2016-03-07 08:56:49 -04:00
/**
* Remove the posted values that are not in the definition of Dynaform.
2017-11-28 09:43:16 -04:00
*
2016-03-07 08:56:49 -04:00
* @param array $post
2017-11-28 09:43:16 -04:00
*
2016-03-07 08:56:49 -04:00
* @return array
*/
2017-11-28 09:43:16 -04:00
public function validatePost($post = [])
2016-03-07 08:56:49 -04:00
{
2016-03-14 09:22:59 -04:00
$result = array();
$previusFunction = $this->onPropertyRead;
2017-12-04 13:25:35 +00:00
$this->onPropertyRead = function ($json, $key, $value) use (&$post) {
2016-03-14 09:22:59 -04:00
if ($key === "type" && isset($json->variable) && !empty($json->variable)) {
2017-11-29 11:51:24 -04:00
//clears the data in the appData for grids
$isThereIdIntoPost = array_key_exists($json->id, $post);
$isThereIdIntoFields = array_key_exists($json->id, $this->fields);
if ($json->type === 'grid' && !$isThereIdIntoPost && $isThereIdIntoFields) {
2017-11-28 09:43:16 -04:00
$post[$json->variable] = [[]];
}
//validate 'protectedValue' property
2016-03-14 09:22:59 -04:00
if (isset($json->protectedValue) && $json->protectedValue === true) {
2017-11-29 11:51:24 -04:00
if (isset($this->fields[$json->variable])) {
$post[$json->variable] = $this->fields[$json->variable];
2016-03-14 09:22:59 -04:00
}
2017-11-29 11:51:24 -04:00
if (isset($this->fields[$json->variable . "_label"])) {
$post[$json->variable . "_label"] = $this->fields[$json->variable . "_label"];
2016-03-07 08:56:49 -04:00
}
}
2016-03-14 09:22:59 -04:00
//validator data
2017-11-29 11:51:24 -04:00
$validatorClass = ValidatorFactory::createValidatorClass($json->type, $json);
2016-03-14 09:22:59 -04:00
if ($validatorClass !== null) {
$validatorClass->validatePost($post);
}
2016-03-07 08:56:49 -04:00
}
2016-03-14 09:22:59 -04:00
};
$json = G::json_decode($this->record["DYN_CONTENT"]);
$this->jsonr($json);
$this->onPropertyRead = $previusFunction;
2016-03-07 08:56:49 -04:00
return $post;
}
2014-08-29 11:19:14 -04:00
private function clientToken()
{
$client = $this->getClientCredentials();
$authCode = $this->getAuthorizationCode($client);
$request = array(
'grant_type' => 'authorization_code',
'code' => $authCode
);
$server = array(
'REQUEST_METHOD' => 'POST'
);
$headers = array(
"PHP_AUTH_USER" => $client['CLIENT_ID'],
"PHP_AUTH_PW" => $client['CLIENT_SECRET'],
"Content-Type" => "multipart/form-data;",
"Authorization" => "Basic " . base64_encode($client['CLIENT_ID'] . ":" . $client['CLIENT_SECRET'])
);
2014-08-01 13:06:51 -04:00
2014-08-29 11:19:14 -04:00
$request = new \OAuth2\Request(array(), $request, array(), array(), array(), $server, null, $headers);
$oauthServer = new \ProcessMaker\Services\OAuth2\Server();
$response = $oauthServer->getServer()->handleTokenRequest($request);
$clientToken = $response->getParameters();
$clientToken["client_id"] = $client['CLIENT_ID'];
$clientToken["client_secret"] = $client['CLIENT_SECRET'];
return $clientToken;
}
protected $clientId = 'x-pm-local-client';
protected function getClientCredentials()
{
$oauthQuery = new ProcessMaker\Services\OAuth2\PmPdo($this->getDsn());
return $oauthQuery->getClientDetails($this->clientId);
}
protected function getAuthorizationCode($client)
{
\ProcessMaker\Services\OAuth2\Server::setDatabaseSource($this->getDsn());
\ProcessMaker\Services\OAuth2\Server::setPmClientId($client['CLIENT_ID']);
$oauthServer = new \ProcessMaker\Services\OAuth2\Server();
$userId = $_SESSION['USER_LOGGED'];
$authorize = true;
$_GET = array_merge($_GET, array(
'response_type' => 'code',
'client_id' => $client['CLIENT_ID'],
'scope' => implode(' ', $oauthServer->getScope())
));
2016-03-18 12:15:38 -04:00
$response = $oauthServer->postAuthorize($authorize, $userId, true, array('USER_LOGGED' => $_SESSION['USER_LOGGED']));
2014-08-29 11:19:14 -04:00
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40);
return $code;
}
private function getDsn()
{
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
$port = empty($port) ? '' : ";port=$port";
$dsn = DB_ADAPTER . ':host=' . $host . ';dbname=' . DB_NAME . $port;
return array('dsn' => $dsn, 'username' => DB_USER, 'password' => DB_PASS);
}
2016-03-07 18:10:01 -04:00
/**
* Returns the value converted to string if it is not null.
HOR-433 "(WSSO Plugin) Cuando se ingresa al proceso, se..." SOLVED Issue: (WSSO Plugin) Cuando se ingresa al proceso, se puede verificar que no se puede recuperar la data del mismo Cause: Se esta usando el mismo VirtualHost para clientes WEB y REST Solution: Se realizo la implementacion de la nueva directiva "server_hostname_requests_frontend" del "env.ini"; esto para el caso en que se requiera del "feature SSO", tomar nota de lo siguiente: - Habilitar el modulo "mod_headers" de apache (httpd.conf) - Tener configurado un VirtualHost normal para ProcessMaker (pmos.conf) - Para el "feature SSO" se debera crear un 2do VirtualHost con toda la configuracion necesaria para el mismo (pmos.conf), por lo que todos los usuarios que requieran este feature, deberan usar este para acceder por browser - Crear un 3er VirtualHost para las solicitudes del front-end (DESIGNER), en donde se agregara lo siguiente (pmos.conf): <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Content-Type,Depth,User-Agent,X-File-Size,X-Requested-With,If-Modified-Since,X-File-Name,Cache-Control,Authorization" Header set Access-Control-Allow-Methods "OPTIONS,GET,POST,PUT,DELETE" </IfModule> De tal forma que quedara asi: <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Content-Type,Depth,User-Agent,X-File-Size,X-Requested-With,If-Modified-Since,X-File-Name,Cache-Control,Authorization" Header set Access-Control-Allow-Methods "OPTIONS,GET,POST,PUT,DELETE" </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^.*/(.*)$ app.php [QSA,L,NC] </IfModule> - Agregar lo siguiente al archivo "/path/to/processmaker/shared/sites/your-workspace/env.ini" server_hostname_requests_frontend = "{your_server_hostname_requests_frontend}" Donde: - your_server_hostname_requests_frontend, es el nombre del servidor configurado para el front-end (3er VirtualHost), ejemplo: server_hostname_requests_frontend = "192.168.40.72:3017" - Tambien se puede hacer la configuracion en el archivo "/path/to/processmaker/workflow/engine/config/env.ini", considerar que esto afectara a todos lo workspaces creados Note: Todo el desarrollo se lo hizo en un server Windows-Server-2012-R2 con Apache-2.4
2016-03-17 08:45:23 -04:00
*
2016-03-07 18:10:01 -04:00
* @param string $string
* @return string
*/
private function toStringNotNullValues($value)
{
if (is_null($value)) {
return "";
}
return (string) $value;
}
/**
* Get grids and fields
*
* @param mixed $form
* @param bool $flagGridAssocToVar
*
* @return array Return an array, FALSE otherwise
*/
public static function getGridsAndFields($form, $flagGridAssocToVar = true)
{
try {
if (!is_object($form)) {
//This code it runs only in the first call to the method
$object = \ProcessMaker\Util\Common::stringToJson($form);
if ($object !== false) {
$form = $object->items[0];
} else {
return false;
}
}
$arrayGrid = [];
foreach ($form->items as $value) {
foreach ($value as $value2) {
$field = $value2;
if (isset($field->type)) {
switch ($field->type) {
case 'grid':
$flagInsert = ($flagGridAssocToVar)? (isset($field->var_uid) && $field->var_uid != '' && isset($field->variable) && $field->variable != '') : true;
if ($flagInsert) {
$arrayGrid[$field->id] = $field;
}
break;
case 'form':
$arrayGrid = array_merge(
2017-12-04 13:25:35 +00:00
$arrayGrid,
self::getGridsAndFields($field, $flagGridAssocToVar)
);
break;
}
}
}
}
//Return
return $arrayGrid;
} catch (Exception $e) {
throw $e;
}
}
/**
* Returns a string containing the JSON representation of the object
*
* @param object $json The object being encoded
*
* @return string Returns a string
*/
public function json_encode($json)
{
$jsonData = G::json_encode($json);
if ($jsonData === false) {
$jsonLastError = json_last_error();
$jsonLastErrorMsg = json_last_error_msg();
$token = time();
$obj = new stdClass();
$obj->type = 'panel';
$obj->id = '__json_encode_error__';
$obj->content = '
<div style="border: 1px solid #9A3A1F; background: #F7DBCE; color: #8C0000; font:0.9em arial, verdana, helvetica, sans-serif;">
<div style="margin: 0.5em;">
<img src="/images/documents/_log_error.png" alt="" style="margin-right: 0.8em; vertical-align: middle;" />' .
G::LoadTranslation('ID_EXCEPTION_LOG_INTERFAZ', [$token]) .
'</div></div>';
$obj->border = 0;
$json->items[0]->items = [[$obj]];
$jsonData = G::json_encode($json);
//Log
\Bootstrap::registerMonolog(
'RenderDynaForm',
400,
'JSON encoded string error ' . $jsonLastError . ': ' . $jsonLastErrorMsg,
['token' => $token, 'projectUid' => $this->record['PRO_UID'], 'dynaFormUid' => $this->record['DYN_UID']],
2017-10-10 12:33:25 -04:00
config("system.workspace"),
'processmaker.log'
);
}
//Return
return $jsonData;
}
2016-12-02 14:14:18 -04:00
public function getLeaveCaseWarning()
{
return defined("LEAVE_CASE_WARNING") ? LEAVE_CASE_WARNING : 0;
}
2017-03-07 10:43:00 -04:00
/**
* Unset a json property from the following controls: text, textarea, dropdown,
* checkbox, checkgroup, radio, datetime, suggest, hidden, file, grid.
* @param stdClass $json
* @param string $property
* @return void
*/
public function jsonUnsetProperty(&$json, $property)
{
if (empty($json)) {
return;
}
foreach ($json as $key => &$value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$this->jsonUnsetProperty($value, $property);
}
if (!$sw1 && !$sw2) {
if ($key === "type" && (
$value === "text" ||
$value === "textarea" ||
$value === "dropdown" ||
$value === "checkbox" ||
$value === "checkgroup" ||
$value === "radio" ||
$value === "datetime" ||
$value === "suggest" ||
$value === "hidden" ||
$value === "file" ||
2017-12-04 13:25:35 +00:00
$value === "grid"
)) {
2017-03-07 10:43:00 -04:00
if ($value === "grid" && $property === "data") {
$json->{$property} = [];
} else {
unset($json->{$property});
}
}
}
}
}
2017-10-23 15:01:21 -04:00
/**
* Returns an array with the basic fields of the Exception class. It isn't returned any extra fields information
* of any derivated Exception class. This way we have a lightweight version of the exception data that can
* be used when logging the exception, for example.
* @param $e an Exception class derivate
2017-10-24 10:48:01 -04:00
* @param $sql query that was executed when the exception was generated
2017-10-23 15:01:21 -04:00
* @return array
*/
private function basicExceptionData($e, $sql)
2017-10-23 15:01:21 -04:00
{
$result = [];
$result['code'] = $e->getCode();
$result['file'] = $e->getFile();
$result['line'] = $e->getLine();
$result['message'] = $e->getMessage();
$result['nativeQuery'] = $sql;
if (property_exists($e, 'nativeError')) {
$result['nativeError'] = $e->getNativeError();
}
if (property_exists($e, 'userInfo')) {
$result['userInfo'] = $e->getUserInfo();
}
2017-10-23 15:01:21 -04:00
return $result;
}
/**
* Get the string variable for google maps
*
* @return string
*/
private function getTheStringVariableForGoogleMaps()
{
$config = Bootstrap::getSystemConfiguration();
$googleMaps = new stdClass();
$googleMaps->key = $config['google_map_api_key'];
$googleMaps->signature = $config['google_map_signature'];
$result = 'var googleMaps = ' . G::json_encode($googleMaps) . ';';
return $result;
2019-03-13 09:09:42 -04:00
}
/**
* Get last query error.
*
* @return object
* @see ProcessMaker\BusinessModel\Variable->executeSqlControl()
*/
public function getLastQueryError()
{
return $this->lastQueryError;
}
/**
* Clear last query error.
*
* @see ProcessMaker\BusinessModel\Variable->executeSqlControl()
*/
public function clearLastQueryError()
{
$this->lastQueryError = null;
}
2019-05-16 15:54:07 -04:00
2019-04-26 09:24:15 -04:00
/**
* Get session message.
*
* @return string
*
* @see PmDynaform->printEdit()
* @see PmDynaform->printABE()
* @link https://wiki.processmaker.com/3.1/Multiple_File_Uploader#File_Extensions
*/
public function getSessionMessage()
{
$message = "";
if (isset($_SESSION['G_MESSAGE_TYPE']) && isset($_SESSION['G_MESSAGE'])) {
$color = "green";
if ($_SESSION['G_MESSAGE_TYPE'] === "ERROR") {
$color = "red";
}
if ($_SESSION['G_MESSAGE_TYPE'] === "WARNING") {
$color = "#C3C380";
}
if ($_SESSION['G_MESSAGE_TYPE'] === "INFO") {
$color = "green";
}
$message = "<div style='background-color:" . $color . ";color: white;padding: 1px 2px 1px 5px;' class='userGroupTitle'>" . $_SESSION['G_MESSAGE_TYPE'] . ": " . $_SESSION['G_MESSAGE'] . "</div>";
unset($_SESSION['G_MESSAGE_TYPE']);
unset($_SESSION['G_MESSAGE']);
}
return $message;
}
/**
* Get session message for supervisor.
*
* @return string
*
* @see PmDynaform->printEditSupervisor();
* @link https://wiki.processmaker.com/3.1/Multiple_File_Uploader#File_Extensions
*/
public function getSessionMessageForSupervisor()
{
$message = "";
if (isset($_SESSION["G_MESSAGE_TYPE"]) && isset($_SESSION["G_MESSAGE"])) {
$message = "<div style=\"margin: 1.2em; border: 1px solid #3C763D; padding: 0.5em; background: #B2D3B3;\"><strong>" . G::LoadTranslation("ID_INFO") . "</strong>: " . $_SESSION["G_MESSAGE"] . "</div>";
unset($_SESSION["G_MESSAGE_TYPE"]);
unset($_SESSION["G_MESSAGE"]);
}
return $message;
}
2019-05-16 15:54:07 -04:00
/**
* This adds a new definition on the json dynaform
* @param json $json
*
* @link https://wiki.processmaker.com/3.0/Grid_Control
* @see workflow/engine/classes/PmDynaform->jsonr
*/
public function setDataSchema($json, $appDataVariables)
{
foreach ($json->data as $key => $value) {
$columnsData = [];
foreach ($json->columns as $keyData => $valueData) {
foreach ($appDataVariables as $keyAppData => $valueAppData) {
if (array_key_exists($valueData->id, $valueAppData) || array_key_exists($valueData->id . "_label",
$valueAppData) || array_key_exists($valueData->name,
$valueAppData) || array_key_exists($valueData->name . "_label", $valueAppData)) {
array_push($columnsData, ["defined" => true]);
break;
} else {
array_push($columnsData, ["defined" => false]);
break;
}
}
}
$json->dataSchema[$key] = $columnsData;
}
}
/**
* Sets the dependentOptions property for datetime control, if it contains dependent fields.
* @param stdClass $json
* @param array $fields
* @return void
*/
private function setDependentOptionsForDatetime(stdClass &$json, array $fields = []): void
{
if (!isset($json->type)) {
return;
}
if ($json->type !== 'datetime') {
return;
}
$json->dependentOptions = '';
$backup = $this->onAfterPropertyRead;
$properties = [
'defaultDate' => $json->defaultDate,
'minDate' => $json->minDate,
'maxDate' => $json->maxDate
];
$this->onAfterPropertyRead = function(stdClass &$json, $key, $value) use($backup, $properties) {
if (isset($json->type) && $json->type === 'datetime' && $key === "dependentOptions") {
$json->dependentOptions = new stdClass();
foreach ($properties as $property => $value) {
if (is_string($value) && in_array(substr($value, 0, 2), self::$prefixs)) {
$json->dependentOptions->{$property} = $value;
}
}
$this->onAfterPropertyRead = $backup;
}
};
}
2015-03-24 16:15:19 -04:00
}