<?php
/**
 * Spreadsheet 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 26/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 FrmSpreadsheetSearch extends GnutecaForm
{
	public $MIOLO;
	public $module;
    public $busMarcTagListingOption;


    public function __construct()
    {
        $this->MIOLO    = MIOLO::getInstance();
        $this->module   = MIOLO::getCurrentModule();
        $this->busMarcTagListingOption = $this->MIOLO->getBusiness($this->module, 'BusMarcTagListingOption');
        $this->setAllFunctions('Spreadsheet', array('category'));
        parent::__construct();
        if ( $this->primeiroAcessoAoForm() && strlen(MIOLO::_REQUEST('event')) == 0)
        {
       	    $this->setFocus('categoryS');
        }
    }


    public function createFields()
    {
        $listCategory = $this->busMarcTagListingOption->listMarcTagListingOption('CATEGORY');
        $fields[] = new GnutecaSelection('categoryS', $this->categoryS->value, _M('Category', $this->module), $listCategory);

        $listLevel = $this->busMarcTagListingOption->listMarcTagListingOption('LEVEL');
        $fields[] = new GnutecaSelection('levelS', $this->levelS->value, _M('Level', $this->module), $listLevel);
        //$fields[] = new MMultiLIneField('fieldS', $this->fieldS->value, _M('Field', $this->module), null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
        $fields[] = new MTextField('fieldS', $this->fieldS->value, _M('Field', $this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = new MTextField('requiredS', $this->requiredS->value, _M('Work validator', $this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = new MTextField('repeatFieldRequiredS', $this->repeatFieldRequiredS->value, _M('Repeat field required', $this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = new MTextField('defaultValueS', $this->defaultValueS->value, _M('Default value', $this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = new MTextField('menuNameS', null, _M('Menu name', $this->module), FIELD_ID_SIZE);

        $this->setFields( $fields );
    }


    public function getGrid()
    {
        $this->business->setData( $this->getData() );
        $gridData = $this->business->searchSpreadsheet();

        if ($gridData)
        {
	        foreach ($gridData as $i => $v)
	        {
	            $gridData[$i][2] = str_replace("\n", "<br>", $v[2]);
	        }
        }
    	return parent::getGrid(null, $gridData);
    }
}
?>
