Ifuturz_Uploadpdf - Version 0.1.0

Version Notes

First Upload PDF Extension

Download this release

Release Info

Developer Iverve
Extension Ifuturz_Uploadpdf
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Ifuturz/Uploadpdf/Block/Adminhtml/Catalog/Product/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ifuturz_Uploadpdf_Block_Adminhtml_Uploadpdf_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ )
13
+ );
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+ }
app/code/local/Ifuturz/Uploadpdf/Block/Adminhtml/Catalog/Product/Edit/Tab/Uploadpdf.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product inventory data
29
+ *
30
+ * @author Magento Core Team <core@magentocommerce.com>
31
+ */
32
+ class Ifuturz_Uploadpdf_Block_Adminhtml_Catalog_Product_Edit_Tab_Uploadpdf extends Mage_Adminhtml_Block_Widget
33
+ {
34
+ public function __construct()
35
+ {
36
+ parent::__construct();
37
+ $this->setTemplate('uploadpdf/catalog/product/tab/uploadpdf.phtml');
38
+ }
39
+
40
+
41
+ }
app/code/local/Ifuturz/Uploadpdf/Block/Adminhtml/Catalog/Product/Edit/Tabs.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php';
3
+ class Ifuturz_Uploadpdf_Block_Adminhtml_Catalog_Product_Edit_Tabs
4
+ extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
5
+ {
6
+ protected function _prepareLayout()
7
+ {
8
+ $product = $this->getProduct();
9
+
10
+ if (!($setId = $product->getAttributeSetId())) {
11
+ $setId = $this->getRequest()->getParam('set', null);
12
+ }
13
+
14
+ if ($setId) {
15
+ $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
16
+ ->setAttributeSetFilter($setId)
17
+ ->setSortOrder()
18
+ ->load();
19
+ /*$groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
20
+ ->setAttributeSetFilter($setId)
21
+ ->load();*/
22
+
23
+ foreach ($groupCollection as $group) {
24
+ $attributes = $product->getAttributes($group->getId(), true);
25
+ // do not add groups without attributes
26
+
27
+ foreach ($attributes as $key => $attribute) {
28
+ if( !$attribute->getIsVisible() ) {
29
+ unset($attributes[$key]);
30
+ }
31
+ }
32
+
33
+ if (count($attributes)==0) {
34
+ continue;
35
+ }
36
+
37
+ $this->addTab('group_'.$group->getId(), array(
38
+ 'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
39
+ 'content' => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
40
+ 'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
41
+ ->setGroupAttributes($attributes)
42
+ ->toHtml()),
43
+ ));
44
+ }
45
+ /* ------------------- Added code by R ----------------------- */
46
+
47
+ $geteditid = $_GET['editid'];
48
+
49
+ if (Mage::helper('core')->isModuleEnabled('Mage_CatalogInventory'))
50
+ {
51
+ $this->addTab('inventory', array(
52
+ 'label' => Mage::helper('catalog')->__('Inventory'),
53
+ 'content' => $this->_translateHtml($this->getLayout()
54
+ ->createBlock('adminhtml/catalog_product_edit_tab_inventory')->toHtml()),
55
+ ));
56
+
57
+ /* ------------------- START Added code by R ----------------------- */
58
+ if($geteditid != '')
59
+ {
60
+ $this->addTab('Upload PDF', array(
61
+ 'label' => Mage::helper('catalog')->__('Upload PDF'),
62
+ 'active' => true,
63
+ 'content' => $this->_translateHtml($this->getLayout()
64
+ ->createBlock('uploadpdf/adminhtml_catalog_product_edit_tab_uploadpdf')->toHtml()),
65
+ ));
66
+ }
67
+ else
68
+ {
69
+ $this->addTab('Upload PDF', array(
70
+ 'label' => Mage::helper('catalog')->__('Upload PDF'),
71
+ 'content' => $this->_translateHtml($this->getLayout()
72
+ ->createBlock('uploadpdf/adminhtml_catalog_product_edit_tab_uploadpdf')->toHtml()),
73
+ ));
74
+
75
+ }
76
+ /* ------------------- END Added code by R ----------------------- */
77
+ }
78
+
79
+ /**
80
+ * Don't display website tab for single mode
81
+ */
82
+ if (!Mage::app()->isSingleStoreMode()) {
83
+ $this->addTab('websites', array(
84
+ 'label' => Mage::helper('catalog')->__('Websites'),
85
+ 'content' => $this->_translateHtml($this->getLayout()
86
+ ->createBlock('adminhtml/catalog_product_edit_tab_websites')->toHtml()),
87
+ ));
88
+ }
89
+
90
+ $this->addTab('categories', array(
91
+ 'label' => Mage::helper('catalog')->__('Categories'),
92
+ 'url' => $this->getUrl('*/*/categories', array('_current' => true)),
93
+ 'class' => 'ajax',
94
+ ));
95
+
96
+ $this->addTab('related', array(
97
+ 'label' => Mage::helper('catalog')->__('Related Products'),
98
+ 'url' => $this->getUrl('*/*/related', array('_current' => true)),
99
+ 'class' => 'ajax',
100
+ ));
101
+
102
+ $this->addTab('upsell', array(
103
+ 'label' => Mage::helper('catalog')->__('Up-sells'),
104
+ 'url' => $this->getUrl('*/*/upsell', array('_current' => true)),
105
+ 'class' => 'ajax',
106
+ ));
107
+
108
+ $this->addTab('crosssell', array(
109
+ 'label' => Mage::helper('catalog')->__('Cross-sells'),
110
+ 'url' => $this->getUrl('*/*/crosssell', array('_current' => true)),
111
+ 'class' => 'ajax',
112
+ ));
113
+
114
+
115
+ $storeId = 0;
116
+ if ($this->getRequest()->getParam('store')) {
117
+ $storeId = Mage::app()->getStore($this->getRequest()->getParam('store'))->getId();
118
+ }
119
+
120
+ $alertPriceAllow = Mage::getStoreConfig('catalog/productalert/allow_price');
121
+ $alertStockAllow = Mage::getStoreConfig('catalog/productalert/allow_stock');
122
+
123
+ if (($alertPriceAllow || $alertStockAllow) && !$product->isGrouped()) {
124
+ $this->addTab('productalert', array(
125
+ 'label' => Mage::helper('catalog')->__('Product Alerts'),
126
+ 'content' => $this->_translateHtml($this->getLayout()
127
+ ->createBlock('adminhtml/catalog_product_edit_tab_alerts', 'admin.alerts.products')->toHtml())
128
+ ));
129
+ }
130
+
131
+ if( $this->getRequest()->getParam('id', false) ) {
132
+ if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')) {
133
+ if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')){
134
+ $this->addTab('reviews', array(
135
+ 'label' => Mage::helper('catalog')->__('Product Reviews'),
136
+ 'url' => $this->getUrl('*/*/reviews', array('_current' => true)),
137
+ 'class' => 'ajax',
138
+ ));
139
+ }
140
+ }
141
+ if (Mage::helper('catalog')->isModuleEnabled('Mage_Tag')) {
142
+ if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')){
143
+ $this->addTab('tags', array(
144
+ 'label' => Mage::helper('catalog')->__('Product Tags'),
145
+ 'url' => $this->getUrl('*/*/tagGrid', array('_current' => true)),
146
+ 'class' => 'ajax',
147
+ ));
148
+
149
+ $this->addTab('customers_tags', array(
150
+ 'label' => Mage::helper('catalog')->__('Customers Tagged Product'),
151
+ 'url' => $this->getUrl('*/*/tagCustomerGrid', array('_current' => true)),
152
+ 'class' => 'ajax',
153
+ ));
154
+ }
155
+ }
156
+
157
+
158
+ }
159
+
160
+ /**
161
+ * Do not change this tab id
162
+ * @see Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs_Configurable
163
+ * @see Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tabs
164
+ */
165
+ if (!$product->isGrouped()) {
166
+ $this->addTab('customer_options', array(
167
+ 'label' => Mage::helper('catalog')->__('Custom Options'),
168
+ 'url' => $this->getUrl('*/*/options', array('_current' => true)),
169
+ 'class' => 'ajax',
170
+ ));
171
+ }
172
+
173
+ }
174
+ else {
175
+ $this->addTab('set', array(
176
+ 'label' => Mage::helper('catalog')->__('Settings'),
177
+ 'content' => $this->_translateHtml($this->getLayout()
178
+ ->createBlock('adminhtml/catalog_product_edit_tab_settings')->toHtml()),
179
+ 'active' => true
180
+ ));
181
+ }
182
+ return parent::_prepareLayout();
183
+ }
184
+
185
+
186
+ }
app/code/local/Ifuturz/Uploadpdf/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Ifuturz_Uploadpdf_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
app/code/local/Ifuturz/Uploadpdf/Model/Mysql4/Uploadpdf.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ifuturz_Uploadpdf_Model_Mysql4_Uploadpdf extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ // Note that the register_id refers to the key field in your database table.
7
+ $this->_init('uploadpdf/uploadpdf', 'pdf_id');
8
+ }
9
+
10
+ }
app/code/local/Ifuturz/Uploadpdf/Model/Mysql4/Uploadpdf/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ifuturz_Uploadpdf_Model_Mysql4_Uploadpdf_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('uploadpdf/uploadpdf');
8
+ }
9
+ /*public function getPublishernameArray()
10
+ {
11
+ $options = array();
12
+ $this->addOrder('publisher_name', 'asc');
13
+ foreach ($this as $item) {
14
+ $options[] = array(
15
+ 'value' => $item->getPublisherId(),
16
+ 'label' => $item->getPublisherName()
17
+ );
18
+ }
19
+ if (count($options)>0) {
20
+ array_unshift($options, array('title'=>null, 'value'=>'0', 'label'=>Mage::helper('publisher')->__('-- Please select --')));
21
+ }
22
+ return $options;
23
+ }*/
24
+
25
+ }
app/code/local/Ifuturz/Uploadpdf/Model/Observer.php ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ifuturz_Uploadpdf_Model_Observer
4
+ {
5
+ /**
6
+ * Flag to stop observer executing more than once
7
+ *
8
+ * @var static bool
9
+ */
10
+ static protected $_singletonFlag = false;
11
+
12
+ /**
13
+ * This method will run when the product is saved from the Magento Admin
14
+ * Use this function to update the product model, process the
15
+ * data or anything you like
16
+ *
17
+ * @param Varien_Event_Observer $observer
18
+ */
19
+ public function saveProductTabData(Varien_Event_Observer $observer)
20
+ {
21
+ //echo "hello";die;
22
+ if (!self::$_singletonFlag) {
23
+ self::$_singletonFlag = true;
24
+
25
+ $product = $observer->getEvent()->getProduct();
26
+ //echo "<pre>"; print_r($product);die;
27
+ $productid = $product->getId();
28
+
29
+ try {
30
+ /**
31
+ * Perform any actions you want here
32
+ *
33
+ */
34
+ //$id = $this->_getRequest()->getParam('id');
35
+ //$countcolorid = $this->_getRequest()->getParam('hidden');
36
+
37
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
38
+ $collection = array();
39
+ $data1 = Mage::getModel('uploadpdf/uploadpdf')->getCollection();
40
+ foreach($data1 as $cd)
41
+ {
42
+ $collection[] = $cd['pdf_file'];
43
+ }
44
+ //echo "<pre>";print_r($collection);die;
45
+ $det_edit_id = $this->_getRequest()->getParam('editid');
46
+ //unlink("/pdfs/test3.pdf");die;
47
+
48
+ if ($data = $this->_getRequest()->getPost())
49
+ {
50
+ //echo "<pre>"; print_r($data);die;
51
+ $pdfname = $data['pdf_name'];
52
+ if(isset($_FILES['upload_pdf']['name']) && $_FILES['upload_pdf']['name'] != '') {
53
+
54
+ //this way the name is saved in DB
55
+ $data['upload_pdf'] = $_FILES['upload_pdf']['name'];
56
+ $front = $data['upload_pdf'];
57
+
58
+ //$imgPath = Mage::getBaseUrl('media')."pdffiles/uploadedfiles/".$front;
59
+ $imgPath1 = Mage::getBaseUrl()."pdfs/".$front;
60
+ $imgPath = str_replace("/index.php","",$imgPath1);//die;
61
+ $data['pdf_path'] = '<img src="'.$imgPath.'" border="0" />';
62
+
63
+ }
64
+ }
65
+
66
+ $collection = array();
67
+ $data1 = Mage::getModel('uploadpdf/uploadpdf')->getCollection();
68
+ foreach($data1 as $cd)
69
+ {
70
+ $collection[] = $cd['pdf_file'];
71
+ }
72
+ //echo "<pre>";print_r($collection);die;
73
+ $cpid=Mage::registry('current_product')->getId();
74
+ //$uploadpdf = "media/pdffiles/uploadedfiles/";
75
+ $uploadpdf = "pdfs/";
76
+
77
+ /*------------------------------ Multiple DELETE PDF CODE -------------------------------------*/
78
+
79
+ if(!empty($_POST['chkdelete'])) {
80
+ foreach($_POST['chkdelete'] as $checkdel) {
81
+ //echo $checkdel;
82
+
83
+ $readresult = $write->query("SELECT pdf_file FROM ifuturz_uploadpdf WHERE pdf_id ='$checkdel'");
84
+ $entityid = $readresult->fetch();
85
+ $delfilef = $entityid['pdf_file'];
86
+
87
+ unlink("pdfs/".$delfilef);
88
+
89
+ $sql1del = "DELETE FROM `ifuturz_uploadpdf` WHERE pdf_id = '$checkdel'";
90
+ $write->query($sql1del);
91
+ }
92
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF(s) deleted successfully.'));
93
+ }
94
+ //die;
95
+
96
+ if($det_edit_id == '')
97
+ {
98
+
99
+ /*------------------------------ ADD PDF CODE -------------------------------------*/
100
+
101
+ if($front != "")
102
+ {
103
+
104
+ if(file_exists($uploadpdf.$front))
105
+ {
106
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('PDF file already exists!!'));
107
+ }
108
+ else
109
+ {
110
+ $ext = end(explode(".", $front));
111
+
112
+ if(($ext == "pdf") || ($ext == "PDF"))
113
+ {
114
+ $pdftempfile = $_FILES['upload_pdf']['tmp_name'];
115
+ //echo $pdftempfile."<br>".$uploadpdf.$front;
116
+ move_uploaded_file($pdftempfile,$uploadpdf.$front);
117
+
118
+ if(!in_array($front,$collection))
119
+ {
120
+ $sql1 = "INSERT INTO `ifuturz_uploadpdf` (`product_id`,`pdf_file`,`pdfname`,`pdf_path`) VALUES ('$productid','$front','$pdfname','$imgPath' )";
121
+ $write->query($sql1);
122
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF uploaded successfully.'));
123
+ }
124
+ }
125
+ else
126
+ {
127
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('Only PDF file is allowed.!'));
128
+ }
129
+ }
130
+ }
131
+ $product->save();
132
+ }
133
+ else
134
+ {
135
+ //die('hello');
136
+ /*------------------------------ UPDATE PDF CODE -------------------------------------*/
137
+
138
+ $readresultn = $write->query("SELECT pdf_file FROM ifuturz_uploadpdf WHERE pdf_id ='$det_edit_id'");
139
+ $entityidn = $readresultn->fetch();
140
+ $delfilefn = $entityidn['pdf_file'];
141
+
142
+ if($front == '')
143
+ {
144
+ $front = $delfilefn;
145
+ }
146
+
147
+ if($front != $delfilefn)
148
+ {
149
+ unlink("pdfs/".$delfilefn);
150
+ }
151
+
152
+ if((file_exists($uploadpdf.$front)) && ($front != $delfilefn))
153
+ {
154
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('PDF file already exists!!'));
155
+ }
156
+ else
157
+ {
158
+ if($front == '')
159
+ {
160
+ $front = $delfilefn;
161
+ }
162
+
163
+ $ext = end(explode(".", $front));
164
+
165
+ if(($ext == "pdf") || ($ext == "PDF"))
166
+ {
167
+ $pdftempfile = $_FILES['upload_pdf']['tmp_name'];
168
+ //echo $pdftempfile."<br>".$uploadpdf.$front;die;
169
+ move_uploaded_file($pdftempfile,$uploadpdf.$front);
170
+
171
+ $imgUpPath1 = Mage::getBaseUrl()."pdfs/".$front;
172
+ $imgUpPath = str_replace("/index.php","",$imgUpPath1);
173
+
174
+ $sql1_edit = "Update ifuturz_uploadpdf SET pdf_file = '$front',pdfname = '$pdfname',pdf_path = '$imgUpPath' WHERE pdf_id='$det_edit_id'";
175
+ $write->query($sql1_edit);
176
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('uploadpdf')->__('PDF updated successfully.'));
177
+ }
178
+ else
179
+ {
180
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('Only PDF file is allowed.!'));
181
+ }
182
+ }
183
+ $product->save();
184
+
185
+ }
186
+
187
+ }
188
+ catch (Exception $e) {
189
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
190
+ }
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Retrieve the product model
196
+ *
197
+ * @return Mage_Catalog_Model_Product $product
198
+ */
199
+ public function getProduct()
200
+ {
201
+ return Mage::registry('product');
202
+ }
203
+
204
+ /**
205
+ * Shortcut to getRequest
206
+ *
207
+ */
208
+ protected function _getRequest()
209
+ {
210
+ return Mage::app()->getRequest();
211
+ }
212
+ }
app/code/local/Ifuturz/Uploadpdf/Model/Uploadpdf.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ifuturz_Uploadpdf_Model_Uploadpdf extends Mage_Core_Model_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('uploadpdf/uploadpdf');
8
+ }
9
+
10
+ }
app/code/local/Ifuturz/Uploadpdf/controllers/Adminhtml/UploadpdfController.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ifuturz_Uploadpdf_Adminhtml_UploadpdfController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ protected function _initAction()
6
+ {
7
+ $this->loadLayout()
8
+ ->_setActiveMenu('uploadpdf')
9
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Add uploadpdf Category Management'), Mage::helper('adminhtml')->__('Add uploadpdf category Management'));
10
+
11
+ return $this;
12
+ }
13
+
14
+ public function indexAction()
15
+ {
16
+ $this->_initAction()
17
+ ->renderLayout();
18
+ }
19
+
20
+
21
+ public function editAction() {
22
+ $id = $this->getRequest()->getParam('id');
23
+ $model = Mage::getModel('uploadpdf/uploadpdf')->load($id);
24
+
25
+ if ($model->getId() || $id == 0) {
26
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
27
+ if (!empty($data)) {
28
+ $model->setData($data);
29
+ }
30
+ /* if($id!=0)
31
+ {
32
+ Mage::register('region_reload', $model);
33
+ }
34
+ */
35
+ Mage::register('uploadpdf_data', $model);
36
+
37
+ $this->loadLayout();
38
+ $this->_setActiveMenu('uploadpdf');
39
+
40
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Add uploadpdf Management'), Mage::helper('adminhtml')->__('Add uploadpdf Management'));
41
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Rule News'), Mage::helper('adminhtml')->__('Rule News'));
42
+
43
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
44
+
45
+ $this->_addContent($this->getLayout()->createBlock('uploadpdf/adminhtml_uploadpdf_edit'))
46
+ ->_addLeft($this->getLayout()->createBlock('uploadpdf/adminhtml_uploadpdf_edit_tabs'));
47
+
48
+ $this->renderLayout();
49
+ } else {
50
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('uploadpdf')->__('uploadpdf does not exist'));
51
+ $this->_redirect('*/*/');
52
+ }
53
+ }
54
+
55
+ public function newAction()
56
+ {
57
+ $this->_forward('edit');
58
+ }
59
+
60
+ public function saveAction()
61
+ {
62
+
63
+ }
64
+
65
+
66
+ }
app/code/local/Ifuturz/Uploadpdf/controllers/IndexController.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ifuturz_Uploadpdf_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+
5
+ public function indexAction()
6
+ {
7
+ $this->loadLayout()->renderLayout();
8
+ }
9
+ }
app/code/local/Ifuturz/Uploadpdf/etc/config.xml ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Ifuturz_Uploadpdf>
5
+ <version>0.1.0</version>
6
+ </Ifuturz_Uploadpdf>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <uploadpdf>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Ifuturz_Uploadpdf</module>
14
+ <frontName>uploadpdf</frontName>
15
+ </args>
16
+ </uploadpdf>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <uploadpdf>
21
+ <file>uploadpdf.xml</file>
22
+ </uploadpdf>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <global>
27
+ <blocks>
28
+ <uploadpdf>
29
+ <class>Ifuturz_Uploadpdf_Block</class>
30
+ </uploadpdf>
31
+ <adminhtml>
32
+ <rewrite>
33
+ <catalog_product_edit_tabs>Ifuturz_Uploadpdf_Block_Adminhtml_Catalog_Product_Edit_Tabs</catalog_product_edit_tabs>
34
+ </rewrite>
35
+ </adminhtml>
36
+ </blocks>
37
+ <models>
38
+ <uploadpdf>
39
+ <class>Ifuturz_Uploadpdf_Model</class>
40
+ <resourceModel>uploadpdf_mysql4</resourceModel>
41
+ </uploadpdf>
42
+ <uploadpdf_mysql4>
43
+ <class>Ifuturz_Uploadpdf_Model_Mysql4</class>
44
+ <entities>
45
+ <uploadpdf>
46
+ <table>ifuturz_uploadpdf</table>
47
+ </uploadpdf>
48
+ </entities>
49
+ </uploadpdf_mysql4>
50
+ </models>
51
+ <resources>
52
+ <uploadpdf_setup>
53
+ <setup>
54
+ <module>Ifuturz_Uploadpdf</module>
55
+ </setup>
56
+ <connection>
57
+ <use>core_setup</use>
58
+ </connection>
59
+ </uploadpdf_setup>
60
+ <uploadpdf_write>
61
+ <connection>
62
+ <use>core_write</use>
63
+ </connection>
64
+ </uploadpdf_write>
65
+ <uploadpdf_read>
66
+ <connection>
67
+ <use>core_read</use>
68
+ </connection>
69
+ </uploadpdf_read>
70
+ </resources>
71
+
72
+ <helpers>
73
+ <uploadpdf>
74
+ <class>Ifuturz_Uploadpdf_Helper</class>
75
+ </uploadpdf>
76
+ </helpers>
77
+ </global>
78
+ <adminhtml>
79
+ <layout>
80
+ <updates>
81
+ <uploadpdf>
82
+ <file>uploadpdf.xml</file>
83
+ </uploadpdf>
84
+ </updates>
85
+ </layout>
86
+ <events>
87
+ <catalog_product_save_after>
88
+ <observers>
89
+ <ifuturz_save_product_data9>
90
+ <type>singleton</type>
91
+ <class>uploadpdf/observer</class>
92
+ <method>saveProductTabData</method>
93
+ </ifuturz_save_product_data9>
94
+ </observers>
95
+ </catalog_product_save_after>
96
+ </events>
97
+ </adminhtml>
98
+ </config>
app/code/local/Ifuturz/Uploadpdf/sql/uploadpdf_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ $installer->startSetup();
5
+
6
+
7
+ $installer->run("
8
+
9
+ -- DROP TABLE IF EXISTS {$this->getTable('ifuturz_uploadpdf')};
10
+ CREATE TABLE {$this->getTable('ifuturz_uploadpdf')} (
11
+ `pdf_id` int(11) unsigned NOT NULL auto_increment,
12
+ `product_id` int(11) NULL,
13
+ `pdf_file` varchar(500) NULL,
14
+ `pdfname` varchar(500) NULL,
15
+ `pdf_path` varchar(500) NULL,
16
+ PRIMARY KEY (`pdf_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+ ");
19
+
20
+ $installer->endSetup();
21
+
app/design/adminhtml/default/default/template/uploadpdf/catalog/product/tab/uploadpdf.phtml ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $get_editid = $_GET['editid']; ?>
2
+
3
+ <style type="text/css">
4
+ .uploadpdf-list td.label {
5
+ background: none repeat scroll 0 center transparent !important;
6
+ border: 0 none !important;
7
+ padding-bottom: 5px !important;
8
+ padding-left: 5px !important;
9
+ padding-top: 5px !important;
10
+ }
11
+ .tdf:hover
12
+ {
13
+ background-color:#F5EEDF;
14
+ }
15
+ </style>
16
+
17
+ <div style="" id="product_info_tabs_group_4_content">
18
+ <div class="entry-edit">
19
+ <div class="entry-edit-head">
20
+ <h4 class="icon-head head-edit-form fieldset-legend">
21
+
22
+ <?php if($get_editid == '') { ?>
23
+ Upload PDF
24
+ <?php } else { ?>
25
+ Edit PDF (ID: <?php echo $get_editid; ?>)
26
+ <?php } ?>
27
+
28
+ </h4>
29
+ </div>
30
+ <div id="group_fields4" class="fieldset fieldset-wide">
31
+ <div class="hor-scroll">
32
+ <table cellspacing="0" class="uploadpdf-list">
33
+ <tbody>
34
+
35
+ <?php
36
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
37
+ $cpid=Mage::registry('current_product')->getId();
38
+ $readresult=$write->query("SELECT pdfname,pdf_file from ifuturz_uploadpdf WHERE pdf_id = '$get_editid'");
39
+ $result = $readresult->fetchAll();
40
+ $pdfname = $result[0]['pdfname'];
41
+ $pdffile = $result[0]['pdf_file'];
42
+ ?>
43
+ <?php if($get_editid != '') { ?>
44
+
45
+ <tr>
46
+ <td class="label" colspan="2">
47
+ <a href="?editid=">Upload New PDF</a>
48
+ </td>
49
+ </tr>
50
+
51
+ <tr>
52
+ <td class="label"><label for="name">ID<!--<span class="required">*</span>--></label></td>
53
+ <td class="value"><b><?php echo $get_editid ?></b></td>
54
+ </tr>
55
+
56
+ <?php } ?>
57
+ <tr>
58
+ <td class="label" width="100px"><label for="name">PDF Name<!--<span class="required">*</span>--></label></td>
59
+ <td class="value"><input type="text" value="<?php echo $pdfname ?>" name="pdf_name" id="pdf_name"></td>
60
+ </tr>
61
+ <tr>
62
+ <td class="label" width="100px"><label for="name">Upload PDF File <!--<span class="required">*</span>--></label></td>
63
+ <td class="value">
64
+ <input type="file" value="" name="upload_pdf" id="Upload pdf file">&nbsp;&nbsp;<?php echo $pdffile; ?>
65
+ </td>
66
+ </tr>
67
+ </tbody>
68
+ </table>
69
+ </div>
70
+ </div>
71
+ </div>
72
+ </div>
73
+
74
+ <div class="entry-edit">
75
+ <div class="entry-edit-head">
76
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('uploadpdf')->__('Manage PDF(s)') ?></h4>
77
+ </div>
78
+ <fieldset style="padding:0px">
79
+ <table cellspacing="0" border = "0" class="uploadpdf-list" id="table_color" style="width:100%">
80
+ <tr bgcolor="#EFE6E6">
81
+ <td class="label" width="60px"><b>ID</b></td>
82
+ <td class="label"><b>PDF Name</b></td>
83
+ <td class="label"><b>PDF File</b></td>
84
+ <td class="label"><b>Action</b></td>
85
+ <td class="label" width="60px"><b>Remove</b></td>
86
+ </tr>
87
+ <?php
88
+ // echo "SELECT pdfname from ifuturz_uploadpdf WHERE product_id='$cpid'";
89
+ $readresult=$write->query("SELECT * from ifuturz_uploadpdf WHERE product_id='$cpid'");
90
+ $result = $readresult->fetchAll();
91
+ $cnt_updf = count($result);
92
+ //echo "<pre>";print_r($result);
93
+ $up = 1;
94
+ if($cnt_updf > 0)
95
+ {
96
+ foreach($result as $col){
97
+ //echo $col['pdf_id'];
98
+ if($up%2==0) {
99
+ ?>
100
+ <tr bgcolor="#F6F6F6" class="tdf">
101
+ <?php } else { ?>
102
+ <tr bgcolor="#FFFFFF" class="tdf">
103
+ <?php } ?>
104
+ <td class="label"><?php echo $col['pdf_id']; ?></td>
105
+ <td class="label"><?php echo $col['pdfname']; ?></td>
106
+ <td class="label"><?php echo $col['pdf_file'];?></td>
107
+ <td class="label">
108
+ <a href="?editid=<?php echo $col['pdf_id']; ?>" title="Edit (ID: <?php echo $col['pdf_id']; ?>)">
109
+ Edit
110
+ </a>
111
+ </td>
112
+ <td class="label">
113
+ <input type="checkbox" class="testdelete" name = "chkdelete[]" title="Delete (ID: <?php echo $col['pdf_id']; ?>)" value = "<?php echo $col['pdf_id']; ?>" />
114
+ </td>
115
+ </tr>
116
+
117
+ <?php
118
+ $up++;
119
+ }
120
+ } else { ?>
121
+
122
+ <tr>
123
+ <td class="label" colspan="3">No PDF uploaded.</td>
124
+ </tr>
125
+
126
+ <?php } ?>
127
+
128
+ <input type="hidden" name="colorid" id="colorid" >
129
+ </table>
130
+ </fieldset>
131
+ </div>
app/design/frontend/base/default/layout/uploadpdf.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <layout version="0.1.0">
3
+ <catalog_product_view>
4
+ <reference name="product.info.extrahint">
5
+ <block type="core/template" as="uploadpdfAs" template="uploadpdf/uploadpdf.phtml" />
6
+ </reference>
7
+ </catalog_product_view>
8
+ </layout>
9
+
10
+
11
+
app/design/frontend/base/default/template/uploadpdf/uploadpdf.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $current_product = Mage::registry('current_product');
3
+ $productid = $current_product->getEntityId();
4
+
5
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
6
+ //echo "SELECT * from ifuturz_uploadpdf WHERE product_id='$pid' ";
7
+ $readresult=$write->query("SELECT * from ifuturz_uploadpdf WHERE product_id='$productid' ");
8
+ $entityid = $readresult->fetchAll();
9
+ //echo "<pre>";print_r($entityid);
10
+ $eid = $entityid[0]['pdf_file'];
11
+ if($eid!='')
12
+ {
13
+ ?>
14
+ <div class="collateral-box">
15
+ <div class="head">
16
+ <h4><?php echo $this->__('PDF Downloads') ?></h4>
17
+ </div>
18
+ </div>
19
+ <?php
20
+
21
+ for($i=0; $i<count($entityid) ;$i++)
22
+ {
23
+ //echo Mage::getBaseUrl('media')."pdffiles/uploadedfiles/".$entityid[$i]['pdf_path'];
24
+ $front = $entityid[$i]['pdf_file'];
25
+ $pdfnm = $entityid[$i]['pdfname'];
26
+ //$pdfnew = explode('/',$pdf);
27
+ //$pdfexp = $pdfnew[8];
28
+ //$pdffinal = str_replace('.pdf','',$pdfexp);
29
+
30
+ if($pdfnm == "")
31
+ {
32
+ $ext = explode(".", $front);
33
+ echo '<li style="font-family: verdana;margin-bottom: 15px;margin-left: 10px;"><a target="_blank" href="'.$entityid[$i]['pdf_path'].'">'.$ext[0].'</a><br /></li>';
34
+ }
35
+ else
36
+ {
37
+ echo '<li style="font-family: verdana;margin-bottom: 15px;margin-left: 10px;"><a target="_blank" href="'.$entityid[$i]['pdf_path'].'">'.$pdfnm.'</a><br /></li>';
38
+ }
39
+ }
40
+ }
41
+ //echo "<pre>"; print_r($entityid);
42
+ ?>
app/etc/modules/Ifuturz_Uploadpdf.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <modules>
4
+ <Ifuturz_Uploadpdf>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Ifuturz_Uploadpdf>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Ifuturz_Uploadpdf</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Customer can upload the multiple pdf for one single product from product page in admin panel and on frontend that uploaded pdf will be shown.</summary>
10
+ <description>&#x2022; Admin can upload pdf from admin panel. Make one custom tab in catalog -&gt; Manage products-&gt; Edit product page and give name it to &#x201C;Upload PDF&#x201D;.&#xD;
11
+ &#x2022; On product edit page admin can upload more than one PDF for specific one product.&#xD;
12
+ &#x2022; Admin can add/update/delete the pdf from admin panel on product edit page. There must be a listing of uploaded pdf so admin can have idea of how many pdfs are uploaded for one particular product.&#xD;
13
+ &#x2022; The uploaded pdf must be shown on product page on front end so customer can see the uploaded pdfs for particular product.</description>
14
+ <notes>First Upload PDF Extension</notes>
15
+ <authors><author><name>Iverve</name><user>iverve</user><email>extension.geek@ifuturz.com</email></author></authors>
16
+ <date>2014-01-09</date>
17
+ <time>06:38:43</time>
18
+ <contents><target name="magelocal"><dir name="Ifuturz"><dir name="Uploadpdf"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><file name="Form.php" hash="da851444cc8a8d054c1fa061b23be63b"/><dir name="Tab"><file name="Uploadpdf.php" hash="29d2e39637ebcc96a530840cf9ba80c7"/></dir><file name="Tabs.php" hash="2d0244615617397f671a327d719aba4a"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="7da275b559a1d56075d4839559ea3903"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Uploadpdf"><file name="Collection.php" hash="a43f5a17243d9c11c8cef06fac2edfef"/></dir><file name="Uploadpdf.php" hash="745f41fbf6c53f262d217eab67ab8e06"/></dir><file name="Observer.php" hash="dcf857ed6c5889d40aa52873e82f0507"/><file name="Uploadpdf.php" hash="be43a3fbf5f88d4cc1434ef80856c0cd"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="UploadpdfController.php" hash="45ac98d3dc6b6ec842da6c3386e01c49"/></dir><file name="IndexController.php" hash="721a4c0c77fbd5df29cfda3f3f2708c8"/></dir><dir name="etc"><file name="config.xml" hash="c97a8f860c19fd9d825de744219ce57a"/></dir><dir name="sql"><dir name="uploadpdf_setup"><file name="mysql4-install-0.1.0.php" hash="cb847f803de84f1dde7c99335b7b501d"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="uploadpdf"><dir name="catalog"><dir name="product"><dir name="tab"><file name="uploadpdf.phtml" hash="bc114f89e585bc0a70f8ed8c2da2b2cf"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="uploadpdf.xml" hash="e1e4382f9123e8cf82bbc6497507327a"/></dir><dir name="template"><dir name="uploadpdf"><file name="uploadpdf.phtml" hash="ba5d09594094f774dcca14e176fb51fa"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ifuturz_Uploadpdf.xml" hash="4bf0cf4a78783360d83d36d82efc0c1c"/></dir></target></contents>
19
+ <compatible/>
20
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
21
+ </package>