dyn_uid = $dyn_uid; $this->app_data = $app_data; $this->getDynaform(); $this->getCredentials(); if (isset($app_data["APPLICATION"])) { $cases = new \ProcessMaker\BusinessModel\Cases(); $this->data = $cases->getCaseVariables($app_data["APPLICATION"]); } } 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->dyn_uid, 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->app_data[$triggerValue])) { $json->$key = $this->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 $option = array(); foreach ($json->options as $valueOptions) { array_push($option, array( "value" => $valueOptions->value, "label" => $valueOptions->label )); } $json->options = $option; } if ($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->data[$json->name]) ? $this->data[$json->name] : $json->data["value"], "label" => isset($this->data[$json->name . "_label"]) ? $this->data[$json->name . "_label"] : $json->data["label"] ); } if ($key === "type" && ($value === "checkbox")) { $json->data = array( "value" => isset($this->data[$json->name]) ? $this->data[$json->name] : array(), "label" => isset($this->data[$json->name . "_label"]) ? $this->data[$json->name . "_label"] : "[]" ); } if ($key === "type" && ($value === "file") && isset($this->app_data["APPLICATION"])) { $oCriteria = new Criteria("workflow"); $oCriteria->addSelectColumn(AppDocumentPeer::APP_DOC_UID); $oCriteria->addSelectColumn(AppDocumentPeer::DOC_VERSION); $oCriteria->add(AppDocumentPeer::APP_UID, $this->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->data[$json->name . "_label"]) ? $this->data[$json->name . "_label"] : "[]" ); } //grid if ($key === "type" && ($value === "grid")) { if (isset($this->data[$json->name])) { //rows $rows = $this->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($pm_run_outside_main_app, $application) { ob_clean(); $json = G::json_decode($this->record["DYN_CONTENT"]); $this->jsonr($json); $a = $this->clientToken(); $clientToken = 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"] ); $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($pm_run_outside_main_app, $application, $headData, $step_mode = 'EDIT') { ob_clean(); $json = G::json_decode($this->record["DYN_CONTENT"]); $this->jsonr($json); $title = "\n" . " \n" . " \n" . " \n" . "
" . $headData["CASE"] . " #: " . $headData["APP_NUMBER"] . "     " . $headData["TITLE"] . ": " . $headData["APP_TITLE"] . "
\n"; $javascrip = "" . "\n" . "\n" . "\n" . ($this->app_data["PRO_SHOW_MESSAGE"] === 1 ? '' : $title ) . "
\n" . "  \n" . " \n" . " \n" . "  \n" . " \n" . " Next Step\n" . " \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 printWebEntry($filename) { ob_clean(); $json = G::json_decode($this->record["DYN_CONTENT"]); $this->jsonr($json); $javascrip = "" . "\n" . "\n" . "
\n" . "  \n" . " \n" . " Next Step\n" . " \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 printPmDynaform() { $json = G::json_decode($this->record["DYN_CONTENT"]); $this->jsonr($json); $javascrip = "" . ""; $file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html'); $file = str_replace("{javascript}", $javascrip, $file); echo $file; exit(); } 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']) ); $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()) )); $response = $oauthServer->postAuthorize($authorize, $userId, true); $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); } }