<?

/*
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 Smilie Order
	// ========================================================================================
	
	$PageTitle = $MsgText[0][60];
	$BrowserTitle = $MsgText[0][60];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[0][60];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		// if permissions are correct and arguments haven't been forged
		if ($Permissions[15] == 'y' && intval($Arguments3) > 0 && ($Arguments4 == 'up' || $Arguments4 == 'down')) {
	
			$Arguments3 = intval($Arguments3);
			
			if ($Arguments4 == 'up') {
			
				$query = "select * from `".$Settings['DBPrefix']."core-Smilies` order by SmilieOrder asc";
				$result = mysql_query($query) or die (mysql_error());
				
				$Counter = -1;
				while ($row = mysql_fetch_array($result)) {
				
					$Counter++;
				
					$SmilieIDs[$Counter] = $row['RecordNumber'];
					$SmilieOrders[$Counter] = $row['SmilieOrder'];
					
					if ($row['RecordNumber'] == $Arguments3) {
						$ThisSmilieFoundAt = $Counter;
					}
				
				}
				
				if ($ThisSmilieFoundAt > 0) {
				
					if ($SmilieOrders[($ThisSmilieFoundAt-1)] == $SmilieOrders[$ThisSmilieFoundAt]) {
						$SmilieOrders[($ThisSmilieFoundAt-1)] = ($SmilieOrders[($ThisSmilieFoundAt-1)]-1);
					}
				
				
					$query = "update `".$Settings['DBPrefix']."core-Smilies` set SmilieOrder=".$SmilieOrders[($ThisSmilieFoundAt-1)]." where RecordNumber=".$SmilieIDs[$ThisSmilieFoundAt]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
					$query = "update `".$Settings['DBPrefix']."core-Smilies` set SmilieOrder=".$SmilieOrders[$ThisSmilieFoundAt]." where RecordNumber=".$SmilieIDs[($ThisSmilieFoundAt-1)]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
				}
				
				
			
			}
			else if ($Arguments4 == 'down') {
			
				$query = "select * from `".$Settings['DBPrefix']."core-Smilies` order by SmilieOrder asc";
				$result = mysql_query($query) or die (mysql_error());
				
				$Counter = -1;
				while ($row = mysql_fetch_array($result)) {
				
					$Counter++;
				
					$SmilieIDs[$Counter] = $row['RecordNumber'];
					$SmilieOrders[$Counter] = $row['SmilieOrder'];
					
					if ($row['RecordNumber'] == $Arguments3) {
						$ThisSmilieFoundAt = $Counter;
					}
				
				}
				
				if ($ThisSmilieFoundAt < $Counter) {
				
					if ($SmilieOrders[($ThisSmilieFoundAt+1)] == $SmilieOrders[$ThisSmilieFoundAt]) {
						$SmilieOrders[($ThisSmilieFoundAt+1)] = ($SmilieOrders[($ThisSmilieFoundAt+1)]+1);
					}
				
				
					$query = "update `".$Settings['DBPrefix']."core-Smilies` set SmilieOrder=".$SmilieOrders[($ThisSmilieFoundAt+1)]." where RecordNumber=".$SmilieIDs[$ThisSmilieFoundAt]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
					$query = "update `".$Settings['DBPrefix']."core-Smilies` set SmilieOrder=".$SmilieOrders[$ThisSmilieFoundAt]." where RecordNumber=".$SmilieIDs[($ThisSmilieFoundAt+1)]." limit 1";
					$result = mysql_query($query) or die (mysql_error());
					
				}
			
			}
			
	
			header('Location: '.$MainURL.'/admin/smilies.html');
	
	
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
	

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




?>
