<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	//  Move Thread
	// ========================================================================================
	
		
	
	ReadFormArguments();
	Global $FormArguments;
			
	if (count($FormArguments) > 0) {
	
			
		ReadPermissions();
		Global $Permissions;
		
		
		$FormArguments['ThreadID'] = intval($FormArguments['ThreadID']);
		
		if ($FormArguments['ThreadID'] > 0) {
		
			if ($Permissions[202] == 'y') {
			
				$query = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber=".$FormArguments['DestinationBoard']." and MinLevel <= ".$UserLevel." limit 1";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				if ($row['RecordNumber'] > 0) {
				
					$NewBoardID = $row['RecordNumber'];
				
					
					$query = "select count(RecordNumber) as RecordsCount from `".$Settings['DBPrefix']."mb-Messages` where ThreadID=".$FormArguments['ThreadID']." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					$row = mysql_fetch_array($result);
				
					$MessagesInThread = $row['RecordsCount'];
				
						
								
					$query = "select * from `".$Settings['DBPrefix']."mb-Threads` where RecordNumber=".$FormArguments['ThreadID']." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					$row = mysql_fetch_array($result);
					
					$OldBoardID = $row['BoardID'];
				
				
					$query = "update `".$Settings['DBPrefix']."mb-Threads` set BoardID=".$NewBoardID." where RecordNumber=".$FormArguments['ThreadID']." limit 1";
					$result = mysql_query($query) or die (mysql_error());
				
				
					$query55 = "update `".$Settings['DBPrefix']."mb-Boards` set Threads=Threads-1, Messages=Messages-".$MessagesInThread." where RecordNumber='".$OldBoardID."' limit 1";
					$result55 = mysql_query($query55) or die (mysql_error());
					
					$query55 = "update `".$Settings['DBPrefix']."mb-Boards` set Threads=Threads+1, Messages=Messages+".$MessagesInThread." where RecordNumber='".$NewBoardID."' limit 1";
					$result55 = mysql_query($query55) or die (mysql_error());
				
				
				
					// update last message stats on old board
				
					$LastReply = 0;
					$LastUser = 0;
					
					$query = "select * from `".$Settings['DBPrefix']."mb-Threads` where BoardID=".$OldBoardID;
					$result = mysql_query($query) or die (mysql_error());
					while ($row = mysql_fetch_array($result)) {
					
						$query3 = "select * from `".$Settings['DBPrefix']."mb-Messages` where ThreadID=".$row['RecordNumber']." order by DateCode desc limit 1";
						$result3 = mysql_query($query3) or die (mysql_error());
						if (mysql_num_rows($result3) != 0) {
						
							$row3 = mysql_fetch_array($result3);
						
							if ($row3['DateCode'] > $LastReply) {
								$LastReply = $row3['DateCode'];
								$LastUser = $row3['Poster'];
							}
						}
					
					}
				
					
					$query55 = "update `".$Settings['DBPrefix']."mb-Boards` set LastReply='".$LastReply."', LastUser='".$LastUser."' where RecordNumber='".$OldBoardID."' limit 1";
					$result55 = mysql_query($query55) or die (mysql_error());
					
					
					
					// update last message stats on new board
				
					$LastReply = 0;
					$LastUser = 0;
					
					$query = "select * from `".$Settings['DBPrefix']."mb-Threads` where BoardID=".$NewBoardID;
					$result = mysql_query($query) or die (mysql_error());
					while ($row = mysql_fetch_array($result)) {
					
						$query3 = "select * from `".$Settings['DBPrefix']."mb-Messages` where ThreadID=".$row['RecordNumber']." order by DateCode desc limit 1";
						$result3 = mysql_query($query3) or die (mysql_error());
						if (mysql_num_rows($result3) != 0) {
						
							$row3 = mysql_fetch_array($result3);
						
							if ($row3['DateCode'] > $LastReply) {
								$LastReply = $row3['DateCode'];
								$LastUser = $row3['Poster'];
							}
						}
					
					}
				
					
					$query55 = "update `".$Settings['DBPrefix']."mb-Boards` set LastReply='".$LastReply."', LastUser='".$LastUser."' where RecordNumber='".$NewBoardID."' limit 1";
					$result55 = mysql_query($query55) or die (mysql_error());
				
			
			
				
					header('Location: ' . $MainURL . '/forum/'.$OldBoardID.'.html');
					
					
				
				}
				else {
					
					$PageContents = $MsgText[2][104];
				
				}
			
			}		
			else {
			
				$PageContents = $MsgText[2][100];
			
			}	
		
		}
		else {
		
			$PageContents = $MsgText[2][58];
		
		}

	
	}
	else {
		$PageContents = $MsgText[0][98];
	}	
			
	
	
?>
