<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$title->SetTitle('Свежие новости - Добавление статьи');
$title->GetHeader();
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT * FROM gazeta_cat WHERE id = ? LIMIT 1", [$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
if ($b['jur'] == 0 OR $b == false) {
header('location: /');
die();
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: <a href="/allnews"style="text-decoration:none; color:white;">Свежие новости</a> :: <a href="category.html?id='.$arr['id'].'"style="text-decoration:none; color:white;">'.$arr['name'].'</a> :: Добавить статью</div></div></div>';
if (isset($_POST['add'])) {
if (empty($_POST['name']) OR empty($_POST['text'])) {
err('Введите название и содержание!');
} elseif (!preg_match('/[А-яA-z0-9]/i', $_POST['name'])) {
err('Заполните название!');
} else {
DB::$dbs->query("INSERT INTO gazeta_article SET name = ?, text = ?, cid = ?, user_id = ?, time= ?", [check($_POST['name']),check($_POST['text']),$id,$b['id'],time()]);
$last = DB::$dbs->lastInsertId();
lenta(Nick($b['id']).' добавил новую <a href="/allnews/news.html?id='.$last.'">[статью]</a> в Газете.');
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` + ? WHERE id = ?", [1,$b['id']]);
header('location: news.html?id='.$last);
}
}
echo '<div class="list-group-item media"><form action="?id='.$id.'" method="POST">Название:<br/> <input type="text" class="form-control" name="name"/><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea name="text" class="form-control" rows="8"></textarea><br/><input type="submit" class="btn btn-primary" name="add" value="Добавить"/></form></div>';
$title->GetMenu();
$title->GetFooter();
?>