<?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();
if ($b == false){
header('location:/');
die();
}
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT * FROM codes_cat WHERE id = ? LIMIT 1", [$id]);
if ($array -> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
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="/codes"style="text-decoration:none; color:white;">Полезные коды</a> :: <a href="codlist.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 codes_code SET name = ?, text = ?, code = ?, cid = ?, user_id = ?, time= ?", [check($_POST['name']),check($_POST['text']),check($_POST['code']),$id,$b['id'],time()]);
$last = DB::$dbs->lastInsertId();
header('location: code.php?id='.$last);
}
}
echo '<div class="list-group-item media"><div class="media-body"><div class="list-group-item-heading"><form action="?id='.$id.'" method="POST">
Название: <br/> <input type="text" name="name" class="form-control" placeholder="Название (100)"><br>
Содержание: <br/><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea name="text" class="form-control" rows="3" placeholder="Описание"></textarea><br>
Код:<br/> <textarea name="code" class="form-control" rows="3" placeholder="Код"></textarea><br>
<input type="submit" name="add" class="btn btn-primary" value="Добавить"/></form></div></div></div>';
$title->GetMenu();
$title->GetFooter();
?>