<?php
class Mproduct extends Model
{
    function __construct()
    {
        parent::__construct();

        $this->load->library('PasswordHash');
    }

    function login($username, $password)
    {
        $user = $this->db->query("SELECT nUserID, password FROM www_archline_hu.jml_users WHERE username = '{$username}' OR email = '{$username}'")->row();

        if (empty($user))
            return false;

        $phpass = new PasswordHash(10, true);
        $ok     = $phpass->CheckPassword($password, $user->password);

        if (!$ok)
            return false;

        return $user;
    }

    function getProduct($id)
    {
        $query = "SELECT * FROM cl_hlusers.o_products
            WHERE id = {$id} AND seq > 0";
        $product = $this->db->query($query)->row();

        if ($product->akcio != '' && $product->akcio != null && date('Y-m-d') <= $product->ackio_date)
            $product->price = $product->akcio;
        else
            $product->price = $product->euro;

        return $product;
    }
}
