<?php
/**
 *
 * Holiday 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 28/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 FrmHoliday extends GnutecaForm
{
    public $MIOLO;
    public $module;
    public $busLibraryUnit;


    public function __construct()
    {
        $this->MIOLO    = MIOLO::getInstance();
        $this->module   = MIOLO::getCurrentModule();
        $this->function = MIOLO::_REQUEST('function');
        $this->busLibraryUnit = $this->MIOLO->getBusiness($this->module, 'BusLibraryUnit');
        $this->setAllFunctions('Holiday', null, 'holidayId', 'description');
        parent::__construct();
        $this->setFocus('date');
    }


    public function createFields()
    {
        if ($this->function != "insert")
        {
            $holidayId = new MTextField('holidayId', $this->holidayId->value, _M('Code',$this->module), FIELD_ID_SIZE);
            $holidayId->setReadOnly(true);
            $fields[] = $holidayId;
            $validators[] = new MRequiredValidator('holidayId');
            $validators[] = new MIntegerValidator('holidayId');
        }

        $date = new MCalendarField('date', $date, _M('Date',$this->module),FIELD_DATE_SIZE);
        $validators[] = new MRequiredValidator('date');
        $fields[] = $date;

        $description = new MTextField('description', $this->description->value, _M('Description',$this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = $description;
        $validators[] = new MRequiredValidator('description');

        $lbl = new MLabel(_M('All year', $this->module) . ':');
        $lbl->setWidth(FIELD_LABEL_SIZE);
        $occursAllYear = new MRadioButtonGroup('occursAllYear', null, GnutecaUtils::listYesNo(1), 'f', null, MRadioButtonGroup::LAYOUT_HORIZONTAL);
        $fields[] = new MHContainer('hctOccoursAllYear', array($lbl, $occursAllYear));
        $validators[] = new MRequiredValidator('occursAllYear', _M('All year', $this->module));

        $this->busLibraryUnit->filterOperator = TRUE;
        $list       = $this->busLibraryUnit->listLibraryUnit();
        $hideDefSel = ! $this->busLibraryUnit->operatorAllLibraries;
        $fields[] = new GnutecaSelection('libraryUnitId', null, _M("Library unit", $this->module), $list, null, null, null, $hideDefSel);

        $this->setFields($fields);
        if ( isset($validators) )
        {
            $this->setValidators($validators);
        }
    }
}
?>
