<?
if (isset($_GET['act']) && $_GET['act']=='txt')
{
ob_clean();
ob_implicit_flush();
header('Content-Type: text/plain; charset=utf-8', true);

header('Content-Disposition: attachment; filename="'.retranslit($them['name']).'.txt";');
echo "Tema: $them[name] ($forum[name]/$razdel[name])\r\n";
$q=mysql_query("SELECT * FROM `forum_p` WHERE `id_them` = '$them[id]' AND `id_forum` = '$forum[id]' AND `id_razdel` = '$razdel[id]' ORDER BY `time` ASC");

while ($post = mysql_fetch_assoc($q))
{
echo "\r\n";
$ank=get_user($post['id_user']);
echo "$ank[nick] (".date("j M Y H:i", $post['time']).")\r\n";

if ($post['cit']!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id` = '$post[cit]'"),0)==1)
{
$cit=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_p` WHERE `id` = '$post[cit]' LIMIT 1"));
$ank_c=get_user($cit['id_user']);
echo "--Mengutip--\r\n";
echo "$ank_c[nick] (".date("j M Y &#1074; H:i", $cit['time'])."):\r\n";
echo trim(br($cit['msg'],"\r\n"))."\r\n";
echo "----------\r\n";
}
echo trim(br($post['msg'],"\r\n"))."\r\n";
}
echo "\r\Sumber: http://$_SERVER[SERVER_NAME]/forum/$forum[id]/$razdel[id]/$them[id]/\r\n";
exit;
}

if (isset($user) && isset($_GET['f_del']) && is_numeric($_GET['f_del']) && isset($_SESSION['file'][$_GET['f_del']]))
{
unlink($_SESSION['file'][$_GET['f_del']]['tmp_name']);
}

if (isset($user) && isset($_GET['zakl']) && $_GET['zakl']==1)
{
mysql_query("INSERT INTO `forum_zakl` (`id_user`, `time`,  `id_them`, `time_obn`) values('$user[id]', '$time', '$them[id]', '$time')");
//if (mysql_error()!=NULL)
echo mysql_error();
msg('Topik ditambah ke Forum favorit');
}
elseif (isset($user) && isset($_GET['zakl']) && $_GET['zakl']==0)
{
mysql_query("DELETE FROM `forum_zakl` WHERE `id_user` = '$user[id]' AND `id_them` = '$them[id]'");
//if (mysql_error()!=NULL)
echo mysql_error();
msg('Topik telah di hapus dari Forum favorit');
}

if (isset($user) && isset($_GET['act']) && $_GET['act']=='new' && isset($_FILES['file_f']) && ereg('\.', $_FILES['file_f']['name']) && isset($_POST['file_s']))
{
copy($_FILES['file_f']['tmp_name'], H.'sys/tmp/'.$user['id'].'_'.md5_file($_FILES['file_f']['tmp_name']).'.forum.tmp');
chmod(H.'sys/tmp/'.$user['id'].'_'.md5_file($_FILES['file_f']['tmp_name']).'.forum.tmp', 0777);

if (isset($_SESSION['file']))$next_f=count($_SESSION['file']);else $next_f=0;

$file=esc(stripcslashes(htmlspecialchars($_FILES['file_f']['name'])));
$_SESSION['file'][$next_f]['name']=eregi_replace('\.[^\.]*$', NULL, $file);

$_SESSION['file'][$next_f]['ras']=strtolower(eregi_replace('^.*\.', NULL, $file));
$_SESSION['file'][$next_f]['tmp_name']=H.'sys/tmp/'.$user['id'].'_'.md5_file($_FILES['file_f']['tmp_name']).'.forum.tmp';
$_SESSION['file'][$next_f]['size']=filesize(H.'sys/tmp/'.$user['id'].'_'.md5_file($_FILES['file_f']['tmp_name']).'.forum.tmp');
$_SESSION['file'][$next_f]['type']=$_FILES['file_f']['type'];
}
if (isset($user) && ($them['close']==0  || $them['close']==1 && user_access('forum_post_close')) && isset($_GET['act']) && $_GET['act']=='new' && isset($_POST['msg']) && !isset($_POST['file_s']))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)<2)$err='Post terlalu pendek,min 2 karakter';
$post1=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_p` WHERE `id_them` = '$them[id]' AND `id_razdel` = '$razdel[id]' AND `id_forum` = '$forum[id]' ORDER BY `time` ASC LIMIT 1"));
$ank=get_user($post1['id_user']);
/*$msg1="$user[nick] New post in topic [url=/forum/$forum[id]/$razdel[id]/]$them[name][/url]";
if (strlen2($msg)>2)mysql_query("INSERT INTO `jurnal`  (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$msg1', '$time')");*/
if (strlen2($msg)>1024)$err='Posting terlalu panjang,max 1024 karakter';

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_them` = '$them[id]' AND `id_forum` = '$forum[id]' AND `id_razdel` = '$razdel[id]' AND `id_user` = '$user[id]' AND `msg` = '".mysql_real_escape_string($msg)."' LIMIT 1"),0)!=0)$err='posting mengulang';

