2014-08-01 13:06:51 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* class.pmDynaform.php
|
|
|
|
|
* Implementing pmDynaform library in the running case.
|
|
|
|
|
*
|
|
|
|
|
* @author Roly Rudy Gutierrez Pinto
|
|
|
|
|
* @package engine.classes
|
|
|
|
|
*/
|
|
|
|
|
class pmDynaform
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static $instance = null;
|
2015-03-12 09:59:19 -04:00
|
|
|
public $fields = null;
|
2014-08-01 13:06:51 -04:00
|
|
|
public $record = null;
|
2015-02-27 18:10:59 -04:00
|
|
|
public $credentials = null;
|
2015-03-24 16:15:19 -04:00
|
|
|
public $lang = null;
|
|
|
|
|
public $langs = null;
|
2014-08-01 13:06:51 -04:00
|
|
|
|
2015-03-31 16:33:28 -04:00
|
|
|
public function __construct($fields = array())
|
2015-02-27 18:10:59 -04:00
|
|
|
{
|
2015-03-12 09:59:19 -04:00
|
|
|
$this->fields = $fields;
|
2015-03-23 22:22:10 -04:00
|
|
|
$this->getDynaform();
|
|
|
|
|
$this->getCredentials();
|
2015-03-12 09:59:19 -04:00
|
|
|
if (isset($this->fields["APP_UID"])) {
|
|
|
|
|
//current
|
2015-02-18 09:50:29 -04:00
|
|
|
$cases = new \ProcessMaker\BusinessModel\Cases();
|
2015-03-12 09:59:19 -04:00
|
|
|
} else {
|
|
|
|
|
//history
|
|
|
|
|
$this->fields["APP_UID"] = null;
|
2015-03-23 22:22:10 -04:00
|
|
|
if (isset($this->fields["APP_DATA"]["DYN_CONTENT_HISTORY"]))
|
|
|
|
|
$this->record["DYN_CONTENT"] = $this->fields["APP_DATA"]["DYN_CONTENT_HISTORY"];
|
2015-02-03 14:40:33 -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;
|
|
|
|
|
}
|
|
|
|
|
$a = new Criteria("workflow");
|
|
|
|
|
$a->addSelectColumn(DynaformPeer::DYN_VERSION);
|
2015-03-24 16:15:19 -04:00
|
|
|
$a->addSelectColumn(DynaformPeer::DYN_LABEL);
|
2014-08-01 13:06:51 -04:00
|
|
|
$a->addSelectColumn(DynaformPeer::DYN_CONTENT);
|
|
|
|
|
$a->addSelectColumn(DynaformPeer::PRO_UID);
|
|
|
|
|
$a->addSelectColumn(DynaformPeer::DYN_UID);
|
2015-03-12 09:59:19 -04:00
|
|
|
$a->add(DynaformPeer::DYN_UID, $this->fields["CURRENT_DYNAFORM"], Criteria::EQUAL);
|
2014-08-01 13:06:51 -04:00
|
|
|
$ds = ProcessPeer::doSelectRS($a);
|
|
|
|
|
$ds->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$ds->next();
|
2015-02-27 18:10:59 -04:00
|
|
|
$row = $ds->getRow();
|
2014-08-01 13:06:51 -04:00
|
|
|
$this->record = isset($row) ? $row : null;
|
2015-03-24 16:15:19 -04:00
|
|
|
$this->langs = ($this->record["DYN_LABEL"] !== "" && $this->record["DYN_LABEL"] !== null) ? G::json_decode($this->record["DYN_LABEL"]) : null;
|
2014-08-01 13:06:51 -04:00
|
|
|
return $this->record;
|
|
|
|
|
}
|
2015-02-27 18:10:59 -04:00
|
|
|
|
|
|
|
|
public function getCredentials()
|
2015-02-03 14:40:33 -04:00
|
|
|
{
|
2015-03-26 15:03:24 -04:00
|
|
|
if (!isset($_SESSION['USER_LOGGED'])) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-27 18:10:59 -04:00
|
|
|
if ($this->credentials != null) {
|
|
|
|
|
return $this->credentials;
|
2015-02-03 14:40:33 -04:00
|
|
|
}
|
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"]
|
|
|
|
|
);
|
|
|
|
|
return $this->credentials;
|
2015-02-03 14:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:10:59 -04:00
|
|
|
public function jsonr(&$json)
|
2015-02-03 14:40:33 -04:00
|
|
|
{
|
2015-02-27 18:10:59 -04:00
|
|
|
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);
|
2015-03-23 22:22:10 -04:00
|
|
|
if (isset($this->fields["APP_DATA"][$triggerValue])) {
|
|
|
|
|
$json->$key = $this->fields["APP_DATA"][$triggerValue];
|
2015-02-03 14:40:33 -04:00
|
|
|
}
|
2015-02-27 18:10:59 -04:00
|
|
|
}
|
|
|
|
|
//query & options
|
2015-03-05 18:14:04 -04:00
|
|
|
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" => ""
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-02-27 18:10:59 -04:00
|
|
|
if (!isset($json->dbConnection))
|
|
|
|
|
$json->dbConnection = "none";
|
|
|
|
|
if (!isset($json->sql))
|
|
|
|
|
$json->sql = "";
|
|
|
|
|
if (!isset($json->options))
|
|
|
|
|
$json->options = array();
|
2015-03-05 18:14:04 -04:00
|
|
|
else {
|
|
|
|
|
//convert stdClass to array
|
2015-03-23 22:22:10 -04:00
|
|
|
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;
|
2015-03-05 18:14:04 -04:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-23 22:22:10 -04:00
|
|
|
if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") {
|
2015-02-27 18:10:59 -04:00
|
|
|
$cnn = Propel::getConnection($json->dbConnection);
|
|
|
|
|
$stmt = $cnn->createStatement();
|
2015-04-03 14:31:32 -04:00
|
|
|
try {
|
|
|
|
|
$rs = $stmt->executeQuery($json->sql, \ResultSet::FETCHMODE_NUM);
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$option = array(
|
|
|
|
|
"label" => isset($row[1]) ? $row[1] : $row[0],
|
|
|
|
|
"value" => $row[0]
|
|
|
|
|
);
|
|
|
|
|
array_push($json->options, $option);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
2015-02-20 12:35:32 -04:00
|
|
|
}
|
2015-03-05 18:14:04 -04:00
|
|
|
}
|
|
|
|
|
if (isset($json->options[0])) {
|
|
|
|
|
$json->data = $json->options[0];
|
2015-02-03 14:40:33 -04:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-03 15:17:43 -04:00
|
|
|
//data
|
2015-03-05 18:14:04 -04:00
|
|
|
if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "suggest" || $value === "dropdown" || $value === "checkbox" || $value === "radio" || $value === "datetime")) {
|
|
|
|
|
$json->data = array(
|
2015-03-23 22:22:10 -04:00
|
|
|
"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)
|
2015-03-05 18:14:04 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ($key === "type" && ($value === "checkbox")) {
|
2015-03-03 15:17:43 -04:00
|
|
|
$json->data = array(
|
2015-03-23 22:22:10 -04:00
|
|
|
"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"] : "[]"
|
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"])) {
|
2015-03-05 18:14:04 -04:00
|
|
|
$oCriteria = new Criteria("workflow");
|
|
|
|
|
$oCriteria->addSelectColumn(AppDocumentPeer::APP_DOC_UID);
|
|
|
|
|
$oCriteria->addSelectColumn(AppDocumentPeer::DOC_VERSION);
|
2015-03-23 22:22:10 -04:00
|
|
|
$oCriteria->add(AppDocumentPeer::APP_UID, $this->fields["APP_DATA"]["APPLICATION"]);
|
2015-03-05 18:14:04 -04:00
|
|
|
$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"]);
|
|
|
|
|
}
|
2015-03-03 15:17:43 -04:00
|
|
|
$json->data = array(
|
2015-03-05 18:14:04 -04:00
|
|
|
"value" => $links,
|
2015-03-23 22:22:10 -04:00
|
|
|
"label" => isset($this->fields["APP_DATA"][$json->name . "_label"]) ? $this->fields["APP_DATA"][$json->name . "_label"] : "[]"
|
2015-03-03 15:17:43 -04:00
|
|
|
);
|
|
|
|
|
}
|
2015-02-27 18:10:59 -04:00
|
|
|
//grid
|
|
|
|
|
if ($key === "type" && ($value === "grid")) {
|
2015-03-23 22:22:10 -04:00
|
|
|
if (isset($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
|
2015-04-04 18:43:24 -04:00
|
|
|
if ($column->type === "text" || $column->type === "textarea" || $column->type === "dropdown" || $column->type === "datetime" || $column->type === "checkbox" || $column->type === "file" || $column->type === "link") {
|
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] : "",
|
|
|
|
|
"label" => isset($row[$column->name . "_label"]) ? $row[$column->name . "_label"] : ""
|
2015-02-27 18:10:59 -04:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
if ($column->type === "suggest") {
|
|
|
|
|
array_push($cells, array(
|
2015-03-02 18:19:55 -04:00
|
|
|
"value" => isset($row[$column->name . "_label"]) ? $row[$column->name . "_label"] : "",
|
|
|
|
|
"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;
|
2015-02-03 14:40:33 -04:00
|
|
|
}
|
2015-02-06 11:11:59 -04:00
|
|
|
}
|
2015-03-24 16:15:19 -04:00
|
|
|
//languages
|
|
|
|
|
if ($this->lang === null && $key === "language" && isset($json->language)) {
|
|
|
|
|
$this->lang = $json->language;
|
|
|
|
|
}
|
|
|
|
|
if ($key === "label" && isset($json->label) && $this->langs !== null && isset($this->langs->{$this->lang})) {
|
|
|
|
|
$langs = $this->langs->{$this->lang}->Labels;
|
|
|
|
|
foreach ($langs as $langsValue) {
|
|
|
|
|
if ($json->label === $langsValue->msgid)
|
|
|
|
|
$json->label = $langsValue->msgstr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($key === "title" && isset($json->title) && $this->langs !== null && isset($this->langs->{$this->lang})) {
|
|
|
|
|
$langs = $this->langs->{$this->lang}->Labels;
|
|
|
|
|
foreach ($langs as $langsValue) {
|
|
|
|
|
if ($json->title === $langsValue->msgid)
|
|
|
|
|
$json->title = $langsValue->msgstr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-03 14:40:33 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-01 13:06:51 -04:00
|
|
|
|
|
|
|
|
public function isResponsive()
|
|
|
|
|
{
|
|
|
|
|
return $this->record != null && $this->record["DYN_VERSION"] == 2 ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-12 09:59:19 -04:00
|
|
|
public function printView()
|
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);
|
|
|
|
|
$javascrip = "" .
|
|
|
|
|
"<script type='text/javascript'>\n" .
|
|
|
|
|
"var jsondata = " . G::json_encode($json) . ";\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" .
|
2015-03-12 09:59:19 -04:00
|
|
|
"var workspace = '" . SYS_SYS . "';\n" .
|
|
|
|
|
"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" .
|
2015-02-27 18:10:59 -04:00
|
|
|
"$(window).load(function () {\n" .
|
|
|
|
|
" var data = jsondata;\n" .
|
2015-03-12 09:59:19 -04:00
|
|
|
" data.items[0].mode = 'disabled';\n" .
|
2015-02-27 18:10:59 -04:00
|
|
|
" window.project = new PMDynaform.core.Project({\n" .
|
|
|
|
|
" data: data,\n" .
|
|
|
|
|
" keys: {\n" .
|
|
|
|
|
" server: location.host,\n" .
|
|
|
|
|
" projectId: prj_uid,\n" .
|
|
|
|
|
" workspace: workspace\n" .
|
|
|
|
|
" },\n" .
|
|
|
|
|
" token: credentials,\n" .
|
|
|
|
|
" submitRest: false\n" .
|
|
|
|
|
" });\n" .
|
|
|
|
|
" $(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);
|
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"] = "";
|
|
|
|
|
}
|
2015-03-02 12:51:29 -04:00
|
|
|
$title = "<table width='100%' align='center'>\n" .
|
|
|
|
|
" <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"] . " " . 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 = " . G::json_encode($json) . ";\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" .
|
|
|
|
|
"var workspace = '" . SYS_SYS . "';\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" .
|
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" .
|
2015-03-12 09:59:19 -04: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;'> \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;'> \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);
|
2014-08-01 13:06:51 -04:00
|
|
|
echo $file;
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 15:36:20 -04:00
|
|
|
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" .
|
|
|
|
|
"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" .
|
|
|
|
|
"var workspace = '" . SYS_SYS . "';\n" .
|
|
|
|
|
"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" .
|
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;'> \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);
|
|
|
|
|
echo $file;
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function printPmDynaform()
|
|
|
|
|
{
|
|
|
|
|
$json = G::json_decode($this->record["DYN_CONTENT"]);
|
|
|
|
|
$this->jsonr($json);
|
|
|
|
|
$javascrip = "" .
|
|
|
|
|
"<script type='text/javascript'>" .
|
|
|
|
|
"var jsonData = " . G::json_encode($json) . ";" .
|
|
|
|
|
"</script>";
|
|
|
|
|
|
|
|
|
|
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/pmdynaform.html');
|
|
|
|
|
$file = str_replace("{javascript}", $javascrip, $file);
|
|
|
|
|
|
2015-02-18 15:36:20 -04:00
|
|
|
echo $file;
|
2015-02-18 09:50:29 -04:00
|
|
|
exit();
|
|
|
|
|
}
|
2015-02-18 15:36:20 -04:00
|
|
|
|
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"];
|
|
|
|
|
if (isset($json->dataType))
|
|
|
|
|
$json->dataType = $newVariable["VAR_FIELD_TYPE"];
|
|
|
|
|
if (isset($json->name))
|
|
|
|
|
$json->name = $newVariable["VAR_NAME"];
|
|
|
|
|
if (isset($json->dbConnection) && $json->dbConnection === $oldVariable["VAR_DBCONNECTION"])
|
|
|
|
|
$json->dbConnection = $newVariable["VAR_DBCONNECTION"];
|
|
|
|
|
if (isset($json->sql) && $json->sql === $oldVariable["VAR_SQL"])
|
|
|
|
|
$json->sql = $newVariable["VAR_SQL"];
|
|
|
|
|
if (isset($json->options) && G::json_encode($json->options) === $oldVariable["VAR_ACCEPTED_VALUES"]) {
|
|
|
|
|
$json->options = G::json_decode($newVariable["VAR_ACCEPTED_VALUES"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isUsed($processUid, $variable)
|
|
|
|
|
{
|
|
|
|
|
$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']);
|
|
|
|
|
if ($this->jsoni($json, $variable)) {
|
|
|
|
|
return $aRow['DYN_UID'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-03 14:31:32 -04:00
|
|
|
public function searchField($dyn_uid, $field_id)
|
|
|
|
|
{
|
|
|
|
|
$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"]);
|
|
|
|
|
return $this->jsonsf($json, $field_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function jsonsf(&$json, $id)
|
|
|
|
|
{
|
|
|
|
|
foreach ($json as $key => $value) {
|
|
|
|
|
$sw1 = is_array($value);
|
|
|
|
|
$sw2 = is_object($value);
|
|
|
|
|
if ($sw1 || $sw2) {
|
|
|
|
|
$val = $this->jsonsf($value, $id);
|
|
|
|
|
if ($val !== null)
|
|
|
|
|
return $val;
|
|
|
|
|
}
|
|
|
|
|
if (!$sw1 && !$sw2) {
|
|
|
|
|
if ($key === "id" && $id === $value) {
|
|
|
|
|
return $json;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
G::LoadSystem('i18n_po');
|
|
|
|
|
$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());
|
|
|
|
|
}
|
|
|
|
|
$dyn_labels->$name[count($name) - 2] = $content;
|
|
|
|
|
|
|
|
|
|
$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") {
|
|
|
|
|
$json->label;
|
|
|
|
|
array_push($this->dyn_conten_labels, $json->label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
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())
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-24 16:15:19 -04:00
|
|
|
}
|