<?php
/**
 *
 * Library Unit search 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]
 * Sandro Roberto Weisheimer [sandrow@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 FrmLibraryUnitSearch extends GnutecaForm
{
    public  $MIOLO,
            $module,
            $action,
            $grid,
            $function,
            $businessLibraryGroup,
            $busLibraryUnitAccess,
            $busBond,
            $busLibraryUnitIsClosed,
            $busWeekDay,
            $businessPrivilegeGroup;

    public function __construct()
    {
        $this->setAllFunctions('LibraryUnit', array('libraryUnitIdS','libraryNameS'));
        $this->MIOLO                    = MIOLO::getInstance();
        $this->module                   = MIOLO::getCurrentModule();
        $this->action                   = MIOLO::getCurrentAction();
        $this->function                 = MIOLO::_REQUEST('function');
        $this->business                 = $this->MIOLO->getBusiness( $this->module, 'BusLibraryUnit');
        $this->businessLibraryGroup     = $this->MIOLO->getBusiness( $this->module, 'BusLibraryGroup');
        $this->businessPrivilegeGroup   = $this->MIOLO->getBusiness( $this->module, 'BusPrivilegeGroup');
        $this->busLibraryUnitIsClosed    = $this->MIOLO->getBusiness($this->module, 'BusLibraryUnitIsClosed');
        $this->busLibraryUnitAccess    = $this->MIOLO->getBusiness($this->module, 'BusLibraryUnitAccess');
        $this->busBond    = $this->MIOLO->getBusiness($this->module, 'BusBond');
        $this->busWeekDay    = $this->MIOLO->getBusiness($this->module, 'BusWeekDay');
        parent::__construct();
        if ( $this->primeiroAcessoAoForm() && strlen(MIOLO::_REQUEST('event')) == 0 )
        {
            $this->setFocus('libraryUnitIdS');
        }
    }


    public function createFields()
    {
        $libraryUnitIdS = new MTextField('libraryUnitIdS', '', _M('Code',$this->module), FIELD_ID_SIZE);
        $fields[] = $libraryUnitIdS;
        $validators[] = new MIntegerValidator('libraryUnitIdS');

        $libraryNameS = new MTextField('libraryNameS', $this->libraryNameS->value, _M('Name',$this->module),FIELD_DESCRIPTION_SIZE );
        $fields[] = $libraryNameS;

        $lbl = new MLabel(_M('Is restricted', $this->module) . ':');
        $lbl->setWidth(FIELD_LABEL_SIZE);
        $isRestrictedS = new MRadioButtonGroup('isRestrictedS', null, GnutecaUtils::listYesNo(1), null, null, MRadioButtonGroup::LAYOUT_HORIZONTAL);
        $fields[] = new MHContainer('hctIsRestrictedS', array($lbl, $isRestrictedS));

        $cityS = new MTextField('cityS', $this->city->value, _M('City',$this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = $cityS;

        $privilegeGroupIdS = new GnutecaSelection('privilegeGroupIdS', $this->privilegeGroupId->value, _M('Privilege group',$this->module), $this->businessPrivilegeGroup->listPrivilegeGroup());
        $fields[] = $privilegeGroupIdS;

        $libraryGroupId = new GnutecaSelection('libraryGroupIdS', $this->libraryGroupId->value, _M('Library group',$this->module), $this->businessLibraryGroup->listLibraryGroup());
        $fields[] = $libraryGroupId;

        $this->business->filterOperator = TRUE;
        $this->business->labelAllLibrary = TRUE;
        $listLibraryUnit = $this->business->listLibraryUnit();
        $fields[] = new GnutecaSelection('libraryUnitIdSelect', null, _M('Library unit', $this->module), $listLibraryUnit, null, null, null, TRUE);

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

    public function showDays()
    {
        $data->libraryUnitIdS = MIOLO::_REQUEST('libraryUnitId');
        $this->busLibraryUnitIsClosed->setData($data);
        $search = $this->busLibraryUnitIsClosed->searchLibraryUnitIsClosed(TRUE);
        if ($search)
        {
	        for ($i=0; $i < count($search); $i++)
	        {
	            $tbData[] = array(
	                $search[$i]->weekDescription
	            );
	        }
	        $fields[] = new MLabel(_M('Library unit code', $this->module) . ': '. $data->libraryUnitIdS);
	        $tbColumns = array(
	            _M('Week day', $this->module),
	        );
	        $tb = new MTableRaw('', $tbData, $tbColumns);
	        $tb->zebra = TRUE;
	        $fields[] = $this->getDefaultDetailDiv($tb);
        }
        else
        {
        	$fields[] = new MLabel(_M('No record found.', $this->module));
        }
        $this->setTitle(_M('Days', $this->module));
        $this->setFields($fields, false);
        parent::_showDetail($this);
    }

    public function showGroups()
    {
        $data->libraryUnitIdS = MIOLO::_REQUEST('libraryUnitId');
        $this->busLibraryUnitAccess->setData($data);
        $search = $this->busLibraryUnitAccess->searchLibraryUnitAccess(TRUE);

        if ($search)
        {
	        for ($i=0; $i < count($search); $i++)
	        {
	            $tbData[] = array(
	                $search[$i]->description
	            );
	        }
	        $fields[] = new MLabel(_M('Library unit code', $this->module) . ': '. $data->libraryUnitIdS);
	        $tbColumns = array(
	            _M('Group', $this->module)
	        );
	        $tb = new MTableRaw('', $tbData, $tbColumns);
	        $tb->zebra = TRUE;
	        $fields[] = $this->getDefaultDetailDiv($tb);
        }
        else
        {
        	$fields[] = new MLabel(_M('No record found.', $this->module));
        }
        $this->setTitle(_M('Group', $this->module));
        $this->setFields($fields, false);
        parent::_showDetail($this);
    }

}
?>
