<?php

class MActionPanelObject extends MActionPanel
{
    public $actionIcon;
    public $module;
    public $action;
    public $object;
    public $formFolder;
    public $formName;
    public $actionLabel;
    public $command;

    public function __construct($name = '', $caption = '', $close = '', $icon = '', $iconType='small')
    {
        parent::__construct($name, $caption, NULL, $close, $icon, $iconType);
        $this->setActionIcon($this->getUI()->getImageTheme($this->manager->getConf('theme.main'),'button_seta.png'));
    }

    public function setActionIcon($icon)
    {
        $this->actionIcon = $icon;
    }

    public function setBaseModule($module)
    {
        $this->module = $module;
    }

    public function setBaseAction($action)
    {
        $this->action = $action;
    }

    public function setBaseFormFolder($folder)
    {
        $this->formFolder = $folder;
    }

    public function setBaseBusiness($module, $class, $item = '')
    {
        $this->object = $this->manager->getBusiness($module, $class, $item);
    }

    public function addCommand($command, $formName, $label = '')
    {
        if ($label != '')
        {
            parent::addAction($label, $this->actionIcon, $this->module, $this->action . ':' . $command);
            $this->actionLabel[$command] = $label;
        }
        $this->formName[$command] = $formName;
    }

    public function addForm($command)
    {
        $this->command = ($command == '') ? ($this->object->getOIDValue() ? 'main' : 'find') : $command;
   	    $form = $this->getUI()->getForm($this->module,$this->formName[$this->command],$this,$this->formFolder);
        $form->setWidth('95%');
		$form->setClose($this->manager->getActionURL($this->module, $this->action));
        $this->addControl($form);
    }

    public function getLabel($command = '')
    {
        return $this->actionLabel[($command == '') ? $this->command : $command];
    }

    public function getFormName($command = '')
    {
        return $this->formName[($command == '') ? $this->command : $command];
    }

    public function getURL($command = '', $oid = '', $args = '')
    {
        $url = $this->manager->getActionURL($this->module, $this->action.':'.$command,$oid, $args);
        return $url;
    }

    public function go($command = '', $oid = '')
    {
        $go = $this->getURL($command, $oid);
        $this->page->redirect($go);
    }

}

?>
