<?php
/**
 * gtcTask business
 *
 * @author Luiz Gilberto Gregory F [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]
 * Sandro Roberto Weisheimer [sandrow@solis.coop.br]
 *
 * @since
 * Class created on 06/08/2009
 *
 * \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 BusinessGnuteca3BusSoapClient extends GnutecaBusiness
{
    public  $soapClientId,//"    integer,
            $clientDescription,
            $ip,//"              varchar,
            $password,//"        varchar,
            $enable;//"          boolean

    public $columns,
           $table       = 'gtcSoapClient',
           $pkeys       = 'soapClientId',
           $cols        = 'clientDescription, ip, password, enable';

    public function __construct()
    {
        $this->columns = "{$this->pkeys}, {$this->cols}";
        parent::__construct($this->table, $this->pkeys, $this->cols);
    }


    public function insertSoapClient()
    {
        return $this->autoInsert();
    }


    public function updateSoapClient()
    {
        return $this->autoUpdate();
    }


    public function deleteSoapClient($soapClient)
    {
        return $this->autoDelete($soapClient);
    }


    /**
    * Autentica um cliente
    *
    * @param integer $clientId
    * @param string $clientPassword
    */
    public function authenticate($clientId, $clientPassword)
    {
        $this->clear();
        $this->setColumns("1");
        $this->setTables($this->table);
        $this->setWhere('soapClientId = ?  AND password = ?');
        $sql = $this->select(array($clientId, base64_decode($clientPassword)));
        $rs = $this->query($sql);
        return isset($rs[0]) && $rs[0][0] == '1';
    }



    /**
     * retorna um cliente soap
     *
     * @param integer $clientId
     * @return object
     */
    public function getSoapClient($clientId)
    {
        $this->clear();
        $this->setColumns("{$this->pkeys}, {$this->cols}");
        $this->setTables($this->table);
        $this->setWhere('soapClientId = ?');
        $sql = $this->select(array($clientId));
        $rs = $this->query($sql, true);
        return isset($rs[0]) ? $rs[0] : false;
    }

}
?>
