NcrightsController.php 8.91 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_NcrightsController extends Mage_Adminhtml_Controller_Action {

//	private static $customerid;

	public function listAction() {
		$rightsBlock = $this->getLayout()->createBlock('anc_lib/adminhtml_ncrights');
		$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() {
		$id = $this->getRequest()->getParam('id');
//		if (!$id){
//			$id=2;
//		}
		$model = Mage::getModel('anc_lib/ncrights')->load($id);
		if ($model->getId() || $id == 0) {
			Mage::register('anc_lib', $model);
			$this->loadLayout();
			$this->_setActiveMenu('test/set_time');
			$this->_addBreadcrumb('test Manager', 'test Manager');
			$this->_addBreadcrumb('Test Description', 'Test Description');
			$this->getLayout()->getBlock('head')
					->setCanLoadExtJs(true);
			$this->_addContent($this->getLayout()
							->createBlock('anc_lib/adminhtml_ncrights_edit'))
					->_addLeft($this->getLayout()
							->createBlock('anc_lib/adminhtml_ncrights_edit_tabs')
			);
			$this->renderLayout();
		} else {
			Mage::getSingleton('adminhtml/session')
					->addError('Test does not exist');
			$this->_redirect('*/*/');
		}
	}

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

	public function saveAction() {
		if ($this->getRequest()->getPost()) {
			$return_self = false;
			try {
				$postData = $this->getRequest()->getPost();
				D::s($postData, '$postDataRights', 5, 1);
				$testModel = Mage::getModel('anc_lib/ncrights');
				if ($this->getRequest()->getParam('id') <= 0)
					$return_self = true;
				$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('entity_id'),'entity_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('entity_id'), $param_where);

					if ($this->getRequest()->getParam('back')) {
						$this->_redirect(
								'*/*/edit', array(
							'id' => $testModel->getId(),
							'albumid' => $postData['albumid']
								)
						);
						return;
					}

					if ($return_self === true) {
						$this->_redirect('*/adminhtml_ncrights/edit', array('id' => $testModel->getData('entity_id'), 'albumid' => $postData['albumid']));
					} else {
						$this->_redirect('album/adminhtml_album/edit', array('id' => $postData['albumid']));
					}

					return;
				} else if ($postData['imageid'] > 0) {
//					D::s(imageid);
					$param_where = array("entity_id" => $postData['imageid']);
					Mage::helper('anc_lib/sql')->updateOneCell('anc_image_ncimage', 'ncright_id', $testModel->getData('entity_id'), $param_where);

					if ($this->getRequest()->getParam('back')) {
						$this->_redirect(
								'*/*/edit', array(
							'id' => $testModel->getId(),
							'imageid' => $postData['imageid']
								)
						);
						return;
					}
					if ($return_self === true) {
						$this->_redirect('*/adminhtml_ncrights/edit', array('id' => $testModel->getData('entity_id'), 'imageid' => $postData['imageid']));
					} else {
						$this->_redirect('image/adminhtml_image/edit', array('id' => $postData['imageid']));
					}

					return;
				} else if ($postData['textid'] > 0) {
					$param_where = array("entity_id" => $postData['textid']);
					Mage::helper('anc_lib/sql')->updateOneCell('anc_text_nctext', 'ncright_id', $testModel->getData('entity_id'), $param_where);

					if ($this->getRequest()->getParam('back')) {
						$this->_redirect(
								'*/*/edit', array(
							'id' => $testModel->getId(),
							'textid' => $postData['textid']
								)
						);
						return;
					}
					if ($return_self === true) {
						$this->_redirect('*/adminhtml_ncrights/edit', array('id' => $testModel->getData('entity_id'), 'textid' => $postData['textid']));
					} else {
						$this->_redirect('text/adminhtml_text/edit', array('id' => $postData['textid']));
					}

					return;
				} else if ($postData['playlistid'] > 0) {
					$param_where = array("entity_id" => $postData['siteid']); //$postData['albumid']);
					Mage::helper('anc_lib/sql')->updateOneCell('anc_site_ncsite', 'ncright_id', $testModel->getData('entity_id'), $param_where);

					if ($this->getRequest()->getParam('back')) {
						$this->_redirect(
								'*/*/edit', array(
							'id' => $testModel->getId(),
							'siteid' => $postData['siteid']
								)
						);
						return;
					}
					if ($return_self === true) {
						$this->_redirect('*/adminhtml_ncrights/edit', array('id' => $testModel->getData('entity_id'), 'siteid' => $postData['siteid']));
					} else {
						$this->_redirect('site/adminhtml_site/edit', array('id' => $postData['siteid']));
					}

					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/ncrights');
				$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('ncrights/form');
	}

	public function removeUserFromRightsAction() {
		$varParam = $this->getRequest()->getParams();
		$result = Mage::helper('anc_lib/sql')->deleteRow('anc_lib_ncrightscustomers', array('entity_id' => $varParam['entityid']));
		if ($result) {
			Mage::getSingleton('adminhtml/session')
					->addSuccess('Datensatz wurde gelöscht');
		}



		$arrayurl = array();

		$arrayurl['id'] = $varParam['rightsid'];
		if ($varParam['albumid']) {
			$arrayurl['albumid'] = $varParam['albumid'];
		}
		if ($varParam['imageid']) {
			$arrayurl['imageid'] = $varParam['imageid'];
		}
		if ($varParam['textid']) {
			$arrayurl['textid'] = $varParam['textid'];
		}
		if ($varParam['siteid']) {
			$arrayurl['siteid'] = $varParam['siteid'];
		}



		$this->_redirect('*/*/edit', $arrayurl);
	}

	public function removeGroupFromRightsAction() {
		$varParam = $this->getRequest()->getParams();
//		Mage::helper('anc_lib/sql')->insertValuesIntoTable('anc_lib_ncrightsgroups', array('rights_id' => $var_params['rightid'], 'customer_group_id' => $var_params['groupid']));
		$result = Mage::helper('anc_lib/sql')->deleteRow('anc_lib_ncrightsgroups', array('entity_id' => $varParam['entityid']));
		if ($result) {
			Mage::getSingleton('adminhtml/session')
					->addSuccess('Datensatz wurde gelöscht');
		}

		$arrayurl = array();

		$arrayurl['id'] = $varParam['rightsid'];
		if ($varParam['albumid']) {
			$arrayurl['albumid'] = $varParam['albumid'];
		}
		if ($varParam['imageid']) {
			$arrayurl['imageid'] = $varParam['imageid'];
		}
		if ($varParam['textid']) {
			$arrayurl['textid'] = $varParam['textid'];
		}
		if ($varParam['siteid']) {
			$arrayurl['siteid'] = $varParam['siteid'];
		}
		$this->_redirect('*/*/edit', $arrayurl);
	}

}