<?php
/**
 *
 *
 *
 * @author Eduardo Bonfandini [eduardo@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 29/07/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
 *
 **/
class FrmGeneralPolicy extends GnutecaForm
{
    public $businessPrivilegeGroup;
    public $businessLink;

    function __construct()
    {
        MIOLO::getInstance()->getClass('gnuteca3', 'GnutecaIntegerField');
        $this->businessPrivilegeGroup   = MIOLO::getInstance()->getBusiness(MIOLO::getCurrentModule(), 'BusPrivilegeGroup');
        $this->businessLink     = MIOLO::getInstance()->getBusiness(MIOLO::getCurrentModule(), 'BusBond');
        $this->setAllFunctions('GeneralPolicy', array('privilegeGroupIdS','linkIdS'), array('privilegeGroupId','linkId'), 'privilegeGroupId');
        parent::__construct();
        $this->page->onLoad("document.getElementById('linkList').style.height = '270px';");
    }

    public function createFields()
    {
        if ( $this->function != 'update' )
        {
            $privilegeGroupId = new GnutecaSelection('privilegeGroupId', $this->privilegeGroupId->value, _M('Privilege group',$this->module), $this->businessPrivilegeGroup->listPrivilegeGroup());
            $this->setFocus('privilegeGroupId');
            $fields[] = $privilegeGroupId;
            $validators[] = new MRequiredValidator('privilegeGroupId');
        }
        else
        {
            $fields[] = new MHiddenField('privilegeGroupId');
            $privilegeGroupId = new MTextField('privilegeGroupDescription', $this->privilegeGroupId->value, _M('Privilege group code',$this->module), FIELD_ID_SIZE);
            $privilegeGroupId->setReadOnly(true);
            $fields[] = $privilegeGroupId;
        }

        if ( $this->function != 'update' )
        {
            $optionsBond = $this->businessLink->listBond();
            $linkList = new MMultiSelection('linkList', array(null), _M('Link',$this->module), $optionsBond, null, null, count($optionsBond));
            $fields[] = $linkList;
            $validators[] = new MRequiredValidator('linkList');
        }
        else
        {
            $this->setFocus('loanGeneralLimit');
            $fields[] = new MHiddenField('linkId');
            $linkId = new MTextField('linkDescription', $this->linkDescription->value, _M('Link code',$this->module), FIELD_ID_SIZE);
            $linkId->setReadOnly(true);
            $fields[] = $linkId;
        }

        $fields[]       = new GnutecaIntegerField('loanGeneralLimit', null, _M('Loan limit', $this->module));
        $validators[]   = new MRequiredValidator('loanGeneralLimit');
        $fields[]       = new GnutecaIntegerField('reserveGeneralLimit', null, _M('Reserve limit', $this->module));
        $validators[] = new MRequiredValidator('reserveGeneralLimit');
        $fields[]       = new GnutecaIntegerField('reserveGeneralLimitIninitialLevel', null, _M('Reserve limit at initial level', $this->module));
        $validators[] = new MRequiredValidator('reserveGeneralLimitIninitialLevel');
        $this->setFields($fields);
        $this->setValidators($validators);
    }
}
?>
