Files
luos/workflow/engine/templates/cases/cases_DynaformHistory.php
2011-09-05 12:47:25 -04:00

167 lines
5.6 KiB
PHP
Executable File

<?php
/**
* cases_DynaformHistory.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.
*
*/
$tpl = new TemplatePower( PATH_TPL . 'cases/cases_DynaformHistory.html' );
$tpl->prepare();
G::LoadClass('case');
$oCase = new Cases();
$Fields = $oCase->loadCase($_SESSION['APPLICATION']);
$historyData=array();
$historyDataAux=array();
require_once 'classes/model/AppHistory.php';
$appHistory = new AppHistory();
$c=$appHistory->getDynaformHistory($_REQUEST['PRO_UID'],$_REQUEST['TAS_UID'],$_REQUEST['APP_UID'],$_REQUEST['DYN_UID']);
$oDataset = ArrayBasePeer::doSelectRs ( $c);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$changeCount=0;
while ($aRow = $oDataset->getRow()) {
$changeCount++;
$changedValues=unserialize($aRow['HISTORY_DATA']);
$tableName="_TCHANGE_".$changeCount;
$historyDataAux[$tableName]=$changedValues;
$oDataset->next();
}
$historyData=array_reverse($historyDataAux);
$changeCount=count($historyData);
foreach($historyData as $key => $value){
$tableName="_TCHANGE_".$changeCount;
$changeCountA=$changeCount+1;
$tableNameA="_TCHANGE_".$changeCountA;
if(isset($historyData[$tableNameA])){
//$historyData[$key]=array_merge($historyData[$tableNameA],$value);
//Array merge recursive doesn't work. So here is an own procedure
$historyData[$key]=$historyData[$tableNameA];
foreach($value as $key1 => $value2){
if(!is_array($value2)){
$historyData[$key][$key1]=$value2;
}else{
foreach($value2 as $key3 => $value3){
if(is_array($value3)){
foreach($value3 as $key4 => $value4){
$historyData[$key][$key1][$key3][$key4]=$value4;
}
}
}
}
}
}
$changeCount--;
}
$oDataset = ArrayBasePeer::doSelectRs ( $c);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$changeCount=0;
while ($aRow = $oDataset->getRow()) {
$changeCount++;
$changedValues=unserialize($aRow['HISTORY_DATA']);
$tpl->newBlock( "DYNLOG" );
$tableName="_TCHANGE_".$changeCount;
$changeCountA=$changeCount+1;
$tableNameA="_TCHANGE_".$changeCountA;
$tpl->assign( "dynTitle" , $aRow['DYN_TITLE'] );
$tpl->assign( "dynDate" , $aRow['HISTORY_DATE'] );
$tpl->assign( "dynUser" , $aRow['USR_NAME'] );
$tpl->assign( "changes" , G::LoadTranslation("ID_CHANGES") );
$tpl->assign( "dynUID" , $aRow['DYN_UID'] );
$tpl->assign( "tablename" , $tableName );
$tpl->assign( "viewForm" , G::LoadTranslation("ID_VIEW") );
$tpl->assign( "dynaform" , G::LoadTranslation("ID_DYNAFORM") );
$tpl->assign( "date" , G::LoadTranslation("ID_DATE") );
$tpl->assign( "user" , G::LoadTranslation("ID_USER") );
$tpl->assign( "fieldNameLabel" , G::LoadTranslation("ID_FIELD_NAME") );
$tpl->assign( "previousValuesLabel" , G::LoadTranslation("ID_PREV_VALUES") );
$tpl->assign( "currentValuesLabel" , G::LoadTranslation("ID_CURRENT_VALUES") );
$count=0;
foreach($changedValues as $key =>$value){
if(($value!=NULL)&&(!is_array($value))){
$tpl->newBlock( "FIELDLOG" );
$tpl->assign( "fieldName" , $key );
$tpl->assign( "previous" , isset($historyData[$tableNameA][$key])?$historyData[$tableNameA][$key]:"" );
$tpl->assign( "actual" , $value );
$count++;
}
if(is_array($value)){
foreach($value as $key1 =>$value1){
if(is_array($value1)){
foreach($value1 as $key2 =>$value2){
$name=$key."[".$key1."]"."[".$key2."]";
$tpl->newBlock( "FIELDLOG" );
$tpl->assign( "fieldName" , $name );
$tpl->assign( "previous" , isset($historyData[$tableNameA][$key][$key1][$key2])?$historyData[$tableNameA][$key][$key1][$key2]:"" );
$tpl->assign( "actual" , $value2 );
$count++;
}
}
}
}
}
$tpl->gotoBlock( "DYNLOG" );
$tpl->assign( "dynChanges" , G::LoadTranslation("ID_FIELDS_CHANGED_NUMBER")." (".$count.")" );
$tpl->assign( "count" , $count+1 );
$oDataset->next();
}
if(!isset($changedValues)){
$tpl->newBlock( "NORESULTS" );
$tpl->assign( "noResults" , G::LoadTranslation("ID_NO_RECORDS_FOUND"));
}
$_SESSION['HISTORY_DATA']=serialize($historyData);
$tpl->gotoBlock( "_ROOT" );
$tpl->printToScreen();
?>