BUG 0000 Validation to import a CSV file in PMTables.

This commit is contained in:
Hector Cortez
2011-07-26 17:54:25 -04:00
parent 784f3be0d2
commit 5d99ab68a6
2 changed files with 48 additions and 25 deletions

View File

@@ -549,6 +549,11 @@ class pmTablesProxy extends HttpProxyController
$i = 1;
$swHead = 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) {
$j = 0;
foreach ($aAdditionalTables['FIELDS'] as $aField) {
@@ -566,32 +571,33 @@ class pmTablesProxy extends HttpProxyController
}
try {
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) {
$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 {
$swHead = false;
}
$i++;
}
}
fclose($oFile);
}
if ($sErrorMessages != '') {
$this->success = false;
$this->message = $sErrorMessages;
} else {
$this->success = true;
$this->message = 'File Imported "'.$filename.'" Successfully';
}
$this->success = true;
$this->message = 'File Imported "'.$filename.'" Successfully';
}
else {
$sMessage = G::LoadTranslation('ID_UPLOAD_VALID_CSV_FILE');
$this->success = false;
$this->message = $sMessage;
}
}
}
/**

View File

@@ -360,9 +360,9 @@ ImportPMTableCSV = function(){
},
items: [{
xtype: 'fileuploadfield',
id: 'form-file',
id: 'csv-file',
emptyText: 'Select a file',
fieldLabel: 'CSV File', // _('ID_FILE'),
fieldLabel: 'CSV File',
name: 'form[CSV_FILE]',
buttonText: '',
buttonCfg: {
@@ -370,6 +370,7 @@ ImportPMTableCSV = function(){
}
}, {
xtype: 'combo',
id: 'csv-delimiter',
fieldLabel: 'Delimited by',
hiddenName: 'form[CSV_DELIMITER]',
mode: 'local',
@@ -389,25 +390,41 @@ ImportPMTableCSV = function(){
buttons: [{
text: _('ID_UPLOAD'),
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()){
uploader.getForm().submit({
url: '../pmTablesProxy/importCSV',
waitMsg: 'Uploading file...',
success: function(o, resp){
w.close();
infoGrid.store.reload();
if(uploader.getForm().isValid()){
uploader.getForm().submit({
url: '../pmTablesProxy/importCSV',
waitMsg: 'Uploading file...',
success: function(o, resp){
w.close();
infoGrid.store.reload();
PMExt.notify('IMPORT RESULT', resp.result.message);
},
failure: function(o, resp){
w.close();
Ext.MessageBox.show({title: '', msg: resp.result.msg, buttons:
Ext.MessageBox.OK, animEl: 'mb9', fn: function(){}, icon:
Ext.MessageBox.ERROR});
}
});
PMExt.notify('IMPORT RESULT', resp.result.message);
},
failure: function(o, resp){
w.close();
Ext.MessageBox.show({title: '',
msg: resp.result.message,
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
});
}
}
},{