Bug 5933 now the save of the data of a dynaform linked with a pmtable dont create a duplicate record with id 0

This commit is contained in:
Gustavo Adolfo Cruz Laura
2011-01-19 16:46:33 +00:00
parent 3e08e2ad4a
commit 5b6cb08ca4

View File

@@ -1,49 +1,49 @@
<?
/**
* cases_SaveData.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.
*
/**
* cases_SaveData.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.
*
*/
//validate the data post
//validate the data post
$oForm = new Form ( $_SESSION ['PROCESS'] . '/' . $_GET ['UID'], PATH_DYNAFORM );
$oForm->validatePost ();
/* Includes */
G::LoadClass ( 'case' );
//load the variables
//load the variables
$oCase = new Cases ( );
$oCase->thisIsTheCurrentUser ( $_SESSION ['APPLICATION'], $_SESSION ['INDEX'], $_SESSION ['USER_LOGGED'], 'REDIRECT', 'cases_List' );
$Fields = $oCase->loadCase ( $_SESSION ['APPLICATION'] );
$Fields ['APP_DATA'] = array_merge ( $Fields ['APP_DATA'], G::getSystemConstants () );
$Fields ['APP_DATA'] = array_merge ( $Fields ['APP_DATA'], ( array ) $_POST ['form'] );
#here we must verify if is a debug session
$trigger_debug_session = $_SESSION ['TRIGGER_DEBUG'] ['ISSET']; #here we must verify if is a debugg session
#here we must verify if is a debug session
$trigger_debug_session = $_SESSION ['TRIGGER_DEBUG'] ['ISSET']; #here we must verify if is a debugg session
#trigger debug routines...
#trigger debug routines...
//cleaning debug variables
//cleaning debug variables
$_SESSION ['TRIGGER_DEBUG'] ['ERRORS'] = Array ();
$_SESSION ['TRIGGER_DEBUG'] ['DATA'] = Array ();
$_SESSION ['TRIGGER_DEBUG'] ['TRIGGERS_NAMES'] = Array ();
@@ -59,12 +59,13 @@ if ($_SESSION ['TRIGGER_DEBUG'] ['NUM_TRIGGERS'] != 0) {
}
if ($_SESSION ['TRIGGER_DEBUG'] ['NUM_TRIGGERS'] != 0) {
//Execute after triggers - Start
//Execute after triggers - Start
$Fields ['APP_DATA'] = $oCase->ExecuteTriggers ( $_SESSION ['TASK'], 'DYNAFORM', $_GET ['UID'], 'AFTER', $Fields ['APP_DATA'] );
//Execute after triggers - End
//Execute after triggers - End
}
//save data in PM Tables if necessary
//save data in PM Tables if necessary
$newValues = array ();
foreach ( $_POST ['form'] as $sField => $sAux ) {
if (isset ( $oForm->fields [$sField]->pmconnection ) && isset ( $oForm->fields [$sField]->pmfield )) {
if (($oForm->fields [$sField]->pmconnection != '') && ($oForm->fields [$sField]->pmfield != '')) {
@@ -105,21 +106,35 @@ foreach ( $_POST ['form'] as $sField => $sAux ) {
try {
$oAdditionalTables->updateDataInTable ( $oForm->fields [$oForm->fields [$sField]->pmconnection]->pmtable, $aValues );
} catch ( Exception $oError ) {
//Nothing
//Nothing
}
} else {
try {
$oAdditionalTables->saveDataInTable ( $oForm->fields [$oForm->fields [$sField]->pmconnection]->pmtable, $aValues );
// assembling the field list in order to save the data ina new record of a pm table
if (empty($newValues)){
$newValues = $aValues;
} else {
foreach ($aValues as $aValueKey=>$aValueCont) {
if (trim($newValues[$aValueKey])==''){
$newValues[$aValueKey] = $aValueCont;
}
}
}
//$oAdditionalTables->saveDataInTable ( $oForm->fields [$oForm->fields [$sField]->pmconnection]->pmtable, $aValues );
} catch ( Exception $oError ) {
//Nothing
//Nothing
}
}
}
}
}
}
//save data
// saving the data ina pm table in case that is a new record
if (!empty($newValues)){
$oAdditionalTables->saveDataInTable ( $oForm->fields [$oForm->fields [$sField]->pmconnection]->pmtable, $newValues);
}
//save data
$aData = array ();
$aData ['APP_NUMBER'] = $Fields ['APP_NUMBER'];
$aData ['APP_PROC_STATUS'] = $Fields ['APP_PROC_STATUS'];
@@ -130,9 +145,9 @@ $aData ['CURRENT_DYNAFORM'] = $_GET ['UID'];
$aData ['USER_UID'] = $_SESSION ['USER_LOGGED'];
$aData ['APP_STATUS'] = $Fields ['APP_STATUS'];
$aData ['PRO_UID'] = $_SESSION ['PROCESS'];
$oCase->updateCase ( $_SESSION ['APPLICATION'], $aData );
//save files
//save files
require_once 'classes/model/AppDocument.php';
if (isset ( $_FILES ['form'] )) {
foreach ( $_FILES ['form'] ['name'] as $sFieldName => $vValue ) {
@@ -190,7 +205,7 @@ if (isset ( $_FILES ['form'] )) {
$sPathName = PATH_DOCUMENT . $_SESSION ['APPLICATION'] . PATH_SEP;
$sFileName = $sAppDocUid . '_'.$iDocVersion.'.' . $sExtension;
G::uploadFile ( $_FILES ['form'] ['tmp_name'] [$sFieldName], $sPathName, $sFileName );
//Plugin Hook PM_UPLOAD_DOCUMENT for upload document
//Plugin Hook PM_UPLOAD_DOCUMENT for upload document
$oPluginRegistry = & PMPluginRegistry::getSingleton ();
if ($oPluginRegistry->existsTrigger ( PM_UPLOAD_DOCUMENT ) && class_exists ( 'uploadDocumentData' )) {
$documentData = new uploadDocumentData ( $_SESSION ['APPLICATION'], $_SESSION ['USER_LOGGED'], $sPathName . $sFileName, $aFields ['APP_DOC_FILENAME'], $sAppDocUid );
@@ -201,7 +216,7 @@ if (isset ( $_FILES ['form'] )) {
}
}
//go to the next step
//go to the next step
$aNextStep = $oCase->getNextStep ( $_SESSION ['PROCESS'], $_SESSION ['APPLICATION'], $_SESSION ['INDEX'], $_SESSION ['STEP_POSITION'] );
if (isset ( $_GET ['_REFRESH_'] )) {
G::header ( 'location: ' . $_SERVER ['HTTP_REFERER'] );
@@ -229,5 +244,5 @@ if ($missing_req_values = $oForm->validateRequiredFields ( $_POST ['form'], $oJS
exit ( 0 );
}
G::header ( 'location: ' . $aNextStep ['PAGE'] );
G::header ( 'location: ' . $aNextStep ['PAGE'] );