PriceslistsController.php 5.28 KB
<?php

/**
 * @package magento
 * @subpackage AncPricepercustomer
 *
 * @author netz.coop code[at]netz.coop
 *
 * @license http://www.gnu.org/licenses/gpl-3.0.de.html GNU GENERAL PUBLIC LICENSE VERSION 3
 * @copyright (C) 2015 netz.coop eG
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
class Anc_Pricespercustomer_Adminhtml_PriceslistsController extends Mage_Adminhtml_Controller_Action {

    public function listAction() {
        $rightsBlock = $this->getLayout()->createBlock('pricespercustomer/adminhtml_ncpriceslists');
        $this->loadLayout()
                ->_addContent($rightsBlock)
                ->renderLayout();
    }

    protected function _initAction() {
        $this->loadLayout()->_setActiveMenu('anc_pricespercustomer/ANC')
                ->_addBreadcrumb('test Manager', 'test Manager');
        return $this;
    }

    public function indexAction() {
        $this->_initAction();
        $this->renderLayout();
    }

    public function editAction() {
        $var_params = $this->getRequest()->getParams();
        $this->_redirect('*/admin/pricespercustomer/edit', $arrayurl);
    }

    public function newAction() {
        $this->_forward('edit');
    }

    public function saveAction() {
        if ($this->getRequest()->getPost()) {
            try {
                $postData = $this->getRequest()->getPost();
                $testModel = Mage::getModel('anc_pricespercustomer/ncpriceslists');
                if ($this->getRequest()->getParam('id') <= 0)
                    $testModel->setCreatedTime(
                            Mage::getSingleton('core/date')
                                    ->gmtDate()
                    );

                $testModel
                        ->addData($postData)
                        ->setUpdateTime(
                                Mage::getSingleton('core/date')
                                ->gmtDate())
                        ->setId($this->getRequest()->getParam('id'))
                        ->save();
                Mage::getSingleton('adminhtml/session')
                        ->addSuccess('successfully saved');
                Mage::getSingleton('adminhtml/session')
                        ->settestData(false);
                if ($postData['albumid'] > 0) {
                    $param_where = array("entity_id" => $postData['albumid']);
                    Mage::helper('anc_pricespercustomer/sql')->updateOneCell('anc_album_ncalbum', 'ncright_id', $testModel->getData('entity_id'), $param_where);

                    $this->_redirect('*/*/list');
                    $this->_redirect('album/adminhtml_album/edit', array('id' => $postData['albumid']));
                    return;
                }

                $this->_redirect('*/*/list');
                return;
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')
                        ->addError($e->getMessage());
                Mage::getSingleton('adminhtml/session')
                        ->settestData($this->getRequest()
                                ->getPost()
                );
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()
                            ->getParam('id')));
                return;
            }
        }
        $this->_redirect('*/*/');
    }

    public function deleteAction() {
        if ($this->getRequest()->getParam('id') > 0) {
            try {
                $testModel = Mage::getModel('anc_pricespercustomer/ncpriceslists');
                $testModel->setId($this->getRequest()
                                ->getParam('id'))
                        ->delete();
                Mage::getSingleton('adminhtml/session')
                        ->addSuccess('successfully deleted');
                $this->_redirect('*/*/');
                $this->_redirect('*/*/list');
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')
                        ->addError($e->getMessage());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            }
        }
        $this->_redirect('*/*/list');
    }

    protected function _isAllowed() {
        return Mage::getSingleton('admin/session')->isAllowed('ncpriceslists/form');
    }

    public function customergridAction() {
        $this->loadLayout();
        $this->getLayout()->getBlock('customer.grid')
                ->setCustomers($this->getRequest()->getPost('customers', null));
        $this->renderLayout();
    }

    public function customerAction() {

        $this->loadLayout();
        $this->getLayout()->getBlock('customer.grid')
                ->setCustomers($this->getRequest()->getPost('customers', null));
        $this->renderLayout();
    }

}