<?php
/**
 * News search form
 *
 * @author Sandro Roberto Weisheimer [sandrow@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 19/03/2009
 *
 * \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 FrmNewsSearch extends GnutecaForm
{
    public $MIOLO;
    public $module;
    public $action;
    public $busNewsAccess;

    public function __construct()
    {
        $this->setAllFunctions('News', array('newsIdS','placeS'));
        $this->MIOLO                    = MIOLO::getInstance();
        $this->module                   = MIOLO::getCurrentModule();
        $this->action                   = MIOLO::getCurrentAction();
        $this->function                 = MIOLO::_REQUEST('function');
        $this->busNewsAccess    = $this->MIOLO->getBusiness($this->module, 'BusNewsAccess');
        parent::__construct();
        if ( $this->primeiroAcessoAoForm() && strlen(MIOLO::_REQUEST('event')) == 0 )
        {
       	    $this->setFocus('newsIdS');
        }
    }


    public function createFields()
    {
        $fieldIdS    = new MTextField('newsIdS', $this->newsIdS->value, _M('Code', $this->module), 3);
        $fields[]    = $fieldIdS;

        $placeS       = new GnutecaSelection('placeS', $this->typeS->value, _M('Place', $this->module), $this->business->listPlace(), null, null, null, FALSE);
        $fields[]    = $placeS;

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

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

        $lblDate             = new MLabel(_M('Date', $this->module) . ':');
        $lblDate->setWidth(FIELD_LABEL_SIZE);
        $beginDateS     = new MCalendarField('beginDateS', $this->beginDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $endDateS       = new MCalendarField('endDateS', $this->endDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $fields[] = new MHContainer('hctDates', array($lblDate, $beginDateS, $endDateS));

        $lblDate             = new MLabel(_M('Begin date', $this->module) . ':');
        $lblDate->setWidth(FIELD_LABEL_SIZE);
        $beginBeginDateS     = new MCalendarField('beginBeginDateS', $this->beginBeginDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $endBeginDateS       = new MCalendarField('endBeginDateS', $this->endBeginDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $fields[] = new MHContainer('hctDates', array($lblDate, $beginBeginDateS, $endBeginDateS));

        $lblDate             = new MLabel(_M('End date', $this->module) . ':');
        $lblDate->setWidth(FIELD_LABEL_SIZE);
        $beginEndDateS     = new MCalendarField('beginEndDateS', $this->beginEndDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $endEndDateS       = new MCalendarField('endEndDateS', $this->endEndDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $fields[] = new MHContainer('hctDates', array($lblDate, $beginEndDateS, $endEndDateS));

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

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

        $lbla = new MLabel(_M('Is active', $this->module) . ':');
        $lbla->setWidth(FIELD_LABEL_SIZE);
        $isActive = new MRadioButtonGroup('isActiveS', null, GnutecaUtils::listYesNo(1), $isActiveValue, null, MRadioButtonGroup::LAYOUT_HORIZONTAL);
        $fields[] = new MHContainer('hctIsActive', array($lbla, $isActive));

        $this->setFields($fields);
    }

    public function showGroups()
    {
        $data->newsIdS = MIOLO::_REQUEST('newsId');
        $this->busNewsAccess->setData($data);
        $search = $this->busNewsAccess->searchNewsAccess(TRUE);

        if ($search)
        {
	        for ($i=0; $i < count($search); $i++)
	        {
	            $tbData[] = array(
	                $search[$i]->description
	            );
	        }
	        $fields[] = new MLabel(_M('News code', $this->module) . ': '. $data->newsIdS);
	        $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);
    }

}
?>
