Files
luos/workflow/engine/classes/WsBase.php

3564 lines
123 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
use App\Jobs\EmailEvent;
2019-12-02 15:32:41 -04:00
use Illuminate\Support\Facades\Crypt;
2020-06-12 21:07:20 -04:00
use ProcessMaker\BusinessModel\Cases as BmCases;
2021-04-30 09:17:09 -04:00
use ProcessMaker\BusinessModel\Cases\Unassigned;
2018-04-04 09:21:59 -04:00
use ProcessMaker\BusinessModel\EmailServer;
2018-06-11 09:58:48 -04:00
/*----------------------------------********---------------------------------*/
2018-06-04 12:33:56 -04:00
use ProcessMaker\ChangeLog\ChangeLog;
2018-06-11 09:58:48 -04:00
/*----------------------------------********---------------------------------*/
use ProcessMaker\Core\JobsManager;
2018-06-04 12:33:56 -04:00
use ProcessMaker\Core\System;
2021-09-30 12:30:00 -04:00
use ProcessMaker\Model\Application;
2019-09-10 15:29:00 -04:00
use ProcessMaker\Model\Delegation;
2017-08-11 14:10:44 -04:00
class WsBase
{
2019-03-29 10:00:39 -04:00
const MESSAGE_TYPE_ACTIONS_BY_EMAIL = 'ACTIONS_BY_EMAIL';
const MESSAGE_TYPE_CASE_NOTE = 'CASE_NOTE';
const MESSAGE_TYPE_EMAIL_EVENT = 'EVENT';
const MESSAGE_TYPE_EXTERNAL_REGISTRATION = 'EXTERNAL_REGISTRATION';
const MESSAGE_TYPE_PM_FUNCTION = 'PM_FUNCTION';
const MESSAGE_TYPE_RETRIEVE_PASSWORD = 'RETRIEVE_PASSWORD';
const MESSAGE_TYPE_SOAP = 'SOAP';
const MESSAGE_TYPE_TASK_NOTIFICATION = 'ROUTING';
const MESSAGE_TYPE_TEST_EMAIL = 'TEST';
public $stored_system_variables; //boolean
public $wsSessionId; //web service session id, if the wsbase function is used from a WS request
2019-03-29 10:00:39 -04:00
private $taskId;
2019-01-30 09:11:57 -04:00
private $flagSameCase = true;
2012-10-09 13:29:25 -04:00
2017-08-15 16:03:21 -04:00
public function __construct($params = null)
{
$this->stored_system_variables = false;
if ($params != null) {
2017-08-15 16:03:21 -04:00
$this->stored_system_variables = (isset($params->stored_system_variables) ? $params->stored_system_variables : false);
2017-08-15 16:03:21 -04:00
$this->wsSessionId = isset($params->wsSessionId) ? $params->wsSessionId : '';
2010-12-02 23:34:41 +00:00
}
}
2019-01-30 09:11:57 -04:00
/**
* Get the flagSameCase
*
* @return boolean
*/
public function getFlagSameCase()
{
return $this->flagSameCase;
}
/**
* Set the flagSameCase
*
* @param boolean $var
*
* @return void
*/
public function setFlagSameCase($var)
{
$this->flagSameCase = $var;
}
2019-03-29 10:00:39 -04:00
/**
* Get the taskId
*
* @return int
*/
public function getTaskId()
{
return $this->taskId;
}
/**
* Set the taskId
*
* @param int $taskId
*
* @return void
*/
public function setTaskId($taskId)
{
$this->taskId = $taskId;
}
/**
* function to start a web services session in ProcessMaker
2012-10-09 13:29:25 -04:00
*
* @param string $userid
* @param string $password
2017-12-04 13:25:35 +00:00
*
* @return $wsResponse will return an object
*/
2017-08-15 16:03:21 -04:00
public function login($userid, $password)
{
global $RBAC;
try {
2017-08-10 16:30:32 -04:00
//To enable compatibility with hash login, method Enable.
//It's necessary to enable the hash start session because there are use cases in both,
//the web entry and in the case planner, where the password is still used in the hash
//format so that is possible to start a session. Thiw way we will mantain the
//compatibility with this type of loggin.
$RBAC->enableLoginWithHash();
2017-08-15 16:03:21 -04:00
$uid = $RBAC->VerifyLogin($userid, $password);
switch ($uid) {
case '':
2017-12-04 13:25:35 +00:00
case -1: //The user doesn't exist
2017-08-15 16:03:21 -04:00
$wsResponse = new WsResponse(3, G::loadTranslation('ID_USER_NOT_REGISTERED'));
2012-10-09 13:29:25 -04:00
break;
2017-12-04 13:25:35 +00:00
case -2: //The password is incorrect
2017-08-15 16:03:21 -04:00
$wsResponse = new WsResponse(4, G::loadTranslation('ID_WRONG_PASS'));
break;
2017-12-04 13:25:35 +00:00
case -3: //The user is inactive
2017-08-15 16:03:21 -04:00
$wsResponse = new WsResponse(5, G::loadTranslation('ID_USER_INACTIVE'));
break;
2017-12-04 13:25:35 +00:00
case -4: //The Due date is finished
2017-08-15 16:03:21 -04:00
$wsResponse = new WsResponse(5, G::loadTranslation('ID_USER_INACTIVE'));
break;
}
if ($uid < 0 || $uid == '') {
2017-08-15 16:03:21 -04:00
throw (new Exception(serialize($wsResponse)));
}
//check access to PM
2017-08-15 16:03:21 -04:00
$RBAC->loadUserRolePermission($RBAC->sSystem, $uid);
$res = $RBAC->userCanAccess("PM_LOGIN");
2017-10-05 15:01:09 -04:00
if ($res != 1 && $uid !== RBAC::GUEST_USER_UID) {
2017-08-15 16:03:21 -04:00
$wsResponse = new WsResponse(2, G::loadTranslation('ID_USER_HAVENT_RIGHTS_SYSTEM'));
throw (new Exception(serialize($wsResponse)));
}
2012-10-09 13:29:25 -04:00
$sessionId = G::generateUniqueID();
2017-08-15 16:03:21 -04:00
$wsResponse = new WsResponse('0', $sessionId);
$session = new Session();
2017-08-15 16:03:21 -04:00
$session->setSesUid($sessionId);
$session->setSesStatus('ACTIVE');
$session->setUsrUid($uid);
$session->setSesRemoteIp($_SERVER['REMOTE_ADDR']);
$session->setSesInitDate(date('Y-m-d H:i:s'));
2017-12-04 13:25:35 +00:00
$session->setSesDueDate(date(
'Y-m-d H:i:s',
mktime(date('H'), date('i') + 15, date('s'), date('m'), date('d'), date('Y'))
));
2017-08-15 16:03:21 -04:00
$session->setSesEndDate('');
$session->Save();
//save the session in DataBase
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$wsResponse = unserialize($e->getMessage());
2010-12-02 23:34:41 +00:00
}
2017-08-10 16:30:32 -04:00
//To enable compatibility with hash login, method disable.
$RBAC->disableLoginWithHash();
return $wsResponse;
}
/**
* get all groups
2012-10-09 13:29:25 -04:00
*
* @param none
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function processList()
{
try {
2017-10-17 11:45:53 -04:00
$result = [];
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->add(ProcessPeer::PRO_STATUS, 'DISABLED', Criteria::NOT_EQUAL);
$oDataset = ProcessPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
$oProcess = new Process();
2017-08-15 16:03:21 -04:00
$arrayProcess = $oProcess->load($aRow['PRO_UID']);
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $aRow['PRO_UID'],
'name' => $arrayProcess['PRO_TITLE']
2012-10-09 13:29:25 -04:00
);
$oDataset->next();
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage(),
'name' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
2010-12-02 23:34:41 +00:00
}
}
/**
* get all roles, to see all roles
2012-10-09 13:29:25 -04:00
*
* @param none
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function roleList()
{
try {
2017-10-17 11:45:53 -04:00
$result = [];
2017-12-04 13:25:35 +00:00
$RBAC = RBAC::getSingleton();
$RBAC->initRBAC();
$oCriteria = $RBAC->listAllRoles();
2017-08-15 16:03:21 -04:00
$oDataset = GulliverBasePeer::doSelectRs($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $aRow['ROL_UID'],
'name' => $aRow['ROL_CODE']
2012-10-09 13:29:25 -04:00
);
$oDataset->next();
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage(),
'name' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
2010-12-02 23:34:41 +00:00
}
}
2010-12-02 23:34:41 +00:00
/**
* get all groups
2012-10-09 13:29:25 -04:00
*
* @param null $search
2016-06-23 15:58:54 -04:00
* @param null $regex
* @param null $start
* @param null $limit
2017-12-04 13:25:35 +00:00
*
* @return array|stdClass
*/
2016-06-23 15:58:54 -04:00
public function groupList($regex = null, $start = null, $limit = null)
{
try {
$criteria = new Criteria('workflow');
$criteria->addSelectColumn(GroupwfPeer::GRP_UID);
$criteria->addSelectColumn(GroupwfPeer::GRP_TITLE);
$criteria->add(GroupwfPeer::GRP_STATUS, 'ACTIVE');
$criteria->addAscendingOrderByColumn(GroupwfPeer::GRP_TITLE);
2016-06-23 15:58:54 -04:00
if ($regex) {
$regex = GroupwfPeer::GRP_TITLE . " REGEXP '" . $regex . "'";
$criteria->add(GroupwfPeer::GRP_TITLE, $regex, Criteria::CUSTOM);
}
if ($start) {
$criteria->setOffset($start);
}
if ($limit) {
$criteria->setLimit($limit);
}
$rs = GroupwfPeer::doSelectRS($criteria);
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2017-10-17 11:45:53 -04:00
$result = [];
while ($rs->next()) {
$rows = $rs->getRow();
$result[] = array('guid' => $rows['GRP_UID'], 'name' => $rows['GRP_TITLE']);
}
return $result;
} catch (Exception $e) {
$result[] = array('guid' => $e->getMessage(), 'name' => $e->getMessage());
return $result;
2010-12-02 23:34:41 +00:00
}
}
/**
* get all department
2012-10-09 13:29:25 -04:00
*
* @param none
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function departmentList()
{
try {
2017-10-17 11:45:53 -04:00
$result = [];
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->add(DepartmentPeer::DEP_STATUS, 'ACTIVE');
$oDataset = DepartmentPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
$oDepartment = new Department();
2017-08-15 16:03:21 -04:00
$aDepartment = $oDepartment->Load($aRow['DEP_UID']);
$node['guid'] = $aRow['DEP_UID'];
$node['name'] = $aDepartment['DEP_TITLE'];
$node['parentUID'] = $aDepartment['DEP_PARENT'];
$node['dn'] = $aDepartment['DEP_LDAP_DN'];
//get the users from this department
$c = new Criteria();
$c->clearSelectColumns();
2017-08-15 16:03:21 -04:00
$c->addSelectColumn('COUNT(*)');
$c->add(UsersPeer::DEP_UID, $aRow['DEP_UID']);
$rs = UsersPeer::doSelectRS($c);
$rs->next();
$row = $rs->getRow();
$count = $row[0];
$node['users'] = $count;
$result[] = $node;
$oDataset->next();
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage(),
'name' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
2010-12-02 23:34:41 +00:00
return $result;
2010-12-02 23:34:41 +00:00
}
}
/**
* Get case list
2012-10-09 13:29:25 -04:00
*
* @param string $userId
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
public function caseList($userUid)
{
try {
$solrEnabled = 0;
2012-10-09 13:29:25 -04:00
2017-08-14 16:13:46 -04:00
if (($solrEnv = System::solrEnv()) !== false) {
$appSolr = new AppSolr(
2017-12-04 13:25:35 +00:00
$solrEnv["solr_enabled"],
$solrEnv["solr_host"],
$solrEnv["solr_instance"]
);
if ($appSolr->isSolrEnabled() && $solrEnv["solr_enabled"] == true) {
//Check if there are missing records to reindex and reindex them
$appSolr->synchronizePendingApplications();
$solrEnabled = 1;
}
}
if ($solrEnabled == 1) {
try {
2017-10-17 11:45:53 -04:00
$arrayData = [];
2017-10-17 11:45:53 -04:00
$delegationIndexes = [];
$columsToInclude = array("APP_UID");
$solrSearchText = null;
//Todo
2017-08-15 16:03:21 -04:00
$solrSearchText = $solrSearchText . (($solrSearchText != null) ? " OR " : null) . "(APP_STATUS:TO_DO AND APP_ASSIGNED_USERS:" . $userUid . ")";
$delegationIndexes[] = "APP_ASSIGNED_USER_DEL_INDEX_" . $userUid . "_txt";
//Draft
2017-08-15 16:03:21 -04:00
$solrSearchText = $solrSearchText . (($solrSearchText != null) ? " OR " : null) . "(APP_STATUS:DRAFT AND APP_DRAFT_USER:" . $userUid . ")";
//Index is allways 1
$solrSearchText = "($solrSearchText)";
//Add del_index dynamic fields to list of resulting columns
$columsToIncludeFinal = array_merge($columsToInclude, $delegationIndexes);
$solrRequestData = EntitySolrRequestData::createForRequestPagination(
2017-12-04 13:25:35 +00:00
array(
"workspace" => $solrEnv["solr_instance"],
"startAfter" => 0,
"pageSize" => 1000,
"searchText" => $solrSearchText,
"numSortingCols" => 1,
"sortCols" => array("APP_NUMBER"),
"sortDir" => array(strtolower("DESC")),
"includeCols" => $columsToIncludeFinal,
"resultFormat" => "json"
)
);
//Use search index to return list of cases
$searchIndex = new BpmnEngineServicesSearchIndex($appSolr->isSolrEnabled(), $solrEnv["solr_host"]);
//Execute query
$solrQueryResult = $searchIndex->getDataTablePaginatedList($solrRequestData);
//Get the missing data from database
2017-10-17 11:45:53 -04:00
$arrayApplicationUid = [];
foreach ($solrQueryResult->aaData as $i => $data) {
$arrayApplicationUid[] = $data["APP_UID"];
}
$aaappsDBData = $appSolr->getListApplicationDelegationData($arrayApplicationUid);
foreach ($solrQueryResult->aaData as $i => $data) {
//Initialize array
2017-10-17 11:45:53 -04:00
$delIndexes = []; //Store all the delegation indexes
//Complete empty values
$applicationUid = $data["APP_UID"]; //APP_UID
//Get all the indexes returned by Solr as columns
2017-08-15 16:03:21 -04:00
for ($i = count($columsToInclude); $i <= count($data) - 1; $i++) {
if (is_array($data[$columsToIncludeFinal[$i]])) {
foreach ($data[$columsToIncludeFinal[$i]] as $delIndex) {
$delIndexes[] = $delIndex;
}
}
}
//Verify if the delindex is an array
//if is not check different types of repositories
//the delegation index must always be defined.
if (count($delIndexes) == 0) {
2017-08-15 16:03:21 -04:00
$delIndexes[] = 1; // the first default index
}
//Remove duplicated
$delIndexes = array_unique($delIndexes);
//Get records
foreach ($delIndexes as $delIndex) {
2017-10-17 11:45:53 -04:00
$aRow = [];
//Copy result values to new row from Solr server
$aRow["APP_UID"] = $data["APP_UID"];
//Get delegation data from DB
//Filter data from db
$indexes = $appSolr->aaSearchRecords($aaappsDBData, array(
"APP_UID" => $applicationUid,
"DEL_INDEX" => $delIndex
));
foreach ($indexes as $index) {
$row = $aaappsDBData[$index];
}
2017-08-15 16:03:21 -04:00
if (!isset($row)) {
continue;
}
$aRow["APP_NUMBER"] = $row["APP_NUMBER"];
$aRow["APP_STATUS"] = $row["APP_STATUS"];
2017-08-15 16:03:21 -04:00
$aRow["PRO_UID"] = $row["PRO_UID"];
$aRow["DEL_INDEX"] = $row["DEL_INDEX"];
$arrayData[] = array(
"guid" => $aRow["APP_UID"],
"name" => $aRow["APP_NUMBER"],
"status" => $aRow["APP_STATUS"],
"delIndex" => $aRow["DEL_INDEX"],
"processId" => $aRow["PRO_UID"]
);
}
}
return $arrayData;
} catch (InvalidIndexSearchTextException $e) {
2017-10-17 11:45:53 -04:00
$arrayData = [];
2017-08-15 16:03:21 -04:00
$arrayData[] = array(
"guid" => $e->getMessage(),
"name" => $e->getMessage(),
"status" => $e->getMessage(),
"delIndex" => $e->getMessage(),
"processId" => $e->getMessage()
);
return $arrayData;
}
} else {
2019-09-10 15:29:00 -04:00
$data = [];
$selectedColumns = [
'APP_DELEGATION.APP_UID',
'APP_DELEGATION.DEL_INDEX',
'APP_DELEGATION.APP_NUMBER',
'APPLICATION.APP_STATUS',
'APPLICATION.APP_TITLE',
'APP_DELEGATION.PRO_UID'
];
$query = Delegation::query()->select($selectedColumns);
$query->join('APPLICATION', function ($join) {
$join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
});
$query->join('APP_THREAD', function ($join) {
$join->on('APP_THREAD.APP_UID', '=', 'APP_DELEGATION.APP_UID');
});
$query->where('APP_DELEGATION.USR_UID', $userUid);
$query->whereNested(function ($query) {
$query->where('APPLICATION.APP_STATUS', 'TO_DO');
$query->orWhere('APPLICATION.APP_STATUS', 'DRAFT');
});
$query->whereNull('APP_DELEGATION.DEL_FINISH_DATE');
$query->where('APP_DELEGATION.DEL_THREAD_STATUS', 'OPEN');
$query->where('APP_THREAD.APP_THREAD_STATUS', 'OPEN');
$query->orderBy('APP_DELEGATION.APP_NUMBER', 'DESC');
$result = $query->get();
$data2 = $result->values()->toArray();
$aux = [];
foreach ($data2 as $value) {
$aux['guid'] = $value['APP_UID'];
$aux['name'] = $value['APP_TITLE'];
$aux['status'] = $value['APP_STATUS'];
$aux['delIndex'] = $value['DEL_INDEX'];
$aux['processId'] = $value['PRO_UID'];
array_push($data, $aux);
}
2019-09-10 15:29:00 -04:00
return $data;
}
} catch (Exception $e) {
2017-10-17 11:45:53 -04:00
$arrayData = [];
2017-08-15 16:03:21 -04:00
$arrayData[] = array(
"guid" => $e->getMessage(),
"name" => $e->getMessage(),
"status" => $e->getMessage(),
"delIndex" => $e->getMessage(),
"processId" => $e->getMessage()
);
return $arrayData;
}
}
/**
* Get unassigned case list
2012-10-09 13:29:25 -04:00
*
2021-04-30 09:17:09 -04:00
* @param string $userUid
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2021-04-30 09:17:09 -04:00
public function unassignedCaseList($userUid)
{
try {
2017-10-17 11:45:53 -04:00
$result = [];
2021-04-30 09:17:09 -04:00
$unassigned = new Unassigned();
$unassigned->setUserUid($userUid);
$data = $unassigned->getData();
foreach ($data as $var) {
array_push($result, [
'guid' => $var['APP_UID'],
'name' => $var['APP_NUMBER'],
'delIndex' => $var['DEL_INDEX'],
'processId' => $var['PRO_UID']
]);
}
return $result;
} catch (Exception $e) {
2021-04-30 09:17:09 -04:00
$result[] = [
2017-12-04 13:25:35 +00:00
'guid' => $e->getMessage(),
2017-08-15 16:03:21 -04:00
'name' => $e->getMessage(),
'status' => $e->getMessage(),
2017-12-04 13:25:35 +00:00
'processId' => $e->getMessage()
2021-04-30 09:17:09 -04:00
];
return $result;
}
}
/**
2017-10-17 11:45:53 -04:00
* Get all users
2012-10-09 13:29:25 -04:00
*
* @param none
2017-10-17 11:45:53 -04:00
* @return array $result, will return an array
* @throws Exception
*/
2017-08-15 16:03:21 -04:00
public function userList()
{
try {
2017-10-17 11:45:53 -04:00
$result = [];
$criteria = new Criteria('workflow');
$criteria->add(UsersPeer::USR_STATUS, 'ACTIVE');
$criteria->add(UsersPeer::USR_UID, [RBAC::GUEST_USER_UID], Criteria::NOT_IN);
$dataset = UsersPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
2017-10-17 11:45:53 -04:00
while ($row = $dataset->getRow()) {
$result[] = ['guid' => $row['USR_UID'], 'name' => $row['USR_USERNAME']];
$dataset->next();
}
return $result;
} catch (Exception $e) {
2017-10-17 11:45:53 -04:00
$result[] = [
'guid' => $e->getMessage(),
'name' => $e->getMessage()
];
return $result;
}
}
/**
* get list of all the available triggers in a workspace
2012-10-09 13:29:25 -04:00
*
* @param none
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function triggerList()
{
try {
2017-10-17 11:45:53 -04:00
$result = [];
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(TriggersPeer::TRI_UID);
$oCriteria->addSelectColumn(TriggersPeer::PRO_UID);
$oCriteria->addAsColumn('TITLE', TriggersPeer::TRI_TITLE);
$oDataset = TriggersPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $aRow['TRI_UID'],
'name' => $aRow['TITLE'],
'processId' => $aRow['PRO_UID']
);
$oDataset->next();
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage(),
'name' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
}
}
/**
* get list of the uploaded documents for a given case
2012-10-09 13:29:25 -04:00
*
* @param string $sApplicationUID
* @param string $sUserUID
2017-12-04 13:25:35 +00:00
*
* @return $result
*/
2017-08-15 16:03:21 -04:00
public function inputDocumentList($sApplicationUID, $sUserUID)
{
try {
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$fields = $oCase->loadCase($sApplicationUID);
$sProcessUID = $fields['PRO_UID'];
$sTaskUID = '';
2017-08-15 16:03:21 -04:00
$oCriteria = $oCase->getAllUploadedDocumentsCriteria($sProcessUID, $sApplicationUID, $sTaskUID, $sUserUID);
2017-10-17 11:45:53 -04:00
$result = [];
global $_DBArray;
foreach ($_DBArray['inputDocuments'] as $key => $row) {
2017-08-15 16:03:21 -04:00
if (isset($row['DOC_VERSION'])) {
2017-10-17 11:45:53 -04:00
$docrow = [];
2012-10-09 13:29:25 -04:00
$docrow['guid'] = $row['APP_DOC_UID'];
$docrow['filename'] = $row['APP_DOC_FILENAME'];
$docrow['docId'] = $row['DOC_UID'];
$docrow['version'] = $row['DOC_VERSION'];
$docrow['createDate'] = $row['CREATE_DATE'];
2012-10-09 13:29:25 -04:00
$docrow['createBy'] = $row['CREATED_BY'];
$docrow['type'] = $row['TYPE'];
$docrow['index'] = $row['APP_DOC_INDEX'];
$docrow['link'] = 'cases/' . $row['DOWNLOAD_LINK'];
$result[] = $docrow;
}
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
}
}
/**
* input document process list
2012-10-09 13:29:25 -04:00
*
* @param string $sProcessUID
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function inputDocumentProcessList($sProcessUID)
{
try {
global $_DBArray;
2017-08-15 16:03:21 -04:00
$_DBArray = (isset($_SESSION['_DBArray']) ? $_SESSION['_DBArray'] : '');
$oMap = new ProcessMap();
2017-08-15 16:03:21 -04:00
$oCriteria = $oMap->getInputDocumentsCriteria($sProcessUID);
$oDataset = InputDocumentPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
2017-10-17 11:45:53 -04:00
$result = [];
while ($aRow = $oDataset->getRow()) {
2012-10-09 13:29:25 -04:00
if ($aRow['INP_DOC_TITLE'] == null) {
//There is no transaltion for this Document name, try to get/regenerate the label
2012-10-09 13:29:25 -04:00
$inputDocument = new InputDocument();
2017-08-15 16:03:21 -04:00
$inputDocumentObj = $inputDocument->load($aRow['INP_DOC_UID']);
2012-10-09 13:29:25 -04:00
$aRow['INP_DOC_TITLE'] = $inputDocumentObj['INP_DOC_TITLE'];
$aRow['INP_DOC_DESCRIPTION'] = $inputDocumentObj['INP_DOC_DESCRIPTION'];
}
2017-10-17 11:45:53 -04:00
$docrow = [];
2012-10-09 13:29:25 -04:00
$docrow['guid'] = $aRow['INP_DOC_UID'];
$docrow['name'] = $aRow['INP_DOC_TITLE'];
$docrow['description'] = $aRow['INP_DOC_DESCRIPTION'];
$result[] = $docrow;
2012-10-09 13:29:25 -04:00
$oDataset->next();
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
}
2010-12-02 23:34:41 +00:00
}
/**
* output document list
2012-10-09 13:29:25 -04:00
*
* @param string $sApplicationUID
* @param string $sUserUID
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function outputDocumentList($sApplicationUID, $sUserUID)
{
try {
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$fields = $oCase->loadCase($sApplicationUID);
$sProcessUID = $fields['PRO_UID'];
$sTaskUID = '';
2017-08-15 16:03:21 -04:00
$oCriteria = $oCase->getAllGeneratedDocumentsCriteria($sProcessUID, $sApplicationUID, $sTaskUID, $sUserUID);
2017-10-17 11:45:53 -04:00
$result = [];
global $_DBArray;
foreach ($_DBArray['outputDocuments'] as $key => $row) {
2017-08-15 16:03:21 -04:00
if (isset($row['DOC_VERSION'])) {
2017-10-17 11:45:53 -04:00
$docrow = [];
2012-10-09 13:29:25 -04:00
$docrow['guid'] = $row['APP_DOC_UID'];
$docrow['filename'] = $row['DOWNLOAD_FILE'];
2012-10-09 13:29:25 -04:00
$docrow['docId'] = $row['DOC_UID'];
$docrow['version'] = $row['DOC_VERSION'];
$docrow['createDate'] = $row['CREATE_DATE'];
2012-10-09 13:29:25 -04:00
$docrow['createBy'] = $row['CREATED_BY'];
$docrow['type'] = $row['TYPE'];
$docrow['index'] = $row['APP_DOC_INDEX'];
$docrow['link'] = 'cases/' . $row['DOWNLOAD_LINK'];
$result[] = $docrow;
}
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
}
2010-12-02 23:34:41 +00:00
}
/**
* remove document
2012-10-09 13:29:25 -04:00
*
* @param string $appDocUid
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function removeDocument($appDocUid)
{
try {
$oAppDocument = new AppDocument();
2017-08-15 16:03:21 -04:00
$oAppDocument->remove($appDocUid, 1); //always send version 1
$result = new WsResponse(0, " $appDocUid");
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* get task list
2012-10-09 13:29:25 -04:00
*
* @param string $userId
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function taskList($userId)
{
try {
$oGroup = new Groups();
2017-08-15 16:03:21 -04:00
$aGroups = $oGroup->getActiveGroupsForAnUser($userId);
2017-10-17 11:45:53 -04:00
$result = [];
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$del = DBAdapter::getStringDelimiter();
2017-08-15 16:03:21 -04:00
$oCriteria->addSelectColumn(TaskPeer::PRO_UID);
$oCriteria->addSelectColumn(TaskPeer::TAS_UID);
$oCriteria->addSelectColumn(TaskPeer::TAS_TITLE);
$oCriteria->addSelectColumn(TaskPeer::TAS_START);
$oCriteria->setDistinct();
2017-08-15 16:03:21 -04:00
$oCriteria->addJoin(TaskPeer::TAS_UID, TaskUserPeer::TAS_UID, Criteria::LEFT_JOIN);
$oCriteria->addOr(TaskUserPeer::USR_UID, $userId);
$oCriteria->addOr(TaskUserPeer::USR_UID, $aGroups, Criteria::IN);
2012-10-09 13:29:25 -04:00
2017-08-15 16:03:21 -04:00
$oDataset = TaskPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $aRow['TAS_UID'],
2017-08-15 16:03:21 -04:00
'name' => $aRow['TAS_TITLE'],
'processId' => $aRow['PRO_UID'],
2017-12-04 13:25:35 +00:00
'initialTask' => $aRow['TAS_START'] == 'TRUE' ? '1' : '0'
);
$oDataset->next();
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage(),
'name' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
}
}
/**
* send message
2012-10-09 13:29:25 -04:00
*
2018-04-04 09:21:59 -04:00
* @param string $appUid
* @param string $from
* @param string $to
* @param string $cc
* @param string $bcc
* @param string $subject
* @param string $template
* @param $appFields = null
2018-04-04 09:21:59 -04:00
* @param $attachment = null
* @param boolean $showMessage = true
* @param int $delIndex = 0
2017-12-04 13:25:35 +00:00
* @param array $config
*
* @return $result will return an object
2019-03-29 10:00:39 -04:00
*
* @see ActionsByEmailCoreClass->sendActionsByEmail()
* @see workflow\engine\classes\class.pmFunctions::PMFSendMessage()
* @see workflow\engine\methods\services\soap2::sendMessage()
* @see \ProcessMaker\BusinessModel\EmailEvent->sendEmail()
* @see \ProcessMaker\BusinessModel\Pmgmail->sendEmailWithApplicationData()
*
*/
public function sendMessage(
2018-04-04 09:21:59 -04:00
$appUid,
$from,
$to,
$cc,
$bcc,
$subject,
$template,
$appFields = null,
$attachment = null,
$showMessage = true,
$delIndex = 0,
$config = [],
2019-03-29 10:00:39 -04:00
$gmail = 0,
$appMsgType = WsBase::MESSAGE_TYPE_PM_FUNCTION
2017-12-04 13:25:35 +00:00
)
{
try {
$setup = [];
/*----------------------------------********---------------------------------*/
if (!empty($config)) {
2017-10-17 11:45:53 -04:00
$arrayConfigAux = [];
if (is_array($config)) {
if (PMLicensedFeatures::getSingleton()->verifyfeature("nKaNTNuT1MzK0RsMEtXTnYzR09ucHF2WGNuS0hRdDBBak42WXJhNVVOOG1INEVoaU1EaTllbjBBeEJNeG9wRVJ6NmxQelhyVTBvdThzPQ==")) {
$arrayConfigAux = $config;
}
} else {
if (PMLicensedFeatures::getSingleton()->verifyfeature("zIKRGpDM3pjcHFsWGplNDN0dTl5bGN3UTNiOWdQU0E5Q05QTksrU1ladWQ0VT0=")) {
2018-04-04 09:21:59 -04:00
$emailServer = new EmailServer();
$criteria = $emailServer->getEmailServerCriteria();
$criteria->add(EmailServerPeer::MESS_UID, $config, Criteria::EQUAL);
$rsCriteria = EmailServerPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$arrayConfigAux = $row;
$arrayConfigAux["SMTPSecure"] = $row["SMTPSECURE"];
2019-12-02 15:32:41 -04:00
$arrayConfigAux["OAUTH_CLIENT_ID"] = !empty($row["OAUTH_CLIENT_ID"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_ID"]) : '';
$arrayConfigAux["OAUTH_CLIENT_SECRET"] = !empty($row["OAUTH_CLIENT_SECRET"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_SECRET"]) : '';
$arrayConfigAux["OAUTH_REFRESH_TOKEN"] = !empty($row["OAUTH_REFRESH_TOKEN"]) ?
Crypt::decryptString($row["OAUTH_REFRESH_TOKEN"]) : '';
}
}
}
2018-04-04 09:21:59 -04:00
$setup = (!empty($arrayConfigAux)) ? $arrayConfigAux : System::getEmailConfiguration();
2018-04-04 09:21:59 -04:00
if (!isset($setup['MESS_ENABLED'])) {
$setup['MESS_ENABLED'] = 1;
$setup['SMTPSecure'] = $setup['SMTPSECURE'];
unset($setup['SMTPSECURE']);
}
} else {
2017-08-15 16:03:21 -04:00
/*----------------------------------********---------------------------------*/
2018-04-04 09:21:59 -04:00
$setup = System::getEmailConfiguration();
2017-08-15 16:03:21 -04:00
/*----------------------------------********---------------------------------*/
}
/*----------------------------------********---------------------------------*/
$msgError = "";
2018-04-04 09:21:59 -04:00
if (sizeof($setup) == 0) {
2017-08-15 16:03:21 -04:00
$msgError = "The default configuration wasn't defined";
}
2018-04-04 09:21:59 -04:00
$case = new Cases();
2019-03-29 10:00:39 -04:00
$oldFields = $case->loadCase($appUid, $delIndex);
2017-08-15 16:03:21 -04:00
if ($gmail == 1) {
$pathEmail = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP;
} else {
$pathEmail = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $oldFields['PRO_UID'] . PATH_SEP;
}
2018-04-04 09:21:59 -04:00
$fileTemplate = $pathEmail . $template;
2017-08-15 16:03:21 -04:00
G::mk_dir($pathEmail, 0777, true);
2017-08-15 16:03:21 -04:00
if (!file_exists($fileTemplate)) {
$data['FILE_TEMPLATE'] = $fileTemplate;
return new WsResponse(28, G::LoadTranslation('ID_TEMPLATE_FILE_NOT_EXIST', SYS_LANG, $data));
}
if ($appFields == null) {
2018-04-04 09:21:59 -04:00
$fieldsCase = $oldFields['APP_DATA'];
} else {
2018-04-04 09:21:59 -04:00
$fieldsCase = array_merge($oldFields['APP_DATA'], $appFields);
}
$messageArray = AppMessage::buildMessageRow(
'',
$appUid,
$delIndex,
2019-03-29 10:00:39 -04:00
$appMsgType,
2018-04-04 09:21:59 -04:00
$subject,
G::buildFrom($setup, $from),
$to,
2019-06-11 10:14:02 -04:00
G::replaceDataGridField(file_get_contents($fileTemplate), $fieldsCase, false),
2018-04-04 09:21:59 -04:00
$cc,
$bcc,
2022-01-13 12:06:44 -04:00
$template,
2018-07-11 13:24:15 -04:00
$attachment,
2018-04-04 09:21:59 -04:00
'pending',
($showMessage) ? 1 : 0,
$msgError,
(preg_match("/^.+\.html?$/i", $fileTemplate)) ? true : false,
isset($fieldsCase['APP_NUMBER']) ? $fieldsCase['APP_NUMBER'] : 0,
isset($fieldsCase['PRO_ID']) ? $fieldsCase['PRO_ID'] : 0,
$this->getTaskId() ? $this->getTaskId() : (isset($oldFields['TAS_ID']) ? $oldFields['TAS_ID'] : 0)
);
if ($gmail === 1) {
return new WsResponse(0, G::loadTranslation('ID_PMGMAIL'));
}
// Create always the record in APP_MESSAGE table
$spool = new SpoolRun();
$spool->setConfig($setup);
$spool->create($messageArray);
// Get the data of the record created
$fileData = $spool->getFileData();
$fileData['spoolId'] = $spool->getSpoolId();
// Create the closure and send the required data
$closure = function() use ($setup, $fileData, $gmail, $to) {
2020-02-26 16:23:08 -04:00
$spool = new SpoolRun();
$spool->setConfig($setup);
$spool->setSpoolId($fileData['spoolId']);
$spool->setFileData($fileData);
$spool->sendMail();
return $spool;
};
switch ($appMsgType) {
case WsBase::MESSAGE_TYPE_EMAIL_EVENT:
case WsBase::MESSAGE_TYPE_PM_FUNCTION:
JobsManager::getSingleton()->dispatch(EmailEvent::class, $closure);
$result = new WsResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $to);
break;
default :
$spool = $closure();
if ($spool->status == 'sent') {
$result = new WsResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $to);
$result->addExtraParam('AppMessUid', $spool->getSpoolId());
} else {
$result = new WsResponse(29, $spool->status . ' ' . $spool->error . PHP_EOL . print_r($setup, 1));
}
break;
}
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
return new WsResponse(100, $e->getMessage());
}
}
/**
* get case information
2012-10-09 13:29:25 -04:00
*
* @param string $caseId
* @param string $iDelIndex
2017-12-04 13:25:35 +00:00
* @param bool $flagUseDelIndex
*
* @return $result will return an object
*/
public function getCaseInfo($caseId, $iDelIndex, $flagUseDelIndex = false)
{
try {
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$aRows = $oCase->loadCase($caseId, $iDelIndex);
2017-08-15 16:03:21 -04:00
if (count($aRows) == 0) {
$data['CASE_NUMBER'] = $caseNumber;
2017-08-15 16:03:21 -04:00
$result = new WsResponse(16, G::loadTranslation('ID_CASE_DOES_NOT_EXIST', SYS_LANG, $data));
return $result;
}
$oProcess = new Process();
try {
2017-08-15 16:03:21 -04:00
$uFields = $oProcess->load($aRows['PRO_UID']);
$processName = $uFields['PRO_TITLE'];
} catch (Exception $e) {
$processName = '';
}
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULLY'));
2012-10-09 13:29:25 -04:00
$result->caseId = $aRows['APP_UID'];
$result->caseNumber = $aRows['APP_NUMBER'];
$result->caseName = $aRows['TITLE'];
$result->caseStatus = $aRows['APP_STATUS'];
$result->caseParalell = $aRows['APP_PARALLEL'];
$result->caseCreatorUser = $aRows['APP_INIT_USER'];
$result->caseCreatorUserName = $aRows['CREATOR'];
2012-10-09 13:29:25 -04:00
$result->processId = $aRows['PRO_UID'];
$result->processName = $processName;
$result->createDate = $aRows['CREATE_DATE'];
$result->updateDate = $aRows['UPDATE_DATE'];
//now fill the array of AppDelay
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(AppDelayPeer::APP_DEL_INDEX);
$oCriteria->add(AppDelayPeer::APP_UID, $caseId);
$oCriteria->add(AppDelayPeer::APP_TYPE, 'PAUSE');
$oCriteria->add(AppDelayPeer::APP_DISABLE_ACTION_USER, '0');
$oDataset = AppDelayPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2017-10-17 11:45:53 -04:00
$aIndexsPaused = [];
while ($oDataset->next()) {
$data = $oDataset->getRow();
$aIndexsPaused[] = $data['APP_DEL_INDEX'];
}
//now fill the array of AppDelegationPeer
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
$oCriteria->addSelectColumn(AppDelegationPeer::USR_UID);
$oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_THREAD);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_THREAD_STATUS);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INIT_DATE);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_TASK_DUE_DATE);
2017-08-15 16:03:21 -04:00
$oCriteria->add(AppDelegationPeer::APP_UID, $caseId);
if (count($aIndexsPaused)) {
2017-08-15 16:03:21 -04:00
$cton1 = $oCriteria->getNewCriterion(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
$cton2 = $oCriteria->getNewCriterion(AppDelegationPeer::DEL_INDEX, $aIndexsPaused, Criteria::IN);
$cton1->addOR($cton2);
$oCriteria->add($cton1);
} else {
$oCriteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
}
2012-10-09 13:29:25 -04:00
2017-08-15 16:03:21 -04:00
$oCriteria->addAscendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
$oDataset = AppDelegationPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2012-10-09 13:29:25 -04:00
2017-10-17 11:45:53 -04:00
$aCurrentUsers = [];
while ($oDataset->next()) {
$aAppDel = $oDataset->getRow();
$oUser = new Users();
try {
2017-08-15 16:03:21 -04:00
$oUser->load($aAppDel['USR_UID']);
$uFields = $oUser->toArray(BasePeer::TYPE_FIELDNAME);
$currentUserName = $oUser->getUsrFirstname() . ' ' . $oUser->getUsrLastname();
} catch (Exception $e) {
$currentUserName = '';
}
$oTask = new Task();
try {
2017-08-15 16:03:21 -04:00
$uFields = $oTask->load($aAppDel['TAS_UID']);
$taskName = $uFields['TAS_TITLE'];
} catch (Exception $e) {
$taskName = '';
}
$currentUser = new stdClass();
2012-10-09 13:29:25 -04:00
$currentUser->userId = $aAppDel['USR_UID'];
$currentUser->userName = $currentUserName;
$currentUser->taskId = $aAppDel['TAS_UID'];
$currentUser->taskName = $taskName;
$currentUser->delIndex = $aAppDel['DEL_INDEX'];
$currentUser->delThread = $aAppDel['DEL_THREAD'];
$currentUser->delThreadStatus = $aAppDel['DEL_THREAD_STATUS'];
$currentUser->delStatus = ($aAppDel["DEL_THREAD_STATUS"] == 'CLOSED') ? 'PAUSED' : $aRows['APP_STATUS'];
$currentUser->delInitDate = $aAppDel["DEL_INIT_DATE"];
$currentUser->delTaskDueDate = $aAppDel["DEL_TASK_DUE_DATE"];
$aCurrentUsers[] = $currentUser;
}
$result->currentUsers = $aCurrentUsers;
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
2010-12-02 23:34:41 +00:00
}
/**
* Create an new user
2012-10-09 13:29:25 -04:00
*
* @param string sessionId : The session ID.
2012-10-09 13:29:25 -04:00
* @param string userName : The username for the new user.
* @param string firstName : The user's first name.
2012-10-09 13:29:25 -04:00
* @param string lastName : The user's last name.
* @param string email : The user's email address.
* @param string role : The user's role, such as "PROCESSMAKER_ADMIN" or "PROCESSMAKER_OPERATOR".
* @param string password : The user's password such as "Be@gle2" (It will be automatically encrypted
2017-12-04 13:25:35 +00:00
* with an MD5 hash).
2012-10-09 13:29:25 -04:00
* @param string dueDate : Optional parameter. The expiration date must be a string in the format "yyyy-mm-dd".
* @param string status : Optional parameter. The user's status, such as "ACTIVE", "INACTIVE" or "VACATION".
2018-07-25 09:25:25 -04:00
*
* @return object|array
*/
2017-12-04 13:25:35 +00:00
public function createUser(
$userName,
$firstName,
$lastName,
$email,
$role,
$password,
$dueDate = null,
$status = null
)
{
try {
global $RBAC;
$RBAC->initRBAC();
2017-08-15 16:03:21 -04:00
if (empty($userName)) {
2017-08-17 16:29:53 -04:00
$result = new WsCreateUserResponse(25, G::loadTranslation("ID_USERNAME_REQUIRED"), null);
return $result;
}
2017-08-15 16:03:21 -04:00
if (empty($firstName)) {
2017-08-17 16:29:53 -04:00
$result = new WsCreateUserResponse(27, G::loadTranslation("ID_MSG_ERROR_USR_FIRSTNAME"), null);
return $result;
}
2017-08-15 16:03:21 -04:00
if (empty($password)) {
2017-08-17 16:29:53 -04:00
$result = new WsCreateUserResponse(26, G::loadTranslation("ID_PASSWD_REQUIRED"), null);
return $result;
}
$mktimeDueDate = 0;
2017-08-15 16:03:21 -04:00
if (!empty($dueDate) && $dueDate != 'null' && $dueDate) {
if (!preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $dueDate, $arrayMatch)) {
2017-12-04 13:25:35 +00:00
$result = new WsCreateUserResponse(-1, G::loadTranslation("ID_INVALID_DATA") . " $dueDate", null);
return $result;
} else {
2017-12-04 13:25:35 +00:00
$mktimeDueDate = mktime(
0,
0,
0,
intval($arrayMatch[2]),
intval($arrayMatch[3]),
intval($arrayMatch[1])
);
}
} else {
2017-08-15 16:03:21 -04:00
$mktimeDueDate = mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1);
}
2017-08-15 16:03:21 -04:00
if (!empty($status) && $status != 'null' && $status) {
if ($status != "ACTIVE" && $status != "INACTIVE" && $status != "VACATION") {
2017-12-04 13:25:35 +00:00
$result = new WsCreateUserResponse(-1, G::loadTranslation("ID_INVALID_DATA") . " $status", null);
return $result;
}
} else {
$status = "ACTIVE";
}
2018-07-25 09:25:25 -04:00
$strRole = $RBAC->getRoleCodeValid($role);
if (empty($strRole)) {
$data = [];
$data["ROLE"] = $role;
$result = new WsCreateUserResponse(6, G::loadTranslation("ID_INVALID_ROLE", SYS_LANG, $data), null);
2018-07-25 09:25:25 -04:00
return $result;
}
2017-08-15 16:03:21 -04:00
if (strlen($password) > 20) {
2017-12-04 13:25:35 +00:00
$result = new WsCreateUserResponse(-1, G::loadTranslation("ID_PASSWORD_SURPRASES"), null);
return $result;
}
2017-08-15 16:03:21 -04:00
if ($RBAC->verifyUser($userName) == 1) {
2017-10-17 11:45:53 -04:00
$data = [];
$data["USER_ID"] = $userName;
2017-12-04 13:25:35 +00:00
$result = new WsCreateUserResponse(
7,
G::loadTranslation("ID_USERNAME_ALREADY_EXISTS", SYS_LANG, $data),
null
);
return $result;
}
//Set fields
2017-10-17 11:45:53 -04:00
$arrayData = [];
2012-10-09 13:29:25 -04:00
$arrayData["USR_USERNAME"] = $userName;
2017-08-15 16:03:21 -04:00
$arrayData["USR_PASSWORD"] = Bootstrap::hashPassword($password);
2012-10-09 13:29:25 -04:00
$arrayData["USR_FIRSTNAME"] = $firstName;
$arrayData["USR_LASTNAME"] = $lastName;
$arrayData["USR_EMAIL"] = $email;
$arrayData["USR_DUE_DATE"] = $mktimeDueDate;
2017-08-15 16:03:21 -04:00
$arrayData["USR_CREATE_DATE"] = date("Y-m-d H:i:s");
$arrayData["USR_UPDATE_DATE"] = date("Y-m-d H:i:s");
$arrayData["USR_BIRTHDAY"] = date("Y-m-d");
$arrayData["USR_AUTH_USER_DN"] = "";
2012-10-09 13:29:25 -04:00
$arrayData["USR_STATUS"] = ($status == "ACTIVE") ? 1 : 0;
2013-03-20 10:58:19 -04:00
try {
2017-08-15 16:03:21 -04:00
$userUid = $RBAC->createUser($arrayData, $strRole);
} catch (Exception $oError) {
2017-08-17 16:29:53 -04:00
$result = new WsCreateUserResponse(100, $oError->getMessage(), null);
2013-03-20 10:58:19 -04:00
return $result;
}
2012-10-09 13:29:25 -04:00
$arrayData["USR_UID"] = $userUid;
$arrayData["USR_STATUS"] = $status;
$arrayData["USR_COUNTRY"] = "";
$arrayData["USR_CITY"] = "";
$arrayData["USR_LOCATION"] = "";
2012-10-09 13:29:25 -04:00
$arrayData["USR_ADDRESS"] = "";
$arrayData["USR_PHONE"] = "";
$arrayData["USR_ZIP_CODE"] = "";
$arrayData["USR_POSITION"] = "";
2012-10-09 13:29:25 -04:00
$arrayData["USR_ROLE"] = $strRole;
$user = new Users();
2017-08-15 16:03:21 -04:00
$user->create($arrayData);
//Response
2017-10-17 11:45:53 -04:00
$data = [];
$data["FIRSTNAME"] = $firstName;
$data["LASTNAME"] = $lastName;
$data["USER_ID"] = $userName;
2017-08-15 16:03:21 -04:00
$res = new WsResponse(0, G::loadTranslation("ID_USER_CREATED_SUCCESSFULLY", SYS_LANG, $data));
2018-07-25 09:25:25 -04:00
$result = [
"status_code" => $res->status_code,
"message" => $res->message,
"userUID" => $userUid,
"timestamp" => $res->timestamp
];
return $result;
} catch (Exception $e) {
2017-08-17 16:29:53 -04:00
$result = new WsCreateUserResponse(100, $e->getMessage(), null);
return $result;
}
}
/**
* Update user
2012-10-09 13:29:25 -04:00
*
* @param string userUid : The user UID.
* @param string userName : The username for the user.
* @param string firstName : Optional parameter. The user's first name.
2012-10-09 13:29:25 -04:00
* @param string lastName : Optional parameter. The user's last name.
* @param string email : Optional parameter. The user's email address.
* @param string dueDate : Optional parameter. The expiration date must be a string in the format "yyyy-mm-dd".
* @param string status : Optional parameter. The user's status, such as "ACTIVE", "INACTIVE" or "VACATION".
2018-07-25 09:25:25 -04:00
* @param string role : Optional parameter. The user's role, such as "PROCESSMAKER_ADMIN" or "PROCESSMAKER_OPERATOR".
2012-10-09 13:29:25 -04:00
* @param string password : Optional parameter. The user's password such as "Be@gle2" (It will be automatically
* encrypted with an MD5 hash).
2018-07-25 09:25:25 -04:00
*
* @return object|array
*/
2017-12-04 13:25:35 +00:00
public function updateUser(
$userUid,
$userName,
$firstName = null,
$lastName = null,
$email = null,
$dueDate = null,
$status = null,
$role = null,
$password = null
)
2012-10-09 13:29:25 -04:00
{
try {
global $RBAC;
$RBAC->initRBAC();
2017-08-15 16:03:21 -04:00
if (empty($userUid)) {
$result = new WsResponse(25, G::LoadTranslation("ID_REQUIRED_FIELD") . " userUid");
return $result;
}
2017-08-15 16:03:21 -04:00
if (empty($userName)) {
$result = new WsResponse(25, G::LoadTranslation("ID_USERNAME_REQUIRED"));
return $result;
}
2017-08-15 16:03:21 -04:00
if ($RBAC->verifyUserId($userUid) == 0) {
$result = new WsResponse(3, G::loadTranslation("ID_USER_NOT_REGISTERED_SYSTEM"));
return $result;
}
$mktimeDueDate = 0;
2017-08-15 16:03:21 -04:00
if (!empty($dueDate)) {
if (!preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $dueDate, $arrayMatch)) {
2017-12-04 13:25:35 +00:00
$result = new WsResponse(-1, G::LoadTranslation("ID_INVALID_DATA") . " $dueDate");
return $result;
} else {
2017-12-04 13:25:35 +00:00
$mktimeDueDate = mktime(
0,
0,
0,
intval($arrayMatch[2]),
intval($arrayMatch[3]),
intval($arrayMatch[1])
);
}
}
2017-08-15 16:03:21 -04:00
if (!empty($status)) {
if ($status != "ACTIVE" && $status != "INACTIVE" && $status != "VACATION") {
2017-12-04 13:25:35 +00:00
$result = new WsResponse(-1, G::LoadTranslation("ID_INVALID_DATA") . " $status");
return $result;
2018-02-19 19:23:51 +00:00
} else {
$status == 'INACTIVE' ? $RBAC->destroySessionUser($userUid) : null;
}
}
2018-08-03 08:12:36 -04:00
if (!empty($role)) {
if ($userUid === $RBAC::ADMIN_USER_UID) {
$result = new WsResponse(15, G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
2018-08-03 08:12:36 -04:00
return $result;
}
$strRole = $RBAC->getRoleCodeValid($role);
if (empty($strRole)) {
$data = [];
$data["ROLE"] = $role;
$result = new WsCreateUserResponse(6, G::loadTranslation("ID_INVALID_ROLE", SYS_LANG, $data), null);
return $result;
}
}
2017-08-15 16:03:21 -04:00
if (!empty($password) && strlen($password) > 20) {
2017-12-04 13:25:35 +00:00
$result = new WsResponse(-1, G::LoadTranslation("ID_PASSWORD_SURPRASES"));
return $result;
}
$criteria = new Criteria();
2017-08-15 16:03:21 -04:00
$criteria->addSelectColumn(UsersPeer::USR_UID);
$criteria->add(UsersPeer::USR_USERNAME, $userName);
$criteria->add(UsersPeer::USR_UID, $userUid, Criteria::NOT_EQUAL);
$rs = UsersPeer::doSelectRS($criteria);
if ($rs->next()) {
2017-10-17 11:45:53 -04:00
$data = [];
$data["USER_ID"] = $userName;
2017-08-15 16:03:21 -04:00
$result = new WsResponse(7, G::LoadTranslation("ID_USERNAME_ALREADY_EXISTS", SYS_LANG, $data));
return $result;
}
//Set fields
2017-10-17 11:45:53 -04:00
$arrayData = [];
2012-10-09 13:29:25 -04:00
$arrayData["USR_UID"] = $userUid;
$arrayData["USR_USERNAME"] = $userName;
2017-08-15 16:03:21 -04:00
if (!empty($firstName)) {
$arrayData["USR_FIRSTNAME"] = $firstName;
}
2017-08-15 16:03:21 -04:00
if (!empty($lastName)) {
$arrayData["USR_LASTNAME"] = $lastName;
}
2017-08-15 16:03:21 -04:00
if (!empty($email)) {
$arrayData["USR_EMAIL"] = $email;
}
if ($mktimeDueDate != 0) {
$arrayData["USR_DUE_DATE"] = $mktimeDueDate;
}
2017-08-15 16:03:21 -04:00
$arrayData["USR_UPDATE_DATE"] = date("Y-m-d H:i:s");
2017-08-15 16:03:21 -04:00
if (!empty($status)) {
$arrayData["USR_STATUS"] = $status;
}
if ($strRole != null) {
$arrayData["USR_ROLE"] = $strRole;
}
2017-08-15 16:03:21 -04:00
if (!empty($password)) {
$arrayData["USR_PASSWORD"] = Bootstrap::hashPassword($password);
}
//Update user
if ($strRole != null) {
2017-08-15 16:03:21 -04:00
$RBAC->updateUser($arrayData, $strRole);
} else {
2017-08-15 16:03:21 -04:00
$RBAC->updateUser($arrayData);
}
$user = new Users();
2017-08-15 16:03:21 -04:00
$user->update($arrayData);
//Response
2017-08-15 16:03:21 -04:00
$res = new WsResponse(0, G::LoadTranslation("ID_UPDATED_SUCCESSFULLY"));
2018-07-25 14:37:42 -04:00
2018-07-25 09:25:25 -04:00
$result = [
"status_code" => $res->status_code,
"message" => $res->message,
"timestamp" => $res->timestamp
];
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* Information User
2017-12-04 13:25:35 +00:00
*
* @param string userUid : The user UID.
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
public function informationUser($userUid)
{
try {
if (empty($userUid)) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " userUid");
return $result;
}
$user = new Users();
$userInfo = $user->getAllInformation($userUid);
//Response
2017-08-15 16:03:21 -04:00
$res = new WsResponse(0, G::LoadTranslation("ID_COMMAND_EXECUTED_SUCCESSFULLY"));
$result = new stdClass();
$result->status_code = $res->status_code;
2017-08-15 16:03:21 -04:00
$result->message = $res->message;
$result->timestamp = $res->timestamp;
$result->info = $userInfo;
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* create Group
2012-10-09 13:29:25 -04:00
*
* @param string $groupName
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function createGroup($groupName)
{
try {
2017-08-15 16:03:21 -04:00
if (trim($groupName) == '') {
$result = new WsCreateGroupResponse(25, G::loadTranslation('ID_GROUP_NAME_REQUIRED'), '');
return $result;
}
$group = new Groupwf();
$grpRow['GRP_TITLE'] = $groupName;
2017-08-15 16:03:21 -04:00
$groupId = $group->create($grpRow);
2010-12-02 23:34:41 +00:00
$data['GROUP_NAME'] = $groupName;
2017-12-04 13:25:35 +00:00
$result = new WsCreateGroupResponse(
0,
G::loadTranslation('ID_GROUP_CREATED_SUCCESSFULLY', SYS_LANG, $data),
$groupId
);
return $result;
} catch (Exception $e) {
2017-08-17 16:29:53 -04:00
$result = WsCreateGroupResponse(100, $e->getMessage(), '');
2010-12-02 23:34:41 +00:00
return $result;
}
2010-12-02 23:34:41 +00:00
}
/**
* Create New Department link on the top section of the left pane allows you to create a root-level department.
2012-10-09 13:29:25 -04:00
*
* @param string $departmentName
* @param string $parentUID
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function createDepartment($departmentName, $parentUID)
{
try {
2017-08-15 16:03:21 -04:00
if (trim($departmentName) == '') {
$result = new WsCreateDepartmentResponse(25, G::loadTranslation('ID_DEPARTMENT_NAME_REQUIRED'), '');
return $result;
}
$department = new Department();
2017-08-15 16:03:21 -04:00
if (($parentUID != '') && !($department->existsDepartment($parentUID))) {
2017-12-04 13:25:35 +00:00
$result = new WsCreateDepartmentResponse(
26,
G::loadTranslation('ID_PARENT_DEPARTMENT_NOT_EXIST'),
$parentUID
);
return $result;
}
2017-08-15 16:03:21 -04:00
if ($department->checkDepartmentName($departmentName, $parentUID)) {
$result = new WsCreateDepartmentResponse(27, G::loadTranslation('ID_DEPARTMENT_EXISTS'), '');
return $result;
}
$row['DEP_TITLE'] = $departmentName;
$row['DEP_PARENT'] = $parentUID;
2017-08-15 16:03:21 -04:00
$departmentId = $department->create($row);
$data['DEPARTMENT_NAME'] = $departmentName;
2012-10-09 13:29:25 -04:00
$data['PARENT_UID'] = $parentUID;
$data['DEPARTMENT_NAME'] = $departmentName;
2017-12-04 13:25:35 +00:00
$result = new WsCreateDepartmentResponse(
0,
G::loadTranslation('ID_DEPARTMENT_CREATED_SUCCESSFULLY', SYS_LANG, $data),
$departmentId
);
return $result;
} catch (Exception $e) {
2017-08-17 16:29:53 -04:00
$result = WsCreateDepartmentResponse(100, $e->getMessage(), '');
return $result;
BUG 9043 Variable for Case Notes content needed SOLVED - Se crearon varias funciones para este caso. - La funcion getCaseNotes en la class.case.php con los parametros applicationID, type que es la forma que quiere que se devuelvan los datos, puede ser array, objetc, string por defecto esta en array, y userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - Se modifico la funcion getNotesList para poder traer las notas por un determinado usuario y por defecto recupera las notas de todos los usuarios. - en class.pmFunctions.php se creo la funcion PMFGetCaseNotes con los parametros applicationID, type que es la forma que quiere que se devuelvan los datos, puede ser array, objetc, string por defecto esta en array, y userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - En class.wsBase.php la funcion getCaseNotes con los parametros applicationID, userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios, esta funcion nos devuelve un array con los fieds en minuscula. - En soap2.php getCaseNotes donde se tienen los siguiente parametros: sessionId, se necesita iniciar una session para poder utilizarlo, applicationID, userID que nos daria solo las notas de ese usuario, por defecto nos devuelve de todos los usuarios. - Se adiciono la funcion para utilizarlo en SoapServer. - En wsResponse se creo un nuevo template para la respuesta del webservice wsGetCaseNotesResponse con los campos status_code, message, notes, timestamp. - En pmos2.wsdl se agregaron los datos necesarios para la salida correcta del webservice.
2012-05-02 09:56:30 -04:00
}
}
/**
* remove user from group
2012-10-09 13:29:25 -04:00
*
* @param string $appDocUid
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function removeUserFromGroup($userId, $groupId)
{
try {
global $RBAC;
$RBAC->initRBAC();
2017-08-15 16:03:21 -04:00
$user = $RBAC->verifyUserId($userId);
if ($user == 0) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(3, G::loadTranslation('ID_USER_NOT_REGISTERED_SYSTEM'));
return $result;
}
2012-10-09 13:29:25 -04:00
$groups = new Groups();
2017-08-15 16:03:21 -04:00
$very_group = $groups->verifyGroup($groupId);
if ($very_group == 0) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(9, G::loadTranslation('ID_GROUP_NOT_REGISTERED_SYSTEM'));
return $result;
}
2017-08-15 16:03:21 -04:00
$very_user = $groups->verifyUsertoGroup($groupId, $userId);
if ($very_user == 1) {
$oGroup = new Groups();
2017-08-15 16:03:21 -04:00
$oGroup->removeUserOfGroup($groupId, $userId);
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULY'));
return $result;
}
2017-08-15 16:03:21 -04:00
$result = new WsResponse(8, G::loadTranslation('ID_USER_NOT_REGISTERED_GROUP'));
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* assigns a user to a group
2012-10-09 13:29:25 -04:00
*
* @param string $userId
* @param string $groupId
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function assignUserToGroup($userId, $groupId)
{
try {
global $RBAC;
$RBAC->initRBAC();
2017-08-15 16:03:21 -04:00
$user = $RBAC->verifyUserId($userId);
if ($user == 0) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(3, G::loadTranslation('ID_USER_NOT_REGISTERED_SYSTEM'));
return $result;
}
$groups = new Groups();
2017-08-15 16:03:21 -04:00
$very_group = $groups->verifyGroup($groupId);
if ($very_group == 0) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(9, G::loadTranslation('ID_GROUP_NOT_REGISTERED_SYSTEM'));
return $result;
}
2017-08-15 16:03:21 -04:00
$very_user = $groups->verifyUsertoGroup($groupId, $userId);
if ($very_user == 1) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(8, G::loadTranslation('ID_USER_ALREADY_EXISTS_GROUP'));
return $result;
}
2017-08-15 16:03:21 -04:00
$groups->addUserToGroup($groupId, $userId);
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULY'));
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* assigns user to department
2012-10-09 13:29:25 -04:00
*
* @param string $userId
* @param string $depId
* @param string $manager
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function assignUserToDepartment($userId, $depId, $manager)
{
try {
global $RBAC;
$RBAC->initRBAC();
2017-08-15 16:03:21 -04:00
$user = $RBAC->verifyUserId($userId);
2012-10-09 13:29:25 -04:00
if ($user == 0) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(3, G::loadTranslation('ID_USER_NOT_REGISTERED_SYSTEM'));
return $result;
}
2012-10-09 13:29:25 -04:00
$deps = new Department();
2017-08-15 16:03:21 -04:00
if (!$deps->existsDepartment($depId)) {
$data['DEP_ID'] = $depId;
2017-12-04 13:25:35 +00:00
$result = new WsResponse(
100,
G::loadTranslation('ID_DEPARTMENT_NOT_REGISTERED_SYSTEM', SYS_LANG, $data)
);
return $result;
}
2017-08-15 16:03:21 -04:00
if (!$deps->existsUserInDepartment($depId, $userId)) {
$deps->addUserToDepartment($depId, $userId, $manager, true);
}
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULY'));
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* sends variables to a case
2012-10-09 13:29:25 -04:00
*
* @param string $caseId
* @param string $variables
2018-10-30 13:41:00 -04:00
* @param bool $forceToSave
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2018-10-30 13:41:00 -04:00
public function sendVariables($caseId, $variables, $forceToSave = false)
{
try {
2018-10-30 13:41:00 -04:00
if (!$forceToSave) {
$criteria = new Criteria('workflow');
$criteria->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
$criteria->add(AppDelegationPeer::APP_UID, $caseId);
$criteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
2018-10-30 13:41:00 -04:00
$criteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
$dataset = AppDelegationPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2018-10-30 13:41:00 -04:00
$cnt = 0;
2018-10-30 13:41:00 -04:00
while ($dataset->next()) {
$row = $dataset->getRow();
$cnt++;
}
2018-10-30 13:41:00 -04:00
if ($cnt == 0) {
$result = new WsResponse(18, G::loadTranslation('ID_CASE_DELEGATION_ALREADY_CLOSED'));
2018-10-30 13:41:00 -04:00
return $result;
}
}
2017-08-15 16:03:21 -04:00
if (is_array($variables)) {
$cant = count($variables);
if ($cant > 0) {
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$oldFields = $oCase->loadCase($caseId);
$oldFields['APP_DATA'] = array_merge($oldFields['APP_DATA'], $variables);
ob_start();
2017-08-15 16:03:21 -04:00
print_r($variables);
$cdata = ob_get_contents();
ob_end_clean();
2017-08-15 16:03:21 -04:00
$up_case = $oCase->updateCase($caseId, $oldFields);
2017-12-04 13:25:35 +00:00
$result = new WsResponse(
0,
$cant . " " . G::loadTranslation('ID_VARIABLES_RECEIVED') . ": \n" . trim(str_replace(
'Array',
'',
$cdata
))
);
return $result;
} else {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(23, G::loadTranslation('ID_VARIABLES_PARAM_ZERO'));
return $result;
}
} else {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(24, G::loadTranslation('ID_VARIABLES_PARAM_NOT_ARRAY'));
return $result;
}
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
2012-10-09 13:29:25 -04:00
* get variables The variables can be system variables and/or case variables
*
* @param string $caseId
* @param string $variables
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function getVariables($caseId, $variables)
{
try {
2017-08-15 16:03:21 -04:00
if (is_array($variables)) {
$cant = count($variables);
if ($cant > 0) {
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$caseFields = $oCase->loadCase($caseId);
2012-10-09 13:29:25 -04:00
$oldFields = $caseFields['APP_DATA'];
2017-10-17 11:45:53 -04:00
$resFields = [];
foreach ($variables as $key => $val) {
$a .= $val->name . ', ';
2017-08-15 16:03:21 -04:00
if (isset($oldFields[$val->name])) {
if (!is_array($oldFields[$val->name])) {
2012-10-09 13:29:25 -04:00
$node = new stdClass();
$node->name = $val->name;
$node->value = $oldFields[$val->name];
$resFields[] = $node;
} else {
foreach ($oldFields[$val->name] as $gridKey => $gridRow) {
//Special Variables like grids or checkgroups
2017-08-15 16:03:21 -04:00
if (is_array($gridRow)) {
//Grids
foreach ($gridRow as $col => $colValue) {
2012-10-09 13:29:25 -04:00
$node = new stdClass();
$node->name = $val->name . "][" . $gridKey . "][" . $col;
$node->value = $colValue;
$resFields[] = $node;
}
} else {
//Checkgroups, Radiogroups
2012-10-09 13:29:25 -04:00
$node = new stdClass();
$node->name = $key;
2017-08-15 16:03:21 -04:00
$node->value = implode("|", $val);
$resFields[] = $node;
}
}
}
}
}
2017-12-04 13:25:35 +00:00
$result = new WsGetVariableResponse(
0,
count($resFields) . G::loadTranslation('ID_VARIABLES_SENT'),
$resFields
);
return $result;
} else {
2017-08-17 16:29:53 -04:00
$result = new WsGetVariableResponse(23, G::loadTranslation('ID_VARIABLES_PARAM_ZERO'), null);
return $result;
}
} else {
2017-08-17 16:29:53 -04:00
$result = new WsGetVariableResponse(24, G::loadTranslation('ID_VARIABLES_PARAM_NOT_ARRAY'), null);
return $result;
}
} catch (Exception $e) {
2017-08-17 16:29:53 -04:00
$result = new WsGetVariableResponse(100, $e->getMessage(), null);
return $result;
}
}
/**
2012-10-09 13:29:25 -04:00
* get all variables the system and case selected
*
* @param string $caseId
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function getVariablesNames($caseId)
{
try {
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$caseFields = $oCase->loadCase($caseId);
2012-10-09 13:29:25 -04:00
$oldFields = $caseFields['APP_DATA'];
2017-10-17 11:45:53 -04:00
$resFields = [];
foreach ($oldFields as $key => $val) {
$node = new stdClass();
2012-10-09 13:29:25 -04:00
$node->name = $key;
$resFields[] = $node;
}
2017-12-04 13:25:35 +00:00
$result = new WsGetVariableResponse(
0,
count($resFields) . G::loadTranslation('ID_VARIABLES_SENT'),
$resFields
);
return $result;
} catch (Exception $e) {
2017-08-17 16:29:53 -04:00
$result = new WsGetVariableResponse(100, $e->getMessage(), null);
return $result;
}
}
/**
* new Case begins a new case under the name of the logged-in user.
*
* @param string $processId
* @param string $userId
* @param string $taskId
* @param string $variables
2017-12-04 13:25:35 +00:00
* @param int $executeTriggers : Optional parameter. The execution all triggers of the task, according to your
* steps, 1 yes 0 no.
2016-11-18 15:47:39 -05:00
* @param string $status
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2016-11-18 15:47:39 -05:00
public function newCase($processId, $userId, $taskId, $variables, $executeTriggers = 0, $status = 'DRAFT')
{
//$executeTriggers, this parameter is not important, it may be the last parameter in the method
$g = new G();
try {
$g->sessionVarSave();
$_SESSION["PROCESS"] = $processId;
$_SESSION["TASK"] = $taskId;
$_SESSION["USER_LOGGED"] = $userId;
2017-10-17 11:45:53 -04:00
$Fields = [];
2017-08-15 16:03:21 -04:00
if (is_array($variables) && count($variables) > 0) {
$Fields = $variables;
}
2012-10-12 12:52:50 -04:00
$oProcesses = new Processes();
2017-08-15 16:03:21 -04:00
$pro = $oProcesses->processExists($processId);
2017-08-15 16:03:21 -04:00
if (!$pro) {
$result = new WsResponse(11, G::LoadTranslation('ID_INVALID_PROCESS') . " " . $processId);
$g->sessionVarRestore();
return $result;
}
2012-10-12 12:52:50 -04:00
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$startingTasks = $oCase->getStartCases($userId);
array_shift($startingTasks); //remove the first row, the header row
2012-10-09 13:29:25 -04:00
$founded = '';
$tasksInThisProcess = 0;
2012-10-09 13:29:25 -04:00
$validTaskId = $taskId;
foreach ($startingTasks as $key => $val) {
if ($val['pro_uid'] == $processId) {
2017-12-04 13:25:35 +00:00
$tasksInThisProcess++;
$validTaskId = $val['uid'];
}
if ($val['uid'] == $taskId) {
$founded = $val['value'];
}
}
if ($taskId == '') {
if ($tasksInThisProcess == 1) {
$founded = $validTaskId;
2012-10-09 13:29:25 -04:00
$taskId = $validTaskId;
}
if ($tasksInThisProcess > 1) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(13, G::LoadTranslation('ID_MULTIPLE_STARTING_TASKS'));
$g->sessionVarRestore();
return $result;
}
}
$task = TaskPeer::retrieveByPK($taskId);
$arrayTaskTypeToExclude = array("START-TIMER-EVENT", "START-MESSAGE-EVENT");
if (!is_null($task) && !in_array($task->getTasType(), $arrayTaskTypeToExclude) && $founded == "") {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(14, G::LoadTranslation('ID_TASK_INVALID_USER_NOT_ASSIGNED_TASK'));
$g->sessionVarRestore();
return $result;
}
2012-10-12 12:52:50 -04:00
//Start case
2017-08-15 16:03:21 -04:00
$case = $oCase->startCase($taskId, $userId);
2012-10-09 13:29:25 -04:00
$_SESSION['APPLICATION'] = $case['APPLICATION'];
$_SESSION['PROCESS'] = $case['PROCESS'];
$_SESSION['TASK'] = $taskId;
$_SESSION['INDEX'] = $case['INDEX'];
$_SESSION['USER_LOGGED'] = $userId;
$_SESSION['USR_USERNAME'] = (isset($case['USR_USERNAME'])) ? $case['USR_USERNAME'] : '';
$_SESSION['STEP_POSITION'] = 0;
$caseId = $case['APPLICATION'];
$caseNr = $case['CASE_NUMBER'];
2012-10-12 12:52:50 -04:00
2017-08-15 16:03:21 -04:00
$oldFields = $oCase->loadCase($caseId);
2012-10-12 12:52:50 -04:00
2017-08-15 16:03:21 -04:00
$oldFields['APP_DATA'] = array_merge($oldFields['APP_DATA'], $Fields);
2012-10-12 12:52:50 -04:00
$oldFields['DEL_INDEX'] = $case['INDEX'];
$oldFields['TAS_UID'] = $taskId;
2016-11-18 15:47:39 -05:00
if (!is_null($status) && $status != 'DRAFT') {
$oldFields['APP_STATUS'] = $status;
}
2017-08-15 16:03:21 -04:00
$up_case = $oCase->updateCase($caseId, $oldFields);
2012-10-12 12:52:50 -04:00
//Execute all triggers of the task, according to your steps
if ($executeTriggers == 1) {
$task = new Tasks();
$arrayStep = $task->getStepsOfTask($taskId);
foreach ($arrayStep as $step) {
$arrayField = $oCase->loadCase($caseId);
2017-12-04 13:25:35 +00:00
$arrayField["APP_DATA"] = $oCase->executeTriggers(
$taskId,
$step["STEP_TYPE_OBJ"],
$step["STEP_UID_OBJ"],
"BEFORE",
$arrayField["APP_DATA"]
);
$arrayField["APP_DATA"] = $oCase->executeTriggers(
$taskId,
$step["STEP_TYPE_OBJ"],
$step["STEP_UID_OBJ"],
"AFTER",
$arrayField["APP_DATA"]
);
unset($arrayField['APP_STATUS']);
unset($arrayField['APP_PROC_STATUS']);
unset($arrayField['APP_PROC_CODE']);
unset($arrayField['APP_PIN']);
$arrayField = $oCase->updateCase($caseId, $arrayField);
}
}
//Response
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::LoadTranslation('ID_STARTED_SUCCESSFULLY'));
2012-10-09 13:29:25 -04:00
$result->caseId = $caseId;
$result->caseNumber = $caseNr;
$g->sessionVarRestore();
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
$g->sessionVarRestore();
return $result;
}
}
/**
2019-01-15 13:59:13 -04:00
* Creates a new case impersonating a user who has the proper privileges to create new cases
2012-10-09 13:29:25 -04:00
*
* @param string $processId
* @param string $userId
2019-01-15 13:59:13 -04:00
* @param array $variables, that are set in the new case
* @param string $taskId, must be in the starting group.
2017-12-04 13:25:35 +00:00
*
2019-01-15 13:59:13 -04:00
* @return object
*
* @see PMFNewCaseImpersonate/class.pmFunctions.php on
* @link https://wiki.processmaker.com/3.1/ProcessMaker_Functions#PMFNewCaseImpersonate.28.29
*
* @see doPostCaseImpersonate/Api/Cases on
* @link https://wiki.processmaker.com/3.2/REST_API_Cases/Cases#New_Case_Impersonate_User:_POST_.2Fcases.2Fimpersonate
*
* @see NewCaseImpersonate/soap2.php on
* @link https://wiki.processmaker.com/3.0/ProcessMaker_WSDL_Web_Services#newCaseImpersonate.28.29
*/
2017-08-15 16:03:21 -04:00
public function newCaseImpersonate($processId, $userId, $variables, $taskId = '')
{
try {
2019-01-15 13:59:13 -04:00
$g = new G();
$g->sessionVarSave();
$c = count($variables);
2017-08-15 16:03:21 -04:00
if (is_array($variables)) {
2019-01-15 13:59:13 -04:00
if ($c > 0) {
$fieldsVariables = $variables;
} elseif ($c === 0) {
$result = new WsResponse(10, G::loadTranslation('ID_ARRAY_VARIABLES_EMPTY'));
$g->sessionVarRestore();
2019-01-15 13:59:13 -04:00
return $result;
}
} else {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(10, G::loadTranslation('ID_VARIABLES_PARAM_NOT_ARRAY'));
2019-01-15 13:59:13 -04:00
$g->sessionVarRestore();
return $result;
}
$processes = new Processes();
2017-08-15 16:03:21 -04:00
if (!$processes->processExists($processId)) {
$result = new WsResponse(11, G::loadTranslation('ID_INVALID_PROCESS') . " " . $processId . "!!");
2019-01-15 13:59:13 -04:00
$g->sessionVarRestore();
return $result;
}
$user = new Users();
2017-08-15 16:03:21 -04:00
if (!$user->userExists($userId)) {
$result = new WsResponse(11, G::loadTranslation('ID_USER_NOT_REGISTERED') . " " . $userId . "!!");
2019-01-15 13:59:13 -04:00
$g->sessionVarRestore();
return $result;
2019-01-15 13:59:13 -04:00
} else {
$user->load($userId);
$userName = $user->getUsrUsername();
}
2019-01-15 13:59:13 -04:00
$caseInstance = new Cases();
$numTasks = 0;
2019-01-15 13:59:13 -04:00
if (!empty($taskId)) {
$startTasks = $processes->getStartingTaskForUser($processId, null);
foreach ($startTasks as $task) {
2013-03-19 13:47:16 -04:00
if ($task['TAS_UID'] == $taskId) {
$arrayTask[0]['TAS_UID'] = $taskId;
$numTasks = 1;
}
}
} else {
2017-08-15 16:03:21 -04:00
$arrayTask = $processes->getStartingTaskForUser($processId, null);
$numTasks = count($arrayTask);
}
2019-01-15 13:59:13 -04:00
if ($numTasks === 1) {
//@todo Find a better way to define session variables
$_SESSION["PROCESS"] = $processId;
$_SESSION["TASK"] = $arrayTask[0]['TAS_UID'];
$_SESSION["USER_LOGGED"] = $userId;
$_SESSION["INDEX"] = 1;
$_SESSION["USR_USERNAME"] = $userName;
2019-01-15 13:59:13 -04:00
//Create a newCase
$infoCase = $caseInstance->startCase($arrayTask[0]['TAS_UID'], $userId);
$_SESSION["APPLICATION"] = $caseId = $infoCase['APPLICATION'];
$oldFields = $caseInstance->loadCase($caseId);
//Merge the data with the $fieldsVariables that are set in the new case
$oldFields['APP_DATA'] = array_merge($oldFields['APP_DATA'], $fieldsVariables);
2019-01-15 13:59:13 -04:00
//Update the case
$res = $caseInstance->updateCase($caseId, $oldFields);
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULLY'));
2012-10-09 13:29:25 -04:00
$result->caseId = $caseId;
2019-01-15 13:59:13 -04:00
$result->caseNumber = $infoCase['CASE_NUMBER'];
$g->sessionVarRestore();
return $result;
} else {
2019-01-15 13:59:13 -04:00
if ($numTasks === 0) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(12, G::loadTranslation('ID_NO_STARTING_TASK'));
2019-01-15 13:59:13 -04:00
$g->sessionVarRestore();
return $result;
}
if ($numTasks > 1) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(13, G::loadTranslation('ID_MULTIPLE_STARTING_TASKS'));
2019-01-15 13:59:13 -04:00
$g->sessionVarRestore();
return $result;
}
}
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
2019-01-15 13:59:13 -04:00
$g->sessionVarRestore();
return $result;
}
}
2017-08-15 16:03:21 -04:00
2017-04-17 10:34:30 -04:00
/**
* Execute the trigger defined in the steps
* This function is used when the case is derived from abe, Soap, PMFDerivateCase
*
2018-11-21 16:32:48 -04:00
* @param string $appUid , Uid related to the case
2017-12-04 13:25:35 +00:00
* @param array $appData , contain all the information about the case related to the index [APP_DATA]
* @param string $tasUid , Uid related to the task
* @param string $stepType , before or after step
* @param string $stepUidObj , can be -1, -2
* @param string $triggerType , can be BEFORE, AFTER
* @param string $labelAssignment , label related to the triggerType
2017-09-29 10:33:41 -04:00
*
* @return string $varTriggers updated
2019-01-30 09:11:57 -04:00
*
* @see WsBase::derivateCase()
2017-04-17 10:34:30 -04:00
*/
2017-08-15 16:03:21 -04:00
public function executeTriggerFromDerivate(
2018-11-21 16:32:48 -04:00
$appUid,
2018-01-30 10:55:41 -04:00
&$appData,
2017-09-29 10:33:41 -04:00
$tasUid,
$stepType,
$stepUidObj,
$triggerType,
$labelAssignment = ''
2017-12-04 13:25:35 +00:00
)
{
2018-11-21 16:32:48 -04:00
$caseInstance = new Cases();
//Set new variables in the APP_DATA
$params = new stdClass();
$params->appData = $appData;
if ($this->stored_system_variables) {
$params->option = "STORED SESSION";
$params->SID = $this->wsSessionId;
}
$appFields["APP_DATA"] = array_merge($appData, G::getSystemConstants($params));
2017-04-17 10:34:30 -04:00
2018-11-21 16:32:48 -04:00
//Load the triggers assigned in the step
$triggersList = $caseInstance->loadTriggers($tasUid, $stepType, $stepUidObj, $triggerType);
2017-04-17 10:34:30 -04:00
2018-11-21 16:32:48 -04:00
//Execute the trigger defined in the step
$lastFields = $caseInstance->executeTriggerFromList($triggersList, $appFields["APP_DATA"], $stepType, $stepUidObj, $triggerType, $labelAssignment);
2017-04-17 10:34:30 -04:00
2018-11-21 16:32:48 -04:00
//Get message of the execution
$varTriggers = $caseInstance->getTriggerMessageExecution();
2017-04-17 10:34:30 -04:00
2018-11-21 16:32:48 -04:00
//Define the new APP_DATA
$appFields['APP_DATA'] = $lastFields;
unset($appFields['APP_STATUS']);
unset($appFields['APP_PROC_STATUS']);
unset($appFields['APP_PROC_CODE']);
unset($appFields['APP_PIN']);
2017-04-17 10:34:30 -04:00
2018-11-21 16:32:48 -04:00
//Update the APP_DATA
$caseInstance->updateCase($appUid, $appFields);
2017-04-17 10:34:30 -04:00
2018-11-21 16:32:48 -04:00
//We need to update the variable $appData for use the new variables in the next trigger
$appData = array_merge($appData, $appFields['APP_DATA']);
2018-06-04 12:33:56 -04:00
2018-06-11 09:58:48 -04:00
/*----------------------------------********---------------------------------*/
2018-06-04 12:33:56 -04:00
ChangeLog::getChangeLog()
2018-11-21 16:32:48 -04:00
->setDate('now')
->setAppNumber($appData['APP_NUMBER'])
->setDelIndex($appData['INDEX'])
->getProIdByProUid($appData['PROCESS'])
->getTasIdByTasUid($appData['TASK'])
->setData(serialize($appData))
->getExecutedAtIdByTriggerType($triggerType)
->getObjectIdByUidAndObjType($stepUidObj, $stepType);
2018-06-11 09:58:48 -04:00
/*----------------------------------********---------------------------------*/
2018-06-04 12:33:56 -04:00
2017-04-17 10:34:30 -04:00
return $varTriggers;
}
/**
2017-04-17 10:34:30 -04:00
* Derivate Case moves the case to the next task in the process according to the routing rules
2017-04-17 11:17:08 -04:00
* This function is used from: action by email, web entry, PMFDerivateCase, Mobile
2017-12-04 13:25:35 +00:00
*
* @param string $userId
* @param string $caseId
2019-01-30 09:11:57 -04:00
* @param integer $delIndex
2017-12-04 13:25:35 +00:00
* @param bool $bExecuteTriggersBeforeAssignment
2019-01-30 09:11:57 -04:00
* @param array $tasks
*
* @return $result will return an object
2019-01-30 09:11:57 -04:00
*
* @see PMFDerivateCase()/class.pmFunctions.php on
* @link https://wiki.processmaker.com/3.2/ProcessMaker_Functions/Case_Routing_Functions#PMFDerivateCase.28.29
*/
2017-10-17 11:45:53 -04:00
public function derivateCase($userId, $caseId, $delIndex, $bExecuteTriggersBeforeAssignment = false, $tasks = [])
{
$g = new G();
try {
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseId;
$_SESSION["INDEX"] = $delIndex;
$_SESSION["USER_LOGGED"] = $userId;
2017-04-17 10:34:30 -04:00
//Define variables
$sStatus = 'TO_DO';
$varResponse = '';
2017-10-17 11:45:53 -04:00
$previousAppData = [];
2017-04-11 11:13:28 -04:00
if ($delIndex == '') {
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
$oCriteria->add(AppDelegationPeer::APP_UID, $caseId);
$oCriteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
2017-08-15 16:03:21 -04:00
if (AppDelegationPeer::doCount($oCriteria) > 1) {
$result = new WsResponse(20, G::LoadTranslation('ID_SPECIFY_DELEGATION_INDEX'));
return $result;
}
2017-08-15 16:03:21 -04:00
$oDataset = AppDelegationPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
2012-10-09 13:29:25 -04:00
$aRow = $oDataset->getRow();
$delIndex = $aRow['DEL_INDEX'];
}
$oAppDel = new AppDelegation();
2017-08-15 16:03:21 -04:00
$appdel = $oAppDel->Load($caseId, $delIndex);
if ($userId != $appdel['USR_UID']) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(17, G::LoadTranslation('ID_CASE_ASSIGNED_ANOTHER_USER'));
return $result;
}
if ($appdel['DEL_FINISH_DATE'] != null) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(18, G::LoadTranslation('ID_CASE_DELEGATION_ALREADY_CLOSED'));
return $result;
}
2017-04-17 10:34:30 -04:00
//Validate if the case is paused or cancelled
$oAppDelay = new AppDelay();
$aRow = $oAppDelay->getCasesCancelOrPaused($caseId);
if (is_array($aRow)) {
2017-08-15 16:03:21 -04:00
if (isset($aRow['APP_DISABLE_ACTION_USER']) && $aRow['APP_DISABLE_ACTION_USER'] != 0 && isset($aRow['APP_DISABLE_ACTION_DATE']) && $aRow['APP_DISABLE_ACTION_DATE'] != '') {
$result = new WsResponse(19, G::LoadTranslation('ID_CASE_IN_STATUS') . " " . $aRow['APP_TYPE']);
return $result;
}
}
2017-10-17 11:45:53 -04:00
$aData = [];
2012-10-09 13:29:25 -04:00
$aData['APP_UID'] = $caseId;
$aData['DEL_INDEX'] = $delIndex;
2012-10-09 13:29:25 -04:00
$aData['USER_UID'] = $userId;
//Load data
2012-10-09 13:29:25 -04:00
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$appFields = $oCase->loadCase($caseId, $delIndex);
2017-08-15 16:03:21 -04:00
if (is_null($appFields["DEL_INIT_DATE"])) {
$oCase->setDelInitDate($caseId, $delIndex);
$appFields = $oCase->loadCase($caseId, $delIndex);
}
2016-08-05 17:38:31 -04:00
unset($appFields['APP_ROUTING_DATA']);
$appFields["APP_DATA"]["APPLICATION"] = $caseId;
2017-08-15 16:03:21 -04:00
if (!isset($_SESSION["PROCESS"])) {
$_SESSION["PROCESS"] = $appFields["PRO_UID"];
}
2016-08-24 16:06:01 -04:00
global $oPMScript;
2017-04-11 11:13:28 -04:00
if (isset($oPMScript->aFields['APPLICATION']) && ($oPMScript->aFields['APPLICATION'] != $caseId)) {
$previousAppData = $oPMScript->aFields;
}
2017-04-17 11:17:08 -04:00
$varTriggers = "\n";
2017-04-17 10:34:30 -04:00
//Execute triggers before assignment
if ($bExecuteTriggersBeforeAssignment) {
2017-12-04 13:25:35 +00:00
$varTriggers .= $this->executeTriggerFromDerivate(
$caseId,
$appFields["APP_DATA"],
$appdel['TAS_UID'],
'ASSIGN_TASK',
-1,
'BEFORE',
"-= Before Assignment =-"
);
}
2017-04-17 10:34:30 -04:00
//Execute triggers before routing
2017-12-04 13:25:35 +00:00
$varTriggers .= $this->executeTriggerFromDerivate(
$caseId,
$appFields["APP_DATA"],
$appdel['TAS_UID'],
'ASSIGN_TASK',
-2,
'BEFORE',
"-= Before Derivation =-"
);
$oDerivation = new Derivation();
if (!empty($tasks)) {
$nextDelegations = $tasks;
} else {
$derive = $oDerivation->prepareInformation($aData);
if (isset($derive[1])) {
if ($derive[1]['ROU_TYPE'] == 'SELECT') {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(21, G::LoadTranslation('ID_CAN_NOT_ROUTE_CASE_USING_WEBSERVICES'));
return $result;
}
} else {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(22, G::LoadTranslation('ID_TASK_DOES_NOT_HAVE_ROUTING_RULE'));
return $result;
}
foreach ($derive as $key => $val) {
//Routed to the next task, if end process then not exist user
2017-10-17 11:45:53 -04:00
$nodeNext = [];
$usrasgdUid = null;
$usrasgdUserName = null;
if (isset($val['NEXT_TASK']['USER_ASSIGNED'])) {
2015-12-22 15:16:17 -04:00
$usrasgdUid = '';
2017-08-15 16:03:21 -04:00
if (isset($val['NEXT_TASK']['USER_ASSIGNED']['USR_UID'])) {
2015-12-22 15:16:17 -04:00
$usrasgdUid = $val['NEXT_TASK']['USER_ASSIGNED']['USR_UID'];
}
2017-08-15 16:03:21 -04:00
if (isset($val['NEXT_TASK']['USER_ASSIGNED']['USR_USERNAME'])) {
$usrasgdUserName = '(' . $val['NEXT_TASK']['USER_ASSIGNED']['USR_USERNAME'] . ')';
} else {
$usrasgdUserName = '';
2015-12-18 13:05:55 -04:00
}
}
$nodeNext['TAS_UID'] = $val['NEXT_TASK']['TAS_UID'];
$nodeNext['USR_UID'] = $usrasgdUid;
$nodeNext['TAS_ASSIGN_TYPE'] = $val['NEXT_TASK']['TAS_ASSIGN_TYPE'];
$nodeNext['TAS_DEF_PROC_CODE'] = $val['NEXT_TASK']['TAS_DEF_PROC_CODE'];
$nodeNext['DEL_PRIORITY'] = $appdel['DEL_PRIORITY'];
$nodeNext['TAS_PARENT'] = $val['NEXT_TASK']['TAS_PARENT'];
2017-04-17 10:34:30 -04:00
$nodeNext['ROU_PREVIOUS_TYPE'] = (isset($val['NEXT_TASK']['ROU_PREVIOUS_TYPE'])) ? $val['NEXT_TASK']['ROU_PREVIOUS_TYPE'] : '';
$nodeNext['ROU_PREVIOUS_TASK'] = (isset($val['NEXT_TASK']['ROU_PREVIOUS_TASK'])) ? $val['NEXT_TASK']['ROU_PREVIOUS_TASK'] : '';
$nextDelegations[] = $nodeNext;
$varResponse = $varResponse . (($varResponse != '') ? ',' : '') . $val['NEXT_TASK']['TAS_TITLE'] . $usrasgdUserName;
}
}
$appFields['DEL_INDEX'] = $delIndex;
2017-08-15 16:03:21 -04:00
if (isset($derive['TAS_UID'])) {
2012-10-09 13:29:25 -04:00
$appFields['TAS_UID'] = $derive['TAS_UID'];
}
2017-04-17 10:34:30 -04:00
//Get from the route information the nextTask
$nextTaskUid = $appdel['TAS_UID'];
$nextRouteType = '';
do {
$oRoute = new \Route();
$nextRouteTask = $oRoute->getNextRouteByTask($nextTaskUid);
$prefix = '';
if (isset($nextRouteTask['ROU_NEXT_TASK'])) {
$nextTaskUid = $nextRouteTask['ROU_NEXT_TASK'];
$nextRouteType = $nextRouteTask['ROU_TYPE'];
$prefix = substr($nextTaskUid, 0, 4);
}
} while ($prefix == 'gtg-');
2017-08-15 16:03:21 -04:00
$aCurrentDerivation = array(
2017-03-03 15:22:25 -04:00
'APP_UID' => $caseId,
'DEL_INDEX' => $delIndex,
'APP_STATUS' => $sStatus,
'TAS_UID' => $appdel['TAS_UID'],
2017-04-17 10:34:30 -04:00
'ROU_TYPE' => $nextRouteType
2017-03-03 15:22:25 -04:00
);
//We define some parameters in the before the derivation
//Then this function will be route the case
$oDerivation->beforeDerivate(
2017-12-04 13:25:35 +00:00
$aData,
$nextDelegations,
$nextRouteType,
$aCurrentDerivation
);
2017-03-03 15:22:25 -04:00
2017-04-17 10:34:30 -04:00
//Execute triggers after routing
2018-05-16 21:48:52 -04:00
$appFields = $oCase->loadCase($caseId);
2017-12-04 13:25:35 +00:00
$varTriggers .= $this->executeTriggerFromDerivate(
$caseId,
$appFields["APP_DATA"],
$appdel['TAS_UID'],
'ASSIGN_TASK',
-2,
'AFTER',
"-= After Derivation =-"
);
$sFromName = "";
if ($userId != "") {
$user = new Users();
$arrayUserData = $user->load($userId);
if (trim($arrayUserData["USR_EMAIL"]) == "") {
2018-10-19 17:01:49 -04:00
$arrayUserData["USR_EMAIL"] = "info@" . System::getDefaultMailDomain();
}
$sFromName = "\"" . $arrayUserData["USR_FIRSTNAME"] . " " . $arrayUserData["USR_LASTNAME"] . "\" <" . $arrayUserData["USR_EMAIL"] . ">";
}
2018-04-04 09:21:59 -04:00
$process = new Process();
$processFieds = $process->Load($appFields['PRO_UID']);
$appFields['APP_DATA']['PRO_ID'] = $processFieds['PRO_ID'];
2018-04-04 09:21:59 -04:00
$oCase->sendNotifications(
$appdel['TAS_UID'],
$nextDelegations,
$appFields['APP_DATA'],
$caseId,
$delIndex,
$sFromName
);
2012-10-09 13:29:25 -04:00
2018-04-04 09:21:59 -04:00
//here debug mode in web entry
if (isset($processFieds['PRO_DEBUG']) && $processFieds['PRO_DEBUG']) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, $varResponse . "
<br><br><table width='100%' cellpadding='0' cellspacing='0'><tr><td class='FormTitle'>
2017-08-15 16:03:21 -04:00
" . G::LoadTranslation('ID_DEBUG_MESSAGE') . "</td></tr></table>" . $varTriggers);
} else {
2018-04-04 09:21:59 -04:00
$result = new WsResponse(0, $varResponse . " --- " . $processFieds['PRO_DEBUG']);
}
$res = $result->getPayloadArray();
2017-08-15 16:03:21 -04:00
2017-04-17 10:34:30 -04:00
//Now fill the array of AppDelegationPeer
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
$oCriteria->addSelectColumn(AppDelegationPeer::USR_UID);
$oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_THREAD);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_THREAD_STATUS);
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
$oCriteria->add(AppDelegationPeer::APP_UID, $caseId);
$oCriteria->add(AppDelegationPeer::DEL_PREVIOUS, $delIndex);
$oCriteria->addAscendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
$oDataset = AppDelegationPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
2017-10-17 11:45:53 -04:00
$aCurrentUsers = [];
while ($oDataset->next()) {
$aAppDel = $oDataset->getRow();
$oUser = new Users();
try {
2017-08-15 16:03:21 -04:00
$oUser->load($aAppDel['USR_UID']);
$uFields = $oUser->toArray(BasePeer::TYPE_FIELDNAME);
$currentUserName = $oUser->getUsrFirstname() . ' ' . $oUser->getUsrLastname();
} catch (Exception $e) {
$currentUserName = '';
}
$oTask = new Task();
try {
2017-08-15 16:03:21 -04:00
$uFields = $oTask->load($aAppDel['TAS_UID']);
$taskName = $uFields['TAS_TITLE'];
} catch (Exception $e) {
$taskName = '';
}
2017-04-17 10:34:30 -04:00
//Execute events
2017-05-25 16:07:32 -04:00
$eventPro = $appFields['PRO_UID'];
$eventApp = $caseId;
$eventInd = $aAppDel['DEL_INDEX'];
$eventTas = $aAppDel['TAS_UID'];
$oEvent = new Event();
2017-08-15 16:03:21 -04:00
$oEvent->createAppEvents($eventPro, $eventApp, $eventInd, $eventTas);
2017-04-17 10:34:30 -04:00
//End events
2012-10-09 13:29:25 -04:00
$currentUser = new stdClass();
2012-10-09 13:29:25 -04:00
$currentUser->userId = $aAppDel['USR_UID'];
$currentUser->userName = $currentUserName;
$currentUser->taskId = $aAppDel['TAS_UID'];
$currentUser->taskName = $taskName;
$currentUser->delIndex = $aAppDel['DEL_INDEX'];
$currentUser->delThread = $aAppDel['DEL_THREAD'];
$currentUser->delThreadStatus = $aAppDel['DEL_THREAD_STATUS'];
$aCurrentUsers[] = $currentUser;
}
$res['routing'] = $aCurrentUsers;
$g->sessionVarRestore();
2017-04-11 11:13:28 -04:00
if (!empty($previousAppData)) {
$oPMScript->aFields = $previousAppData;
}
return $res;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
$g->sessionVarRestore();
return $result;
}
}
/**
2012-10-09 13:29:25 -04:00
* execute Trigger, executes a ProcessMaker trigger.
* Note that triggers which are tied to case derivation
* will executing automatically.
2012-10-09 13:29:25 -04:00
*
* @param string $userId
* @param string $caseId
* @param string $delIndex
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function executeTrigger($userId, $caseId, $triggerIndex, $delIndex)
{
$g = new G();
try {
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseId;
$_SESSION["INDEX"] = $delIndex;
$_SESSION["USER_LOGGED"] = $userId;
$oAppDel = new AppDelegation();
2017-08-15 16:03:21 -04:00
$appdel = $oAppDel->Load($caseId, $delIndex);
2012-10-09 13:29:25 -04:00
if ($userId != $appdel['USR_UID']) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(17, G::loadTranslation('ID_CASE_ASSIGNED_ANOTHER_USER'));
$g->sessionVarRestore();
return $result;
}
if ($appdel['DEL_FINISH_DATE'] != null) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(18, G::loadTranslation('ID_CASE_DELEGATION_ALREADY_CLOSED'));
$g->sessionVarRestore();
return $result;
}
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(AppDelayPeer::APP_UID);
$oCriteria->addSelectColumn(AppDelayPeer::APP_DEL_INDEX);
$oCriteria->addSelectColumn(AppDelayPeer::APP_TYPE);
$oCriteria->addSelectColumn(AppDelayPeer::APP_DISABLE_ACTION_USER);
$oCriteria->addSelectColumn(AppDelayPeer::APP_DISABLE_ACTION_DATE);
$oCriteria->add(AppDelayPeer::APP_UID, $caseId);
2017-12-04 13:25:35 +00:00
$oCriteria->add($oCriteria->getNewCriterion(
AppDelayPeer::APP_TYPE,
'PAUSE'
)->addOr($oCriteria->getNewCriterion(AppDelayPeer::APP_TYPE, 'CANCEL')));
2017-08-15 16:03:21 -04:00
$oCriteria->addAscendingOrderByColumn(AppDelayPeer::APP_ENABLE_ACTION_DATE);
$oDataset = AppDelayPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$aRow = $oDataset->getRow();
2017-08-15 16:03:21 -04:00
if (is_array($aRow)) {
if ($aRow['APP_DISABLE_ACTION_USER'] == 0 || is_null($aRow['APP_DISABLE_ACTION_DATE'])) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(19, G::loadTranslation('ID_CASE_IN_STATUS') . " " . $aRow['APP_TYPE']);
$g->sessionVarRestore();
return $result;
}
}
//Load data
2012-10-09 13:29:25 -04:00
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$appFields = $oCase->loadCase($caseId);
$appFields["APP_DATA"]["APPLICATION"] = $caseId;
2017-08-15 16:03:21 -04:00
if (!isset($_SESSION["PROCESS"])) {
$_SESSION["PROCESS"] = $appFields["PRO_UID"];
}
//executeTrigger
2017-10-17 11:45:53 -04:00
$aTriggers = [];
$c = new Criteria();
2017-08-15 16:03:21 -04:00
$c->add(TriggersPeer::TRI_UID, $triggerIndex);
$rs = TriggersPeer::doSelectRS($c);
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$rs->next();
$row = $rs->getRow();
2017-08-15 16:03:21 -04:00
if (is_array($row) && $row['TRI_TYPE'] == 'SCRIPT') {
$aTriggers[] = $row;
$oPMScript = new PMScript();
$oPMScript->setDataTrigger($row);
2017-08-15 16:03:21 -04:00
$oPMScript->setFields($appFields['APP_DATA']);
$oPMScript->setScript($row['TRI_WEBBOT']);
2018-10-30 13:41:00 -04:00
$oPMScript->setExecutedOn(PMScript::ISOLATED_TRIGGER);
$oPMScript->execute();
if (isset($oPMScript->aFields["__ERROR__"]) && trim($oPMScript->aFields["__ERROR__"]) != "" && $oPMScript->aFields["__ERROR__"] != "none") {
throw new Exception($oPMScript->aFields["__ERROR__"]);
}
//Save data - Start
$appFields['APP_DATA'] = $oPMScript->aFields;
unset($appFields['APP_STATUS']);
unset($appFields['APP_PROC_STATUS']);
unset($appFields['APP_PROC_CODE']);
unset($appFields['APP_PIN']);
2017-08-15 16:03:21 -04:00
$oCase->updateCase($caseId, $appFields);
//Save data - End
} else {
$data['TRIGGER_INDEX'] = $triggerIndex;
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::loadTranslation('ID_INVALID_TRIGGER', SYS_LANG, $data));
$g->sessionVarRestore();
return $result;
}
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::loadTranslation('ID_EXECUTED') . ": " . trim($row['TRI_WEBBOT']));
$g->sessionVarRestore();
2012-10-09 13:29:25 -04:00
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
$g->sessionVarRestore();
return $result;
}
}
/**
* task Case
2012-10-09 13:29:25 -04:00
*
* @param string sessionId : The session ID which is obtained when logging in
* @param string caseId : The case ID. The caseList() function can be used to find the ID number for cases
2017-12-04 13:25:35 +00:00
*
* @return $result returns the current task for a given case. Note that the logged-in user must have privileges
* to access the task
*/
2017-08-15 16:03:21 -04:00
public function taskCase($caseId)
{
2017-10-17 11:45:53 -04:00
$result = [];
try {
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
$oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
2016-07-18 14:13:01 -04:00
$oCriteria->addSelectColumn(TaskPeer::TAS_TITLE);
$oCriteria->addJoin(AppDelegationPeer::TAS_UID, TaskPeer::TAS_UID);
2017-08-15 16:03:21 -04:00
$oCriteria->add(AppDelegationPeer::APP_UID, $caseId);
$oCriteria->add(AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN');
$oCriteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
$oDataset = AppDelegationPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
while ($aRow = $oDataset->getRow()) {
2017-08-15 16:03:21 -04:00
$result[] = array(
'guid' => $aRow['TAS_UID'],
'name' => $aRow['TAS_TITLE'],
'delegate' => $aRow['DEL_INDEX']
2012-10-09 13:29:25 -04:00
);
$oDataset->next();
}
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result[] = array('guid' => $e->getMessage(), 'name' => $e->getMessage(), 'delegate' => $e->getMessage());
return $result;
}
}
/**
* process list verified
2012-10-09 13:29:25 -04:00
*
* @param string sessionId : The session ID which is obtained when logging in
* @param string userId :
2017-12-04 13:25:35 +00:00
*
2012-10-09 13:29:25 -04:00
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function processListVerified($userId)
{
try {
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$rows = $oCase->getStartCases($userId);
2017-10-17 11:45:53 -04:00
$result = [];
foreach ($rows as $key => $val) {
if ($key != 0) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $val['pro_uid'],
'name' => $val['value']
2012-10-09 13:29:25 -04:00
);
}
}
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage(),
'name' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
return $result;
}
}
/**
* reassign Case
2012-10-09 13:29:25 -04:00
*
* @param string sessionId : The session ID (which was obtained during login)
* @param string caseId : The case ID (which can be obtained with the caseList() function)
* @param string delIndex : The delegation index number of the case (which can be obtained with the caseList()
2017-12-04 13:25:35 +00:00
* function).
2012-10-09 13:29:25 -04:00
* @param string userIdSource : The user who is currently assigned the case.
* @param string userIdTarget : The target user who will be newly assigned to the case.
2017-12-04 13:25:35 +00:00
*
2012-10-09 13:29:25 -04:00
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function reassignCase($sessionId, $caseId, $delIndex, $userIdSource, $userIdTarget)
{
$g = new G();
try {
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseId;
$_SESSION["INDEX"] = $delIndex;
$_SESSION["USER_LOGGED"] = $userIdSource;
if ($userIdTarget == $userIdSource) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(30, G::loadTranslation('ID_TARGET_ORIGIN_USER_SAME'));
$g->sessionVarRestore();
return $result;
}
2012-10-09 13:29:25 -04:00
/**
* ****************( 1 )*****************
*/
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->add(UsersPeer::USR_STATUS, 'ACTIVE');
$oCriteria->add(UsersPeer::USR_UID, $userIdSource);
$oDataset = UsersPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$aRow = $oDataset->getRow();
2017-08-15 16:03:21 -04:00
if (!is_array($aRow)) {
$result = new WsResponse(31, G::loadTranslation('ID_INVALID_ORIGIN_USER'));
$g->sessionVarRestore();
return $result;
}
2012-10-09 13:29:25 -04:00
/**
* ****************( 2 )*****************
*/
$oCase = new Cases();
2017-08-15 16:03:21 -04:00
$rows = $oCase->loadCase($caseId);
2017-08-15 16:03:21 -04:00
if (!is_array($aRow)) {
$result = new WsResponse(32, G::loadTranslation('ID_CASE_NOT_OPEN'));
$g->sessionVarRestore();
return $result;
}
2012-10-09 13:29:25 -04:00
/**
* ****************( 3 )*****************
*/
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
2017-10-17 11:45:53 -04:00
$aConditions = [];
2017-08-15 16:03:21 -04:00
$oCriteria->add(AppDelegationPeer::APP_UID, $caseId);
$oCriteria->add(AppDelegationPeer::USR_UID, $userIdSource);
$oCriteria->add(AppDelegationPeer::DEL_INDEX, $delIndex);
$oCriteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
$oDataset = AppDelegationPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$aRow = $oDataset->getRow();
2017-08-15 16:03:21 -04:00
if (!is_array($aRow)) {
$result = new WsResponse(33, G::loadTranslation('ID_INVALID_CASE_DELEGATION_INDEX'));
$g->sessionVarRestore();
return $result;
}
$tasUid = $aRow['TAS_UID'];
$derivation = new Derivation();
$userList = $derivation->getAllUsersFromAnyTask($tasUid, true);
2017-08-15 16:03:21 -04:00
if (!in_array($userIdTarget, $userList)) {
$result = new WsResponse(34, G::loadTranslation('ID_TARGET_USER_DOES_NOT_HAVE_RIGHTS'));
$g->sessionVarRestore();
return $result;
}
2012-10-09 13:29:25 -04:00
/**
* ****************( 4 )*****************
*/
2017-08-15 16:03:21 -04:00
$oCriteria = new Criteria('workflow');
$oCriteria->add(UsersPeer::USR_STATUS, 'ACTIVE');
$oCriteria->add(UsersPeer::USR_UID, $userIdTarget);
$oDataset = UsersPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$aRow = $oDataset->getRow();
2017-08-15 16:03:21 -04:00
if (!is_array($aRow)) {
$result = new WsResponse(35, G::loadTranslation('ID_TARGET_USER_DESTINATION_INVALID'));
$g->sessionVarRestore();
return $result;
}
2012-10-09 13:29:25 -04:00
/**
* ****************( 5 )*****************
*/
2017-08-15 16:03:21 -04:00
$var = $oCase->reassignCase($caseId, $delIndex, $userIdSource, $userIdTarget);
2017-08-15 16:03:21 -04:00
if (!$var) {
$result = new WsResponse(36, G::loadTranslation('ID_CASE_COULD_NOT_REASSIGNED'));
$g->sessionVarRestore();
return $result;
}
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULLY'));
$g->sessionVarRestore();
return $result;
} catch (Exception $e) {
2017-12-04 13:25:35 +00:00
$result[] = array(
'guid' => $e->getMessage(),
'name' => $e->getMessage()
2012-10-09 13:29:25 -04:00
);
$g->sessionVarRestore();
return $result;
}
}
/**
* get system information
2012-10-09 13:29:25 -04:00
*
* @param string sessionId : The session ID (which was obtained at login)
2017-12-04 13:25:35 +00:00
*
* @return $eturns information about the WAMP/LAMP stack, the workspace database, the IP number and version
* of ProcessMaker, and the IP number and version of web browser of the user
*/
2017-08-15 16:03:21 -04:00
public function systemInformation()
{
try {
2017-08-15 16:03:21 -04:00
define('SKIP_RENDER_SYSTEM_INFORMATION', true);
2017-08-15 16:03:21 -04:00
require_once(PATH_METHODS . 'login' . PATH_SEP . 'dbInfo.php');
2012-10-09 13:29:25 -04:00
$result->status_code = 0;
2017-08-15 16:03:21 -04:00
$result->message = G::loadTranslation('ID_SUCESSFUL');
$result->timestamp = date('Y-m-d H:i:s');
2017-08-14 16:13:46 -04:00
$result->version = System::getVersion();
2012-10-09 13:29:25 -04:00
$result->operatingSystem = $redhat;
2017-08-15 16:03:21 -04:00
$result->webServer = getenv('SERVER_SOFTWARE');
$result->serverName = getenv('SERVER_NAME');
2012-10-09 13:29:25 -04:00
$result->serverIp = $Fields['IP']; //lookup ($ip);
$result->phpVersion = phpversion();
$result->databaseVersion = $Fields['DATABASE'];
$result->databaseServerIp = $Fields['DATABASE_SERVER'];
$result->databaseName = $Fields['DATABASE_NAME'];
$result->availableDatabases = $Fields['AVAILABLE_DB'];
2012-10-09 13:29:25 -04:00
$result->userBrowser = $Fields['HTTP_USER_AGENT'];
$result->userIp = $Fields['IP'];
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* import process fromLibrary: downloads and imports a process from the ProcessMaker library
2012-10-09 13:29:25 -04:00
*
* @param string sessionId : The session ID (which was obtained at login).
* @param string processId :
* @param string version :
* @param string importOption :
* @param string usernameLibrary : The username to obtain access to the ProcessMaker library.
* @param string passwordLibrary : The password to obtain access to the ProcessMaker library.
2017-12-04 13:25:35 +00:00
*
2012-10-09 13:29:25 -04:00
* @return $eturns will return an object
*/
2017-08-15 16:03:21 -04:00
public function getCaseNotes($applicationID, $userUid = '')
{
try {
2017-12-04 13:25:35 +00:00
$result = new WsGetCaseNotesResponse(
0,
G::loadTranslation('ID_SUCCESS'),
Cases::getCaseNotes($applicationID, 'array', $userUid)
);
2017-10-17 11:45:53 -04:00
$var = [];
foreach ($result->notes as $key => $value) {
2017-10-17 11:45:53 -04:00
$var2 = [];
foreach ($value as $keys => $values) {
2017-08-15 16:03:21 -04:00
$field = strtolower($keys);
$var2[$field] = $values;
}
$var[] = $var2;
}
$result->notes = $var;
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* Delete case
2012-10-09 13:29:25 -04:00
*
* @param string caseUid : ID of the case.
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function deleteCase($caseUid)
{
$g = new G();
try {
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseUid;
2017-08-15 16:03:21 -04:00
if (empty($caseUid)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " caseUid");
$g->sessionVarRestore();
return $result;
}
$case = new Cases();
2017-08-15 16:03:21 -04:00
$case->removeCase($caseUid);
//Response
2018-04-20 08:57:55 -04:00
$result = self::messageExecuteSuccessfully();
$g->sessionVarRestore();
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
$g->sessionVarRestore();
return $result;
}
}
/**
* Cancel case
2012-10-09 13:29:25 -04:00
*
* @param string caseUid : ID of the case.
2017-12-04 13:25:35 +00:00
* @param int delIndex : Delegation index of the case.
2012-10-09 13:29:25 -04:00
* @param string userUid : The unique ID of the user who will cancel the case.
2017-12-04 13:25:35 +00:00
*
2018-04-20 08:57:55 -04:00
* @return array | object
*/
2017-08-15 16:03:21 -04:00
public function cancelCase($caseUid, $delIndex, $userUid)
{
$g = new G();
2019-01-30 09:11:57 -04:00
//We will to review if the current case in execution will be execute the same
if (isset($_SESSION["APPLICATION"]) && $_SESSION["APPLICATION"] !== $caseUid){
$this->setFlagSameCase(false);
}
try {
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseUid;
$_SESSION["INDEX"] = $delIndex;
$_SESSION["USER_LOGGED"] = $userUid;
2017-08-15 16:03:21 -04:00
if (empty($caseUid)) {
$g->sessionVarRestore();
2018-04-20 08:57:55 -04:00
return self::messageRequiredField('caseUid');
}
2018-04-20 08:57:55 -04:00
$case = new Cases();
$statusCase = $case->loadCase($caseUid)['APP_STATUS'];
if ($statusCase !== 'TO_DO') {
$g->sessionVarRestore();
2018-04-20 08:57:55 -04:00
return self::messageIllegalValues('ID_CASE_IN_STATUS', ' ' . $statusCase);
}
2018-04-20 08:57:55 -04:00
/** If those parameters are null we will to force the cancelCase */
if (is_null($delIndex) && is_null($userUid)) {
/*----------------------------------********---------------------------------*/
2019-01-30 09:11:57 -04:00
$case->cancelCase($caseUid, null, null, $this->getFlagSameCase());
2018-04-20 08:57:55 -04:00
$result = self::messageExecuteSuccessfully();
$g->sessionVarRestore();
return $result;
2018-04-20 08:57:55 -04:00
/*----------------------------------********---------------------------------*/
}
2018-04-20 08:57:55 -04:00
/** We will to continue with review the threads */
if (empty($delIndex)) {
$g->sessionVarRestore();
2018-04-20 08:57:55 -04:00
return self::messageRequiredField('delIndex');
}
2018-04-20 08:57:55 -04:00
$delegation = new AppDelegation();
$indexOpen = $delegation->LoadParallel($caseUid, $delIndex);
if (empty($indexOpen)) {
$g->sessionVarRestore();
2018-04-20 08:57:55 -04:00
return self::messageIllegalValues('ID_CASE_DELEGATION_ALREADY_CLOSED');
}
2018-04-20 08:57:55 -04:00
if (empty($userUid)) {
2016-08-11 10:42:29 -04:00
$g->sessionVarRestore();
2018-04-20 08:57:55 -04:00
return self::messageRequiredField('userUid');
2016-08-11 10:42:29 -04:00
}
2018-04-20 08:57:55 -04:00
if (AppThread::countStatus($caseUid, 'OPEN') > 1) {
$g->sessionVarRestore();
2018-04-20 08:57:55 -04:00
return self::messageIllegalValues("ID_CASE_CANCELLED_PARALLEL");
}
2018-04-20 08:57:55 -04:00
/** Cancel case */
2019-01-30 09:11:57 -04:00
$case->cancelCase($caseUid, (int)$delIndex, $userUid, $this->getFlagSameCase());
2018-04-20 08:57:55 -04:00
//Define the result of the cancelCase
$result = self::messageExecuteSuccessfully();
$g->sessionVarRestore();
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
$g->sessionVarRestore();
return $result;
}
}
/**
* Pause case
2012-10-09 13:29:25 -04:00
*
* @param string caseUid : ID of the case.
2017-12-04 13:25:35 +00:00
* @param int delIndex : Delegation index of the case.
2012-10-09 13:29:25 -04:00
* @param string userUid : The unique ID of the user who will pause the case.
* @param string unpauseDate : Optional parameter. The date in the format "yyyy-mm-dd" indicating when to unpause
2017-12-04 13:25:35 +00:00
* the case.
2019-02-01 10:41:44 -04:00
*
* @see workflow/engine/classes/class.pmFunctions.php::PMFPauseCase()
* @see workflow/engine/methods/services/soap2.php::pauseCase()
*
* @link https://wiki.processmaker.com/3.3/ProcessMaker_Functions/Case_Functions#PMFPauseCase.28.29
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function pauseCase($caseUid, $delIndex, $userUid, $unpauseDate = null)
{
$g = new G();
try {
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseUid;
$_SESSION["INDEX"] = $delIndex;
$_SESSION["USER_LOGGED"] = $userUid;
2021-09-30 12:30:00 -04:00
// Validate the appUid
2017-08-15 16:03:21 -04:00
if (empty($caseUid)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " caseUid");
$g->sessionVarRestore();
return $result;
}
2021-09-30 12:30:00 -04:00
// Validate the status
$caseInfo = Application::getCase($caseUid);
if ($caseInfo['APP_STATUS'] === Application::STATUS_DRAFT_NAME) {
$result = new WsResponse(100, G::LoadTranslation("ID_DRAFT_CASES_CAN_NOT_PAUSED"));
$g->sessionVarRestore();
2021-09-30 12:30:00 -04:00
return $result;
}
// Validate the index
2017-08-15 16:03:21 -04:00
if (empty($delIndex)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " delIndex");
$g->sessionVarRestore();
return $result;
}
2021-09-30 12:30:00 -04:00
// Validate the user
2017-08-15 16:03:21 -04:00
if (empty($userUid)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " userUid");
$g->sessionVarRestore();
return $result;
}
2021-09-30 12:30:00 -04:00
// Validate if status is closed
2019-02-01 10:41:44 -04:00
$appDelegation = new AppDelegation();
$rows = $appDelegation->LoadParallel($caseUid, $delIndex);
if (empty($rows)) {
$result = new WsResponse(100, G::LoadTranslation('ID_CASE_DELEGATION_ALREADY_CLOSED'));
$g->sessionVarRestore();
return $result;
}
2021-09-30 12:30:00 -04:00
// Validate if the case is paused
2019-02-01 10:41:44 -04:00
$appDelay = new AppDelay();
$sw = $appDelay->isPaused($caseUid, $delIndex);
if ($sw === true) {
$result = new WsResponse(19, G::LoadTranslation('ID_CASE_IN_STATUS') . " " . AppDelay::APP_TYPE_PAUSE);
$g->sessionVarRestore();
return $result;
}
2021-09-30 12:30:00 -04:00
// Review the unpaused date
2017-08-15 16:03:21 -04:00
if (strlen($unpauseDate) >= 10) {
if (!preg_match("/^\d{4}-\d{2}-\d{2}| \d{2}:\d{2}:\d{2}$/", $unpauseDate)) {
$result = new WsResponse(100, G::LoadTranslation("ID_INVALID_DATA") . " $unpauseDate");
$g->sessionVarRestore();
return $result;
}
2017-08-15 16:03:21 -04:00
} else {
$unpauseDate = null;
}
$case = new Cases();
2017-08-15 16:03:21 -04:00
$case->pauseCase($caseUid, $delIndex, $userUid, $unpauseDate);
2021-09-30 12:30:00 -04:00
// Response
2018-04-20 08:57:55 -04:00
$result = self::messageExecuteSuccessfully();
$g->sessionVarRestore();
2018-04-20 08:57:55 -04:00
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
$g->sessionVarRestore();
return $result;
}
}
/**
* Unpause case
2012-10-09 13:29:25 -04:00
*
* @param string caseUid : ID of the case.
2017-12-04 13:25:35 +00:00
* @param int delIndex : Delegation index of the case.
2012-10-09 13:29:25 -04:00
* @param string userUid : The unique ID of the user who will unpause the case.
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
2017-08-15 16:03:21 -04:00
public function unpauseCase($caseUid, $delIndex, $userUid)
{
$g = new G();
try {
$g->sessionVarSave();
$_SESSION["APPLICATION"] = $caseUid;
$_SESSION["INDEX"] = $delIndex;
$_SESSION["USER_LOGGED"] = $userUid;
2017-08-15 16:03:21 -04:00
if (empty($caseUid)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " caseUid");
$g->sessionVarRestore();
return $result;
}
2017-08-15 16:03:21 -04:00
if (empty($delIndex)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " delIndex");
$g->sessionVarRestore();
return $result;
}
2017-08-15 16:03:21 -04:00
if (empty($userUid)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " userUid");
$g->sessionVarRestore();
return $result;
}
$case = new Cases();
2017-08-15 16:03:21 -04:00
$case->unpauseCase($caseUid, $delIndex, $userUid);
//Response
2018-04-20 08:57:55 -04:00
$result = self::messageExecuteSuccessfully();
$g->sessionVarRestore();
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
$g->sessionVarRestore();
return $result;
}
}
/**
* Add case note
*
2020-06-04 10:38:48 -04:00
* @param string $caseUid, ID of the case.
* @param string $processUid, ID of the process.
* @param string $taskUid, ID of the task.
* @param string $userUid, The unique ID of the user who will add note case.
* @param string $note, Note of the case.
* @param int $sendMail, Optional parameter. If set to 1, will send an email to all participants in the case.
* @param array $files, Optional parameter. This is an array of files.
2017-12-04 13:25:35 +00:00
*
2020-06-04 10:38:48 -04:00
* @return object
*/
2020-06-04 10:38:48 -04:00
public function addCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail = 1, $files = [])
{
try {
if (empty($caseUid)) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " caseUid");
return $result;
}
if (empty($processUid)) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " processUid");
return $result;
}
if (empty($taskUid)) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " taskUid");
return $result;
}
if (empty($userUid)) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " userUid");
return $result;
}
if (empty($note)) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " note");
return $result;
}
$case = new Cases();
$respView = $case->getAllObjectsFrom($processUid, $caseUid, $taskUid, $userUid, "VIEW");
$respBlock = $case->getAllObjectsFrom($processUid, $caseUid, $taskUid, $userUid, "BLOCK");
if ($respView["CASES_NOTES"] == 0 && $respBlock["CASES_NOTES"] == 0) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, G::LoadTranslation("ID_CASES_NOTES_NO_PERMISSIONS"));
return $result;
}
2020-12-16 17:47:42 -04:00
// Define the Case for register a case note
2020-06-12 21:07:20 -04:00
$appNote = new BmCases();
2020-06-04 10:38:48 -04:00
$response = $appNote->addNote($caseUid, $userUid, $note, $sendMail, $files);
//Response
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::LoadTranslation("ID_COMMAND_EXECUTED_SUCCESSFULLY"));
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
/**
* ClaimCase
*
* @param string $userId
* @param string $guid
* @param string $delIndex
2017-12-04 13:25:35 +00:00
*
* @return $result will return an object
*/
public function claimCase($userId, $guid, $delIndex)
{
try {
$oCase = new Cases();
$oCase->loadCase($guid);
$oCase->setCatchUser($guid, $delIndex, $userId);
2017-08-15 16:03:21 -04:00
$result = new WsResponse(0, G::LoadTranslation("ID_COMMAND_EXECUTED_SUCCESSFULLY"));
return $result;
} catch (Exception $e) {
2017-08-15 16:03:21 -04:00
$result = new WsResponse(100, $e->getMessage());
return $result;
}
}
2018-04-20 08:57:55 -04:00
/**
* Define the message for the required fields
*
* @param string $field
* @param integer code
*
* @return object
*/
private function messageRequiredField($field, $code = 100)
{
$result = new WsResponse($code, G::LoadTranslation("ID_REQUIRED_FIELD") . ' ' . $field);
return $result;
}
/**
* Define the message for the required fields
*
* @param string $translationId
* @param string $field
* @param integer code
*
* @return object
*/
private function messageIllegalValues($translationId, $field = '', $code = 100)
{
$result = new WsResponse($code, G::LoadTranslation($translationId) . $field);
return $result;
}
/**
* Define the result when it's execute successfully
*
* @return object
*/
private function messageExecuteSuccessfully()
{
$res = new WsResponse(0, G::LoadTranslation("ID_COMMAND_EXECUTED_SUCCESSFULLY"));
$result = [
"status_code" => $res->status_code,
"message" => $res->message,
"timestamp" => $res->timestamp
];
return $result;
}
}