<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';
include_once 'sys/inc/thead.php';
aut();

if (!isset($user) && !isset($_GET['id'])){header("Location: /index.php?".SID);exit;}
if (isset($user))$ank['id']=$user['id'];
if (isset($_GET['id']))$ank['id']=intval($_GET['id']);

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$ank[id]' LIMIT 1"),0)==0){header("Location: /info.php?".SID);exit;}
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank[id] LIMIT 1"));
$set['title']=$ank['nick'].'&nbsp; Wall'; //
include_once 'sys/inc/thead.php';
//title();

if ((!isset($_SESSION['refer']) || $_SESSION['refer']==NULL)
&& isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL &&
!ereg('info\.php',$_SERVER['HTTP_REFERER']))
$_SESSION['refer']=str_replace('&','&amp;',ereg_replace('^http://[^/]*/','/', $_SERVER['HTTP_REFERER']));

$user_id = $ank['id'];
echo "<br/><b> Profil $ank[nick]</b>";

if (isset($user) && $user['id']!=$ank['id']){
echo "<br/><a href=\"podarki/gifts.php?id=$ank[id]&pod=1\">Sent gift </a> &#183;";
echo "<a href=\"mail.php?id=$ank[id]\"> Sent mail</a>";
}
echo "<table class='post' width='100%'>";
echo "<tr>\n";
echo "<td width='35%' align='center'>";
avatars($ank['id']);
echo "<br/><img src='/rat.php?p=$ank[rating]' height='10' width='70'/>";
echo"</td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td>\n";
if($ank[id]==$user[id]){
echo "<img src='/style/icons/avt.png' height='10' width='10'/> <a href='/avatar.php'>Upload avatar</a><br/>";
}
echo '<img src="/style/icons/gallery.png" height="10" width="10"/> <a href="/foto/'.$ank['id'].'/">Album</a> (';
echo mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `id_user` = '$ank[id]'"),0);
echo ")";
echo"</td></tr>";
echo "</table>\n";


echo "</div>";
$user_id = $ank['id'];
if(isset($_GET['delete']) AND !empty($_GET['delete']))
{
$delete = (int)$_GET['delete'];
if($user['level'] > 3 OR $ank['id'] == $user['id'])
{
$query = @mysql_query("SELECT `id` FROM `wall` WHERE `user_id` = '$user_id' AND `id` = '$delete';");
if(@mysql_affected_rows() > 0)
{
@mysql_query("DELETE FROM `wall` WHERE `user_id` = '$user_id' AND `id` = '$delete' LIMIT 1;");

echo '<div class="msg">successful message delete!</div>';
}
else
echo '<div class="news">not fount!</div>';
}
else
echo '<div class="news">you are not allowed to delete this message!</div>';
}

