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
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 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 {
|
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;
|
|
|
|
|
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'];
|
2014-04-08 12:50:16 -04:00
|
|
|
$docrow['app_doc_create_date'] = $row['CREATE_DATE'];
|
2014-03-24 17:03:13 -04:00
|
|
|
$docrow['app_doc_create_user'] = $row['CREATED_BY'];
|
|
|
|
|
$docrow['app_doc_type'] = $row['TYPE'];
|
|
|
|
|
$docrow['app_doc_index'] = $row['APP_DOC_INDEX'];
|
|
|
|
|
$docrow['app_doc_link'] = 'cases/' . $row['DOWNLOAD_LINK'];
|
|
|
|
|
$result[] = $docrow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
} 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'];
|
|
|
|
|
$docrow['app_doc_link'] = 'cases/' . $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
|
|
|
|
|
*/
|
2014-03-26 15:22:54 -04:00
|
|
|
public function addCasesInputDocument($applicationUid, $taskUid, $appDocComment, $inputDocumentUid, $userUid)
|
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);
|
|
|
|
|
$case->thisIsTheCurrentUser($applicationUid, $delIndex, $userUid, "REDIRECT", "casesListExtJs");
|
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());
|
|
|
|
|
//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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|