Medma_Background_Setting - Version 1.0.0

Version Notes

This is a stable version

Download this release

Release Info

Developer Medma Infomatix
Extension Medma_Background_Setting
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (22) hide show
  1. app/code/local/Medma/Background/Block/Adminhtml/Background.php +13 -0
  2. app/code/local/Medma/Background/Block/Adminhtml/Background/Edit.php +23 -0
  3. app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Form.php +95 -0
  4. app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Form.php~ +104 -0
  5. app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Tab/Form.php +18 -0
  6. app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Tabs.php +25 -0
  7. app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Tabs.php~ +24 -0
  8. app/code/local/Medma/Background/Block/Adminhtml/Background/Grid.php +66 -0
  9. app/code/local/Medma/Background/Block/Adminhtml/Background/Renderer/Getimage.php +0 -0
  10. app/code/local/Medma/Background/Block/Adminhtml/Background/Renderer/Productimage.php +10 -0
  11. app/code/local/Medma/Background/Helper/Data.php +6 -0
  12. app/code/local/Medma/Background/Model/Background.php +10 -0
  13. app/code/local/Medma/Background/Model/Mysql4/Background.php +8 -0
  14. app/code/local/Medma/Background/Model/Mysql4/Background/Collection.php +10 -0
  15. app/code/local/Medma/Background/controllers/Adminhtml/BackgroundController.php +133 -0
  16. app/code/local/Medma/Background/etc/config.xml +107 -0
  17. app/code/local/Medma/Background/sql/background_setup/mysql4-install-0.1.0.php +27 -0
  18. app/design/frontend/default/default/layout/background.xml +14 -0
  19. app/design/frontend/default/default/template/background/background.phtml +33 -0
  20. app/design/frontend/default/default/template/background/background.phtml~ +33 -0
  21. app/etc/modules/Medma_Background.xml +9 -0
  22. package.xml +19 -0
