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

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

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

class Myuploader_ImageAddAction extends Myuploader_ImageEditAction
{
    function prepare() {
        $root = Xcube_Root::getSingleton();
        $root->mController->setDialogMode(true);
        
        return parent::prepare();
    }

    /**
     * @public
     */
    function executeViewInput(&$render)
    {
        parent::executeViewInput($render);
        $render->setAttribute('actionName', $this->mModule->mActionName);
        $render->setAttribute('target', xoops_getrequest('target'));
        $render->setAttribute('moduleUrl', XOOPS_MODULE_URL.'/'.$this->mAsset->mDirname);
    }

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

    function hasPermission()
    {
        if(!(in_array($this->mObject->get('category_id'), $this->mModuleGlobal->getUploadable()))) {
            return false;
        }
        
	$allCategories =& $this->mModuleGlobal->getAllCategories();
        $this->mActionForm->mCategory =& $allCategories[$this->mObject->get('category_id')];
        return true;
    }

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

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

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

?>