<?php
/**
 *
 * Penalty 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 23/09/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 FrmPenalty extends GnutecaForm
{
    public $MIOLO;
    public $module;
    public $businessLibraryUnit;


    function __construct()
    {
        $this->MIOLO    = MIOLO::getInstance();
        $this->module   = MIOLO::getCurrentModule();
        $this->businessLibraryUnit = $this->MIOLO->getBusiness( $this->module, 'BusLibraryUnit');

        $this->setAllFunctions('Penalty');
        $this->setPrimaryKeys('penaltyId');
        $this->setSaveArgs(array('personId', 'operator'));
        parent::__construct();
       	$this->setFocus('personId');
    }


    public function createFields()
    {
        if ($this->function != 'insert')
        {
            $penaltyId      = new MTextField('penaltyId', $this->penaltyId->value, _M('Code', $this->module), FIELD_ID_SIZE);
            $penaltyId->setReadOnly(TRUE);
            $fields[]       = $penaltyId;
            $validators[]   = new MIntegerValidator('penaltyId', null, 'required');
        }
        else
        {
            $operatorValue  = $this->MIOLO->getLogin()->id;
        }

        $personIdLabel = new MLabel(_M('Person code', $this->module) . ':');
        $personIdLabel->setWidth(FIELD_LABEL_SIZE);
        $personId = new MLookupTextField('personId', '', '', FIELD_LOOKUPFIELD_SIZE);
        $personId->setContext($this->module, $this->module, 'Person', 'filler', 'personId,personIdDescription');
        $personIdDescription = new MTextField('personIdDescription', $this->personIdDescription, NULL, FIELD_DESCRIPTION_LOOKUP_SIZE);
        $personIdDescription->setReadOnly(true);
        $fields[] = new MHcontainer('personIdContainer', array($personIdLabel, $personId, $personIdDescription));
        $validators[] = new MIntegerValidator('personId', _M('Person code', $this->module), 'required');

        $observation = new MMultiLineField('observation', $this->observation->value, _M('Observation', $this->module), null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
        $observation->hint = _M('This field is visible for students in its historical', $this->module);
        $fields[] = $observation;
        $validators[] = new MRequiredValidator('observation');

        $internalObservation = new MMultiLineField('internalObservation', $this->internalObservation->value, _M('Internal observation', $this->module), null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
        $fields[] = $internalObservation;

        $penaltyDate = new MCalendarField('penaltyDate', $this->penaltyDate->value, _M('Penalty date', $this->module), FIELD_DATE_SIZE, null);
        $fields[] = $penaltyDate;
        $validators[] = new MDateDMYValidator('penaltyDate', null);
        $validators[] = new MRequiredValidator('penaltyDate');

        $penaltyEndDate = new MCalendarField('penaltyEndDate', $this->penaltyEndDate->value, _M('Penalty end date', $this->module), FIELD_DATE_SIZE, null);
        $fields[] = $penaltyEndDate;
        $validators[] = new MDateDMYValidator('penaltyEndDate', null);

        $operator = new MTextField('operator', GnutecaOperator::getOperatorId(), _M('Operator', $this->module));
        $operator->setReadOnly(true);
        $fields[]       = $operator;
        $validators[]   = new MRequiredValidator('operator');

        $this->businessLibraryUnit->filterOperator = TRUE;
        $fields[]       = new GnutecaSelection('libraryUnitId',   $this->libraryUnitId->value, _M('Library unit', $this->module), $this->businessLibraryUnit->listLibraryUnit());

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

        if ($this->function == 'insert')
        {
            $this->penaltyDate->value = GnutecaDate::now( GnutecaDate::getDbMask('DATE') );
        }
    }


    public function loadFields()
    {
        $data = $this->business->getPenalty( MIOLO::_REQUEST('penaltyId') );
        $data->penaltyDate    = explode(' ', $data->penaltyDate);
        $data->penaltyDate    = $data->penaltyDate[0];
        $data->penaltyEndDate = explode(' ', $data->penaltyEndDate);
        $data->penaltyEndDate = $data->penaltyEndDate[0];
        $this->business->setData($data);
        $this->setData( $this->business );
    }
}
?>
