<?
class frmTabbed extends MTabbedForm
{
    public function __construct()
    {   
		parent::__construct('Title: TabbedForm Example');
        $this->setPainterMethod('javascript'); 
//        $this->setPainterMethod('html'); 
        $form0 = new FrmTabbedZero($this);
        $form1 = new FrmTabbedOne($this);
        $form2 = new FrmTabbedTwo();
        $form3 = new FrmTabbedThree();
        $form4 = new FrmTabbedFour();

        $this->addPage($form0);
        $this->addPage($form1);
        $this->addPage($form2);
        $this->addPage($form3);
        $this->addPage($form4);

        $this->header = "(header) in: [pagecount: $this->pagecount] [currentpage: $this->currentpage] [Page 2 disable]";
        $this->getPage(2)->enabled = false;
        if ($this->page->isPostBack())
		{
            if ($this->getCurrentPage() == 4)
            {
               $fields = $this->getFieldList();
               $s = '';
               foreach($fields as $f)
               {
                   $s .= $f->name . ' = [' . Form::getFormValue($f->name) . ']<br>';
               }
               $form4->setFieldValue('tabfields',$s);
            }

            $this->eventHandler();
		}
        else
        {
            $this->setCurrentPage(3);
        }
        $this->footer = "(footer) out: [pagecount: $this->pagecount] [currentpage: $this->currentpage]";
	}
    
}

class FrmTabbedZero extends MForm
{
    public $tabbedForm;

    public function __construct($tabbedForm)
    {
        $this->tabbedForm = $tabbedForm;
        parent::__construct('Tabbed Zero');
    }

    public function createFields()
    {
        $fields1 = array(
			new MTextField('field0','','Campo 0',20),
            new MText('alert0','Button Post submited: header alterado')
        );
        $this->setFields($fields1); 
        $this->setFieldAttr('alert0','visible',false);
        $buttons = Array(
           new MButton('btnPostZero', 'Page Zero'),
           new MButton('btnGoOne', 'Goto Page One >>', $this->tabbedForm->goForward())
        );
	    $this->setButtons($buttons);
    }

    public function btnPost_click()
    {
        $this->setFieldAttr('alert0','visible',true);
    }
}

class FrmTabbedOne extends MForm
{
    public $tabbedForm;

    public function __construct($tabbedForm)
    {
        $this->tabbedForm = $tabbedForm;
        parent::__construct('Tabbed One');
    }

    public function createFields()
    {
        $options = array('Common','Example','SGA');
        $selection = new MSelection('selModule','','Module',$options);
        $selection->setAutoPostBack(true);

        $fields1 = array(
			$selection,
			new MTextField('field1','','Campo 1',20),
        );
        $this->setFields($fields1); 
        $buttons = Array(
           new MButton('btnPostOne', 'Page One'),
           new MButton('btnGoBack', ' << Go Back', $this->tabbedForm->goBack())
        );
	    $this->setButtons($buttons);
    }

    public function btnPost_click()
    {
        $tab = $this->tabbedform;
        $tab->header .= '[OnClick em btnPost da pagina 1]';
    }
}


class FrmTabbedTwo extends MForm
{
    public function __construct()
    {
       parent::__construct('Tabbed Two');
    }

    public function createFields()
    {
        $options = array('Common','Example','SGA');
        $selection = new MSelection('selModule','','Module',$options);
        $selection->setAutoPostBack(true);

        $fields2 = array(
			new MTextField('field2','','Campo 2',20),
			new MTextField('field2a','','Campo 2a',20)
        );
        $this->setFields($fields2); 
        $buttons = Array(
           new MButton('btnPostTwo', 'Page Two'),
        );
	    $this->setButtons($buttons);
        $validators = array(
           new MRequiredValidator('field2')
        );
        $this->setValidators($validators);
    }

    public function btnPost_click()
    {
        $this->tabbedform->header .= '[OnClick em btnPost da pagina 2]';
    }
}

class FrmTabbedThree extends MForm
{
    public function __construct()
    {
       parent::__construct('Tabbed Three');
       $chk = $this->getFieldAttr('chkBox','checked');
       $this->setFieldAttr('field3a','visible',$chk);
    }

    public function createFields()
    {
        $options = array('Common','Example','SGA');
        $selection = new MSelection('selModule','','Module',$options);
        $selection->setAutoPostBack(true);

        $fields3 = array(
			new MTextField('field3','','Campo 3',20),
            new MCheckBox('chkBox','value','Choice',true,'Campo 3a visible'),
			new MTextField('field3a','','Campo 3a',20),
            new MHContainer('', array(
               new MText('tx','Equipe composta por:'),
               new MTextField('eqp','','',5),
               new MText('tx2','programadores'))
            )
        );
        $this->setFields($fields3); 
        $buttons = Array(
           new MButton('btnPostThree', 'Page Three'),
        );
	    $this->setButtons($buttons);
    }
}

class FrmTabbedFour extends MForm
{
    public function __construct()
    {
       parent::__construct('Tabbed Four');
    }

    public function createFields()
    {
        $fields4 = array(
            new MTextLabel('tabfields','','Fields')
		);

        $this->setFields($fields4); 
    }
}
?>
