<?php
/**
 * Tag 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]
 *
 * @since
 * Class created on 25/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
 */


class FrmTagSearch extends GnutecaForm
{
    public function __construct()
    {
        $this->setAllFunctions('Tag', array('fieldIdS'));
        parent::__construct();
        if ( $this->primeiroAcessoAoForm() && strlen(MIOLO::_REQUEST('event')) == 0 )
        {
       	    $this->setFocus('fieldIdS');
        }
    }


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

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

        //$fields[] = new MMultiLIneField ('observationS', $this->observationS->value,  _M('Observation',   $this->module), null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);

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

        $lbl = new MLabel(_M('Has subfield', $this->module) . ':');
        $lbl->setWidth(FIELD_LABEL_SIZE);
        $hasSubfieldS = new MRadioButtonGroup('hasSubfieldS', null, GnutecaUtils::listYesNo(1), null, null, MRadioButtonGroup::LAYOUT_HORIZONTAL);
        $fields[] = new MHContainer('hctHasSubfieldS', array($lbl, $hasSubfieldS));

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

        $lbl = new MLabel(_M('In demonstration', $this->module) . ':');
        $lbl->setWidth(FIELD_LABEL_SIZE);
        $inDemonstrationS = new MRadioButtonGroup('inDemonstrationS', null, GnutecaUtils::listYesNo(1), null, null, MRadioButtonGroup::LAYOUT_HORIZONTAL);
        $fields[] = new MHContainer('hctInDemonstrationS', array($lbl, $inDemonstrationS));

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

        //$fields[] = new MMultiLIneField ('helpS', $this->helpS->value,  _M('Help', $this->module), null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);

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


    public function getGrid()
    {
        $data = $this->getData();

        //Filter only results with MARC_SPACE
        $data->subfieldIdS = MARC_SPACE;

        return parent::getGrid($data);
    }


    public function showSubfield()
    {
        $data->fieldIdS = MIOLO::_REQUEST('fieldId');
        $opts->toObject         = TRUE;
        $opts->excludeMarcSpace = TRUE;
        $this->business->setData($data);
        $search = $this->business->searchTag($opts);
        for ($i=0; $i < count($search); $i++)
        {
            $tbData[] = array($search[$i]->subfieldId,
                              $search[$i]->description);
        }
        $fields[] = new MLabel(_M('Code', $this->module) . ': '. $data->fieldIdS);
        $tbColumns = array(
            _M('Subfield code', $this->module),
            _M('Description', $this->module)
        );
        $tb = new MTableRaw('', $tbData, $tbColumns);
        $tb->zebra = TRUE;
        $fields[] = $tb;
        $this->setTitle(_M('Subfields', $this->module));
        $this->setFields($fields, false);
        parent::_showDetail($this);
    }
}
?>
