Mage_Navadmin - Version 1.0

Version Notes

Navigation bar administration

Download this release

Release Info

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


Version 1.0

app/code/community/Mage/Navadmin/Block/Adminhtml/Navadmin.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mage_Navadmin_Block_Adminhtml_Navadmin extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->_controller = 'adminhtml_navadmin';
7
+ $this->_blockGroup = 'navadmin';
8
+ $this->_headerText = Mage::helper('navadmin')->__('Item Manager');
9
+ $this->_addButtonLabel = Mage::helper('navadmin')->__('Add Item');
10
+ parent::__construct();
11
+ }
12
+ }
app/code/community/Mage/Navadmin/Block/Adminhtml/Navadmin/Edit.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Block_Adminhtml_Navadmin_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'navadmin';
11
+ $this->_controller = 'adminhtml_navadmin';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('navadmin')->__('Save Item'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('navadmin')->__('Delete Item'));
15
+
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+
22
+ $this->_formScripts[] = "
23
+ function toggleEditor() {
24
+ if (tinyMCE.getInstanceById('navadmin_content') == null) {
25
+ tinyMCE.execCommand('mceAddControl', false, 'navadmin_content');
26
+ } else {
27
+ tinyMCE.execCommand('mceRemoveControl', false, 'navadmin_content');
28
+ }
29
+ }
30
+
31
+ function saveAndContinueEdit(){
32
+ editForm.submit($('edit_form').action+'back/edit/');
33
+ }
34
+ ";
35
+ }
36
+
37
+ public function getHeaderText()
38
+ {
39
+ if( Mage::registry('navadmin_data') && Mage::registry('navadmin_data')->getId() ) {
40
+ return Mage::helper('navadmin')->__("Edit Item '%s'", $this->htmlEscape(Mage::registry('navadmin_data')->getTitle()));
41
+ } else {
42
+ return Mage::helper('navadmin')->__('Add Item');
43
+ }
44
+ }
45
+ }
app/code/community/Mage/Navadmin/Block/Adminhtml/Navadmin/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Block_Adminhtml_Navadmin_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/community/Mage/Navadmin/Block/Adminhtml/Navadmin/Edit/Tab/Form.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Block_Adminhtml_Navadmin_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('navadmin_form', array('legend'=>Mage::helper('navadmin')->__('Item information')));
10
+
11
+ $fieldset->addField('title', 'text', array(
12
+ 'label' => Mage::helper('navadmin')->__('Label'),
13
+ 'class' => 'required-entry',
14
+ 'required' => true,
15
+ 'name' => 'title',
16
+ ));
17
+
18
+ $fieldset->addField('link', 'text', array(
19
+ 'label' => Mage::helper('navadmin')->__('Link'),
20
+ 'class' => 'required-entry',
21
+ 'required' => true,
22
+ 'name' => 'link',
23
+ ));
24
+
25
+ $fieldset->addField('target', 'select', array(
26
+ 'label' => Mage::helper('navadmin')->__('Target'),
27
+ 'name' => 'target',
28
+ 'values' => array(
29
+ array(
30
+ 'value' => 'self',
31
+ 'label' => Mage::helper('navadmin')->__('Self'),
32
+ ),
33
+
34
+ array(
35
+ 'value' => '_blank',
36
+ 'label' => Mage::helper('navadmin')->__('New window'),
37
+ ),
38
+ ),
39
+ ));
40
+
41
+ $fieldset->addField('pid', 'select', array(
42
+ 'label' => Mage::helper('navadmin')->__('Pid'),
43
+ 'name' => 'pid',
44
+ 'values' => Mage::helper('navadmin')->getSelectcat(),
45
+ ));
46
+
47
+ $fieldset->addField('position', 'text', array(
48
+ 'label' => Mage::helper('navadmin')->__('Position'),
49
+ 'required' => false,
50
+ 'name' => 'position',
51
+ ));
52
+
53
+ $fieldset->addField('status', 'select', array(
54
+ 'label' => Mage::helper('navadmin')->__('Status'),
55
+ 'name' => 'status',
56
+ 'values' => array(
57
+ array(
58
+ 'value' => 1,
59
+ 'label' => Mage::helper('navadmin')->__('Enabled'),
60
+ ),
61
+
62
+ array(
63
+ 'value' => 2,
64
+ 'label' => Mage::helper('navadmin')->__('Disabled'),
65
+ ),
66
+ ),
67
+ ));
68
+
69
+
70
+ if ( Mage::getSingleton('adminhtml/session')->getNavadminData() )
71
+ {
72
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getNavadminData());
73
+ Mage::getSingleton('adminhtml/session')->setNavadminData(null);
74
+ } elseif ( Mage::registry('navadmin_data') ) {
75
+ $form->setValues(Mage::registry('navadmin_data')->getData());
76
+ }
77
+ return parent::_prepareForm();
78
+ }
79
+ }
app/code/community/Mage/Navadmin/Block/Adminhtml/Navadmin/Edit/Tabs.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Block_Adminhtml_Navadmin_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('navadmin_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle(Mage::helper('navadmin')->__('Item Information'));
12
+ }
13
+
14
+ protected function _beforeToHtml()
15
+ {
16
+ $this->addTab('form_section', array(
17
+ 'label' => Mage::helper('navadmin')->__('Item Information'),
18
+ 'title' => Mage::helper('navadmin')->__('Item Information'),
19
+ 'content' => $this->getLayout()->createBlock('navadmin/adminhtml_navadmin_edit_tab_form')->toHtml(),
20
+ ));
21
+
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/community/Mage/Navadmin/Block/Adminhtml/Navadmin/Grid.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Block_Adminhtml_Navadmin_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('navadminGrid');
9
+ $this->setDefaultSort('navadmin_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ protected function _prepareCollection()
15
+ {
16
+ $collection = Mage::getModel('navadmin/navadmin')->getCollection();
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns()
22
+ {
23
+ $this->addColumn('navadmin_id', array(
24
+ 'header' => Mage::helper('navadmin')->__('ID'),
25
+ 'align' =>'right',
26
+ 'width' => '50px',
27
+ 'index' => 'navadmin_id',
28
+ ));
29
+
30
+ $this->addColumn('title', array(
31
+ 'header' => Mage::helper('navadmin')->__('Title'),
32
+ 'align' =>'left',
33
+ 'index' => 'title',
34
+ ));
35
+
36
+ /*
37
+ $this->addColumn('content', array(
38
+ 'header' => Mage::helper('navadmin')->__('Item Content'),
39
+ 'width' => '150px',
40
+ 'index' => 'content',
41
+ ));
42
+ */
43
+
44
+ $this->addColumn('status', array(
45
+ 'header' => Mage::helper('navadmin')->__('Status'),
46
+ 'align' => 'left',
47
+ 'width' => '80px',
48
+ 'index' => 'status',
49
+ 'type' => 'options',
50
+ 'options' => array(
51
+ 1 => 'Enabled',
52
+ 2 => 'Disabled',
53
+ ),
54
+ ));
55
+
56
+ $this->addColumn('action',
57
+ array(
58
+ 'header' => Mage::helper('navadmin')->__('Action'),
59
+ 'width' => '100',
60
+ 'type' => 'action',
61
+ 'getter' => 'getId',
62
+ 'actions' => array(
63
+ array(
64
+ 'caption' => Mage::helper('navadmin')->__('Edit'),
65
+ 'url' => array('base'=> '*/*/edit'),
66
+ 'field' => 'id'
67
+ )
68
+ ),
69
+ 'filter' => false,
70
+ 'sortable' => false,
71
+ 'index' => 'stores',
72
+ 'is_system' => true,
73
+ ));
74
+
75
+ $this->addExportType('*/*/exportCsv', Mage::helper('navadmin')->__('CSV'));
76
+ $this->addExportType('*/*/exportXml', Mage::helper('navadmin')->__('XML'));
77
+
78
+ return parent::_prepareColumns();
79
+ }
80
+
81
+ protected function _prepareMassaction()
82
+ {
83
+ $this->setMassactionIdField('navadmin_id');
84
+ $this->getMassactionBlock()->setFormFieldName('navadmin');
85
+
86
+ $this->getMassactionBlock()->addItem('delete', array(
87
+ 'label' => Mage::helper('navadmin')->__('Delete'),
88
+ 'url' => $this->getUrl('*/*/massDelete'),
89
+ 'confirm' => Mage::helper('navadmin')->__('Are you sure?')
90
+ ));
91
+
92
+ $statuses = Mage::getSingleton('navadmin/status')->getOptionArray();
93
+
94
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
95
+ $this->getMassactionBlock()->addItem('status', array(
96
+ 'label'=> Mage::helper('navadmin')->__('Change status'),
97
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
98
+ 'additional' => array(
99
+ 'visibility' => array(
100
+ 'name' => 'status',
101
+ 'type' => 'select',
102
+ 'class' => 'required-entry',
103
+ 'label' => Mage::helper('navadmin')->__('Status'),
104
+ 'values' => $statuses
105
+ )
106
+ )
107
+ ));
108
+ return $this;
109
+ }
110
+
111
+ public function getRowUrl($row)
112
+ {
113
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
114
+ }
115
+
116
+ }
app/code/community/Mage/Navadmin/Block/Navadmin.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mage_Navadmin_Block_Navadmin extends Mage_Core_Block_Template
3
+ {
4
+ public function _prepareLayout()
5
+ {
6
+ return parent::_prepareLayout();
7
+ }
8
+
9
+ public function getNavadmin()
10
+ {
11
+ if (!$this->hasData('navadmin')) {
12
+ $this->setData('navadmin', Mage::registry('navadmin'));
13
+ }
14
+ return $this->getData('navadmin');
15
+
16
+ }
17
+ }
app/code/community/Mage/Navadmin/Helper/Data.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ public function getSelectcat(){
6
+ $model = Mage::getModel('navadmin/tree');
7
+ $aux[0]['value'] = 0;
8
+ $aux[0]['label'] = 'Root';
9
+ $out = $this->drawSelect(0, $aux);
10
+ return $out;
11
+ }
12
+
13
+ public function drawSelect($pid=0, $outini=null, $sep=1){
14
+ $out = array();
15
+ if(!empty($outini)){
16
+ $out = $outini;
17
+ }
18
+
19
+ $spacer = '';
20
+ for ($i = 0; $i <= $sep; $i++){
21
+ $spacer.= '&nbsp;&nbsp;&nbsp;';
22
+ }
23
+
24
+ $items = $this->getChildrens($pid);
25
+ if(count($items) > 0 ){
26
+ foreach ($items as $item){
27
+ $aux['value'] = $item['navadmin_id'];
28
+ $aux['label'] = $spacer.$item['title'];
29
+ $out[] = $aux;
30
+ $child = $this->getChildrens($item['navadmin_id']);
31
+ if(!empty($child)){
32
+ $out = $this->drawSelect($item['navadmin_id'], $out, $sep + 1);
33
+ }
34
+ }
35
+ }
36
+ return $out;
37
+ }
38
+
39
+ public function getChildrens($pid=0){
40
+ $out = array();
41
+ $collection = Mage::getModel('navadmin/navadmin')->getCollection()
42
+ ->addFieldToFilter('pid', array('in'=>$pid) )
43
+ ->addFieldToFilter('status', array('in'=>'1') )
44
+ ->setOrder('position', 'asc');
45
+
46
+ foreach ($collection as $item){
47
+ $out[] = $item->getData();
48
+ }
49
+ return $out;
50
+ }
51
+
52
+ public function hasChildrens($pid=0){
53
+ $collection = Mage::getModel('navadmin/navadmin')->getCollection()
54
+ ->addFieldToFilter('pid', array('in'=>$pid) )
55
+ ->addFieldToFilter('status', array('in'=>'1') )
56
+ ->setOrder('position', 'asc')
57
+ ->load();
58
+ if($collection->count() > 0){
59
+ return true;
60
+ }
61
+ return false;
62
+ }
63
+
64
+
65
+ public function drawItem($pid=0, $level=0)
66
+ {
67
+ $html = '';
68
+ $items = $this->getChildrens($pid);
69
+ if (!empty($childrens)) {
70
+ return $html;
71
+ }
72
+ $i = 0;
73
+ $totreg = count($items);
74
+ foreach ($items as $k => $item){
75
+ $html.= '<li';
76
+ $hasChildrens = $this->hasChildrens($item['navadmin_id']);
77
+ if ($hasChildrens) {
78
+ $html.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"';
79
+ }
80
+
81
+ $html.= ' class="level'.$level;
82
+ $html.= ' nav-'.str_replace('/', '-', $item['link']);
83
+ if ($i == 0){
84
+ $html .= ' first';
85
+ }elseif ($totreg == ($k + 1)){
86
+ $html .= ' last';
87
+ }
88
+
89
+ if ($hasChildrens) {
90
+ $html .= ' parent';
91
+ }
92
+ $html.= '">'."\n";
93
+ if($item['target'] == '_blank'){
94
+ $html.= '<a href="http://'.$item['link'].'" target="_blank">';
95
+ }else{
96
+ $html.= '<a href="'.$item['link'].'">';
97
+ }
98
+ $html.= '<span>'.$this->htmlEscape($item['title']).'</span></a>'."\n";
99
+
100
+ if ($hasChildrens){
101
+ $htmlChildren = '';
102
+ $htmlChildren.= $this->drawItem($item['navadmin_id'], $level+1);
103
+ if (!empty($htmlChildren)) {
104
+ $html.= '<ul class="level' . $level . '">'."\n"
105
+ .$htmlChildren
106
+ .'</ul>';
107
+ }
108
+ }
109
+ $html.= '</li>'."\n";
110
+ $i++;
111
+ }
112
+ return $html;
113
+ }
114
+ }
app/code/community/Mage/Navadmin/Model/Mysql4/Navadmin.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Model_Mysql4_Navadmin extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ // Note that the navadmin_id refers to the key field in your database table.
8
+ $this->_init('navadmin/navadmin', 'navadmin_id');
9
+ }
10
+ }
app/code/community/Mage/Navadmin/Model/Mysql4/Navadmin/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Model_Mysql4_Navadmin_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('navadmin/navadmin');
9
+ }
10
+ }
app/code/community/Mage/Navadmin/Model/Navadmin.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Model_Navadmin extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('navadmin/navadmin');
9
+ }
10
+ }
app/code/community/Mage/Navadmin/Model/Status.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Model_Status extends Varien_Object
4
+ {
5
+ const STATUS_ENABLED = 1;
6
+ const STATUS_DISABLED = 2;
7
+
8
+ static public function getOptionArray()
9
+ {
10
+ return array(
11
+ self::STATUS_ENABLED => Mage::helper('navadmin')->__('Enabled'),
12
+ self::STATUS_DISABLED => Mage::helper('navadmin')->__('Disabled')
13
+ );
14
+ }
15
+ }
app/code/community/Mage/Navadmin/Model/Tree.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Model_Tree extends Varien_Object
4
+ {
5
+ const STATUS_ENABLED = 1;
6
+ const STATUS_DISABLED = 2;
7
+
8
+ static public function getOptionArray()
9
+ {
10
+ $x = array(
11
+ array(
12
+ 'value' => 1,
13
+ 'label' => Mage::helper('navadmin')->__('zzEnabled'),
14
+ ),
15
+
16
+ array(
17
+ 'value' => 2,
18
+ 'label' => Mage::helper('navadmin')->__('zzDisabled'),
19
+ ),
20
+ );
21
+ return $x;
22
+ }
23
+
24
+ }
app/code/community/Mage/Navadmin/controllers/Adminhtml/NavadminController.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mage_Navadmin_Adminhtml_NavadminController extends Mage_Adminhtml_Controller_action
4
+ {
5
+
6
+ protected function _initAction() {
7
+ $this->loadLayout()
8
+ ->_setActiveMenu('navadmin/items')
9
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
10
+
11
+ return $this;
12
+ }
13
+
14
+ public function indexAction() {
15
+ $this->_initAction()
16
+ ->renderLayout();
17
+ }
18
+
19
+ public function editAction() {
20
+ $id = $this->getRequest()->getParam('id');
21
+ $model = Mage::getModel('navadmin/navadmin')->load($id);
22
+
23
+ if ($model->getId() || $id == 0) {
24
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
25
+ if (!empty($data)) {
26
+ $model->setData($data);
27
+ }
28
+
29
+ Mage::register('navadmin_data', $model);
30
+
31
+ $this->loadLayout();
32
+ $this->_setActiveMenu('navadmin/items');
33
+
34
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
35
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
36
+
37
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
38
+
39
+ $this->_addContent($this->getLayout()->createBlock('navadmin/adminhtml_navadmin_edit'))
40
+ ->_addLeft($this->getLayout()->createBlock('navadmin/adminhtml_navadmin_edit_tabs'));
41
+
42
+ $this->renderLayout();
43
+ } else {
44
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('navadmin')->__('Item does not exist'));
45
+ $this->_redirect('*/*/');
46
+ }
47
+ }
48
+
49
+ public function newAction() {
50
+ $this->_forward('edit');
51
+ }
52
+
53
+ public function saveAction() {
54
+ if ($data = $this->getRequest()->getPost()) {
55
+
56
+ if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
57
+ try {
58
+ /* Starting upload */
59
+ $uploader = new Varien_File_Uploader('filename');
60
+
61
+ // Any extention would work
62
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
63
+ $uploader->setAllowRenameFiles(false);
64
+
65
+ // Set the file upload mode
66
+ // false -> get the file directly in the specified folder
67
+ // true -> get the file in the product like folders
68
+ // (file.jpg will go in something like /media/f/i/file.jpg)
69
+ $uploader->setFilesDispersion(false);
70
+
71
+ // We set media as the upload dir
72
+ $path = Mage::getBaseDir('media') . DS ;
73
+ $uploader->save($path, $_FILES['filename']['name'] );
74
+
75
+ } catch (Exception $e) {
76
+
77
+ }
78
+
79
+ //this way the name is saved in DB
80
+ $data['filename'] = $_FILES['filename']['name'];
81
+ }
82
+
83
+
84
+ $model = Mage::getModel('navadmin/navadmin');
85
+ $model->setData($data)
86
+ ->setId($this->getRequest()->getParam('id'));
87
+
88
+ try {
89
+ if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
90
+ $model->setCreatedTime(now())
91
+ ->setUpdateTime(now());
92
+ } else {
93
+ $model->setUpdateTime(now());
94
+ }
95
+
96
+ $model->save();
97
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('navadmin')->__('Item was successfully saved'));
98
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
99
+
100
+ if ($this->getRequest()->getParam('back')) {
101
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
102
+ return;
103
+ }
104
+ $this->_redirect('*/*/');
105
+ return;
106
+ } catch (Exception $e) {
107
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
108
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
109
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
110
+ return;
111
+ }
112
+ }
113
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('navadmin')->__('Unable to find item to save'));
114
+ $this->_redirect('*/*/');
115
+ }
116
+
117
+ public function deleteAction() {
118
+ if( $this->getRequest()->getParam('id') > 0 ) {
119
+ try {
120
+ $model = Mage::getModel('navadmin/navadmin');
121
+
122
+ $model->setId($this->getRequest()->getParam('id'))
123
+ ->delete();
124
+
125
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
126
+ $this->_redirect('*/*/');
127
+ } catch (Exception $e) {
128
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
129
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
130
+ }
131
+ }
132
+ $this->_redirect('*/*/');
133
+ }
134
+
135
+ public function massDeleteAction() {
136
+ $navadminIds = $this->getRequest()->getParam('navadmin');
137
+ if(!is_array($navadminIds)) {
138
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
139
+ } else {
140
+ try {
141
+ foreach ($navadminIds as $navadminId) {
142
+ $navadmin = Mage::getModel('navadmin/navadmin')->load($navadminId);
143
+ $navadmin->delete();
144
+ }
145
+ Mage::getSingleton('adminhtml/session')->addSuccess(
146
+ Mage::helper('adminhtml')->__(
147
+ 'Total of %d record(s) were successfully deleted', count($navadminIds)
148
+ )
149
+ );
150
+ } catch (Exception $e) {
151
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
152
+ }
153
+ }
154
+ $this->_redirect('*/*/index');
155
+ }
156
+
157
+ public function massStatusAction()
158
+ {
159
+ $navadminIds = $this->getRequest()->getParam('navadmin');
160
+ if(!is_array($navadminIds)) {
161
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
162
+ } else {
163
+ try {
164
+ foreach ($navadminIds as $navadminId) {
165
+ $navadmin = Mage::getSingleton('navadmin/navadmin')
166
+ ->load($navadminId)
167
+ ->setStatus($this->getRequest()->getParam('status'))
168
+ ->setIsMassupdate(true)
169
+ ->save();
170
+ }
171
+ $this->_getSession()->addSuccess(
172
+ $this->__('Total of %d record(s) were successfully updated', count($navadminIds))
173
+ );
174
+ } catch (Exception $e) {
175
+ $this->_getSession()->addError($e->getMessage());
176
+ }
177
+ }
178
+ $this->_redirect('*/*/index');
179
+ }
180
+
181
+ public function exportCsvAction()
182
+ {
183
+ $fileName = 'navadmin.csv';
184
+ $content = $this->getLayout()->createBlock('navadmin/adminhtml_navadmin_grid')
185
+ ->getCsv();
186
+
187
+ $this->_sendUploadResponse($fileName, $content);
188
+ }
189
+
190
+ public function exportXmlAction()
191
+ {
192
+ $fileName = 'navadmin.xml';
193
+ $content = $this->getLayout()->createBlock('navadmin/adminhtml_navadmin_grid')
194
+ ->getXml();
195
+
196
+ $this->_sendUploadResponse($fileName, $content);
197
+ }
198
+
199
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
200
+ {
201
+ $response = $this->getResponse();
202
+ $response->setHeader('HTTP/1.1 200 OK','');
203
+ $response->setHeader('Pragma', 'public', true);
204
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
205
+ $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
206
+ $response->setHeader('Last-Modified', date('r'));
207
+ $response->setHeader('Accept-Ranges', 'bytes');
208
+ $response->setHeader('Content-Length', strlen($content));
209
+ $response->setHeader('Content-type', $contentType);
210
+ $response->setBody($content);
211
+ $response->sendResponse();
212
+ die;
213
+ }
214
+ }
app/code/community/Mage/Navadmin/controllers/IndexController.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mage_Navadmin_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+
7
+ /*
8
+ * Load an object by id
9
+ * Request looking like:
10
+ * http://site.com/navadmin?id=15
11
+ * or
12
+ * http://site.com/navadmin/id/15
13
+ */
14
+ /*
15
+ $navadmin_id = $this->getRequest()->getParam('id');
16
+
17
+ if($navadmin_id != null && $navadmin_id != '') {
18
+ $navadmin = Mage::getModel('navadmin/navadmin')->load($navadmin_id)->getData();
19
+ } else {
20
+ $navadmin = null;
21
+ }
22
+ */
23
+
24
+ /*
25
+ * If no param we load a the last created item
26
+ */
27
+ /*
28
+ if($navadmin == null) {
29
+ $resource = Mage::getSingleton('core/resource');
30
+ $read= $resource->getConnection('core_read');
31
+ $navadminTable = $resource->getTableName('navadmin');
32
+
33
+ $select = $read->select()
34
+ ->from($navadminTable,array('navadmin_id','title','content','status'))
35
+ ->where('status',1)
36
+ ->order('created_time DESC') ;
37
+
38
+ $navadmin = $read->fetchRow($select);
39
+ }
40
+ Mage::register('navadmin', $navadmin);
41
+ */
42
+
43
+
44
+ $this->loadLayout();
45
+ $this->renderLayout();
46
+ }
47
+ }
app/code/community/Mage/Navadmin/etc/config.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mage_Navadmin>
5
+ <version>0.1.0</version>
6
+ </Mage_Navadmin>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <navadmin>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Mage_Navadmin</module>
14
+ <frontName>navadmin</frontName>
15
+ </args>
16
+ </navadmin>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <navadmin>
21
+ <file>navadmin.xml</file>
22
+ </navadmin>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <admin>
27
+ <routers>
28
+ <navadmin>
29
+ <use>admin</use>
30
+ <args>
31
+ <module>Mage_Navadmin</module>
32
+ <frontName>navadmin</frontName>
33
+ </args>
34
+ </navadmin>
35
+ </routers>
36
+ </admin>
37
+ <adminhtml>
38
+ <menu>
39
+ <cms>
40
+ <children>
41
+ <items module="navadmin">
42
+ <title>Navigation Bar</title>
43
+ <sort_order>71</sort_order>
44
+ <children>
45
+ <items module="navadmin">
46
+ <title>Manage Items</title>
47
+ <sort_order>0</sort_order>
48
+ <action>navadmin/adminhtml_navadmin</action>
49
+ </items>
50
+ </children>
51
+ </items>
52
+ </children>
53
+ </cms>
54
+ </menu>
55
+ <acl>
56
+ <resources>
57
+ <all>
58
+ <title>Allow Everything</title>
59
+ </all>
60
+ <admin>
61
+ <children>
62
+ <Mage_Navadmin>
63
+ <title>Navadmin Module</title>
64
+ <sort_order>10</sort_order>
65
+ </Mage_Navadmin>
66
+ </children>
67
+ </admin>
68
+ </resources>
69
+ </acl>
70
+ <layout>
71
+ <updates>
72
+ <navadmin>
73
+ <file>navadmin.xml</file>
74
+ </navadmin>
75
+ </updates>
76
+ </layout>
77
+ </adminhtml>
78
+ <global>
79
+ <models>
80
+ <navadmin>
81
+ <class>Mage_Navadmin_Model</class>
82
+ <resourceModel>navadmin_mysql4</resourceModel>
83
+ </navadmin>
84
+ <navadmin_mysql4>
85
+ <class>Mage_Navadmin_Model_Mysql4</class>
86
+ <entities>
87
+ <navadmin>
88
+ <table>navadmin</table>
89
+ </navadmin>
90
+ </entities>
91
+ </navadmin_mysql4>
92
+ </models>
93
+ <resources>
94
+ <navadmin_setup>
95
+ <setup>
96
+ <module>Mage_Navadmin</module>
97
+ </setup>
98
+ <connection>
99
+ <use>core_setup</use>
100
+ </connection>
101
+ </navadmin_setup>
102
+ <navadmin_write>
103
+ <connection>
104
+ <use>core_write</use>
105
+ </connection>
106
+ </navadmin_write>
107
+ <navadmin_read>
108
+ <connection>
109
+ <use>core_read</use>
110
+ </connection>
111
+ </navadmin_read>
112
+ </resources>
113
+ <blocks>
114
+ <navadmin>
115
+ <class>Mage_Navadmin_Block</class>
116
+ </navadmin>
117
+ </blocks>
118
+ <helpers>
119
+ <navadmin>
120
+ <class>Mage_Navadmin_Helper</class>
121
+ </navadmin>
122
+ </helpers>
123
+ </global>
124
+ </config>
app/code/community/Mage/Navadmin/sql/navadmin_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ -- DROP TABLE IF EXISTS {$this->getTable('navadmin')};
10
+ CREATE TABLE {$this->getTable('navadmin')} (
11
+ `navadmin_id` int(11) unsigned NOT NULL auto_increment,
12
+ `pid` int(11),
13
+ `title` varchar(255) NOT NULL default '',
14
+ `link` varchar(255) NOT NULL default '',
15
+ `target` varchar(255) NOT NULL default '',
16
+ `position` int(11),
17
+ `status` smallint(6) NOT NULL default '0',
18
+ `created_time` datetime NULL,
19
+ `update_time` datetime NULL,
20
+ PRIMARY KEY (`navadmin_id`)
21
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
22
+
23
+ ");
24
+
25
+ $installer->endSetup();
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Mage_Navadmin</name>
4
+ <version>1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Navigation bar administration</summary>
10
+ <description>Navigation bar administration with multiple menu levels</description>
11
+ <notes>Navigation bar administration</notes>
12
+ <authors><author><name>Oliver</name><user>auto-converted</user><email>olivertar@gmail.com</email></author></authors>
13
+ <date>2008-11-20</date>
14
+ <time>19:05:13</time>
15
+ <contents><target name="magecommunity"><dir name="Mage"><dir name="Navadmin"><dir name="Block"><dir name="Adminhtml"><dir name="Navadmin"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="65239aae13f7ecca41f077c34cebe587"/></dir><file name="Form.php" hash="75a0c4d1d6978c6ea4227df318de6684"/><file name="Tabs.php" hash="1709f08951d71dbe5b9799623e63dc21"/></dir><file name="Edit.php" hash="c8ae5fb904e3581e190287bf533886a1"/><file name="Grid.php" hash="6dfe0821839995966531d466be07afd8"/></dir><file name="Navadmin.php" hash="370bac5766ceb3c11fd20292f4137fda"/></dir><file name="Navadmin.php" hash="1c0064780467a1c006b046c2a18c4036"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="NavadminController.php" hash="bc80d517a2ac63116f97e701ea5ea772"/></dir><file name="IndexController.php" hash="722639334ba05b4d0622d1a6221b5930"/></dir><dir name="etc"><file name="config.xml" hash="8d6b202e30fed22abc066bbb80fff127"/></dir><dir name="Helper"><file name="Data.php" hash="7a0ff96443ac44b81756e08ca8e9e856"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Navadmin"><file name="Collection.php" hash="9635425cc867d26b9c1cbb9625714a16"/></dir><file name="Navadmin.php" hash="ffb1441070adc6198d22fc5d6c39eabb"/></dir><file name="Navadmin.php" hash="bdf57884f6b450414032ac8ac061f5dd"/><file name="Status.php" hash="d829853984dd1297d90d736299405d56"/><file name="Tree.php" hash="ab98e484af6b9fad35055fb74b50ef20"/></dir><dir name="sql"><dir name="navadmin_setup"><file name="mysql4-install-0.1.0.php" hash="1b3797a92e31ed7052d3ec77d4108ff4"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>