<?php

class MLink extends MActionControl
{
    public $target = '_self';
    public $href;

    public function __construct( $name = NULL, $label = NULL, $href = NULL, $text = NULL, $target = '_self' )
    {
        parent::__construct( $name, $href, $label );

        $this->setText($text);
        $this->href    = $href;
        $this->target  = $target;
    }

    public function setTarget( $target )
    {
        $this->target = $target;
    }

    public function setHREF( $href )
    {
        $this->href = $href;
    }

    public function setAction( $module = '', $action = '', $item = null, $args = null )
    {
        $this->href = $this->manager->getActionURL( $module, $action, $item, $args );
//        $this->addEvent('click', "miolo.doLink('{$goto}','{$this->formId}');");
    }

    /* deprecated */
    public function setOnClick($code)
    {
        $this->href = $code;
    }

    public function generateLink()
    {

        // if not SPI Mode, use href as link
        if ((!$this->manager->SPI) && ( substr(strtoupper($this->href), 0, 7) == 'HTTP://')) return;

        // if SPI Mode, get the OnClick method
        if ($this->href != '')
        {
            // if href is set and target points to another window, the anchor is handled by browser 
            if (($this->target == '') || ($this->target == "_self"))
            {
                $onclick = $this->getOnClick($this->href);
                $this->addAttribute('onclick',$onclick);
            }
        }
    }

    public function generateInner()
    {
        $this->generateLink();

        if ( $this->readOnly )
        {
            $this->inner = MHtmlPainter::span( 'mReadOnly', $this->name, $this->caption );

            return;
        }

        if ( $this->getClass() == '' )
        {
            $this->setClass( 'mLink' );
        }

        if ( $this->target != '_self' )
        {
            $this->addAttribute( 'target', $this->target );
        }


        if ( $this->text == '' )
        {
            $this->text = $this->label;
        }

        $this->inner = $this->generateLabel() . $this->getRender('anchor');

    }
}

?>