alreadyRouted($_SESSION['APPLICATION'],$_SESSION['INDEX']) ) {
if($_SESSION['gmail'] == 1){
$mUrl = '../cases/cases_Open?APP_UID='.$_SESSION['APPLICATION'].'&DEL_INDEX='.$_SESSION['INDEX'].'&action=sent';
header( 'location:' . $mUrl );
die();
}
G::header('location: ../cases/casesListExtJs');
die();
}
if (!isset($_SESSION['USER_LOGGED'])) {
G::SendTemporalMessage( 'ID_LOGIN_AGAIN', 'warning', 'labels' );
die( '');
}
/**
* cases_Step.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 .
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
/* Permissions */
switch ($RBAC->userCanAccess( 'PM_CASES' )) {
case - 2:
G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels' );
G::header( 'location: ../login/login' );
die();
break;
case - 1:
G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels' );
G::header( 'location: ../login/login' );
die();
break;
}
if ((int) $_SESSION['INDEX'] < 1) {
G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels' );
G::header( 'location: ' . $_SERVER['HTTP_REFERER'] );
die();
}
global $_DBArray;
if (! isset( $_DBArray )) {
$_DBArray = array ();
}
/* Includes */
G::LoadClass( 'case' );
G::LoadClass( 'derivation' );
/* GET , POST & $_SESSION Vars */
if (isset( $_GET['POSITION'] )) {
$_SESSION['STEP_POSITION'] = (int) $_GET['POSITION'];
}
if (isset( $_SESSION['CASES_REFRESH'] )) {
unset( $_SESSION['CASES_REFRESH'] );
G::evalJScript( "if(typeof parent != 'undefined' && parent.refreshCountFolders) parent.refreshCountFolders();" );
}
/* Menues */
$G_MAIN_MENU = 'processmaker';
$G_ID_MENU_SELECTED = 'CASES';
$G_SUB_MENU = 'caseOptions';
$G_ID_SUB_MENU_SELECTED = '_';
/* Prepare page before to show */
$oTemplatePower = new TemplatePower( PATH_TPL . 'cases/cases_Step.html' );
$oTemplatePower->prepare();
$G_PUBLISH = new Publisher();
$oHeadPublisher = & headPublisher::getSingleton();
$oHeadPublisher->addScriptCode( '
var Cse = {};
Cse.panels = {};
var leimnud = new maborak();
leimnud.make();
leimnud.Package.Load("rpc,drag,drop,panel,app,validator,fx,dom,abbr",{Instance:leimnud,Type:"module"});
leimnud.exec(leimnud.fix.memoryLeak);
leimnud.event.add(window,"load",function(){
' . (isset( $_SESSION['showCasesWindow'] ) ? 'try{' . $_SESSION['showCasesWindow'] . '}catch(e){}' : '') . '
});
' );
$G_PUBLISH->AddContent( 'template', '', '', '', $oTemplatePower );
$oCase = new Cases();
$oStep = new Step();
$Fields = $oCase->loadCase( $_SESSION['APPLICATION'] );
$Fields['APP_DATA'] = array_merge( $Fields['APP_DATA'], G::getSystemConstants() );
$sStatus = $Fields['APP_STATUS'];
$APP_NUMBER = $Fields['APP_NUMBER'];
$APP_TITLE = $Fields['TITLE'];
$oProcess = new Process();
$oProcessFieds = $oProcess->Load( $_SESSION['PROCESS'] );
#trigger debug routines...
if (isset( $oProcessFieds['PRO_DEBUG'] ) && $oProcessFieds['PRO_DEBUG']) {
#here we must verify if is a debugg session
$_SESSION['TRIGGER_DEBUG']['ISSET'] = 1;
$_SESSION['PMDEBUGGER'] = true;
} else {
$_SESSION['TRIGGER_DEBUG']['ISSET'] = 0;
$_SESSION['PMDEBUGGER'] = false;
}
//cleaning debug variables
$flagExecuteBeforeTriggers = !isset($_GET["breakpoint"]);
if (isset($_GET["TYPE"]) && $_GET["TYPE"] == "OUTPUT_DOCUMENT" && isset($_GET["ACTION"]) && $_GET["ACTION"] != "GENERATE") {
$flagExecuteBeforeTriggers = false;
}
if ($flagExecuteBeforeTriggers) {
if (isset( $_SESSION['TRIGGER_DEBUG']['info'] )) {
unset( $_SESSION['TRIGGER_DEBUG']['info'] );
}
if (! isset( $_SESSION['_NO_EXECUTE_TRIGGERS_'] )) {
$_SESSION['TRIGGER_DEBUG']['ERRORS'] = Array ();
}
$_SESSION['TRIGGER_DEBUG']['DATA'] = Array ();
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = Array ();
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = Array ();
$triggers = $oCase->loadTriggers( $_SESSION['TASK'], $_GET['TYPE'], $_GET['UID'], 'BEFORE' );
$_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] = count( $triggers );
$_SESSION['TRIGGER_DEBUG']['TIME'] = G::toUpper(G::loadTranslation('ID_BEFORE'));
if ($_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] != 0) {
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = $oCase->getTriggerNames( $triggers );
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = $triggers;
}
if (! isset( $_SESSION['_NO_EXECUTE_TRIGGERS_'] )) {
//Execute before triggers - Start
$Fields['APP_DATA'] = $oCase->ExecuteTriggers( $_SESSION['TASK'], $_GET['TYPE'], $_GET['UID'], 'BEFORE', $Fields['APP_DATA'] );
//Execute before triggers - End
} else {
unset( $_SESSION['_NO_EXECUTE_TRIGGERS_'] );
}
}
$Fields["DEL_INDEX"] = $_SESSION["INDEX"];
$Fields["TAS_UID"] = $_SESSION["TASK"];
if (isset( $_GET['breakpoint'] )) {
$_POST['NextStep'] = $_SESSION['TRIGGER_DEBUG']['BREAKPAGE'];
}
/**
* Here we throw the debug view
*/
if (isset( $_GET['breakpoint'] )) {
$G_PUBLISH->AddContent( 'view', 'cases/showDebugFrameLoader' );
$G_PUBLISH->AddContent( 'view', 'cases/showDebugFrameBreaker' );
G::RenderPage( 'publish', 'blank' );
exit();
}
#end trigger debug session.......
//$oCase->thisIsTheCurrentUser($_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['USER_LOGGED'], 'REDIRECT', 'casesListExtJs');
//Save data - Start
unset($Fields['APP_STATUS']);
unset($Fields['APP_PROC_STATUS']);
unset($Fields['APP_PROC_CODE']);
unset($Fields['APP_PIN']);
$Fields["USER_UID"] = $_SESSION["USER_LOGGED"];
$Fields["CURRENT_DYNAFORM"] = $_GET["UID"];
$Fields["OBJECT_TYPE"] = ($_GET["UID"] == "-1")? "ASSIGN_TASK" : $_GET["TYPE"];
$oCase->updateCase( $_SESSION['APPLICATION'], $Fields );
//Save data - End
//Obtain previous and next step - Start
try {
$oCase = new Cases();
$aNextStep = $oCase->getNextStep( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION'] );
$aPreviousStep = $oCase->getPreviousStep( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION'] );
} catch (Exception $e) {
}
//Obtain previous and next step - End
$aRequiredFields = array(
'APPLICATION' => $Fields['APP_DATA']['APPLICATION'],
'PROCESS' => $Fields['APP_DATA']['PROCESS'],
'TASK' => $Fields['APP_DATA']['TASK'],
'INDEX' => $Fields['APP_DATA']['INDEX'],
'TRIGGER_DEBUG' => isset($Fields['APP_DATA']['TRIGGER_DEBUG']) ? $Fields['APP_DATA']['TRIGGER_DEBUG']:array()
);
$oHeadPublisher->addScriptCode('var __dynaformSVal__ = \'' . base64_encode(serialize($aRequiredFields)) . '\'; ');
try {
//Add content content step - Start
$oApp = ApplicationPeer::retrieveByPK( $_SESSION['APPLICATION'] );
$array['APP_NUMBER'] = $APP_NUMBER;
$sTitleCase = $oApp->getAppTitle();
$array['APP_TITLE'] = $sTitleCase;
$array['CASE'] = G::LoadTranslation( 'ID_CASE' );
$array['TITLE'] = G::LoadTranslation( 'ID_TITLE' );
$noShowTitle = 0;
if (isset( $oProcessFieds['PRO_SHOW_MESSAGE'] )) {
$noShowTitle = $oProcessFieds['PRO_SHOW_MESSAGE'];
}
switch ($_GET['TYPE']) {
case 'DYNAFORM':
if ($noShowTitle == 0) {
$G_PUBLISH->AddContent( 'smarty', 'cases/cases_title', '', '', $array );
}
if (! $aPreviousStep) {
$Fields['APP_DATA']['__DYNAFORM_OPTIONS']['PREVIOUS_STEP_LABEL'] = '';
} else {
$Fields['APP_DATA']['__DYNAFORM_OPTIONS']['PREVIOUS_STEP'] = $aPreviousStep['PAGE'];
$Fields['APP_DATA']['__DYNAFORM_OPTIONS']['PREVIOUS_STEP_LABEL'] = G::loadTranslation( "ID_PREVIOUS_STEP" );
}
$Fields['APP_DATA']['__DYNAFORM_OPTIONS']['NEXT_STEP'] = $aNextStep['PAGE'];
$Fields['APP_DATA']['__DYNAFORM_OPTIONS']['NEXT_STEP_LABEL'] = G::loadTranslation( 'ID_NEXT_STEP' );
$Fields['APP_DATA']['__DYNAFORM_OPTIONS']['PHPSESSID'] = @session_id();
$Fields['APP_DATA']['__DYNAFORM_OPTIONS']['DYNUIDPRINT'] = $_GET['UID'];
$oHeadPublisher = & headPublisher::getSingleton();
if (!isset($_SESSION["PM_RUN_OUTSIDE_MAIN_APP"])) {
$oHeadPublisher->addScriptCode( "
if (typeof parent != 'undefined') {
if (parent.setNode) {
parent.setNode('" . $_GET['UID'] . "');
}
}" );
}
$oStep = $oStep->loadByProcessTaskPosition( $_SESSION['PROCESS'], $_SESSION['TASK'], $_GET['POSITION'] );
/**
* Added By erik 16-05-08
* Description: this was added for the additional database connections
*/
G::LoadClass( 'dbConnections' );
$oDbConnections = new dbConnections( $_SESSION['PROCESS'] );
$oDbConnections->loadAdditionalConnections();
$_SESSION['CURRENT_DYN_UID'] = $_GET['UID'];
G::LoadClass('pmDynaform');
$FieldsPmDynaform = $Fields;
$FieldsPmDynaform["PM_RUN_OUTSIDE_MAIN_APP"] = (!isset($_SESSION["PM_RUN_OUTSIDE_MAIN_APP"])) ? "true" : "false";
$FieldsPmDynaform["STEP_MODE"] = $oStep->getStepMode();
$FieldsPmDynaform["PRO_SHOW_MESSAGE"] = $noShowTitle;
$FieldsPmDynaform["TRIGGER_DEBUG"] = $_SESSION['TRIGGER_DEBUG']['ISSET'];
$a = new pmDynaform($FieldsPmDynaform);
if ($a->isResponsive()) {
$a->printEdit();
} else {
$G_PUBLISH->AddContent('dynaform', 'xmlform', $_SESSION['PROCESS'] . '/' . $_GET['UID'], '', $Fields['APP_DATA'], 'cases_SaveData?UID=' . $_GET['UID'] . '&APP_UID=' . $_SESSION['APPLICATION'], '', (strtolower($oStep->getStepMode()) != 'edit' ? strtolower($oStep->getStepMode()) : ''));
}
break;
case 'INPUT_DOCUMENT':
if ($noShowTitle == 0) {
$G_PUBLISH->AddContent( 'smarty', 'cases/cases_title', '', '', $array );
}
$oInputDocument = new InputDocument();
$Fields = $oInputDocument->load( $_GET['UID'] );
if (! $aPreviousStep) {
$Fields['__DYNAFORM_OPTIONS']['PREVIOUS_STEP_LABEL'] = '';
$Fields['PREVIOUS_STEP_LABEL'] = '';
} else {
$Fields['__DYNAFORM_OPTIONS']['PREVIOUS_STEP'] = $aPreviousStep['PAGE'];
$Fields['__DYNAFORM_OPTIONS']['PREVIOUS_STEP_LABEL'] = G::loadTranslation( "ID_PREVIOUS_STEP" );
$Fields['PREVIOUS_STEP'] = $aPreviousStep['PAGE'];
$Fields['PREVIOUS_STEP_LABEL'] = G::loadTranslation( "ID_PREVIOUS_STEP" );
}
$Fields['NEXT_STEP'] = $aNextStep['PAGE'];
$Fields['NEXT_STEP_LABEL'] = G::loadTranslation( "ID_NEXT_STEP" );
switch ($_GET['ACTION']) {
case 'ATTACH':
switch ($Fields['INP_DOC_FORM_NEEDED']) {
case 'REAL':
$Fields['TYPE_LABEL'] = G::LoadTranslation( 'ID_NEW' );
$sXmlForm = 'cases/cases_AttachInputDocument2';
break;
case 'VIRTUAL':
$Fields['TYPE_LABEL'] = G::LoadTranslation( 'ID_ATTACH' );
$sXmlForm = 'cases/cases_AttachInputDocument1';
break;
case 'VREAL':
$Fields['TYPE_LABEL'] = G::LoadTranslation( 'ID_ATTACH' );
$sXmlForm = 'cases/cases_AttachInputDocument3';
break;
}
$Fields['MESSAGE1'] = G::LoadTranslation( 'ID_PLEASE_ENTER_COMMENTS' );
$Fields['MESSAGE2'] = G::LoadTranslation( 'ID_PLEASE_SELECT_FILE' );
//START: If there is a Break Step registered from Plugin Similar as a Trigger debug
$oPluginRegistry = & PMPluginRegistry::getSingleton();
if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT_BEFORE )) {
//If a Plugin has registered a Break Page Evaluator
$oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT_BEFORE, array ('USR_UID' => $_SESSION['USER_LOGGED']) );
}
//END: If there is a Break Step registered from Plugin
$G_PUBLISH->AddContent( 'propeltable', 'cases/paged-table-inputDocuments', 'cases/cases_InputdocsList', $oCase->getInputDocumentsCriteria( $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_GET['UID'] ), array_merge( array ('DOC_UID' => $_GET['UID']
), $Fields ) ); //$aFields
//call plugin
//if ( $oPluginRegistry->existsTrigger ( PM_CASE_DOCUMENT_LIST ) ) {
// $folderData = new folderData (null, null, $_SESSION['APPLICATION'], null, $_SESSION['USER_LOGGED'] );
// $oPluginRegistry =& PMPluginRegistry::getSingleton();
// $oPluginRegistry->executeTriggers ( PM_CASE_DOCUMENT_LIST , $folderData );
// //end plugin
//}
//else
// $G_PUBLISH->AddContent('propeltable', 'cases/paged-table-inputDocuments', 'cases/cases_InputdocsList', $oCase->getInputDocumentsCriteria($_SESSION['APPLICATION'], $_SESSION['INDEX'], $_GET['UID']), array_merge(array('DOC_UID'=>$_GET['UID']),$Fields));//$aFields
$oHeadPublisher = & headPublisher::getSingleton();
$titleDocument = "
" . $Fields['INP_DOC_TITLE'] . "
" . G::LoadTranslation( 'ID_INPUT_DOCUMENT' ) . "
";
if ($Fields['INP_DOC_DESCRIPTION']) {
$titleDocument .= " " . str_replace( "\n", "", str_replace( "'", "\'", nl2br( html_entity_decode($Fields['INP_DOC_DESCRIPTION'], ENT_COMPAT, "UTF-8") ) ) ) . "";
}
$oHeadPublisher->addScriptCode( "documentName='{$titleDocument}';" );
break;
case 'VIEW':
//require_once 'classes/model/AppDocument.php';
//require_once 'classes/model/Users.php';
$oAppDocument = new AppDocument();
$oAppDocument->Fields = $oAppDocument->load( $_GET['DOC'], $_GET['VERSION'] );
$Fields['POSITION'] = $_SESSION['STEP_POSITION'];
$oUser = new Users();
$aUser = $oUser->load( $oAppDocument->Fields['USR_UID'] );
$Fields['CREATOR'] = $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'];
switch ($Fields['INP_DOC_FORM_NEEDED']) {
case 'REAL':
$sXmlForm = 'cases/cases_ViewInputDocument2';
break;
case 'VIRTUAL':
$sXmlForm = 'cases/cases_ViewInputDocument1';
break;
case 'VREAL':
$sXmlForm = 'cases/cases_ViewInputDocument3';
break;
}
$oAppDocument->Fields['VIEW'] = G::LoadTranslation( 'ID_OPEN' );
$oAppDocument->Fields['FILE'] = 'cases_ShowDocument?a=' . $_GET['DOC'] . '&r=' . rand();
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', $sXmlForm, '', G::array_merges( $Fields, $oAppDocument->Fields ), '' );
break;
}
break;
case 'OUTPUT_DOCUMENT':
//$G_PUBLISH->AddContent('smarty', 'cases/cases_title', '', '', $array);
//require_once 'classes/model/OutputDocument.php';
$oOutputDocument = new OutputDocument();
$aOD = $oOutputDocument->load( $_GET['UID'] );
if (! $aPreviousStep) {
$aOD['__DYNAFORM_OPTIONS']['PREVIOUS_STEP_LABEL'] = '';
} else {
$aOD['__DYNAFORM_OPTIONS']['PREVIOUS_STEP'] = $aPreviousStep['PAGE'];
$aOD['__DYNAFORM_OPTIONS']['PREVIOUS_STEP_LABEL'] = G::loadTranslation( "ID_PREVIOUS_STEP" );
}
$aOD['__DYNAFORM_OPTIONS']['NEXT_STEP'] = $aNextStep['PAGE'];
$aOD['__DYNAFORM_OPTIONS']['NEXT_STEP_LABEL'] = G::loadTranslation( "ID_NEXT_STEP" );
switch ($_GET['ACTION']) {
case 'GENERATE':
//START: If there is a Break Step registered from Plugin Similar as a Trigger debug
$oPluginRegistry = & PMPluginRegistry::getSingleton();
if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT_BEFORE )) {
//If a Plugin has registered a Break Page Evaluator
$oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT_BEFORE, array ('USR_UID' => $_SESSION['USER_LOGGED']) );
}
//END: If there is a Break Step registered from Plugin
$sFilenameOriginal = $sFilename = preg_replace( '[^A-Za-z0-9_]', '_', G::replaceDataField( $aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA'] ) );
//require_once 'classes/model/AppFolder.php';
//require_once 'classes/model/AppDocument.php';
//Get the Custom Folder ID (create if necessary)
$oFolder = new AppFolder();
$folderId = $oFolder->createFromPath( $aOD['OUT_DOC_DESTINATION_PATH'] );
//Tags
$fileTags = $oFolder->parseTags( $aOD['OUT_DOC_TAGS'] );
//Get last Document Version and apply versioning if is enabled
$oAppDocument = new AppDocument();
$lastDocVersion = $oAppDocument->getLastDocVersion( $_GET['UID'], $_SESSION['APPLICATION'] );
//if(($aOD['OUT_DOC_VERSIONING'])||($lastDocVersion==0)){
// $lastDocVersion++;
//}
$oCriteria = new Criteria( 'workflow' );
$oCriteria->add( AppDocumentPeer::APP_UID, $_SESSION['APPLICATION'] );
//$oCriteria->add(AppDocumentPeer::DEL_INDEX, $_SESSION['INDEX']);
$oCriteria->add( AppDocumentPeer::DOC_UID, $_GET['UID'] );
$oCriteria->add( AppDocumentPeer::DOC_VERSION, $lastDocVersion );
$oCriteria->add( AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT' );
$oDataset = AppDocumentPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
if (($aOD['OUT_DOC_VERSIONING']) && ($lastDocVersion != 0)) {
//Create new Version of current output
$lastDocVersion ++;
if ($aRow = $oDataset->getRow()) {
$aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $_SESSION['APPLICATION'],'DEL_INDEX' => $_SESSION['INDEX'],'DOC_UID' => $_GET['UID'],'DOC_VERSION' => $lastDocVersion + 1,'USR_UID' => $_SESSION['USER_LOGGED'],'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
);
$oAppDocument = new AppDocument();
$oAppDocument->create( $aFields );
$sDocUID = $aRow['APP_DOC_UID'];
}
} else {
//No versioning so Update a current Output or Create new if no exist
if ($aRow = $oDataset->getRow()) {
//Update
$aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $_SESSION['APPLICATION'],'DEL_INDEX' => $_SESSION['INDEX'],'DOC_UID' => $_GET['UID'],'DOC_VERSION' => $lastDocVersion,'USR_UID' => $_SESSION['USER_LOGGED'],'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags );
$oAppDocument = new AppDocument();
$oAppDocument->update( $aFields );
$sDocUID = $aRow['APP_DOC_UID'];
} else {
//create
if ($lastDocVersion == 0) {
$lastDocVersion ++;
}
$aFields = array ('APP_UID' => $_SESSION['APPLICATION'],'DEL_INDEX' => $_SESSION['INDEX'],'DOC_UID' => $_GET['UID'],'DOC_VERSION' => $lastDocVersion,'USR_UID' => $_SESSION['USER_LOGGED'],'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags);
$oAppDocument = new AppDocument();
$aFields['APP_DOC_UID'] = $sDocUID = $oAppDocument->create( $aFields );
}
}
//$sFilename = ereg_replace('[^A-Za-z0-9_]', '_', G::replaceDataField($aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA']));
//if ( $sFilename == '' ) $sFilename='_';
$sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion;
$pathOutput = PATH_DOCUMENT . G::getPathFromUID($_SESSION['APPLICATION']) . PATH_SEP . 'outdocs' . PATH_SEP;
G::mk_dir( $pathOutput );
switch ($aOD['OUT_DOC_TYPE']) {
case 'HTML':
$aProperties = array (); //maui
if (! isset( $aOD['OUT_DOC_MEDIA'] )) {
$aOD['OUT_DOC_MEDIA'] = 'Letter';
}
if (! isset( $aOD['OUT_DOC_LEFT_MARGIN'] )) {
$aOD['OUT_DOC_LEFT_MARGIN'] = '15';
}
if (! isset( $aOD['OUT_DOC_RIGHT_MARGIN'] )) {
$aOD['OUT_DOC_RIGHT_MARGIN'] = '15';
}
if (! isset( $aOD['OUT_DOC_TOP_MARGIN'] )) {
$aOD['OUT_DOC_TOP_MARGIN'] = '15';
}
if (! isset( $aOD['OUT_DOC_BOTTOM_MARGIN'] )) {
$aOD['OUT_DOC_BOTTOM_MARGIN'] = '15';
}
$aProperties['media'] = $aOD['OUT_DOC_MEDIA'];
$aProperties['margins'] = array ('left' => $aOD['OUT_DOC_LEFT_MARGIN'],'right' => $aOD['OUT_DOC_RIGHT_MARGIN'],'top' => $aOD['OUT_DOC_TOP_MARGIN'],'bottom' => $aOD['OUT_DOC_BOTTOM_MARGIN']);
if ($aOD['OUT_DOC_PDF_SECURITY_ENABLED'] == '1') {
$aProperties['pdfSecurity'] = array ('openPassword' => $aOD['OUT_DOC_PDF_SECURITY_OPEN_PASSWORD'],'ownerPassword' => $aOD['OUT_DOC_PDF_SECURITY_OWNER_PASSWORD'],'permissions' => $aOD['OUT_DOC_PDF_SECURITY_PERMISSIONS']);
}
if (isset($aOD['OUT_DOC_REPORT_GENERATOR'])) {
$aProperties['report_generator'] = $aOD['OUT_DOC_REPORT_GENERATOR'];
}
$oOutputDocument->generate( $_GET['UID'], $Fields['APP_DATA'], $pathOutput, $sFilename, $aOD['OUT_DOC_TEMPLATE'], (boolean) $aOD['OUT_DOC_LANDSCAPE'], $aOD['OUT_DOC_GENERATE'], $aProperties );
//$sFilename, $aOD['OUT_DOC_TEMPLATE'], (boolean)$aOD['OUT_DOC_LANDSCAPE'], $aOD['OUT_DOC_GENERATE'] );
break;
case 'JRXML':
//creating the xml with the application data;
$xmlData = "\n";
foreach ($Fields['APP_DATA'] as $key => $val) {
$xmlData .= " <$key>$val$key>\n";
}
$xmlData .= "\n";
$iSize = file_put_contents( $javaOutput . 'addressBook.xml', $xmlData );
G::LoadClass( 'javaBridgePM' );
$JBPM = new JavaBridgePM();
$JBPM->checkJavaExtension();
$util = new Java( "com.processmaker.util.pmutils" );
$util->setInputPath( $javaInput );
$util->setOutputPath( $javaOutput );
G::LoadSystem('inputfilter');
$filter = new InputFilter();
//$content = file_get_contents ( PATH_DYNAFORM . $aOD['PRO_UID'] . PATH_SEP . $aOD['OUT_DOC_UID'] . '.jrxml' );
//$iSize = file_put_contents ( $javaInput . $aOD['OUT_DOC_UID'] . '.jrxml', $content );
$locationFrom = PATH_DYNAFORM . $aOD['PRO_UID'] . PATH_SEP . $aOD['OUT_DOC_UID'] . '.jrxml';
$locationFrom = $filter->validateInput($locationFrom, "path");
copy( $locationFrom, $javaInput . $aOD['OUT_DOC_UID'] . '.jrxml' );
$outputFile = $javaOutput . $sFilename . '.pdf';
print $util->jrxml2pdf( $aOD['OUT_DOC_UID'] . '.jrxml', basename( $outputFile ) );
//$content = file_get_contents ( $outputFile );
//$iSize = file_put_contents ( $pathOutput . $sFilename . '.pdf' , $content );
$outputFile = $filter->validateInput($outputFile, "path");
copy( $outputFile, $pathOutput . $sFilename . '.pdf' );
//die;
break;
case 'ACROFORM':
//creating the xml with the application data;
$xmlData = "\n";
foreach ($Fields['APP_DATA'] as $key => $val) {
$xmlData .= " <$key>$val$key>\n";
}
$xmlData .= "\n";
//$iSize = file_put_contents ( $javaOutput . 'addressBook.xml' , $xmlData );
G::LoadClass( 'javaBridgePM' );
$JBPM = new JavaBridgePM();
$JBPM->checkJavaExtension();
$util = new Java( "com.processmaker.util.pmutils" );
$util->setInputPath( $javaInput );
$util->setOutputPath( $javaOutput );
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$locationFrom = PATH_DYNAFORM . $aOD['PRO_UID'] . PATH_SEP . $aOD['OUT_DOC_UID'] . '.pdf';
$locationFrom = $filter->validateInput($locationFrom, "path");
copy( $locationFrom, $javaInput . $aOD['OUT_DOC_UID'] . '.pdf' );
$outputFile = $javaOutput . $sFilename . '.pdf';
print $util->writeVarsToAcroFields( $aOD['OUT_DOC_UID'] . '.pdf', $xmlData );
$locationFrom = $javaOutput . $aOD['OUT_DOC_UID'] . '.pdf';
$locationFrom = $filter->validateInput($locationFrom, "path");
copy( $locationFrom, $pathOutput . $sFilename . '.pdf' );
break;
default:
throw (new Exception( 'invalid output document' ));
}
//Execute after triggers - Start
$Fields['APP_DATA'] = $oCase->ExecuteTriggers( $_SESSION['TASK'], 'OUTPUT_DOCUMENT', $_GET['UID'], 'AFTER', $Fields['APP_DATA'] );
$Fields['DEL_INDEX'] = $_SESSION['INDEX'];
$Fields['TAS_UID'] = $_SESSION['TASK'];
//Execute after triggers - End
//Save data - Start
unset($Fields['APP_STATUS']);
unset($Fields['APP_PROC_STATUS']);
unset($Fields['APP_PROC_CODE']);
unset($Fields['APP_PIN']);
$oCase->updateCase( $_SESSION['APPLICATION'], $Fields );
//Save data - End
/*----------------------------------********---------------------------------*/
$licensedFeatures = &PMLicensedFeatures::getSingleton();
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
G::LoadClass( "pmDrive" );
$pmDrive = new PMDrive();
if ($pmDrive->getStatusService()) {
$app = new Application();
$user = new Users();
$dataUser = $user->load($_SESSION['USER_LOGGED']);
$pmDrive->setDriveUser($dataUser['USR_EMAIL']);
$applicationUid = $_SESSION['APPLICATION'];
$appData = $app->Load($applicationUid);
if ($appData['APP_DRIVE_FOLDER_UID'] == null) {
$process = new Process();
$process->setProUid($appData['PRO_UID']);
$result = $pmDrive->createFolder($process->getProTitle() . ' - ' . G::LoadTranslation("ID_CASE") . ' #' . $appData['APP_NUMBER'],
$pmDrive->getFolderIdPMDrive($_SESSION['USER_LOGGED']));
$appData['APP_DRIVE_FOLDER_UID'] = $result->id;
$app->update($appData);
}
$fileIdDriveDoc = '';
$fileIdDrivePdf = '';
switch ($aOD['OUT_DOC_GENERATE']) {
case "BOTH":
$result = $pmDrive->uploadFile('application/pdf', $pathOutput . $sFilename . '.pdf',
$sFilenameOriginal . '.pdf', $appData['APP_DRIVE_FOLDER_UID']);
$oAppDocument->setDriveDownload('OUTPUT_PDF', $result->webContentLink);
$fileIdDrivePdf = $result->id;
$result = $pmDrive->uploadFile('application/doc', $pathOutput . $sFilename . '.doc',
$sFilenameOriginal . '.doc', $appData['APP_DRIVE_FOLDER_UID']);
$oAppDocument->setDriveDownload('OUTPUT_DOC', $result->webContentLink);
$fileIdDriveDoc = $result->id;
break;
case "PDF":
$result = $pmDrive->uploadFile('application/pdf', $pathOutput . $sFilename . '.pdf',
$sFilenameOriginal . '.pdf', $appData['APP_DRIVE_FOLDER_UID']);
$oAppDocument->setDriveDownload('OUTPUT_PDF', $result->webContentLink);
$fileIdDrivePdf = $result->id;
break;
case "DOC":
$result = $pmDrive->uploadFile('application/doc', $pathOutput . $sFilename . '.doc',
$sFilenameOriginal . '.doc', $appData['APP_DRIVE_FOLDER_UID']);
$oAppDocument->setDriveDownload('OUTPUT_DOC', $result->webContentLink);
$fileIdDriveDoc = $result->id;
break;
}
$aFields['DOC_VERSION'] = $oAppDocument->getDocVersion();// $docVersion;
$aFields['APP_DOC_UID'] = $oAppDocument->getAppDocUid();//$appDocUid;
$appDocUid = $aFields['APP_DOC_UID'];
$oAppDocument->update($aFields);
//$option = 'pmDrive';
//add permissions
$criteria = new Criteria('workflow');
$criteria->addSelectColumn(ApplicationPeer::PRO_UID);
$criteria->addSelectColumn(TaskUserPeer::TAS_UID);
$criteria->addSelectColumn(TaskUserPeer::USR_UID);
$criteria->addSelectColumn(TaskUserPeer::TU_RELATION);
$criteria->add(ApplicationPeer::APP_UID, $applicationUid);
$criteria->addJoin(ApplicationPeer::PRO_UID, TaskPeer::PRO_UID, Criteria::LEFT_JOIN);
$criteria->addJoin(TaskPeer::TAS_UID, TaskUserPeer::TAS_UID, Criteria::LEFT_JOIN);
$dataset = ApplicationPeer::doSelectRs($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$userPermission = array();
$case = new Cases();
while ($dataset->next()) {
$row = $dataset->getRow();
if ($row['TU_RELATION'] == 1) {
//users
$dataUser = $user->load($row['USR_UID']);
if (array_search($dataUser['USR_EMAIL'], $userPermission) == null) {
$objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid,
$row['TAS_UID'], $row['USR_UID']);
if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) != null) {
$userPermission[] = $dataUser['USR_EMAIL'];
}
}
} else {
//Groups
$criteria = new Criteria('workflow');
$criteria->addSelectColumn(UsersPeer::USR_EMAIL);
$criteria->addSelectColumn(UsersPeer::USR_UID);
$criteria->add(GroupUserPeer::GRP_UID, $row['USR_UID']);
$criteria->addJoin(GroupUserPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN);
$oDataset = AppDelegationPeer::doSelectRs($criteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($oDataset->next()) {
$aRow = $oDataset->getRow();
if (array_search($aRow['USR_EMAIL'], $userPermission) == null) {
$objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid,
$row['TAS_UID'], $aRow['USR_UID']);
if (array_search($appDocUid,
$objectPermissions['OUTPUT_DOCUMENTS']) != null
) {
$userPermission[] = $aRow['USR_EMAIL'];
}
}
}
}
}
$userPermission = array_unique($userPermission);
foreach ($userPermission as $key => $val) {
$pmDrive->setPermission($appData['APP_DRIVE_FOLDER_UID'], $val, 'user', 'writer');
$pmDrive->setPermission($fileIdDrivePdf, $val);
$pmDrive->setPermission($fileIdDriveDoc, $val);
}
}
}
/*----------------------------------********---------------------------------*/
//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 );
$sPathName = PATH_DOCUMENT . G::getPathFromUID($_SESSION['APPLICATION']) . PATH_SEP;
$oData['APP_UID'] = $_SESSION['APPLICATION'];
$oData['ATTACHMENT_FOLDER'] = true;
switch ($aOD['OUT_DOC_GENERATE']) {
case "BOTH":
$documentData = new uploadDocumentData( $_SESSION['APPLICATION'], $_SESSION['USER_LOGGED'], $pathOutput . $sFilename . '.pdf', $sFilenameOriginal . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "PDF";
$documentData->bUseOutputFolder = true;
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
$aFields['APP_DOC_PLUGIN'] = $triggerDetail->sNamespace;
//$oAppDocument = new AppDocument();
//$oAppDocument->update($aFields);
unlink( $pathOutput . $sFilename . '.pdf' );
}
$documentData = new uploadDocumentData( $_SESSION['APPLICATION'], $_SESSION['USER_LOGGED'], $pathOutput . $sFilename . '.doc', $sFilenameOriginal . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "DOC";
$documentData->bUseOutputFolder = true;
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
unlink( $pathOutput . $sFilename . '.doc' );
}
break;
case "PDF":
$documentData = new uploadDocumentData( $_SESSION['APPLICATION'], $_SESSION['USER_LOGGED'], $pathOutput . $sFilename . '.pdf', $sFilenameOriginal . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "PDF";
$documentData->bUseOutputFolder = true;
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
unlink( $pathOutput . $sFilename . '.pdf' );
}
break;
case "DOC":
$documentData = new uploadDocumentData( $_SESSION['APPLICATION'], $_SESSION['USER_LOGGED'], $pathOutput . $sFilename . '.doc', $sFilenameOriginal . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
$documentData->sFileType = "DOC";
$documentData->bUseOutputFolder = true;
$uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
if ($uploadReturn) {
//Only delete if the file was saved correctly
unlink( $pathOutput . $sFilename . '.doc' );
}
break;
}
}
$outputNextStep = 'cases_Step?TYPE=OUTPUT_DOCUMENT&UID=' . $_GET['UID'] . '&POSITION=' . $_SESSION['STEP_POSITION'] . '&ACTION=VIEW&DOC=' . $sDocUID;
G::header( 'location: ' . $outputNextStep );
die();
break;
case 'VIEW':
if ($noShowTitle == 0) {
$G_PUBLISH->AddContent( 'smarty', 'cases/cases_title', '', '', $array );
}
//require_once 'classes/model/AppDocument.php';
$oAppDocument = new AppDocument();
$lastVersion = $oAppDocument->getLastAppDocVersion( $_GET['DOC'], $_SESSION['APPLICATION'] );
$aFields = $oAppDocument->load( $_GET['DOC'], $lastVersion );
$listing = false;
$oPluginRegistry = & PMPluginRegistry::getSingleton();
if ($oPluginRegistry->existsTrigger( PM_CASE_DOCUMENT_LIST )) {
$folderData = new folderData( null, null, $_SESSION['APPLICATION'], null, $_SESSION['USER_LOGGED'] );
$folderData->PMType = "OUTPUT";
$folderData->returnList = true;
$listing = $oPluginRegistry->executeTriggers( PM_CASE_DOCUMENT_LIST, $folderData );
}
//require_once 'classes/model/OutputDocument.php';
$oOutputDocument = new OutputDocument();
$aGields = $oOutputDocument->load( $aFields['DOC_UID'] );
if (isset( $aGields['OUT_DOC_VERSIONING'] ) && $aGields['OUT_DOC_VERSIONING'] != 0) {
$oAppDocument = new AppDocument();
$lastDocVersion = $oAppDocument->getLastDocVersion( $_GET['UID'], $_SESSION['APPLICATION'] );
} else {
$lastDocVersion = '';
}
$aFields['VIEW1'] = G::LoadTranslation( 'ID_OPEN' );
$aFields['VIEW2'] = G::LoadTranslation( 'ID_OPEN' );
$aFields['FILE1'] = 'cases_ShowOutputDocument?a=' . $aFields['APP_DOC_UID'] . '&v=' . $lastDocVersion . '&ext=doc&random=' . rand() . '&PHPSESSID=' . @session_id();
$aFields['FILE2'] = 'cases_ShowOutputDocument?a=' . $aFields['APP_DOC_UID'] . '&v=' . $lastDocVersion . '&ext=pdf&random=' . rand() . '&PHPSESSID=' . @session_id();
if (is_array( $listing )) {
//If exist in Plugin Document List
foreach ($listing as $folderitem) {
if (($folderitem->filename == $aFields['APP_DOC_UID']) && ($folderitem->type == 'DOC')) {
$aFields['VIEW1'] = G::LoadTranslation( 'ID_GET_EXTERNAL_FILE' );
$aFields['FILE1'] = $folderitem->downloadScript;
continue;
}
if (($folderitem->filename == $aFields['APP_DOC_UID']) && ($folderitem->type == 'PDF')) {
$aFields['VIEW2'] = G::LoadTranslation( 'ID_GET_EXTERNAL_FILE' );
$aFields['FILE2'] = $folderitem->downloadScript;
continue;
}
}
}
/*----------------------------------********---------------------------------*/
$licensedFeatures = &PMLicensedFeatures::getSingleton();
$enablePMGmail = false;
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
G::LoadClass( "pmDrive" );
$pmDrive = new PMDrive();
if ($pmDrive->getStatusService()) {
//change donwload link - drive
$driveDownload = @unserialize($aFields['APP_DOC_DRIVE_DOWNLOAD']);
if ($driveDownload !== false && is_array($driveDownload) && array_key_exists('OUTPUT_DOC',
$driveDownload)
) {
$aFields['FILE1'] = $driveDownload['OUTPUT_DOC'];
}
if ($driveDownload !== false && is_array($driveDownload) && array_key_exists('OUTPUT_PDF',
$driveDownload)
) {
$aFields['FILE2'] = $driveDownload['OUTPUT_PDF'];
}
}
}
/*----------------------------------********---------------------------------*/
if (($aGields['OUT_DOC_GENERATE'] == 'BOTH') || ($aGields['OUT_DOC_GENERATE'] == '')) {
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'cases/cases_ViewOutputDocument1', '', G::array_merges( $aOD, $aFields ), '' );
}
if ($aGields['OUT_DOC_GENERATE'] == 'DOC') {
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'cases/cases_ViewOutputDocument2', '', G::array_merges( $aOD, $aFields ), '' );
}
if ($aGields['OUT_DOC_GENERATE'] == 'PDF') {
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'cases/cases_ViewOutputDocument3', '', G::array_merges( $aOD, $aFields ), '' );
}
break;
}
break;
case 'ASSIGN_TASK':
$oDerivation = new Derivation();
$oProcess = new Process();
$aData = $oCase->loadCase( $_SESSION['APPLICATION'] );
$aFields['PROCESS'] = $oProcess->load( $_SESSION['PROCESS'] );
$aFields['PREVIOUS_PAGE'] = $aPreviousStep['PAGE'];
$aFields['PREVIOUS_PAGE_LABEL'] = G::LoadTranslation( 'ID_PREVIOUS_STEP' );
$aFields['ASSIGN_TASK'] = G::LoadTranslation( 'ID_ASSIGN_TASK' );
$aFields['END_OF_PROCESS'] = G::LoadTranslation( 'ID_END_OF_PROCESS' );
$aFields['NEXT_TASK_LABEL'] = G::LoadTranslation( 'ID_NEXT_TASK' );
$aFields['EMPLOYEE'] = G::LoadTranslation( 'ID_EMPLOYEE' );
$aFields['LAST_EMPLOYEE'] = G::LoadTranslation( 'ID_LAST_EMPLOYEE' );
$aFields['OPTION_LABEL'] = G::LoadTranslation( 'ID_OPTION' );
$aFields['CONTINUE'] = G::LoadTranslation( 'ID_CONTINUE' );
$aFields['FINISH'] = G::LoadTranslation( 'ID_FINISH' );
$aFields['CONTINUE_WITH_OPTION'] = G::LoadTranslation( 'ID_CONTINUE_WITH_OPTION' );
$aFields['FINISH_WITH_OPTION'] = G::LoadTranslation( 'ID_FINISH_WITH_OPTION' );
$aFields['TAS_TIMING_TITLE'] = G::LoadTranslation( 'ID_TIMING_CONTROL' );
$aFields['TAS_DURATION'] = G::LoadTranslation( 'ID_TASK_DURATION' );
$aFields['TAS_TIMEUNIT'] = G::LoadTranslation( 'ID_TIME_UNIT' );
$aFields['TAS_TYPE_DAY'] = G::LoadTranslation( 'ID_COUNT_DAYS' );
$aFields['TAS_CALENDAR'] = G::LoadTranslation( 'ID_CALENDAR' );
$aFields['TASK'] = $oDerivation->prepareInformation( array ('USER_UID' => $_SESSION['USER_LOGGED'],'APP_UID' => $_SESSION['APPLICATION'],'DEL_INDEX' => $_SESSION['INDEX']
) );
if (empty( $aFields['TASK'] )) {
throw (new Exception( G::LoadTranslation( 'ID_NO_DERIVATION_RULE' ) ));
}
//take the first derivation rule as the task derivation rule type.
$aFields['PROCESS']['ROU_TYPE'] = $aFields['TASK'][1]['ROU_TYPE'];
$aFields['PROCESS']['ROU_FINISH_FLAG'] = false;
foreach ($aFields['TASK'] as $sKey => &$aValues) {
$sPriority = ''; //set priority value
if ($aFields['TASK'][$sKey]['NEXT_TASK']['TAS_PRIORITY_VARIABLE'] != '') {
//TO DO: review this type of assignment
if (isset( $aData['APP_DATA'][str_replace( '@@', '', $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_PRIORITY_VARIABLE'] )] )) {
$sPriority = $aData['APP_DATA'][str_replace( '@@', '', $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_PRIORITY_VARIABLE'] )];
}
} //set priority value
//$sTask = $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_UID'];
//TAS_UID has a hidden field to store the TAS_UID
$hiddenName = "form[TASKS][" . $sKey . "][TAS_UID]";
$hiddenField = '';
$aFields['TASK'][$sKey]['NEXT_TASK']['TAS_HIDDEN_FIELD'] = $hiddenField;
//print "
".$aValues['NEXT_TASK']['TAS_ASSIGN_TYPE']."
";
switch ($aValues['NEXT_TASK']['TAS_ASSIGN_TYPE']) {
case 'EVALUATE':
case 'REPORT_TO':
case 'BALANCED':
case 'SELF_SERVICE':
$hiddenName = "form[TASKS][" . $sKey . "][USR_UID]";
$aFields['TASK'][$sKey]['NEXT_TASK']['USR_UID'] = $aFields['TASK'][$sKey]['NEXT_TASK']['USER_ASSIGNED']['USR_FULLNAME'];
$aFields['TASK'][$sKey]['NEXT_TASK']['USR_HIDDEN_FIELD'] = '';
//var_dump($aFields);
//there is a error with reportsTo, when the USR_UID is empty means there are no manager for this user, so we are disabling buttons
//but this validation is not for SELF_SERVICE
if ($aValues['NEXT_TASK']['TAS_ASSIGN_TYPE'] != 'SELF_SERVICE') {
if ($aFields['TASK'][$sKey]['NEXT_TASK']['USER_ASSIGNED']['USR_UID'] == '') {
$aFields['PROCESS']['ERROR'] = $aFields['TASK'][$sKey]['NEXT_TASK']['USER_ASSIGNED']['USR_FULLNAME'];
}
}
break;
case 'MANUAL':
$Aux = array ();
foreach ($aValues['NEXT_TASK']['USER_ASSIGNED'] as $aUser) {
$Aux[$aUser['USR_UID']] = $aUser['USR_FULLNAME'];
}
asort( $Aux );
$sAux = '';
$aFields['TASK'][$sKey]['NEXT_TASK']['USR_UID'] = $sAux;
break;
case 'CANCEL_MI':
case 'STATIC_MI':
//count the Users in the group
$cntInstanceUsers = count( $aValues['NEXT_TASK']['USER_ASSIGNED'] );
//set TAS_MI_INSTANCE_VARIABLE value
$sMIinstanceVar = '';
if ($aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_INSTANCE_VARIABLE'] != '') {
if (isset( $aData['APP_DATA'][str_replace( '@@', '', $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_INSTANCE_VARIABLE'] )] )) {
$sMIinstanceVar = $aData['APP_DATA'][str_replace( '@@', '', $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_INSTANCE_VARIABLE'] )];
if ($sMIinstanceVar > $cntInstanceUsers) {
throw (new Exception( "Total Multiple Instance Task cannot be greater than number of users in the group." ));
} elseif ($sMIinstanceVar == 0) {
throw (new Exception( "Total Multiple Instance Task cannot be zero." ));
}
} elseif (is_int( (int) $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_INSTANCE_VARIABLE'] )) {
$sMIinstanceVar = $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_INSTANCE_VARIABLE'];
if ($sMIinstanceVar > $cntInstanceUsers) {
throw (new Exception( "Total Multiple Instance Task cannot be greater than number of users in the group." ));
}
} else {
throw (new Exception( "Total Multiple Instance Task variable doesn't have valid value." ));
}
} else {
throw (new Exception( "Total Multiple Instance Task variable doesn't have valid value." ));
////set TAS_MI_INSTANCE_VARIABLE value
}
//set TAS_MI_COMPLETE_VARIABLE value
$sMIcompleteVar = '';
if ($aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_COMPLETE_VARIABLE'] != '') {
if (isset( $aData['APP_DATA'][str_replace( '@@', '', $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_COMPLETE_VARIABLE'] )] )) {
$sMIcompleteVar = $aData['APP_DATA'][str_replace( '@@', '', $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_COMPLETE_VARIABLE'] )];
//
if ($sMIcompleteVar > $sMIinstanceVar) {
throw (new Exception( "Total Multiple Instance Task to complete cannot be greater than Total number of Instances." ));
}
} elseif (is_int( (int) $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_COMPLETE_VARIABLE'] )) {
$sMIcompleteVar = $aFields['TASK'][$sKey]['NEXT_TASK']['TAS_MI_COMPLETE_VARIABLE'];
if ($sMIcompleteVar > $sMIinstanceVar) {
throw (new Exception( "Total Multiple Instance Task to complete cannot be greater than Total number of Instances." ));
}
} else {
throw (new Exception( "Total Multiple Instance Task to complete variable doesn't have valid value." ));
}
} else {
throw (new Exception( "Total Multiple Instance Task to complete variable doesn't have valid value." ));
}
//set TAS_MI_COMPLETE_VARIABLE value
$aFields['TASK'][$sKey]['NEXT_TASK']['TAS_NEXT'] = $aValues['NEXT_TASK']['TAS_ASSIGN_TYPE'];
//If the Users in the group is equal to the MI Instance variable then Show all the users without Dropdown
if ($sMIinstanceVar == $cntInstanceUsers) {
foreach ($aValues['NEXT_TASK']['USER_ASSIGNED'] as $key => $aUser) {
$hiddenName = "form[TASKS][" . $sKey . "][NEXT_TASK][USER_ASSIGNED][" . $key . "][USR_UID]";
$aFields['TASK'][$sKey]['NEXT_TASK']['USER_ASSIGNED'][$key]['USR_UID'] = $aUser['USR_FULLNAME'];
$aFields['TASK'][$sKey]['NEXT_TASK']['USER_ASSIGNED'][$key]['USR_HIDDEN_FIELD'] = '';
}
} //If the Users in the group is not equal to the MI Instance variable then Show Only count users in dropdown
else {
$Aux = array ();
foreach ($aValues['NEXT_TASK']['USER_ASSIGNED'] as $aUser) {
$Aux[$aUser['USR_UID']] = $aUser['USR_FULLNAME'];
}
asort( $Aux );
$aAux = '';
foreach ($Aux as $akey => $value) {
$aAux .= '';
}
for ($key = 0; $key < $sMIinstanceVar; $key ++) {
$hiddenName = "form[TASKS][" . $sKey . "][NEXT_TASK][USER_ASSIGNED][" . $key . "][USR_UID]";
$sAux = "