<?php
/**
 *
 *
 * @author Luiz Gilberto Gregory Filho [luiz@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/10/2008
 *
 * \b Organization: \n
 * SOLIS - Cooperativa de Solucoes Livres \n
 * The Gnuteca3 Development Team
 *
 * \b CopyLeft: \n
 * CopyLeft (L) 2007 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 FrmMyFineSearch extends GnutecaForm
{
    /**
     * Attributes
     */
    public $MIOLO,
            $module,
            $function,
            $localFields,
            $ui,
            $grid,
            $business,
            $busFineStatus,
            $busAuthenticate;

    public $action;


    /**
     * Constructor Method
     **/
    function __construct()
    {
        $this->getInstace();

        parent::__construct(TITLE_SEARCH);
        parent::setIcon( $this->MIOLO->getUI()->getImage( $this->module, "myFine-16x16.png" ) );

        $this->eventHandler();

        if (($f = $this->page->request( 'cpaint_function' )) != '')
        {
            $this->manager->getTheme()->clearContent();
            $this->$f( $this->page->request( 'cpaint_argument' ) );
            $this->page->generateMethod = 'generateAjax';
        }
        else
        {
            $this->defineFields();
        }
    }


    /**
     * Instance Class Attributes
     */
    public function getInstace()
    {
        $this->MIOLO    = MIOLO::getInstance();
        $this->module   = MIOLO::getCurrentModule();
        $this->action   = MIOLO::getCurrentAction();
        $this->function = MIOLO::_REQUEST('function');
        $this->ui       = MIOLO::getUI();
        $this->business         = $this->MIOLO->getBusiness( $this->module, 'BusFine');
        $this->busFineStatus    = $this->MIOLO->getBusiness( $this->module, 'BusFineStatus');
        $this->busAuthenticate  = $this->MIOLO->getBusiness( $this->module, 'BusAuthenticate');        
    }


    /**
     * Seta as Opções para o form
     *
     * @return void
     */
    public function getOptions()
    {
        $this->setLabelWidth(FIELD_LABEL_SIZE);
        $this->defaultButton = false;
        
        $this->divHistoric->addBoxStyle('position', 'absolute');
        $this->divHistoric->addBoxStyle('left',     '20%');
        $this->divHistoric->addBoxStyle('top',      '30%');
        $this->divHistoric->addBoxStyle('width',    '60%');
        $this->divHistoric->addBoxStyle('z-index',  '1000');        
    }


    /**
     * Create Default Fileds for Search Form
     *
     * @return void
     */
    public function defineFields()
    {
        $this->getInstace();

        // add tolbar in Field List
        $this->getTooBar();

        // add field for search conditions
        $this->localFields[] = new MHiddenField     ('personId',        $this->busAuthenticate->getUserCode());
        $this->localFields[] = new MCalendarField   ('startDateS',      $this->startDateS->value,       _M('Start date',    $this->module), FIELD_DATE_SIZE, null);
        $this->localFields[] = new GnutecaSelection       ('fineStatusIdS',   $this->fineStatusIdS->value,    _M('Fine status',   $this->module), $this->busFineStatus->listFineStatus());
        $this->localFields[] = new MButton          ('btnSearch',       _M('Search',$this->module));
        $this->localFields[] = new MDiv             ('divHistoric');

        // set Search Form Fileds
        $this->setFields( $this->localFields );

        // set Search Form Options
        $this->getOptions();

        // get grid in field list
        $this->getGrid();
        
        $this->MIOLO->getRequiredJS4Ajax();        
        $this->page->addScript('GnutecaHistoric.js', $this->module);
    }


    /**
     * Create Tollbar
     *
     * @return void
     */
    public function getTooBar()
    {
        $toolBar = new MToolBar('toolBar', $this->MIOLO->getActionURL($this->module, $this->action) );

        $toolBar->disableButton('tbBtnSave');
        $toolBar->disableButton('tbBtnDelete');
        $toolBar->disableButton('tbBtnPrint');

        $this->localFields[] = $toolBar;
    }


    /**
     * Create a grid list
     *
     * @return void
     */
    public function getGrid()
    {
        $this->business->setData( $this->getData() );
        $this->grid = $this->ui->getGrid( $this->module, 'GrdMyFine' );

        // verifica se clicou em buscar para adicionar os dados do banco
        $data = array();
        if ( MIOLO::_REQUEST("btnSearch") || $this->page->isPostBack())
        {
            $data = $this->business->searchFine();
        }

        $this->grid->setData($data);

        $this->AddField($this->grid);
    }
    
    
    /**
     *
     */
    public function showHistoric($args)
    {
        $data->fineId = $args[0];
        $frm = $this->MIOLO->getUI()->getForm($this->module, 'FrmFineStatusHistory', $data);
        $frm->setClose("javascript:closeHistoric();");
        exit($frm->generate());
    }    


} // final da classe
?>
