<?php
/**
 * Bond 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 07/08/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 FrmPersonSearch extends GnutecaForm
{
    public $MIOLO;
    public $module;
    public $busBond;
    public $busPenalty;


    public function __construct()
    {
        $this->MIOLO    = MIOLO::getInstance();
        $this->module   = MIOLO::getCurrentModule();
        $this->busBond    = $this->MIOLO->getBusiness($this->module, 'BusBond');
        $this->busPenalty = $this->MIOLO->getBusiness($this->module, 'BusPenalty');
        $this->setAllFunctions('Person');
        $this->setGrid('GrdPerson', 'personNameS');
        parent::__construct();
        if ( $this->primeiroAcessoAoForm() && strlen(MIOLO::_REQUEST('event')) == 0 )
        {
       	    $this->setFocus('personIdS');
        }
    }


    public function createFields()
    {
        $personIdS = new MTextField('personIdS', '', _M('Code',$this->module), FIELD_ID_SIZE);
        $fields[] = $personIdS;

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

        $cityS = new MTextField('cityS', $this->city->value, _M('City',$this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = $cityS;


        $emailS = new MTextField('emailS', $this->emailS->value, _M('E-mail',$this->module), FIELD_DESCRIPTION_SIZE);
        $fields[] = $emailS;

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


    public function showBond()
    {
    	$data = new StdClass();
        $data->personIdS = MIOLO::_REQUEST('personId');
        $this->busBond->setData($data);
        $search = $this->busBond->searchBond(TRUE);
        if ($search)
        {
	        for ($i=0; $i < count($search); $i++)
	        {
	            $tbData[] = array(
	                $search[$i]->linkIdName,
	                GnutecaDate::toUser($search[$i]->dateValidate, 'DATE')
	            );
	        }
	        $fields[] = new MLabel(_M('Person code', $this->module) . ': '. $data->personIdS);
	        $tbColumns = array(
	            _M('User group', $this->module),
	            _M('Date validate', $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('Bond', $this->module));
        $this->setFields($fields, false);
        parent::_showDetail($this);
    }


    public function showPenalty()
    {
    	$data = new StdClass();
        $data->personIdS = MIOLO::_REQUEST('personId');
        $this->busPenalty->setData($data);
        $search = $this->busPenalty->searchPenalty(TRUE);
        if ($search)
        {
	        foreach ($search as $v)
	        {
	            $tbData[] = array($v->observation,
                                  $v->internalObservation,
	                              GnutecaDate::toUser($v->penaltyDate, 'DATE'),
	                              GnutecaDate::toUser($v->penaltyEndDate, 'DATE'),
	                              $v->operator,
	                              $v->libraryName);
	        }
	        $fields[] = new MLabel(_M('Person code', $this->module) . ': '. $data->personIdS);
	        $tbColumns = array(
	            _M('Observation', $this->module),
	            _M('Internal observation', $this->module),
	            _M('Penalty date', $this->module),
	            _M('Penalty end date', $this->module),
	            _M('Operator', $this->module),
	            _M('Library unit', $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('Penalty', $this->module) );
        $this->setFields($fields, false);
        parent::_showDetail($this);
    }
}
?>
