Download_Exports - Version 1.0

Version Notes

none

Download this release

Release Info

Developer Magento Core Team
Extension Download_Exports
Version 1.0
Comparing to
See all releases


Version 1.0

app/code/local/Mage/Downloadexports/Block/Exportview.php ADDED
File without changes
app/code/local/Mage/Downloadexports/Block/Grid.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Downloadexports_Block_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('downloadexports');
9
+ $this->setDefaultSort('file_id');
10
+ $this->setDefaultDir('desc');
11
+ $this->setSaveParametersInSession(false);
12
+ $this->setUseAjax(true);
13
+ $this->setVarNameFilter('export_filter');
14
+ }
15
+
16
+ protected function _getStore()
17
+ {
18
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
19
+ return Mage::app()->getStore($storeId);
20
+ }
21
+
22
+ protected function _prepareCollection()
23
+ {
24
+ $store = $this->_getStore();
25
+ $collection = Mage::getModel('varien/data_collection');
26
+
27
+ ob_start();
28
+ $lines = array();
29
+ $z = exec("ls -lht ".dirname(__FILE__)."/../../../../../../var/export", $lines);
30
+ array_shift($lines);
31
+ ob_end_clean();
32
+ $files = array();
33
+ foreach($lines as $k=>$line) {
34
+ $fileModel = new Varien_Object();
35
+ $matches = array();
36
+ preg_match("/(.*) (.*) (.*) (.*) (.*) (.*) (.*)/", $line, $matches);
37
+ $fullpath = dirname(__FILE__)."/../../../../../../var/export/".$matches[7];
38
+ $fileModel->setData('ctime', date('Y-m-d h:i:s', filectime($fullpath)));
39
+ $fileModel->setData('file_id', $k);
40
+ $fileModel->setData('size', round((filesize($fullpath)/1000),1).'kB');
41
+ $fileModel->setData('name', $matches[7]);
42
+ $collection->addItem($fileModel);
43
+ }
44
+
45
+ $this->setCollection($collection);
46
+
47
+ parent::_prepareCollection();
48
+ return $this;
49
+ }
50
+
51
+ protected function _addColumnFilterToCollection($column)
52
+ {
53
+ return parent::_addColumnFilterToCollection($column);
54
+ }
55
+
56
+ protected function _prepareColumns()
57
+ {
58
+ $this->addColumn('file_id',
59
+ array(
60
+ 'header'=> Mage::helper('catalog')->__('ID'),
61
+ 'width' => '20px',
62
+ 'type' => 'number',
63
+ 'index' => 'file_id',
64
+ 'filter' => false,
65
+ 'sortable' => false,
66
+ ));
67
+ $this->addColumn('name',
68
+ array(
69
+ 'header'=> Mage::helper('catalog')->__('Name'),
70
+ 'index' => 'name',
71
+ ));
72
+
73
+ $this->addColumn('ctime',
74
+ array(
75
+ 'header'=> Mage::helper('catalog')->__('Created'),
76
+ 'width' => '160px',
77
+ 'index' => 'ctime',
78
+ ));
79
+
80
+ $this->addColumn('size',
81
+ array(
82
+ 'header'=> Mage::helper('catalog')->__('Size (kB)'),
83
+ 'width' => '100px',
84
+ 'index' => 'size',
85
+ 'sortable'=> false,
86
+ ));
87
+ $this->addColumn('action',
88
+ array(
89
+ 'header' => Mage::helper('catalog')->__('Action'),
90
+ 'width' => '60px',
91
+ 'type' => 'action',
92
+ 'getter' => 'getName',
93
+ 'actions' => array(
94
+ array(
95
+ 'caption' => Mage::helper('catalog')->__('Delete'),
96
+ 'url' => array(
97
+ 'base'=>'*/*/delete' ),
98
+ 'field' => 'name'
99
+ )
100
+ ),
101
+ 'filter' => false,
102
+ 'sortable' => false,
103
+ ));
104
+ return parent::_prepareColumns();
105
+ }
106
+
107
+ protected function _prepareMassaction()
108
+ {
109
+ $this->setMassactionIdField('name');
110
+ $this->getMassactionBlock()->setFormFieldName('downloadexports');
111
+
112
+ $this->getMassactionBlock()->addItem('delete', array(
113
+ 'label'=> Mage::helper('downloadexports')->__('Delete'),
114
+ 'url' => $this->getUrl('*/*/massDelete'),
115
+ 'confirm' => Mage::helper('downloadexports')->__('Are you sure?')
116
+ ));
117
+
118
+ $this->getMassactionBlock()->addItem('status', array(
119
+ 'label'=> Mage::helper('downloadexports')->__('Download'),
120
+ 'url' => $this->getUrl('*/*/massDownload', array('_current'=>true))
121
+ ));
122
+
123
+ return $this;
124
+ }
125
+
126
+ public function getGridUrl()
127
+ {
128
+ return $this->getUrl('*/*/grid', array('_current'=>true));
129
+ }
130
+
131
+ public function getRowUrl($row)
132
+ {
133
+ return "#";
134
+ return $this->getUrl('*/*/edit', array(
135
+ 'store'=>$this->getRequest()->getParam('store'),
136
+ 'id'=>$row->getId())
137
+ );
138
+ }
139
+ }
app/code/local/Mage/Downloadexports/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?PHP
2
+
3
+ class Mage_Downloadexports_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ }
app/code/local/Mage/Downloadexports/controllers/Adminhtml/ExportviewController.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Downloadexports_Adminhtml_ExportviewController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ $this->loadLayout()->renderLayout();
8
+ }
9
+
10
+ public function downloadAction()
11
+ {
12
+ $post = $this->getRequest()->getPost();
13
+
14
+ try {
15
+ if (empty($post)) {
16
+ Mage::throwException($this->__('Invalid form data.'));
17
+ }
18
+ if(count($post['downloadform']['export'])>1) {
19
+ $zip_str = '';
20
+ foreach($post['downloadform']['export'] as $k=>$v) {
21
+ $zip_str .= dirname(__FILE__).'/../../../../../../../var/export/'.$v.' ';
22
+ }
23
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
24
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
25
+ header("Content-type: application/zip;\n");
26
+ header("Content-Transfer-Encoding: binary");
27
+ header("Cache-Control: no-cache");
28
+ header("Expires: -1");
29
+ header("Content-Disposition: attachment; filename=\"export_".date('m-d-Y').".zip\";\n\n");
30
+ die(passthru("zip -j - $zip_str | cat"));
31
+ } else {
32
+ $v = array_shift($post['downloadform']['export']);
33
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
34
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
35
+ header("Content-type: text/csv;\n");
36
+ header("Content-Transfer-Encoding: binary");
37
+ header("Cache-Control: no-cache");
38
+ header("Expires: -1");
39
+ header("Content-Disposition: attachment; filename=\"$v\";\n\n");
40
+ echo file_get_contents(dirname(__FILE__).'/../../../../../../../var/export/'.$v);
41
+ die();
42
+ }
43
+
44
+ $message = $this->__('Your form has been submitted successfully.');
45
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
46
+ } catch (Exception $e) {
47
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
48
+ }
49
+ $this->_redirect('*/*');
50
+ }
51
+ public function gridAction()
52
+ {
53
+ $this->loadLayout();
54
+ $this->getResponse()->setBody(
55
+ $this->getLayout()->createBlock('downloadexports/grid')->toHtml()
56
+ );
57
+ }
58
+
59
+ public function deleteAction() {
60
+ $file = $this->getRequest()->getParam('name');
61
+ if(unlink(dirname(__FILE__).'/../../../../../../../var/export/'.$file))
62
+ $this->_getSession()->addSuccess($this->__("Deleted file $file successfully"));
63
+ else
64
+ $this->_getSession()->addError($this->__("Could not delete file $file"));
65
+
66
+ $this->_redirect('*/*');
67
+ }
68
+
69
+ public function massDeleteAction() {
70
+ $deleteFiles = $this->getRequest()->getParam($this->getRequest()->getParam('massaction_prepare_key'));
71
+ $successful = 0;
72
+ $failed = 0;
73
+
74
+ if($deleteFiles) {
75
+ foreach($deleteFiles as $fileName) {
76
+ $result = unlink(dirname(__FILE__).'/../../../../../../../var/export/'.$fileName);
77
+ if($result) {
78
+ $successful++;
79
+ } else {
80
+ $failed++;
81
+ }
82
+ }
83
+ if($successful>0)
84
+ $this->_getSession()->addSuccess($this->__("Deleted $successful files successfully"));
85
+ if($failed>0)
86
+ $this->_getSession()->addSuccess($this->__("Unable to delete $failed files"));
87
+ }
88
+ $this->_redirect('*/*');
89
+ }
90
+
91
+ public function massDownloadAction() {
92
+ $dlFiles = $this->getRequest()->getParam($this->getRequest()->getParam('massaction_prepare_key'));
93
+
94
+ if($dlFiles) {
95
+ $zip_str = '';
96
+ foreach($dlFiles as $fileName)
97
+ $zip_str .= dirname(__FILE__).'/../../../../../../../var/export/'.$fileName.' ';
98
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
99
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
100
+ header("Content-type: application/zip;\n");
101
+ header("Content-Transfer-Encoding: binary");
102
+ header("Cache-Control: no-cache");
103
+ header("Expires: -1");
104
+ header("Content-Disposition: attachment; filename=\"export_".date('m-d-Y').".zip\";\n\n");
105
+ die(passthru("zip -j - $zip_str | cat"));
106
+ }
107
+ }
108
+ }
app/code/local/Mage/Downloadexports/etc/config.xml ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mage_Downloadexports>
5
+ <version>0.1.0</version>
6
+ </Mage_Downloadexports>
7
+ </modules>
8
+
9
+ <global>
10
+ <models>
11
+ <downloadexports>
12
+ <class>Mage_Downloadexports_Model</class>
13
+ <resourceModel>downloadexports_mysql4</resourceModel>
14
+ </downloadexports>
15
+ <downloadexports_mysql4>
16
+ <class>Mage_Downloadexports_Model_Mysql4</class>
17
+ </downloadexports_mysql4>
18
+ </models>
19
+ <blocks>
20
+ <downloadexports>
21
+ <class>Mage_Downloadexports_Block</class>
22
+ </downloadexports>
23
+ </blocks>
24
+ <helpers>
25
+ <downloadexports>
26
+ <class>Mage_Downloadexports_Helper</class>
27
+ </downloadexports>
28
+ </helpers>
29
+ </global>
30
+
31
+ <admin>
32
+ <routers>
33
+ <downloadexports>
34
+ <use>admin</use>
35
+ <args>
36
+ <module>Mage_Downloadexports</module>
37
+ <frontName>downloadexports</frontName>
38
+ </args>
39
+ </downloadexports>
40
+ </routers>
41
+ </admin>
42
+
43
+ <adminhtml>
44
+ <translate>
45
+ <modules>
46
+ <mage_adminhtml>
47
+ <files>
48
+ <downloadexports>Mage_Downloadexports.csv</downloadexports>
49
+ </files>
50
+ </mage_adminhtml>
51
+ </modules>
52
+ </translate>
53
+
54
+ <menu>
55
+ <system>
56
+ <children>
57
+ <convert>
58
+ <children>
59
+ <downloadexports_adminform translate="title" module="downloadexports">
60
+ <title>Download Exported Files</title>
61
+ <action>downloadexports/adminhtml_exportview</action>
62
+ <sort_order>50</sort_order>
63
+ </downloadexports_adminform>
64
+ </children>
65
+ </convert>
66
+ </children>
67
+ </system>
68
+ </menu>
69
+
70
+ <acl>
71
+ <resources>
72
+ <admin>
73
+ <children>
74
+ <system>
75
+ <children>
76
+ <downloadexports_adminform>
77
+ <title>Download Exported Files</title>
78
+ </downloadexports_adminform>
79
+ </children>
80
+ </system>
81
+ </children>
82
+ </admin>
83
+ </resources>
84
+ </acl>
85
+
86
+ <layout>
87
+ <updates>
88
+ <downloadexports>
89
+ <file>downloadexports.xml</file>
90
+ </downloadexports>
91
+ </updates>
92
+ </layout>
93
+ </adminhtml>
94
+ </config>
app/design/adminhtml/default/default/layout/downloadexports.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <downloadexports_adminhtml_exportview_index>
4
+ <update handle="downloadexports_exportview_index"/>
5
+ <reference name="content">
6
+ <block type="adminhtml/template" name="exportview" template="downloadexports/exportview.phtml"/>
7
+ <block type="downloadexports/grid" name="exports_widget"/>
8
+ </reference>
9
+ </downloadexports_adminhtml_exportview_index>
10
+ </layout>
app/design/adminhtml/default/default/template/downloadexports/exportview.phtml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--<div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?=$this->__('Download Exported Files')?></h3></td>
5
+ <td class="a-right">
6
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span>Download</span></button>
7
+ </td>
8
+ </tr>
9
+ </table>
10
+ </div>
11
+ <div class="entry-edit">
12
+ <form id="edit_form" name="edit_form" method="post" action="<?=$this->getUrl('*/*/download')?>">
13
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
14
+ <h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__('Select Files to Download')?></h4>
15
+ <span class="smalltext">Multiple selections will be zip archived</span>
16
+ <table cellspacing="0" class="grid" width="100%">
17
+ <tr class="headings">
18
+ <th>&nbsp;</th>
19
+ <th>Filename</th>
20
+ <th>Created</th>
21
+ <th>File Size</th>
22
+ </tr>
23
+ <?php
24
+ ob_start();
25
+ $lines = array();
26
+ $z = exec("ls -lht ".dirname(__FILE__)."/../../../../../../../var/export", $lines);
27
+ array_shift($lines);
28
+ ob_end_clean();
29
+ $files = array();
30
+ foreach($lines as $line) {
31
+ $matches = array();
32
+ preg_match("/(.*) (.*) (.*) (.*) (.*) (.*) (.*)/", $line, $matches);
33
+ $files[] = $matches[7];
34
+ }
35
+
36
+ $odd_or_even = 0;
37
+ foreach($files as $file) {
38
+ $fullpath = dirname(__FILE__)."/../../../../../../../var/export/".$file;
39
+ ?>
40
+ <tr class="<?=($odd_or_even%2)?'odd':'even'?>">
41
+ <td style="width:50px" class="a-center"><input type="checkbox" id="downloadform[export_<?=$odd_or_even?>]" name="downloadform[export][<?=$odd_or_even?>]" value="<?=$file?>" /></td>
42
+ <td><label for="downloadform[export_<?=$odd_or_even?>]"><?=$file?></label></td>
43
+ <td><?=date('m-d-Y h:i:s', filectime($fullpath))?></td>
44
+ <td><?=round((filesize($fullpath)/1000),1)?> Kb</td>
45
+ </tr>
46
+ <?php
47
+ $odd_or_even++;
48
+ }?>
49
+ <!-- <tr>
50
+ <td class="label"><?=$this->__('Field label')?> <span class="required">*</span></td>
51
+ <td class="input-ele"><input class="input-text required-entry" name="myform[myfield]" /></td>
52
+ </tr>
53
+ </table>
54
+ </form>
55
+ </div>-->
56
+ <script type="text/javascript">
57
+ var editForm = new varienForm('edit_form');
58
+ </script>
app/etc/modules/Mage_Downloadexports.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mage_Downloadexports>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Mage_Downloadexports>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Download_Exports</name>
4
+ <version>1.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Download exports through a web interface</summary>
10
+ <description>Magento's great, but it still doesn't provide a way for you to download your export files created through the export profiles.
11
+
12
+ This takes care of that, especially handy for pre 1.5 users who do not have the new ImportExport module!</description>
13
+ <notes>none</notes>
14
+ <authors><author><name>Brad Zasada</name><user>auto-converted</user><email>zasadab03@gmail.com</email></author></authors>
15
+ <date>2011-03-17</date>
16
+ <time>20:47:10</time>
17
+ <contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="downloadexports.xml" hash="b45a2ddebe0f130e78fb01492a4c5d75"/></dir><dir name="template"><dir name="downloadexports"><file name="exportview.phtml" hash="df018e7d4b8bcd9963a09874a609f9b7"/></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Mage"><dir name="Downloadexports"><dir name="Block"><file name="Exportview.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Grid.php" hash="beb4980414cb56c1b11ea67357edb140"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ExportviewController.php" hash="d5d923112feaaa02b41ca59fff89e10f"/></dir></dir><dir name="etc"><file name="config.xml" hash="6ba5c8d013bc0d1806540b2f4e3cb736"/></dir><dir name="Helper"><file name="Data.php" hash="83c91780a78eb431619445de0a3c5284"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mage_Downloadexports.xml" hash="9cde0ce7caa45608e0de3052044d20ad"/></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies/>
20
+ </package>