| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/awebpaca/boutiques/app/code/community/AsiaConnect/FreeCms/controllers/Cms/ |
Upload File : |
<?php
class AsiaConnect_FreeCms_Cms_BlockController extends Mage_Adminhtml_Controller_Action
{
/**
* Init actions
*
* @return AsiaConnect_FreeCms_Cms_BlockController
*/
protected function _initAction()
{
// load layout, set active menu and breadcrumbs
$this->loadLayout()
->_setActiveMenu('freecms/freeblock')
->_addBreadcrumb(Mage::helper('cms')->__('CMS'), Mage::helper('cms')->__('CMS'))
->_addBreadcrumb(Mage::helper('freecms')->__('Free Blocks'), Mage::helper('freecms')->__('Free Blocks'))
;
return $this;
}
/**
* Index action
*/
public function indexAction()
{
$this->_initAction()
->_addContent($this->getLayout()->createBlock('freecms/cms_block'))
->renderLayout();
}
/**
* Create new CMS block
*/
public function newAction()
{
// the same form is used to create and edit
$this->_forward('edit');
}
/**
* Edit CMS block
*/
public function editAction()
{
// 1. Get ID and create model
$id = $this->getRequest()->getParam('block_id');
$model = Mage::getModel('cms/block');
// 2. Initial checking
if ($id) {
$model->load($id);
if (! $model->getId()) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists'));
$this->_redirect('*/*/');
return;
}
}
// 3. Set entered data if was error when we do save
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
if (! empty($data)) {
$model->setData($data);
}
// 4. Register model to use later in blocks
Mage::register('cms_block', $model);
// 5. Build edit form
$this->_initAction()
->_addBreadcrumb($id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block'), $id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block'))
->_addContent($this->getLayout()->createBlock('freecms/cms_block_edit')->setData('action', $this->getUrl('*/cms_block/save')))
->renderLayout();
}
/**
* Save action
*/
public function saveAction()
{
// check if data sent
if ($data = $this->getRequest()->getPost()) {
// init model and set data
$model = Mage::getModel('cms/block');
$model->setData($data);
// try to save it
try {
// save the data
$model->save();
// display success message
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Block was successfully saved'));
// clear previously saved data from session
Mage::getSingleton('adminhtml/session')->setFormData(false);
// check if 'Save and Continue'
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('block_id' => $model->getId()));
return;
}
// go to grid
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
// display error message
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
// save data in session
Mage::getSingleton('adminhtml/session')->setFormData($data);
// redirect to edit form
$this->_redirect('*/*/edit', array('block_id' => $this->getRequest()->getParam('block_id')));
return;
}
}
$this->_redirect('*/*/');
}
/**
* Delete action
*/
public function deleteAction()
{
// check if we know what should be deleted
if ($id = $this->getRequest()->getParam('block_id')) {
$title = "";
try {
// init model and delete
$model = Mage::getModel('cms/block');
$model->load($id);
$title = $model->getTitle();
$model->delete();
// display success message
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Block was successfully deleted'));
// go to grid
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
// display error message
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
// go back to edit form
$this->_redirect('*/*/edit', array('block_id' => $id));
return;
}
}
// display error message
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a block to delete'));
// go to grid
$this->_redirect('*/*/');
}
/**
* Check the permission to run it
*
* @return boolean
*/
protected function _isAllowed()
{
return Mage::getSingleton('admin/session')->isAllowed('cms/block');
}
}