<?php
//=================================================================
// KOOBI R7 - CMS - PORTALSOFTWARE(c) DREAM4(r) 
// HTTP://WWW.DREAM4.DE
//=================================================================
// ACHTUNG!
// DIESER PROGRAMMCODE IST URHERRECHTLICH GESCHUETZT
// DIE URHEBERRECHTE LIEGEN BEI DEN JEWEILIGEN AUTOREN.
// AENDERUNGEN IN DIESER DATEI ERFOLGEN AUF EIGENE GEFAHR!
// ES IST NICHT GESTATTET, DEN COPYRIGHTHINWEIS ZU AENDERN ODER ZU
// ENTFERNEN. NUR WENN SIE EINE COPYRIGHTHINWEIS-ENTFERNUNG BESTELLT
// HABEN, DUERFEN SIE DIESEN ENTFERNEN.
//================================================================
// BEI FRAGEN WENDEN SIE SICH BITTE AN: KONTAKT@DREAM4.DE
//=================================================================
if(!defined('BASE_DIR')) exit;
if(!get_active('forums'))
{
	notActive();
}


if ($_REQUEST["id"] == "")
{
	koobi_message('Forums_Title', 'Forums_PermissionDenied',  HOME_PATH . '/index.php?p=showforums&amp;area=' . AREA);
}

$type = escs($_REQUEST['item']);
$f_id = escs($_REQUEST['fid']);

$sql = $GLOBALS['db']->Query("SELECT uid FROM ".PREFIX."_f_topic WHERE id='".escs($_REQUEST['id'])."'");
$row = $sql->fetchrow();
if($row->uid == UID)
{
	$own = 1;
}

// =========================================================
// <<-- zugriffsrechte -->>
// =========================================================
$cat_query = $GLOBALS['db']->Query("SELECT group_id FROM " . PREFIX . "_f_forum WHERE id = '" . $f_id . "'");
while ($category = $cat_query->fetchrow_assoc()) {
	
	// miscrechte
	$group_ids = miscIds();
	$groups = explode(",", $category['group_id']);
	if (array_intersect($group_ids, $groups))
	{
		$permissions = getForumPermissionsByUser($f_id, UID);
	}
}
// =========================================================

if($own != 1)
{
	if ($permissions[FORUM_PERMISSIONS_CAN_MOVE_TOPIC] == 0)
	{
		koobi_message('Global_NoPermission_t', 'Forums_PermissionDenied',  HOME_PATH . '/index.php?p=showforums&amp;area=' . AREA);
	}
}
else
{
	if ($permissions[FORUM_PERMISSION_CAN_MOVE_OWN_TOPIC] == 0) 
	{
		koobi_message('Global_NoPermission_t', 'Forums_PermissionDenied',  HOME_PATH . '/index.php?p=showforums&amp;area=' . AREA);
	}
}

if($NOOUT != 1)
{
	if (isset($_REQUEST['action']) && $_REQUEST['action'] == "commit") 
	{
        $Source_Board = Koobi_Board_GetTopic_Board($_REQUEST['id']);
        
		$r_commit = $GLOBALS['db']->Query("UPDATE " . PREFIX . "_f_topic SET forum_id = '".escs($_REQUEST['dest'])."' WHERE id = '".escs($_REQUEST['id'])."'");
		
		 /* Reorganize LastPost */
        Koobi_Board_SetLastPost($_REQUEST['dest']); // Destination
        Koobi_Board_SetLastPost($Source_Board); // Source
        
		koobi_message('Forums_Title', 'Forums_ItemMoved',  HOME_PATH . '/index.php?p=showforums&amp;area=' . AREA);
		
	} else {
		
		$r_item = $GLOBALS['db']->Query("SELECT id, title FROM " . PREFIX . "_f_topic WHERE id = '".escs($_REQUEST['id'])."'");
		$item = $r_item->fetchrow();
		
		$r_dest = $GLOBALS['db']->Query("SELECT id, title FROM " . PREFIX . "_f_forum");
		$destinations = array();
		
		while ($destination = $r_dest->fetchrow())
		{
			array_push($destinations, $destination);
		}
		
		$stitle = $GLOBALS["config_vars"]["Forums_Title"];
		$sname = $stitle;
		
		// foren fuer das dropdown feld
		$forums_dropdown = array();
		getForums(0, $forums_dropdown, "", $fid);
		
		$categories = array();
		getCategories(0, $categories, "");
		$GLOBALS['tmpl']->assign("categories_dropdown", $categories);
	
		$GLOBALS['tmpl']->assign("item", $item);
		$GLOBALS['tmpl']->assign("lang", $lang);
		$GLOBALS['tmpl']->assign("navigation", getNavigation(escs($_REQUEST['id']), "topic"));
		$GLOBALS['tmpl']->assign("destinations", $destinations);
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/forums/move.tpl')); 
	}
}
?>