if (!isset($err))
{
if (isset($_POST['cit']) && is_numeric($_POST['cit'])
&& mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id` = '".intval($_POST['cit'])."' AND `id_them` = '".intval($_GET['id_them'])."' AND `id_razdel` = '".intval($_GET['id_razdel'])."' AND `id_forum` = '".intval($_GET['id_forum'])."'"),0)==1)
$cit=intval($_POST['cit']); else $cit='null';
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `forum_zakl` SET `time_obn` = '$time' WHERE `id_them` = '$them[id]'");
mysql_query("INSERT INTO `forum_p` (`id_forum`, `id_razdel`, `id_them`, `id_user`, `msg`, `time`, `cit`) values('$forum[id]', '$razdel[id]', '$them[id]', '$user[id]', '".mysql_real_escape_string($msg)."', '$time', $cit)");
######################## REEDIT BY ANTOQ HTTP://INDWAP.TK ##################
$post_id=mysql_insert_id();

if (isset($_SESSION['file']) && isset($user))
{
for ($i=0; $i<count($_SESSION['file']);$i++)
{
if (isset($_SESSION['file'][$i]) && is_file($_SESSION['file'][$i]['tmp_name']))
{
mysql_query("INSERT INTO `forum_files` (`id_post`, `name`, `ras`, `size`, `type`) values('$post_id', '".$_SESSION['file'][$i]['name']."', '".$_SESSION['file'][$i]['ras']."', '".$_SESSION['file'][$i]['size']."', '".$_SESSION['file'][$i]['type']."')");
$file_id=mysql_insert_id();
copy($_SESSION['file'][$i]['tmp_name'], H.'sys/forum/files/'.$file_id.'.frf');
unlink($_SESSION['file'][$i]['tmp_name']);
}
}
unset($_SESSION['file']);
}
unset($_SESSION['msg']);
mysql_query("UPDATE `forum_r` SET `time` = '$time' WHERE `id` = '$razdel[id]' LIMIT 1");
mysql_query("UPDATE `forum_t` SET `time` = '$time' WHERE `id` = '$them[id]' LIMIT 1");
msg('Posting telah ditambahkan');
aut();

header("Refresh: 1; url=/forum/$forum[id]/$razdel[id]/$them[id]/?page=end&".SID);
echo "<div class='menu'>\n";
echo "<a href=\"/forum/$forum[id]/$razdel[id]/$them[id]/?page=end\"> Back to topik</a><br/>";
echo "<a href=\"/forum/$forum[id]/$razdel[id]/\"> $razdel[name]</a><br/> <a href=\"/forum/$forum[id]/\"> $forum[name]</a>";
echo "</div>\n";
include_once '../sys/inc/tfoot.php';

}

}
######################## REEDIT BY ANTOQ HTTP://INDWAP.TK ##################
if ($them['close']==1)
msg('Topik di Tutup');

if (isset($user) &&  $user['balls']>=1 && $user['rating']>=0 && isset($_GET['id_post'])
&&
mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id` = '$post[id]'"), 0)==1
&&
mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_thank` WHERE `id_user` = '$user[id]' AND `id_post` = '$post[id]'"), 0)==0)
{
if(isset($_GET['rating']) && $_GET['rating']=='up')
{
mysql_query("INSERT INTO `forum_thank` (`id_user`, `id_post`, `rating`) values('$user[id]', '$post[id]', '1')");
msg ('Ucapan terima kasih anda telah kami terima');
}
}
err();
aut();
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_them` = '$them[id]' AND `id_forum` = '$forum[id]' AND `id_razdel` = '$razdel[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

if ((user_access('forum_post_ed') || isset($user) && $ank2['id']==$user['id']) && isset($_GET['act']) && $_GET['act']=='post_delete'){$lim=NULL;}else $lim=" LIMIT $start, $set[p_str]";
$q=mysql_query("SELECT * FROM `forum_p` WHERE `id_them` = '$them[id]' AND `id_forum` = '$forum[id]' AND `id_razdel` = '$razdel[id]' ORDER BY `time` ASC$lim");
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='32px' />\n";
}

if (mysql_num_rows($q)==0)
{
echo "<div class='p_m'>\n";
echo "Tidak ada topik pada \"$them[name]\"\n";
echo "</div>\n";
}

if ((user_access('forum_post_ed') || isset($user) && $ank2['id']==$user['id']) && isset($_GET['act']) && $_GET['act']=='post_delete'){}
$post_k=$start;
echo "<div class='footer'>";
echo "<a name='up' id='up'></a><a href='#down'><img src='/style/icons/down.png'/></a>  ";
echo "  <a href='/forum/search.php'>Search</a> ";
echo "| <a href='/forum/files_list.php'>Files</a>";
echo "</div>";
while ($post = mysql_fetch_assoc($q))
{
$ank=get_user($post['id_user']);
$post_k++;
echo ceil(ceil($i / 2) - ($i / 2)) == 0 ? '<div class="p_m">' : '<div class="p_m">';
echo ''.$ank['group_name'].'';
echo '<table class="post" width="100%">';
echo '<tr>';
echo '<td width="20%" align="center">';
echo'<a href="/info.php?id='.$ank['id'].'">'.getAvatar($ank['id']).'</a>';
echo '</td>';
echo '<td class="p_t" width="80%">';
if (isset($user) && $them['close']==0 || user_access('forum_post_close'))
echo "<span style=\"color:$ank[ncolor]\">$ank[nick]</span> ".online($ank['id'])."";
else
echo "<a href='/info.php?id=$ank[id]'><span style=\"color:$ank[ncolor]\">$ank[nick]</span></a> ".online($ank['id'])."";
echo "<br />";
$k_p_forum=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_user` = '$ank[id]'"),0);
if ($them['close']==0 && isset($user) && $user['id']!=$ank['id'])
echo "<a href='/forum/$forum[id]/$razdel[id]/$them[id]/$post[id]/cit'><span class='btn'>reply</span></a> ";
if (isset($user) && $user['balls']>=25 && $user['rating']>=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_thank` WHERE `id_user` = '$user[id]' AND `id_post` = '$post[id]'"), 0)==0)
{
echo '<a href="/forum/'.$forum['id'].'/'.$razdel['id'].'/'.$them['id'].'/?page='.$page.'&amp;id_post='.$post['id'].'&amp;rating=up"><span class="btn">thank</span></a> ';
}
if (isset($user) && $user['id']!=$ank['id'])
echo " <a href=\"/mail.php?id=$ank[id]\"><span class='btn'>pm</span></a> ";
if (user_access('forum_post_ed') && ($ank['level']<=$user['level'] || $ank['level']==$user['level'] && $ank['id']==$user['id']))
echo "<a href='/forum/$forum[id]/$razdel[id]/$them[id]/$post[id]/edit'><span class='btn'>edit</span></a>";
elseif (isset($user) && $user['id']==$post['id_user'] && $post['time']>time()-600 && $post_k==$k_post)
echo "<br /><a href='/forum/$forum[id]/$razdel[id]/$them[id]/$post[id]/edit'><span class='btn'>edit</span></a>  (".($post['time']+60-time()).")";
echo "</td>";
echo '</tr>';
echo "<tr>";
echo "<td colspan='2'>";
if (isset($user))
{
if ($post['cit']!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id` = '$post[cit]'"),0)==1)
{
$cit=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_p` WHERE `id` = '$post[cit]' LIMIT 1"));
$ank_c=get_user($cit['id_user']);
echo "<div class='cit'><span style=\"color:$ank_c[ncolor]\">$ank_c[nick]</span> bilang...";
echo "<br />";
echo htmlspecialchars(substr($cit['msg'],0,40)) . '...';
echo "</div>";
}
echo output_text($post['msg'])."<br />";
include H.'/forum/inc/file.php';

if (isset($user) && $them['close']==0 || user_access('forum_post_close'))
echo "<div class='time'><img src='/style/icons/msg.png' width='10' height='10'/> ".vremja($post['time'])." -";
echo ' thanks: '.mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_thank` WHERE `id_post` = '$post[id]'"),0).'</span><br />';
$thank=mysql_query("SELECT * FROM `forum_thank` WHERE `id_post` = '$post[id]' ORDER BY `id_user` DESC LIMIT 5");
while ($thanks = mysql_fetch_assoc($thank))
{
$ank_l=get_user($thanks['id_user']);
echo "<img src='/style/icons/suka.gif' width='10' height='10' />$ank_l[nick], ";
}
}
else
{
echo "<div class='msg'><b>Forum Indwap Community</b><br /> Silahkan <a href='/'>login </a> atau <a href='/reg.php'>registrasi</a> terlebih dahulu.. </div>";
}
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'/></a> ";
echo " Total Post: ".mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_forum` = '$forum[id]' AND `id_razdel` = '$razdel[id]' AND `id_them` = '$them[id]'"),0)."";
echo "</div>";
if ((user_access('forum_post_ed') || isset($user) && $ank2['id']==$user['id']) && isset($_GET['act']) && $_GET['act']=='post_delete'){}
if ($k_page>1)str("/forum/$forum[id]/$razdel[id]/$them[id]/?",$k_page,$page);

if ((user_access('forum_post_ed') || isset($user) && $ank2['id']==$user['id']) && isset($_GET['act']) && $_GET['act']=='post_delete'){}
elseif (isset($user) && ($them['close']==0 || $them['close']==1 && user_access('forum_post_close')))
{
if ($user['set_files']==1)
echo "<form method='post' name='message' enctype='multipart/form-data' action='/forum/$forum[id]/$razdel[id]/$them[id]/new?$passgen'>\n";
else
echo "<form method='post' name='message' action='/forum/$forum[id]/$razdel[id]/$them[id]/new?$passgen'>\n";
if (isset($_POST['msg']) && isset($_POST['file_s']))$msg2=output_text($_POST['msg'],false,true,false,false,false); else $msg2=NULL;

echo "<textarea name=\"msg\">$msg2</textarea><br />\n";

if ($user['set_files']==1)
{
if (isset($_SESSION['file']))
{
echo "Attachment:<br />";
for ($i=0; $i<count($_SESSION['file']);$i++)
{
if (isset($_SESSION['file'][$i]) && is_file($_SESSION['file'][$i]['tmp_name']))
{
echo "<img src='/style/themes/$set[set_them]/forum/14/file.png' alt='' />\n";
echo $_SESSION['file'][$i]['name'].'.'.$_SESSION['file'][$i]['ras'].' (';
echo size_file($_SESSION['file'][$i]['size']);
echo ") <a href='/forum/$forum[id]/$razdel[id]/$them[id]/d_file$i'><img src='/style/themes/$set[set_them]/forum/14/del_file.png' alt='' /></a>\n";
echo "<br />\n";
}
}
}
echo "<input name='file_f' type='file' /><br />\n";
echo "<input name='file_s' value='attach file' type='submit' /><br />\n";
}
echo "<input class='button' name='post' value='Posting' type='submit' />  <a href='/smiles/'> smiles </a>";
echo "</form>";
}
?>
