Размер файла: 7.81Kb
<?php
require '../inc/func.php';
if(!$user){
header('location:/ index.php');
}
$id = isset($_GET['id'])? num($_GET['id']):'1';
$status=mysql_fetch_array(mysql_query("select * from `status` where `id`='".$id."';"));
$c_likes = mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status` = '".$id."' "),0);
$ch_likes = mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status` = '".$status['id']."' AND `id_user` = '".$userid."' "),0);
switch (isset($_GET['act']) ? $_GET['act']:''){
default :
if(empty($id)){
header('location: /index.php');
}
$ch_id = mysql_query("SELECT `id` FROM `status` WHERE `id` = '".$id."' ");
if(!mysql_num_rows($ch_id)){
header('location: /index.php');
}
bk_head('Trò Chuyện');
require '../inc/head.php';
echo '<div class="list1">';
echo '<div class="tt"> Trò Chuyện</div>';
if(isset($_POST['submit'])){
$msg = bk_check($_POST['msg']);
$tagtv = bk_check($_POST['msg']);
##tag thanh vien
if(preg_match('#@([\w\d]{2,})#si',$tagtv)){
preg_match_all('#@([\w\d]{2,})#si',$tagtv,$arr);
foreach($arr[1] as $tag){
$db=mysql_fetch_array(mysql_query("select * from users where username='{$tag}'"));
if(mysql_num_rows(mysql_query("select * from users where username='{$tag}'"))==0 || $db['id']==$userid){
} else {
mysql_query("INSERT INTO `notice` SET
`id_topic`='".$status['id']."',
`type` = 't',
`id_user`='".$db['id']."',
`id_from`='".$userid."',
`time` = '" . time() . "'
");
}
}
}
##tag thanh vien
if(empty($msg) OR strlen($msg) > 9999 OR strlen($msg) < 2){
err('Lỗi! Nội dung cmt quá ngắn or quá dài');
}else{
mysql_query("INSERT INTO status_cmt (id_user,id_status,msg,time) VALUES ('$userid','$id','$msg',".time().")");
if ($userid!=$status['from_id']){
mysql_query("INSERT INTO notice (id_id,type,time,id_user,id_from) VALUES ('$id','cmt',".time().",'$status[from_id]','$userid')");
}
}
}
echo '<div class="list1">';
echo '<b>'.user($status['from_id']).'</b><br /><br /><b>'.smiles(tags($status['text'])).'</b>';
if($userid == $status['from_id'] OR $datauser['level'] >=4){
echo '<br />•<a href="/status/list.php?act=edit&id='.$id.'"> Edit</a>';
}
echo '</div>';
echo '<div class="shadow">
<span style="color: #8f8f8f;">'.time_post($status['time']).'</span> ';
echo ' '.($ch_likes > 0 ? '<a href="like.php?id='.$id.'&unlike">Unlike</a>':'<a href="like.php?id='.$id.'&like">Like</a>').' ';
if($c_likes){
echo '<br /><a href="?act=who_likes&id='.$id.'">
'.$c_likes.' people like this.</a><hr />';
}
echo '</div>';
$c_cmt = mysql_result(mysql_query("SELECT COUNT(*) FROM `status_cmt` WHERE `id_status` = '".$id."' "),0);
$display = 3;
$count_pages = ceil($c_cmt/$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;
$q_cmt = mysql_query("SELECT * FROM `status_cmt` WHERE `id_status` = '".$id."' ORDER BY `id` ASC LIMIT $start,$display");
if($c_cmt > 0){
while ($cmt = mysql_fetch_assoc($q_cmt)){
echo '<div class="list1">';
echo '<b>'.user($cmt['id_user']).' ('.time_post($cmt['time']).')</b><br /><br />'.smiles(tags($cmt['msg'])).'';
if($userid == $cmt['id_user'] OR $datauser['level'] >=4){
echo '<br /><br />• <a href="/status/list.php?act=editcmt&mid='.$cmt['id'].'">Edit</a> • <a href="/status/list.php?act=delcmt&mid='.$cmt['id'].'">Del</a>';
}
echo '</div>';
}
if($c_cmt > 3 && $page < $count_pages){
echo '<div class="shadow">';
pages($page,$count_pages,'list.php?id='.$id.'&page=');
echo '</div><br />';
}
}
echo '<form action="" method="post">
Write a comment...<br/>
<textarea name="msg" cols="20" rows="2"></textarea>
<input type="submit" class="login" style="vertical-align: top;" value="Comment" name="submit"/>
</form>
';
break;
case 'who_likes':
bk_head('Who Likes This');
require '../inc/head.php';
if(!$c_likes){
header('location: list.php?id='.$id.'');
}
$q_w_likes = mysql_query("SELECT `id_user` FROM `status_like` WHERE `id_status` = '".$id."' ");
echo '<div class="list1">';
echo '<div class="tt"> People likes this</div>';
echo '<div class="blank">';
if($c_likes < 5){
while ($w_likes = mysql_fetch_assoc($q_w_likes)){
echo '<div class="list1">';
echo avatar($w_likes['id_user'], 35, 50);
echo '<b>'.user_info($w_likes['id_user'],'username').'</b>';
echo '</div>';
}
}else{
while ($w_likes = mysql_fetch_assoc($q_w_likes)){
echo ''.user($w_likes['id_user']).', ';
}
echo '<br /><br /> likes this.';
}
echo '<br /><a href="javascript:history.go(-1)">← Back</a>';
echo '</div>';
break;
case 'edit':
bk_head('Edit');
require '../inc/head.php';
if($userid != $status['from_id']){
header('location: list.php?id='.$id.'');
}
if(isset($_POST['submit'])){
$msg = bk_check($_POST['msg']);
if(empty($_POST['msg']) OR strlen($_POST['msg']) > 9999 OR strlen($_POST['msg']) < 2){
err('Chiều dài cmmt quá ngắn or quá dài');
}else{
mysql_query("UPDATE status SET text = '$msg' WHERE id = '$id' ");
header('location: list.php?id='.$id.'');
}
}else{
####form edit
echo '<div class="list1"><div class="tt"> Sửa status</div>';
echo '<div class="shadow">';
echo '<form action="" method="post">';
echo '<br /><textarea name="msg">'.$status['text'].'</textarea>';
echo '<br /><input type="submit" class="submit" value="Sửa" name="submit">';
echo '</form></div>';
}
break;
case 'editcmt':
bk_head('Edit CMT');
require '../inc/head.php';
$mid = isset($_GET['mid'])? num($_GET['mid']):'1';
$cmt = mysql_fetch_assoc(mysql_query("SELECT * FROM status_cmt WHERE id = '$mid' "));
if($userid != $cmt['id_user'] && $datauser['level'] < 4){
header('location: list.php?id='.$cmt['id_status'].'');
}
if(isset($_POST['submit'])){
$msg = bk_check($_POST['msg']);
if(empty($_POST['msg']) OR strlen($_POST['msg']) > 9999 OR strlen($_POST['msg']) < 2){
err('Chiều dài cmmt quá ngắn or quá dài');
}else{
mysql_query("UPDATE status_cmt SET msg = '$msg' WHERE id = '$mid' ");
header('location: list.php?id='.$cmt['id_status'].'');
}
}else{
####form edit cmt
echo '<div class="list1"><div class="tt"> Sửa cmt</div>';
echo '<div class="shadow">';
echo '<form action="" method="post">';
echo '<textarea name="msg">'.$cmt['msg'].'</textarea>';
echo '<br /><input type="submit" value="Sửa" name="submit">';
echo '</form>';
echo '<a href="javascript:history.go(-1)"><b>← Back</b></a>';
echo '</div>';
}
break;
case 'delcmt':
bk_head('Xóa cmt');
require '../inc/head.php';
$mid = isset($_GET['mid'])? num($_GET['mid']):'';
$cmt = mysql_fetch_assoc(mysql_query("SELECT * FROM status_cmt WHERE id = '$mid' "));
if(empty($mid)){
header('location: /status/list.php?id=1');
}
if($userid != $cmt['id_user'] && $datauser['level'] < 4){
header('location: list.php?id='.$cmt['id_status'].'');
}
if(isset($_POST['submit'])){
$q = num($_POST['q']);
if($q == '0'){
header('location: list.php?id='.$cmt['id_status'].'');
}else
{
mysql_query("DELETE FROM status_cmt WHERE id = '$mid' ");
mysql_query("OPTIMIZE `status_cmt`");
header('location: list.php?id='.$cmt['id_status'].'');
}
}else{
###form del
echo '<div class="list1"><div class="tt"> Xóa cmt</div>';
echo '<form action="" method="post">';
echo 'Bạn muốn xóa cmt này?<br />';
echo '<select class="dob_select" name="q">';
echo '<option value="1">Xóa</option><option value="0">Không</option>';
echo '<input type="submit" class="button" value="OK" name="submit">';
echo '</select>';
echo '<br /><a href="javascript:history.go(-1)"><b>← Back</b></a>';
echo '</form>';
}
break;
}
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>';
bk_foot();
?>