Файл: soc-set/moduls/guestbook/index.php
Строк: 94
<?php
require_once('../../core/start.php');
check_auth();
head('Беседка');
panel();
if ( (isset($_GET['del']) && check($_GET['del'])) || (isset($_GET['edit']) && check($_GET['edit']))) {
if ($_GET['del']) {
$post = DB::$dbs->queryFetch("SELECT * FROM ".GUESTBOOK." WHERE `id` = ? ",array(num($_GET['del'])));
if (!empty($post['file'])) {
$path = '../../files/guestbook/'.$post['file'];
unlink($path);
}
DB::$dbs->query("DELETE FROM ".GUESTBOOK." WHERE `id` = ?", array(num($_GET['del'])));
header("Location: ".HOME."/guestbook/");
}
if ($_GET['edit']) {
$post = DB::$dbs->queryFetch("SELECT * FROM ".GUESTBOOK." WHERE `id` = ? ",array(num($_GET['edit'])));
if ($_POST['edit']) {
$msg = html($_POST['msg']);
if (empty($msg)) {
$err = 'Пустое сообщение<br />';
}
if (!empty($err)) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".GUESTBOOK." SET `msg` = ? WHERE `id` = ?", array($msg, $post['id']));
header("Location: ".HOME."/guestbook/");
}
}
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo '<b>Редактирование:</b><br /><textarea name="msg">'.$post['msg'].'</textarea><br />';
echo '<input type="submit" name="edit" value="Изменить"/>';
echo '</form>';
echo CLOSE_DIV;
}
}
echo DIV_AUT;
if (!empty($_GET['otv'])) {
$ank = DB::$dbs->queryFetch("SELECT `user_id`, `nick` FROM ".USERS." WHERE `user_id` = ? ",array(abs(num($_GET['otv']))));
if (!empty($ank) && $ank['user_id'] != $user['id']) {
echo 'Сообщение пользователю <b>' . $ank['nick'] . '</b><br />';
} else {
echo '<b>Сообщение:</b><br />';
}
}
echo '<form action="'.(isset($_GET['otv']) ? '?otv='.(int)$_GET['otv'] : NULL).'" enctype="multipart/form-data" method="POST">';
echo '<textarea name="msg"></textarea><br />';
echo '<b>Прикрепить файл:</b> [max. '.$config['max_upload_guestbook'].'mb.]<br /><input type="file" name="file"/><br />';
echo '<input type="submit" name="add" value="Написать"/>';
echo '</form>';
echo CLOSE_DIV;
bbsmile();
function check($id) {
global $user;
$post = DB::$dbs->queryFetch("SELECT * FROM ".GUESTBOOK." WHERE `id` = ? ",array($id));
if (privilegy('guestbook_moder')) {
return TRUE;
}
if ($post['user_id'] == $user['user_id']) {
$sql = DB::$dbs->queryFetch("SELECT * FROM ".GUESTBOOK." WHERE `id` = ? ",array(++$id));
if ($sql) {
return FALSE;
} else {
return TRUE;
}
}
}
if ($_POST['add']) {
$msg = html($_POST['msg']);
if (!empty($_FILES['file'])) {
$name = $_FILES['file']['name']; # Название файла
$ext = strtolower(strrchr($name, '.')); # Расширение файла
$par = getimagesize($_FILES['file']['tmp_name']); # Разрешение изображения
$size = $_FILES['file']['size']; # Вес файла
$time = time();
$file = $time.$ext;
if ($size > (1048576 * $config['max_upload_guestbook'])) {
$err .= 'Размер фотографии превышает допустимое значение. [Max. '.$config['max_upload_guestbook'].'Mb.]<br />';
}
if (preg_match('/.phtml/i', $name) || preg_match('/.php/i', $name) || preg_match('/.pl/i', $name) || $name == '.htaccess') {
$err .= 'Не верное расширение файла.<br />';
}
}
if (empty($msg)) {
$err = 'Пустое сообщение<br />';
}
if (!empty($_GET['otv']) && $_GET['otv'] != $user['user_id']) {
$ank = DB::$dbs->queryFetch("SELECT `user_id`, `nick` FROM ".USERS." WHERE `user_id` = ? ",array(abs(num($_GET['otv']))));
if (!empty($ank)) {
$msg = '[b]' . $ank['nick'] . '[/b], ' . $msg;
}
$lenta = '<a href="'.HOME.'/id'.$user['user_id'].'"><b>' . $user['nick'] . '</b></a> ответил'.(empty($user['gender']) ? 'a' : NULL).' на Ваше сообщение в <a href="'.HOME.'/guestbook/"><b>беседке</b></a>';
lenta($lenta, $ank['user_id']);
}
if (!empty($err)) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".USERS." SET `guestbook_post` = ? WHERE `user_id` = ? ", array((++$user['guestbook_post']), $user['user_id']));
if ($ext) {
copy($_FILES['file']['tmp_name'], '../../files/guestbook/'.$file);
DB::$dbs->query("INSERT INTO ".GUESTBOOK." (`user_id`, `file`, `time`, `msg`) VALUES (?, ?, ?, ?)", array($user['user_id'], $file, time(), $msg));
} else {
DB::$dbs->query("INSERT INTO ".GUESTBOOK." (`user_id`, `file`, `time`, `msg`) VALUES (?, ?, ?, ?)", array($user['user_id'], 0, time(), $msg));
}
balls_operation(1);
header("Location: ".HOME."/guestbook/");
}
}
if (privilegy('guestbook_moder') && !empty($_POST['post_delete'])) {
foreach ($_POST as $name => $value) {
DB::$dbs->query("DELETE FROM ".GUESTBOOK." WHERE `id` = ?", array($name));
}
header("Location: ".HOME."/guestbook/");
}
if (privilegy('guestbook_moder') && !empty($_POST['clean'])) {
$sql = DB::$dbs->query("SELECT * FROM ".GUESTBOOK."");
while($post = $sql -> fetch()) {
if (!empty($post['file'])) {
$path = '../../files/guestbook/'.$post['file'];
unlink($path);
}
}
DB::$dbs->query("TRUNCATE ".GUESTBOOK."");
header("Location: ".HOME."/guestbook/");
}
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GUESTBOOK."");
if (empty($all)) {
echo DIV_BLOCK . 'Сообщений нет' . CLOSE_DIV;
} else {
echo '<form action="#" method="POST">';
$n = new Navigator($all,$config['write']['guestbook'],'');
$sql = DB::$dbs->query("SELECT * FROM ".GUESTBOOK." ORDER BY `id` DESC LIMIT {$n->start()}, ".$config['write']['guestbook']."");
while($post = $sql -> fetch()) {
$ank = DB::$dbs->queryFetch("SELECT `nick` FROM ".USERS." WHERE `user_id` = ?",array($post['user_id']));
echo DIV_LI;
echo (privilegy('guestbook_moder') ? '<input type="checkbox" name="'.$post['id'].'" /> ' : NULL);
echo '[' . vrem($post['time']) . '] ' . user_choice($post['user_id'], 'link') . ($post['user_id'] != $user['user_id'] ? '<a href="?otv='.$post['user_id'].'"> [ответить]</a> ' : NULL) . (check($post['id']) ? ' <a href="'.HOME.'/guestbook/?del='.$post['id'].'">[Удал]</a> <a href="'.HOME.'/guestbook/?edit='.$post['id'].'">[Ред.]</a>' : null) . ': ' . CLOSE_DIV . DIV_BLOCK . text($post['msg']) . '<br />';
if (!empty($post['file'])) {
$path = '../../files/guestbook/'.$post['file'];
$size = get_size(filesize($path));
$path_info = pathinfo($path);
echo '<br />Прикреплен файл: <a href="'.HOME.'/files/guestbook/'.$post['file'].'"><b>[Скачать]</b></a> ['.$path_info['extension'].'] ['.$size.']<br />';
}
echo CLOSE_DIV;
}
echo $n->navi();
echo (privilegy('guestbook_moder') ? DIV_LI . '<input type="submit" name="post_delete" value="Удалить выделенные посты"/> <input type="submit" name="clean" value="Очистить беседку"/></form>' . CLOSE_DIV : NULL);
}
$array = array('Беседка');
nav($array);
require_once('../../core/stop.php');
?>