<?php
require '../inc/func.php';
if(!$user){
header('location: /index.php');
}
switch (isset($_GET['act']) ? $_GET['act']:'' ) {
default:
bk_head('Forum');
require '../inc/head.php';
echo '<div class="list1"><div class="tt"> Chuyên mục</div>';
$cats_r = mysql_query("SELECT * FROM `forum_cats` ORDER BY `time`");
if (mysql_num_rows($cats_r)) {
while ($cat = mysql_fetch_assoc($cats_r)) {
echo '<div class="list1">';
$count_cats = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_cat` = '".$cat['id']."' "),0);
if($cat['closed']==1){
echo '<img src="/images/locked.png" /> ';
}else{
echo '';
}
echo '<a href="'.$cat['id'].'">'.$cat['name'].'('.$count_cats.')</a>';
echo '</div>';
}
} else {
echo 'Chưa có chuyên mục nào!';
}
if($datauser['level'] >=4){
echo '<br /><a href="index.php?act=add">Tạo mới</a>';
}
echo '<hr><div class="shadow"><a href="/users/my.php"><b>My Menu</b></a> | <a href="/u/'.$userid.'"><b>Profile</b></a> | <a href="/exit.php"><b>LogOut</b></a></div></div>';
break;
case 'topic':
$cid = $_GET['cid'];
$ch_cid = mysql_query("SELECT `id` FROM `forum_cats` WHERE `id` = '".$cid."' ");
if(!mysql_num_rows($ch_cid)){
header('location: index.php');
}
$s = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_cats` WHERE `id` = '".$cid."' "));
bk_head(''.$s['name'].'');
require '../inc/head.php';
echo '<div class="list1">';
echo '<div class="tt"> '.$s['name'].'</div>';
#########page##############
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_cat` = '".$cid."' "),0);
$display = 6;
$count_pages = ceil($total/$display);
$page = (isset($_GET['page']) and is_numeric($_GET['page']) and $_GET['page']>1 and $_GET['page']<=$count_pages) ? $_GET['page'] : 1;
$start = $page*$display-$display;
######page#########
#####add cat#####
if(isset($_GET['add'])){
if($s['closed'] != 0 AND $datauser['level'] < 4){
err('Lỗi! Chuyên mục này không được phép đăng bài!');
echo '<a href="index.php">← Back</a>';
bk_foot();
exit;
}
if(isset($_POST['submit'])){
$title = $_POST['title'];
$text = bk_check($_POST['text']);
$time = time();
$adda = mysql_query("INSERT INTO `forum_topics` (`id_cat`,`title`,`id_user`,`time`) VALUES ('".$cid."','".$title."','".$userid."','".$time."')");
$idt = mysql_insert_id();
$addb = mysql_query("INSERT INTO `forum_msg` (`id_cat`,`id_topic`,`id_user`,`text`,`time`) VALUES ('".$cid."','".$idt."','".$userid."','".$text."','".$time."')");
if($adda && $addb){
$lid = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id_cat` = '".$cid."' ORDER BY `time` DESC LIMIT 1 "));
header('location: /forum/?act=view&id='.$lid['id'].'');
}
}else{
echo '<div class="left"><b>• Đăng bài trong box <font color="red">'.$s['name'].'</font><br />• <font color="red">Lưu ý:</font> Bài viết đăng sai chuyên mục sẽ bị xóa ko cần báo trước, và người đăng sai box sẽ bị ban (ra đảo)!</b><br />';
echo '<form action="" method="post"><b>Tiêu Đề</b><br /><input type="text" name="title"><br /><b>Nội Dung</b><br /><textarea name="text"></textarea><br /><input type="submit" value="Đăng" name="submit"></form>';
echo '<br /><a href="javascript:history.go(-1)">←Quay Lại</a>';
echo '</div>';
}}####end add cat
elseif(isset($_GET['edit']))####edit cat
{
if(isset($_POST['submit'])){
$name = $_POST['name'];
$about = $_POST['about'];
$close = isset($_POST['close']) ? num($_POST['close']) :'0';
$add = mysql_query("UPDATE `forum_cats` SET `name` = '".$name."', `about` = '".$about."', `closed` = '".$close."' WHERE `id` = '".$cid."' ");
if($add){
err('Thay đổi thành công!');
}
}else{
echo '<div class="shadow"><b>• Sửa chuyên mục <font color="red">'.$s['name'].'</font><br />• <font color="red">Lưu ý:</font> Cân nhắc cẩn thận trước khi tiến hành sửa tên, about của chuyên mục nhé!</b><br />';
echo '<form action="" method="post"><b>Tiêu Đề</b><br /><input type="text" value="'.$s['name'].'" name="name"><br /><b>Nội Dung</b><br /><textarea name="about">'.$s['about'].'</textarea><br /><input type="checkbox" value="1" name="close"> Đóng<br /><input type="submit" value="Save" name="submit"></form>';
echo '<br /><a href="javascript:history.go(-1)">←Quay Lại</a>';
echo '</div>';
}
}#####end edit cat
else{
if($datauser['level'] >=4 OR $s['id_user'] == $userid){
echo '<a href="/forum/?act=topic&cid='.$cid.'&edit=edit"><input type="button" value="Sửa chuyên mục"></a> ';
}
if($s['closed'] != 1){
echo '<a href="/forum/?act=topic&cid='.$cid.'&add=add"><input type="button" value="Đăng Bài" name=""></a><div class="li"></div>';
}else{
echo '<input type="button" value="Chuyên mục đã bị khóa" name="">';
}
if($total > 0){
$q_topic = mysql_query("SELECT * FROM `forum_topics` WHERE `id_cat` = '".$cid."' ORDER BY `time` DESC LIMIT $start,$display");
while ($topic = mysql_fetch_assoc($q_topic)){
$count_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '".$topic['id']."' "),0);
echo '<div class="lefft_bot">';
if($topic['closed'] == "1"){
echo '<img src="/images/locked.png" /> ';
}
echo '<a href="/threads/'.rewrite($topic['title']).'_'.$topic['id'].'">'.smiles($topic['title']).' ('.$count_msg.')</a></div>';
echo '<div class="li"></div>';
}
#####page
if($total > 6 && $page < $count_pages){
echo '<div class="shadow">';
pages($page,$count_pages,'?act=topic&cid='.$cid.'&page=');
echo '</div><br />';
}
}else{
err('Chưa có bài viết!');
}
}
echo '<div class="shadow"><a href="/forum">←Về trang chính</a></div></div>';
break;
case 'add':
bk_head('Thêm chuyên mục');
require '../inc/head.php';
if($datauser['level'] <4){
header('location: index.php');
}
echo '<div class="list1">';
if(isset($_POST['submit'])){
$name = bk_check($_POST['name']);
$close = isset($_POST['close'])? num($_POST['close']): 0 ;
$about = bk_check($_POST['about']);
$time = time();
if(empty($name) OR empty($about)){
err('Chưa nhập tên hoặc chưa nhập about!');
}elseif(strlen($name) > 30 OR (strlen($name) < 6))
{
err('Tên quá dài or quá ngắn! Tối đa chỉ từ 6-30 ký tự');
}elseif(strlen($about) > 100 OR (strlen($about) < 4))
{
err('About quá dài or quá ngắn! Cho phép từ 4-100 ký tự');
}elseif(mysql_num_rows(mysql_query("SELECT `name` FROM `forum_cats` WHERE `name` = '".$name."' ")) != 0)
{
err ('Chuyên mục này đã có sẵn!');
}else{
$add = mysql_query("INSERT INTO `forum_cats` (`name`,`about`,`id_user`,`time`,`closed`) VALUES ('".$name."','".$about."','".$userid."','".$time."','".$close."')");
if($add){
err('Tạo chuyên mục thành công');
$lc = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_cats` ORDER BY `time` DESC LIMIT 1"));
echo '<div class="shadow"><a href="?act=topic&cid='.$lc['id'].'">Tới chuyên mục</a></div>';
}
}
}else{
echo '<div class="tt"> Tạo chuyên mục</div>';
echo '<form action="" method="post"><b>Tên chuyên mục</b></br /><input type="text" name="name"><br /><b>About</b><br /><textarea name="about"></textarea><br /><input type="checkbox" value="1" name="close"> <b>Đóng</b><br /><input type="submit" value="Tạo" name="submit"></form>';
echo '<a href="javascript:history.go(-1)">← Back</a>';
}
echo '</div>';
break;
case 'view':
$id = num($_GET['id']);
$q_cid = mysql_fetch_assoc(mysql_query("SELECT `id_cat` FROM `forum_topics` WHERE `id` = '".$id."' "));
$cid = $q_cid['id_cat'];
$ch_id = mysql_query("SELECT `id` FROM `forum_msg` WHERE `id_topic` = '".$id."' ");
$ch_cid = mysql_query("SELECT `id` FROM `forum_topics` WHERE `id_cat` = '".$cid."' ");
if(!mysql_num_rows($ch_id) OR !mysql_num_rows($ch_cid)){
header('location: index.php');
}
$url = $_SERVER['REQUEST_URI'] ;
#####pages#####
$count_msg = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_msg` WHERE `id_topic` = '".$id."' "),0);
$display = 6;
$count_pages = ceil($count_msg/$display);
$page = (isset($_GET['page']) and is_numeric($_GET['page']) and $_GET['page']>1 and $_GET['page']<=$count_pages) ? $_GET['page'] : 1;
$start = $page*$display-$display;
################
if ($page=="") {
echo '<script type="text/javascript">stt=0;</script>';
}else{
echo '<script type="text/javascript">stt=( '.$page.' - 1 )*6 ;</script>';
}
$q_view = mysql_query("SELECT * FROM `forum_msg` WHERE `id_topic` = '".$id."' ORDER BY `time` ASC LIMIT $start,$display");
$t = mysql_fetch_assoc(mysql_query("SELECT `forum_topics`.*,`forum_msg`.* FROM `forum_topics` LEFT JOIN `forum_msg` ON `forum_topics`.`id_user` = `forum_msg`.`id_user` WHERE `forum_topics`.`id` = '".$id."' "));
bk_head(''.$t['title'].'');
require '../inc/head.php';
echo '<div class="list1">';
echo '<div class="tt"> '.$t['title'].' ('.$t['view'].' view)</div>';
if(isset($_GET['edit'])){
$idmsg = $_GET['edit'];
$vidmsg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".$idmsg."' "));
if(isset($_POST['edit'])){
$msg = bk_check($_POST['msg']);
if($msg == $vidmsg['text']){
err('Lỗi');
}else{
$edit = mysql_query("UPDATE forum_msg SET text = '$msg', edit_by = '$userid', edit_time = '".time()."' WHERE id = '$idmsg' ");
header('location: /forum/?act=view&id='.$id.'');
}}
echo '<form action="" method="post"><textarea name="msg">'.$vidmsg['text'].'</textarea><br /><input type="submit" value="Save" name="edit" class="submit"></form>';
echo '<div class="shadow"><a href="javascript:history.go(-1)">← Back</a></div></div>';
}elseif(isset($_GET['del']))
{
$idmsg = $_GET['del'];
$vidmsg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".$idmsg."' "));
if(isset($_POST['submit'])){
$q = bk_check($_POST['q']);
if($q == "1" AND $count_msg > 1){
mysql_query("DELETE FROM `forum_msg` WHERE `id` = '".$idmsg."' ");
header('location: /forum/?act=view&id='.$id.'');
}else{
header('location: /forum/?act=view&id='.$id.'');
}
}
echo '<div class="left_bot">'.smiles($vidmsg['text']).'<br />Xóa cmt này?<br /><form action="" method="post"><select name="q"><option value="1">Yes</option><option value="2">No</option></select><br /><input type="submit" value="OK" name="submit"></form>';
echo '<br /><a href="javascript:history.go(-1)">← Back</a></div>';
}elseif(isset($_GET['close']))
{
if(user_info($t['id_user'],'level') > $datauser['level'] AND $t['id_user'] != $userid ){
header('location: /forum/?act=view&id='.$id.'');
}
if($t['closed'] == "1"){header('location: /forum/?act=view&id='.$id.'');}
if(isset($_POST['submit'])){
$q = num($_POST['q']);
if($q == "1"){
mysql_query("UPDATE `forum_topics` SET `closed` = '1', `who_close` = '".$userid."' WHERE `id` = '".$id."' ");
header('location: /forum/?act=view&id='.$id.'');
}else{
header('location: /forum/?act=view&id='.$id.'');
}
}
else{
echo '<div class="shadow">'.smiles($t['title']).'<br />Close topic này?<br /><font color="red"><b>Lưu ý:</b></font> Close topic đồng nghĩa với việc ko nhận thêm bất kì cmt nào trong topic này nữa!<br /><form action="" method="post"><select name="q"><option value="1">Yes</option><option value="2">No</option></select><br /><input type="submit" value="OK" name="submit"></form>';
echo '<br /><a href="javascript:history.go(-1)">← Back</a></div></div>';
}
}elseif(isset($_GET['open']))
{
if($t['closed'] == "0"){header('location: /forum/?act=view&id='.$id.'');}
if(isset($_POST['submit'])){
$q = num($_POST['q']);
if($q == "1"){
mysql_query("UPDATE `forum_topics` SET `closed` = '0' WHERE `id` = '".$id."' ");
header('location: /forum/?act=view&id='.$id.'');
}else{
header('location: /forum/?act=view&id='.$id.'');
}
}else{
echo '<div class="left_bot">'.smiles($t['title']).'<br />Mở topic này?<br /><font color="red"><b>Lưu ý:</b></font> Mở topic đồng nghĩa với việc cho phép người khác cmt trong topic này!<br /><form action="" method="post"><select name="q"><option value="1">Yes</option><option value="2">No</option></select><br /><input type="submit" value="OK" name="submit"></form>';
echo '<br /><a href="javascript:history.go(-1)">← Back</a></div>';
}
}elseif(isset($_GET['rename']))
{
if(isset($_POST['submit'])){
$name = bk_check($_POST['name']);
if($name == $t['title']){
err('Có đổi cmgđ, đùa bố à!');
echo '<a href="javascript:history.go(-1)">← Back</a>';
}elseif(strlen($name) > 100 OR strlen($name) < 6)
{
err('Tên quá ngắn or quá dài');
echo '<a href="javascript:history.go(-1)">← Back</a>';
}else{
mysql_query("UPDATE `forum_topics` SET `title` = '".$name."' WHERE `id` = '".$id."' ");
header('location: /forum/?act=view&id='.$id.'');
}
}else{
####form rename
echo ''.smiles($t['title']).'<br />Đổi tên topic này?<br /><font color="red"><b>Lưu ý:</b></font> Đổi tên bậy bạ là ra đảo à nha! <img src="/smiles/yao.png" /><br /><form action="" method="post"><textarea name="name">'.$t['title'].'</textarea><br /><input type="submit" value="OK" name="submit" class="submit"></form>';
echo '<br /><a href="javascript:history.go(-1)">← Back</a></div>';
}
}else{
mysql_query("UPDATE forum_topics SET view = view+1 WHERE id = '$id' ");
$i = 1;
while ($view = mysql_fetch_assoc($q_view)){
echo '<div class="list1">';
?>
<script type="text/javascript"> stt++; document.write('<a href="'+location.href+'#'+stt+'" id="'+stt+'" name="'+stt+'" style="float:right;"><b>#'+stt+'</b></a>'); </script>
<?php
echo ''.user($view['id_user']).' ('.time_post($view['time']).')';
echo '<br />'.smiles(tags($view['text'])).'';
if($view['edit_by'] != "0"){
echo '<br /><small>Sửa bởi: '.user_info($view['edit_by'],'username').'</small>';
}
if($datauser['level'] >= 4 OR $view['id_user'] == $userid){
echo '<br /><br /><div class="shadow">• <a href="/forum/?act=view&id='.$id.'&edit='.$view['id'].'">Sửa</a> •<a href="/forum/?act=view&id='.$id.'&del='.$view['id'].'"> Xóa</a></div>';
}
echo '</div>';
}
if($count_msg > 6){
echo '<div class="pages"><div class="list">';
navi($page,$count_pages,"/threads/$id-page=");
echo '</div></div><br />';
}
echo '<div class="list1">';
if(isset($_POST['submit'])){
$time = time();
$text = $_POST['text'];
$pages = isset($_GET['page']) ? $_GET['page']:'1';
if(empty($text) OR strlen($text) > 1000 OR strlen($text) < 2){err('Nội dung bạn nhập không đủ chiều dài!');}
else{
$add = mysql_query("INSERT INTO `forum_msg` (`id_cat`,`id_topic`,`id_user`,`time`,`text`) VALUES ('".$cid."','".$id."','".$userid."','".$time."','".$text."')");
$tb = mysql_query("INSERT INTO `notice` (`id_id`,`type`,`time`,`id_from`,`read`,`pages`,`id_user`) VALUES ('".$id."','c','".time()."','".$userid."','0','".$count_pages."','".$t['id_user']."')");
if($add){
header('location: /forum/?act=view&id='.$id.'&page='.$count_pages.'');
}
}
}
if($t['closed'] == "0"){
echo '<br /><form action="" method="post"><textarea name="text"></textarea><br /><input type="submit" value="Trả Lời" name="submit" class="submit"></form>';
}else{
echo '<div class="notic">Topic này đã đóng bởi '.user_info($t['who_close'],'username').'!</div>';
}
if($datauser['level'] >= 4 OR $t['id_user'] == $userid){
if($t['closed'] != 1){
echo '• <a href="/forum/?act=view&id='.$id.'&close">Close topic</a>';
}else{
echo '• <a href="/forum/?act=view&id='.$id.'&open">Mở topic</a>';
}
echo'<br />• <a href="/forum/?act=view&id='.$id.'&rename">Sửa tên topic</a>';
}
echo '</div><div class="shadow"><a href="/forum/'.$cid.'">←Về chuyên mục</a></div></div>';
}
break;
}
bk_foot();