<?

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



	// ========================================================================================
	// block priority modification
	// ========================================================================================
	
	$PageTitle = $MsgText[0][240];
	$BrowserTitle = $MsgText[0][240];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL. '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL. '/admin/blocks.html">'.$MsgText[0][151].'</a> > '.$MsgText[0][240];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		
		$Arguments3 = intval($Arguments3);
		
		$query = "select * from `".$Settings['DBPrefix']."core-Blocks` where RecordNumber='".$Arguments3."' limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		
		if ($Permissions[2] == 'y' && $row['MinLevel'] <= $UserLevel && $row['MinEditLevel'] <= $UserLevel) {
		
	
			if ($Arguments3 != '' && ($Arguments4 == 'up' || $Arguments4 == 'down')) {
						
				
				
				
				if ($Arguments4 == 'up') {
			
					$query = "select * from `".$Settings['DBPrefix']."core-Blocks` order by BlockLocation,BlockPriority asc";
					$result = mysql_query($query) or die (mysql_error());
					
					$Counter = -1;
					while ($row = mysql_fetch_array($result)) {
					
						$Counter++;
					
						$BlockIDs[$Counter] = $row['RecordNumber'];
						$BlockPriorities[$Counter] = $row['BlockPriority'];
						
						if ($row['RecordNumber'] == $Arguments3) {
							$ThisBlockFoundAt = $Counter;
						}
					
					}
					
					if ($ThisBlockFoundAt > 0) {
					
						if ($BlockPriorities[($ThisBlockFoundAt-1)] == $BlockPriorities[$ThisBlockFoundAt]) {
							$BlockPriorities[($ThisBlockFoundAt-1)] = ($BlockPriorities[($ThisBlockFoundAt-1)]-1);
						}
					
					
						$query = "update `".$Settings['DBPrefix']."core-Blocks` set BlockPriority=".$BlockPriorities[($ThisBlockFoundAt-1)]." where RecordNumber=".$BlockIDs[$ThisBlockFoundAt]." limit 1";
						$result = mysql_query($query) or die (mysql_error());
						
						$query = "update `".$Settings['DBPrefix']."core-Blocks` set BlockPriority=".$BlockPriorities[$ThisBlockFoundAt]." where RecordNumber=".$BlockIDs[($ThisBlockFoundAt-1)]." limit 1";
						$result = mysql_query($query) or die (mysql_error());
						
					}
					
					
				
				}
				else if ($Arguments4 == 'down') {
				
					$query = "select * from `".$Settings['DBPrefix']."core-Blocks` order by BlockLocation,BlockPriority asc";
					$result = mysql_query($query) or die (mysql_error());
					
					$Counter = -1;
					while ($row = mysql_fetch_array($result)) {
					
						$Counter++;
					
						$BlockIDs[$Counter] = $row['RecordNumber'];
						$BlockPriorities[$Counter] = $row['BlockPriority'];
						
						if ($row['RecordNumber'] == $Arguments3) {
							$ThisBlockFoundAt = $Counter;
						}
					
					}
					
					if ($ThisBlockFoundAt < $Counter) {
					
						if ($BlockPriorities[($ThisBlockFoundAt+1)] == $BlockPriorities[$ThisBlockFoundAt]) {
							$BlockPriorities[($ThisBlockFoundAt+1)] = ($BlockPriorities[($ThisBlockFoundAt+1)]+1);
						}
					
					
						$query = "update `".$Settings['DBPrefix']."core-Blocks` set BlockPriority=".$BlockPriorities[($ThisBlockFoundAt+1)]." where RecordNumber=".$BlockIDs[$ThisBlockFoundAt]." limit 1";
						$result = mysql_query($query) or die (mysql_error());
						
						$query = "update `".$Settings['DBPrefix']."core-Blocks` set BlockPriority=".$BlockPriorities[$ThisBlockFoundAt]." where RecordNumber=".$BlockIDs[($ThisBlockFoundAt+1)]." limit 1";
						$result = mysql_query($query) or die (mysql_error());
					
					}
			
				}
				
					
				header('Location: ' . $MainURL . '/admin/blocks.html');
			
			}


		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
