<?

/*
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
*/



	// ========================================================================================
	// Change Category Order
	// ========================================================================================
	
	$PageTitle = $MsgText[2][4];
	$BrowserTitle = $MsgText[2][4];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[2][4];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		// if permissions are correct and arguments haven't been forged
		if ($Permissions[204] == 'y' && intval($Arguments3) > 0 && ($Arguments4 == 'up' || $Arguments4 == 'down')) {
	
			$Arguments3 = intval($Arguments3);
			
			if ($Arguments4 == 'up') {
			
				$query = "select * from `".$Settings['DBPrefix']."mb-Categories` order by CategoryOrder asc, Title asc";
				$result = mysql_query($query) or die (mysql_error());
				
				$Counter = -1;
				while ($row = mysql_fetch_array($result)) {
				
					$Counter++;
				
					$CatIDs[$Counter] = $row['RecordNumber'];
					$CatOrders[$Counter] = $row['CategoryOrder'];
					
					if ($row['RecordNumber'] == $Arguments3) {
						$ThisFoundAt = $Counter;
					}
				
				}
				
				if ($ThisFoundAt > 0) {
				
					if ($CatOrders[($ThisFoundAt-1)] == $CatOrders[$ThisFoundAt]) {
						$CatOrders[($ThisFoundAt-1)] = ($CatOrders[($ThisFoundAt-1)]-1);
					}
				
				
					$query = "update `".$Settings['DBPrefix']."mb-Categories` set CategoryOrder=".$CatOrders[($ThisFoundAt-1)]." where RecordNumber=".$CatIDs[$ThisFoundAt]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
					$query = "update `".$Settings['DBPrefix']."mb-Categories` set CategoryOrder=".$CatOrders[$ThisFoundAt]." where RecordNumber=".$CatIDs[($ThisFoundAt-1)]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
				}
				
				
			
			}
			else if ($Arguments4 == 'down') {
			
				$query = "select * from `".$Settings['DBPrefix']."mb-Categories` order by CategoryOrder asc, Title asc";
				$result = mysql_query($query) or die (mysql_error());
				
				$Counter = -1;
				while ($row = mysql_fetch_array($result)) {
				
					$Counter++;
				
					$CatIDs[$Counter] = $row['RecordNumber'];
					$CatOrders[$Counter] = $row['CategoryOrder'];
					
					if ($row['RecordNumber'] == $Arguments3) {
						$ThisFoundAt = $Counter;
					}
				
				}
				
				if ($ThisFoundAt < $Counter) {
				
					if ($CatOrders[($ThisFoundAt+1)] == $CatOrders[$ThisFoundAt]) {
						$CatOrders[($ThisFoundAt+1)] = ($CatOrders[($ThisFoundAt+1)]+1);
					}
				
				
					$query = "update `".$Settings['DBPrefix']."mb-Categories` set CategoryOrder=".$CatOrders[($ThisFoundAt+1)]." where RecordNumber=".$CatIDs[$ThisFoundAt]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
					$query = "update `".$Settings['DBPrefix']."mb-Categories` set CategoryOrder=".$CatOrders[$ThisFoundAt]." where RecordNumber=".$CatIDs[($ThisFoundAt+1)]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
				}
			
			}
			
	
			header('Location: '.$MainURL.'/admin/messageboard_boardsandcats.html');
	
	
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
	

	// ========================================================================================




?>
