include '../system/base.php';
include '../system/function.php';
auth(); // Закроем от неавторизированых
$id = intval(trim($_GET['id']));
$stmt = $base->prepare("SELECT * FROM `forum_topic` WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$topic = $stmt->get_result()->fetch_assoc();
$stmt = $base->prepare("SELECT * FROM `profile` WHERE id = ?");
$title = $topic['name'];
include '../system/header.php';
$reply = intval(trim($_GET['reply']));
if($reply) {
$stmt->bind_param("i", $reply);
$stmt->execute();
$_reply = $stmt->get_result()->fetch_assoc();
if(!$_reply['id'] OR $_reply['id'] == $profile['id']) {
header('location: /forum/t-'.$topic['id'].'/');
exit();
}
$stmt->close();
}
if(!$topic){
$stmt = $base->prepare("INSERT INTO log (uid, self, url, time) VALUES (?, ?, ?, ?)");
$stmt->bind_param('issi', $profile['id'], $_SERVER['PHP_SELF'], $_SERVER['REQUEST_URI'], $time);
$stmt->execute();
$stmt->close();
header('Location: /forum'); exit();
}
$stmt->bind_param("i", $topic['uid']);
$stmt->execute();
$result = $stmt->get_result()->fetch_assoc();
echo '<div class="block">';
echo '<div style="padding: 10px;">';
echo 'Автор: <a href="/profile/'.$result['id'].'" style="font-weight: bold">'.$result['login'].'</a> <span style="float: right;">'.timestep($topic['time']).'</span>';
echo '</div>';
echo '<div class="link-line"></div>';
echo '<div style="padding: 10px;">'.$topic['text'].'</div>';
$stmt = $base->prepare("SELECT * FROM `forum_comment` WHERE topic = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$data = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
echo '<div class="link-line"></div>';
foreach ($data as $comment) {
$stmt = $base->prepare("SELECT * FROM `profile` WHERE id = ?");
$stmt->bind_param("i", $comment['uid']);
$stmt->execute();
$res = $stmt->get_result()->fetch_assoc();
echo '<a href="/profile/'.$res['id'].'/" style="font-weight: bold">'.$res['login'].'</a>';
echo ''.($comment['uid'] == $profile['id'] ? ': ' : '<a href="/forum/t-'.$topic['id'].'?reply='.$comment['uid'].'">(»)</a>: ').'';
echo ''.$comment['text'].'';
echo '<div class="link-line"></div>';
}
if($topic['status'] == 'open'){
if(isset($_REQUEST['ok'])){
$text = trim(filter_input(INPUT_POST, 'text', FILTER_SANITIZE_STRING));
if(empty($text)) msg('Введите сообщение');
elseif(!preg_match("#[a-zа-я0-9]+#ui", $text)) msg('В тексте могут содержаться только буквы и цифры');
elseif(mb_strlen($text) > 1199 or mb_strlen($login) < 5) msg('Количество символов от 5 до 3000');
else{
$stmt = $base->prepare("INSERT INTO forum_comment (uid, topic, reply, text, time) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param('iiisi', $profile['id'], $topic['id'], $reply, $text, $time);
$stmt->execute();
$stmt->close();
header('Location: /forum/t-'.$topic['id'].'/');
}
}
echo '<div class="content" align="center">';
echo '<form active="" method="post">
<textarea class="forum" name="text">'.($reply == '0' ? '' : ''.$_reply['login'].', ').'</textarea>
<button name="ok" class="sub" >Отправить</button>
</form>';
echo '</div><div class="link-line"></div>';
}else{
echo '<div class="content" align="center" style="color: red; font-weight: bold">Тема закрыта...</div>';
}
echo '<div style="padding: 15px;">';
echo '<a href="/forum/'.$topic['section'].'/" class="pages" style="padding: 5px;"> Назад</a> ';
echo '<a href="/forum/moder/t-'.$topic['id'].'/" class="pages" style="padding: 5px;"> Пожаловаться</a>';
echo '</div>';
echo '</div>';
include '../system/footer.php';
class MyPDO extends PDO
{
public function run($sql, $args = NULL)
{
$stmt = $this->prepare($sql);
$stmt->execute($args);
return $stmt;
}
}
$data = $pdo->run("SELECT * FROM users WHERE sex='male'")->fetchAll();
array(5) { [0]=> array(5) { ["id"]=> int(1) ["uid"]=> int(20) ["tid"]=> int(20) ["text"]=> string(6) "sadasd" ["time"]=> int(1550745018) } [1]=> array(5) { ["id"]=> int(2) ["uid"]=> int(20) ["tid"]=> int(20) ["text"]=> string(6) "sadasd" ["time"]=> int(1550745081) } [2]=> array(5) { ["id"]=> int(3) ["uid"]=> int(20) ["tid"]=> int(20) ["text"]=> string(8) "sasadasd" ["time"]=> int(1550745090) } [3]=> array(5) { ["id"]=> int(4) ["uid"]=> int(20) ["tid"]=> int(20) ["text"]=> string(8) "sasadasd" ["time"]=> int(1550745130) } [4]=> array(5) { ["id"]=> int(5) ["uid"]=> int(20) ["tid"]=> int(20) ["text"]=> string(8) "sasadasd" ["time"]=> int(1550745161) } }
$max = 10;
$count = mysqli_num_rows(mysqli_query($base, 'SELECT COUNT(*) FROM `chat`'));
$pages = ceil($count/$max);
$page = filter_var(trim($_GET['page'], FILTER_SANITIZE_NUMBER_INT));
if($page > $pages) {$page = $pages;}
if($page < 1) {$page = 1;}
$start = $page * $max - $max;
$q = mysqli_query($base, "SELECT * FROM `chat` ORDER BY `id` DESC LIMIT $start, $max");
echo '<div class="block">';
if($count){
while ($row = mysqli_fetch_array($q)) {
$sql = mysqli_query($base, "SELECT * FROM `profile` WHERE`id` = $row[uid]");
$fetch = mysqli_fetch_array($sql);
echo '<div style="padding: 5px">';
echo ''.$fetch['login'].' |'.filter_db_text($row['text']).'';
echo '</div>';
echo '<div class="link-line"></div>';
}}else{
echo '<div class="gl-obv">Сообщений нет</div>';
}
$stmt = $base->prepare("SELECT * FROM `chat` ORDER BY id LIMIT 5");
$stmt->execute();
$data = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
foreach ($data as $row) {
echo $row['das'];
}
// Переменные $start и $max используются, определяются выше (в ненужном здесь куске кода)
$q = mysqli_query($base, "SELECT * FROM `chat` ORDER BY `id` DESC LIMIT $start, $max");
echo '<div class="block">';
if($count){
while ($row = mysqli_fetch_array($q)) {
$sql = mysqli_query($base, "SELECT * FROM `profile` WHERE`id` = $row[uid]");
$fetch = mysqli_fetch_array($sql);
echo '<div style="padding: 5px">';
echo ''.$fetch['login'].' |'.filter_db_text($row['text']).'';
echo '</div>';
echo '<div class="link-line"></div>';
}}else{
echo '<div class="gl-obv">Сообщений нет</div>';
}
$sql = "SELECT count(1) FROM users WHERE login= ?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $login);
$stmt->execute();
$stmt->bind_result($result);
$stmt->fetch();
if ($result)
{
echo "Логин доступен";
} else {
echo "Увы, но логин уже занят";
}