<?php
/**
 * @version $Id: ImageDeleteAction.class.php 679 2012-08-20 12:41:35Z hodaka $
 * @package myuploader
 */

if (!defined('XOOPS_ROOT_PATH')) exit();

require_once dirname(dirname(__FILE__)) . "/class/AbstractDeleteAction.class.php";

class Myuploader_ImageDeleteAction extends Myuploader_AbstractDeleteAction
{
    var $mCategory = null;

    function isMemberOnly() {
        return true;
    }

    function prepare() {
        parent::prepare();
        if(!is_object($this->mObject)) {
        	return false;
        }
        
	$category_handler =& $this->mAsset->getObject('handler', 'category');
	$this->mCategory =& $category_handler->get($this->mObject->get('category_id'));
        return true;
    }
    
	/**
	 * @protected
	 */
	function _getId()
	{
		return xoops_getrequest('image_id');
	}

	/**
	 * @protected
	 */
	function &_getHandler()
	{
		$handler =& $this->mAsset->getObject('handler', 'image');
		return $handler;
	}

	/**
	 * @protected
	 */
	function _setupActionForm()
	{
		// $this->mActionForm = new Myuploader_ImageDeleteForm();
		$this->mActionForm =& $this->mAsset->getObject('form', 'image', false, 'delete');
		$this->mActionForm->prepare();
	}

	/**
	 * @public
	 */
	function executeViewInput(&$render)
	{
		$render->setTemplateName($this->mAsset->mDirname."_main_image_delete.html");
		$render->setAttribute('actionForm', $this->mActionForm);
		#cubson::lazy_load('image', $this->mObject);
		$render->setAttribute('object', $this->mObject);
        $render->setAttribute('category', $this->mCategory);

	}

	/**
	 * @public
	 */
	function executeViewSuccess(&$render)
	{
		$this->mRoot->mController->executeForward("./index.php?action=ImageList&category_id=".$this->mObject->get('category_id'));
	}

	/**
	 * @public
	 */
	function executeViewError(&$render)
	{
		$this->mRoot->mController->executeRedirect("./index.php?action=ImageList&category_id=".$this->mObject->get('category_id'), 1, _MD_MYUPLOADER_ERROR_DBUPDATE_FAILED);
	}

	/**
	 * @public
	 */
	function executeViewCancel(&$render)
	{
		$this->mRoot->mController->executeForward("./index.php?action=ImageList&category_id=".$this->mObject->get('category_id'));
	}
}

?>
