HOR-1899
This commit is contained in:
@@ -644,4 +644,148 @@ class InputDocument
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $FILES $_FILES request files
|
||||
* @param $Cases \Cases object class.cases
|
||||
* @param $userUid string user id
|
||||
* @param $appUid string application id
|
||||
* @param $delIndex int the index case
|
||||
*/
|
||||
public function uploadFileCase($FILES, $Cases, $userUid, $appUid, $delIndex)
|
||||
{
|
||||
$arrayField = array();
|
||||
$arrayFileName = array();
|
||||
$arrayFileTmpName = array();
|
||||
$arrayFileError = array();
|
||||
$i = 0;
|
||||
foreach ($FILES["form"]["name"] as $fieldIndex => $fieldValue) {
|
||||
if (is_array($fieldValue)) {
|
||||
foreach ($fieldValue as $index => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $grdFieldIndex => $grdFieldValue) {
|
||||
$arrayField[$i]["grdName"] = $fieldIndex;
|
||||
$arrayField[$i]["grdFieldName"] = $grdFieldIndex;
|
||||
$arrayField[$i]["index"] = $index;
|
||||
|
||||
$arrayFileName[$i] = $FILES["form"]["name"][$fieldIndex][$index][$grdFieldIndex];
|
||||
$arrayFileTmpName[$i] = $FILES["form"]["tmp_name"][$fieldIndex][$index][$grdFieldIndex];
|
||||
$arrayFileError[$i] = $FILES["form"]["error"][$fieldIndex][$index][$grdFieldIndex];
|
||||
$i = $i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$arrayField[$i] = $fieldIndex;
|
||||
|
||||
$arrayFileName[$i] = $FILES["form"]["name"][$fieldIndex];
|
||||
$arrayFileTmpName[$i] = $FILES["form"]["tmp_name"][$fieldIndex];
|
||||
$arrayFileError[$i] = $FILES["form"]["error"][$fieldIndex];
|
||||
$i = $i + 1;
|
||||
}
|
||||
}
|
||||
if (count($arrayField) > 0) {
|
||||
foreach ($arrayField as $i => $item) {
|
||||
//for ($i = 0; $i <= count($arrayField) - 1; $i++) {
|
||||
if ($arrayFileError[$i] == 0) {
|
||||
$indocUid = null;
|
||||
$fieldName = null;
|
||||
$fileSizeByField = 0;
|
||||
|
||||
if (is_array($arrayField[$i])) {
|
||||
if (isset($_POST["INPUTS"][$arrayField[$i]["grdName"]][$arrayField[$i]["grdFieldName"]]) && !empty($_POST["INPUTS"][$arrayField[$i]["grdName"]][$arrayField[$i]["grdFieldName"]])) {
|
||||
$indocUid = $_POST["INPUTS"][$arrayField[$i]["grdName"]][$arrayField[$i]["grdFieldName"]];
|
||||
}
|
||||
$fieldName = $arrayField[$i]["grdName"] . "_" . $arrayField[$i]["index"] . "_" . $arrayField[$i]["grdFieldName"];
|
||||
if (isset($FILES["form"]["size"][$arrayField[$i]["grdName"]][$arrayField[$i]["index"]][$arrayField[$i]["grdFieldName"]])) {
|
||||
$fileSizeByField = $FILES["form"]["size"][$arrayField[$i]["grdName"]][$arrayField[$i]["index"]][$arrayField[$i]["grdFieldName"]];
|
||||
}
|
||||
} else {
|
||||
if (isset($_POST["INPUTS"][$arrayField[$i]]) && !empty($_POST["INPUTS"][$arrayField[$i]])) {
|
||||
$indocUid = $_POST["INPUTS"][$arrayField[$i]];
|
||||
}
|
||||
$fieldName = $arrayField[$i];
|
||||
if (isset($FILES["form"]["size"][$fieldName])) {
|
||||
$fileSizeByField = $FILES["form"]["size"][$fieldName];
|
||||
}
|
||||
}
|
||||
if ($indocUid != null) {
|
||||
$oInputDocument = new \InputDocument();
|
||||
$aID = $oInputDocument->load($indocUid);
|
||||
|
||||
//Get the Custom Folder ID (create if necessary)
|
||||
$oFolder = new \AppFolder();
|
||||
|
||||
//***Validating the file allowed extensions***
|
||||
$res = \G::verifyInputDocExtension($aID['INP_DOC_TYPE_FILE'], $arrayFileName[$i], $arrayFileTmpName[$i]);
|
||||
if ($res->status == 0) {
|
||||
$message = $res->message;
|
||||
\G::SendMessageText($message, "ERROR");
|
||||
$backUrlObj = explode("sys" . SYS_SYS, $_SERVER['HTTP_REFERER']);
|
||||
\G::header("location: " . "/sys" . SYS_SYS . $backUrlObj[1]);
|
||||
die();
|
||||
}
|
||||
|
||||
//--- Validate Filesize of $_FILE
|
||||
$inpDocMaxFilesize = $aID["INP_DOC_MAX_FILESIZE"];
|
||||
$inpDocMaxFilesizeUnit = $aID["INP_DOC_MAX_FILESIZE_UNIT"];
|
||||
|
||||
$inpDocMaxFilesize = $inpDocMaxFilesize * (($inpDocMaxFilesizeUnit == "MB") ? 1024 * 1024 : 1024); //Bytes
|
||||
|
||||
if ($inpDocMaxFilesize > 0 && $fileSizeByField > 0) {
|
||||
if ($fileSizeByField > $inpDocMaxFilesize) {
|
||||
\G::SendMessageText(\G::LoadTranslation("ID_SIZE_VERY_LARGE_PERMITTED"), "ERROR");
|
||||
$arrayAux1 = explode("sys" . SYS_SYS, $_SERVER["HTTP_REFERER"]);
|
||||
\G::header("location: /sys" . SYS_SYS . $arrayAux1[1]);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
$aFields = array("APP_UID" => $appUid, "DEL_INDEX" => $delIndex, "USR_UID" => $userUid, "DOC_UID" => $indocUid, "APP_DOC_TYPE" => "INPUT", "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), "APP_DOC_COMMENT" => "", "APP_DOC_TITLE" => "", "APP_DOC_FILENAME" => $arrayFileName[$i], "FOLDER_UID" => $oFolder->createFromPath($aID["INP_DOC_DESTINATION_PATH"]), "APP_DOC_TAGS" => $oFolder->parseTags($aID["INP_DOC_TAGS"]), "APP_DOC_FIELDNAME" => $fieldName);
|
||||
} else {
|
||||
$aFields = array("APP_UID" => $appUid, "DEL_INDEX" => $delIndex, "USR_UID" => $userUid, "DOC_UID" => -1, "APP_DOC_TYPE" => "ATTACHED", "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), "APP_DOC_COMMENT" => "", "APP_DOC_TITLE" => "", "APP_DOC_FILENAME" => $arrayFileName[$i], "APP_DOC_FIELDNAME" => $fieldName);
|
||||
}
|
||||
|
||||
$oAppDocument = new \AppDocument();
|
||||
$oAppDocument->create($aFields);
|
||||
|
||||
$iDocVersion = $oAppDocument->getDocVersion();
|
||||
$sAppDocUid = $oAppDocument->getAppDocUid();
|
||||
$aInfo = pathinfo($oAppDocument->getAppDocFilename());
|
||||
$sExtension = ((isset($aInfo["extension"])) ? $aInfo["extension"] : "");
|
||||
$pathUID = \G::getPathFromUID($appUid);
|
||||
$sPathName = PATH_DOCUMENT . $pathUID . PATH_SEP;
|
||||
$sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $sExtension;
|
||||
|
||||
\G::uploadFile($arrayFileTmpName[$i], $sPathName, $sFileName);
|
||||
|
||||
//set variable for APP_DOC_UID
|
||||
$aData["APP_DATA"][$oAppDocument->getAppDocFieldname()] = \G::json_encode([$oAppDocument->getAppDocUid()]);
|
||||
$aData["APP_DATA"][$oAppDocument->getAppDocFieldname() . "_label"] = \G::json_encode([$oAppDocument->getAppDocFilename()]);
|
||||
$Cases->updateCase($appUid, $aData);
|
||||
|
||||
//Plugin Hook PM_UPLOAD_DOCUMENT for upload document
|
||||
$oPluginRegistry = &\PMPluginRegistry::getSingleton();
|
||||
|
||||
if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists("uploadDocumentData")) {
|
||||
$triggerDetail = $oPluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT);
|
||||
$documentData = new \uploadDocumentData($appUid, $userUid, $sPathName . $sFileName, $aFields["APP_DOC_FILENAME"], $sAppDocUid, $iDocVersion);
|
||||
$uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
|
||||
|
||||
if ($uploadReturn) {
|
||||
$aFields["APP_DOC_PLUGIN"] = $triggerDetail->sNamespace;
|
||||
if (!isset($aFields["APP_DOC_UID"])) {
|
||||
$aFields["APP_DOC_UID"] = $sAppDocUid;
|
||||
}
|
||||
if (!isset($aFields["DOC_VERSION"])) {
|
||||
$aFields["DOC_VERSION"] = $iDocVersion;
|
||||
}
|
||||
$oAppDocument->update($aFields);
|
||||
unlink($sPathName . $sFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user