View file gallery/photo.php

File size: 5.95Kb
<?php

require '../inc/func.php';
bk_head('Xem ảnh');
require '../inc/head.php';
if(!$user) {
header('location: /index.php');
}
echo '<div class="list1">';
$photo['id'] = num($_GET['num']);
$q = mysql_query("SELECT * FROM `album_photo` WHERE `id` = '$photo[id]'");
$photo = mysql_fetch_assoc($q);
if(!mysql_num_rows($q)){
	err (''.$lng_photo['not'].'<br /><a href="index.php"> '.$lng_photo['home'].' </a>');
echo '</div>';
	bk_foot();
exit;
}

if($photo['user'] == $userid && isset($_GET['dell_photo'])){
	 if($photo['name'] == $datauser['avatar']){
		err (''.$lng_photo['y'].'');

	} else { 
		unlink('/gallery/photos/'.$photo['user'].'/small/'.$photo['name'].'');
		unlink('/gallery/photos/'.$photo['user'].'/micro/'.$photo['name'].'');
		unlink('/gallery/photos/'.$photo['user'].'/ori/'.$photo['name'].'');
		mysql_query("DELETE FROM `album_photo` WHERE `id` = '$photo[id]'");
		mysql_query("OPTIMIZE TABLE `album_photo`");
		header("Location: index.php");
	 }
}
$q = mysql_fetch_assoc(mysql_query("SELECT * FROM `album_photo` WHERE `id` = '$photo[id]'"));
$next = mysql_fetch_assoc(mysql_query("SELECT * FROM `album_photo` WHERE `album` = '$q[album]' AND `id` > '$photo[id]' ORDER BY `id`"));
$pre = mysql_fetch_assoc(mysql_query("SELECT * FROM `album_photo` WHERE `album` = '$q[album]' AND `id` < '$photo[id]' ORDER BY `id` DESC LIMIT 1"));




echo '<div class="photo">
<div style="text-align:center;">';
echo '<img src="/gallery/photos/'.$photo['user'].'/small/' . $photo['name'] . '" />';
echo '</div>';
echo '<a style="color: #FFFFFF;" href="'.homeurl.'/gallery/photo.php?num='.$pre['id'].'">Previous</a><span style="float: right;"> <a style="color: #FFFFFF;" href="'.homeurl.'/gallery/photo.php?num='.$next['id'].'">Next</a>';
echo '</div>';



####like photo####
$ch_like = mysql_result(mysql_query("SELECT COUNT(*) FROM `album_likes` WHERE `ida` = '".$photo['id']."' AND `id_user` = '$userid' "),0);
$c_likes = mysql_result(mysql_query("SELECT COUNT(*) FROM `album_likes` WHERE `ida` = '".$photo['id']."' "),0);
echo '<div class="shadow">'.($ch_like == 0 ? '<a href="photo.php?num='.$photo['id'].'&like">Like</a>':'<a href="photo.php?num='.$photo['id'].'&unlike">UnLike</a>').'&nbsp;&nbsp;&nbsp;<a href="/gallery/photos/'.$photo['user'].'/ori/' . $photo['name'] . '">View full size</a></div>';

if($c_likes){
echo '<div class="shadark">&nbsp;&nbsp;&nbsp;'.$c_likes.' <img src="/images/like.gif" /> <a href="photo.php?num='.$photo['id'].'&wholikes">Likes Photo</a></div>';
}

if(isset($_GET['like'])){
mysql_query("INSERT INTO album_likes (ida,id_user) VALUES ('$photo[id]','$userid')");
if($photo['user'] != $userid){
mysql_query("INSERT INTO notice (id_id,id_user,type,time,id_from) VALUES ('$photo[id]','$photo[user]','la',".time().",'$userid')");
}
header('location: photo.php?num='.$photo['id'].'');
}

if(isset($_GET['unlike'])){
if(!mysql_num_rows(mysql_query("SELECT COUNT(*) FROM `album_likes` WHERE `ida` = '".$photo['id']."' ")))
{
header('location: photo.php?num='.$photo['id'].'');
}else{
mysql_query("DELETE FROM `album_likes` WHERE `ida` = '".$photo['id']."' AND `id_user` = '".$userid."' ");
mysql_query("OPTIMIZE `album_likes`");
header('location: photo.php?num='.$photo['id'].'');
}
}

if(isset($_GET['wholikes'])){
$q_likes = mysql_query("SELECT * FROM `album_likes` WHERE `ida` = '".$photo['id']."' ");
echo '<div class="tt">Ai like ảnh?</div><div class="shadow">';
while ($who = mysql_fetch_assoc($q_likes)){
echo ''.user($who['id_user']).', ';
}
echo '<br /><br /><a href="javascript:history.go(-1)"><b>&larr; Back</b></a>';
echo '</div></div>';
bk_foot();
exit;
}
########end like###########
if($photo['user'] == $userid && isset($_GET['avatar'])){
	mysql_query("UPDATE users SET avatar = '$photo[name]' WHERE id = '$userid'");
	err(''.$lng_photo['suc'].'');
}

echo '<div class="shadow">';
if($photo['user'] == $userid){
	if($datauser['avatar'] != $photo['name']){
		echo '<br />&raquo; <a href="?num='.$photo['id'].'&amp;avatar">'.$lng_photo['set'].'</a>';
	}
	echo '<br />&raquo; <a href="?num='.$photo['id'].'&amp;dell_photo">'.$lng_photo['del'].'</a>';
}
echo '</div>';

######show cmt####
########page###########
$c_cmt = mysql_result(mysql_query("SELECT COUNT(*) FROM `album_cmt` WHERE `ida` = '".$photo['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;
######page###########

$q_cmt = mysql_query("SELECT * FROM `album_cmt` WHERE `ida` = '".$photo['id']."' ORDER BY `time` DESC LIMIT $start,$display");
echo '<br />Bình Luận...<div class="list1">';
if($c_cmt){
while ($cmt = mysql_fetch_assoc($q_cmt)){
echo ''.user($cmt['id_user']).' ('.time_post($cmt['time']).')<br />'.smiles(tags($cmt['msg'])).'';
echo '<hr>';
}
echo '</div>';
}else{
echo '<div class="notic">Chưa có ai chê ảnh này <img src="/smiles/yao.png" /></div></div>';
}

####page
if($c_cmt > 3 && $page < $count_pages)
{
echo '<div class="shadow">';
pages($page,$count_pages,'?num='.$photo['id'].'&page=');
echo '</div><br />';
}

###page
//echo '</div>';

######end show#######

#####form cmt
echo '<div class="shadow"><form action="" method="post">Nói gì đó về ảnh này<br /><textarea name="msg"></textarea><input type="submit" value="Comment" name="submit"></form></div>';



	if(isset($_POST['submit'])){
	$msg = bk_check($_POST['msg']);
	if( strlen($msg) > 0 && strlen($msg) < 200){
	mysql_query("INSERT INTO album_cmt (ida,id_user,msg,time) VALUES ('$photo[id]','$userid','$msg',".time().") ");
	header('location: ?num='.$photo['id'].'');
	}else{
	echo '<div class="notic">Nội dung quá dài, tối đa chỉ 200 ký tự !</div>';
	}
	
	}
	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();