00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Adminhtml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Tax rule controller 00029 * 00030 * @category Mage 00031 * @package Mage_Adminhtml 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_Adminhtml_Checkout_AgreementController extends Mage_Adminhtml_Controller_Action 00035 { 00036 public function indexAction() 00037 { 00038 $this->_initAction() 00039 ->_addContent($this->getLayout()->createBlock('adminhtml/checkout_agreement')) 00040 ->renderLayout(); 00041 return $this; 00042 } 00043 00044 public function newAction() 00045 { 00046 $this->_forward('edit'); 00047 } 00048 00049 public function editAction() 00050 { 00051 $id = $this->getRequest()->getParam('id'); 00052 $agreementModel = Mage::getModel('checkout/agreement'); 00053 $hlp = Mage::helper('checkout'); 00054 if ($id) { 00055 $agreementModel->load($id); 00056 if (!$agreementModel->getId()) { 00057 Mage::getSingleton('adminhtml/session')->addError($hlp->__('This condition no longer exists')); 00058 $this->_redirect('*/*/'); 00059 return; 00060 } 00061 } 00062 00063 $data = Mage::getSingleton('adminhtml/session')->getAgreementData(true); 00064 if (!empty($data)) { 00065 $agreementModel->setData($data); 00066 } 00067 00068 Mage::register('checkout_agreement', $agreementModel); 00069 00070 $this->_initAction() 00071 ->_addBreadcrumb($id ? $hlp->__('Edit Condition') : $hlp->__('New Condition'), $id ? $hlp->__('Edit Condition') : $hlp->__('New Condition')) 00072 ->_addContent($this->getLayout()->createBlock('adminhtml/checkout_agreement_edit')->setData('action', $this->getUrl('*/*/save'))) 00073 ->renderLayout(); 00074 } 00075 00076 public function saveAction() 00077 { 00078 if ($postData = $this->getRequest()->getPost()) { 00079 $model = Mage::getSingleton('checkout/agreement'); 00080 $model->setData($postData); 00081 00082 try { 00083 $model->save(); 00084 00085 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('checkout')->__('Condition was successfully saved')); 00086 $this->_redirect('*/*/'); 00087 00088 return; 00089 } 00090 catch (Mage_Core_Exception $e) { 00091 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00092 } 00093 catch (Exception $e) { 00094 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('Error while saving this condition. Please try again later.')); 00095 } 00096 00097 Mage::getSingleton('adminhtml/session')->setAgreementData($postData); 00098 $this->_redirectReferer(); 00099 } 00100 } 00101 00102 public function deleteAction() 00103 { 00104 $id = (int)$this->getRequest()->getParam('id'); 00105 $model = Mage::getSingleton('checkout/agreement') 00106 ->load($id); 00107 if (!$model->getId()) { 00108 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('This condition no longer exists')); 00109 $this->_redirect('*/*/'); 00110 return; 00111 } 00112 00113 try { 00114 $model->delete(); 00115 00116 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('checkout')->__('Condition was successfully deleted')); 00117 $this->_redirect('*/*/'); 00118 00119 return; 00120 } 00121 catch (Mage_Core_Exception $e) { 00122 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00123 } 00124 catch (Exception $e) { 00125 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('Error while deleting this condition. Please try again later.')); 00126 } 00127 00128 $this->_redirectReferer(); 00129 } 00130 00131 /** 00132 * Initialize action 00133 * 00134 * @return Mage_Adminhtml_Controller_Action 00135 */ 00136 protected function _initAction() 00137 { 00138 $this->loadLayout() 00139 ->_setActiveMenu('sales/checkoutagreement') 00140 ->_addBreadcrumb(Mage::helper('checkout')->__('Sales'), Mage::helper('checkout')->__('Sales')) 00141 ->_addBreadcrumb(Mage::helper('checkout')->__('Checkout Conditions'), Mage::helper('checkout')->__('Checkout Terms and Conditions')) 00142 ; 00143 return $this; 00144 } 00145 00146 protected function _isAllowed() 00147 { 00148 return Mage::getSingleton('admin/session')->isAllowed('sales/checkoutagreement'); 00149 } 00150 }