BUG 10957 "Feature request - Limit input document..." SOLVED

- Feature request - Limit input document maximum size
- Problema resuelto, al crear un nuevo Input Document se ha adicionado un nuevo campo "Maximum file size" y un dropdown
  que determina la unidad de medida en "KB y MB", esto permite definir el limite del tamañel archivo a anexar.
  Cuando se ejectua el caso al hacer click en "Attach", se muestra el tamañaximo que se puede adjuntar el archivo si es
  mayor	al limite se mostrara un mensaje; asi tambien si se tiene un file asocioado a un input document al igual que lo
  anterior se mostrara un mensaje.
This commit is contained in:
Luis Fernando Saisa Lopez
2014-09-15 12:09:31 -04:00
parent 12692ca8aa
commit 42f06bce9f
21 changed files with 414 additions and 71 deletions

View File

@@ -1,9 +1,9 @@
<?php
if (!isset($_SESSION['USER_LOGGED'])) {
$response = new stdclass();
$response->message = G::LoadTranslation('ID_LOGIN_AGAIN');
$response->lostSession = true;
print G::json_encode( $response );
if (!isset($_SESSION['USER_LOGGED'])) {
$response = new stdclass();
$response->message = G::LoadTranslation('ID_LOGIN_AGAIN');
$response->lostSession = true;
print G::json_encode( $response );
die();
}
/**
@@ -908,9 +908,17 @@ switch (($_POST['action']) ? $_POST['action'] : $_REQUEST['action']) {
$Fields['APP_DOC_UID'] = $_POST['appDocId'];
$Fields['actionType'] = $_POST['actionType'];
$Fields['docVersion'] = $_POST['docVersion'];
$oInputDocument = new InputDocument();
$InpDocData = $oInputDocument->load( $Fields['DOC_UID'] );
$oInputDocument = new InputDocument();
$InpDocData = $oInputDocument->load( $Fields['DOC_UID'] );
$inpDocMaxFilesize = $InpDocData["INP_DOC_MAX_FILESIZE"];
$inpDocMaxFilesizeUnit = $InpDocData["INP_DOC_MAX_FILESIZE_UNIT"];
$inpDocMaxFilesize = $inpDocMaxFilesize * (($inpDocMaxFilesizeUnit == "MB")? 1024 *1024 : 1024); //Bytes
$Fields["INP_DOC_MAX_FILESIZE"] = $inpDocMaxFilesize;
$Fields["INP_DOC_MAX_FILESIZE_LABEL"] = ($inpDocMaxFilesize > 0)? "[" . $InpDocData["INP_DOC_MAX_FILESIZE"] . " " . $InpDocData["INP_DOC_MAX_FILESIZE_UNIT"] . "]" : "";
$Fields['fileTypes'] = $InpDocData['INP_DOC_TYPE_FILE'];
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'cases/cases_AttachInputDocumentGeneral', '', $Fields, 'cases_SaveDocument?UID=' . $_POST['docID'] );
G::RenderPage( 'publish', 'raw' );
break;

View File

@@ -40,10 +40,10 @@ try {
if ($_GET['APP_UID'] !== $_SESSION['APPLICATION']) {
throw new Exception( G::LoadTranslation( 'ID_INVALID_APPLICATION_ID_MSG', array ('<a href=\'' . $_SERVER['HTTP_REFERER'] . '\'>{1}</a>',G::LoadTranslation( 'ID_REOPEN' ) ) ) );
}
/*
* PMDynaform
* DYN_VERSION is 1: classic Dynaform,
* DYN_VERSION is 1: classic Dynaform,
* DYN_VERSION is 2: responsive form, Pmdynaform.
*/
$a = new Criteria("workflow");
@@ -183,7 +183,7 @@ try {
$aData['USER_UID'] = $_SESSION['USER_LOGGED'];
//$aData['APP_STATUS'] = $Fields['APP_STATUS'];
$aData['PRO_UID'] = $_SESSION['PROCESS'];
if ($swpmdynaform) {
$aData['APP_DATA'] = array_merge($aData['APP_DATA'], $pmdynaform);
$_POST["DynaformRequiredFields"] = '[]';
@@ -255,6 +255,7 @@ try {
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"]] )) {
@@ -262,12 +263,20 @@ try {
}
$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) {
@@ -290,6 +299,21 @@ try {
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" => $_SESSION["APPLICATION"],"DEL_INDEX" => $_SESSION["INDEX"],"USR_UID" => $_SESSION["USER_LOGGED"],"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" => $_SESSION["APPLICATION"],"DEL_INDEX" => $_SESSION["INDEX"],"USR_UID" => $_SESSION["USER_LOGGED"],"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);

View File

@@ -93,36 +93,45 @@ if ($_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] > 0) {
$_SESSION["TRIGGER_DEBUG"]["TRIGGERS_VALUES"] = $arrayTrigger;
}
//***Validating the file allowed extensions***
$oInputDocument = new InputDocument();
//***Validating the file allowed extensions***
$oInputDocument = new InputDocument();
$InpDocData = $oInputDocument->load( $inputDocumentUid );
$res = G::verifyInputDocExtension($InpDocData['INP_DOC_TYPE_FILE'], $_FILES["form"]["name"]["APP_DOC_FILENAME"], $_FILES["form"]["tmp_name"]["APP_DOC_FILENAME"]);
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] );
$message = $res->message;
G::SendMessageText( $message, "ERROR" );
$backUrlObj = explode( "sys" . SYS_SYS, $_SERVER['HTTP_REFERER'] );
G::header( "location: " . "/sys" . SYS_SYS . $backUrlObj[1] );
die();
}
//Add Input Document
if (isset($_FILES) && isset($_FILES["form"]) && count($_FILES["form"]) > 0) {
$appDocUid = $case->addInputDocument(
$inputDocumentUid,
$appDocUid,
$docVersion,
$appDocType,
$appDocComment,
$actionType,
$_SESSION["APPLICATION"],
$_SESSION["INDEX"],
$_SESSION["TASK"],
$_SESSION["USER_LOGGED"],
"xmlform",
$_FILES["form"]["name"]["APP_DOC_FILENAME"],
$_FILES["form"]["error"]["APP_DOC_FILENAME"],
$_FILES["form"]["tmp_name"]["APP_DOC_FILENAME"]
);
try {
$appDocUid = $case->addInputDocument(
$inputDocumentUid,
$appDocUid,
$docVersion,
$appDocType,
$appDocComment,
$actionType,
$_SESSION["APPLICATION"],
$_SESSION["INDEX"],
$_SESSION["TASK"],
$_SESSION["USER_LOGGED"],
"xmlform",
$_FILES["form"]["name"]["APP_DOC_FILENAME"],
$_FILES["form"]["error"]["APP_DOC_FILENAME"],
$_FILES["form"]["tmp_name"]["APP_DOC_FILENAME"],
$_FILES["form"]["size"]["APP_DOC_FILENAME"]
);
} catch (Exception $e) {
G::SendMessageText($e->getMessage(), "ERROR");
$arrayAux = explode("sys" . SYS_SYS, $_SERVER["HTTP_REFERER"]);
G::header("location: /sys" . SYS_SYS . $arrayAux[1]);
exit(0);
}
}
if ($_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] > 0) {

View File

@@ -45,6 +45,19 @@ try {
}
$aFields['INP_DOC_TAGS'] = isset( $aFields['INP_DOC_TAGS'] ) ? $aFields['INP_DOC_TAGS'] : 'INPUT';
$aFields['INP_DOC_VERSIONING'] = strval( isset( $aFields['INP_DOC_VERSIONING'] ) ? $aFields['INP_DOC_VERSIONING'] : '' );
$uploadMaxFilesize = 0;
$uploadMaxFilesizeUnit = "KB";
if (preg_match("/^(\d+)(.*)$/", ini_get("upload_max_filesize"), $arrayMatch)) {
$uploadMaxFilesize = (int)($arrayMatch[1]);
$uploadMaxFilesizeUnit = (strlen(strtoupper($arrayMatch[2])) > 1)? $arrayMatch[2] : $arrayMatch[2] . "B";
$uploadMaxFilesize = $uploadMaxFilesize * (($uploadMaxFilesizeUnit == "MB")? 1024 * 1024 : 1024); //Bytes
}
$aFields["INP_DOC_UPLOAD_MAX_FILESIZE"] = $uploadMaxFilesize;
$aFields["INP_DOC_UPLOAD_MAX_FILESIZE_LABEL"] = "(" . $arrayMatch[1] . " " . $uploadMaxFilesizeUnit . ")";
G::LoadClass( 'xmlfield_InputPM' );
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'inputdocs/inputdocs_Edit', '', $aFields, '../inputdocs/inputdocs_Save' );