Files
luos/workflow/engine/methods/services/ActionsByEmailDataFormPost.php

182 lines
6.9 KiB
PHP
Raw Normal View History

<?php
if (PMLicensedFeatures
2017-05-30 10:57:29 -04:00
::getSingleton()
->verifyfeature('zLhSk5TeEQrNFI2RXFEVktyUGpnczV1WEJNWVp6cjYxbTU3R29mVXVZNWhZQT0=')) {
$G_PUBLISH = new Publisher();
try {
2017-04-04 09:42:10 -04:00
/**
* $backupSession = serialize($_SESSION);
* This script runs with $ _SESSION ['USER_LOGGED'] = '00000000000000000000000000000001',
* this action enables login as admin if you enter the url 'http://myserver.net/sysworkflow/en/neoclassic/processes/main',
* in the Browser that invoked this script.
* This action ensures that any changes to the session variables required by
* this script do not affect the main session if it exists, for example
* when multiple tabs are open.
* Serialization is used because for object types the simple assignment:
* $backupSession = $ _SESSION will not work because the assignment is by
* reference, eg:
* <?php
* $obj = new stdClass();
2017-04-04 10:07:08 -04:00
* $obj->value = "value";
2017-04-04 09:42:10 -04:00
*
2017-04-04 10:07:08 -04:00
* $a = ["one" => 1, "two" => $obj, "three" => 3];
2017-04-04 09:42:10 -04:00
* $b = $a;
2017-04-04 10:07:08 -04:00
* $a["two"]->value = "modify";
2017-04-04 09:42:10 -04:00
*
* In 'b' is reflected the output of 'a'.
*/
2017-04-03 14:48:51 -04:00
$backupSession = serialize($_SESSION);
2017-05-30 10:57:29 -04:00
if (empty($_GET['APP_UID'])) {
$sw = empty($_REQUEST['APP_UID']);
if (!$sw && !G::verifyUniqueID32($_REQUEST['APP_UID'])) {
$_GET['APP_UID'] = $_REQUEST['APP_UID'];
}
if ($sw) {
throw new Exception('The parameter APP_UID is empty.');
}
}
2016-07-21 13:04:17 -04:00
2017-05-30 10:57:29 -04:00
if (empty($_REQUEST['DEL_INDEX'])) {
throw new Exception('The parameter DEL_INDEX is empty.');
}
2016-07-21 13:04:17 -04:00
2017-05-30 10:57:29 -04:00
if (empty($_REQUEST['ABER'])) {
throw new Exception('The parameter ABER is empty.');
}
2016-07-21 13:04:17 -04:00
2017-05-30 10:57:29 -04:00
$appUid = G::decrypt($_GET['APP_UID'], URL_KEY);
$delIndex = G::decrypt($_REQUEST['DEL_INDEX'], URL_KEY);
$aber = G::decrypt($_REQUEST['ABER'], URL_KEY);
$forms = isset($_REQUEST['form']) ? $_REQUEST['form'] : [];
2016-07-21 13:04:17 -04:00
G::LoadClass('case');
2016-07-21 13:04:17 -04:00
$case = new Cases();
2017-05-30 10:57:29 -04:00
$casesFields = $case->loadCase($appUid, $delIndex);
2016-07-21 13:04:17 -04:00
2017-05-30 10:57:29 -04:00
$casesFields['APP_DATA'] = array_merge($casesFields['APP_DATA'], $forms);
2016-07-21 13:04:17 -04:00
//Get user info
$current_user_uid = null;
2017-05-30 10:57:29 -04:00
$currentUsrName = null;
2016-07-21 13:04:17 -04:00
$criteria = new Criteria("workflow");
2016-07-21 13:04:17 -04:00
$criteria->addSelectColumn(AppDelegationPeer::USR_UID);
2017-05-30 10:57:29 -04:00
$criteria->add(AppDelegationPeer::APP_UID, $appUid);
$criteria->add(AppDelegationPeer::DEL_INDEX, $delIndex);
2016-07-21 13:04:17 -04:00
$rsSQL = AppDelegationPeer::doSelectRS($criteria);
$rsSQL->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2016-07-21 13:04:17 -04:00
while ($rsSQL->next()) {
$row = $rsSQL->getRow();
2016-07-21 13:04:17 -04:00
$current_user_uid = $row["USR_UID"];
}
2016-07-21 13:04:17 -04:00
if ($current_user_uid != null) {
$criteria = new Criteria("workflow");
2016-07-21 13:04:17 -04:00
$criteria->addSelectColumn(UsersPeer::USR_USERNAME);
$criteria->add(UsersPeer::USR_UID, $current_user_uid);
2016-07-21 13:04:17 -04:00
$rsSQL = UsersPeer::doSelectRS($criteria);
$rsSQL->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2016-07-21 13:04:17 -04:00
$rsSQL->next();
2016-07-21 13:04:17 -04:00
$row = $rsSQL->getRow();
$currentUsrName = $row["USR_USERNAME"];
2016-07-21 13:04:17 -04:00
2017-05-30 10:57:29 -04:00
$casesFields["APP_DATA"]["USER_LOGGED"] = $current_user_uid;
$casesFields["APP_DATA"]["USR_USERNAME"] = $currentUsrName;
}
2016-07-21 13:04:17 -04:00
foreach ($casesFields["APP_DATA"] as $index => $value) {
$_SESSION[$index] = $value;
}
2016-07-21 13:04:17 -04:00
//Update case info
2017-05-30 10:57:29 -04:00
$case->updateCase($appUid, $casesFields);
2016-07-21 13:04:17 -04:00
G::LoadClass('wsBase');
2016-07-21 13:04:17 -04:00
$wsBaseInstance = new wsBase();
2017-05-30 10:57:29 -04:00
$result = $wsBaseInstance->derivateCase($casesFields['CURRENT_USER_UID'], $appUid, $delIndex, true);
$code = (is_array($result) ? $result['status_code'] : $result->status_code);
2016-07-21 13:04:17 -04:00
$dataResponses = array();
2017-05-30 10:57:29 -04:00
$dataResponses['ABE_REQ_UID'] = $aber;
$dataResponses['ABE_RES_CLIENT_IP'] = $_SERVER['REMOTE_ADDR'];
2017-05-30 10:57:29 -04:00
$dataResponses['ABE_RES_DATA'] = serialize($forms);
$dataResponses['ABE_RES_STATUS'] = 'PENDING';
$dataResponses['ABE_RES_MESSAGE'] = '';
2016-07-21 13:04:17 -04:00
try {
require_once 'classes/model/AbeResponses.php';
2016-07-21 13:04:17 -04:00
$abeAbeResponsesInstance = new AbeResponses();
$dataResponses['ABE_RES_UID'] = $abeAbeResponsesInstance->createOrUpdate($dataResponses);
} catch (Exception $error) {
throw $error;
}
2016-07-21 13:04:17 -04:00
if ($code == 0) {
//Save Cases Notes
include_once 'utils.php';
2016-07-21 13:04:17 -04:00
2017-05-30 10:57:29 -04:00
$dataAbeRequests = loadAbeRequest($aber);
$dataAbeConfiguration = loadAbeConfiguration($dataAbeRequests['ABE_UID']);
2016-07-21 13:04:17 -04:00
if ($dataAbeConfiguration['ABE_CASE_NOTE_IN_RESPONSE'] == 1) {
$response = new stdclass();
$response->usrUid = $casesFields['APP_DATA']['USER_LOGGED'];
2017-05-30 10:57:29 -04:00
$response->appUid = $appUid;
$response->noteText = "Check the information that was sent for the receiver: " . $dataAbeRequests['ABE_REQ_SENT_TO'];
2016-07-21 13:04:17 -04:00
postNote($response);
}
2016-07-21 13:04:17 -04:00
$dataAbeRequests['ABE_REQ_ANSWERED'] = 1;
$code == 0 ? uploadAbeRequest($dataAbeRequests) : '';
2016-07-21 13:04:17 -04:00
2017-05-30 10:57:29 -04:00
if (isset($_FILES ['form'])) {
if (isset($_FILES["form"]["name"]) && count($_FILES["form"]["name"]) > 0) {
2016-09-20 12:03:48 -04:00
$oInputDocument = new \ProcessMaker\BusinessModel\Cases\InputDocument();
2017-05-30 10:57:29 -04:00
$oInputDocument->uploadFileCase($_FILES, $case, $casesFields, $current_user_uid, $appUid, $delIndex);
}
}
2016-07-21 13:04:17 -04:00
$assign = $result['message'];
$aMessage['MESSAGE'] = '<strong>The information was submitted. Thank you.</strong>';
} else {
throw new Exception('An error occurred while the application was being processed.<br /><br />
2017-05-30 10:57:29 -04:00
Error code: ' . $result->status_code . '<br />
Error message: ' . $result->message . '<br /><br />');
}
2016-07-21 13:04:17 -04:00
// Update
$dataResponses['ABE_RES_STATUS'] = ($code == 0 ? 'SENT' : 'ERROR');
$dataResponses['ABE_RES_MESSAGE'] = ($code == 0 ? '-' : $result->message);
2016-07-21 13:04:17 -04:00
try {
$abeAbeResponsesInstance = new AbeResponses();
$abeAbeResponsesInstance->createOrUpdate($dataResponses);
} catch (Exception $error) {
throw $error;
}
2016-07-21 13:04:17 -04:00
2017-04-03 14:48:51 -04:00
$_SESSION = unserialize($backupSession);
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showInfo', '', $aMessage);
} catch (Exception $error) {
2017-05-30 10:57:29 -04:00
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', array('MESSAGE' => $error->getMessage() . ' Please contact to your system administrator.'));
}
2017-04-03 14:48:51 -04:00
$_SESSION = unserialize($backupSession);
G::RenderPage('publish', 'blank');
}