<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$title->SetTitle(homeurl.' - Личный блокнот');
$title->GetHeader();
if ($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="/office"style="text-decoration:none; color:white;"> Кабинет</a> :: Личный блокнот</div></div>';

echo '<div class="list-group-item media">Здесь Вы можете хранить текстовые записи, которые никто кроме вас не увидит, если только Вы сами не дадите на запись ссылку. | <img src="/assets/images/pen2.png" alt="*" /> <a href="create">Написать</a></div>';

if (isset($_GET['delete'])){
$notebook = DB::$dbs->queryFetch("SELECT * FROM `notebook` WHERE `id` = ? LIMIT 1", [intval($_GET['delete'])]);
if ($notebook['id_user'] == $b['id']){
DB::$dbs->query("DELETE FROM `notebook` WHERE `id` = ? LIMIT 1", [$notebook['id']]);
header('Location: ?');
exit;
}
}
$k_post = DB::$dbs->querySingle("SELECT COUNT(*) FROM `notebook` WHERE `id_user` = ?", [$b['id']]);
$num = 10;
$k_page = k_page($k_post, $num);
$page = page($k_page);
$start = $num * $page - $num;

if ($k_post == 0){
err('Cписок записей пуст');
}

$sql = DB::$dbs->query("SELECT * FROM `notebook` WHERE `id_user` = ? ORDER BY `time` DESC LIMIT $start,$num",[$b['id']]);
while($post = $sql -> fetch()) {
echo '<div class="list-group-item media"><a href="note.php?key=' . $post['key'] . '"><img src="/assets/images/note.png" alt="*" /> <b>' . $post['name'] . '</b></a> (' . vr($post['time']) . ') [<a href="create.php?edit=' . $post['id'] . '">изм</a>] [<a href="?delete=' . $post['id'] . '">удл</a>]</br>'.text($post['msg']) . '</div>';
}
if ($k_page>1) {
str('?', $k_page, $page);
}
$title->GetMenu();
$title->GetFooter();
?>
