<?php
// ======================================================================== //
//   KOOBI - CMS                                                            //
//   SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS                     //
//                                                                          //
//   DREAM4 - AM MICHELSGRUND 7 - 69469 WEINHEIM - GERMANY                  //    
//   TEL. +49(0) 6201 - 980442 / FAX. +49(0) 6201 - 64809                   //
// ======================================================================== //
$q_forum = "
	SELECT
	f.id,
	p.uid
	FROM
		" . PREFIX . "_f_forum AS f,
		" . PREFIX . "_f_topic AS t,
		" . PREFIX . "_f_post AS p
	WHERE
	t.id = " . $_GET['toid'] . " AND
	t.forum_id = f.id AND
	p.id = " . $_GET['pid'];

$r_forum = new dbc($q_forum);
$forum = $r_forum->fetchrow();
$permissions = getForumPermissionsByUser($forum->id, UID);
// $permissions = getForumPermissions($forum->id, UGROUP);


// wenn user andere beitraege nicht loeschen kann und kein admin ist ...
if( ($permissions[FORUM_PERMISSION_CAN_DELETE_OTHER_POST] == 0) && (UGROUP != 1) ) {
	
	// eigener beitrag
	if ($forum->uid == UID) {
		if ($islogged == 0 || $permissions[FORUM_PERMISSION_CAN_DELETE_OWN_POST] == 0) {
			// user nicht eingeloggt
			$EOUT = msg("nopermission", "nopermission_t", str_replace("__URL__", "index.php?p=showtopic&amp;toid=" . $_GET['toid'], $lang['redirect']), "index.php?p=showtopic&amp;toid=" . $_GET['toid']);
			$NOOUT = 1;
		}
		// fremder eintrag
	}
	
	if ( ($forum->uid != UID) && (UGROUP != 1) ) {
		$EOUT = msg("nopermission", "noperms_del_post", str_replace("__URL__", "index.php?p=showtopic&amp;toid=" . $_GET['toid'], $lang['redirect']), "index.php?p=showtopic&amp;toid=" . $_GET['toid']);
		$NOOUT = 1;
	}
	
	
	if ($_GET["pid"] == "") {
		$EOUT = msg("f_newforum", "f_noid", str_replace("__URL__", "index.php?p=showforums", $lang['redirect']), "index.php?p=showforums");
		$NOOUT = 1;
	}
}

if($NOOUT != 1){
	$q_delpost = "DELETE FROM " . PREFIX . "_f_post WHERE id = '" . $_GET['pid'] . "'";
	$r_delpost = new dbc($q_delpost);
	
	$q_decrement = "UPDATE " . PREFIX . "_f_topic SET replies = replies - 1 WHERE id = '" . $_GET['toid'] . "'";
	$r_decrement = new dbc($q_decrement);
	
	$q_topic = "SELECT replies FROM " . PREFIX . "_f_topic WHERE id = '" . $_GET['toid'] . "'";
	$r_topic = new dbc($q_topic);
	$topic = $r_topic->fetchrow();
	
	if ($topic->replies == 0) {
		deleteTopic($_GET['toid']);
		$EOUT = msg("f_forum", "f_actionsuccess", str_replace("__URL__", "index.php?p=showforum&amp;fid=" . $forum->id, $lang['redirect']), "index.php?p=showforum&amp;fid=" . $forum->id);
	} else {	
		$EOUT = msg("f_forum", "f_actionsuccess", str_replace("__URL__", "index.php?p=showtopic&amp;toid=" . $_GET["toid"], $lang['redirect']), "index.php?p=showtopic&amp;toid=" . $_GET["toid"]);
	}
	$NOOUT = 1;
}
?>
