fields = $fields; $this->getDynaform(); $this->getCredentials(); if (isset($this->fields["APP_UID"])) { //current $cases = new \ProcessMaker\BusinessModel\Cases(); } else { //history $this->fields["APP_UID"] = null; if (isset($this->fields["APP_DATA"]["DYN_CONTENT_HISTORY"])) $this->record["DYN_CONTENT"] = $this->fields["APP_DATA"]["DYN_CONTENT_HISTORY"]; } } public function getDynaform() { if ($this->record != null) { return $this->record; } $a = new Criteria("workflow"); $a->addSelectColumn(DynaformPeer::DYN_VERSION); $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 = ProcessPeer::doSelectRS($a); $ds->setFetchmode(ResultSet::FETCHMODE_ASSOC); $ds->next(); $row = $ds->getRow(); $this->record = isset($row) ? $row : null; return $this->record; } public function getCredentials() { if ($this->credentials != null) { 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"] ); return $this->credentials; } public function jsonr(&$json) { foreach ($json as $key => $value) { $sw1 = is_array($value); $sw2 = is_object($value); if ($sw1 || $sw2) { $this->jsonr($value); } if (!$sw1 && !$sw2) { //property $prefixs = array("@@", "@#", "@%", "@?", "@$", "@="); if (is_string($value) && in_array(substr($value, 0, 2), $prefixs)) { $triggerValue = substr($value, 2); if (isset($this->fields["APP_DATA"][$triggerValue])) { $json->$key = $this->fields["APP_DATA"][$triggerValue]; } } //query & options if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "dropdown" || $value === "suggest" || $value === "checkbox" || $value === "radio" || $value === "datetime")) { if (!isset($json->data)) { $json->data = array( "value" => "", "label" => "" ); } if (!isset($json->dbConnection)) $json->dbConnection = "none"; if (!isset($json->sql)) $json->sql = ""; if (!isset($json->options)) $json->options = array(); else { //convert stdClass to array if (is_array($json->options)) { $option = array(); foreach ($json->options as $valueOptions) { array_push($option, array( "value" => $valueOptions->value, "label" => isset($valueOptions->label) ? $valueOptions->label : "" )); } $json->options = $option; } } if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") { $cnn = Propel::getConnection($json->dbConnection); $stmt = $cnn->createStatement(); $rs = $stmt->executeQuery(strtoupper($json->sql), \ResultSet::FETCHMODE_NUM); while ($rs->next()) { $row = $rs->getRow(); $option = array( "label" => $row[1], "value" => $row[0] ); array_push($json->options, $option); } } if (isset($json->options[0])) { $json->data = $json->options[0]; } } //data if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "suggest" || $value === "dropdown" || $value === "checkbox" || $value === "radio" || $value === "datetime")) { $json->data = array( "value" => isset($this->fields["APP_DATA"][$json->name]) ? $this->fields["APP_DATA"][$json->name] : (is_array($json->data) ? $json->data["value"] : $json->data->value), "label" => isset($this->fields["APP_DATA"][$json->name . "_label"]) ? $this->fields["APP_DATA"][$json->name . "_label"] : (is_array($json->data) ? $json->data["label"] : $json->data->label) ); } if ($key === "type" && ($value === "checkbox")) { $json->data = array( "value" => isset($this->fields["APP_DATA"][$json->name]) ? $this->fields["APP_DATA"][$json->name] : array(), "label" => isset($this->fields["APP_DATA"][$json->name . "_label"]) ? $this->fields["APP_DATA"][$json->name . "_label"] : "[]" ); } if ($key === "type" && ($value === "file") && isset($this->fields["APP_DATA"]["APPLICATION"])) { $oCriteria = new Criteria("workflow"); $oCriteria->addSelectColumn(AppDocumentPeer::APP_DOC_UID); $oCriteria->addSelectColumn(AppDocumentPeer::DOC_VERSION); $oCriteria->add(AppDocumentPeer::APP_UID, $this->fields["APP_DATA"]["APPLICATION"]); $oCriteria->add(AppDocumentPeer::APP_DOC_FIELDNAME, $json->name); $rs = AppDocumentPeer::doSelectRS($oCriteria); $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); $links = array(); while ($rs->next()) { $row = $rs->getRow(); array_push($links, "../cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"]); } $json->data = array( "value" => $links, "label" => isset($this->fields["APP_DATA"][$json->name . "_label"]) ? $this->fields["APP_DATA"][$json->name . "_label"] : "[]" ); } //grid if ($key === "type" && ($value === "grid")) { if (isset($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 === "checkbox" || $column->type === "text" || $column->type === "textarea" || $column->type === "dropdown" || $column->type === "datetime") { array_push($cells, array( "value" => isset($row[$column->name]) ? $row[$column->name] : "", "label" => isset($row[$column->name . "_label"]) ? $row[$column->name . "_label"] : "" )); } if ($column->type === "suggest") { array_push($cells, array( "value" => isset($row[$column->name . "_label"]) ? $row[$column->name . "_label"] : "", "label" => isset($row[$column->name]) ? $row[$column->name] : "" )); } } $rows[$keyRow] = $cells; } $json->rows = count($rows); $json->data = $rows; } } } } } public function isResponsive() { return $this->record != null && $this->record["DYN_VERSION"] == 2 ? true : false; } public function printView() { ob_clean(); $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); 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"] = ""; } $title = "
| " . 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" .
"