<?php
	class OSRegion
	{
        private $RegionID			=	0;
		private	$RegionPort			=	0;
		private $RegionName			=	"";
		private $RegionUUID			=	"";
		private $UserUUID			=	"";
		private $RegionImage		=	"";
		private	$RegionHostname		=	"";

		private $Grid				=	null;

		function __construct($regionName, $regionImage, $regionUUID, $userUUID, $regionHostname, $regionPort, $grid, $regionID = 0) 
		{
			global $RUNTIME;

			$this->Grid				=	$grid;

			$this->RegionName		=	$regionName;
			$this->RegionImage		=	$regionImage;
			$this->RegionUUID		=	$regionUUID;
			$this->UserUUID			=	$userUUID;
			$this->RegionHostname	=	$regionHostname;
			$this->RegionPort		=	$regionPort;

			if($regionID == 0)
			{
				$addRegionStatement = $RUNTIME['PDO']->prepare("INSERT IGNORE INTO regions (GridID, RegionName, RegionUUID, UserUUID, RegionImage, RegionHostname, RegionPort) VALUES (:GridID, :RegionName, :RegionUUID, :UserUUID, :RegionImage, :RegionHostname, :RegionPort)");
				$addRegionStatement->execute(array("GridID" => $this->Grid->getGridID(), "RegionName" => $regionName, "RegionUUID" => $regionUUID, "UserUUID" => $userUUID, "RegionImage" => $regionImage, "RegionHostname" => $regionHostname, "RegionPort" => $regionPort)); 
				$this->RegionID		= $RUNTIME['PDO']->lastInsertId();

				if($this->RegionID == 0)
				{
					$getRegionStatement = $RUNTIME['PDO']->prepare("SELECT * FROM regions WHERE RegionName = :RegionName AND GridID = :GridID");
					$getRegionStatement->execute(array("RegionName" => $regionName, "GridID" => $this->Grid->getGridID())); 
	
					if($row = $getRegionStatement->fetch())
						$this->RegionID = $row['RegionID'];
				}
			}
		}
    }
?>