<?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_edit extends Model
{
    public function getCommentInfo($id)
    {
        if (is_numeric($id)) {
            $query = "SELECT * FROM " . core::database()->getTableName('messages') . " WHERE id=" . $id;
            $result = core::database()->querySQL($query);

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

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

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

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