NcimagesController.php 4.04 KB
<?php
/**
 * @package  anc_image
 * @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_Image_Adminhtml_AlbumController extends Mage_Adminhtml_Controller_Action {

//	private static $customerid;

	public function listAction() {
		$albumBlock = $this->getLayout()->createBlock('anc_image/adminhtml_albums');
		$this->loadLayout()
				->_addContent($albumBlock)
				->renderLayout();
	}

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

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

	public function editAction() {
		$id = $this->getRequest()->getParam('id');
		$model = Mage::getModel('anc_image/album')->load($id);
		if ($model->getId() || $id == 0) {
			Mage::register('anc_album', $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_image/adminhtml_albums_edit'))
					->_addLeft($this->getLayout()
							->createBlock('anc_image/adminhtml_albums_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()) {
			try {
				$postData = $this->getRequest()->getPost();
				$testModel = Mage::getModel('anc_image/album');
				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);
				$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_image/album');
				$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('image/form');
	}

}