<?php
/**
 * Bond form
 *
 * @author Moises Heberle [moises@solis.coop.br]
 *
 * @version $Id$
 *
 * \b Maintainers \n
 * Eduardo Bonfandini [eduardo@solis.coop.br]
 * Jamiel Spezia [jamiel@solis.coop.br]
 * Luiz Gregory Filho [luiz@solis.coop.br]
 * Moises Heberle [moises@solis.coop.br]
 *
 * @since
 * Class created on 06/08/2008
 *
 * \b Organization: \n
 * SOLIS - Cooperativa de Solucoes Livres \n
 * The Gnuteca3 Development Team
 *
 * \b CopyLeft: \n
 * CopyLeft (L) 2008 SOLIS - Cooperativa de Solucoes Livres \n
 *
 * \b License: \n
 * Licensed under GPL (for further details read the COPYING file or http://www.gnu.org/copyleft/gpl.html )
 *
 * \b History: \n
 * See history in SVN repository: http://gnuteca.solis.coop.br
 */


/**
 * Form to manipulate a preference
 **/
class FrmBond extends GnutecaForm
{
    function __construct()
    {
        $this->setAllFunctions('Bond');
        $this->setPrimaryKeys(array('personId', 'linkId'));
        $this->setSaveArgs(array('personId', 'linkId'));
        parent::__construct();
    }


    public function createFields()
    {
        if ($this->function != "insert")
        {
            $personLabel = new MLabel (_M('Person code',$this->module));
            $personLabel->setWidth(FIELD_LABEL_SIZE);
            $personId = new MLookupTextField ('personId',$this->personId->value,'', FIELD_LOOKUPFIELD_SIZE);
            $personId->setContext($this->module, $this->module, 'Person', 'filler', 'personId,personIdName');
            $personId->baseModule = $this->module;
            $personId->setReadOnly(true);
            $validators[] = new MRequiredValidator('personId', _M('Person code', $this->module));
            $personIdName = new MTextField ('personIdName','',null, FIELD_DESCRIPTION_LOOKUP_SIZE);
            $personIdName->setReadOnly(true);
            $personCont = new MHcontainer('personCont', array ($personLabel, $personId, $personIdName));
            $fields[] = $personCont;

            $linkLabel = new MLabel (_M('User group code',$this->module));
            $linkLabel->setWidth(FIELD_LABEL_SIZE);
            $linkId = new MLookupTextField ('linkId',$this->linkId->value,'',FIELD_LOOKUPFIELD_SIZE);
            $linkId->setContext($this->module, $this->module, 'link', 'filler', 'linkId,linkIdName');
            $linkId->baseModule = $this->module;
            $linkId->setReadOnly(true);
            $validators[] = new MRequiredValidator('linkId', _M('User group code', $this->module));
            $linkIdName = new MTextField ('linkIdName','',null, FIELD_DESCRIPTION_LOOKUP_SIZE);
            $linkIdName->setReadOnly(true);
            $linkCont = new MHcontainer('linkCont', array ($linkLabel, $linkId, $linkIdName));
            $fields[] = $linkCont;

        }
        elseif ($this->function == "insert")
        {
           	$this->setFocus('personId');
            $personLabel = new MLabel (_M('Person code',$this->module));
            $personLabel->setWidth(FIELD_LABEL_SIZE);
            $personId = new MLookupTextField ('personId',$this->personId->value,'',FIELD_LOOKUPFIELD_SIZE);
            $personId->setContext($this->module, $this->module, 'Person', 'filler', 'personId,personIdName');
            $validators[] = new MRequiredValidator('personId', _M('Person code', $this->module));
            $personIdName = new MTextField ('personIdName','',null, FIELD_DESCRIPTION_LOOKUP_SIZE);
            $personIdName->setReadOnly(true);
            $personCont = new MHcontainer('personCont', array ($personLabel, $personId, $personIdName));
            $fields[] = $personCont;

            $linkLabel = new MLabel(_M('User group code',$this->module));
            $linkLabel->setWidth(FIELD_LABEL_SIZE);
            $linkId = new MLookupTextField ('linkId',$this->linkId->value,'',FIELD_LOOKUPFIELD_SIZE, null, null, 'linkIdName', $this->module, 'link');
            $linkId->setContext($this->module, $this->module, 'link', 'filler', 'linkId,linkIdName');

            $linkId->baseModule = $this->module;
            $validators[] = new MRequiredValidator('linkId', _M('User group code', $this->module));
            $linkIdName = new MTextField ('linkIdName','',null, FIELD_DESCRIPTION_LOOKUP_SIZE);
            $linkIdName->setReadOnly(true);
            $linkCont = new MHcontainer('linkCont', array ($linkLabel, $linkId, $linkIdName));
            $fields[] = $linkCont;
        }

        $dateValidate = new MCalendarField('dateValidate', NULL, _M('Date validate', $this->module), FIELD_DATE_SIZE, null);
        $fields[] = $dateValidate;
        $validators[] = new MDateDMYValidator('dateValidate', NULL, 'required');

        $this->setFields($fields);
        $this->setValidators($validators);
    }


    public function loadFields()
    {
        //Condition for not bug busBond
        $data = $this->business->getBond( MIOLO::_REQUEST('personId') , MIOLO::_REQUEST('linkId') );
        $this->business->setData($data);
        $this->setData($this->business);
    }
}
?>
