2014-03-24 17:03:13 -04:00
|
|
|
<?php
|
2014-04-02 16:51:28 -04:00
|
|
|
namespace ProcessMaker\BusinessModel\Cases;
|
2014-03-24 17:03:13 -04:00
|
|
|
|
|
|
|
|
class InputDocument
|
|
|
|
|
{
|
2016-01-25 15:00:41 -04:00
|
|
|
/**
|
|
|
|
|
* Verify exists app_doc_uid in table APP_DOCUMENT
|
|
|
|
|
*
|
|
|
|
|
* @param string $applicationUid
|
|
|
|
|
*
|
|
|
|
|
* return void Throw exception
|
|
|
|
|
*/
|
|
|
|
|
private function throwExceptionIfNotExistsAppDocument($appDocumentUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$appDocument = \AppDocumentPeer::retrieveByPK($appDocumentUid, 1);
|
|
|
|
|
|
|
|
|
|
if (is_null($appDocument)) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CASES_INPUT_DOES_NOT_EXIST", array($appDocumentUid)));
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 10:07:11 -04:00
|
|
|
/**
|
|
|
|
|
* Check if the user has permissions
|
|
|
|
|
*
|
|
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param string $delIndex Delegataion index
|
|
|
|
|
* @param string $userUid Unique id of User
|
|
|
|
|
* @param string $inputDocumentUid
|
|
|
|
|
*
|
|
|
|
|
* return void Throw exception the user does not have permission to delete
|
|
|
|
|
*/
|
|
|
|
|
public function throwExceptionIfHaventPermissionToDelete($applicationUid, $delIndex, $userUid, $appDocumentUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify data inbox
|
|
|
|
|
$case = new \ProcessMaker\BusinessModel\Cases();
|
|
|
|
|
$arrayResult = $case->getStatusInfo($applicationUid, $delIndex, $userUid);
|
|
|
|
|
|
|
|
|
|
$flagInbox = 1;
|
|
|
|
|
|
|
|
|
|
if (empty($arrayResult) || !preg_match("/^(?:TO_DO|DRAFT)$/", $arrayResult["APP_STATUS"])) {
|
|
|
|
|
$flagInbox = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Verify data Supervisor
|
|
|
|
|
$application = \ApplicationPeer::retrieveByPK($applicationUid);
|
|
|
|
|
|
|
|
|
|
$flagSupervisor = 0;
|
|
|
|
|
|
|
|
|
|
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
2015-10-16 15:34:30 -04:00
|
|
|
$processSupervisor= $supervisor->getProcessSupervisors($application->getProUid(), "ASSIGNED");
|
|
|
|
|
|
|
|
|
|
$arraySupervisor = $processSupervisor["data"];
|
2015-09-29 10:07:11 -04:00
|
|
|
|
|
|
|
|
foreach ($arraySupervisor as $value) {
|
|
|
|
|
if($value["usr_uid"] == $userUid) {
|
|
|
|
|
$flagSupervisor = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($flagInbox == 0 && $flagSupervisor == 0) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_USER_NOT_HAVE_PERMISSION_DELETE_INPUT_DOCUMENT", array($userUid)));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 15:00:41 -04:00
|
|
|
//verfiry exists $appDocumentUid
|
|
|
|
|
$this->throwExceptionIfNotExistsAppDocument($appDocumentUid);
|
|
|
|
|
|
2015-09-29 10:07:11 -04:00
|
|
|
//Verify data permission
|
|
|
|
|
$flagPermission = 0;
|
|
|
|
|
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::DOC_UID);
|
|
|
|
|
|
|
|
|
|
$criteria->add(\AppDocumentPeer::APP_DOC_UID, $appDocumentUid, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\AppDocumentPeer::APP_UID, $applicationUid, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\AppDocumentPeer::APP_DOC_TYPE, "INPUT", \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \AppDocumentPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
$inputDocumentUid = $row["DOC_UID"];
|
|
|
|
|
|
|
|
|
|
//Criteria
|
|
|
|
|
$criteria2 = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria2->addSelectColumn(\ObjectPermissionPeer::OP_UID);
|
|
|
|
|
|
|
|
|
|
$criteria2->add(\ObjectPermissionPeer::PRO_UID, $application->getProUid(), \Criteria::EQUAL);
|
|
|
|
|
$criteria2->add(\ObjectPermissionPeer::OP_OBJ_TYPE, "INPUT", \Criteria::EQUAL);
|
|
|
|
|
$criteria2->add(
|
|
|
|
|
$criteria2->getNewCriterion(\ObjectPermissionPeer::OP_OBJ_UID, $inputDocumentUid, \Criteria::EQUAL)->addOr(
|
|
|
|
|
$criteria2->getNewCriterion(\ObjectPermissionPeer::OP_OBJ_UID, "0", \Criteria::EQUAL))->addOr(
|
|
|
|
|
$criteria2->getNewCriterion(\ObjectPermissionPeer::OP_OBJ_UID, "", \Criteria::EQUAL))
|
|
|
|
|
);
|
|
|
|
|
$criteria2->add(\ObjectPermissionPeer::OP_ACTION, "DELETE", \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
//User
|
|
|
|
|
$criteriaU = clone $criteria2;
|
|
|
|
|
|
|
|
|
|
$criteriaU->add(\ObjectPermissionPeer::OP_USER_RELATION, 1, \Criteria::EQUAL);
|
|
|
|
|
$criteriaU->add(\ObjectPermissionPeer::USR_UID, $userUid, \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteriaU = \ObjectPermissionPeer::doSelectRS($criteriaU);
|
|
|
|
|
$rsCriteriaU->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if ($rsCriteriaU->next()) {
|
|
|
|
|
$flagPermission = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Group
|
|
|
|
|
if ($flagPermission == 0) {
|
|
|
|
|
$criteriaG = clone $criteria2;
|
|
|
|
|
|
|
|
|
|
$criteriaG->add(\ObjectPermissionPeer::OP_USER_RELATION, 2, \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$criteriaG->addJoin(\ObjectPermissionPeer::USR_UID, \GroupUserPeer::GRP_UID, \Criteria::LEFT_JOIN);
|
|
|
|
|
$criteriaG->add(\GroupUserPeer::USR_UID, $userUid, \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteriaG = \ObjectPermissionPeer::doSelectRS($criteriaG);
|
|
|
|
|
$rsCriteriaG->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if ($rsCriteriaG->next()) {
|
|
|
|
|
$flagPermission = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($flagPermission == 0) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_USER_NOT_HAVE_PERMISSION_DELETE_INPUT_DOCUMENT", array($userUid)));
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify if not exists input Document in Steps
|
|
|
|
|
*
|
|
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param string $delIndex Delegataion index
|
|
|
|
|
* @param string $appDocumentUid
|
|
|
|
|
*
|
|
|
|
|
* return void Throw exception if not exists input Document in Steps
|
|
|
|
|
*/
|
|
|
|
|
public function throwExceptionIfInputDocumentNotExistsInSteps($applicacionUid, $delIndex, $appDocumentUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify Case
|
|
|
|
|
$appDelegation = \AppDelegationPeer::retrieveByPK($applicacionUid, $delIndex);
|
|
|
|
|
|
|
|
|
|
if (is_null($appDelegation)) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CASE_DEL_INDEX_DOES_NOT_EXIST", array("app_uid", $applicacionUid, "del_index", $delIndex)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$taskUid = $appDelegation->getTasUid();
|
|
|
|
|
|
|
|
|
|
//Verify Steps
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::DOC_UID);
|
|
|
|
|
|
|
|
|
|
$criteria->add(\AppDocumentPeer::APP_DOC_UID, $appDocumentUid, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\AppDocumentPeer::APP_UID, $applicacionUid, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\AppDocumentPeer::APP_DOC_TYPE, "INPUT", \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \AppDocumentPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
$inputDocumentUid = $row["DOC_UID"];
|
|
|
|
|
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(\StepPeer::STEP_UID);
|
|
|
|
|
|
|
|
|
|
$criteria->add(\StepPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\StepPeer::STEP_TYPE_OBJ, "INPUT_DOCUMENT", \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\StepPeer::STEP_UID_OBJ, $inputDocumentUid, \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \StepPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if (!$rsCriteria->next()) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CASES_INPUT_DOCUMENT_DOES_NOT_EXIST", array($appDocumentUid)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 10:10:29 -04:00
|
|
|
/**
|
|
|
|
|
* Get criteria for AppDocument
|
|
|
|
|
*
|
|
|
|
|
* return object
|
|
|
|
|
*/
|
|
|
|
|
public function getAppDocumentCriteriaByData($applicationUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_UID);
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::DOC_VERSION);
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::DOC_UID);
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::USR_UID);
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_TYPE);
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_CREATE_DATE);
|
|
|
|
|
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_INDEX);
|
|
|
|
|
|
|
|
|
|
$sql = "
|
|
|
|
|
SELECT MAX(APPDOC.DOC_VERSION)
|
|
|
|
|
FROM " . \AppDocumentPeer::TABLE_NAME . " AS APPDOC
|
|
|
|
|
WHERE APPDOC.APP_DOC_UID = " . \AppDocumentPeer::APP_DOC_UID . "
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
$criteria->add(
|
|
|
|
|
$criteria->getNewCriterion(\AppDocumentPeer::APP_UID, $applicationUid, \Criteria::EQUAL)->addAnd(
|
|
|
|
|
$criteria->getNewCriterion(\AppDocumentPeer::APP_DOC_TYPE, array("INPUT", "ATTACHED"), \Criteria::IN))->addAnd(
|
|
|
|
|
$criteria->getNewCriterion(\AppDocumentPeer::APP_DOC_STATUS, array("ACTIVE"), \Criteria::IN))->addAnd(
|
|
|
|
|
$criteria->getNewCriterion(\AppDocumentPeer::DOC_VERSION, \AppDocumentPeer::DOC_VERSION . " IN ($sql)", \Criteria::CUSTOM))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$criteria->addAscendingOrderByColumn(\AppDocumentPeer::APP_DOC_INDEX);
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $criteria;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get data of a AppDocument from a record
|
|
|
|
|
*
|
|
|
|
|
* @param array $record Record
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with data AppDocument
|
|
|
|
|
*/
|
|
|
|
|
public function getAppDocumentDataFromRecord(array $record)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return array(
|
|
|
|
|
"app_doc_uid" => $record["APP_DOC_UID"],
|
|
|
|
|
"app_doc_filename" => $record["APP_DOC_FILENAME"],
|
|
|
|
|
"doc_uid" => $record["DOC_UID"],
|
|
|
|
|
"app_doc_version" => $record["DOC_VERSION"],
|
|
|
|
|
"app_doc_create_date" => $record["APP_DOC_CREATE_DATE"],
|
|
|
|
|
"app_doc_create_user" => $record["APP_DOC_CREATE_USER"],
|
|
|
|
|
"app_doc_type" => $record["APP_DOC_TYPE"],
|
|
|
|
|
"app_doc_index" => (int)($record["APP_DOC_INDEX"]),
|
|
|
|
|
"app_doc_link" => $record["APP_DOC_LINK"]
|
|
|
|
|
);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the user is Supervisor
|
|
|
|
|
*
|
|
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param string $userUid Unique id of User
|
|
|
|
|
*
|
|
|
|
|
* return array Return data of input documents
|
|
|
|
|
*/
|
|
|
|
|
public function getCasesInputDocumentsBySupervisor($applicationUid, $userUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify data Supervisor
|
|
|
|
|
$application = \ApplicationPeer::retrieveByPK($applicationUid);
|
|
|
|
|
|
|
|
|
|
$flagSupervisor = 0;
|
|
|
|
|
|
|
|
|
|
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
2015-11-11 08:44:19 -04:00
|
|
|
$processSupervisor = $supervisor->getProcessSupervisors($application->getProUid(), "ASSIGNED");
|
|
|
|
|
$arraySupervisor = $processSupervisor["data"];
|
2015-10-01 10:10:29 -04:00
|
|
|
|
|
|
|
|
foreach ($arraySupervisor as $value) {
|
2015-11-11 08:44:19 -04:00
|
|
|
if(!empty($value["usr_uid"]) && $value["usr_uid"] == $userUid) {
|
2015-10-01 10:10:29 -04:00
|
|
|
$flagSupervisor = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = new \Users();
|
|
|
|
|
$appDocument = new \AppDocument();
|
|
|
|
|
$configuraction = new \Configurations();
|
|
|
|
|
|
|
|
|
|
$confEnvSetting = $configuraction->getFormats();
|
|
|
|
|
|
|
|
|
|
$arrayInputDocument = array();
|
|
|
|
|
|
|
|
|
|
//Query
|
|
|
|
|
$criteria = $this->getAppDocumentCriteriaByData($applicationUid);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \AppDocumentPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
while ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
$arrayUserData = $user->load($row["USR_UID"]);
|
|
|
|
|
|
|
|
|
|
$arrayAppDocument = $appDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]);
|
|
|
|
|
|
|
|
|
|
$row["APP_DOC_FILENAME"] = $arrayAppDocument["APP_DOC_FILENAME"];
|
|
|
|
|
$row["APP_DOC_CREATE_USER"] = $configuraction->usersNameFormatBySetParameters($confEnvSetting["format"], $arrayUserData["USR_USERNAME"], $arrayUserData["USR_FIRSTNAME"], $arrayUserData["USR_LASTNAME"]);
|
|
|
|
|
$row["APP_DOC_LINK"] = "cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
|
|
|
|
|
|
|
|
|
|
$arrayInputDocument[] = $this->getAppDocumentDataFromRecord($row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($arrayInputDocument) && $flagSupervisor == 0) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_USER_IS_NOT_SUPERVISOR"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayInputDocument;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-24 17:03:13 -04:00
|
|
|
/**
|
|
|
|
|
* Get data of Cases InputDocument
|
|
|
|
|
*
|
2014-03-25 16:43:50 -04:00
|
|
|
* @param string $applicationUid
|
2014-03-24 17:03:13 -04:00
|
|
|
* @param string $userUid
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with data of an InputDocument
|
|
|
|
|
*/
|
2014-03-25 16:43:50 -04:00
|
|
|
public function getCasesInputDocuments($applicationUid, $userUid)
|
2014-03-24 17:03:13 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2015-10-01 10:10:29 -04:00
|
|
|
//Verify data inbox
|
|
|
|
|
$case = new \ProcessMaker\BusinessModel\Cases();
|
|
|
|
|
$arrayResult = $case->getStatusInfo($applicationUid, 0, $userUid);
|
|
|
|
|
|
|
|
|
|
$flagInbox = true;
|
|
|
|
|
|
|
|
|
|
if (empty($arrayResult) || !preg_match("/^(?:TO_DO|DRAFT)$/", $arrayResult["APP_STATUS"])) {
|
|
|
|
|
$flagInbox = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = new \Users();
|
|
|
|
|
$appDocument = new \AppDocument();
|
|
|
|
|
$configuraction = new \Configurations();
|
|
|
|
|
|
|
|
|
|
$confEnvSetting = $configuraction->getFormats();
|
|
|
|
|
|
|
|
|
|
$arrayInputDocument = array();
|
|
|
|
|
|
|
|
|
|
//Query
|
|
|
|
|
$criteria = $this->getAppDocumentCriteriaByData($applicationUid);
|
|
|
|
|
|
|
|
|
|
if (!$flagInbox) {
|
|
|
|
|
$criteria->add(\AppDocumentPeer::USR_UID, $userUid, \Criteria::EQUAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \AppDocumentPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
while ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
2016-02-01 11:37:35 -04:00
|
|
|
$sUser = '***';
|
|
|
|
|
if ($row["USR_UID"] !== '-1') {
|
|
|
|
|
$arrayUserData = $user->load($row["USR_UID"]);
|
|
|
|
|
$sUser = $configuraction->usersNameFormatBySetParameters($confEnvSetting["format"], $arrayUserData["USR_USERNAME"], $arrayUserData["USR_FIRSTNAME"], $arrayUserData["USR_LASTNAME"]);
|
|
|
|
|
}
|
2015-10-01 10:10:29 -04:00
|
|
|
$arrayAppDocument = $appDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]);
|
|
|
|
|
|
2015-11-11 08:44:19 -04:00
|
|
|
|
2015-10-01 10:10:29 -04:00
|
|
|
$row["APP_DOC_FILENAME"] = $arrayAppDocument["APP_DOC_FILENAME"];
|
2016-02-01 11:37:35 -04:00
|
|
|
$row["APP_DOC_CREATE_USER"] = $sUser;
|
2015-10-01 10:10:29 -04:00
|
|
|
$row["APP_DOC_LINK"] = "cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
|
|
|
|
|
|
|
|
|
|
$arrayInputDocument[] = $this->getAppDocumentDataFromRecord($row);
|
2014-03-24 17:03:13 -04:00
|
|
|
}
|
2015-10-01 10:10:29 -04:00
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayInputDocument;
|
2014-03-24 17:03:13 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get data of Cases InputDocument
|
|
|
|
|
*
|
2014-03-25 16:43:50 -04:00
|
|
|
* @param string $applicationUid
|
2014-03-24 17:03:13 -04:00
|
|
|
* @param string $userUid
|
|
|
|
|
* @param string $inputDocumentUid
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with data of an InputDocument
|
|
|
|
|
*/
|
2014-03-25 16:43:50 -04:00
|
|
|
public function getCasesInputDocument($applicationUid, $userUid, $inputDocumentUid)
|
2014-03-24 17:03:13 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-03-25 16:43:50 -04:00
|
|
|
$sApplicationUID = $applicationUid;
|
2014-03-24 17:03:13 -04:00
|
|
|
$sUserUID = $userUid;
|
|
|
|
|
\G::LoadClass('case');
|
|
|
|
|
$oCase = new \Cases();
|
|
|
|
|
$fields = $oCase->loadCase( $sApplicationUID );
|
|
|
|
|
$sProcessUID = $fields['PRO_UID'];
|
|
|
|
|
$sTaskUID = '';
|
2014-04-02 16:51:28 -04:00
|
|
|
$oCaseRest = new \ProcessMaker\BusinessModel\Cases();
|
2014-03-24 17:03:13 -04:00
|
|
|
$oCaseRest->getAllUploadedDocumentsCriteria( $sProcessUID, $sApplicationUID, $sTaskUID, $sUserUID );
|
|
|
|
|
$result = array ();
|
|
|
|
|
global $_DBArray;
|
2015-09-14 15:56:23 -04:00
|
|
|
$flagInputDocument = false;
|
|
|
|
|
|
2014-03-24 17:03:13 -04:00
|
|
|
foreach ($_DBArray['inputDocuments'] as $key => $row) {
|
|
|
|
|
if (isset( $row['DOC_VERSION'] )) {
|
|
|
|
|
$docrow = array ();
|
|
|
|
|
$docrow['app_doc_uid'] = $row['APP_DOC_UID'];
|
|
|
|
|
$docrow['app_doc_filename'] = $row['APP_DOC_FILENAME'];
|
|
|
|
|
$docrow['doc_uid'] = $row['DOC_UID'];
|
|
|
|
|
$docrow['app_doc_version'] = $row['DOC_VERSION'];
|
|
|
|
|
$docrow['app_doc_create_date'] = $row['CREATE_DATE'];
|
|
|
|
|
$docrow['app_doc_create_user'] = $row['CREATED_BY'];
|
|
|
|
|
$docrow['app_doc_type'] = $row['TYPE'];
|
|
|
|
|
$docrow['app_doc_index'] = $row['APP_DOC_INDEX'];
|
2015-11-11 08:44:19 -04:00
|
|
|
$docrow['app_doc_link'] = $row['DOWNLOAD_LINK'];
|
2015-09-14 15:56:23 -04:00
|
|
|
|
|
|
|
|
if ($docrow["app_doc_uid"] == $inputDocumentUid) {
|
|
|
|
|
$flagInputDocument = true;
|
|
|
|
|
|
|
|
|
|
$appDocument = \AppDocumentPeer::retrieveByPK($inputDocumentUid, $row["DOC_VERSION"]);
|
|
|
|
|
|
|
|
|
|
if (is_null($appDocument)) {
|
|
|
|
|
$flagInputDocument = false;
|
2014-04-23 16:50:31 -04:00
|
|
|
}
|
2015-09-14 15:56:23 -04:00
|
|
|
|
2014-03-24 17:03:13 -04:00
|
|
|
$result = $docrow;
|
2015-09-14 15:56:23 -04:00
|
|
|
break;
|
2014-03-24 17:03:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-14 15:56:23 -04:00
|
|
|
|
|
|
|
|
if (!$flagInputDocument) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CASES_INPUT_DOES_NOT_EXIST", array($inputDocumentUid)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 14:39:55 -04:00
|
|
|
$oResponse = json_decode(json_encode($result), false);
|
|
|
|
|
return $oResponse;
|
2014-03-24 17:03:13 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete InputDocument
|
|
|
|
|
*
|
|
|
|
|
* @param string $inputDocumentUid
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with data of an InputDocument
|
|
|
|
|
*/
|
|
|
|
|
public function removeInputDocument($inputDocumentUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oAppDocument = \AppDocumentPeer::retrieveByPK( $inputDocumentUid, 1 );
|
|
|
|
|
if (is_null( $oAppDocument ) || $oAppDocument->getAppDocStatus() == 'DELETED') {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CASES_INPUT_DOES_NOT_EXIST", array($inputDocumentUid)));
|
2014-03-24 17:03:13 -04:00
|
|
|
}
|
|
|
|
|
\G::LoadClass('wsBase');
|
|
|
|
|
$ws = new \wsBase();
|
|
|
|
|
$ws->removeDocument($inputDocumentUid);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get data of Cases InputDocument
|
|
|
|
|
*
|
2014-03-25 16:43:50 -04:00
|
|
|
* @param string $applicationUid
|
|
|
|
|
* @param string $taskUid
|
2014-03-26 15:22:54 -04:00
|
|
|
* @param string $appDocComment
|
2014-03-24 17:03:13 -04:00
|
|
|
* @param string $inputDocumentUid
|
|
|
|
|
* @param string $userUid
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with data of an InputDocument
|
|
|
|
|
*/
|
2016-07-06 18:55:58 -04:00
|
|
|
public function addCasesInputDocument($applicationUid, $taskUid, $appDocComment, $inputDocumentUid, $userUid, $runningWorkflow = true)
|
2014-03-24 17:03:13 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-03-25 16:43:50 -04:00
|
|
|
if ((isset( $_FILES['form'] )) && ($_FILES['form']['error'] != 0)) {
|
|
|
|
|
$code = $_FILES['form']['error'];
|
2014-03-24 17:03:13 -04:00
|
|
|
switch ($code) {
|
|
|
|
|
case UPLOAD_ERR_INI_SIZE:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_INI_SIZE' );
|
|
|
|
|
break;
|
|
|
|
|
case UPLOAD_ERR_FORM_SIZE:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_FORM_SIZE' );
|
|
|
|
|
break;
|
|
|
|
|
case UPLOAD_ERR_PARTIAL:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_PARTIAL' );
|
|
|
|
|
break;
|
|
|
|
|
case UPLOAD_ERR_NO_FILE:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_FILE' );
|
|
|
|
|
break;
|
|
|
|
|
case UPLOAD_ERR_NO_TMP_DIR:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_TMP_DIR' );
|
|
|
|
|
break;
|
|
|
|
|
case UPLOAD_ERR_CANT_WRITE:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_CANT_WRITE' );
|
|
|
|
|
break;
|
|
|
|
|
case UPLOAD_ERR_EXTENSION:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_EXTENSION' );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_UNKNOWN' );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
\G::SendMessageText( $message, "ERROR" );
|
|
|
|
|
$backUrlObj = explode( "sys" . SYS_SYS, $_SERVER['HTTP_REFERER'] );
|
|
|
|
|
\G::header( "location: " . "/sys" . SYS_SYS . $backUrlObj[1] );
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
\G::LoadClass("case");
|
2014-03-25 16:43:50 -04:00
|
|
|
$appDocUid = \G::generateUniqueID();
|
2014-03-24 17:03:13 -04:00
|
|
|
$docVersion = '';
|
|
|
|
|
$appDocType = 'INPUT';
|
|
|
|
|
$case = new \Cases();
|
2014-03-25 16:43:50 -04:00
|
|
|
$delIndex = \AppDelegation::getCurrentIndex($applicationUid);
|
2016-07-06 18:55:58 -04:00
|
|
|
|
|
|
|
|
if ($runningWorkflow) {
|
|
|
|
|
$case->thisIsTheCurrentUser($applicationUid, $delIndex, $userUid, 'REDIRECT', 'casesListExtJs');
|
|
|
|
|
} else {
|
|
|
|
|
$criteria = new \Criteria('workflow');
|
|
|
|
|
|
|
|
|
|
$criteria->add(\AppDelegationPeer::APP_UID, $applicationUid);
|
|
|
|
|
$criteria->add(\AppDelegationPeer::DEL_INDEX, $delIndex);
|
|
|
|
|
$criteria->add(\AppDelegationPeer::USR_UID, $userUid);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \ProcessUserPeer::doSelectRS($criteria);
|
|
|
|
|
|
|
|
|
|
if (!$rsCriteria->next()) {
|
|
|
|
|
$case2 = new \ProcessMaker\BusinessModel\Cases();
|
|
|
|
|
|
|
|
|
|
$arrayApplicationData = $case2->getApplicationRecordByPk($applicationUid, [], false);
|
|
|
|
|
|
|
|
|
|
$msg = '';
|
|
|
|
|
|
|
|
|
|
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
|
|
|
|
$flagps = $supervisor->isUserProcessSupervisor($arrayApplicationData['PRO_UID'], $userUid);
|
|
|
|
|
|
|
|
|
|
if ($flagps == false) {
|
|
|
|
|
$msg = \G::LoadTranslation('ID_USER_NOT_IT_BELONGS_CASE_OR_NOT_SUPERVISOR');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($msg == '') {
|
|
|
|
|
$criteria = new \Criteria('workflow');
|
|
|
|
|
|
|
|
|
|
$criteria->add(\StepSupervisorPeer::PRO_UID, $arrayApplicationData['PRO_UID'], \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\StepSupervisorPeer::STEP_TYPE_OBJ, 'INPUT_DOCUMENT', \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\StepSupervisorPeer::STEP_UID_OBJ, $inputDocumentUid, \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \StepSupervisorPeer::doSelectRS($criteria);
|
|
|
|
|
|
|
|
|
|
if (!$rsCriteria->next()) {
|
|
|
|
|
$msg = \G::LoadTranslation('ID_USER_IS_SUPERVISOR_DOES_NOT_ASSOCIATED_INPUT_DOCUMENT');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($msg != '') {
|
|
|
|
|
if ($runningWorkflow) {
|
|
|
|
|
\G::SendMessageText($msg, 'ERROR');
|
|
|
|
|
$backUrlObj = explode('sys' . SYS_SYS, $_SERVER['HTTP_REFERER']);
|
|
|
|
|
|
|
|
|
|
\G::header('location: ' . '/sys' . SYS_SYS . $backUrlObj[1]);
|
|
|
|
|
exit(0);
|
|
|
|
|
} else {
|
|
|
|
|
throw new \Exception($msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-24 17:03:13 -04:00
|
|
|
//Load the fields
|
2014-03-25 16:43:50 -04:00
|
|
|
$arrayField = $case->loadCase($applicationUid);
|
2014-03-24 17:03:13 -04:00
|
|
|
$arrayField["APP_DATA"] = array_merge($arrayField["APP_DATA"], \G::getSystemConstants());
|
2016-04-18 20:00:00 -04:00
|
|
|
//Validate Process Uid and Input Document Process Uid
|
|
|
|
|
$inputDocumentInstance = new \InputDocument();
|
|
|
|
|
$inputDocumentFields = $inputDocumentInstance->load($inputDocumentUid);
|
|
|
|
|
if ($arrayField['PRO_UID'] != $inputDocumentFields['PRO_UID']) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INPUT_DOCUMENT_DOES_NOT_EXIST",
|
|
|
|
|
array('UID=' . $inputDocumentUid, 'PRO_UID=' . $arrayField['PRO_UID'])));
|
|
|
|
|
}
|
2014-03-24 17:03:13 -04:00
|
|
|
//Triggers
|
2014-03-25 16:43:50 -04:00
|
|
|
$arrayTrigger = $case->loadTriggers($taskUid, "INPUT_DOCUMENT", $inputDocumentUid, "AFTER");
|
2014-03-24 17:03:13 -04:00
|
|
|
//Add Input Document
|
2014-04-23 16:50:31 -04:00
|
|
|
if (empty($_FILES)) {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CASES_INPUT_FILENAME_DOES_NOT_EXIST"));
|
2014-04-23 16:50:31 -04:00
|
|
|
}
|
|
|
|
|
if (!$_FILES["form"]["error"]) {
|
2014-03-25 16:43:50 -04:00
|
|
|
$_FILES["form"]["error"] = 0;
|
|
|
|
|
}
|
2014-03-24 17:03:13 -04:00
|
|
|
if (isset($_FILES) && isset($_FILES["form"]) && count($_FILES["form"]) > 0) {
|
2014-04-22 11:11:03 -04:00
|
|
|
$appDocUid = $case->addInputDocument($inputDocumentUid,
|
2014-04-23 16:50:31 -04:00
|
|
|
$appDocUid,
|
|
|
|
|
$docVersion,
|
|
|
|
|
$appDocType,
|
|
|
|
|
$appDocComment,
|
|
|
|
|
'',
|
|
|
|
|
$applicationUid,
|
|
|
|
|
$delIndex,
|
|
|
|
|
$taskUid,
|
|
|
|
|
$userUid,
|
|
|
|
|
"xmlform",
|
|
|
|
|
$_FILES["form"]["name"],
|
|
|
|
|
$_FILES["form"]["error"],
|
|
|
|
|
$_FILES["form"]["tmp_name"]);
|
2014-04-22 11:11:03 -04:00
|
|
|
}
|
|
|
|
|
//Trigger - Execute after - Start
|
|
|
|
|
$arrayField["APP_DATA"] = $case->executeTriggers ($taskUid,
|
2014-04-23 16:50:31 -04:00
|
|
|
"INPUT_DOCUMENT",
|
|
|
|
|
$inputDocumentUid,
|
|
|
|
|
"AFTER",
|
|
|
|
|
$arrayField["APP_DATA"]);
|
2014-04-22 11:11:03 -04:00
|
|
|
//Trigger - Execute after - End
|
2014-03-24 17:03:13 -04:00
|
|
|
//Save data
|
|
|
|
|
$arrayData = array();
|
|
|
|
|
$arrayData["APP_NUMBER"] = $arrayField["APP_NUMBER"];
|
|
|
|
|
//$arrayData["APP_PROC_STATUS"] = $arrayField["APP_PROC_STATUS"];
|
|
|
|
|
$arrayData["APP_DATA"] = $arrayField["APP_DATA"];
|
2014-03-25 16:43:50 -04:00
|
|
|
$arrayData["DEL_INDEX"] = $delIndex;
|
|
|
|
|
$arrayData["TAS_UID"] = $taskUid;
|
|
|
|
|
$case->updateCase($applicationUid, $arrayData);
|
2014-04-04 16:40:12 -04:00
|
|
|
return($this->getCasesInputDocument($applicationUid, $userUid, $appDocUid));
|
2014-03-24 17:03:13 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|