<?php
define('Solex', 1) or die ('Unknown Error!');
require_once '../system/db.php';
require_once '../system/sys.php';
$title = 'Форум';
require_once '../system/head.php';
auth();
switch($act){
case 'creat_cat';
break;
case 'creat_theme';
if(!$_POST){
echo '
<form action = "?act=creat_theme&id='.$gid.'" method = "POST">
<input type = "text" name = "name" placeholder = "Название темы" required/>
<textarea required minlength = "5" maxlength = "250" name = "text" placeholder = "Введите текст" >
</textarea>
<input type = "submit" value = "Создать"/>
</form>
';
}else{
$name = check($_POST['name']);
$text = check($_POST['text']);
if(mb_strlen($name) < '5' OR mb_strlen($name) > '30'){
$error = $error . 'Название темы должно быть минимум 5 и максимум 30 символов.';
}
if(mb_strlen($text) < '5' OR mb_strlen($text) > '250'){
$error = $error . 'Текст должен быть минимум 5 и максимум 250 символов.';
}
if(empty($error)){
$new_user = $db -> prepare("INSERT INTO forum_theme SET uid = :uid, name = :nam, text = :text, time_s = :time_s, cat_id = :cat");
$new_user -> execute(array(":uid" => $user_id, ":text" => $text, ":nam" => $name, ":time_s" => time(), ":cat" => $gid));
header('location: ?act=all_theme&id='.$gid.'');
}else{
echo $error;
}
}
break;
case 'all_post';
$o = $db -> prepare("SELECT * FROM forum_theme WHERE id = :uid");
$o -> execute(array(":uid" => $gid));
$o1= $o -> fetch(PDO::FETCH_BOTH);
$c3 = $db -> prepare("SELECT * FROM user WHERE id = :uid");
$c3 -> execute(array(":uid" => $o1['uid']));
$c4 = $c3 -> fetch(PDO::FETCH_BOTH);
if(!$_POST){
echo '
<a href ="?act=all_theme&id='.$o1['cat_id'].'" class = "btn">Назад</a>
<form action = "?act=all_post&id='.$gid.'" method = "POST" class = "center">
<textarea required minlength = "5" maxlength = "250" name = "text" placeholder = "Введите текст" >
</textarea>
<input type = "submit" value = "Отправить"/>
</form>
';
}else{
$text = check($_POST['text']);
if(mb_strlen($text) < '5' OR mb_strlen($text) > '250'){
$error = $error . 'Текст должен быть минимум 5 и максимум 250 символов.';
}
if(empty($error)){
$new_user = $db -> prepare("INSERT INTO forum_post SET uid = :uid, theme_id = :gid, text = :text, time_s = :time_s");
$new_user -> execute(array(":uid" => $user_id, ":text" => $text, ":time_s" => time(), ":gid" => $gid));
header('location: ?act=all_post&id='.$gid.'');
}else{
echo $error;
}
}
echo '<div class = "block">
<a href = "/user/profile.php?id='.num(check($c4['uid'])).'" class = "btn_u">'.check($c4['name']).'</a>
<div class = "right">
'.a_time($o1['time_s']).'
</div><div class = "block_u center"></div>
'.check($o1['text']).'<br/>
</div>
';
$k_post1 = $db -> query("SELECT * FROM forum_post WHERE theme_id = ".$gid);
$k_post1 -> execute();
$k_post = $k_post1 -> rowCount();
$k_page = k_page($k_post,10);
$page = page($k_page);
$start = 10*$page-10;
$ms = $db -> query("SELECT * FROM `forum_post` WHERE `theme_id` = ".$gid." ORDER BY `time_s` DESC LIMIT $start, 10");
$ms -> execute();
while($f = $ms -> fetch(PDO::FETCH_ASSOC)){
$c1 = $db -> prepare("SELECT * FROM user WHERE id = :uid");
$c1 -> execute(array(":uid" => $f['uid']));
$c2 = $c1 -> fetch(PDO::FETCH_BOTH);
echo '<div class = "block">
<a href = "/user/profile.php?id='.num(check($f['uid'])).'" class = "btn_u">'.check($c2['name']).'</a>
<div class = "right">
'.a_time($f['time_s']).'
</div><div class = "block_u center"></div>
'.check($f['text']).'<br/>
</div>
';
}
if($k_post > '10') { echo str('?',$k_page,$page); echo '<br/>'; }
break;
case 'all_theme';
echo '
<div class = "container dva">
<a href = "?act=all_cat"><div>Назад</div></a>
<a href = "?act=creat_theme&id='.$gid.'"<div>Создать тему</div></a>
</div>
';
$k_post1 = $db -> query("SELECT * FROM forum_theme WHERE cat_id = " . $gid );
$k_post1 -> execute();
$k_post = $k_post1 -> rowCount();
$k_page = k_page($k_post,10);
$page = page($k_page);
$start = 10*$page-10;
$ms = $db -> query("SELECT * FROM forum_theme WHERE cat_id = $gid ORDER BY time_s DESC LIMIT $start, 10");
$ms -> execute();
while($f = $ms -> fetch(PDO::FETCH_ASSOC)){
echo '
<a href = "?act=all_post&id='.check(num($f['id'])).'" class = "btn">'.check($f['name']).'</a>
';
}
if($k_post > '10') { echo str('?',$k_page,$page); echo '<br/>'; }
if($k_post == '0') {echo 'Темы отсутсвуют';}
break;
default:
$k_post1 = $db -> query("SELECT * FROM forum_cat");
$k_post = $k_post1 -> rowCount();
$k_page = k_page($k_post,10);
$page = page($k_page);
$start = 10*$page-10;
$ms = $db -> query("SELECT * FROM `forum_cat` ORDER BY `id` DESC LIMIT $start, 10");
while($f = $ms -> fetch(PDO::FETCH_ASSOC)){
echo '
<a href = "?act=all_theme&id='.check($f['id']).'" class = "btn">'.check($f['name']).'</a>
';
}
if($k_post > '10') { echo str('?',$k_page,$page); echo '<br/>'; }
if($k_post == '0') {echo 'Сообщений нет';}
break;
}
require_once '../system/foot.php';
?>