<?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                   //
// ======================================================================== //

if ($_REQUEST["id"] == "") {
	$EOUT = msg("f_newforum", "f_noid", str_replace("__URL__", "index.php?p=showforums&amp;area=$area", $lang['redirect']), "index.php?p=showforums&amp;area=$area");
	$NOOUT = 1;
}

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

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

// =========================================================
// <<-- zugriffsrechte -->>
// =========================================================
$cat_query = new dbc("SELECT group_id FROM " . PREFIX . "_f_forum WHERE id = '" . $f_id . "'");
while ($category = $cat_query->fetchrow_assoc()) {
	
	// miscrechte
	include ( BASEDIR . "/system/misc_ids.php");
	
	$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) {
		$EOUT = msg("nopermission", "nopermission_t", str_replace("__URL__", "index.php?p=showforums&amp;area=$area", $lang['redirect']), "index.php?p=showforums&amp;area=$area");
		$NOOUT = 1;
	}
}
else
{
	if ($permissions[FORUM_PERMISSION_CAN_MOVE_OWN_TOPIC] == 0) {
		$EOUT = msg("nopermission", "nopermission_t", str_replace("__URL__", "index.php?p=showforums&amp;area=$area", $lang['redirect']), "index.php?p=showforums&amp;area=$area");
		$NOOUT = 1;
	}
}

if($NOOUT != 1){
	
	if ($_GET["action"] == "commit") {
		$r_commit = new dbc("UPDATE " . PREFIX . "_f_topic SET forum_id = '".escs($_REQUEST['dest'])."' WHERE id = '".escs($_REQUEST['id'])."'");
		$EOUT = msg("f_msg_header_forum", "f_msg_itemmoved", str_replace("__URL__", "index.php?p=showforums&amp;area=$area", $lang['redirect']), "index.php?p=showforums&amp;area=$area");
		$NOOUT = 1;
		
	} else {
		
		$r_item = new dbc("SELECT id, title FROM " . PREFIX . "_f_topic WHERE id = '".escs($_REQUEST['id'])."'");
		$item = $r_item->fetchrow();
		
		$r_dest = new dbc("SELECT id, title FROM " . PREFIX . "_f_forum");
		$destinations = array();
		
		while ($destination = $r_dest->fetchrow()) {
			array_push($destinations, $destination);
		}
		
		$stitle = $lang["forumtitle"];
		$sname = simpletitle($stitle);
		
		
			// foren fuer das dropdown feld
	$forums_dropdown = array();
	getForums(0, $forums_dropdown, "", $fid);
	
	$categories = array();
	getCategories(0, $categories, "");
	$tmpl->assign("categories_dropdown", $categories);
	
		$tmpl->assign("item", $item);
		$tmpl->assign("lang", $lang);
		$tmpl->assign("navigation", getNavigation(escs($_GET['id']), "topic"));
		$tmpl->assign("destinations", $destinations);
		$tmpl->assign("content", parsetrue("container/".container("forum"), $stitle, $tmpl->fetch("forums/move.tpl")));
	}
}
?>