Файл: 4mast/profmas.ru/downloads/komm.php
Строк: 48
<?
require_once('../includes/Headers.php');
require_once('../includes/PDO_func.php');
if($us['id'] == false){
header('location: /login/auth');
exit;
}
$query = DB :: $dbs -> query ("SELECT * FROM `down_files` WHERE (`id`=?)", array ((int) $_GET['id']));
if ($query -> rowCount () == 0) {
header ('location: /');
exit;
}
$f = $query -> fetch ();
if (!isset ($f['dop']) || $f['dop']=='net') {
header ('location: /');
exit;
}
$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `down_komm` WHERE (`id_f`='" . $f['id'] . "')");
H ($f['name'], 'Комментарии к файлу (' . $items . ')');
$items_per_page = 10;
$pages = ceil ( $items / $items_per_page );
if ($page < 1)
$page = 1;
if ($page > $pages)
$page = $pages;
$start = $page * $items_per_page - $items_per_page;
$_GET['komu'] = isset ($_GET['komu']) ? intval ($_GET['komu']) : 0;
if ($_GET['komu']!=0) {
$query = DB :: $dbs -> query ("SELECT * FROM `us` WHERE (`id`='" . $_GET['komu'] . "')");
if ($query -> rowCount () == 0) {
header ('location: /');
exit;
}
$komu = $query -> fetch ();
if ($komu['id'] == $us['id']) {
header ('location: /');
exit;
}
}
echo '<div class="list1">';
echo 'Файл: <a href="/downloads/file' . $f['id'] . '">' . $f['name'] . '</a><br/>';
echo 'Загрузил: ' . Nick ($f['us']);
echo '</div>';
echo '<div class="list1">';
echo '<form action="/downloads/komm.php?id=' . $f['id'] . '&komu=' . $komu['id'] . '&add" method="post">';
echo 'Комментарии:<br/><textarea name="kom">' . ($_GET['komu']!=0 ? '[b]' . $komu['nick'] . '[/b], ':'') . '</textarea><br/>';
echo '<input type="submit" value="Добавить"/>';
echo '</form>';
echo '</div>';
if (isset ($_GET['add'])) {
$_POST['kom'] = htmlspecialchars (addslashes (trim ($_POST['kom'])));
if (empty ($_POST['kom'])) {
echo '<div class="list1"><b style="color:red;">Вы не ввели текст комментария..</b></div>';
}
else {
if (DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `down_komm` WHERE (`id_f`='" . $f['id'] . "') AND (`us`='" . $us['id'] . "') AND (`text`=?)", array ($_POST['kom'])) != 0) {
echo '<div class="list1"><b style="color:red;">Вы уже писали это.</b></div>';
}
else {
DB :: $dbs -> query ("INSERT INTO `down_komm` (`id_f`,`us`,`komu`, `text`,`t`) VALUES ('" . $f['id'] . "','" . $us['id'] . "', '" . $_GET['komu'] . "',?,'" . time () . "')", array ($_POST['kom']));
if ($_GET['komu']!=0) {
DB :: $dbs -> query ("INSERT INTO `action` (`value`,`t`,`us`,`razd`) VALUES ('us{" . $us['id'] . "} ответил вам в [url=/downloads/komm.php?id=" . $f['id'] . "]комментариях[/url] к файлу!', '" . time () . "', '" . $_GET['komu'] . "','comm')");
}
if ($f['us']!=$us['id']) {
DB :: $dbs -> query ("INSERT INTO `action` (`value`,`t`,`us`,`razd`) VALUES ('us{" . $us['id'] . "} [url=/downloads/komm.php?id=" . $f['id'] . "]прокомментировал[/url] ваш файл!', '" . time () . "', '" . $f['us'] . "','comm')");
}
header ('location: /downloads/komm.php?id=' . $f['id']);
}
}
}
if ($items == 0) {
echo '<div class="error">Комментариев нет..</div>';
}
else {
if (isset ($_GET['del'])) {
$query = DB :: $dbs -> query ("SELECT * FROM `zc_komm` WHERE (`id_f`='" . $f['id'] . "') AND (`id`=?)", array (intval ($_GET['del'])));
if ($query -> rowCount () != 0) {
$komm = $query -> fetch ();
$u = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE (`id`='" . $komm['us'] . "')");
if ($u['id']==$us['id'] && $us['level']>0 || $u['level']<$us['level']) {
DB :: $dbs -> query ("DELETE FROM `down_komm` WHERE (`id`='" . $komm['id'] . "')");
}
}
header ('lcoation: /downloads/komm.php?id=' . $f['id']);
}
$query = DB :: $dbs -> query ("SELECT * FROM `down_komm` WHERE (`id_f`='" . $f['id'] . "') ORDER BY `id` DESC LIMIT $start, $items_per_page");
while ($komm = $query -> fetch ()) {
$u = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE (`id`='" . $komm['us'] . "')");
echo '<div class="list1">';
echo Nick ($komm['us']) . ' (' . datef ($komm['t']) . ')';
if ($komm['us']!=$us['id']) {
echo ' [<a href="/downloads/komm.php?id=' . $f['id'] . '&komu=' . $komm['us'] . '">отв</a>]';
}
if ($u['id']==$us['id'] && $us['level']>0 || $u['level']<$us['level']) {
echo ' [<a href="/downloads/komm.php?id=' . $f['id'] . '&del=' . $komm['id'] . '">x</a>]';
}
echo '<br/>';
echo tag ($komm['text']);
echo '</div>';
}
if($items>10) page('/downloads/komm' . $f['id']);
}
require_once('../includes/Footers.php');
?>