NcrightsgroupsController.php 6.01 KB
<?php
/**
 * @package  anc_lib 
 * @category magento
 * @mailto	code [at] netz.coop
 * @author	netz.coop eG* 
 * @copyright (c) 2014, 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_Lib_Adminhtml_NcrightsgroupsController extends Mage_Adminhtml_Controller_Action {

//	private static $customerid;

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

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

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

	public function editAction() {
		$var_params = $this->getRequest()->getParams();
		D::s($var_params, 'entity_id', 5, 1);


		$item_exists = Mage::helper('anc_lib/sql')->selectFetchOneRow('anc_lib_ncrightsgroups', array('rights_id' => $var_params['rightid'], 'customer_group_id' => $var_params['groupid']));
		$arrayurl['rightid'] = $var_params['rightid'];
		$arrayurl['id'] = $var_params['rightid'];
		if ($var_params['albumid']) {
			$arrayurl['albumid'] = $var_params['albumid'];
		}
		if ($var_params['imageid']) {
			$arrayurl['imageid'] = $var_params['imageid'];
		}
		if ($var_params['textid']) {
			$arrayurl['textid'] = $var_params['textid'];
		}
		if ($var_params['siteid']) {
			$arrayurl['siteid'] = $var_params['siteid'];
		}
		if (!$item_exists) {
			Mage::helper('anc_lib/sql')->insertValuesIntoTable('anc_lib_ncrightsgroups', array('rights_id' => $var_params['rightid'], 'customer_group_id' => $var_params['groupid']));

			Mage::getSingleton('adminhtml/session')
					->addSuccess('successfully saved');
//			$arrayurl['rightid'] = $var_params['rightid'];
//			$arrayurl['albumid'] = $var_params['albumid'];
			$this->_redirect('*/*/list', $arrayurl);
//			return;
		} else {
			Mage::getSingleton('adminhtml/session')
					->addError('Benutzer existiert schon');
//			$arrayurl['id'] = $var_params['rightid'];
//			$arrayurl['albumid'] = $var_params['albumid'];
//			$varurlcustomers = $this->getUrl('lib/adminhtml_ncrights/edit', $arrayurl);
			$this->_redirect('lib/adminhtml_ncrights/edit', $arrayurl);
//			return;
		}


		$arrayurl = array();
		if (TRUE) {
			
		} else {
			
		}

//			$varurlcustomers = $this->getUrl('lib/adminhtml_ncrights/edit', $arrayurl);
//		
//		 $this->getUrl('*/*/edit', array('id' => $row->getId(),'rightid'=>$var_params['rightid']));
//			$this->_redirect('lib/adminhtml_ncrights/edit',$arrayurl);
//		}
	}

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

	public function saveAction() {
		if ($this->getRequest()->getPost()) {
			try {
				$postData = $this->getRequest()->getPost();
				D::s($postData, '$postDataRights', 5, 1);
				$testModel = Mage::getModel('anc_lib/ncrightsgroups');
				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);
				D::s($testModel->getData('customer_group_id'), 'customer_group_id', 5, 1);
				if ($postData['albumid'] > 0) {
					$param_where = array("entity_id" => $postData['albumid']); //$postData['albumid']);
					Mage::helper('anc_lib/sql')->updateOneCell('anc_album_ncalbum', 'ncright_id', $testModel->getData('customer_group_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_lib/ncrightsgroups');
				$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');
//		$this->_redirect('*/*/');
	}

	protected function _isAllowed() {
		return Mage::getSingleton('admin/session')->isAllowed('ncrightsgroups/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();
	}

}