app/code/local/Medma/Background/Block/Adminhtml/Background.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Block_Adminhtml_Background extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->_controller = 'adminhtml_background';
8
+ $this->_blockGroup = 'background';
9
+ $this->_headerText = Mage::helper('background')->__('Manage Background');
10
+ $this->_removeButton('add');
11
+ $this->_removeButton('task');
12
+ }
13
+ }
app/code/local/Medma/Background/Block/Adminhtml/Background/Edit.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Block_Adminhtml_Background_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->_removeButton('add');
8
+ $this->_objectId = 'id';
9
+ $this->_blockGroup = 'background';
10
+ $this->_controller = 'adminhtml_background';
11
+ $this->_removeButton('delete');
12
+ $this->_removeButton('reset');
13
+ }
14
+
15
+ public function getHeaderText()
16
+ {
17
+ if( Mage::registry('background_data') && Mage::registry('background_data')->getId() ) {
18
+ return Mage::helper('background')->__("Change Background");
19
+ } else {
20
+ return Mage::helper('background')->__('Add Background');
21
+ }
22
+ }
23
+ }
app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Form.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Block_Adminhtml_Background_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
3
+ {
4
+ protected function _prepareForm()
5
+ {
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
+ $form->setUseContainer(true);
15
+ $this->setForm($form);
16
+ $hlp = Mage::helper('background');
17
+
18
+ /*******************Code to get values from table*********************/
19
+
20
+ $get_key = Mage::getSingleton('adminhtml/url')->getSecretKey("adminhtml_background","getSellerImages");
21
+ $home_url = Mage::helper('core/url')->getHomeUrl();
22
+
23
+ $id = Mage::registry('background_data')->getId();
24
+ $imgPath = Mage::getBaseUrl("media");
25
+ $background_data = Mage::registry('background_data')->getData();
26
+
27
+ $getBestsellerProduct = Mage::getModel('background/background')->getCollection()->addFieldToFilter('background_id',array('eq'=>$id))->getData();
28
+
29
+ /*******************Code to get values from table*********************/
30
+
31
+ $fldInfo = $form->addFieldset('background_info', array('legend'=> $hlp->__('Background Details')));
32
+
33
+ $fldInfo->addField('status', 'select', array(
34
+ 'label' => $hlp->__('Status'),
35
+ 'required' => true,
36
+ 'name' => 'status',
37
+ 'values' => array(
38
+ array(
39
+ 'value' => 1,
40
+ 'label' => $hlp->__('Enabled'),
41
+ ),
42
+ array(
43
+ 'value' => 0,
44
+ 'label' => $hlp->__('Disabled'),
45
+ ),
46
+ ),
47
+ ));
48
+
49
+ $fldInfo->addField('options', 'select', array(
50
+ 'label' => $hlp->__('Background Option'),
51
+ 'required' => true,
52
+ 'name' => 'options',
53
+ 'values' => array(
54
+ array(
55
+ 'value' => 1,
56
+ 'label' => $hlp->__('Color'),
57
+ ),
58
+ array(
59
+ 'value' => 0,
60
+ 'label' => $hlp->__('Image'),
61
+ ),
62
+ ),
63
+ ));
64
+ //----------------Code show uploaded image and specify if class is Requried or Not---------------//
65
+ $object = Mage::getModel('background/background')->load($this->getRequest()->getParam('id'));
66
+ $image = false;
67
+ if($object->getImageValue()){
68
+ $image = '<img style="width:120px; height:120px;" src="'.$object->getImageValue().'" title="'.$object->getImageValue().'" align="center"/>';
69
+ }
70
+
71
+ $note = $hlp->__('Image must be 131x36 dimensions');
72
+
73
+ $fldInfo->addField('image_value', 'file', array(
74
+ 'label' => $hlp->__('Background Image'),
75
+ 'note' => $note,
76
+ 'after_element_html' => $image,
77
+ 'name' => 'image_value',
78
+
79
+ ));
80
+
81
+ $fldInfo->addField('color_value', 'text', array(
82
+ 'label' => $hlp->__('Background Color'),
83
+ 'name' => 'color_value',
84
+
85
+ ));
86
+ //----------------------------End of Code----------------------------//
87
+
88
+ if ( Mage::registry('background_data') ) {
89
+ $form->setValues(Mage::registry('background_data')->getData());
90
+ }
91
+
92
+ return parent::_prepareForm();
93
+ }
94
+ }
95
+ ?>
app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Form.php~ ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Block_Adminhtml_Background_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
3
+ {
4
+ protected function _prepareForm()
5
+ {
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
+ $form->setUseContainer(true);
15
+ $this->setForm($form);
16
+ $hlp = Mage::helper('background');
17
+
18
+ /*******************Code to get values from table*********************/
19
+
20
+ $get_key = Mage::getSingleton('adminhtml/url')->getSecretKey("adminhtml_background","getSellerImages");
21
+ $home_url = Mage::helper('core/url')->getHomeUrl();
22
+
23
+ $id = Mage::registry('background_data')->getId();
24
+ $imgPath = Mage::getBaseUrl("media");
25
+ $background_data = Mage::registry('background_data')->getData();
26
+
27
+ $getBestsellerProduct = Mage::getModel('background/background')->getCollection()->addFieldToFilter('background_id',array('eq'=>$id))->getData();
28
+
29
+ /*******************Code to get values from table*********************/
30
+
31
+ $fldInfo = $form->addFieldset('background_info', array('legend'=> $hlp->__('Background Details')));
32
+
33
+ $fldInfo->addField('status', 'select', array(
34
+ 'label' => $hlp->__('Status'),
35
+ 'required' => true,
36
+ 'name' => 'status',
37
+ 'values' => array(
38
+ array(
39
+ 'value' => 1,
40
+ 'label' => $hlp->__('Enabled'),
41
+ ),
42
+ array(
43
+ 'value' => 0,
44
+ 'label' => $hlp->__('Disabled'),
45
+ ),
46
+ ),
47
+ ));
48
+ $fldInfo->addField('store_id', 'select', array(
49
+ 'label' => $hlp->__('Store View'),
50
+ 'class' => 'required-entry',
51
+ 'required' => true,
52
+ 'name' => 'store_id',
53
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm()
54
+ ));
55
+
56
+ $fldInfo->addField('option', 'select', array(
57
+ 'label' => $hlp->__('Background Option'),
58
+ 'required' => true,
59
+ 'name' => 'status',
60
+ 'values' => array(
61
+ array(
62
+ 'value' => 1,
63
+ 'label' => $hlp->__('Color'),
64
+ ),
65
+ array(
66
+ 'value' => 0,
67
+ 'label' => $hlp->__('Image'),
68
+ ),
69
+ ),
70
+ ));
71
+ //----------------Code show uploaded image and specify if class is Requried or Not---------------//
72
+ $object = Mage::getModel('background/background')->load($this->getRequest()->getParam('id'));
73
+ $image = false;
74
+ if($object->getImageValue()){
75
+ $image = '<img style="width:120px; height:120px;" src="'.$object->getImageValue().'" title="'.$object->getImageValue().'" align="center"/>';
76
+ }
77
+
78
+ $note = $hlp->__('Image must be 131x36 dimensions');
79
+
80
+ $fldInfo->addField('image_value', 'file', array(
81
+ 'label' => $hlp->__('Background Image'),
82
+ 'note' => $note,
83
+ 'after_element_html' => $image,
84
+ 'name' => 'image_value',
85
+ // 'class' => (($object->getImageValue()) ? '' : 'required-entry'),
86
+ // 'required' => (($object->getImageValue()) ? false : true),
87
+ ));
88
+
89
+ $fldInfo->addField('color_value', 'text', array(
90
+ 'label' => $hlp->__('Background Color'),
91
+ 'name' => 'color_value',
92
+ // 'class' => (($object->getImageValue()) ? '' : 'required-entry'),
93
+ // 'required' => (($object->getImageValue()) ? false : true),
94
+ ));
95
+ //----------------------------End of Code----------------------------//
96
+
97
+ if ( Mage::registry('background_data') ) {
98
+ $form->setValues(Mage::registry('background_data')->getData());
99
+ }
100
+
101
+ return parent::_prepareForm();
102
+ }
103
+ }
104
+ ?>
app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Tab/Form.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Medma_Background_Block_Adminhtml_Background_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $this->setForm($form);
9
+ $fieldset = $form->addFieldset('background_info', array('legend'=>Mage::helper('background')->__('Module information')));
10
+ $tempArray = array(
11
+ 'label' => Mage::helper('background')->__('Sample Work'),
12
+ 'name' => 'image_value',
13
+ 'style' => 'display:none;',
14
+ );
15
+ $fieldset->addField('image_value', 'thumbnail',$tempArray);
16
+ }
17
+ }
18
+ ?>
app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Tabs.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Medma_Background_Block_Adminhtml_Background_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+
10
+ $this->setId('background_tabs');
11
+ $this->setDestElementId('edit_form');
12
+ $this->setTitle(Mage::helper('background')->__('Manage Backgrounds'));
13
+ $this->_removeButton('delete');
14
+ }
15
+
16
+ protected function _beforeToHtml()
17
+ {
18
+ $this->addTab('form_section', array(
19
+ 'label' => Mage::helper('background')->__('Item Information'),
20
+ 'title' => Mage::helper('background')->__('Item Information'),
21
+ 'content' => $this->getLayout()->createBlock('background/adminhtml_background_edit_tab_form')->toHtml(),
22
+ ));
23
+ return parent::_beforeToHtml();
24
+ }
25
+ }
app/code/local/Medma/Background/Block/Adminhtml/Background/Edit/Tabs.php~ ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Medma_Background_Block_Adminhtml_Background_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->_removeButton('add');
10
+ $this->setId('background_tabs');
11
+ $this->setDestElementId('edit_form');
12
+ $this->setTitle(Mage::helper('background')->__('Manage Backgrounds'));
13
+ }
14
+
15
+ protected function _beforeToHtml()
16
+ {
17
+ $this->addTab('form_section', array(
18
+ 'label' => Mage::helper('background')->__('Item Information'),
19
+ 'title' => Mage::helper('background')->__('Item Information'),
20
+ 'content' => $this->getLayout()->createBlock('background/adminhtml_background_edit_tab_form')->toHtml(),
21
+ ));
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/local/Medma/Background/Block/Adminhtml/Background/Grid.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Adjustware
4
+ */
5
+ class Medma_Background_Block_Adminhtml_Background_Grid extends Mage_Adminhtml_Block_Widget_Grid
6
+ {
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setId('backgroundGrid');
11
+
12
+
13
+ }
14
+
15
+ protected function _prepareCollection()
16
+ {
17
+ $collection = Mage::getModel('background/background')->getCollection();
18
+
19
+
20
+ // Most Important Line for printing the above query
21
+ //$collection->printlogquery(true);
22
+ // exit(0);
23
+ //Most Important Line for printing the above query
24
+ $this->setCollection($collection);
25
+ return parent::_prepareCollection();
26
+ }
27
+
28
+ protected function _prepareColumns()
29
+ {
30
+ $hlp = Mage::helper('background');
31
+
32
+ $this->addColumn('status', array(
33
+ 'header' => $hlp->__('Status'),
34
+ 'index' => 'status',
35
+ 'type' => 'options',
36
+ 'width' => '25px',
37
+ 'filter' => false,
38
+ 'options' => array(
39
+ 1 => 'Enabled',
40
+ 0 => 'Disabled',
41
+ ),
42
+ ));
43
+ $this->addColumn('options', array(
44
+ 'header' => $hlp->__('BG Option'),
45
+ 'index' => 'options',
46
+ 'type' => 'options',
47
+ 'width' => '25px',
48
+ 'filter' => false,
49
+ 'options' => array(
50
+ 1 => 'Color',
51
+ 0 => 'Image',
52
+ ),
53
+ ));
54
+ return parent::_prepareColumns();
55
+ }
56
+
57
+ public function getRowUrl($row)
58
+ {
59
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
60
+ }
61
+
62
+ public function getMainButtonsHtml()
63
+ {
64
+ return '';
65
+ }
66
+ }
app/code/local/Medma/Background/Block/Adminhtml/Background/Renderer/Getimage.php ADDED
File without changes
app/code/local/Medma/Background/Block/Adminhtml/Background/Renderer/Productimage.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Block_Adminhtml_Background_Renderer_Productimage extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
3
+ public function render(Varien_Object $row) {
4
+ return ($this->_getImage($row));
5
+ }
6
+ protected function _getImage(Varien_Object $row) {
7
+ $img = $row->getImageValue() != '' ? '<img width="131" height="36" src="'.$row->getImageValue().'" alt="" />' : '';
8
+ return $img;
9
+ }
10
+ }
app/code/local/Medma/Background/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
6
+ ?>
app/code/local/Medma/Background/Model/Background.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Model_Background extends Mage_Core_Model_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('background/background');
8
+ }
9
+ }
10
+ ?>
app/code/local/Medma/Background/Model/Mysql4/Background.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Model_Mysql4_Background extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ $this->_init('background/background', 'background_id');
7
+ }
8
+ }
app/code/local/Medma/Background/Model/Mysql4/Background/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Model_Mysql4_Background_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
3
+ {
4
+ public function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->_init('background/background');
8
+ }
9
+
10
+ }
app/code/local/Medma/Background/controllers/Adminhtml/BackgroundController.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Medma_Background_Adminhtml_BackgroundController extends Mage_Adminhtml_Controller_action
3
+ {
4
+ public function indexAction() {
5
+ $this->loadLayout();
6
+ $this->_setActiveMenu('catalog/background/background');
7
+ $this->_addBreadcrumb($this->__('Manage Page Backgrounds'), $this->__('Background'));
8
+ $this->_addContent($this->getLayout()->createBlock('background/adminhtml_background'));
9
+ $this->renderLayout();
10
+ }
11
+
12
+ public function editAction() {
13
+ $id = $this->getRequest()->getParam('id');
14
+ $model = Mage::getModel('background/background')->load($id);
15
+
16
+ if ($model->getId() || $id == 0) {
17
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
18
+ if (!empty($data)) {
19
+ $model->setData($data);
20
+ }
21
+
22
+ Mage::register('background_data', $model);
23
+
24
+ $this->loadLayout();
25
+ $this->_setActiveMenu('catalog/background/background');
26
+
27
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
28
+
29
+ $this->_addContent($this->getLayout()->createBlock('background/adminhtml_background_edit'));
30
+
31
+ $this->renderLayout();
32
+ } else {
33
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('background')->__('Item does not exist'));
34
+ $this->_redirect('*/*/');
35
+ }
36
+ }
37
+
38
+ public function newAction() {
39
+ $this->editAction();
40
+ }
41
+
42
+ public function saveAction() {
43
+ $id = $this->getRequest()->getParam('id');
44
+ $model = Mage::getModel('background/background');
45
+ if ($data = $this->getRequest()->getPost()) {
46
+ if(isset($_FILES['image_value']['name']) and (file_exists($_FILES['image_value']['tmp_name']))) {
47
+ try {
48
+ $uploader = new Varien_File_Uploader('image_value');
49
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); // or pdf or anything
50
+ $uploader->setAllowRenameFiles(false);
51
+ // setAllowRenameFiles(true) -> move your file in a folder the magento way
52
+ // setAllowRenameFiles(true) -> move your file directly in the $path folder
53
+ $uploader->setFilesDispersion(false);
54
+ $path = Mage::getBaseDir('media') . DS ;
55
+ $uploader->save($path, $_FILES['image_value']['name']);
56
+ $mediaUrl = Mage::getBaseUrl('media');
57
+ $data['image_value'] = $mediaUrl.$_FILES['image_value']['name'];
58
+ }catch(Exception $e) {}
59
+ }else {
60
+ $get_data_for_image = $model->load($id);
61
+ $img = $get_data_for_image->getImageValue();
62
+ $data['image_value'] = $img;
63
+ }
64
+ $model->setData($data)->setId($id);
65
+ try{
66
+ $model->save();
67
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('background')->__('Background has been successfully saved'));
68
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
69
+ $this->_redirect('*/*/');
70
+ return;
71
+ } catch (Exception $e) {
72
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
73
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
74
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
75
+ return;
76
+ }
77
+ }
78
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('background')->__('Unable to find item to save'));
79
+ $this->_redirect('*/*/');
80
+ }
81
+
82
+ public function massDeleteAction()
83
+ {
84
+ $ids = $this->getRequest()->getParam('background');
85
+ if(!is_array($ids)) {
86
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('background')->__('Please select Background Image(s)'));
87
+ } else {
88
+ try {
89
+ foreach ($ids as $id) {
90
+ $model = Mage::getModel('background/background')->load($id);
91
+ $path = Mage::getBaseDir('media') . DS ;
92
+ unlink($path.$model['image_value']);
93
+ $model->delete();
94
+ }
95
+ Mage::getSingleton('adminhtml/session')->addSuccess(
96
+ Mage::helper('adminhtml')->__(
97
+ 'Total of %d record(s) were successfully deleted', count($ids)
98
+ )
99
+ );
100
+ } catch (Exception $e) {
101
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
102
+ }
103
+ }
104
+ $this->_redirect('*/*/');
105
+ }
106
+
107
+ public function deleteAction() {
108
+ if( $this->getRequest()->getParam('id') > 0 ) {
109
+ try {
110
+ $model = Mage::getModel('background/background')->load($this->getRequest()->getParam('id'));
111
+ $path = Mage::getBaseDir('media') . DS ;
112
+ //$path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
113
+ unlink($path.$model['image_value']);
114
+ $model->delete();
115
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('background')->__('Background has been deleted'));
116
+ $this->_redirect('*/*/');
117
+ } catch (Exception $e) {
118
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
119
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
120
+ }
121
+ }
122
+ $this->_redirect('*/*/');
123
+ }
124
+
125
+ public function getSellerImagesAction() {
126
+ $pramas = $this->getRequest()->getParams();
127
+ if(Mage::getModel('background/background')->getCollection()->addFieldToFilter('background_id', $pramas['backgroundId'])->addFieldToSelect('image_value')->getData()) {
128
+ $sellerProduct = Mage::getModel('background/background')->getCollection()->addFieldToFilter('background_id', $pramas['backgroundId'])->addFieldToSelect('image_value')->getData();
129
+ $_background_image = $sellerProduct[0]['image_value'];
130
+ }
131
+ echo Mage::getBaseUrl('media').'catalog/product'.$_background_image;
132
+ }
133
+ }
app/code/local/Medma/Background/etc/config.xml ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Medma_Background>
5
+ <version>0.1.0</version>
6
+ </Medma_Background>
7
+ </modules>
8
+ <frontend>
9
+ <layout>
10
+ <updates>
11
+ <background>
12
+ <file>background.xml</file>
13
+ </background>
14
+ </updates>
15
+ </layout>
16
+ </frontend>
17
+ <admin>
18
+ <routers>
19
+ <background>
20
+ <use>admin</use>
21
+ <args>
22
+ <module>Medma_Background</module>
23
+ <frontName>background</frontName>
24
+ </args>
25
+ </background>
26
+ </routers>
27
+ </admin>
28
+ <adminhtml>
29
+ <menu>
30
+
31
+ <background translate="title" module="background">
32
+ <title>Background Image</title>
33
+ <sort_order>1600</sort_order>
34
+ <children>
35
+ <background translate="title" module="background">
36
+ <title>Manage BG Images</title>
37
+ <action>background/adminhtml_background</action>
38
+ </background>
39
+ </children>
40
+ </background>
41
+
42
+ </menu>
43
+ <acl>
44
+ <resources>
45
+ <admin>
46
+ <children>
47
+ <system>
48
+ <children>
49
+ <background translate="title">
50
+ <title>background</title>
51
+ <sort_order>1600</sort_order>
52
+ </background>
53
+ </children>
54
+ </system>
55
+ </children>
56
+ </admin>
57
+ </resources>
58
+ </acl>
59
+ </adminhtml>
60
+ <global>
61
+ <models>
62
+ <background>
63
+ <class>Medma_Background_Model</class>
64
+ <resourceModel>background_mysql4</resourceModel>
65
+ </background>
66
+ <background_mysql4>
67
+ <class>Medma_Background_Model_Mysql4</class>
68
+ <entities>
69
+ <background>
70
+ <table>background_info</table>
71
+ </background>
72
+ </entities>
73
+ </background_mysql4>
74
+ </models>
75
+ <resources>
76
+ <background_setup>
77
+ <setup>
78
+ <module>Medma_Background</module>
79
+ </setup>
80
+ <connection>
81
+ <use>core_setup</use>
82
+ </connection>
83
+ </background_setup>
84
+ <background_write>
85
+ <connection>
86
+ <use>core_write</use>
87
+ </connection>
88
+ </background_write>
89
+ <background_read>
90
+ <connection>
91
+ <use>core_read</use>
92
+ </connection>
93
+ </background_read>
94
+ </resources>
95
+ <blocks>
96
+ <background>
97
+ <class>Medma_Background_Block</class>
98
+ </background>
99
+ </blocks>
100
+ <helpers>
101
+ <background>
102
+ <class>Medma_Background_Helper</class>
103
+ </background>
104
+ </helpers>
105
+ </global>
106
+
107
+ </config>
app/code/local/Medma/Background/sql/background_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // echo 'Running This Upgrade: '.get_class($this)."\n <br /> \n";
3
+ //die("Exit for now");
4
+ $installer = $this;
5
+ $installer->startSetup();
6
+ $installer->run("
7
+
8
+ -- DROP TABLE IF EXISTS {$installer->getTable('background_info')};
9
+ CREATE TABLE {$installer->getTable('background_info')} (
10
+ `background_id` int(10) NOT NULL AUTO_INCREMENT,
11
+ `store_id` int(10) DEFAULT NULL,
12
+ `status` int(10) DEFAULT NULL,
13
+ `options` int(10) DEFAULT NULL,
14
+ `image_value` varchar(255) default NULL,
15
+ `color_value` varchar(255) default NULL,
16
+ PRIMARY KEY (`background_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+ ");
20
+ $installer->run("
21
+ INSERT INTO {$installer->getTable('background_info')} (background_id ,status ,options ,image_value ,color_value)
22
+ VALUES ('' , '1', '1', NULL , '#fff');
23
+ ");
24
+
25
+
26
+ $installer->endSetup();
27
+ ?>
app/design/frontend/default/default/layout/background.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="head">
5
+ <block type="core/text" name="google.cdn.jquery">
6
+ <action method="setText">
7
+ <text><![CDATA[<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript">jQuery.noConflict();</script>]]>
8
+ </text>
9
+ </action>
10
+ </block>
11
+ <block type="core/template" name="background" template="background/background.phtml" />
12
+ </reference>
13
+ </default>
14
+ </layout>
app/design/frontend/default/default/template/background/background.phtml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ $js = jQuery.noConflict();
3
+ $js(document).ready(function($js) {
4
+ changeBG();
5
+ });
6
+ function changeBG(){
7
+
8
+ <?php
9
+
10
+ $backgroundImg = Mage::getModel('background/background')->getCollection()->addFieldToFilter("status",1);
11
+ foreach($backgroundImg as $bgimg){
12
+ $bgimage=$bgimg->getImageValue();
13
+ $bgcolor=$bgimg->getColorValue();
14
+ $bgoptions=$bgimg->getOptions();
15
+ }
16
+
17
+ if($bgoptions==0){
18
+ ?>
19
+
20
+
21
+ document.getElementsByTagName("body")[0].style.backgroundImage = "url('<?php echo $bgimage; ?>')";
22
+ <?php
23
+ }
24
+ else{
25
+ ?>
26
+ document.getElementsByTagName("body")[0].style.backgroundColor = '<?php echo $bgcolor ?>';
27
+
28
+
29
+ <?php
30
+ }?>
31
+ }
32
+
33
+ </script>
app/design/frontend/default/default/template/background/background.phtml~ ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ $js = jQuery.noConflict();
3
+ $js(document).ready(function($js) {
4
+ changeBG();
5
+ });
6
+ function changeBG(){
7
+
8
+ <?php
9
+
10
+ $backgroundImg = Mage::getModel('background/background')->getCollection()->addFieldToFilter("status",1);
11
+ foreach($backgroundImg as $bgimg){
12
+ $bgimage=$bgimg->getImageValue();
13
+ $bgcolor=$bgimg->getColorValue();
14
+ $bgoptions=$bgimg->getOptions();
15
+ }
16
+
17
+ if($bgoptions==0){
18
+ s ?>
19
+
20
+
21
+ document.getElementsByTagName("body")[0].style.backgroundImage = "url('<?php echo $bgimage; ?>')";
22
+ <?php
23
+ }
24
+ else{
25
+ ?>
26
+ document.getElementsByTagName("body")[0].style.backgroundColor = '<?php echo $bgcolor ?>';
27
+
28
+
29
+ <?php
30
+ }?>
31
+ }
32
+
33
+ </script>
app/etc/modules/Medma_Background.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Medma_Background>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Medma_Background>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Medma_Background_Setting</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension manages the body background of the whole store.</summary>
10
+ <description>This extension manages the body background of the whole store. This is very useful extension for the look &amp; feel of any store.&#xD;
11
+ This extension adds the image as well as color which is to be displayed on the front-end.</description>
12
+ <notes>This is a stable version</notes>
13
+ <authors><author><name>Medma Infomatix</name><user>Medma_Infomatix</user><email>gaurav@medma.in</email></author></authors>
14
+ <date>2012-09-29</date>
15
+ <time>10:56:37</time>
16
+ <contents><target name="magelocal"><dir name="Medma"><dir name="Background"><dir name="Block"><dir name="Adminhtml"><dir name="Background"><dir name="Edit"><file name="Form.php" hash="d3b37e1e61ced49a7da4aba25f928be4"/><file name="Form.php~" hash="10cdf7b16156cc3adca5d4ff4f549123"/><dir name="Tab"><file name="Form.php" hash="295234c4b0e4810e65f1a231d9085c96"/></dir><file name="Tabs.php" hash="f265acb45bd2c140d7cf337b58dbf640"/><file name="Tabs.php~" hash="ad2951000fb9ea0bc48918710ff58cbe"/></dir><file name="Edit.php" hash="ef94ffa82c4220699475e1a96cd29598"/><file name="Grid.php" hash="8e6af9ae5b08116ff8fc9d9c051e9263"/><dir name="Renderer"><file name="Getimage.php" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="Productimage.php" hash="afd995017702088197b17a50568d85b6"/></dir></dir><file name="Background.php" hash="1650f6a519ab4bcb45450a3a28a114d6"/></dir></dir><dir name="Helper"><file name="Data.php" hash="104b4fee716ed1019915e17e014a0ddc"/></dir><dir name="Model"><file name="Background.php" hash="e2150534b535a4474d7080c3ad16eb12"/><dir name="Mysql4"><dir name="Background"><file name="Collection.php" hash="e5aaecb8993ee15a7cdaa12097a7bd20"/></dir><file name="Background.php" hash="5523cd67d5910d0ba08bbf1f900ac979"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="BackgroundController.php" hash="38ff71a561fd3a3f2b0e10dc3a3ebb36"/></dir></dir><dir name="etc"><file name="config.xml" hash="74332ac21bed8d0201bf051f76e20cc7"/></dir><dir name="sql"><dir name="background_setup"><file name="mysql4-install-0.1.0.php" hash="97966de6dfce64a8d864a6b5571f2faf"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Medma_Background.xml" hash="b3ed29016e4e2353bd6e6b214c41f441"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="background.xml" hash="f35db4541bb80eb98fed999741ef350a"/></dir><dir name="template"><dir name="background"><file name="background.phtml" hash="99998716627e37cd60111c35244ad914"/><file name="background.phtml~" hash="2498fbc3bf9160e55828f95fb146e69c"/></dir></dir></dir></dir></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>