sysSys = (defined("SYS_SYS")) ? SYS_SYS : "Undefined"; $this->context = \Bootstrap::getDefaultContextLog(); $this->dataSources = array("database", "dataVariable"); $this->pathRTLCss = '/lib/pmdynaform/build/css/PMDynaform-rtl.css'; $this->serverConf = &serverConf::getSingleton(); $this->isRTL = ($this->serverConf->isRtl(SYS_LANG)) ? 'true' : 'false'; $this->fields = $fields; $this->propertiesToExclude = array('dataVariable'); $this->getDynaform(); $this->getDynaforms(); $this->synchronizeSubDynaform(); $this->getCredentials(); if (is_array($this->fields) && !isset($this->fields["APP_UID"])) { $this->fields["APP_UID"] = null; } if (isset($this->fields["APP_DATA"]["DYN_CONTENT_HISTORY"])) { $decode = base64_decode($this->fields["APP_DATA"]["DYN_CONTENT_HISTORY"], true); if ($decode !== false) { $this->record["DYN_CONTENT"] = $decode; } } //todo: compatibility checkbox 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); } $this->record["DYN_CONTENT"] = G::json_encode($json); } } public function getDynaformTitle($idDynaform) { $d = new Dynaform(); $d->setDynUid($idDynaform); $titleDynaform = $d->getDynTitle(); return $titleDynaform; } public function getDynaform() { if (!isset($this->fields["CURRENT_DYNAFORM"])) { return; } if ($this->record != null) { return $this->record; } $a = new Criteria("workflow"); $a->addSelectColumn(DynaformPeer::DYN_VERSION); $a->addSelectColumn(DynaformPeer::DYN_LABEL); $a->addSelectColumn(DynaformPeer::DYN_CONTENT); $a->addSelectColumn(DynaformPeer::PRO_UID); $a->addSelectColumn(DynaformPeer::DYN_UID); $a->add(DynaformPeer::DYN_UID, $this->fields["CURRENT_DYNAFORM"], Criteria::EQUAL); $ds = DynaformPeer::doSelectRS($a); $ds->setFetchmode(ResultSet::FETCHMODE_ASSOC); $ds->next(); $row = $ds->getRow(); $this->record = isset($row) ? $row : null; $this->langs = ($this->record["DYN_LABEL"] !== "" && $this->record["DYN_LABEL"] !== null) ? G::json_decode($this->record["DYN_LABEL"]) : null; return $this->record; } public function getDynaforms() { if ($this->record === null) { return; } if ($this->records != null) { return $this->records; } $a = new Criteria("workflow"); $a->addSelectColumn(DynaformPeer::DYN_UPDATE_DATE); $a->addSelectColumn(DynaformPeer::DYN_VERSION); $a->addSelectColumn(DynaformPeer::DYN_LABEL); $a->addSelectColumn(DynaformPeer::DYN_CONTENT); $a->addSelectColumn(DynaformPeer::PRO_UID); $a->addSelectColumn(DynaformPeer::DYN_UID); $a->add(DynaformPeer::PRO_UID, $this->record["PRO_UID"], Criteria::EQUAL); $a->add(DynaformPeer::DYN_UID, $this->record["DYN_UID"], Criteria::NOT_EQUAL); $ds = DynaformPeer::doSelectRS($a); $ds->setFetchmode(ResultSet::FETCHMODE_ASSOC); $this->records = array(); while ($ds->next()) { array_push($this->records, $ds->getRow()); } return $this->records; } public function getCredentials() { $flagTrackerUser = false; if (!isset($_SESSION['USER_LOGGED'])) { 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"]) ) { return; } $_SESSION["USER_LOGGED"] = "00000000000000000000000000000001"; $flagTrackerUser = true; } if ($this->credentials != null) { return $this->credentials; } 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"]; return $this->credentials; } } $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"] ); if ($flagTrackerUser) { unset($_SESSION["USER_LOGGED"]); } $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)); return $this->credentials; } public function jsonr(&$json, $clearCache = true) { if ($clearCache === true) { $this->cache = []; } if (empty($json)) { return; } $dataGridEnvironment = []; foreach ($json as $key => &$value) { $sw1 = is_array($value); $sw2 = is_object($value); if ($sw1 || $sw2) { $this->jsonr($value, false); } if (!$sw1 && !$sw2) { //read event $fn = $this->onPropertyRead; if (is_callable($fn) || function_exists($fn)) { $fn($json, $key, $value); } //set properties from trigger if (is_string($value) && in_array(substr($value, 0, 2), self::$prefixs)) { $triggerValue = substr($value, 2); if (isset($this->fields["APP_DATA"][$triggerValue])) { if (!in_array($key, $this->propertiesToExclude)) { $json->{$key} = $this->fields["APP_DATA"][$triggerValue]; } } else { if (!in_array($key, $this->propertiesToExclude)) { $json->{$key} = ""; } } } //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; } } } } } //options & query options if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "hidden" || $value === "dropdown" || $value === "checkgroup" || $value === "radio" || $value === "suggest")) { if (!isset($json->dbConnection)) { $json->dbConnection = "none"; } if (!isset($json->sql)) { $json->sql = ""; } if (!isset($json->datasource)) { $json->datasource = "database"; } if (!in_array($json->datasource, $this->dataSources)) { $json->datasource = "database"; } $json->optionsSql = array(); if ($json->datasource === "database" && $json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") { if (isset($json->queryField)) { $dtFields = $json->queryInputData; } else { $dtFields = $this->getValuesDependentFields($json); foreach ($dtFields as $keyF => $valueF) { if (isset($this->fields["APP_DATA"][$keyF])) { $dtFields[$keyF] = $this->fields["APP_DATA"][$keyF]; } } } $sql = G::replaceDataField($json->sql, $dtFields); if ($value === "suggest") { $sql = $this->sqlParse($sql, function($parsed, &$select, &$from, &$where, &$groupBy, &$having, &$orderBy, &$limit) use ($json) { $dt = $parsed["SELECT"]; $isWhere = empty($where); if ($isWhere === false) { $where = substr_replace($where, " (", 5, 0) . ")"; } if (!isset($json->queryField) && isset($dt[0]["base_expr"])) { $col = $dt[0]["base_expr"]; $dv = str_replace("'", "''", $json->defaultValue); if ($dv !== "") { $where = $isWhere ? "WHERE " . $col . "='" . $dv . "'" : $where . " AND " . $col . "='" . $dv . "'"; } } if (isset($json->queryField) && isset($dt[0]["base_expr"])) { $col = isset($dt[1]["base_expr"]) ? $dt[1]["base_expr"] : $dt[0]["base_expr"]; $qf = str_replace("'", "''", $json->queryFilter); $where = $isWhere ? "WHERE " . $col . " LIKE '%" . $qf . "%'" : $where . " AND " . $col . " LIKE '%" . $qf . "%'"; } $provider = $this->getDatabaseProvider($json->dbConnection); $start = 0; $end = 10; if (isset($json->queryStart)) { $start = $json->queryStart; } if (isset($json->queryLimit)) { $end = $json->queryLimit; } if (empty($limit) && $provider === "mysql") { $limit = "LIMIT " . $start . "," . $end . ""; } if (empty($limit) && $provider === "pgsql") { $limit = "OFFSET " . $start . " LIMIT " . $end . ""; } if ($provider === "mssql") { $limit = ""; if (strpos(strtoupper($select), "TOP") === false) { $isDistinct = strpos(strtoupper($select), "DISTINCT"); $isAll = strpos(strtoupper($select), "ALL"); if ($isDistinct === false && $isAll === false) { $select = preg_replace("/SELECT/", "SELECT TOP(" . $end . ")", strtoupper($select), 1); } if ($isDistinct !== false) { $select = preg_replace("/DISTINCT/", "DISTINCT TOP(" . $end . ")", strtoupper($select), 1); } if ($isAll !== false) { $select = preg_replace("/DISTINCT/", "DISTINCT TOP(" . $end . ")", strtoupper($select), 1); } } } if ($provider === "oracle") { $limit = ""; $rowNumber = ""; if (strpos(strtoupper($where), "ROWNUM") === false) { $rowNumber = " AND " . $start . " <= ROWNUM AND ROWNUM <= " . $end; } $where = empty($where) ? "WHERE " . $start . " <= ROWNUM AND ROWNUM <= " . $end : $where . $rowNumber; } }); } $dt = $this->getCacheQueryData($json->dbConnection, $sql, $json->type); foreach ($dt as $row) { $option = new stdClass(); $option->value = isset($row[0]) ? $row[0] : ""; $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(); $option->value = isset($row[0]) ? $row[0] : ""; $option->label = isset($row[1]) ? $row[1] : ""; $json->optionsSql[] = $option; } } if ($value === "suggest" && isset($json->queryField) && $json->queryField == true) { $json->queryOutputData = array(); foreach ($json->optionsSql as $option) { if ($json->queryFilter !== '') { if (stripos($option->label, $json->queryFilter) !== false) { $json->queryOutputData[] = $option; } } else { $json->queryOutputData[] = $option; } } } } } //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; } } 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]; } if (isset($this->fields["APP_DATA"][$json->name . "_label"])) { $json->data->label = $this->fields["APP_DATA"][$json->name . "_label"]; } } 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; } } } 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"]; } } 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; } } 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]; } if (isset($this->fields["APP_DATA"][$json->name . "_label"])) { $json->data->label = $this->fields["APP_DATA"][$json->name . "_label"]; } } if ($key === "type" && ($value === "checkbox")) { $json->data = new stdClass(); $json->data->value = "0"; $json->data->label = ""; 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; } } } if (isset($this->fields["APP_DATA"][$json->name])) { $json->data->value = $this->fields["APP_DATA"][$json->name]; if (is_array($json->data->value) && isset($json->data->value[0])) { $json->data->value = $json->data->value[0]; } 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; } } } } 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); } } } $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]; } if (isset($this->fields["APP_DATA"][$json->name . "_label"])) { $json->data->label = $this->fields["APP_DATA"][$json->name . "_label"]; } } 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]; } if (isset($this->fields["APP_DATA"][$json->name . "_label"])) { $json->data->label = $this->fields["APP_DATA"][$json->name . "_label"]; } } 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); $oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_STATUS, 'ACTIVE'); $oCriteriaAppDocument->addDescendingOrderByColumn(AppDocumentPeer::APP_DOC_CREATE_DATE); $oCriteriaAppDocument->setLimit(1); $rs = AppDocumentPeer::doSelectRS($oCriteriaAppDocument); $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); $rs->next(); $links = array(); $labelsFromDb = array(); $appDocUids = array(); $oAppDocument = new AppDocument(); if ($row = $rs->getRow()) { $oAppDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]); $links[] = "../cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"]; $labelsFromDb[] = $oAppDocument->getAppDocFilename(); $appDocUids[] = $row["APP_DOC_UID"]; } $json->data = new stdClass(); $json->data->value = $links; $json->data->app_doc_uid = $appDocUids; 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] : "[]"); } } if ($key === "type" && ($value === "file") && isset($json->variable)) { //todo $oCriteria = new Criteria("workflow"); $oCriteria->addSelectColumn(ProcessVariablesPeer::INP_DOC_UID); $oCriteria->add(ProcessVariablesPeer::VAR_UID, $json->var_uid); $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"]); } } 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"]; } } //synchronize var_label if ($key === "type" && ($value === "dropdown" || $value === "suggest" || $value === "radio")) { if (isset($this->fields["APP_DATA"]["__VAR_CHANGED__"]) && in_array($json->name, explode(",", $this->fields["APP_DATA"]["__VAR_CHANGED__"]))) { foreach ($json->optionsSql as $io) { if ($this->toStringNotNullValues($json->data->value) === $io->value) { $json->data->label = $io->label; } } foreach ($json->options as $io) { if ($this->toStringNotNullValues($json->data->value) === $io->value) { $json->data->label = $io->label; } } $_SESSION["TRIGGER_DEBUG"]["DATA"][] = Array("key" => $json->name . "_label", "value" => $json->data->label); } } 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(); $dv = array(); if (isset($this->fields["APP_DATA"][$json->name])) $dv = $this->fields["APP_DATA"][$json->name]; if (!is_array($dv)) { $dv = explode(",", $dv); } foreach ($dv as $idv) { foreach ($json->optionsSql as $os) { if ($os->value === $idv) { $dataValue[] = $os->value; $dataLabel[] = $os->label; } } foreach ($json->options as $os) { if ($os->value === $idv) { $dataValue[] = $os->value; $dataLabel[] = $os->label; } } } $json->data->value = $dataValue; $json->data->label = G::json_encode($dataLabel); $_SESSION["TRIGGER_DEBUG"]["DATA"][] = Array("key" => $json->name . "_label", "value" => $json->data->label); } } 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; $_SESSION["TRIGGER_DEBUG"]["DATA"][] = Array("key" => $json->name . "_label", "value" => $json->data->label); } } //clear optionsSql if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "hidden" || $value === "suggest")) { $json->optionsSql = array(); } //grid if ($key === "type" && ($value === "grid")) { $columnsDataVariable = []; //todo compatibility 'columnWidth' foreach ($json->columns as $column) { if (!isset($column->columnWidth) && $column->type !== "hidden") { $json->layout = "static"; $column->columnWidth = ""; } $column->parentIsGrid = true; //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; } } } } //data grid environment $json->dataGridEnvironment = "onDataGridEnvironment"; if (isset($this->fields["APP_DATA"])) { $dataGridEnvironment = $this->fields["APP_DATA"]; $this->fields["APP_DATA"] = []; //restore AppData with dataVariable definition, only for columns control foreach ($columnsDataVariable as $dge) { if (isset($dataGridEnvironment[$dge])) { $this->fields["APP_DATA"][$dge] = $dataGridEnvironment[$dge]; } } } } if ($key === "dataGridEnvironment" && ($value === "onDataGridEnvironment")) { if (isset($this->fields["APP_DATA"])) { $this->fields["APP_DATA"] = $dataGridEnvironment; $dataGridEnvironment = []; } if (isset($this->fields["APP_DATA"][$json->name]) && is_array($this->fields["APP_DATA"][$json->name])) { //rows $rows = $this->fields["APP_DATA"][$json->name]; foreach ($rows as $keyRow => $row) { //cells $cells = array(); foreach ($json->columns as $column) { //data 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") { array_push($cells, array( "value" => isset($row[$column->name]) ? $row[$column->name] : "", "label" => isset($row[$column->name . "_label"]) ? $row[$column->name . "_label"] : (isset($row[$column->name]) ? $row[$column->name] : "") )); } } $rows[$keyRow] = $cells; } $json->rows = count($rows); $json->data = $rows; } } //languages if ($this->lang === null && $key === "language" && isset($json->language)) { $this->lang = $json->language; } if ($this->langs !== null) { if (($key === "label" || $key === "title" || $key === "hint" || $key === "placeholder" || $key === "validateMessage" || $key === "alternateText" || $key === "comment" || $key === "alt") && isset($this->langs->{$this->lang})) { $langs = $this->langs->{$this->lang}->Labels; foreach ($langs as $langsValue) { if (is_object($json) && $json->{$key} === $langsValue->msgid) { $json->{$key} = $langsValue->msgstr; } if (is_array($json) && $json[$key] === $langsValue->msgid) { $json[$key] = $langsValue->msgstr; } } } } //EDIT,VIEW if (isset($this->fields["STEP_MODE"]) && $this->fields["STEP_MODE"] === "VIEW" && isset($json->mode)) { $json->mode = "view"; } if ($this->displayMode !== null && isset($json->mode)) { $json->mode = $this->displayMode; } if ($key === "type" && ($value === "form") && $this->records != null) { foreach ($this->records as $ri) { if ($json->id === $ri["DYN_UID"] && !isset($json->jsonUpdate)) { $jsonUpdate = G::json_decode($ri["DYN_CONTENT"]); $jsonUpdate = $jsonUpdate->items[0]; $jsonUpdate->colSpan = $json->colSpan; $jsonUpdate->mode = $json->mode; $jsonUpdate->jsonUpdate = true; $json = $jsonUpdate; $this->jsonr($json); } } } } } } private function getValuesDependentFields($json) { if (!isset($this->record["DYN_CONTENT"])) { return array(); } $data = array(); if (isset($json->dbConnection) && isset($json->sql)) { $result = array(); preg_match_all('/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $json->sql, $result, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $variables = isset($result[2]) ? $result[2] : array(); foreach ($variables as $key => $value) { $jsonSearch = $this->jsonsf(G::json_decode($this->record["DYN_CONTENT"]), $value[0], $json->variable === "" ? "id" : "variable"); $a = $this->getValuesDependentFields($jsonSearch); foreach ($a as $i => $v) { $data[$i] = $v; } } if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") { if (isset($this->fields["APP_DATA"])) { foreach ($this->fields["APP_DATA"] as $keyA => $valueA) { if (!isset($data[$keyA]) && !is_array($valueA)) { $data[$keyA] = $valueA; } } } $sql = G::replaceDataField($json->sql, $data); $dt = $this->getCacheQueryData($json->dbConnection, $sql, $json->type); $row = isset($dt[0]) ? $dt[0] : []; if (isset($row[0]) && $json->type !== "suggest" && $json->type !== "radio") { $data[$json->variable === "" ? $json->id : $json->variable] = $row[0]; } } } 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 !== "") { $data[$json->variable === "" ? $json->id : $json->variable] = ""; } if (isset($json->defaultValue) && $json->defaultValue !== "") { $data[$json->variable === "" ? $json->id : $json->variable] = $json->defaultValue; } return $data; } 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; \Bootstrap::registerMonolog("sqlExecution", 400, "Sql Execution", $this->context, $this->sysSys, "processmaker.log"); } return $data; } public function getDatabaseProvider($dbConnection) { 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": if (strpos($sAlias, $sBaseExpr, 0) != 0) { $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) { $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"]) . " " . $dt[$key]["ref_type"] . " " . $dt[$key]["ref_clause"]; } } } $from = trim($from); $where = ""; if (!empty($parsed["WHERE"])) { $where = "WHERE "; $dt = ($parsed['WHERE'][0]['expr_type'] == 'expression') ? $parsed['WHERE'][0]['sub_tree'] : $parsed["WHERE"]; $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) { $groupBy .= $value["base_expr"] . ", "; } $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) { $orderBy .= $value["base_expr"] . ", "; } $orderBy = rtrim($orderBy, ", "); $orderBy .= " " . $value["direction"]; } $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; } public function isResponsive() { return $this->record != null && $this->record["DYN_VERSION"] == 2 ? true : false; } public function printTracker() { ob_clean(); $this->fields["STEP_MODE"] = "VIEW"; $json = G::json_decode($this->record["DYN_CONTENT"]); foreach ($json->items[0]->items as $key => $value) { $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 = "
"; $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); $file = str_replace("{sys_skin}", SYS_SKIN, $file); echo $file; exit(0); } public function printView() { ob_clean(); $this->displayMode = "disabled"; $json = G::json_decode($this->record["DYN_CONTENT"]); $this->jsonr($json); $javascrip = "" . "\n"; $file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html'); $file = str_replace("{javascript}", $javascrip, $file); $file = str_replace("{sys_skin}", SYS_SKIN, $file); echo $file; exit(); } public function printEdit() { ob_clean(); $json = G::json_decode($this->record["DYN_CONTENT"]); $this->jsonr($json); if (!isset($this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["PREVIOUS_STEP"])) { $this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["PREVIOUS_STEP"] = ""; } $msg = ""; 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"; $msg = "| " . G::LoadTranslation('ID_CASE') . " #: " . $this->fields["APP_NUMBER"] . " " . G::LoadTranslation('ID_TITLE') . ": " . $this->fields["APP_TITLE"] . " | \n" . "
\n" .
" \n" .
" " . $this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["PREVIOUS_STEP_LABEL"] . "" .
" \n" .
"
\n" .
" \n" .
" " . $this->fields["APP_DATA"]["__DYNAFORM_OPTIONS"]["NEXT_STEP_LABEL"] . "" .
" \n" .
"
\n" .
" \n" .
" Next Step\n" .
" \n" .
"
' .
G::LoadTranslation('ID_EXCEPTION_LOG_INTERFAZ', [$token]) .
'