<?php
/**
 * @author Eduardo Bonfandini [eduardo@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 21/10/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 FrmInterestsArea extends GnutecaForm
{
	public $MIOLO;
	public $module;
    public $business;
    public $busAthenticate;
    public $busLibraryUnit;
    public $personId;


    public function __construct()
    {
        $this->MIOLO    = MIOLO::getInstance();
        $this->module   = MIOLO::getCurrentModule();
        $this->business       = $this->MIOLO->getBusiness($this->module, 'BusInterestsArea');
        $this->busAthenticate = $this->MIOLO->getBusiness($this->module, 'BusAuthenticate');
        $this->busLibraryUnit = $this->MIOLO->getBusiness($this->module, 'BusLibraryUnit');
        $this->personId       = BusinessGnuteca3BusAuthenticate::getUserCode();
        parent::__construct( _M('Interests area', $this->module) );
        $this->eventHandler();
    }


    public function createFields()
    {
    	$fields[] = new GnutecaUserMenu();

        //Mensagem a ser mostrada no topo da tela
        $fields[] = new MLabel(_M(LABEL_INTEREST_AREA, $this->module));

        //Data
        $data = $this->business->mountInterestsArea( $this->personId );
        //Create array with person interests defined
        $selecteds = array();
        if  (count($data))
        {
            foreach ($data as $key => $val)
            {
                if (strlen($val[2]) > 0)
                {
                    $selecteds[] = $key;
                }
            }
        }

        //UI
        $grid = $this->MIOLO->getUI()->getGrid($this->module, 'GrdInterestsArea');
        $grid->setData($data);
        $grid->selecteds = $selecteds;
        $grid->setShowHeaders(false);
        $fields[] = $grid;
        $fields[] = new MButton('btnSave', _M('Save', $this->module));
        $this->setFields( $fields );
        $this->loadFields();
    }


    public function btnSave_click()
    {
        $action = MIOLO::getCurrentAction();
        $this->business->personId       = $this->personId;
        $this->business->interestsArray = MIOLO::_REQUEST('selectgridInterestsArea');
        $this->business->insertInterestsArea();
        //$goto = $this->MIOLO->getActionURL($this->module, substr($action, 0, strrpos($action, ':')));
        $this->information(MSG_RECORD_UPDATED, 'javascript:gnuteca.closeAction()');
    }
}
?>