<?php
/**
 * Answered reserves 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 17/11/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 FrmAnsweredReserves extends GnutecaForm
{
    public $MIOLO;
    public $module;
    public $busOperationReserve;
    public $busLibraryUnit;


    public function __construct()
    {
        $this->MIOLO  = MIOLO::getInstance();
        $this->module = MIOLO::getCurrentModule();
        $this->busOperationReserve = $this->MIOLO->getBusiness($this->module, 'BusOperationReserve');
        $this->busLibraryUnit   = $this->MIOLO->getBusiness($this->module, 'BusLibraryUnit');
        parent::__construct(_M('Communicate answered reserves', $this->module));
        $this->eventHandler();
    }


    public function createFields()
    {
        $lblInfo = new MLabel(_M('Communicates by email users who have answered reserves', $this->module));
        $lblInfo->setBold(true);
        $fields[] = $lblInfo;

        $this->busLibraryUnit->filterOperator = TRUE;
        $fields[] = new GnutecaSelection('libraryUnitId', null, _M('Library unit', $this->module), $this->busLibraryUnit->listLibraryUnit(), NULL, NULL, NULL, TRUE);
        $fields[] = new MButton('btnOk', _M('Send', $this->module), ':doAction');
        $fields[] = new MDiv('divGrid');

        $this->setFields($fields);
    }


    public function doAction()
    {
        $data   = $this->getData();
        $this->busOperationReserve->setLibraryUnit($data->libraryUnitId);
        $ok     = $this->busOperationReserve->comunicateReserveAnswered();
        $goto   = $this->MIOLO->getActionURL($this->module, $this->_action);

        if (($data = $this->busOperationReserve->getGridData()) && (count($data) > 0))
        {
            $grid = $this->MIOLO->getUI()->getGrid($this->module, 'GrdOperationReserve');
            $grid->setData($data);
            $this->setResponse($grid, 'divGrid');
        }
        else if (count($this->busOperationReserve->getMessages()) > 0)
        {
            $this->injectContent($this->busOperationReserve->getMessagesTableRaw(), true);
        }
        else
        {
            $this->information(_M('There are no answered reserves to be commmunicate', $this->module), $goto);
        }
    }
}
?>
