<?
class frmLookup extends MForm
{
    public function frmLookup()
    {   
		global $MIOLO, $self, $module, $page, $action;

		parent::__construct('Lookup Sample');
        $curso = $MIOLO->GetBusiness('example','curso');
        $query = $curso->listAll();

        $fields = array(
  		   new MHiddenField('key',''),
           new MSeparator('MLookupField, with 2 fields for lookup with filler'),
           array(
              new MSelection('selField','','MSelection - Curso',$query->result),
		      new MTextField('txtField','','MTextField - Aluno', 45),
              new MLookupField('lkpField','&nbsp;','&nbsp;')
           ),
           new MSpacer('15px'),
           new MSeparator('MLookupTextField with autocomplete'),
           new MLookupTextField('lkpAlunoId','','Id Aluno', 5),
           new MTextField('lkpAlunoIdNome','','Aluno', 45),
           new MTextField('lkpAlunoIdCurso','','Curso', 45),
           new MSpacer('15px'),
           new MSeparator('MLookupTextField with filler'),
           new MLookupTextField('lkpAluno','','Aluno', 45),
           new MTextField('lkpAlunoCurso','','Curso', 45),
           new MSpacer('15px'),
           new MSeparator('MLookupTextField using cursor with filler'),
           new MLookupTextField('lkpAlunoObj','','Aluno', 45),
           new MSpacer('15px'),
           new MSeparator('MLookupTextField using query with filler'),
           new MLookupTextField('lkpAlunoQuery','','Aluno', 45),
           new MSpacer('15px'),
           new MSeparator('MLookupTextField with event'),
		   new MLookupTextField('lkpAlunoEvent','','Aluno', 45),
           new MText('lblIdAluno',''),
           new MSpacer('15px'),
           new MSeparator('MLookupFieldValue with filler'),
		   new MLookupFieldValue('lkpFieldTest','','Aluno', 45),
 		);
  	   $this->SetFields($fields);
//       $this->SetFieldAttr('selField','options', $objQuery->result);

       // lkpField - with 2 fields and filler
       // baseModule - module with a lookup.inc at /handlers to... handler lookups :-) 
	   $this->SetFieldAttr('lkpField','baseModule','example');
       // module - module with a lookup.class at /classes (/db)  
	   $this->SetFieldAttr('lkpField','module','example');
       // item - a method of lookup.class to handle _this_ lookup
       // the method is named Business<Module><Item>, so: BusinessexampleCursoAluno
	   $this->SetFieldAttr('lkpField','item','cursoaluno');
       // event - how to handler the response?
       // - filler : fill the 'related' fields with the response
       // - method : calls the event method
	   $this->SetFieldAttr('lkpField','event','filler');
       // related - in conjuntion with event=filler it indicates the fields to be filled
       // the order MUST BE equal the order of columns of lookup grid 
       // "none" is used when there is no field corresponding to column
	   $this->SetFieldAttr('lkpField','related','none,txtField,selField,none');
       // filter - fields whose values will be used later on lookup filter
	   $this->SetFieldAttr('lkpField','filter','selField,txtField');

       // lkpAluno - with filler - using setContext
       $this->lkpAluno->setContext('example','example','aluno','filler','key,lkpAluno,lkpAlunoCurso');
//	   $this->SetFieldAttr('lkpAluno','baseModule','example');
//	   $this->SetFieldAttr('lkpAluno','module','example');
//	   $this->SetFieldAttr('lkpAluno','item','aluno');
//	   $this->SetFieldAttr('lkpAluno','event','filler');
//	   $this->SetFieldAttr('lkpAluno','related','key,lkpAluno');

       // lkpAlunoID with autocomplete
	   $this->SetFieldAttr('lkpAlunoId','baseModule','example');
	   $this->SetFieldAttr('lkpAlunoId','module','example');
	   $this->SetFieldAttr('lkpAlunoId','item','alunoid');
	   $this->SetFieldAttr('lkpAlunoId','autocomplete',true);
	   $this->SetFieldAttr('lkpAlunoId','related','lkpAlunoIdNome,lkpAlunoIdCurso');

       // lkpAluno using cursor - with filler
	   $this->SetFieldAttr('lkpAlunoObj','baseModule','example');
	   $this->SetFieldAttr('lkpAlunoObj','module','example');
	   $this->SetFieldAttr('lkpAlunoObj','item','objaluno');
	   $this->SetFieldAttr('lkpAlunoObj','event','filler');
	   $this->SetFieldAttr('lkpAlunoObj','related','key,lkpAlunoObj');

       // lkpAluno using query - with filler
	   $this->SetFieldAttr('lkpAlunoQuery','baseModule','example');
	   $this->SetFieldAttr('lkpAlunoQuery','module','example');
	   $this->SetFieldAttr('lkpAlunoQuery','item','queryaluno');
	   $this->SetFieldAttr('lkpAlunoQuery','event','filler');
	   $this->SetFieldAttr('lkpAlunoQuery','related','key,lkpAlunoQuery');

       // lkpTransaction - with event
	   $this->SetFieldAttr('lkpAlunoEvent','baseModule','example');
	   $this->SetFieldAttr('lkpAlunoEvent','module','example');
	   $this->SetFieldAttr('lkpAlunoEvent','item','aluno');
	   $this->SetFieldAttr('lkpAlunoEvent','event','btnShow:click');
	   $this->SetFieldAttr('lkpAlunoEvent','autocomplete',false);

       // lkpFieldTest - with filler
	   $this->SetFieldAttr('lkpFieldTest','baseModule','example');
	   $this->SetFieldAttr('lkpFieldTest','module','example');
	   $this->SetFieldAttr('lkpFieldTest','item','aluno');
	   $this->SetFieldAttr('lkpFieldTest','event','filler');
	   $this->SetFieldAttr('lkpFieldTest','related','key,lkpFieldTest');
	   $this->SetFieldAttr('lkpFieldTest','filter','lkpFieldTest');

       $this->SetFieldAttr('lblIdTrans','visible',false);
        $buttons = Array(
           new MButton('btnPost', 'Enviar'),
        );
	    $this->SetButtons($buttons);
    	$this->GetData();
        $this->EventHandler();
	}

    function btnShow_click($key='')
    {
       // what about key? key is the value at the column 0 of selected row at lookupgrid...
       $this->SetFieldAttr('lblIdAluno','visible',true);
       $this->SetFieldAttr('lblIdAluno','value',"Id Aluno = $key");
       // to get the other attributes, i need to instance a object
       $aluno = $this->manager->getBusiness('example','aluno',$key);
       $this->SetFieldValue('lkpAlunoEvent', $aluno->nome);
    }

}
?>