View file top_reit/rustats.su/system/model/news.class.php

File size: 1.37Kb
<?php 
/**
------------------------------------------------------------------------
* Модель кабинета пользователя
*
* @application         PHPage Core
* @support             http://phpage.ru
* @copyright           Copyright (c) 2014 PHPage Group
* @author              http://phpage.ru/PHPage/Group
* @documentation       http://phpage.ru/documentation
* @license             http://phpage.ru/license.txt (see attached file)
* @instruction         http://phpage.ru/readme.txt (see attached file)
* @file                /system/model/cabinet.class.php
------------------------------------------------------------------------
*/

class news_model{
	public function com(){
		if(isset($_POST['text'])){
			$user = User::getUser();
			$text= $_POST['text'];
			if(Core::count("SELECT COUNT(*) FROM `news` WHERE `id` = ?", array($_GET['get'])) == false) $err = 'Новость не найдена';
			if(strlen($text) <5 or strlen($text) > 1000) $err = 'Пост должен быть в пределах 5 - 1000 символов';			
			if(!isset($err)){
				Core::query("INSERT INTO `com_news` SET `id_user` = ?, `text` = ?, `id_news` = ?, `time` = '".time()."'", array($user['id'], $text, $_GET['get']));
				Core::redirect('/news/comments/'.$_GET['get'].'', 'Комментарий успешно добавлен');
			}else{
				Core::redirect('/news', $err);
			}
		}
	}
}
?>