Location: PHPKode > scripts > phpGamesCenter > rgames/rincludes/class_games.php
<?php

/**
* Class library which is the main brain of RgameScript Pro
*
* @author Roosevelt Purification
* @package RGameScriptPro1.1
*/

/*===========================================================================*\
|| ######################################################################### ||
|| # RGameScript Pro Version 1.1
|| # --------------------------------------------------------------------- # ||
|| # Copyright ©2005-2006 Roosevelt Purification. All Rights Reserved.     # ||
|| # RGameScript Pro is a free software released under GNU/GPL License	   # ||
|| # Website URL: http://www.photoshopcity.com/                            # ||
|| ######################################################################### ||
\*===========================================================================*/

class GAMES extends RCORE
{	
	/**
	* Function to display top games
	*
	* @param integer $amount	The amount of latest games you wish to display
	*/
	function TopGames($amount)
	{
		$this->Connection();
		$temp = new TEMPLATES();
		$skin = $this->RSqlArray("SELECT * FROM rgames_templates WHERE TempId = '5'");
		$sql = mysql_query("SELECT * FROM rgames_flash, rgames_cats 
							WHERE rgames_flash.GameCat = rgames_cats.GameCatId
							AND rgames_flash.GameAlive = '1' 
							ORDER BY GameTotalPlayed DESC LIMIT $amount");
		echo $skin['TempHead'];
		while ($data = mysql_fetch_array($sql))
		{
			$data['GameLink'] = $temp->RGameLinkParser(2, $data['GameId'], $data['GameName']);
			$data['GameScreen'] = "<img src='rgames/game_icons/".$data['GameScreen']."' alt='".$data['GameName']."' width='60px' height='60px' />";
			$data['GameCatLink'] = $temp->RGameLinkParser(1, $data['GameCatId'], $data['GameCatName']);
			$body = $temp->RGameScriptParser($skin['TempBody'], $data);
			echo $body;
		}
		echo $skin['TempFoot'];
	}
	
	/**
	* Function to display latest games
	*
	* @param integer $amount	The amount of latest games you wish to display
	*/
	function LatestGames($amount)
	{
		$this->Connection();
		$temp = new TEMPLATES();
		$skin = $this->RSqlArray("SELECT * FROM rgames_templates WHERE TempId = '1'");
		$sql = mysql_query("SELECT * FROM rgames_flash, rgames_cats 
							WHERE rgames_flash.GameCat = rgames_cats.GameCatId
							AND rgames_flash.GameAlive = '1' 
							ORDER BY GameId DESC LIMIT $amount");
		echo $skin['TempHead'];
		while ($data = mysql_fetch_array($sql))
		{
			$data['GameLink'] = $temp->RGameLinkParser(2, $data['GameId'], $data['GameName']);
			$data['GameScreen'] = "<img src='rgames/game_icons/".$data['GameScreen']."' alt='".$data['GameName']."' width='60px' height='60px' />";
			$data['GameCatLink'] = $temp->RGameLinkParser(1, $data['GameCatId'], $data['GameCatName']);
			$body = $temp->RGameScriptParser($skin['TempBody'], $data);
			echo $body;
		}
		echo $skin['TempFoot'];
	}
	
	/**
	* Function to display game categories, games and others
	*
	*/
	function ShowGames()
	{
		$this->LoadSettings();
		$temp = new TEMPLATES();
		if (isset($_GET['cid']))
		{
			//Start Roosevelt's Pagination
			$rowsPerPage = $this->rsettings['GamesPerPage'];
			$pageNum = 1;
			
			if(isset($_GET['page']))
			{
			    $pageNum = $_GET['page'];
			}
			
			$offset = ($pageNum - 1) * $rowsPerPage;
			
			$skin = $this->RSqlArray("SELECT * FROM rgames_templates WHERE TempId = '4'");
			$sql = mysql_query("SELECT * FROM rgames_flash WHERE GameCat = '".$_GET['cid']."'
								AND GameAlive = '1' LIMIT $offset, $rowsPerPage");
			
			echo $skin['TempHead'];
			while ($data = mysql_fetch_array($sql))
			{
				$data['GameLink'] = $temp->RGameLinkParser(2, $data['GameId'], $data['GameName']);
				$data['GameScreen'] = "<img src='rgames/game_icons/".$data['GameScreen']."' alt='".$data['GameName']."' width='60px' height='60px' />";
				$body = $temp->RGameScriptParser($skin['TempBody'], $data);
				echo $body;
			}
			echo $skin['TempFoot'];
			
			$countrows = $this->RSqlArray("SELECT COUNT(GameId) AS numrows FROM rgames_flash WHERE GameCat = '".$_GET['cid']."' AND GameAlive = '1'");
			
			$numrows = $countrows['numrows'];
			
			// how many pages we have when using paging?
			$maxPage = ceil($numrows/$rowsPerPage);
			
			// print the link to access each page
			
			$self = "index.php?id=cats&cid={$_GET['cid']}";			
			$nav  = '';
			
			for($page = 1; $page <= $maxPage; $page++)
			{
			   if ($page == $pageNum)
			   {
			      $nav .= " $page "; // no need to create a link to current page
			   }
			   else
			   {
		      	$nav .= " <a href=\"$self&page=$page\">$page</a> ";
			   }
			}
			
			if ($pageNum > 1)
			{
				$page  = $pageNum - 1;
				$prev  = " <a href=\"$self&page=$page\">[Prev]</a> ";
			   	$first = "<a href=\"$self&page=1\">[First]</a>";
			}
			else
			{
			   $prev  = '&nbsp;'; // we're on page one, don't print previous link
			   $first = '&nbsp;'; // nor the first page link
			}
			
			if ($pageNum < $maxPage)
			{
			   $page = $pageNum + 1;
			   $next = " <a href=\"$self&page=$page\">[Next]</a> ";
			   $last = " <a href=\"$self&page=$maxPage\">[Last]</a> ";
			}
			else
			{
			   $next = '&nbsp;'; // we're on the last page, don't print next link
			   $last = '&nbsp;'; // nor the last page link
			}
			
			// print the navigation link
			echo "<div align='center'><p>".$first . $prev . $nav . $next . $last."</p>";
			echo "<p>".$first . $prev . " Showing page $pageNum of $maxPage pages " . $next . $last."</p></div>";
			
		}
		else
		{
			//Left for future work
		}
	}
	
	/**
	* Function to play the game :)
	*
	*/
	function PlayGame()
	{
		$this->LoadSettings();
		$this->CheckPermission("USER");
		$gid = $_GET['gid'];
		if (($this->rsettings['GuestPlay'] == 1) || ($this->rpermissions['PlayGames'] == 1))
		{
			$this->LoadGame($gid);
		}
		else
		{
			DisplayMessage(RgameNoGamePermissionFailure, 1, 0, 0, "radmincp/");
		}
	}
	
		/**
		* Function to play the game regardless of permission
		*
		* @param integer $gid	The unique id of the game
		*/
		function LoadGame($gid)
		{
			$this->Connection();
			$temp = new TEMPLATES();
			//Get game data
			$gamedat = $this->RSqlArray("SELECT * FROM rgames_flash WHERE GameId = '".$gid."'");
			$gameplayed = $gamedat['GameTotalPlayed'];
			$addone = $gameplayed + 1;
			
			//Update database
			$addquery = $this->RQuery("UPDATE rgames_flash SET GameTotalPlayed = '".$addone."'WHERE GameId = '".$gid."'");
			
			$skin = $this->RSqlArray("SELECT * FROM rgames_templates WHERE TempId = '2'");
			$sql = mysql_query("SELECT * FROM rgames_flash, rgames_cats WHERE rgames_flash.GameCat = rgames_cats.GameCatId 
								AND GameId = '".$gid."'");
			echo $skin['TempHead'];
			while ($data = mysql_fetch_array($sql))
			{
				$gamefilelocation = "rgames/swf/".$data['GameFile'];
				
				$data['FullScreenMode'] = JavaScriptPopUp("Full Screen View", "index.php?id=ljg&gid={$data['GameId']}", 1000, 1000, 1);
				
				$data['GameCat'] = $data['GameCatName'];
				
				$data['GameFile'] = 
				"
					<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='".$data['GameWidth']."' height='".$data['GameHeight']."'>
					<param name='movie' value='rgames/swf/".$data['GameFile']."' />
					<param name='quality' value='high' />
					<embed src='rgames/swf/".$data['GameFile']."' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='".$data['GameWidth']."' height='".$data['GameHeight']."'></embed>
					</object>
				";
				
				$body = $temp->RGameScriptParser($skin['TempBody'], $data);
				echo $body;
			}
			echo $skin['TempFoot'];
		}
		
		/**
		* Function to load just the game
		*
		* @param integer $gid		The game id to play
		*/
		function LoadJustGame($gid)
		{
			$this->Connection();
			$this->LoadSettings();
			$this->CheckPermission("USER");
			if (($this->rsettings['GuestPlay'] == 1) || ($this->rpermissions['PlayGames'] == 1))
			{
				$sql = mysql_query("SELECT * FROM rgames_flash WHERE GameId = '".$gid."'");
				while ($data = mysql_fetch_array($sql))
				{
					$gamefilelocation = "rgames/swf/".$data['GameFile'];
					$data['GameWidth']  = 1000;
					$data['GameHeight'] = 1000;
									
					$data['GameFile'] = 
					"	<div align='center'>
						<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='".$data['GameWidth']."' height='".$data['GameHeight']."'>
						<param name='movie' value='rgames/swf/".$data['GameFile']."' />
						<param name='quality' value='high' />
						<embed src='rgames/swf/".$data['GameFile']."' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='".$data['GameWidth']."' height='".$data['GameHeight']."'></embed>
						</object>
						</div>
					";
					
					echo $data['GameFile'];
				}
			}
			else
			{
				DisplayMessage(RgameNoGamePermissionFailure, 1, 0, '', "radmincp/");
			}
		}
		
	
	/**
	* Function to edit existing game in the database
	*
	*/
	function EditGame()
	{
		if (isset($_POST['delete']))
		{
			$deletegame = $_POST['deletegame'];
			
			foreach ($deletegame as $key => $value)
			{
				//Get the swf file and image file names
				$data = $this->RSqlArray("SELECT * FROM rgames_flash WHERE GameId = '".$key."'");
				
				$filedirectory = "./../rgames/";
				
				$swffile = $data['GameFile'];
				$imagefile = $data['GameScreen'];
				
				//Delete swf
				$delete1 = unlink($filedirectory."swf/".$swffile);
				
				if ($delete1)
				{
					//Delete image
					$delete2 = unlink($filedirectory."game_icons/".$imagefile);
					
					if ($delete2)
					{
						$delete3 = true;
						
					}
					else 
					{
						DisplayMessage(RgameDeleteGameIconFailure.": $imagefile", 0, 0);
						$delete3 = false;
					}
				}
				else
				{
					DisplayMessage(RgameDeleteGameFileFailure.": $swffile", 0,  0);
					$delete3 - false;
				}
				
				if ($delete3)
				{
					//remove from db
					$sql2 = mysql_query("DELETE FROM rgames_flash WHERE GameId = '".$key."'");
					
					if ($sql2)
					{
						DisplayMessage(RgameDeleteGameSuccess.": $value", 0, 1, "index.php?id=efg");
					}
					else 
					{
						DisplayMessage(RgameDeleteGameFailure.": $value", 0, 0);
					}
						
				}				
			}
		}
		elseif (isset($_POST['update']))
		{
			$gamename = $_POST['gamename'];
			$gamedesc = $_POST['gamedesc'];
			$gamecat = $_POST['gamecat'];
			$gamefile = $_POST['gamefile'];
			$gameicon = $_POST['gameicon'];
			$gameorder = $_POST['gameorder'];
			$gameon = $_POST['gameon'];
			$totalplayed = $_POST['totalplayed'];
			$gamewidth = $_POST['gamewidth'];
			$gameheight = $_POST['gameheight'];
			$gameid = $_GET['gameid'];
			
			$check1 = $this->CheckField($gamename, RgameFieldGameName);
			$check2 = $this->CheckField($gamedesc, RgameFieldGameDesc);
			$check3 = $this->CheckField($gamecat, RgameFieldGameCat);
			$check4 = $this->CheckField($gamefile, RgameFieldGameUploadSWF);
			$check5 = $this->CheckField($gameicon, RgameFieldGameUploadAvatar);
			$gameon = $this->CheckField($gameon, RgameFieldGameOn, 1);
			
			$data = $this->RSqlArray("SELECT * FROM rgames_flash WHERE GameId = '".$gameid."'");
				
			if (empty($gamewidth))
			{
				$gamewidth = 500;
			}
			
			if (empty($gameheight))
			{
				$gameheight = 400;
			}
			
			if (empty($totalplayed))
			{
				$totalplayed = 0;
			}
			
			if ($check1 && $check2 && $check3 && $check4 && $check5)
			{
				$sql = $this->RQuery("UPDATE rgames_flash SET GameCat = '".$gamecat."',
  															  GameName = '".$gamename."',
															  GameDesc = '".$gamedesc."',
															  GameFile = '".$gamefile."',
															  GameHeight = '".$gameheight."',
															  GameWidth = '".$gamewidth."',
															  GameScreen = '".$gameicon."',
															  GameOrder = '".$gameorder."',
															  GameAlive = '".$gameon."',
															  GameTotalPlayed = '".$totalplayed."'
									 WHERE GameId = '".$gameid."'");
				if ($sql)
				{
					DisplayMessage(RgameUpdateGameSuccess, 0, 1, "index.php?id=efg");
				}
				else
				{
					DisplayMessage(RgameUpdateGameFailure, 0, 0);
				}						
			}
			else 
			{
				DisplayMessage(RgameFillFields, 0, 0);
			}
		}
		elseif (isset($_GET['fgid']))
		{
			$gameid = $_GET['fgid'];
			$data = $this->RSqlArray("SELECT * FROM rgames_flash WHERE GameId = '".$gameid."' LIMIT 1");
			$gamefilelocation = "./../rgames/swf/".$data['GameFile'];
			
			if ($data['GameAlive'] == 1)
			{
				$gameon = " checked";
			}
			else
			{
				$gameon = '';
			}
			
			$formname = "EditGame";
			
			$fields = array("*".RgameFieldGameName => FieldMaker($formname, 1, "gamename", $data['GameName']),
							"*".RgameFieldGameDesc => FieldMaker($formname, 3, "gamedesc", $data['GameDesc']),
							"*".RgameFieldGameCat => $this->GameCatGenerator($data['GameCatId']),
							"*".RgameFieldGameUploadSWF => GenerateDirectories("./../rgames/swf/", "gamefile", $data['GameFile']),
							RgameFieldGameWidth => FieldMaker($formname, 1, "gamewidth", $data['GameWidth'], 5),
							RgameFieldGameHeight =>  FieldMaker($formname,  1, "gameheight", $data['GameHeight'], 5),
							"*".RgameFieldGameUploadAvatar => GenerateDirectories("./../rgames/game_icons/", "gameicon", $data['GameScreen']),
							RgameFieldGameOrder => FieldMaker($formname, 1, 'gameorder', $data['GameOrder'], 5),
							RgameFieldGameOn => FieldMaker($formname, 4, 'gameon', $data['GameAlive']),
							RgameFieldGameTotalPlayed => FieldMaker($formname, 1, 'totalplayed', $data['GameTotalPlayed'], 5)
							);
							
			echo FormGenerator(RgameInputEditGame.": ".$data['GameName'], $formname, "index.php?id=efg&gameid={$data['GameId']}", $fields, "update", RgameInputEditGame);
						
		}
		else
		{
			if (isset($_GET['catid']))
			{
				//Fetch games by category
				$sql = mysql_query("SELECT * FROM rgames_flash WHERE GameCat = '".$_GET['catid']."'");
				
				echo "
					<form action='index.php?id=efg' method='post' enctype='application/x-www-form-urlencoded' name='form1'>
					<fieldset><legend><strong>".RgameFieldEditGamesNumber."</strong></legend>
					<table width='100%'cellspacing='6' cellpadding='5'>
					<tr>
					<td><div align='center'><strong>Delete</strong></div></td>
					<td><div align='center'><strong>".RgameFieldGameName."</strong></div></td>
					<td><div align='center'><strong>".RgameFieldGameDesc."</strong></div></td>
					<td><div align='center'><strong>".RgameFieldGameIcon."</strong></div></td>
					<td><div align='center'><strong>".RgameFieldGameOn."</strong></div></td>
					</tr>
				";
				while ($data = mysql_fetch_array($sql))
				{
					
					if ($data['GameAlive'] == 1)
					{
						$gameon = "<img src='misc/icon_yes.gif'>";
					}
					else 
					{
						$gameon = "<img src='misc/icon_no.gif'>";
					}
					
					echo "
						<tr>
						<td><div align='center'>
						<input name='deletegame[".$data['GameId']."]' type='checkbox' id='deletegame[]' value='$gamename'>
						</div></td>
						<td><div align='center'><a href='index.php?id=efg&fgid=".$data['GameId']."'>{$data['GameName']}</a></div></td>
						<td><div align='center'><em>{$data['GameDesc']}</em></div></td>
						<td><div align='center'><img src='./../rgames/game_icons/".$data['GameScreen']."' width='85' height='85'></div></td>
						<td><div align='center'>$gameon</div></td>
						</tr>
					";
				}
				echo "
					</table>
					<p align='center'>
					<input name='delete' type='submit' id='delete' value='".RgameInputDeleteGames."'>
					</p>
					</fieldset>
					</form>
				";
			}
			else
			{
				$sql = mysql_query("SELECT * FROM rgames_cats");
				echo "
					<form action='index.php?id=efg' method='post' enctype='application/x-www-form-urlencoded' name='form1'>
					<fieldset><legend><strong>".RgameFieldEditGamesByCategoryNumber."</strong></legend>
					<table width='100%'cellspacing='6' cellpadding='5'>
					<tr>
					<td valign='top'><strong>".RgameFieldGameCategories.":</strong></td>
					<td valign='top'>
					<ul>
					";
				while ($data = mysql_fetch_array($sql))
				{
					//count total games
					$data2 = $this->RNumRows("SELECT * FROM rgames_flash WHERE GameCat = '".$data['GameCatId']."'");
					echo "<li><a href='index.php?id=efg&catid=".$data['GameCatId']."'>{$data['GameCatName']}</a> <i>($data2) ".RgameGames."</i></li>\n";
				}
				echo "
					</ul>
					</td>
					</tr>
					</table>
					</fieldset>
					</form>
				";
			}
		}
	}
	
	/**
	* Function to add a flash game
	*
	*/
	function AddGame()
	{
		if (isset($_POST['submit']))
		{
			$gamename = $_POST['gamename'];
			$gamedesc = $_POST['gamedesc'];
			$gamecat = $_POST['gamecat'];
			$gamefile = $_POST['gamefile'];
			$gameicon = $_POST['gameicon'];
			$gameorder = $_POST['gameorder'];
			$gameon = $_POST['gameon'];
			$totalplayed = $_POST['totalplayed'];
			$gamewidth = $_POST['gamewidth'];
			$gameheight = $_POST['gameheight'];
			
			$check1 = $this->CheckField($gamename, RgameFieldGameName);
			$check2 = $this->CheckField($gamedesc, RgameFieldGameDesc);
			$check3 = $this->CheckField($gamecat, RgameFieldGameCat);
			$check4 = $this->CheckField($gamefile, RgameFieldGameUploadSWF);
			$check5 = $this->CheckField($gameicon, RgameFieldGameUploadAvatar);
			$gameon = $this->CheckField($gameon, RgameFieldGameOn, 1);
			
			if (empty($gamewidth))
			{
				$gamewidth = 500;
			}
			
			if (empty($gameheight))
			{
				$gameheight = 400;
			}
			
			if (empty($totalplayed))
			{
				$totalplayed = 0;
			}
			
			if ($check1 && $check2 && $check3 && $check4 && $check5)
			{
				//Insert the records
				$sql = $this->RQuery("INSERT INTO rgames_flash(GameCat,
				 											   GameName,
															   GameDesc,
															   GameFile,
															   GameHeight,
															   GameWidth,
															   GameScreen,
															   GameOrder,
															   GameAlive,
															   GameTotalPlayed)
									  VALUES ('".$gamecat."',
										      '".$gamename."',
											  '".$gamedesc."',
											  '".$gamefile."',
											  '".$gameheight."',
											  '".$gamewidth."',
											  '".$gameicon."',
											  '".$gameorder."',
											  '".$gameon."',
											  '".$totalplayed."')
									 ");
						
				if ($sql)
				{
					DisplayMessage(RgameAddGameSuccess, 0, 1, "index.php?id=efg");
				}
				else
				{
					DisplayMessage(RgameAddGameFailure, 0, 0);
				}
			}
		}
		else
		{
			$formname = "AddGame";
			
			$fields = array("*".RgameFieldGameName => FieldMaker($formname, 1, "gamename"),
							"*".RgameFieldGameDesc => FieldMaker($formname, 3, "gamedesc"),
							"*".RgameFieldGameCat => $this->GameCatGenerator(),
							"*".RgameFieldGameUploadSWF => GenerateDirectories("./../rgames/swf/", "gamefile"),
							RgameFieldGameWidth => FieldMaker($formname, 1, "gamewidth", '', 5),
							RgameFieldGameHeight =>  FieldMaker($formname,  1, "gameheight", '', 5),
							"*".RgameFieldGameUploadAvatar => GenerateDirectories("./../rgames/game_icons/", "gameicon"),
							RgameFieldGameOrder => FieldMaker($formname, 1, 'gameorder', "", 5),
							RgameFieldGameOn => FieldMaker($formname, 4, 'gameon'),
							RgameFieldGameTotalPlayed => FieldMaker($formname, 1, 'totalplayed', '', 5)
							);
							
			echo FormGenerator(RgameInputAddGame, $formname, "index.php?id=afg", $fields, "submit", RgameInputAddGame);			
		}
	}
	
	/**
	* Function to reorder game categories
	*
	*/
	function ReorderGameCats()
	{
		if (isset($_POST['submit']))
		{
			$neworder = $_POST['neworder'];
			
			foreach ($neworder as $key => $value)
			{
				//Get category name
				$data = $this->RSqlArray("SELECT * FROM rgames_cats WHERE GameCatId = '".$key."'");
				$catname = $data['GameCatName'];
				
				$sql2 = $this->RQuery("UPDATE rgames_cats SET GameCatOrder = '".$value."'
									 WHERE GameCatId = '".$key."'");
				
				if ($sql2)
				{
					DisplayMessage(RgameCategoryOrderSuccess." $catname", 0, 1, "index.php?id=egc");
				}
				else
				{
					DisplayMessage(RgameCategoryOrderFailutre." $catname", 0, 0);
				}
			}
		}
		else
		{
			$sql = $this->RQuery("SELECT * FROM rgames_cats ORDER BY GameCatOrder");
			echo "
				<form action='index.php?id=ogc' method='post' enctype='application/x-www-form-urlencoded' name='form1'>
				<fieldset><legend><strong>".RgameFieldReorderGameCatNumber."</strong></legend>
				<table width='100%'cellspacing='6' cellpadding='5'>
				<tr>
				<td><div align='center'><strong>".RgameFieldCatName."</strong></div></td>
				<td><div align='center'><strong>".RgameFieldCatCurentOrder."</strong></div></td>
				<td><div align='center'><strong>".RgameFieldCatNewsOrder."</strong></div></td>
				</tr>
			";
			while ($data = mysql_fetch_array($sql))
			{
				echo "
					<tr>
					<td><div align='center'><a href='index.php?id=egc&gcid=".$data['GameCatId']."'>{$data['GameCatName']}</a></div></td>
					<td><div align='center'>{$data['GameCatOrder']}</div></td>
					<td><div align='center'>
					<input name='neworder[".$data['GameCatId']."]' type='text' id='neworder[]' size='5'>
					</div></td>
					</tr>
				";
			}
			echo "
				</table>
				</fieldset>
				<p align='center'>
				<input name='submit' type='submit' id='delete' value='".RgameInputReorderGameCat."'>
				</p>
				</form>
			";
		}
	}
	
	/**
	* Function to edit game categories
	*
	*/
	function EditGameCats()
	{
		if (isset($_POST['delete']))
		{
			$deletegcat = $_POST['deletegcat'];
			
			foreach ($deletegcat as $key => $value)
			{			
				$sql2 = $this->RQuery("DELETE FROM rgames_cats WHERE GameCatId = '".$key."'");
				if ($sql2)
				{
					DisplayMessage(RgameCategoryDeleteSuccess.": $value", 0, 1, "index.php?id=egc");
				}
				else
				{
					DisplayMessage(RgameCategoryDeleteFailure.": $value", 0, 0);
				}
			}
			
		}
		elseif (isset($_POST['update']))
		{
			$catname = $_POST['catname'];
			$catdesc = $_POST['catdesc'];
			$caticon = $_FILES['caticon'];
			$catorder = $_POST['catorder'];
			$gamecatid = $_GET['gcid'];
			
			//Check fields
			$check1 = $this->CheckField($catname, RgameFieldCatName);
			$check2 = $this->CheckField($catdesc, RgameFieldCatDesc);
			
			if (empty($catorder))
			{
				$catorder = 1;
			}
			
			if (is_numeric($catorder))
			{
				$check3 = TRUE;
			}
			else
			{
				DisplayMessage(RgameBadFieldNotNumber, 0, 0);
				$check3 = FALSE;
			}
			
			if ($check1 && $check2 && $check3)
			{
				if (empty($caticon))
				{
					$caticon = "noavatar.gif";
				}
					
				//Do SQL Query
				$sql = $this->RQuery("UPDATE rgames_cats SET GameCatName = '".$catname."',
														     GameCatDescription = '".$catdesc."',
															 GameCatIcon = '".$caticon."',
															 GameCatOrder = '".$catorder."'
									  WHERE GameCatId = '".$gamecatid."' LIMIT 1");
				if ($sql)
				{
					DisplayMessage(RgameCategoryUpdateSuccess.": $catname", 1, 1, "index.php?id=egc");
				}
				else
				{
					DisplayMessage(RgameCategoryUpdateFailure.": $catname", 0, 0);
				}
			}
			else
			{
				DisplayMessage(RgameFillFields, 0, 0);
			}
		}
		elseif (isset($_GET['gcid']))
		{
			$data = $this->RSqlArray("SELECT * FROM rgames_cats WHERE GameCatId = '".$_GET['gcid']."' LIMIT 1");
			
			$formname = "EditCategory";			
			$fields = array("*".RgameFieldCatName.":" => FieldMaker($formname, 1, "catname", $data['GameCatName']),
							"*".RgameFieldCatDesc.":" => FieldMaker($formname, 3, "catdesc", $data['GameCatDescription']),
							"*".RgameFieldCatOrder.":" => FieldMaker($formname, 1, "catorder", $data['GameCatOrder']),
							RgameFieldCatIcon.":" => GenerateDirectories("./../icons/", "caticon", $data['GameCatIcon']));
							
			echo FormGenerator(RgameFieldEditGameCatNumber, $formname, "index.php?id=egc&gcid={$data['GameCatId']}", $fields, "update", RgameInputUpdateGameCat);
			
		}
		else
		{
			$sql = $this->RQuery("SELECT * FROM rgames_cats ORDER BY GameCatOrder");
			echo "
				<form action='index.php?id=egc' method='post' enctype='application/x-www-form-urlencoded' name='form1'>
				<fieldset><legend><strong>".RgameFieldEditGameCatNumber."</strong></legend>
				<table width='100%'cellspacing='6' cellpadding='5'>
				<tr>
				<td><div align='center'><strong>".RgameFieldDelete."</strong></div></td>
				<td><div align='center'><strong>".RgameFieldCatName."</strong></div></td>
				<td><div align='center'><strong>".RgameFieldCatDesc."</strong></div></td>
				<td><div align='center'><strong>".RgameFieldCatIcon2."</strong></div></td>
				</tr>
			";
			while ($data = mysql_fetch_array($sql))
			{
				echo "
					<tr>
					<td><div align='center'>
					<input name='deletegcat[".$data['GameCatId']."]' type='checkbox' value='".$data['GameCatName']."'>
					</div></td>
					<td><div align='center'><a href='index.php?id=egc&gcid=".$data['GameCatId']."'>{$data['GameCatName']}</a></div></td>
					<td><em>{$data['GameCatDescription']}</em></td>
					<td><div align='center'><img src='./../icons/".$data['GameCatIcon']."' width='85' height='85'></div></td>
					</tr>
				";
				
			}
			echo "
				</table>
				<p align='center'>
				<input name='delete' type='submit' id='delete' value='".RgameInputDeleteGameCat."' onclick='return confirm(\"".RgameDeleteGamecatsConfirm."\");' \>
				</p>
				</fieldset>
				<p align='left'>".RgameEditGameCatsGuide."</p>
				</form>
			";
			
		}
	}
		
	/**
	* Function to create a new category
	*
	*/
	function AddGameCat()
	{
		if (isset($_POST['submit']))
		{
			$catname = $_POST['catname'];
			$catdesc = $_POST['catdesc'];
			$caticon = $_POST['caticon'];
			$catorder = $_POST['catorder'];
			
			//Check fields
			$check1 = $this->CheckField($catname, RgameFieldCatName);
			$check2 = $this->CheckField($catdesc, RgameFieldCatDesc);
			
			if (empty($catorder))
			{
				$catorder = 1;
			}
			
			if (is_numeric($catorder))
			{
				$check3 = TRUE;
			}
			else
			{
				DisplayMessage(RgameBadFieldNotNumber,  0, 0);
				$check3 = FALSE;
			}
			
			if ($check1 && $check2 && $check3)
			{
				
				if (empty($caticon))
				{
					$caticon = "noavatar.gif";	
				}
				
				//Do SQL Query
				$sql = $this->RQuery("INSERT INTO rgames_cats (GameCatName,
															   GameCatDescription,
															   GameCatIcon,
															   GameCatOrder)
									  VALUES ('".$catname."',
										      '".$catdesc."',
											  '".$caticon."',
											  '".$catorder."')");
				if ($sql)
				{
					DisplayMessage(RgameCategoryCreateSuccess.": $catname", 1, 1, "index.php?id=egc");
				}
				else
				{
					DisplayMessage(RgameCategoryCreateFailure.": $catname", 0, 1);
				}
			}
			else
			{
				DisplayMessage(RgameFillFields, 0, 0);
			}
		}
		else
		{
			$formname = "NewCategory";			
			$fields = array("*".RgameFieldCatName.":" => FieldMaker($formname, 1, "catname"),
							"*".RgameFieldCatDesc.":" => FieldMaker($formname, 3, "catdesc"),
							RgameFieldCatOrder.":" => FieldMaker($formname, 1, "catorder", "", 5),
							RgameFieldCatIcon.":" => GenerateDirectories("./../icons/", "caticon"));
							
			echo FormGenerator(RgameFieldCreateGameCatNumber, $formname, "index.php?id=cgc", $fields, "submit", RgameInputCreateGameCat);
		}
	}
	
	/**
	* Function to edit an existing user group
	*
	*/
	function EditGroups()
	{
		if (isset($_POST['delete']))
		{
			$deletegroup = $_POST['deletegroup'];
			foreach ($deletegroup as $key => $value)
			{
				$delete = $this->RQuery("DELETE FROM rgames_groups WHERE GroupId = '".$key."'");
				if ($delete)
				{
					$group .= "$value<br />";
				}
				else
				{
					DisplayMessage(RgameGroupDeleteFailure.": $value", 0, 0);
				}
			}
			DisplayMessage(RgameGroupDeleteSuccess."<p>$group</p>", 0, 1, "index.php?id=eg");
		}
		else if (isset($_GET['gid']))
		{
			//Edit user
			$data = $this->RSqlArray("SELECT * FROM rgames_groups WHERE GroupId = '".$_GET['gid']."' LIMIT 1");
			
			$formname = "EditGroup";			
			$fields = array("*".RgameFieldGroupName.":" => FieldMaker($formname, 1, "groupname", $data['GroupName']),
							RgameFieldGroupPermissionPlayGames.":" => FieldMaker($formname, 4, "playgames", $data['PlayGames']),
							RgameFieldGroupPermissionAdmin.":" => FieldMaker($formname, 4, "accessadmin", $data['AccessAdmin']),
							RgameFieldGroupPermissionManageGroups.":" => FieldMaker($formname, 4, "managegroups", $data['ManageGroups']),
							RgameFieldGroupPermissionManageUsers.":" => FieldMaker($formname, 4, "manageusers", $data['ManageUsers']),
							RgameFieldGroupPermissionManageGames.":" => FieldMaker($formname, 4, "managegames", $data['ManageGames']),
							RgameFieldGroupPermissionManageCats.":" => FieldMaker($formname, 4, "managecats", $data['ManageCats']),
							RgameFieldGroupPermissionManageTemplates.":" => FieldMaker($formname, 4, "managetemplates", $data['ManageTemplates']));
							
			echo FormGenerator(RgameFieldEditGroup, $formname, "index.php?id=eg&v={$data['GroupId']}", $fields, "UpdateGroup", RgameInputUpdateGroups);
				
		}
		else if (isset($_POST['UpdateGroup']))
		{
			$groupname = $_POST['groupname'];
			$accessadmin = $_POST['accessadmin'];
			$managegroups = $_POST['managegroups'];
			$manageusers = $_POST['manageusers'];
			$managegames = $_POST['managegames'];
			$managecats = $_POST['managecats'];
			$managetemplates = $_POST['managetemplates'];
			$playgames = $_POST['playgames'];
			
			$check1 = $this->CheckField($groupname, RgameFieldGroupName);
			
			$accessadmin = $this->CheckField($accessadmin, "", 1);
			$managegroups = $this->CheckField($managegroups, "", 1);
			$manageusers = $this->CheckField($manageusers, "", 1);
			$managegames = $this->CheckField($managegames, "", 1);
			$managecats = $this->CheckField($managecats, "", 1);
			$managetemplates = $this->CheckField($managetemplates, "", 1);
			$playgames = $this->CheckField($playgames, "", 1);
				
			if ($check1)
			{
				//If everything went well, add thegroup
				$sql = $this->RQuery("UPDATE rgames_groups SET GroupName = '".$groupname."',
															   PlayGames = '".$playgames."',
														       AccessAdmin = '".$accessadmin."', 
															   ManageGroups = '".$managegroups."',
															   ManageUsers = '".$manageusers."',
															   ManageCats = '".$managecats."',
															   ManageTemplates = '".$managetemplates."',
															   ManageGames = '".$managegames."'
								     WHERE GroupId = '".$_GET['v']."'");
				if ($sql)
				{
					echo DisplayMessage(RgameGroupUpdateSuccess.": ".$groupname."<br />", 0, 1, "index.php?id=eg");
				}
				else
				{
					DisplayMessage(RgameDbQueryError, 0, 0);
				}				
			}
			else
			{
				DisplayMessage(RgameFillFields, 0, 0);
			}			
		}
		else
		{
			echo "
				<form name='Edit Users' method='post' action='index.php?id=eg' enctype='application/x-www-form-urlencoded'>
				<fieldset><legend><strong>".RgameFieldModerateGroupNumber."</strong>: {$data['GameCatName']}</legend>
				<table width='100%'cellspacing='6' cellpadding='5'>
				<tr>
				<td width='7%'><div align='center'><strong>".RgameFieldDelete."</strong></div></td>
				<td width='56%'><div align='center'><strong>".RgameFieldGroupName."</strong></div></td>
				</tr>
			";
			$sql = $this->RQuery("SELECT * FROM rgames_groups");
			while ($data = mysql_fetch_array($sql))
			{
				
				$yes = "Yes";
				$no = "No";
				
				if ($data['AccessAdmin'] == 1)
				{
					$accessadmin = $yes;
				}
				else
				{
					$accessadmin = $no;
				}
				
				if ($data['ManageGroups'] == 1)
				{
					$ManageGroups = $yes;
				}
				else
				{
					$ManageGroups = $no;
				}
				
				if ($data['ManageUsers'] == 1)
				{
					$ManageUsers = $yes;
				}
				else
				{
					$ManageUsers = $no;
				}
				
				if ($data['ManageGames'] == 1)
				{
					$ManageGames = $yes;
				}
				else
				{
					$ManageGames = $no;
				}
				
				if ($data['PlayGames'] == 1)
				{
					$PlayGames = $yes;
				}
				else
				{
					$PlayGames = $no;
				}
				
				if ($data['ManageCats'] == 1)
				{
					$ManageCats = $yes;
				}
				else
				{
					$ManageCats = $no;
				}
				
				if ($data['ManageTemplates'] == 1)
				{
					$ManageTemplates = $yes;
				}
				else
				{
					$ManageTemplates = $no;
				}
				
				$tooltip = 
				"
					<table width='100%'cellspacing='6' cellpadding='5'>
					<tr>
					<td width='37%'><div align='center'><strong>".RgameFieldGroupPermissionAdmin."</strong></div></td>
					<td width='37%'><div align='center'><strong>".RgameFieldGroupPermissionManageGroups."</strong></div></td>
					<td width='37%'><div align='center'><strong>".RgameFieldGroupPermissionManageUsers."</strong></div></td>
					<td width='37%'><div align='center'><strong>".RgameFieldGroupPermissionManageGames."</strong></div></td>
					<td width='37%'><div align='center'><strong>".RgameFieldGroupPermissionManageTemplates."</strong></div></td>
					<td width='37%'><div align='center'><strong>".RgameFieldGroupPermissionManageCats."</strong></div></td>
					<td width='37%'><div align='center'><strong>".RgameFieldGroupPermissionPlayGames."</strong></div></td>
					</tr>
					<tr>
					<td><div align='center'>$accessadmin</div></td>
					<td><div align='center'>$ManageGroups</div></td>
					<td><div align='center'>$ManageUsers</div></td>
					<td><div align='center'>$ManageGames</div></td>
					<td><div align='center'>$ManageTemplates</div></td>
					<td><div align='center'>$ManageCats</div></td>
					<td><div align='center'>$PlayGames</div></td>
					</tr>
					</table>
				";
				
				$toolstips = 
				"".RgameFieldGroupPermissionAdmin.": $accessadmin<br />  ".
				"".RgameFieldGroupPermissionManageGroups.": $ManageGroups<br />  ".
				"".RgameFieldGroupPermissionManageUsers.": $ManageUsers<br />  ".
				"".RgameFieldGroupPermissionManageGames.": $ManageGames<br />  ".
				"".RgameFieldGroupPermissionManageTemplates.": $ManageTemplates<br />  ".
				"".RgameFieldGroupPermissionPlayGames.": $PlayGames<br />  ";
				
				$grouplink = LinkMaker("index.php?id=eg&gid=".$data['GroupId'], $data['GroupName'], $toolstips);
				
				echo "
					<tr>
					<td>
					<div align='center'>
					<input name='deletegroup[".$data['GroupId']."]' type='checkbox' id='deletegroup[]' value='".$data['GroupName']."'>
					</div></td>
					<td><div align='center'>$grouplink</div></td>
					</tr>
				";
			}
			echo "
				</table>
				<p align='center'>
				<input name='delete' type='submit' id='delete' value='".RgameInputDeleteGroups."' onclick='return confirm(\"".RgameDeleteUserGroupsConfirm."\");' \>
				</p>
				</fieldset>
				<p align='left'>".RgameEditGroupsGuide."</p>
				</form>
			";
		}
	}
	
	/**
	* Function to create new usergroup
	*
	*/
	function AddGroup()
	{
		if (isset($_POST['creategroups']))
		{
			$groupname = $_POST['groupname'];
			$accessadmin = $_POST['accessadmin'];
			$managegroups = $_POST['managegroups'];
			$manageusers = $_POST['manageusers'];
			$managegames = $_POST['managegames'];
			$managecats = $_POST['managecats'];
			$managetemplates = $_POST['managetemplates'];
			$playgames = $_POST['playgames'];
			
			$check1 = $this->CheckField($groupname, RgameFieldGroupName, 3, "rgames_groups", "GroupName");
			
			$accessadmin = $this->CheckField($accessadmin, "", 1);
			$managegroups = $this->CheckField($managegroups, "", 1);
			$manageusers = $this->CheckField($manageusers, "", 1);
			$managegames = $this->CheckField($managegames, "", 1);
			$managecats = $this->CheckField($managecats, "", 1);
			$managetemplates = $this->CheckField($managetemplates, "", 1);
			$playgames = $this->CheckField($playgames, "", 1);
				
			if ($check1)
			{
				$available = $this->RNumRows("SELECT * FROM rgames_groups WHERE GroupName = '".$groupname."'");
				//First check incase the username exists
				if ($available)
				{
					$this->DisplayMessage(RgameGroupNameExists.": $groupname");
				}
				else
				{
					$password = $this->Encryptor($password);
					//If everything went well, add the users
					$sql = $this->RQuery("INSERT INTO rgames_groups (GroupName, 
																   AccessAdmin, 
																   ManageGroups,
																   ManageUsers,
																   ManageCats,
																   ManageTemplates,
																   ManageGames)
										VALUES ('".$groupname."',
												'".$accessadmin."',
												'".$managegroups."',
												'".$manageusers."',
												'".$managecats."',
												'".$managetemplates."',
												'".$managegames."')");
					if ($sql)
					{
						echo DisplayMessage(RgameGroupCreateSuccess.": ".$groupname."<br />", 0, 1, "index.php?id=eg");
					}
					else
					{
						$this->DisplayMessage(RgameDbQueryError, 1, 1);
					}
				}
			}
			else
			{
				$this->DisplayMessage(RgameFillFields, 1);
			}
			
		}
		else
		{
			$formname = "AddGroup";			
			$fields = array("*".RgameFieldGroupName.":" => FieldMaker($formname, 1, "groupname"),
							RgameFieldGroupPermissionPlayGames.":" => FieldMaker($formname, 4, "playgames"),
							RgameFieldGroupPermissionAdmin.":" => FieldMaker($formname, 4, "accessadmin"),
							RgameFieldGroupPermissionManageGroups.":" => FieldMaker($formname, 4, "managegroups"),
							RgameFieldGroupPermissionManageUsers.":" => FieldMaker($formname, 4, "manageusers"),
							RgameFieldGroupPermissionManageGames.":" => FieldMaker($formname, 4, "managegames"),
							RgameFieldGroupPermissionManageCats.":" => FieldMaker($formname, 4, "managecats"),
							RgameFieldGroupPermissionManageTemplates.":" => FieldMaker($formname, 4, "managetemplates"));
							
			echo FormGenerator(RgameFieldCreateGroupNumber, $formname, "index.php?id=ag", $fields, "creategroups", RgameInputCreateGroups);
		}
	}
	
	/**
	* Function to generate game categories list in a drop down menu
	*
	* @param integer $current	The current category
	*/
	function GameCatGenerator($current = NULL)
	{
		$this->Connection();
		$sql = $this->RQuery("SELECT * FROM rgames_cats");
		$form = "<select name='gamecat' id='gamecat'>\n<option></option>\n";
		while ($data = mysql_fetch_array($sql))
		{
			if ($current == $data['GameCatId'])
			{
				$form .= "<option value='".$data['GameCatId']."' selected>{$data['GameCatName']}</option>\n";
			}
			else
			{
				$form .= "<option value='".$data['GameCatId']."'>{$data['GameCatName']}</option>\n";
			}
		}
		$form .= "</select>";
		return $form;
	}
	
	/**
	* Function to edit an existing user
	*
	*/
	function EditUser()
	{
		if (isset($_POST['delete']))
		{
			$deleteuser = $_POST['deleteuser'];
			foreach ($deleteuser as $key => $value)
			{
				$delete = $this->RQuery("DELETE FROM rgames_users WHERE UserId = '".$key."'");
				if ($delete)
				{
					$username .= RgameUserDeleteSuccess.": $value<br />";
				}
				else
				{
					$username .= RgameUserDeleteFailure.": $value<br />";
				}
			}
			echo DisplayMessage($username, 0, 1, "index.php?id=eu");
		}
		elseif (isset($_GET['uid']))
		{
			//Edit user
			$data = $this->RSqlArray("SELECT * FROM rgames_users, rgames_groups 
								WHERE UserId = '".$_GET['uid']."'
								AND rgames_users.UserGroup = rgames_groups.GroupId LIMIT 1");
			
			$formname = "EditUser";			
			$fields = array(RgameFieldUsername.":" => FieldMaker($formname, 1, "username", $data['UserName']),
							RgameFieldPassword.":" => FieldMaker($formname, 2, "Password"),
							RgameFieldUsergroup.":" => $this->GroupGenerator("usergroup", $data['GroupName']));
							
			echo FormGenerator(RgameFieldEditUserNumber.": {$data['UserName']}", $formname, "index.php?id=eu&userid={$data['UserId']}", $fields, "UpdateUser", RgameFieldUpdateUser, RgameAddUserGuide);
		}
		elseif (isset($_POST['UpdateUser']))
		{
			$username = $_POST['username'];
			$password = $_POST['Password'];
			$usergroup = $_POST['usergroup'];
			
			$check1 = $this->CheckField($username, RgameFieldUsername);
			//Check for password field
			$check2 = $this->CheckField($password, RgameFieldPassword);
			//Check for password field
			$check3 = $this->CheckField($usergroup, RgameFieldUsergroup);
			
			if ($check1 && $check2 && $check3)
			{
				$password = $this->Encryptor($password);
				//If everything went well, add the users
				$sql = $this->RQuery("UPDATE rgames_users SET UserGroup = '".$usergroup."',
															UserName = '".$username."',
															PassWord = '".$password."'
									WHERE UserId = '".$_GET['userid']."'");
				if ($sql)
				{
						echo DisplayMessage(RgameUserEditSuccess.": ".$username."<br />", 1, 1, "index.php?id=eu");
				}
			}
			
		}
		else
		{
			echo "
				<fieldset><legend><strong>".RgameFieldEditUserNumber."</strong></legend>
				<form name='Edit Users' method='post' action='index.php?id=eu' enctype='application/x-www-form-urlencoded'>
				<table width='100%'cellspacing='6' cellpadding='5'>
				<tr>
				<td width='7%'><div align='center'><strong>".RgameFieldDelete."</strong></div></td>
				<td width='56%'><div align='center'><strong>".RgameFieldUsername."</strong></div></td>
				<td width='37%'><div align='center'><strong>".RgameFieldUsergroup."</strong></div></td>
				</tr>
			";
			$sql = $this->RQuery("SELECT * FROM rgames_users, rgames_groups WHERE
			 					rgames_users.UserGroup = rgames_groups.GroupId");
			while ($data = mysql_fetch_array($sql))
			{
				echo "
					<tr>
					<td>
					<div align='center'>
					<input name='deleteuser[".$data['UserId']."]' type='checkbox' id='deleteuser[]' value='".$data['UserName']."'>
					</div></td>
					<td><div align='center'><a href='index.php?id=eu&uid=".$data['UserId']."'>{$data['UserName']}</a></div></td>
					<td><div align='center'>{$data['GroupName']}</div></td>
					</tr>
				";
			}
			echo "
				</table>
				<p align='center'>
				<input name='delete' type='submit' id='delete' value='".RgameInputDeleteUsers."' onclick='return confirm(\"".RgameDeleteUserConfirm."\");' \>
				</p>
				</fieldset>
				</form>
				<p align='left'>".RgameEditUsersGuide."</p>
			";
		}
	}
	
	/**
	* Function to create a new user
	*
	*/
	function AddUser()
	{
		if (isset($_POST['createusers']))
		{
			$username = $_POST['username'];
			$password = $_POST['Password'];
			$usergroup = $_POST['usergroup'];
			
			$check1 = $this->CheckField($username, RgameFieldUsername, 3, "rgames_users", "UserName");
			//Check for password field
			$check2 = $this->CheckField($password, RgameFieldPassword);
			//Check for password field
			$check3 = $this->CheckField($usergroup, RgameFieldUsergroup);
				
			if ($check1 && $check2 && $check3)
			{
				$available = $this->RNumRows("SELECT * FROM rgames_users WHERE UserName = '".$username."'");
				//First check incase the username exists
				if ($available)
				{
					DisplayMessage(RgameUserNameExists.": $username", 0, 0);
				}
				else
				{
					$password = $this->Encryptor($password);
					//If everything went well, add the users
					$sql = $this->RQuery("INSERT INTO rgames_users (UserGroup, UserName, PassWord)
										VALUES ('".$usergroup."',
												'".$username."',
												'".$password."')");
					if ($sql)
					{
						echo DisplayMessage(RgameUserCreateSuccess.": ".$username."<br />", 0, 1, "index.php?id=eu");;
					}
				}
			}
			
		}
		else
		{
			$formname = "CreateUser";			
			$fields = array(RgameFieldUsername.":" => FieldMaker($formname, 1, "username"),
							RgameFieldPassword.":" => FieldMaker($formname, 2, "Password"),
							RgameFieldUsergroup.":" => $this->GroupGenerator("usergroup"));
							
			echo FormGenerator(RgameSiteConfig, $formname, "index.php?id=au", $fields, "createusers", RgameInputCreateUsers, 1, 1, RgameAddUserGuide);
		}
	}
	
	/**
	* Function to generate a drop down list of all the games
	*
	*/
	function AllGamesMenu()
	{
		echo " <select name=\"url\" onchange=\"switchpage(this)\"><option></option>\n";
		$sql = $this->RQuery("SELECT * FROM rgames_flash ORDER BY GameName");
		while ($data = mysql_fetch_array($sql))
		{
			echo "<option value='index.php?id=play&gid=".$data['GameId']."'>{$data['GameName']}</option>\n";
		}
		echo "</select>\n";
	}
	
	/**
	* Function to display the search box
	*
	*/
	function GameSearch()
	{
		$temp = new TEMPLATES();
		$all = $_POST['all'];
		$any = $_POST['any'];
		$none = $_POST['none'];
		
		if((!$all) || ($all == ""))
		{
			$all = ""; 
		}
		else
		{
			$all = "+(".$all.")"; 
		}
		   
		if((!$any) || ($any == ""))
		{
			$any = ""; 
		} 
		   
		if((!$none) || ($none == ""))
		{ 
			$none = ""; 
		} 
		else
		{
			$none = "-(".$none.")"; 
		}

		$skin = $this->RSqlArray("SELECT * FROM rgames_templates WHERE TempId = '4'"); 
		$sql = mysql_query("SELECT *, MATCH(GameName, GameDesc) AGAINST ('$all $none $any' IN BOOLEAN MODE) AS score FROM rgames_flash WHERE MATCH(GameName, GameDesc) AGAINST ('$all $none $any' IN BOOLEAN MODE)");
		      
		echo 
		"
			<fieldset>
			<legend><strong>".RgameLegendSearch."</strong></legend>
			<table width='100%' align='center' cellpadding='5' cellspacing='6'>
			<tr>
			<td>
		";
		if(mysql_num_rows($sql) > 0)
		{
			echo $skin['TempHead'];
		    while($data = mysql_fetch_array($sql))
		    {
				$data['GameLink'] = $temp->RGameLinkParser(2, $data['GameId'], $data['GameName']);
				$data['GameScreen'] = "<img src='rgames/game_icons/".$data['GameScreen']."' alt='".$data['GameName']."' width='60px' height='60px' />";
				$body = $temp->RGameScriptParser($skin['TempBody'], $data);
				echo $body;
		    }
		    echo $skin['TempFoot'];
		}
		else
		{ 
			echo "<div align='center'>".RgameSearchNoMatch."</div>"; 
		}
		
		echo
		"
			</td>
			</tr>
			</table>
			</fieldset>
		";
	}
}

?>
Return current item: phpGamesCenter