<?php

/********************************************
 * PHP Guestbook 3.0.1 beta
 * Copyright (c) 2007-2016 Alexander Yanitsky
 * Website: http://janicky.com
 * E-mail: janickiy@mail.ru
 * Skype: janickiy
 ********************************************/

defined('GUESTBOOK') || exit('GUESTBOOK: access denied!');

class Model_blackip extends Model
{
    public function getBlackListIp()
    {
        $query = "SELECT * FROM " . core::database()->getTableName('ip');
        $result = core::database()->querySQL($query);
        return core::database()->getColumnArray($result);
    }

    public function getBlackIpInfo($id)
    {
        if (is_numeric($id)) {
            $query = "SELECT * FROM " . core::database()->getTableName('ip') . " WHERE id=" . $id;
            $result = core::database()->querySQL($query);

            return core::database()->getRow($result);
        }
    }

    public function editBlackIp($fields, $id)
    {
        if (is_numeric($id)) {
            return core::database()->update($fields, core::database()->getTableName('ip'), "id=".$id);
        }
    }

    public function removeIp($id)
    {
        if (is_numeric($id)) {
            return core::database()->delete(core::database()->getTableName('ip'), "id=" . $id);
        }
    }

    public function checkIPExist($id)
    {
        if (is_numeric($id)) {
            $query = "SELECT * FROM " . core::database()->getTableName('ip') . " WHERE id=" . $id;
            $result = core::database()->querySQL($query);

            if(core::database()->getRecordCount($result) == 0)
                return FALSE;
            else
                return TRUE;
        } else {
            return FALSE;
        }
    }
}