BUG 0000 New feature Export data to CSV from a PMTables.
This commit is contained in:
@@ -567,6 +567,71 @@ class pmTablesProxy extends HttpProxyController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* export a pm tables record to CSV
|
||||||
|
* @param string $httpData->id
|
||||||
|
*/
|
||||||
|
public function exportCSV($httpData)
|
||||||
|
{
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
$link = '';
|
||||||
|
$size = '';
|
||||||
|
$META = 'Content';
|
||||||
|
$bytesSaved = 0;
|
||||||
|
|
||||||
|
require_once 'classes/model/AdditionalTables.php';
|
||||||
|
$oAdditionalTables = new AdditionalTables();
|
||||||
|
$aAdditionalTables = $oAdditionalTables->load($_POST['ADD_TAB_UID'], true);
|
||||||
|
$sErrorMessages = '';
|
||||||
|
$sDelimiter = $_POST['CSV_DELIMITER'];
|
||||||
|
|
||||||
|
$resultData = $oAdditionalTables->getAllData($_POST['ADD_TAB_UID']);
|
||||||
|
$rows = $resultData['rows'];
|
||||||
|
$count = $resultData['count'];
|
||||||
|
|
||||||
|
$PUBLIC_ROOT_PATH = PATH_DATA . 'sites' . PATH_SEP . SYS_SYS . PATH_SEP . 'public' . PATH_SEP;
|
||||||
|
$filenameOnly = strtolower( $aAdditionalTables['ADD_TAB_NAME'] ."_".date("Y-m-d").'_'.date("Hi").".csv");
|
||||||
|
$filename = $PUBLIC_ROOT_PATH . $filenameOnly;
|
||||||
|
$fp = fopen( $filename, "wb");
|
||||||
|
|
||||||
|
foreach($rows as $keyCol => $cols ){
|
||||||
|
$SDATA = "";
|
||||||
|
$cnt = count($cols);
|
||||||
|
foreach($cols as $key => $val){
|
||||||
|
$SDATA .= $val;
|
||||||
|
if(--$cnt > 0 ) $SDATA .= $sDelimiter;
|
||||||
|
}
|
||||||
|
$SDATA .= "\n";
|
||||||
|
$bytesSaved += fwrite($fp, $SDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fclose ($fp);
|
||||||
|
|
||||||
|
|
||||||
|
// $filenameLink = "pmTables/streamExported?f=$filenameOnly";
|
||||||
|
$filenameLink = "streamExported?f=$filenameOnly";
|
||||||
|
$size = round(($bytesSaved/1024), 2)." Kb";
|
||||||
|
$filename = $filenameOnly;
|
||||||
|
$link = $filenameLink;
|
||||||
|
|
||||||
|
|
||||||
|
$result->success = true;
|
||||||
|
$result->filename = $filenameOnly;
|
||||||
|
$result->link = $link;
|
||||||
|
$result->message = "Generated file: $filenameOnly, size: $size";
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$result->success = false;
|
||||||
|
$result->message = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* import a pm table
|
* import a pm table
|
||||||
* @param string $httpData->id
|
* @param string $httpData->id
|
||||||
|
|||||||
@@ -17,78 +17,86 @@ var _fields;
|
|||||||
var isReport;
|
var isReport;
|
||||||
|
|
||||||
Ext.onReady(function(){
|
Ext.onReady(function(){
|
||||||
|
|
||||||
pageSize = 20; //parseInt(CONFIG.pageSize);
|
pageSize = 20; //parseInt(CONFIG.pageSize);
|
||||||
|
|
||||||
isReport = tableDef.PRO_UID ? true : false;
|
isReport = tableDef.PRO_UID ? true : false;
|
||||||
|
|
||||||
newButton = new Ext.Action({
|
newButton = new Ext.Action({
|
||||||
text: _('ID_ADD_ROW'),
|
text : _('ID_ADD_ROW'),
|
||||||
iconCls: 'button_menu_ext ss_sprite ss_add',
|
iconCls : 'button_menu_ext ss_sprite ss_add',
|
||||||
handler: NewPMTableRow
|
handler : NewPMTableRow
|
||||||
});
|
});
|
||||||
|
|
||||||
editButton = new Ext.Action({
|
editButton = new Ext.Action({
|
||||||
text: _('ID_EDIT'),
|
text : _('ID_EDIT'),
|
||||||
iconCls: 'button_menu_ext ss_sprite ss_pencil',
|
iconCls : 'button_menu_ext ss_sprite ss_pencil',
|
||||||
handler: EditPMTableRow,
|
handler : EditPMTableRow,
|
||||||
disabled: true
|
disabled : true
|
||||||
});
|
});
|
||||||
|
|
||||||
deleteButton = new Ext.Action({
|
deleteButton = new Ext.Action({
|
||||||
text: _('ID_DELETE'),
|
text : _('ID_DELETE'),
|
||||||
iconCls: 'button_menu_ext ss_sprite ss_delete',
|
iconCls : 'button_menu_ext ss_sprite ss_delete',
|
||||||
handler: DeletePMTableRow,
|
handler : DeletePMTableRow,
|
||||||
disabled: true
|
disabled : true
|
||||||
});
|
});
|
||||||
|
|
||||||
importButton = new Ext.Action({
|
importButton = new Ext.Action({
|
||||||
text: _('ID_IMPORT'),
|
text : _('ID_IMPORT_CSV'),
|
||||||
iconCls: 'silk-add',
|
iconCls : 'silk-add',
|
||||||
icon: '/images/import.gif',
|
icon : '/images/import.gif',
|
||||||
handler: ImportPMTableCSV
|
handler : ImportPMTableCSV
|
||||||
|
});
|
||||||
|
|
||||||
|
exportButton = new Ext.Action({
|
||||||
|
text : _('ID_EXPORT_CSV'),
|
||||||
|
iconCls : 'silk-add',
|
||||||
|
icon : '/images/export.png',
|
||||||
|
handler : ExportPMTableCSV
|
||||||
});
|
});
|
||||||
|
|
||||||
backButton = new Ext.Action({
|
backButton = new Ext.Action({
|
||||||
text: _('ID_BACK'),
|
text : _('ID_BACK'),
|
||||||
icon: '/images/back-icon.png',
|
icon : '/images/back-icon.png',
|
||||||
handler: BackPMList
|
handler : BackPMList
|
||||||
});
|
});
|
||||||
|
|
||||||
contextMenu = new Ext.menu.Menu({
|
contextMenu = new Ext.menu.Menu({
|
||||||
items: [editButton, deleteButton]
|
items : [ editButton,
|
||||||
|
deleteButton ]
|
||||||
});
|
});
|
||||||
|
|
||||||
//This loop loads columns and fields to store and column model
|
//This loop loads columns and fields to store and column model
|
||||||
_columns = new Array();
|
_columns = new Array();
|
||||||
_fields = new Array();
|
_fields = new Array();
|
||||||
_idProperty = '__index__';
|
_idProperty = '__index__';
|
||||||
|
|
||||||
//default generated id
|
//default generated id
|
||||||
_columns.push({
|
_columns.push({
|
||||||
id: _idProperty,
|
id : _idProperty,
|
||||||
hidden: true
|
hidden : true
|
||||||
});
|
});
|
||||||
|
|
||||||
_fields.push({name: _idProperty});
|
_fields.push({name: _idProperty});
|
||||||
|
|
||||||
for (i=0;i<tableDef.FIELDS.length; i++) {
|
for (i=0;i<tableDef.FIELDS.length; i++) {
|
||||||
column = {
|
column = {
|
||||||
id: tableDef.FIELDS[i].FLD_NAME,
|
id : tableDef.FIELDS[i].FLD_NAME,
|
||||||
header: tableDef.FIELDS[i].FLD_DESCRIPTION,
|
header : tableDef.FIELDS[i].FLD_DESCRIPTION,
|
||||||
dataIndex: tableDef.FIELDS[i].FLD_NAME,
|
dataIndex : tableDef.FIELDS[i].FLD_NAME,
|
||||||
width: 40
|
width : 40
|
||||||
};
|
};
|
||||||
if (tableDef.FIELDS[i].FLD_AUTO_INCREMENT != 1) {
|
if (tableDef.FIELDS[i].FLD_AUTO_INCREMENT != 1) {
|
||||||
column.editor = {
|
column.editor = {
|
||||||
xtype: 'textfield',
|
xtype : 'textfield',
|
||||||
allowBlank: true
|
allowBlank : true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
column.editor = {
|
column.editor = {
|
||||||
xtype: 'displayfield',
|
xtype : 'displayfield',
|
||||||
style: 'font-size:11px; padding-left:7px'
|
style : 'font-size:11px; padding-left:7px'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_columns.push(column);
|
_columns.push(column);
|
||||||
@@ -103,7 +111,7 @@ Ext.onReady(function(){
|
|||||||
|
|
||||||
smodel = new Ext.grid.CheckboxSelectionModel({
|
smodel = new Ext.grid.CheckboxSelectionModel({
|
||||||
listeners:{
|
listeners:{
|
||||||
selectionchange: function(sm){
|
selectionchange : function(sm){
|
||||||
var count_rows = sm.getCount();
|
var count_rows = sm.getCount();
|
||||||
switch(count_rows){
|
switch(count_rows){
|
||||||
case 0:
|
case 0:
|
||||||
@@ -128,9 +136,9 @@ Ext.onReady(function(){
|
|||||||
//row editor for table columns grid
|
//row editor for table columns grid
|
||||||
if (!isReport) {
|
if (!isReport) {
|
||||||
editor = new Ext.ux.grid.RowEditor({
|
editor = new Ext.ux.grid.RowEditor({
|
||||||
saveText: _("ID_UPDATE"),
|
saveText : _("ID_UPDATE"),
|
||||||
listeners: {
|
listeners : {
|
||||||
afteredit: {
|
afteredit : {
|
||||||
fn:function(rowEditor, obj, data, rowIndex ){
|
fn:function(rowEditor, obj, data, rowIndex ){
|
||||||
if (data.phantom === true) {
|
if (data.phantom === true) {
|
||||||
//store.reload(); // only if it is an insert
|
//store.reload(); // only if it is an insert
|
||||||
@@ -253,8 +261,15 @@ Ext.onReady(function(){
|
|||||||
store: store,
|
store: store,
|
||||||
cm: cmodel,
|
cm: cmodel,
|
||||||
sm: smodel,
|
sm: smodel,
|
||||||
tbar:[newButton,'-',editButton, deleteButton,'-',importButton,{xtype: 'tbfill'}, backButton],
|
tbar:[ newButton,
|
||||||
// tbar:[newButton,'-',editButton, deleteButton,'-',{xtype: 'tbfill' }, backButton],
|
'-',
|
||||||
|
editButton,
|
||||||
|
deleteButton,
|
||||||
|
'-',
|
||||||
|
importButton,
|
||||||
|
exportButton,
|
||||||
|
{xtype: 'tbfill'},
|
||||||
|
backButton ],
|
||||||
bbar: bbarpaging
|
bbar: bbarpaging
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,65 +376,65 @@ DeletePMTableRow = function(){
|
|||||||
ImportPMTableCSV = function(){
|
ImportPMTableCSV = function(){
|
||||||
|
|
||||||
var comboDelimiter = new Ext.data.SimpleStore({
|
var comboDelimiter = new Ext.data.SimpleStore({
|
||||||
fields: ['id', 'value'],
|
fields : ['id', 'value'],
|
||||||
data: [[';', 'SemiColon (;)'],
|
data : [[';', 'SemiColon (;)'],
|
||||||
[',', 'Comma (,)']]
|
[',', 'Comma (,)']]
|
||||||
});
|
});
|
||||||
var w = new Ext.Window({
|
var w = new Ext.Window({
|
||||||
title: '',
|
title : '',
|
||||||
width: 440,
|
width : 440,
|
||||||
height: 180,
|
height : 180,
|
||||||
modal: true,
|
modal : true,
|
||||||
autoScroll: false,
|
autoScroll : false,
|
||||||
maximizable: false,
|
maximizable : false,
|
||||||
resizable: false,
|
resizable : false,
|
||||||
items: [
|
items: [
|
||||||
new Ext.FormPanel({
|
new Ext.FormPanel({
|
||||||
id:'uploader',
|
id :'uploader',
|
||||||
fileUpload: true,
|
fileUpload : true,
|
||||||
width: 420,
|
width : 420,
|
||||||
frame: true,
|
frame : true,
|
||||||
title: 'Import Data from CSV file',
|
title : _('ID_IMPORT_DATA_CSV'),
|
||||||
autoHeight: false,
|
autoHeight : false,
|
||||||
bodyStyle: 'padding: 10px 10px 0 10px;',
|
bodyStyle : 'padding: 10px 10px 0 10px;',
|
||||||
labelWidth: 80,
|
labelWidth : 80,
|
||||||
defaults: {
|
defaults : {
|
||||||
anchor: '90%',
|
anchor : '90%',
|
||||||
allowBlank: false,
|
allowBlank : false,
|
||||||
msgTarget: 'side'
|
msgTarget : 'side'
|
||||||
},
|
},
|
||||||
items: [{
|
items : [{
|
||||||
xtype: 'fileuploadfield',
|
xtype : 'fileuploadfield',
|
||||||
id: 'csv-file',
|
id : 'csv-file',
|
||||||
emptyText: 'Select a file',
|
emptyText : 'Select a file',
|
||||||
fieldLabel: 'CSV File',
|
fieldLabel : 'CSV File',
|
||||||
name: 'form[CSV_FILE]',
|
name : 'form[CSV_FILE]',
|
||||||
buttonText: '',
|
buttonText : '',
|
||||||
buttonCfg: {
|
buttonCfg : {
|
||||||
iconCls: 'upload-icon'
|
iconCls: 'upload-icon'
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
xtype: 'combo',
|
xtype : 'combo',
|
||||||
id: 'csv-delimiter',
|
id : 'csv-delimiter',
|
||||||
fieldLabel: 'Delimited by',
|
fieldLabel : 'Delimited by',
|
||||||
hiddenName: 'form[CSV_DELIMITER]',
|
hiddenName : 'form[CSV_DELIMITER]',
|
||||||
mode: 'local',
|
mode : 'local',
|
||||||
store: comboDelimiter,
|
store : comboDelimiter,
|
||||||
displayField: 'value',
|
displayField : 'value',
|
||||||
valueField: 'id',
|
valueField : 'id',
|
||||||
allowBlank: false,
|
allowBlank : false,
|
||||||
triggerAction: 'all',
|
triggerAction : 'all',
|
||||||
emptyText: _('ID_SELECT'),
|
emptyText : _('ID_SELECT'),
|
||||||
selectOnFocus:true
|
selectOnFocus : true
|
||||||
|
|
||||||
},{
|
},{
|
||||||
xtype: 'hidden',
|
xtype : 'hidden',
|
||||||
name: 'form[ADD_TAB_UID]',
|
name : 'form[ADD_TAB_UID]',
|
||||||
value: tableDef.ADD_TAB_UID
|
value : tableDef.ADD_TAB_UID
|
||||||
}],
|
}],
|
||||||
buttons: [{
|
buttons : [{
|
||||||
text: _('ID_UPLOAD'),
|
text : _('ID_UPLOAD'),
|
||||||
handler: function(){
|
handler : function(){
|
||||||
var filePath = Ext.getCmp('csv-file').getValue();
|
var filePath = Ext.getCmp('csv-file').getValue();
|
||||||
var fileType = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
|
var fileType = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
|
||||||
if(fileType =='csv' ){
|
if(fileType =='csv' ){
|
||||||
@@ -427,9 +442,9 @@ ImportPMTableCSV = function(){
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
@@ -438,30 +453,138 @@ ImportPMTableCSV = function(){
|
|||||||
failure: function(o, resp){
|
failure: function(o, resp){
|
||||||
w.close();
|
w.close();
|
||||||
Ext.MessageBox.show({title: '',
|
Ext.MessageBox.show({title: '',
|
||||||
msg: resp.result.message,
|
msg : resp.result.message,
|
||||||
buttons: Ext.MessageBox.OK,
|
buttons : Ext.MessageBox.OK,
|
||||||
animEl: 'mb9',
|
animEl : 'mb9',
|
||||||
fn: function(){},
|
fn : function(){},
|
||||||
icon: Ext.MessageBox.ERROR
|
icon : Ext.MessageBox.ERROR
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ext.MessageBox.show({ title: '',
|
Ext.MessageBox.show({ title : '',
|
||||||
msg: _('ID_INVALID_EXTENSION') + ' ' + fileType,
|
msg : _('ID_INVALID_EXTENSION') + ' ' + fileType,
|
||||||
buttons: Ext.MessageBox.OK,
|
buttons : Ext.MessageBox.OK,
|
||||||
animEl: 'mb9',
|
animEl : 'mb9',
|
||||||
fn: function(){},
|
fn : function(){},
|
||||||
icon: Ext.MessageBox.ERROR
|
icon : Ext.MessageBox.ERROR
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
text: TRANSLATIONS.ID_CANCEL,
|
text : TRANSLATIONS.ID_CANCEL,
|
||||||
handler: function(){
|
handler : function(){
|
||||||
w.close();
|
w.close();
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
]
|
||||||
|
|
||||||
|
});
|
||||||
|
w.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
ExportPMTableCSV = function(){
|
||||||
|
|
||||||
|
var comboDelimiter = new Ext.data.SimpleStore({
|
||||||
|
fields : ['id', 'value'],
|
||||||
|
data : [[';', 'SemiColon (;)'],
|
||||||
|
[',', 'Comma (,)']]
|
||||||
|
});
|
||||||
|
var w = new Ext.Window({
|
||||||
|
title : '',
|
||||||
|
width : 320,
|
||||||
|
height : 140,
|
||||||
|
modal : true,
|
||||||
|
autoScroll : false,
|
||||||
|
maximizable : false,
|
||||||
|
resizable : false,
|
||||||
|
items: [
|
||||||
|
new Ext.FormPanel({
|
||||||
|
id :'uploader',
|
||||||
|
fileUpload : true,
|
||||||
|
width : 300,
|
||||||
|
frame : true,
|
||||||
|
title : _('ID_EXPORT_DATA_CSV'),
|
||||||
|
autoHeight : false,
|
||||||
|
bodyStyle : 'padding: 10px 10px 0 10px;',
|
||||||
|
labelWidth : 80,
|
||||||
|
defaults : {
|
||||||
|
anchor : '90%',
|
||||||
|
allowBlank : false,
|
||||||
|
msgTarget : 'side'
|
||||||
|
},
|
||||||
|
items : [{
|
||||||
|
xtype : 'combo',
|
||||||
|
id : 'csv_delimiter',
|
||||||
|
fieldLabel : 'Delimited by',
|
||||||
|
hiddenName : 'form[CSV_DELIMITER]',
|
||||||
|
mode : 'local',
|
||||||
|
store : comboDelimiter,
|
||||||
|
displayField : 'value',
|
||||||
|
valueField : 'id',
|
||||||
|
allowBlank : false,
|
||||||
|
triggerAction : 'all',
|
||||||
|
emptyText : _('ID_SELECT'),
|
||||||
|
selectOnFocus : true
|
||||||
|
|
||||||
|
},{
|
||||||
|
xtype : 'hidden',
|
||||||
|
name : 'form[ADD_TAB_UID]',
|
||||||
|
value : tableDef.ADD_TAB_UID
|
||||||
|
} ],
|
||||||
|
buttons : [{
|
||||||
|
text : _('ID_EXPORT'),
|
||||||
|
handler : function(){
|
||||||
|
var csvDelimiter = Ext.getCmp('csv_delimiter').getValue();
|
||||||
|
if(csvDelimiter != '') {
|
||||||
|
Ext.Msg.show({
|
||||||
|
title : '',
|
||||||
|
msg : _('ID_PROCESSING'),
|
||||||
|
wait : true,
|
||||||
|
waitConfig : {interval:500}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ext.Ajax.request({
|
||||||
|
url: '../pmTablesProxy/exportCSV',
|
||||||
|
params: {
|
||||||
|
ADD_TAB_UID : tableDef.ADD_TAB_UID,
|
||||||
|
CSV_DELIMITER : Ext.getCmp('csv_delimiter').getValue()
|
||||||
|
},
|
||||||
|
success: function(resp){
|
||||||
|
|
||||||
|
Ext.Msg.hide();
|
||||||
|
w.close();
|
||||||
|
|
||||||
|
result = Ext.util.JSON.decode(resp.responseText);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
location.href = result.link;
|
||||||
|
} else {
|
||||||
|
PMExt.error(_('ID_ERROR', result.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
failure: function(obj, resp){
|
||||||
|
Ext.Msg.alert( _('ID_ERROR'), resp.result.msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Ext.MessageBox.show({ title : '',
|
||||||
|
msg : _('ID_INVALID_DELIMITER'),
|
||||||
|
buttons : Ext.MessageBox.OK,
|
||||||
|
animEl : 'mb9',
|
||||||
|
fn : function(){},
|
||||||
|
icon : Ext.MessageBox.ERROR
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
},{
|
||||||
|
text : TRANSLATIONS.ID_CANCEL,
|
||||||
|
handler : function(){
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
@@ -470,6 +593,7 @@ ImportPMTableCSV = function(){
|
|||||||
w.show();
|
w.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Load PM Table List
|
//Load PM Table List
|
||||||
BackPMList = function(){
|
BackPMList = function(){
|
||||||
//location.href = 'additionalTablesList';
|
//location.href = 'additionalTablesList';
|
||||||
|
|||||||
Reference in New Issue
Block a user