Merged in bugfix/HOR-4009 (pull request #6144)
HOR-4009 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -1,119 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* cases_SupervisorSaveDocument.php
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2008 Colosa Inc.23
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*/
|
||||
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
|
||||
try {
|
||||
|
||||
$oAppDocument = new AppDocument();
|
||||
$aFields = array (
|
||||
$appDocument = new AppDocument();
|
||||
$fields = array(
|
||||
"APP_UID" => $_GET["APP_UID"],
|
||||
"DEL_INDEX" => 100000,
|
||||
"USR_UID" => $_SESSION["USER_LOGGED"],
|
||||
"DOC_UID" => $_GET["UID"],
|
||||
"APP_DOC_TYPE" => $_POST["form"]["APP_DOC_TYPE"],
|
||||
"APP_DOC_CREATE_DATE" => date( "Y-m-d H:i:s" ),
|
||||
"APP_DOC_COMMENT" => isset( $_POST["form"]["APP_DOC_COMMENT"] ) ? $_POST["form"]["APP_DOC_COMMENT"] : "",
|
||||
"APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"),
|
||||
"APP_DOC_COMMENT" => isset($_POST["form"]["APP_DOC_COMMENT"]) ? $_POST["form"]["APP_DOC_COMMENT"] : "",
|
||||
"APP_DOC_TITLE" => "",
|
||||
"APP_DOC_FILENAME" => isset( $_FILES["form"]["name"]["APP_DOC_FILENAME"] ) ? $_FILES["form"]["name"]["APP_DOC_FILENAME"] : "",
|
||||
"APP_DOC_UID" => $_GET["APP_DOC_UID"],
|
||||
"DOC_VERSION" => $_GET["DOC_VERSION"]
|
||||
"APP_DOC_FILENAME" => isset($_FILES["form"]["name"]["APP_DOC_FILENAME"]) ? $_FILES["form"]["name"]["APP_DOC_FILENAME"] : ""
|
||||
);
|
||||
if (!empty($_GET["APP_DOC_UID"])) {
|
||||
$fields['APP_DOC_UID'] = $_GET["APP_DOC_UID"];
|
||||
}
|
||||
if (!empty($_GET["DOC_VERSION"])) {
|
||||
$fields['DOC_VERSION'] = $_GET["DOC_VERSION"];
|
||||
}
|
||||
|
||||
$oAppDocument->create( $aFields );
|
||||
$sAppDocUid = $oAppDocument->getAppDocUid();
|
||||
$info = pathinfo( $oAppDocument->getAppDocFilename() );
|
||||
$ext = (isset( $info['extension'] ) ? $info['extension'] : '');
|
||||
//save the file
|
||||
if (! empty( $_FILES['form'] )) {
|
||||
$appDocument->create($fields);
|
||||
$appDocUid = $appDocument->getAppDocUid();
|
||||
$info = pathinfo($appDocument->getAppDocFilename());
|
||||
$ext = (isset($info['extension']) ? $info['extension'] : '');
|
||||
|
||||
//Save the file
|
||||
if (!empty($_FILES['form'])) {
|
||||
if ($_FILES['form']['error']['APP_DOC_FILENAME'] == 0) {
|
||||
$sPathName = PATH_DOCUMENT . G::getPathFromUID($_GET['APP_UID']) . PATH_SEP;
|
||||
$sFileName = $sAppDocUid . '.' . $ext;
|
||||
$sOriginalName = $_FILES['form']['name']['APP_DOC_FILENAME'];
|
||||
G::uploadFile( $_FILES['form']['tmp_name']['APP_DOC_FILENAME'], $sPathName, $sFileName );
|
||||
$pathName = PATH_DOCUMENT . G::getPathFromUID($_GET['APP_UID']) . PATH_SEP;
|
||||
$fileName = $appDocUid . '.' . $ext;
|
||||
$originalName = $_FILES['form']['name']['APP_DOC_FILENAME'];
|
||||
G::uploadFile($_FILES['form']['tmp_name']['APP_DOC_FILENAME'], $pathName, $fileName);
|
||||
|
||||
//Plugin Hook PM_UPLOAD_DOCUMENT for upload document
|
||||
$oPluginRegistry = PluginRegistry::loadSingleton();
|
||||
if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT ) && class_exists( 'uploadDocumentData' )) {
|
||||
$oData['APP_UID'] = $_GET['APP_UID'];
|
||||
$documentData = new uploadDocumentData( $_GET['APP_UID'], $_SESSION['USER_LOGGED'], $sPathName . $sFileName, $aFields['APP_DOC_FILENAME'], $sAppDocUid );
|
||||
$oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
|
||||
unlink( $sPathName . $sFileName );
|
||||
$pluginRegistry = PluginRegistry::loadSingleton();
|
||||
if ($pluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) {
|
||||
$data['APP_UID'] = $_GET['APP_UID'];
|
||||
$documentData = new uploadDocumentData(
|
||||
$_GET['APP_UID'],
|
||||
$_SESSION['USER_LOGGED'],
|
||||
$pathName . $fileName,
|
||||
$fields['APP_DOC_FILENAME'],
|
||||
$appDocUid
|
||||
);
|
||||
$pluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
|
||||
unlink($pathName . $fileName);
|
||||
}
|
||||
//end plugin
|
||||
|
||||
//update AppData with the current file uploaded
|
||||
$oCase = new Cases();
|
||||
$aAppDataFields = $oCase->loadCase( $_GET['APP_UID'] );
|
||||
//Update AppData with the current file uploaded
|
||||
$case = new Cases();
|
||||
$appDataFields = $case->loadCase($_GET['APP_UID']);
|
||||
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
|
||||
$oCriteria->add(AppDelegationPeer::APP_UID, $_GET['APP_UID'], CRITERIA::EQUAL);
|
||||
$oCriteria->addAscendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
||||
$oDataset = AppDelegationPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$criteria = new Criteria('workflow');
|
||||
$criteria->addSelectColumn(AppDelegationPeer::TAS_UID);
|
||||
$criteria->add(AppDelegationPeer::APP_UID, $_GET['APP_UID'], CRITERIA::EQUAL);
|
||||
$criteria->addAscendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
||||
$dataset = AppDelegationPeer::doSelectRS($criteria);
|
||||
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
$oDataset->next();
|
||||
$oTask = new Tasks();
|
||||
$dataset->next();
|
||||
$task = new Tasks();
|
||||
|
||||
$aDynaforms = array();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$aSteps = $oTask->getStepsOfTask($aRow['TAS_UID']);
|
||||
if (is_array($aSteps)) {
|
||||
foreach ($aSteps as $key => $value) {
|
||||
$oCriteriaStep = new Criteria('workflow');
|
||||
$oCriteriaStep->addSelectColumn(StepPeer::STEP_UID_OBJ);
|
||||
$sStepId = (isset($value['STEP_UID'])) ? $value['STEP_UID'] : 0 ;
|
||||
$oCriteriaStep->add(StepPeer::STEP_UID, $sStepId, CRITERIA::EQUAL);
|
||||
$oCriteriaStep->add(StepPeer::STEP_TYPE_OBJ, 'DYNAFORM', CRITERIA::EQUAL);
|
||||
$oDataSetStep = StepPeer::doSelectRS($oCriteriaStep);
|
||||
$oDataSetStep->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataSetStep->next();
|
||||
$aRows = $oDataSetStep->getRow();
|
||||
$dynaforms = [];
|
||||
while ($row = $dataset->getRow()) {
|
||||
$steps = $task->getStepsOfTask($row['TAS_UID']);
|
||||
if (is_array($steps)) {
|
||||
foreach ($steps as $key => $value) {
|
||||
$criteriaStep = new Criteria('workflow');
|
||||
$criteriaStep->addSelectColumn(StepPeer::STEP_UID_OBJ);
|
||||
$stepId = (isset($value['STEP_UID'])) ? $value['STEP_UID'] : 0;
|
||||
$criteriaStep->add(StepPeer::STEP_UID, $stepId, CRITERIA::EQUAL);
|
||||
$criteriaStep->add(StepPeer::STEP_TYPE_OBJ, 'DYNAFORM', CRITERIA::EQUAL);
|
||||
$dataSetStep = StepPeer::doSelectRS($criteriaStep);
|
||||
$dataSetStep->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$dataSetStep->next();
|
||||
$rowStep = $dataSetStep->getRow();
|
||||
|
||||
if (is_array($aRows) && !in_array($aRows['STEP_UID_OBJ'], $aDynaforms)) {
|
||||
$aDynaforms[] = $aRows['STEP_UID_OBJ'];
|
||||
if (is_array($rowStep) && !in_array($rowStep['STEP_UID_OBJ'], $dynaforms)) {
|
||||
$dynaforms[] = $rowStep['STEP_UID_OBJ'];
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
}
|
||||
$oDataset->next();
|
||||
$dataset->next();
|
||||
}
|
||||
|
||||
|
||||
if (count($aDynaforms) > 0) {
|
||||
require_once ("classes/model/Dynaform.php");
|
||||
if (count($dynaforms) > 0) {
|
||||
require_once("classes/model/Dynaform.php");
|
||||
$dynInstance = new Dynaform();
|
||||
foreach ($aDynaforms as $key => $value) {
|
||||
$aAllFields = $dynInstance->getDynaformFields($value);
|
||||
if (is_array($aAllFields)) {
|
||||
foreach ($aAllFields as $kInput => $input) {
|
||||
if (!isset($input->input)) continue;
|
||||
foreach ($dynaforms as $key => $value) {
|
||||
$allFields = $dynInstance->getDynaformFields($value);
|
||||
if (is_array($allFields)) {
|
||||
foreach ($allFields as $kInput => $input) {
|
||||
if (!isset($input->input)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($input->type == 'file' && $input->input == $_GET['UID'] && !empty($aAppDataFields['APP_DATA'][$kInput])) {
|
||||
$aAppDataFields['APP_DATA'][$kInput] = $sOriginalName;
|
||||
$oCase->updateCase( $_GET['APP_UID'], $aAppDataFields );
|
||||
if ($input->type == 'file' && $input->input == $_GET['UID'] && !empty($appDataFields['APP_DATA'][$kInput])) {
|
||||
$appDataFields['APP_DATA'][$kInput] = $originalName;
|
||||
$case->updateCase($_GET['APP_UID'], $appDataFields);
|
||||
}
|
||||
}
|
||||
unset($input);
|
||||
@@ -124,22 +115,23 @@ try {
|
||||
//End Update AppData with the current file uploaded
|
||||
}
|
||||
}
|
||||
//go to the next step
|
||||
if (! isset( $_POST['form']['MORE'] )) {
|
||||
$oCase = new Cases();
|
||||
$aFields = $oCase->loadCase( $_GET['APP_UID'] );
|
||||
$aNextStep = $oCase->getNextSupervisorStep( $aFields['PRO_UID'], $_GET['position'], 'INPUT_DOCUMENT' );
|
||||
G::header( 'location: ' . 'cases_StepToReviseInputs?type=INPUT_DOCUMENT&INP_DOC_UID=' . $aNextStep['UID'] . '&position=' . $aNextStep['POSITION'] . '&APP_UID=' . $_GET['APP_UID'] . '&DEL_INDEX=' );
|
||||
|
||||
//Go to the next step
|
||||
if (!isset($_POST['form']['MORE'])) {
|
||||
$case = new Cases();
|
||||
$fields = $case->loadCase($_GET['APP_UID']);
|
||||
$nextStep = $case->getNextSupervisorStep($fields['PRO_UID'], $_GET['position'], 'INPUT_DOCUMENT');
|
||||
G::header('location: ' . 'cases_StepToReviseInputs?type=INPUT_DOCUMENT&INP_DOC_UID=' . $nextStep['UID'] . '&position=' . $nextStep['POSITION'] . '&APP_UID=' . $_GET['APP_UID'] . '&DEL_INDEX=');
|
||||
die();
|
||||
} else {
|
||||
G::header( 'location: ' . $_SERVER['HTTP_REFERER'] );
|
||||
G::header('location: ' . $_SERVER['HTTP_REFERER']);
|
||||
die();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* Render Error page */
|
||||
$aMessage['MESSAGE'] = $e->getMessage();
|
||||
$message = [];
|
||||
$message['MESSAGE'] = $e->getMessage();
|
||||
$G_PUBLISH = new Publisher();
|
||||
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
|
||||
G::RenderPage( 'publish' );
|
||||
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $message);
|
||||
G::RenderPage('publish');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user