BUG 0000 Validation to import a CSV file in PMTables.
This commit is contained in:
@@ -549,6 +549,11 @@ class pmTablesProxy extends HttpProxyController
|
|||||||
$i = 1;
|
$i = 1;
|
||||||
$swHead = false;
|
$swHead = false;
|
||||||
while (($aAux = fgetcsv($oFile, 4096, $_POST['form']['CSV_DELIMITER'])) !== false) {
|
while (($aAux = fgetcsv($oFile, 4096, $_POST['form']['CSV_DELIMITER'])) !== false) {
|
||||||
|
if(count($aAdditionalTables['FIELDS']) != count($aAux)){
|
||||||
|
$this->success = false;
|
||||||
|
$this->message = 'INVALID_FILE';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if($i == 1) {
|
if($i == 1) {
|
||||||
$j = 0;
|
$j = 0;
|
||||||
foreach ($aAdditionalTables['FIELDS'] as $aField) {
|
foreach ($aAdditionalTables['FIELDS'] as $aField) {
|
||||||
@@ -566,11 +571,11 @@ class pmTablesProxy extends HttpProxyController
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!$oAdditionalTables->saveDataInTable($_POST['form']['ADD_TAB_UID'], $aData)) {
|
if (!$oAdditionalTables->saveDataInTable($_POST['form']['ADD_TAB_UID'], $aData)) {
|
||||||
$sErrorMessages .= G::LoadTranslation('ID_DUPLICATE_ENTRY_PRIMARY_KEY') . ', ' . G::LoadTranslation('ID_LINE') . ' ' . $i . '<br />';
|
$sErrorMessages .= G::LoadTranslation('ID_DUPLICATE_ENTRY_PRIMARY_KEY') . ', ' . G::LoadTranslation('ID_LINE') . ' ' . $i . '. ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception $oError) {
|
catch (Exception $oError) {
|
||||||
$sErrorMessages .= G::LoadTranslation('ID_ERROR_INSERT_LINE') . ': ' . G::LoadTranslation('ID_LINE') . ' ' . $i . '<br />';
|
$sErrorMessages .= G::LoadTranslation('ID_ERROR_INSERT_LINE') . ': ' . G::LoadTranslation('ID_LINE') . ' ' . $i . '. ';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$swHead = false;
|
$swHead = false;
|
||||||
@@ -582,9 +587,10 @@ class pmTablesProxy extends HttpProxyController
|
|||||||
if ($sErrorMessages != '') {
|
if ($sErrorMessages != '') {
|
||||||
$this->success = false;
|
$this->success = false;
|
||||||
$this->message = $sErrorMessages;
|
$this->message = $sErrorMessages;
|
||||||
|
} else {
|
||||||
|
$this->success = true;
|
||||||
|
$this->message = 'File Imported "'.$filename.'" Successfully';
|
||||||
}
|
}
|
||||||
$this->success = true;
|
|
||||||
$this->message = 'File Imported "'.$filename.'" Successfully';
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sMessage = G::LoadTranslation('ID_UPLOAD_VALID_CSV_FILE');
|
$sMessage = G::LoadTranslation('ID_UPLOAD_VALID_CSV_FILE');
|
||||||
|
|||||||
@@ -360,9 +360,9 @@ ImportPMTableCSV = function(){
|
|||||||
},
|
},
|
||||||
items: [{
|
items: [{
|
||||||
xtype: 'fileuploadfield',
|
xtype: 'fileuploadfield',
|
||||||
id: 'form-file',
|
id: 'csv-file',
|
||||||
emptyText: 'Select a file',
|
emptyText: 'Select a file',
|
||||||
fieldLabel: 'CSV File', // _('ID_FILE'),
|
fieldLabel: 'CSV File',
|
||||||
name: 'form[CSV_FILE]',
|
name: 'form[CSV_FILE]',
|
||||||
buttonText: '',
|
buttonText: '',
|
||||||
buttonCfg: {
|
buttonCfg: {
|
||||||
@@ -370,6 +370,7 @@ ImportPMTableCSV = function(){
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
xtype: 'combo',
|
xtype: 'combo',
|
||||||
|
id: 'csv-delimiter',
|
||||||
fieldLabel: 'Delimited by',
|
fieldLabel: 'Delimited by',
|
||||||
hiddenName: 'form[CSV_DELIMITER]',
|
hiddenName: 'form[CSV_DELIMITER]',
|
||||||
mode: 'local',
|
mode: 'local',
|
||||||
@@ -389,25 +390,41 @@ ImportPMTableCSV = function(){
|
|||||||
buttons: [{
|
buttons: [{
|
||||||
text: _('ID_UPLOAD'),
|
text: _('ID_UPLOAD'),
|
||||||
handler: function(){
|
handler: function(){
|
||||||
var uploader = Ext.getCmp('uploader');
|
var filePath = Ext.getCmp('csv-file').getValue();
|
||||||
|
var fileType = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
|
||||||
|
if(fileType =='csv' ){
|
||||||
|
var uploader = Ext.getCmp('uploader');
|
||||||
|
|
||||||
if(uploader.getForm().isValid()){
|
if(uploader.getForm().isValid()){
|
||||||
uploader.getForm().submit({
|
uploader.getForm().submit({
|
||||||
url: '../pmTablesProxy/importCSV',
|
url: '../pmTablesProxy/importCSV',
|
||||||
waitMsg: 'Uploading file...',
|
waitMsg: 'Uploading file...',
|
||||||
success: function(o, resp){
|
success: function(o, resp){
|
||||||
w.close();
|
w.close();
|
||||||
infoGrid.store.reload();
|
infoGrid.store.reload();
|
||||||
|
|
||||||
PMExt.notify('IMPORT RESULT', resp.result.message);
|
PMExt.notify('IMPORT RESULT', resp.result.message);
|
||||||
},
|
},
|
||||||
failure: function(o, resp){
|
failure: function(o, resp){
|
||||||
w.close();
|
w.close();
|
||||||
Ext.MessageBox.show({title: '', msg: resp.result.msg, buttons:
|
Ext.MessageBox.show({title: '',
|
||||||
Ext.MessageBox.OK, animEl: 'mb9', fn: function(){}, icon:
|
msg: resp.result.message,
|
||||||
Ext.MessageBox.ERROR});
|
buttons: Ext.MessageBox.OK,
|
||||||
}
|
animEl: 'mb9',
|
||||||
});
|
fn: function(){},
|
||||||
|
icon: Ext.MessageBox.ERROR
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ext.MessageBox.show({ title: '',
|
||||||
|
msg: _('ID_INVALID_EXTENSION') + ' ' + fileType,
|
||||||
|
buttons: Ext.MessageBox.OK,
|
||||||
|
animEl: 'mb9',
|
||||||
|
fn: function(){},
|
||||||
|
icon: Ext.MessageBox.ERROR
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
|
|||||||
Reference in New Issue
Block a user