# Add message:
if(isset($_POST['message']) AND isset($user))
{
$message = $_POST['message'];

if(isset($_POST['translit']) AND $_POST['translit']) $message = translit($message);

$err = '';

if(strlen2($message) > 512) $err .= 'Message is too long!!<br />';
if(strlen2($message) < 2) $err .= 'Message is too short!!<br />';
if(@mysql_result(@mysql_query("SELECT COUNT(*) FROM `wall` WHERE `user_id` = '$user_id' AND `message` = '".@mysql_escape_string($message)."' AND `time` > '".($time - 300)."' LIMIT 1"), 0) != 0) $err .= 'You repeat the previous message!!<br />';
if(time() - @mysql_result(@mysql_query("SELECT `time` FROM `wall` WHERE `user_id` = '$user_id' ORDER BY `id` DESC LIMIT 1;"), 0) < 30) $err .= 'Not too often write message!!<br />';

if($err != '')
{
echo '<div class="msg">There is an error:<br />'.$err.'</div>';
}
else
{
$message = @mysql_escape_string($message);
################## EDITED BY ANTOQ HTTP://INDWAP.TK###########################
@mysql_query("INSERT INTO `wall` (`user_id`, `who`, `time`, `message`) values('$user_id', '".$user['id']."', '".time()."', '$message')");
@mysql_query("UPDATE `user` SET `msg_on_wall` = `msg_on_wall` + 1 WHERE `id` = '".$user['id']."' LIMIT 1");

if($user['id']!=$user_id){

$msg = '[url=/info.php?id='.$user['id'].'] '.$user['nick'].'[/url] Posted [url=/info.php]massage[/url] on your wall';
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '".$user_id."', '".$msg."', '".$time."')");
}
mysql_query("OPTIMIZE TABLE `wall`, `user`, `jurnal`");
echo '<div class="news">message successfull added!!</div>';
$ddg = '[img]http://indwap.tk/style/wtw.png[/img][url=/info.php?id='.$ank['id'].'][b] '.$ank['nick'].'[/b][/url] '.htmlspecialchars($_POST['message']).'';
mysql_query("INSERT INTO `statuse_list` (`id_user`, `name`, `msg`, `time`, `privat`) values('$user[id]', '$name', '$ddg', '$time', '$privat')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
}
}
if (!isset($_GET['info'])){
echo "<div class='main_menu'>";
echo "<a name='up' id='up'></a><a href='#down'><img src='/style/icons/down.png'/></a>  <b>Dinding</b> &#183;<a href='?id=$ank[id]&amp;info'>info</a>";
echo "</div>";
# Form message
$d1sql = mysql_query("SELECT COUNT(*) FROM `frends_new` WHERE (`user` = '$user[id]' AND `to` = '$ank[id]') OR (`user` = '$ank[id]' AND `to` = '$user[id]') LIMIT 1");
$d2sql = mysql_query("SELECT COUNT(*) FROM `frends` WHERE (`user` = '$ank[id]' AND `frend` = '$user[id]') OR (`user` = '$user[id]' AND `frend` = '$ank[id]') LIMIT 1");
if (isset($user) && $user['id']!=$ank['id'] && mysql_result($d1sql, 0)==0 && mysql_result($d2sql, 0)==0)
{
echo 'The message field will appear after adding as a friend!!<br/><a href="/frend_add.php?id='.$ank['id'].'">add as friend</a>';
}
else
{
if (isset($user) && $user['id']!=$ank['id'])
{
echo '<div class="main_menu"><form method="post" action="info.php?id='.$user_id.'">
Send '.$ank['nick'].' message<br />
<textarea name="message"></textarea><br /><input class="button" type="submit" value="Send"/><a href="/smiles/">Smiles</a>
</form></div>';
}
}
################## EDITED BY ANTOQ HTTP://INDWAP.TK###########################
# Display message:
$k_post = @mysql_result(@mysql_query("SELECT COUNT(*) FROM `wall` WHERE `user_id` = '$user_id'"), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];
if(!$k_post)
{
echo '<div class="p_t">No message!!</div>';
}

function getAvatar($id)
{
global $set;
if(is_file(H."sys/avatar/$id.gif"))
return "<img src='/sys/avatar/$id.gif' alt='wapid.org' width='32' height='32' />\n";
elseif (is_file(H."sys/avatar/$id.jpg"))
return "<img src='/sys/avatar/$id.jpg' alt='wapid.org' width='32' height='32' />\n";
elseif (is_file(H."sys/avatar/$id.png"))
return "<img src='/sys/avatar/$id.png' alt='wapid.org' width='32' height='32' />\n";
else
return "<img src='/sys/avatar/0.png' alt='wapid.org' width='32' height='32' />\n";
}
$query = @mysql_query("SELECT * FROM `wall` WHERE `user_id` = '$user_id' ORDER BY `time` DESC LIMIT $start, $set[p_str];");

while ($array = mysql_fetch_array($query))
{
$user_nick = @mysql_result(@mysql_query("SELECT `nick` FROM `user` WHERE `id` = '".$array['who']."';"), 0);
echo ceil(ceil($i / 2) - ($i / 2)) == 0 ? '<div class="list1">' : '<div class="list2">';
echo '<table class="post" width="100%">';
echo '<tr>';
//echo '<td width="20%" align="center">';
//echo '<a href="/info.php?id='.$array['who'].'">'.avt($array['who']).'</a>';
//echo '</td>';
echo '<td class="status" width="80%" valign="top">';
echo '<a href="/info.php?id='.$array['who'].'">'.$user_nick.'</a> '.online($array['who']).'';
echo ' '.output_text($array['message']).'<br/>';
echo '<span class="post"><img src="/style/icons/msg.png" height="10" width="10" /> <font class="time">'.waktu($array['time']).'</font></span>';
if (isset($user) && $user['id']==$ank['id'])
{
echo ' &#183; <a href="/info.php?id='.$array['who'].'"><span class="post">Reply</span></a> ';
}
if($user['level'] > 3 OR $ank['id'] == $user['id'])
{
echo ' &#183; <a href="info.php?id='.$user_id.'&amp;wall&amp;delete='.$array['id'].'"><span class="post">Delete</span></a>';
}
echo'</td>';
echo'</tr>';
//echo'<tr>';
//echo "<td colspan='2'>";
//echo ''.output_text($array['message']).'';
################## EDITED BY ANTOQ HTTP://INDWAP.TK###########################
//echo'<br />';
//echo '<span class="post"><img src="/style/icons/msg.png" height="10" width="10" /> '.vremja($array['time']).'</span>';
//echo '</td>';
//echo '</tr>';
echo '</table>';
echo '</div>';
++$i;
}
echo "<div class='footer'>";
echo "<a name='down' id='down'></a><a href='#up'><img src='/style/icons/up.png' height='10' width='10'/></a><b> Dinding</b> <br/>";

echo '<img src="/style/icons/users.png" height="10" width="10" /> <a href="frend.php?id='.$ank['id'].'">Friends</a> (';
echo mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE `user` = '$ank[id]' AND `i` = '1'"), 0);
echo ")<br/>";

echo "<img src='/style/icons/gift.png' height='10' width='10' /> <a href=\"gifts.php?id=$ank[id]\" title=\"Bce\">Gift</a>\n";
$k_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `gifts` WHERE `id_user` = $ank[id] ",$db), 0);
echo " ($k_p)<br />";

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `gifts` WHERE `id_user` = '$ank[id]' LIMIT 1"), 0);

if ($k_post==0)
{
echo '<sub>There is no prize</sub>';
}

$q = mysql_query("SELECT * FROM `gifts` WHERE `id_user` = '$ank[id]' ORDER BY time DESC LIMIT 4");
while ($f = mysql_fetch_array($q))
{
$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$f[ot_id]' LIMIT 1"));
echo"<img src='/gifts/".$f['id_gifts'].".png' width='32' height='32'  alt='' class='icon'/></hr>";
}
echo "</div>";
}
else {
echo "<div class='main_menu'>";
echo "<a name='up' id='up'></a><a href='#down'><img src='/style/icons/down.png' height='10' width='10'/> <a href='?id=$ank[id]'>Info</a> &#183; <b>Dinding</b></div>";
include_once 'ank.php';
}
if($k_page > 1) str('info.php?id='.$user_id.'&amp;wall&amp;'.rand(1000, 9999).'&amp;', $k_page, $page);
################## EDITED BY ANTOQ HTTP://INDWAP.TK###########################
include_once 'sys/inc/tfoot.php';
?>
