From 8a3936c46b5d342d73ab4cf520bc16359693c0eb Mon Sep 17 00:00:00 2001 From: Hector Cortez Date: Wed, 2 May 2012 18:16:55 -0400 Subject: [PATCH] BUG 9098 Migrate Import Process to ExtJS SOLVED - Migrate Import Process in Desiggner to ExtJS (from master branch). - Import Process ExtJS migrated from the master branch. --- workflow/engine/classes/class.processes.php | 4 +- .../processes/processes_Import_Ajax.php | 298 +++++++++++++ workflow/engine/templates/processes/main.js | 419 +++++++++++++++++- 3 files changed, 715 insertions(+), 6 deletions(-) create mode 100644 workflow/engine/methods/processes/processes_Import_Ajax.php diff --git a/workflow/engine/classes/class.processes.php b/workflow/engine/classes/class.processes.php index 1e6f7476a..5f3290ecb 100755 --- a/workflow/engine/classes/class.processes.php +++ b/workflow/engine/classes/class.processes.php @@ -722,7 +722,7 @@ class Processes { // New process bpmn if ( isset($oData->event ) && is_array($oData->event) ) { foreach ( $oData->event as $key => $val ) { - if (isset($map[ $val['EVN_TAS_UID_FROM'] ])) { + if (isset($val['EVN_TAS_UID_FROM']) && isset($map[ $val['EVN_TAS_UID_FROM'] ])) { $newGuid = $map[ $val['EVN_TAS_UID_FROM'] ]; $oData->event[$key]['EVN_TAS_UID_FROM'] = $newGuid; } @@ -753,7 +753,7 @@ class Processes { $oData->dynaforms[$key]['DYN_UID'] = $newGuid; } - if (!is_array($oData->process['PRO_DYNAFORMS'])) { + if ( isset($oData->process['PRO_DYNAFORMS']) && !is_array($oData->process['PRO_DYNAFORMS'])) { $oData->process['PRO_DYNAFORMS'] = @unserialize($oData->process['PRO_DYNAFORMS']); } diff --git a/workflow/engine/methods/processes/processes_Import_Ajax.php b/workflow/engine/methods/processes/processes_Import_Ajax.php new file mode 100644 index 000000000..f98279185 --- /dev/null +++ b/workflow/engine/methods/processes/processes_Import_Ajax.php @@ -0,0 +1,298 @@ +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + ini_set('max_execution_time', '0'); + + $action = isset($_REQUEST['ajaxAction']) ? $_REQUEST['ajaxAction'] : null; + + $result = new stdClass(); + $result->success = true; + $result->catchMessage = ""; + + if ( $action == "uploadFileNewProcess") { + try { + //type of file, bpmn, xpdl, or pm + $processFileType = $_REQUEST["processFileType"]; + $oProcess = new stdClass(); + $oData = new stdClass(); + + $isCorrectTypeFile = 1; + + if ( isset($_FILES['form']['type']['PROCESS_FILENAME']) ) { + $allowedExtensions = array($processFileType); + $allowedExtensions = array( 'xpdl', 'bpmn', 'pm'); + if (!in_array(end(explode(".", $_FILES['form']['name']['PROCESS_FILENAME'])), $allowedExtensions)) { + throw new Exception(G::LoadTranslation("ID_FILE_UPLOAD_INCORRECT_EXTENSION")); + } + } + if ($processFileType != "pm" && $processFileType != "xpdl" && $processFileType != "bpmn" ) { + throw new Exception(G::LoadTranslation("ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR")); + } + + if ($processFileType == "pm") { + G::LoadClass('processes'); + $oProcess = new Processes(); + } + + if ($processFileType == "xpdl") { + G::LoadClass('xpdl'); + $oProcess = new Xpdl(); + } + + $result->success = true; + $result->ExistProcessInDatabase = ""; //"" -Default + //0 -Dont exist process + //1 -exist process + $result->ExistGroupsInDatabase = ""; //"" -Default + //0 -Dont exist process + //1 -exist process + $optionGroupExistInDatabase = isset($_REQUEST["optionGroupExistInDatabase"]) ? $_REQUEST["optionGroupExistInDatabase"] : null; + + //!Upload file + if ( ! is_null($optionGroupExistInDatabase)) { + $filename = $_REQUEST["PRO_FILENAME"]; + $path = PATH_DOCUMENT . 'input' . PATH_SEP ; + } + else { + if ($_FILES['form']['error']['PROCESS_FILENAME'] == 0){ + $filename = $_FILES['form']['name']['PROCESS_FILENAME']; + $path = PATH_DOCUMENT . 'input' . PATH_SEP ; + $tempName = $_FILES['form']['tmp_name']['PROCESS_FILENAME']; + //$action = "none"; + G::uploadFile($tempName, $path, $filename ); + } + } + + //importing a bpmn diagram, using external class to do it. + if ($processFileType == "bpmn") { + G::LoadClass('bpmnExport'); + $bpmn = new bpmnExport(); + $bpmn->importBpmn( $path . $filename); + die; + } + + //if file is a .pm or .xpdl file continues normally the importing + if ($processFileType == "pm") { + $oData = $oProcess->getProcessData ( $path . $filename ); + } + else { + $oData = $oProcess->getProcessDataXpdl ( $path . $filename ); + } + + //!Upload file + $Fields['PRO_FILENAME'] = $filename; + $Fields['IMPORT_OPTION'] = 2; + + $sProUid = $oData->process['PRO_UID']; + + $oData->process['PRO_UID_OLD'] = $sProUid; + + if ( $oProcess->processExists ( $sProUid ) ) { + $result->ExistProcessInDatabase = 1; + } + else { + $result->ExistProcessInDatabase = 0; + } + + //!respect of the groups + $result->ExistGroupsInDatabase = 1; + $result->groupBeforeAccion = $action; + if (!is_null($optionGroupExistInDatabase)) { + if ($optionGroupExistInDatabase == 1) { + $oData->groupwfs = $oProcess->renameExistingGroups($oData->groupwfs); + } + else if ($optionGroupExistInDatabase == 2) { + $oBaseGroup = $oData->groupwfs; + $oNewGroup = $oProcess->mergeExistingGroups($oData->groupwfs); + $oData->groupwfs = $oNewGroup; + $oData->taskusers = $oProcess->mergeExistingUsers($oBaseGroup, $oNewGroup, $oData->taskusers); + } + $result->ExistGroupsInDatabase = 0; + } + else { + if ( !($oProcess->checkExistingGroups($oData->groupwfs) > 0) ) { + $result->ExistGroupsInDatabase = 0; + } + } + //!respect of the groups + + if ($result->ExistProcessInDatabase == 0 && $result->ExistGroupsInDatabase == 0){ + if ($processFileType == "pm") { + $oProcess->createProcessFromData ($oData, $path . $filename ); + } + else { + if ( !isset( $oData->tasks) ) $oData->tasks = array(); + $tasks = $oData->tasks; + $oProcess->createProcessFromDataXpdl ($oData,$tasks); + } + } + + //!data ouput + $result->sNewProUid = $sProUid; + $result->proFileName = $Fields['PRO_FILENAME']; + } + catch (Exception $e ) { + $result->response = $e->getMessage(); + $result->catchMessage = $e->getMessage(); + $result->success = true; + } + } + + if ($action == "uploadFileNewProcessExist") { + try { + $option = $_REQUEST["IMPORT_OPTION"]; + $filename = $_REQUEST["PRO_FILENAME"]; + $processFileType = $_REQUEST["processFileType"]; + + $result->ExistGroupsInDatabase = ""; //"" -Default + //0 -Dont exist process + //1 -exist process + + $optionGroupExistInDatabase = isset($_REQUEST["optionGroupExistInDatabase"]) ? $_REQUEST["optionGroupExistInDatabase"] : null; + $sNewProUid = ""; + + $oProcess = new stdClass(); + if ($processFileType != "pm" && $processFileType != "xpdl") { + throw new Exception(G::LoadTranslation("ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR")); + } + + //load the variables + if ($processFileType == "pm") { + G::LoadClass('processes'); + $oProcess = new Processes(); + } + else { + G::LoadClass('xpdl'); + $oProcess = new Xpdl(); + } + + $path = PATH_DOCUMENT . 'input' . PATH_SEP ; + + if ($processFileType == "pm"){ + $oData = $oProcess->getProcessData ( $path . $filename ); + } + else { + $oData = $oProcess->getProcessDataXpdl ( $path . $filename ); + } + + $Fields['PRO_FILENAME'] = $filename; + $sProUid = $oData->process['PRO_UID']; + + $oData->process['PRO_UID_OLD'] = $sProUid; + + $result->ExistGroupsInDatabase = 1; + if ( !is_null($optionGroupExistInDatabase)) { + if ($optionGroupExistInDatabase == 1){ + $oData->groupwfs = $oProcess->renameExistingGroups($oData->groupwfs); + } + else if ($optionGroupExistInDatabase == 2) { + $oBaseGroup = $oData->groupwfs; + $oNewGroup = $oProcess->mergeExistingGroups($oData->groupwfs); + $oData->groupwfs = $oNewGroup; + $oData->taskusers = $oProcess->mergeExistingUsers($oBaseGroup, $oNewGroup, $oData->taskusers); + } + $result->ExistGroupsInDatabase = 0; + } + else { + if ( !($oProcess->checkExistingGroups($oData->groupwfs) > 0) ) { + $result->ExistGroupsInDatabase = 0; + } + } + + if ($result->ExistGroupsInDatabase == 0) { + //Update the current Process, overwriting all tasks and steps + if ( $option == 1 ) { + $oProcess->updateProcessFromData ($oData, $path . $filename ); + if (file_exists(PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid)) { + $oDirectory = dir(PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid); + while ($sObjectName = $oDirectory->read()) { + if (($sObjectName != '.') && ($sObjectName != '..')) { + unlink(PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid . PATH_SEP . $sObjectName); + } + } + $oDirectory->close(); + } + $sNewProUid = $sProUid; + } + + //Disable current Process and create a new version of the Process + if ( $option == 2 ) { + $oProcess->disablePreviousProcesses( $sProUid ); + $sNewProUid = $oProcess->getUnusedProcessGUID() ; + $oProcess->setProcessGuid ( $oData, $sNewProUid ); + $oProcess->setProcessParent( $oData, $sProUid ); + $oData->process['PRO_TITLE'] = "New - " . $oData->process['PRO_TITLE'] . ' - ' . date ( 'M d, H:i' ); + $oProcess->renewAll ( $oData ); + + if ($processFileType == "pm") { + $oProcess->createProcessFromData ($oData, $path . $filename ); + } + else { + if ( !isset( $oData->tasks) ) { + $oData->tasks = array(); + } + $tasks = $oData->tasks; + $oProcess->createProcessFromDataXpdl ($oData,$tasks); + } + } + + //Create a completely new Process without change the current Process + if ( $option == 3 ) { + //krumo ($oData); die; + $sNewProUid = $oProcess->getUnusedProcessGUID() ; + $oProcess->setProcessGuid ( $oData, $sNewProUid ); + $oData->process['PRO_TITLE'] = "Copy of - " . $oData->process['PRO_TITLE'] . ' - ' . date ( 'M d, H:i' ); + $oProcess->renewAll ( $oData ); + + if ($processFileType == "pm"){ + $oProcess->createProcessFromData ($oData, $path . $filename ); + } + else { + if ( !isset( $oData->tasks) ) { + $oData->tasks = array(); + } + $tasks = $oData->tasks; + $oProcess->createProcessFromDataXpdl ($oData,$tasks); + } + } + } + + //!data ouput + $result->fileName = $filename; + $result->importOption = $option; + $result->sNewProUid = $sNewProUid; + $result->success = true; + $result->ExistGroupsInDatabase = $result->ExistGroupsInDatabase; + $result->groupBeforeAccion = $action; + //!data ouput + } + catch (Exception $e ) { + $result->response = $e->getMessage(); + $result->success = true; + } + } + + echo G::json_encode($result); + exit(); + diff --git a/workflow/engine/templates/processes/main.js b/workflow/engine/templates/processes/main.js index 953e7ebbe..23795a3c7 100755 --- a/workflow/engine/templates/processes/main.js +++ b/workflow/engine/templates/processes/main.js @@ -6,6 +6,16 @@ var processesGrid; var store; var comboCategory; +/** + * Global variables and variable initialization for import process. + */ +var importProcessGlobal = {}; +importProcessGlobal.proFileName = ""; +importProcessGlobal.groupBeforeAccion=""; +importProcessGlobal.sNewProUid = ""; +importProcessGlobal.importOption = ""; +importProcessGlobal.processFileType = ""; + new Ext.KeyMap(document, { key: Ext.EventObject.F5, fn: function(keycode, e) { @@ -231,12 +241,20 @@ Ext.onReady(function(){ text: _('ID_IMPORT'), iconCls: 'silk-add', icon: '/images/import.gif', - handler:importProcess + // handler:importProcess + handler : function(){ + importProcessGlobal.processFileType = "pm"; + importProcess(); + } },{ text: _('ID_XPDL_IMPORT'), iconCls: 'silk-add', icon: '/images/import.gif', - handler:importXPDLProcess + // handler:importXPDLProcess + handler:function(){ + importProcessGlobal.processFileType="xpdl"; + importProcess(); + } },/*{ text:'Export', iconCls: 'silk-add', @@ -615,8 +633,401 @@ deleteProcess = function(){ } } -importProcess = function(){ - window.location = 'processes_Import'; +importProcessExistGroup = function() +{ + + var processFileTypeTitle = (processFileType == "pm") ? "" : " " + processFileType; + + proFileName = importProcessGlobal.proFileName; + groupBeforeAccion = importProcessGlobal.groupBeforeAccion; + sNewProUid = importProcessGlobal.sNewProUid; + importOption = importProcessGlobal.importOption; + var processFileType = importProcessGlobal.processFileType; + + var w = new Ext.Window({ + title : _('ID_IMPORT_PROCESS') + processFileTypeTitle, + header : false, + width : 460, + height : 210, + modal : true, + autoScroll : false, + maximizable : false, + resizable : false, + items : [ + new Ext.form.FormPanel({ + title : _('ID_LAN_UPLOAD_TITLE'), + header : false, + id : 'formUploadExistGroup', + fileUpload : false, + width : 440, + frame : true, + autoHeight : false, + bodyStyle : 'padding: 10px 10px 0 10px;', + labelWidth : 50, + defaults : { + anchor : '90%', + allowBlank : false, + msgTarget : 'side' + }, + items : [ + { + xtype : 'box', + autoEl : { + tag : 'div', + html : '
' + _('ID_PROCESS_EXIST_SOME_GROUP') + '
 
' + } + }, { + xtype : 'spacer', + height : 10 + }, { + items: [ + { + xtype : "radio", + boxLabel : _('ID_PROCESS_GROUP_RENAME'), + name : "optionGroupExistInDatabase", + inputValue : '1', + tabIndex : 1 + } + ] + }, { + items:[ + { + xtype : "radio", + boxLabel : _('ID_PROCESS_GROUP_MERGE_PREEXISTENT'), + tabIndex : 2, + name : "optionGroupExistInDatabase", + inputValue : '2', + checked : "checked" + } + ] + }, { + xtype : 'hidden', + name : 'ajaxAction', + value : groupBeforeAccion + }, { + xtype : 'hidden', + name : 'PRO_FILENAME', + value : proFileName + }, { + xtype : 'hidden', + name : 'sNewProUid', + value : sNewProUid + }, { + xtype : 'hidden', + name : 'IMPORT_OPTION', + value : importOption + }, { + name : 'processFileType', + xtype : 'hidden', + value : processFileType + }, { + xtype : 'spacer', + height : 10 + } + ], + buttons : [ + { + text : _('ID_SAVE'), + handler : function() { + var uploader = Ext.getCmp('formUploadExistGroup'); + + if (uploader.getForm().isValid()) { + uploader.getForm().submit({ + url : 'processes_Import_Ajax', + waitMsg : _('ID_UPLOADING_PROCESS_FILE'), + + success : function(o, resp) { + var resp_ = Ext.util.JSON.decode(resp.response.responseText); + var sNewProUid = resp_.sNewProUid; + window.location.href = "processes_Map?PRO_UID=" + sNewProUid; + }, + failure: function(o, resp) { + w.close(); + Ext.MessageBox.show({ + title : _('ID_ERROR'), + msg : resp.result.msg, + buttons : Ext.MessageBox.OK, + animEl : 'mb9', + fn : function(){}, + icon : Ext.MessageBox.ERROR + }); + } + }); + } + } + }, { + text : _('ID_CANCEL'), + handler : function(){ + w.close(); + } + } + ] + }) + ] + }); + w.show(); +}; + +importProcessExistProcess = function() +{ + + var processFileTypeTitle = (processFileType == "pm") ? "" : " " + processFileType; + var processFileType = importProcessGlobal.processFileType; + var proFileName = importProcessGlobal.proFileName; + + var w = new Ext.Window({ + title : _('ID_IMPORT_PROCESS') + processFileTypeTitle, + header : false, + width : 460, + height : 210, + modal : true, + autoScroll : false, + maximizable : false, + resizable : false, + items : [ + new Ext.form.FormPanel({ + title : _('ID_LAN_UPLOAD_TITLE'), + header : false, + id : 'formUploader', + fileUpload : false, + width : 440, + frame : true, + autoHeight : false, + bodyStyle : 'padding: 10px 10px 0 10px;', + labelWidth : 50, + defaults : { + anchor : '90%', + allowBlank : false, + msgTarget : 'side' + }, + items : [ + { + xtype : 'box', + autoEl : { + tag : 'div', + html : '
' + _('ID_IMPORT_ALREADY_EXISTS') + '
 
' + } + }, { + xtype : 'spacer', + height : 10 + }, { + items : [ + { + xtype : "radio", + boxLabel : _('IMPORT_PROCESS_OVERWRITING'), + name : "IMPORT_OPTION", + inputValue : '1', + tabIndex : 1 + } + ] + }, { + items : [{ + xtype : "radio", + boxLabel : _('IMPORT_PROCESS_DISABLE'), + tabIndex : 2, + name : "IMPORT_OPTION", + inputValue : '2', + checked : "checked" + }] + }, { + items: [{ + xtype : "radio", + boxLabel : _('IMPORT_PROCESS_NEW'), + name : "IMPORT_OPTION", + inputValue : '3', + tabIndex : 3 + }] + }, { + xtype : 'hidden', + name : 'ajaxAction', + value : 'uploadFileNewProcessExist' + }, { + xtype : 'hidden', + name : 'PRO_FILENAME', + value : proFileName + }, { + name : 'processFileType', + xtype : 'hidden', + value : processFileType + }, { + xtype : 'spacer', + height : 10 + } + ], + buttons:[ + { + text : _('ID_SAVE'), + handler : function() { + var uploader = Ext.getCmp('formUploader'); + if (uploader.getForm().isValid()) { + uploader.getForm().submit({ + url : 'processes_Import_Ajax', + waitMsg : _('ID_UPLOADING_PROCESS_FILE'), + + success: function(o, resp) { + var resp_ = Ext.util.JSON.decode(resp.response.responseText); + var sNewProUid = resp_.sNewProUid; + if (resp_.ExistGroupsInDatabase == 0) { + window.location.href = "processes_Map?PRO_UID=" + sNewProUid; + } + else { + importProcessGlobal.proFileName = resp_.fileName; + importProcessGlobal.groupBeforeAccion = resp_.groupBeforeAccion; + importProcessGlobal.sNewProUid = resp_.sNewProUid; + importProcessGlobal.importOption = resp_.importOption; + importProcessExistGroup(); + } + }, + failure : function(o, resp) { + w.close(); + Ext.MessageBox.show({ + title : _('ID_ERROR'), + msg : resp.result.msg, + buttons : Ext.MessageBox.OK, + animEl : 'mb9', + fn : function(){}, + icon : Ext.MessageBox.ERROR + }); + } + }); + } + } + }, { + text : _('ID_CANCEL'), + handler : function(){ + w.close(); + } + } + ] + }) + ] + }); + w.show(); +}; + +//importProcess = function(){ +// window.location = 'processes_Import'; +//} + +importProcess = function() +{ + var processFileType = importProcessGlobal.processFileType; + var processFileTypeTitle = (processFileType == "pm") ? "" : " " + processFileType; + + var w = new Ext.Window({ + title : _('ID_IMPORT_PROCESS')+processFileTypeTitle, + width : 420, + height : 130, + modal : true, + autoScroll : false, + maximizable : false, + resizable : false, + items: [ + new Ext.FormPanel({ + id : 'uploader', + fileUpload : true, + width : 400, + height : 90, + frame : true, + title : _('ID_IMPORT_PROCESS'), + header : false, + autoHeight : false, + bodyStyle : 'padding: 10px 10px 0 10px;', + labelWidth : 50, + defaults : { + anchor : '90%', + allowBlank : false, + msgTarget : 'side' + }, + items : [ + { + name : 'ajaxAction', + xtype : 'hidden', + value : 'uploadFileNewProcess' + }, { + name : 'processFileType', + xtype : 'hidden', + value : processFileType + }, { + xtype : 'fileuploadfield', + id : 'form-file', + emptyText : _('ID_SELECT_PROCESS_FILE'), + fieldLabel : _('ID_LAN_FILE'), + name : 'form[PROCESS_FILENAME]', + buttonText : '', + buttonCfg : { + iconCls : 'upload-icon' + } + } + ], + buttons : [{ + text : _('ID_UPLOAD'), + handler : function(){ + var uploader = Ext.getCmp('uploader'); + if (uploader.getForm().isValid()) { + uploader.getForm().submit({ + url : 'processes_Import_Ajax', + waitMsg : _('ID_UPLOADING_PROCESS_FILE'), + success : function(o, resp) { + + var resp_ = Ext.util.JSON.decode(resp.response.responseText); + + if (resp_.catchMessage == "") { + if (resp_.ExistProcessInDatabase == "0") { + if (resp_.ExistGroupsInDatabase == "0") { + var sNewProUid = resp_.sNewProUid; + window.location.href = "processes_Map?PRO_UID=" + sNewProUid; + } + else { + importProcessGlobal.sNewProUid = resp_.sNewProUid; + importProcessGlobal.proFileName = resp_.proFileName; + importProcessGlobal.groupBeforeAccion = resp_.groupBeforeAccion; + importProcessExistGroup(); + } + } + else if (resp_.ExistProcessInDatabase == "1") { + + importProcessGlobal.proFileName = resp_.proFileName; + importProcessExistProcess(); + } + } + else { + w.close(); + Ext.MessageBox.show({ + title : '', + msg : resp_.catchMessage, + buttons : Ext.MessageBox.OK, + animEl : 'mb9', + fn : function(){}, + icon : Ext.MessageBox.ERROR + }); + } + }, + failure : function(o, resp) { + w.close(); + + Ext.MessageBox.show({ + title : '', + msg : resp_.catchMessage, + buttons : Ext.MessageBox.OK, + animEl : 'mb9', + fn : function(){}, + icon : Ext.MessageBox.ERROR + }); + } + }); + } + } + },{ + text: _('ID_CANCEL'), + handler: function(){ + w.close(); + } + }] + }) + ] + }); + w.show(); } importXPDLProcess = function(){