HOR-180

HOR-180
This commit is contained in:
Paula V. Quispe
2016-03-01 19:12:13 -04:00
parent 5767eb6c8b
commit 640f1b718d
4 changed files with 529 additions and 417 deletions

View File

@@ -229,7 +229,7 @@ class G
* @param string $key
* @return string
*/
public function encrypt ($string, $key)
public static function encrypt ($string, $key)
{
//print $string;
// if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) {
@@ -3368,7 +3368,7 @@ class G
*
* @author Erik A.O. <erik@colosa.com>
*/
public function json_decode($Json, $assoc = false)
public static function json_decode($Json, $assoc = false)
{
if (function_exists('json_decode')) {
return json_decode($Json, $assoc);
@@ -5034,7 +5034,7 @@ class G
$rest->handle();
}
public function reservedWordsSql ()
public static function reservedWordsSql ()
{
//Reserved words SQL
$reservedWordsSql = array ("ACCESSIBLE","ACTION","ADD","ALL","ALTER","ANALYZE","AND","ANY","AS","ASC","ASENSITIVE","AUTHORIZATION","BACKUP","BEFORE","BEGIN","BETWEEN","BIGINT","BINARY","BIT","BLOB","BOTH","BREAK","BROWSE","BULK","BY","CALL","CASCADE","CASE","CHANGE","CHAR","CHARACTER","CHECK","CHECKPOINT","CLOSE","CLUSTERED","COALESCE","COLLATE","COLUMN","COMMIT","COMPUTE","CONDITION","CONSTRAINT","CONTAINS","CONTAINSTABLE","CONTINUE","CONVERT","CREATE","CROSS","CURRENT","CURRENT_DATE","CURRENT_TIME","CURRENT_TIMESTAMP","CURRENT_USER","CURSOR","DATABASE","DATABASES","DATE","DAY_HOUR","DAY_MICROSECOND","DAY_MINUTE","DAY_SECOND","DBCC","DEALLOCATE","DEC","DECIMAL","DECLARE","DEFAULT","DELAYED","DELETE","DENY","DESC","DESCRIBE","DETERMINISTIC","DISK","DISTINCT","DISTINCTROW",

View File

@@ -311,7 +311,7 @@ class AdditionalTables extends BaseAdditionalTables
$pmTable->remove();
}
public function getPHPName($sName)
public static function getPHPName($sName)
{
$sName = trim($sName);
$aAux = explode('_', $sName);

View File

@@ -937,6 +937,11 @@ class pmTablesProxy extends HttpProxyController
*/
public function import ($httpData)
{
define('ERROR_PM_TABLES_OVERWRITE', '1');
define('ERROR_PROCESS_NOT_EXIST', '2');
define('ERROR_RP_TABLES_OVERWRITE', '3');
define('ERROR_NO_REPORT_TABLE', '4');
define('ERROR_OVERWRITE_RELATED_PROCESS', '5');
$fromAdmin = false;
if (isset( $_POST["form"]["TYPE_TABLE"] ) && ! empty( $_POST["form"]["TYPE_TABLE"] )) {
if($_POST["form"]["TYPE_TABLE"] == 'admin') {
@@ -986,21 +991,223 @@ class pmTablesProxy extends HttpProxyController
throw new Exception( G::loadTranslation( 'ID_PMTABLE_INVALID_FILE' ) );
}
$fp = fopen( $PUBLIC_ROOT_PATH . $filename, "rb" );
$fsData = intval( fread( $fp, 9 ) ); //reading the metadata
$sType = fread( $fp, $fsData );
$currentProUid = '';
if (isset( $_POST["form"]["PRO_UID_HELP"] ) && !empty($_POST["form"]["PRO_UID_HELP"])) {
$currentProUid = $_POST["form"]["PRO_UID_HELP"];
} else {
if(isset( $_POST["form"]["PRO_UID"]) && !empty( $_POST["form"]["PRO_UID"])){
$currentProUid = $_POST["form"]["PRO_UID"];
$_SESSION['PROCESS'] = $currentProUid;
} else{
$currentProUid = $_SESSION['PROCESS'];
}
}
//First Validate the file
$pathPmtableFile = $PUBLIC_ROOT_PATH . $filename;
$arrayOverwrite = array();
$arrayRelated = array();
$arrayMessage = array();
$validationType = 0;
if(!$fromConfirm){
$aErrors = $this->checkPmtFileThrowErrors($pathPmtableFile,$filename,$fromAdmin,$overWrite,$currentProUid);
$countC = 0;
$countM = 0;
$countI = 0;
foreach($aErrors as $row){
if($row['ERROR_TYPE'] == ERROR_PM_TABLES_OVERWRITE || $row['ERROR_TYPE'] == ERROR_RP_TABLES_OVERWRITE){
$arrayOverwrite[$countC] = $row;
$countC++;
} else {
if($row['ERROR_TYPE'] == ERROR_OVERWRITE_RELATED_PROCESS){
$arrayRelated[$countI] = $row;
$countI++;
} else {
$arrayMessage[$countM] = $row;
$countM++;
}
}
}
if(sizeof($aErrors)){
$validationType = 1; //Yes no
throw new Exception(G::loadTranslation( 'ID_PMTABLE_IMPORT_WITH_ERRORS', array ($filename)));
}
}
//Then create the tables
if(isset($_POST["form"]["TABLES_OF_NO"])){
$arrayOfNo = $_POST["form"]["TABLES_OF_NO"];
$arrayOfNew = $_POST["form"]["TABLES_OF_NEW"];
$aTablesCreateNew = explode('|',$arrayOfNew);
$aTablesNoCreate = explode('|',$arrayOfNo);
$errors = $this->createStructureOfTables($pathPmtableFile, $fromAdmin, $currentProUid, true, $aTablesNoCreate, $aTablesCreateNew);
} else {
$errors = $this->createStructureOfTables($pathPmtableFile, $fromAdmin, $currentProUid, true);
}
if ($errors == '') {
$result->success = true;
$msg = G::loadTranslation( 'ID_DONE' );
} else {
$result->success = false;
$result->errorType = 'warning';
$msg = G::loadTranslation( 'ID_PMTABLE_IMPORT_WITH_ERRORS', array ($filename) ) . "\n\n" . $errors;
}
$result->message = $msg;
} catch (Exception $e) {
$result = new stdClass();
$result->fromAdmin = $fromAdmin;
$result->arrayMessage = $arrayMessage;
$result->arrayRelated = $arrayRelated;
$result->arrayOverwrite = $arrayOverwrite;
$result->validationType = $validationType;
$result->errorType = 'error';
$result->buildResult = ob_get_contents();
ob_end_clean();
$result->success = false;
// if it is a propel exception message
if (preg_match( '/(.*)\s\[(.*):\s(.*)\]\s\[(.*):\s(.*)\]/', $e->getMessage(), $match )) {
$result->message = $match[3];
$result->type = G::loadTranslation( 'ID_ERROR' );
} else {
$result->message = $e->getMessage();
$result->type = G::loadTranslation( 'ID_EXCEPTION' );
}
}
return $result;
}
/**
* Review the *.pmt file and Throw all errors
* @param string $tableFile
* @param string $fileName
* @param bool $fromAdmin
* @param bool $overWrite
* @param string $currentProUid
* @return string $aErrors
*/
public static function checkPmtFileThrowErrors($tableFile,$fileName,$fromAdmin,$overWrite,$currentProUid){
$aErrors = array();
//Ask for all Process
$processMap = new processMap();
$aProcess = json_decode ($processMap->getAllProcesses());
$aProcess = G::json_decode($processMap->getAllProcesses());
foreach($aProcess as $key => $val){
if ($val->value != ''){
$proUids[] = $val->value;
}
}
// first create the tables structures
$fp = fopen( $tableFile, "rb" );
$fsData = intval( fread( $fp, 9 ) ); //reading the metadata
$sType = fread( $fp, $fsData );
$count = 0;
while (! feof( $fp )) {
$validationType = 0;
switch ($sType) {
case '@META':
$fsData = intval( fread( $fp, 9 ) );
$METADATA = fread( $fp, $fsData );
break;
case '@SCHEMA':
$fsUid = intval( fread( $fp, 9 ) );
$uid = fread( $fp, $fsUid );
$fsData = intval( fread( $fp, 9 ) );
$schema = fread( $fp, $fsData );
$contentSchema = unserialize( $schema );
//The table exists?
$additionalTable = new additionalTables();
$tableExists = $additionalTable->loadByName( $contentSchema['ADD_TAB_NAME'] );
$tableProUid = isset($contentSchema["PRO_UID"])?$contentSchema["PRO_UID"]:$_POST["form"]["PRO_UID"];
$isPmTable = empty($contentSchema["PRO_UID"])? true : false;
if($fromAdmin) {
if($isPmTable){
if ($tableExists !== false && !$overWrite) {
$aErrors[$count]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$aErrors[$count]['ERROR_TYPE'] = ERROR_PM_TABLES_OVERWRITE;
$aErrors[$count]['ERROR_MESS'] = G::loadTranslation('ID_OVERWRITE_PMTABLE', array($contentSchema['ADD_TAB_NAME']));
$aErrors[$count]['IS_PMTABLE'] = $isPmTable;
$aErrors[$count]['PRO_UID'] = $tableProUid;
}
} else {
if(!in_array($tableProUid, $proUids)){
$aErrors[$count]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$aErrors[$count]['ERROR_TYPE'] = ERROR_PROCESS_NOT_EXIST;
$aErrors[$count]['ERROR_MESS'] = G::loadTranslation('ID_PROCESS_NOT_EXIST', array($contentSchema['ADD_TAB_NAME']));
$aErrors[$count]['IS_PMTABLE'] = $isPmTable;
$aErrors[$count]['PRO_UID'] = $tableProUid;
} else {
$aErrors[$count]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$aErrors[$count]['ERROR_TYPE'] = ERROR_RP_TABLES_OVERWRITE;
$aErrors[$count]['ERROR_MESS'] = G::loadTranslation('ID_OVERWRITE_RPTABLE', array($contentSchema['ADD_TAB_NAME']));
$aErrors[$count]['IS_PMTABLE'] = $isPmTable;
$aErrors[$count]['PRO_UID'] = $tableProUid;
}
}
} else {
if($isPmTable){
$aErrors[$count]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$aErrors[$count]['ERROR_TYPE'] = ERROR_NO_REPORT_TABLE;
$aErrors[$count]['ERROR_MESS'] = G::loadTranslation('ID_NO_REPORT_TABLE', array($contentSchema['ADD_TAB_NAME']));
$aErrors[$count]['IS_PMTABLE'] = $isPmTable;
$aErrors[$count]['PRO_UID'] = $tableProUid;
} else {
if(!$currentProUid != $tableProUid){
$aErrors[$count]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$aErrors[$count]['ERROR_TYPE'] = ERROR_OVERWRITE_RELATED_PROCESS;
$aErrors[$count]['ERROR_MESS'] = G::loadTranslation('ID_OVERWRITE_RELATED_PROCESS', array($contentSchema['ADD_TAB_NAME']));
$aErrors[$count]['IS_PMTABLE'] = $isPmTable;
$aErrors[$count]['PRO_UID'] = $tableProUid;
} else {
if ($tableExists !== false && !$overWrite) {
$aErrors[$count]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$aErrors[$count]['ERROR_TYPE'] = ERROR_RP_TABLES_OVERWRITE;
$aErrors[$count]['ERROR_MESS'] = G::loadTranslation('ID_OVERWRITE_RPTABLE', array($contentSchema['ADD_TAB_NAME']));
$aErrors[$count]['IS_PMTABLE'] = $isPmTable;
$aErrors[$count]['PRO_UID'] = $tableProUid;
}
}
}
}
break;
case '@DATA':
break;
}
$fsData = intval( fread( $fp, 9 ) );
if ($fsData > 0) {
$sType = fread( $fp, $fsData );
} else {
break;
}
$count++;
}
fclose( $fp );
return $aErrors;
}
/**
* Create the structure of tables
* @param string $tableFile,
* @param bool $fromAdmin
* @param string $currentProUid
* @param bool $overWrite
* @param array $aTables
* @return string $errors
*/
public function createStructureOfTables($tableFile,$fromAdmin,$currentProUid,$overWrite = true, $aTables=array(), $aTablesNew=array()){
$fp = fopen( $tableFile, "rb" );
$fsData = intval( fread( $fp, 9 ) );
$sType = fread( $fp, $fsData );
$errors = '';
$tableNameMap = array();
$processQueue = array();
$processQueueTables = array();
while (! feof( $fp )) {
$validationType = 0;
switch ($sType) {
case '@META':
$fsData = intval( fread( $fp, 9 ) );
@@ -1013,6 +1220,7 @@ class pmTablesProxy extends HttpProxyController
$schema = fread( $fp, $fsData );
$contentSchema = unserialize( $schema );
$additionalTable = new additionalTables();
if(!in_array($contentSchema['ADD_TAB_NAME'],$aTables)){
$tableExists = $additionalTable->loadByName( $contentSchema['ADD_TAB_NAME'] );
$tableNameMap[$contentSchema['ADD_TAB_NAME']] = $contentSchema['ADD_TAB_NAME'];
@@ -1024,54 +1232,15 @@ class pmTablesProxy extends HttpProxyController
$tableData->PRO_UID = $_POST["form"]["PRO_UID"];
}
$isPmTable = false; /*is a report table*/
if($contentSchema["PRO_UID"] == "" ) {
if($contentSchema["PRO_UID"] === '' ) {
$isPmTable = true;
}
$currentPRO_UID = '';
if (isset( $_POST["form"]["PRO_UID_HELP"] ) && !empty($_POST["form"]["PRO_UID_HELP"])) {
$currentPRO_UID = $_POST["form"]["PRO_UID_HELP"];
} else {
if(isset( $_POST["form"]["PRO_UID"]) && !empty( $_POST["form"]["PRO_UID"])){
$currentPRO_UID = $_POST["form"]["PRO_UID"];
$_SESSION['PROCESS'] = $currentPRO_UID;
} else{
$currentPRO_UID = $_SESSION['PROCESS'];
if(!$fromAdmin && !$isPmTable) {
$tableData->PRO_UID = $currentProUid;
}
if(in_array($contentSchema['ADD_TAB_NAME'],$aTablesNew)){
$overWrite = false;
}
if($fromAdmin) { /* from admin tab */
if ($tableExists !== false && !$fromConfirm && !$overWrite) {
$validationType = 1;
throw new Exception( G::loadTranslation( 'ID_OVERWRITE_PMTABLE' ) );
}
if(!in_array($tableData->PRO_UID, $proUids) && !$isPmTable) {
$validationType = 2;
throw new Exception( G::loadTranslation( 'ID_NO_RELATED_PROCESS' ) );
}
} else { /* from designer tab */
if($isPmTable){
$validationType = '';
throw new Exception( G::loadTranslation( 'ID_NO_REPORT_TABLE' ) );
}
if ($tableExists !== false && !$fromConfirm && !$overWrite) {
$validationType = 1;
throw new Exception( G::loadTranslation( 'ID_OVERWRITE_PMTABLE' ) );
}
if($currentPRO_UID != $tableData->PRO_UID) {
if(!in_array($tableData->PRO_UID, $proUids)) {
$validationType = 2;
if(($fromConfirm == $validationType || !$fromConfirm) && !$isPmTable) {
throw new Exception( G::loadTranslation( 'ID_OVERWRITE_RELATED_PROCESS' ) );
} else {
$tableData->PRO_UID = $currentPRO_UID;
}
} else {
$validationType = 3;
throw new Exception( G::loadTranslation( 'ID_ALREADY_RELATED_TABLE ' ) );
}
}
}
if ($overWrite) {
if ($tableExists !== false) {
$additionalTable->deleteAll( $tableExists['ADD_TAB_UID'] );
@@ -1097,7 +1266,16 @@ class pmTablesProxy extends HttpProxyController
$columns = array ();
foreach ($contentSchema['FIELDS'] as $field) {
$column = array ('uid' => '','field_uid' => '','field_name' => $field['FLD_NAME'],'field_dyn' => isset( $field['FLD_DYN_NAME'] ) ? $field['FLD_DYN_NAME'] : '','field_label' => isset( $field['FLD_DESCRIPTION'] ) ? $field['FLD_DESCRIPTION'] : '','field_type' => $field['FLD_TYPE'],'field_size' => $field['FLD_SIZE'],'field_key' => isset( $field['FLD_KEY'] ) ? $field['FLD_KEY'] : 0,'field_null' => isset( $field['FLD_NULL'] ) ? $field['FLD_NULL'] : 1,'field_autoincrement' => isset( $field['FLD_AUTO_INCREMENT'] ) ? $field['FLD_AUTO_INCREMENT'] : 0
$column = array (
'uid' => '',
'field_uid' => '',
'field_name' => $field['FLD_NAME'],
'field_dyn' => isset( $field['FLD_DYN_NAME'] ) ? $field['FLD_DYN_NAME'] : '',
'field_label' => isset( $field['FLD_DESCRIPTION'] ) ? $field['FLD_DESCRIPTION'] : '',
'field_type' => $field['FLD_TYPE'],'field_size' => $field['FLD_SIZE'],
'field_key' => isset( $field['FLD_KEY'] ) ? $field['FLD_KEY'] : 0,
'field_null' => isset( $field['FLD_NULL'] ) ? $field['FLD_NULL'] : 1,
'field_autoincrement' => isset( $field['FLD_AUTO_INCREMENT'] ) ? $field['FLD_AUTO_INCREMENT'] : 0
);
$columns[] = $column;
}
@@ -1106,7 +1284,6 @@ class pmTablesProxy extends HttpProxyController
$tableData->REP_TAB_NAME = $contentSchema['ADD_TAB_NAME'];
$tableData->REP_TAB_DSC = $contentSchema['ADD_TAB_DESCRIPTION'];
$tableData->REP_TAB_CONNECTION = $contentSchema['DBS_UID'];
$tableData->REP_TAB_TYPE = isset( $contentSchema['ADD_TAB_TYPE'] ) ? $contentSchema['ADD_TAB_TYPE'] : '';
$tableData->REP_TAB_GRID = isset( $contentSchema['ADD_TAB_GRID'] ) ? $contentSchema['ADD_TAB_GRID'] : '';
$tableData->columns = G::json_encode( $columns );
@@ -1117,11 +1294,12 @@ class pmTablesProxy extends HttpProxyController
$result = $this->save( $tableData, $alterTable );
if ($result->success) {
G::auditLog("ImportTable", $contentSchema['ADD_TAB_NAME']." (".$contentSchema['ADD_TAB_UID'].") ");
$processQueueTables[$contentSchema['DBS_UID']][] = $contentSchema['ADD_TAB_NAME'];
} else {
$errors .= 'Error creating table: ' . $tableData->REP_TAB_NAME . '-> ' . $result->message . "\n\n";
$errors .= G::loadTranslation('ID_ERROR_CREATE_TABLE') . $tableData->REP_TAB_NAME . '-> ' . $result->message . "\n\n";
}
}
break;
case '@DATA':
$fstName = intval( fread( $fp, 9 ) );
@@ -1141,10 +1319,9 @@ class pmTablesProxy extends HttpProxyController
break;
}
}
fclose( $fp );
G::loadClass( 'pmTable' );
G::loadClass( 'pmTable' );
foreach ($processQueueTables as $dbsUid => $tables) {
$pmTable = new pmTable();
ob_start();
@@ -1153,41 +1330,35 @@ class pmTablesProxy extends HttpProxyController
ob_end_clean();
$errors .= $pmTable->upgradeDatabaseFor( $pmTable->getDataSource(), $tables );
}
$fp = fopen( $PUBLIC_ROOT_PATH . $filename, "rb" );
if(sizeof($tableNameMap)>0){
$errors = $this->dataProcessingOfTables($tableFile,$tableNameMap);
}
return $errors;
}
/**
* Review the *.pmt file and populate the data
* @param string $tableFile
* @param array $tableNameMap
* @return string errors
*/
public function dataProcessingOfTables($tableFile,$tableNameMap){
$fp = fopen( $tableFile, "rb" );
$fsData = intval( fread( $fp, 9 ) );
$sType = fread( $fp, $fsData );
// data processing
$errors = '';
while (! feof( $fp )) {
switch ($sType) {
case '@META':
$fsData = intval( fread( $fp, 9 ) );
$METADATA = fread( $fp, $fsData );
break;
case '@SCHEMA':
$fsUid = intval( fread( $fp, 9 ) );
$uid = fread( $fp, $fsUid );
$fsData = intval( fread( $fp, 9 ) );
$schema = fread( $fp, $fsData );
$contentSchema = unserialize( $schema );
$additionalTable = new additionalTables();
$table = $additionalTable->loadByName( $tableNameMap[$contentSchema['ADD_TAB_NAME']] );
if ($table['PRO_UID'] != '') {
// is a report table, try populate it
$additionalTable->populateReportTable( $table['ADD_TAB_NAME'], pmTable::resolveDbSource( $table['DBS_UID'] ), $table['ADD_TAB_TYPE'], $table['PRO_UID'], $table['ADD_TAB_GRID'], $table['ADD_TAB_UID'] );
}
G::auditLog("ImportTable", $table['ADD_TAB_NAME']." (".$table['ADD_TAB_UID'].") ");
break;
case '@DATA':
$fstName = intval( fread( $fp, 9 ) );
$tableName = fread( $fp, $fstName );
$fsData = intval( fread( $fp, 9 ) );
if ($fsData > 0) {
$data = fread( $fp, $fsData );
$contentData = unserialize( $data );
if(isset($tableNameMap[$tableName])){
$tableName = $tableNameMap[$tableName];
$oAdditionalTables = new AdditionalTables();
@@ -1219,6 +1390,7 @@ class pmTablesProxy extends HttpProxyController
}
}
}
}
break;
}
@@ -1229,43 +1401,7 @@ class pmTablesProxy extends HttpProxyController
break;
}
}
////////////
if ($errors == '') {
$result->success = true;
$msg = G::loadTranslation( 'ID_PMTABLE_IMPORT_SUCCESS', array ($filename
) );
} else {
$result->success = false;
$result->errorType = 'warning';
$msg = G::loadTranslation( 'ID_PMTABLE_IMPORT_WITH_ERRORS', array ($filename
) ) . "\n\n" . $errors;
}
$result->message = $msg;
} catch (Exception $e) {
$result = new stdClass();
$result->fromAdmin = $fromAdmin;
$result->validationType = $validationType;
$result->errorType = 'error';
$result->buildResult = ob_get_contents();
ob_end_clean();
$result->success = false;
// if it is a propel exception message
if (preg_match( '/(.*)\s\[(.*):\s(.*)\]\s\[(.*):\s(.*)\]/', $e->getMessage(), $match )) {
$result->message = $match[3];
$result->type = G::loadTranslation( 'ID_ERROR' );
} else {
$result->message = $e->getMessage();
$result->type = G::loadTranslation( 'ID_EXCEPTION' );
}
//$result->trace = $e->getTraceAsString();
}
return $result;
return $errors;
}
/**

View File

@@ -515,6 +515,9 @@ DeletePMTable = function() {
//Load Import PM Table Form
ImportPMTable = function(){
var aOverwrite,
aRelated,
aMessage;
var w = new Ext.Window({
id: 'windowPmTableUploaderImport',
title: '',
@@ -550,12 +553,6 @@ ImportPMTable = function(){
buttonCfg: {
iconCls: 'upload-icon'
}
}, {
id: 'importPMTableOverwrite',
xtype: 'checkbox',
fieldLabel: '',
boxLabel: _('ID_OVERWRITE_EXIST'), // 'Overwrite if exists?',
name: 'form[OVERWRITE]'
}, {
xtype: 'hidden',
name: 'form[TYPE_TABLE]',
@@ -580,7 +577,7 @@ ImportPMTable = function(){
var result = Ext.util.JSON.decode(resp.response.responseText);
if (result.success) {
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
PMExt.notify('', result.message);
}
else {
win = new Ext.Window({
@@ -613,219 +610,34 @@ ImportPMTable = function(){
var result = Ext.util.JSON.decode(resp.response.responseText);
if (result.errorType == 'warning') {
PMExt.warning(_('ID_WARNING'), result.message.replace(/\n/g,' <br>'));
}
else {
Ext.MessageBox.show({
title: _('ID_WARNING_PMTABLES'),
width: 510,
height: 300,
msg: "<div style=\"overflow: auto; width: 439px; height: 200px;\">" + result.message.replace(/\n/g,' <br>') + "</div>",
buttons: Ext.MessageBox.OK,
animEl: 'mb9',
fn: function(){},
icon: Ext.MessageBox.INFO
});
} else {
if(result.fromAdmin) { /* from admin tab */
if(result.validationType == 1) {
Ext.MessageBox.confirm('Confirmation', result.message.replace(/\n/g,' <br>'), function(btn, text){
if (btn == 'yes'){
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'overWrite',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin'),
'form[OVERWRITE]':true
},
success: function(resp){
var result = Ext.util.JSON.decode(resp.responseText);
if (result.success) {
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
Ext.getCmp('infoGrid').getStore().reload();
} else {
if(result.validationType == 2) {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
}
},
failure: function(obj, resp){
var result = Ext.util.JSON.decode(resp.responseText);
if(result.validationType == 2) {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
}
});
} else {
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'clear',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin')
},
success: function(resp) {
var result = Ext.util.JSON.decode(resp.responseText);
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
Ext.getCmp('infoGrid').getStore().reload();
}
});
}
Ext.getCmp('infoGrid').getStore().reload();
});
return false;
} else {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
aOverwrite = result.arrayOverwrite;
aRelated = result.arrayRelated;
aMessage = result.arrayMessage;
pmtablesErrors(aOverwrite,aRelated,aMessage);
} else { /* from designer tab */
if(result.validationType == 1) {
Ext.MessageBox.confirm('Confirmation', result.message.replace(/\n/g,' <br>'), function(btn, text){
if (btn == 'yes'){
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'2',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin'),
'form[OVERWRITE]':true
},
success: function(resp){
var result = Ext.util.JSON.decode(resp.responseText);
if (result.success) {
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
Ext.getCmp('infoGrid').getStore().reload();
} else {
if(result.validationType == 2) {
Ext.MessageBox.confirm('Confirmation', result.message.replace(/\n/g,' <br>'), function(btn, text){
if (btn == 'yes'){
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'overWrite',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin'),
'form[OVERWRITE]':true
},
success: function(resp){
var result = Ext.util.JSON.decode(resp.responseText);
if (result.success) {
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
Ext.getCmp('infoGrid').getStore().reload();
} else {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
},
failure: function(obj, resp){
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
});
Ext.getCmp('infoGrid').getStore().reload();
}
});
return false;
}
else {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
}
},
failure: function(obj, resp){
var result = Ext.util.JSON.decode(resp.responseText);
if(result.validationType == 2) {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
}
});
Ext.getCmp('infoGrid').getStore().reload();
} else {
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'2',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin'),
'form[PRO_UID_HELP]':PRO_UID
},
success: function(resp) {
var result = Ext.util.JSON.decode(resp.responseText);
if(result.validationType == 2) {
/*add code if related process*/
Ext.MessageBox.confirm('Confirmation', result.message.replace(/\n/g,' <br>'), function(btn, text){
if (btn == 'yes'){
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'overWrite',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin'),
'form[PRO_UID_HELP]':PRO_UID
},
success: function(resp){
var result = Ext.util.JSON.decode(resp.responseText);
if (result.success) {
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
Ext.getCmp('infoGrid').getStore().reload();
} else {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
},
failure: function(obj, resp){
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
});
Ext.getCmp('infoGrid').getStore().reload();
}
});
return false;
} else {
var result = Ext.util.JSON.decode(resp.responseText);
if (result.success) {
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
Ext.getCmp('infoGrid').getStore().reload();
} else {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
}
//PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
},
failure: function(obj, resp){
var result = Ext.util.JSON.decode(resp.responseText);
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
});
}
Ext.getCmp('infoGrid').getStore().reload();
});
return false;
}
if(result.validationType == 2) {
Ext.MessageBox.confirm('Confirmation', result.message.replace(/\n/g,' <br>'), function(btn, text){
if (btn == 'yes'){
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'overWrite',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin'),
'form[OVERWRITE]':true,
'form[PRO_UID_HELP]':PRO_UID
},
success: function(resp){
var result = Ext.util.JSON.decode(resp.responseText);
if (result.success) {
PMExt.notify(_('ID_IMPORT_RESULT'), result.message);
Ext.getCmp('infoGrid').getStore().reload();
} else {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
},
failure: function(obj, resp){
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
});
Ext.getCmp('infoGrid').getStore().reload();
}
});
return false;
} else {
PMExt.error(_('ID_ERROR'), result.message.replace(/\n/g,' <br>'));
}
aOverwrite = result.arrayOverwrite;
aRelated = result.arrayRelated;
aMessage = result.arrayMessage;
pmtablesErrors(aOverwrite,aRelated,aMessage);
}
}
}
});
}
}
}/*,{
text: 'Reset',
handler: function(){
uploader = Ext.getCmp('uploader');
uploader.getForm().reset();
}
}*/,{
},{
id: 'importPMTableButtonCancel',
text: TRANSLATIONS.ID_CANCEL,
handler: function(){
@@ -959,3 +771,167 @@ function updateTagPermissions(){
var top = (Ext.getBody().getViewSize().height/3);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
function pmtablesErrors(aOverwrite,aRelated,aMessage){
var jsonDataArray = [],
i,
fieldMessage,
fieldRadio2Options,
fieldRadio3Options,
win,
tablesOfNo,
tablesOfYes,
tablesOfNew,
valueSelected,
nameId,
number;
//Show the error message ERROR_PROCESS_NOT_EXIST or ERROR_NO_REPORT_TABLE
for (i = 0; i < aMessage.length; i++){
fieldMessage = {
xtype : 'fieldset',
title : aMessage[i]['ERROR_MESS'],
id : aMessage[i]['NAME_TABLE'],
autoHeight : true
};
jsonDataArray.push(fieldMessage);
}
//Check the ERROR_OVERWRITE_RELATED_PROCESS
for (i = 0; i < aRelated.length; i++){
fieldRadio2Options = {
xtype : 'fieldset',
title : aRelated[i]['ERROR_MESS'],
id : aRelated[i]['NAME_TABLE'],
autoHeight : true,
defaultType: 'radio', // each item will be a radio button
items: [{
checked : true,
boxLabel : _('ID_RADIO_RELATED_PROCESS'),
name : aRelated[i]['NAME_TABLE'],
inputValue : 'related'
}, {
boxLabel : _('ID_RADIO_NOT_IMPORTED_RPT'),
name : aRelated[i]['NAME_TABLE'],
inputValue : 'no'
}]
};
jsonDataArray.push(fieldRadio2Options);
}
// check the ERROR_PM_TABLES_OVERWRITE or ERROR_RP_TABLES_OVERWRITE
for (i = 0; i < aOverwrite.length; i++){
fieldRadio3Options = {
xtype : 'fieldset',
title : aOverwrite[i]['ERROR_MESS'],
id : aOverwrite[i]['NAME_TABLE'],
autoHeight : true,
defaultType : 'radio', // each item will be a radio button
items: [{
boxLabel : _('ID_RADIO_CREATE_NEW'),
name : aOverwrite[i]['NAME_TABLE'],
inputValue : 'new'
}, {
boxLabel : _('ID_RADIO_OVERWRITE'),
name : aOverwrite[i]['NAME_TABLE'],
inputValue : 'overwrite'
}, {
checked : true,
boxLabel : _('ID_RADIO_NOT_IMPORTED'),
name : aOverwrite[i]['NAME_TABLE'],
inputValue : 'no'
}]
};
jsonDataArray.push(fieldRadio3Options);
}
number = Math.floor((Math.random() * 100) + 1);
win = new Ext.Window({
id : 'winPmtableRptableErrors'+number,
layout : 'fit',
width : 700,
height : 400,
title : _('ID_WARNING_PMTABLES'),
modal : true,
maximizable: true,
constrain : true,
plain : true,
autoScroll : true,
items : jsonDataArray,
buttons : [{
text : _('ID_CONTINUE'),
handler: function(){
tablesOfNo = '';
tablesOfYes = '';
tablesOfNew = '';
for (i = 0; i < aMessage.length; i++){
nameId = aMessage[i]['NAME_TABLE'];
tablesOfNo = tablesOfNo.concat('|',nameId);
}
for (i = 0; i < aRelated.length; i++){
nameId = aRelated[i]['NAME_TABLE'];
valueSelected = Ext.getCmp(nameId).items.get(0).getGroupValue();
switch(valueSelected) {
case 'related':
tablesOfYes = tablesOfYes.concat('|',nameId);
break;
case 'no':
tablesOfNo = tablesOfNo.concat('|',nameId);
break;
}
}
for (i = 0; i < aOverwrite.length; i++){
nameId = aOverwrite[i]['NAME_TABLE'];
valueSelected = Ext.getCmp(nameId).items.get(0).getGroupValue();
switch(valueSelected) {
case 'new':
tablesOfNew = tablesOfNew.concat('|',nameId);
break;
case 'overwrite':
tablesOfYes = tablesOfYes.concat('|',nameId);
break;
case 'no':
tablesOfNo = tablesOfNo.concat('|',nameId);
break;
}
}
win.close();
Ext.Ajax.request({
url: 'pmTablesProxy/import',
params: {
'form[FROM_CONFIRM]':'yes',
'form[TYPE_TABLE]':(PRO_UID? 'designer' : 'admin'),
'form[OVERWRITE]':true,
'form[TABLES_OF_NO]':tablesOfNo,
'form[TABLES_OF_YES]':tablesOfYes,
'form[TABLES_OF_NEW]':tablesOfNew
},
success: function(resp){
var result = Ext.util.JSON.decode(resp.responseText);
if (result.success) {
PMExt.notify('', result.message);
Ext.getCmp('infoGrid').getStore().reload();
}
},
failure: function(obj, resp){
var result = Ext.util.JSON.decode(resp.responseText);
Ext.getCmp('infoGrid').getStore().reload();
}
});
}
},{
text: _('ID_CANCEL'),
handler: function(){
win.close();
}
}]
});
win.show();
for (i = 0; i < aMessage.length; i++){
Ext.get(aMessage[i]['NAME_TABLE']).setStyle({border: '0', marginTop:'0'} );
}
for (i = 0; i < aRelated.length; i++){
Ext.get(aRelated[i]['NAME_TABLE']).setStyle({border: '0', marginTop:'0'} );
}
for (i = 0; i < aOverwrite.length; i++){
Ext.get(aOverwrite[i]['NAME_TABLE']).setStyle({border: '0', marginTop:'0'} );
}
}