<?php
/**
 *
 * Spreadsheet 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 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 FrmSpreadsheet 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');
        if (!$_REQUEST['level'])
        {
        	$_REQUEST['level'] = '#';
        }
        $this->setAllFunctions('Spreadsheet', null, array('category', 'level'), array('category', 'level'));
        parent::__construct();
    }


    public function createFields()
    {
        if ($this->function == 'update')
        {
           	$this->setFocus('field');
            $category = new MTextField('category', $this->category->value, _M('Category', $this->module));
            $category->setReadOnly(TRUE);
            $fields[] = $category;
            $level = new MTextField('level', $this->level->value, _M('Level', $this->module));
            $level->setReadOnly(TRUE);
            $fields[] = $level;
        }
        else if ($this->function == 'insert')
        {
           	$this->setFocus('category');
            $listCategory = $this->busMarcTagListingOption->listMarcTagListingOption('CATEGORY');
            $fields[] = new GnutecaSelection('category', $this->category->value, _M('Category', $this->module), $listCategory);
            $validators[] = new MRequiredValidator('category');

            $listLevel = $this->busMarcTagListingOption->listMarcTagListingOption('LEVEL');
            $fields[] = new GnutecaSelection('level', $this->level->value, _M('Level', $this->module), $listLevel);
            $validators[] = new MRequiredValidator('level');
        }

        $fields[] = new MMultiLIneField('field', $this->field->value, _M('Field', $this->module), null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
        $validators[] = new MRequiredValidator('field');

        // REQUIRED BOX
        $requiredLabel  = new MLabel( _M('Work validator', $this->module) . ':' );
        $requiredLabel  ->setWidth(FIELD_LABEL_SIZE);
        $required       = new MMultiLIneField   ('required', $this->required->value, null, null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
        $requiredHelp   = $this->getFieldHelpButton('required');
        $fields[]       = new MHContainer       ("requiredContainer", array($requiredLabel, $required, $requiredHelp));


        // REQUIRED BOX
        $repeatFieldRequiredLabel   = new MLabel( _M('Repeat field validator', $this->module) . ':' );
        $repeatFieldRequiredLabel   ->setWidth(FIELD_LABEL_SIZE);
        $repeatFieldRequired        = new MMultiLIneField   ('repeatFieldRequired', $this->repeatFieldRequired->value, null, null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
        $repeatFieldRequiredHelp    = $this->getFieldHelpButton('repeatFieldRequired');
        $fields[]                   = new MHContainer       ("repeatFieldRequiredContainer", array($repeatFieldRequiredLabel, $repeatFieldRequired, $repeatFieldRequiredHelp));


        // DEFAULT VALUE BOX
        $defaultValueLabel  = new MLabel( _M('Default value', $this->module) . ':' );
        $defaultValueLabel  ->setWidth(FIELD_LABEL_SIZE);
        $defaultValue       = new MMultiLIneField   ('defaultValue', $this->defaultValue->value, null, null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
        $defaultValueHelp   = $this->getFieldHelpButton('defaultValue');
        $fields[]           = new MHContainer       ("defaultValueContainer", array($defaultValueLabel, $defaultValue, $defaultValueHelp));


        // MENU BASE GROUP
        $lblMenuName    = new MLabel( _M('Menu name',   $this->module) . ':' );
        $lblMenuLevel   = new MLabel( _M('Level',       $this->module) . ':' );
        $lblMenuOption  = new MLabel( _M('Option',      $this->module) . ':' );

        $lblMenuName    ->setWidth(FIELD_LABEL_SIZE);
        $lblMenuLevel   ->setWidth(FIELD_LABEL_SIZE);
        $lblMenuOption  ->setWidth(FIELD_LABEL_SIZE);

        $menuLevel      = new MTextField('menuLevel',   null, null, FIELD_ID_SIZE);
        $menuName       = new MTextField('menuName',    null, null, FIELD_DESCRIPTION_SIZE);
        $menuOption     = new MTextField('menuOption',  null, null, FIELD_DESCRIPTION_SIZE);

        $controls[]     = new MHContainer("menuNameContainer",      array($lblMenuName,     $menuName));
        $controls[]     = new MHContainer("menuOptionContainer",    array($lblMenuOption,   $menuOption));
        $controls[]     = new MHContainer("menuLevelContainer",     array($lblMenuLevel,     $menuLevel));

        $fields[]       = new MBaseGroup("baseGMenu", _M('Menu', $this->module), $controls, 'vertical');

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

        $arrayContent = array
        (
            'defaultValue'          => HELP_FIELD_SPREADSHEET_DEFAULT_VALUES,
            'required'              => HELP_FIELD_SPREADSHEET_WORK_VALIDATOR,
            'repeatFieldRequired'   => HELP_FIELD_SPREADSHEET_REPEAT_FIELD_VALIDATOR,
        );
        $this->setHelpFieldsContent($arrayContent);
    }
}
?>
