<?
    class frmForm extends MForm
    {
        public function __construct()
        {
            parent::__construct("Exemplo de Form - width:70%");
            $this->setWidth('70%');
            $this->eventHandler();
        }

        public function createFields()
        { 
            $selection1 = array('a','b','c','d','e');
            $selection2 = array('1','2','3','4','6');

            $mt = array(
                new MTextField('teste', '', 'a label'),
                new MSelection('selection1', '', 'Selection 1', $selection1),
                new MSelection('selection2', '', 'Selection 2', $selection2)
            );

            $mt0 = array(
                new MTextField('teste0', '', 'a label'),
                new MSelection('selection1a', '', 'Selection 1a', $selection1),
                new MSelection('selection2a', '', 'Selection 2a', $selection2)
            );

            $checks = array(
                new MCheckBox('chk1','c1','Label Check1', true,'Text Check1'),
                new MCheckBox('chk2','c2','Label Check2', false,'Text Check2'),
                new MCheckBox('chk3','c3','Label Check3', true,'Text Check3'),
                new MCheckBox('chk4','c4','Label Check4', false,'Text Check4'),
                new MCheckBox('chk5','c5','Label Check5', true,'Text Check5')
            );

            $options = array(
                new MOption('opt1','o1','Label Option1', false),
                new MOption('opt2','o2','Label Option2', false),
                new MOption('opt3','o3','Label Option3', false),
                new MOption('opt4','o4','Label Option4', false),
                new MOption('opt5','o5','Label Option5', false)
            );
 
            $fields = array (
                new MBaseGroup('bp', 'A MBaseGroup', $mt),
                new MTextField('idaluno', '', 'Id'),
                new MLookupTextField('aluno', '', 'formMode=1',20, 'formMode=1'),
                new MCalendarField('cal', '', "formMode = 2"),
                new MSelection('idgroup', '', 'formMode = 3', $selection1),
                new MSeparator(),
                new MTextLabel('text','Field com 70%', 'Label com 25%'),
                new MSeparator(),
                new MCheckBoxGroup('grpChk','MCheckBoxGroup Label - using MCheckBox', $checks,'','vertical','css'),
                new MCheckBoxGroup('grpOpt','MCheckBoxGroup Label - using MOption', $options,'','horizontal','css'),
                new MRadioButtonGroup('grpOptRadio','MRadioButtonGroup Label - using MOption', $options,'o4','','horizontal','css'),
                new MMultiTextField3('grupos', null, 'Acesso', $mt0, 200, true, 'horizontal'),
            );

            $this->setFields($fields);
            $this->setFieldAttr('bp', 'showLabel', true);
            $this->setFieldAttr('idaluno', 'visible', false);
            $this->setFieldAttr('aluno', 'formMode', '1');
            $this->setFieldAttr('cal', 'formMode', '2');
            $this->setFieldAttr('idgroup', 'formMode', '3');
            $this->setFieldAttr('aluno', 'module', 'example');
            $this->setFieldAttr('aluno', 'item', 'aluno');
            $this->setFieldAttr('aluno', 'event', 'btnEdit:click');
            $this->setLabelWidth('25');
            $this->setFocus('aluno');

            $buttons = Array
                (
                new MButton('btnPost', 'Enviar'),
                new MButton('btnNew', 'Novo'),
                new MButton('btnBgColor', 'BgColor Blue'),
                );

            $this->setButtons($buttons);
        }

        public function btnPost_click()
        {
            $v = $this->grpChk->getValue();
            $values = array();
            foreach($v as $name=>$value)
            {
                $values[] = array($name,$value);
            }
            $this->addField(new MTableRaw('grpChk Value',$values));

            $v = $this->grpOpt->getValue();
            $values = array();
            foreach($v as $name=>$value)
            {
                $values[] = array($name,$value);
            }
            $this->addField(new MTableRaw('grpOpt Value',$values));

            $v = $this->grpOptRadio->getValue();
            $this->addField(new MLabel('grpOptRadio Value = ' . $v));
        }

        public function btnEdit_click($key = '')
        {
        }

        public function btnBgColor_click()
        {
            $this->setBackgroundColor('blue');
        }

    }
?>
