<?php

class MActionControl extends MInputControl
{
    public $click;
    public $action = ''; // '', <url>, <go:url>, <:action>, <window:url>, SUBMIT, PRINT, RESET, REPORT, PDF, RETURN, NONE, WINDOW

    public function __construct( $name, $value, $label = '', $color = '', $hint = '' )
    {
        parent::__construct( $name, $value, $label, $color, $hint );
    }

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

    public function getOnClick($action)
    {
        if ($action == '')
        {
            $action = $this->action;
        }
        $upper = strtoupper($action);
        if ( $upper == 'SUBMIT' )
        {

            if ( count($this->eventHandlers) )
            {
                $param   = $this->eventHandlers['click']['param'];
                $onclick = "miolo.doPostBack('{$this->name}:click','{$param}','{$this->formId}');";
            }
            else
            {
                if (( $this->name != '' ) && ($onclick == ''))
                {
                    $onclick = "miolo.doPostBack('{$this->name}:click','','{$this->formId}');";
                }
            }
            if ( $this->onclickdisable )
            {
                $onclick .= "miolo.doDisableButton('{$this->name}');";
            }
        }
        elseif ( $upper == 'PRINT' )
        {
            $onclick = "miolo.doPrintForm();";
        }
        elseif ($upper == 'REPORT')
        {
            if ( $this->name != '' )
            {
                $onclick = "miolo.doPrintFile('{$this->name}:click','','{$this->formId}');";
            }
        }
        elseif ($upper == 'FILE')
        {
            if ( $this->name != '' )
            {
                $onclick = "miolo.doGetFile('{$this->name}:click','','{$this->formId}');";
            }
        }
        elseif ( $upper == 'PDF' )
        {
            if ( $this->name != '' )
            {
                $onclick = "miolo.doShowPDF('{$this->name}:click','','{$this->formId}');";
            }
        }
        elseif ( $upper == 'RETURN' )
        {
            global $history;
            $href = $history->back('action');
            $onclick = "miolo.doHandler('$href','{$this->formId}');";
        }
        elseif ( substr($upper, 0, 7) == 'WINDOW:' )
        {
            $url = substr($action, 7);
            $onclick = "miolo.doWindow('{$url}','{$this->target}');";
        }
        elseif ( $upper == 'NONE' )
        {
            return "";
        }
        elseif ( substr($upper, 0, 4) == 'BTN:' )
        {
            $goto = substr($action, 4);
            $event = ($this->name != '') ? "{$this->name}:click" : '';
            $onclick = "miolo.doLinkButton('{$goto}', '{$event}', '', '{$this->formId}');";
        }
        elseif ( substr($upper, 0, 7) == 'HTTP://' )
        {
            $onclick = "miolo.doLink('{$action}','{$this->formId}');";
        }
        elseif ( substr($upper, 0, 3) == 'GO:' )
        {
            $goto = substr($action, 3);
            $onclick = "miolo.doHandler('$goto','{$this->formId}');";
        }
        elseif ( substr($upper, 0, 5) == 'PAGE:' )
        {
            $goto = substr($action, 5) . "&__ISPAGE=yes";
            $onclick = "miolo.doPage('$goto');";
        }
        elseif ( substr($upper, 0,11) == 'JAVASCRIPT:' )
        {
            $onclick = $action;
        }
        elseif ( $action{0} == ':' )
        {
            $event = substr($action, 1);
            $onclick = $this->manager->getUI()->getAjax($event);
        }
        else
        {
            $onclick = $action;
        }
        return $onclick . ' return false;';
    }
}
?>