<?php //--->leave out close tag when the file is PURE PHP only.
/***
	In order to provide custom OG tags which are recognizes in social media sites, we need to configure the OG tags in the <head>
	section of the page. Sable will configure general <META> tags for the whole site, but in cases where a specific page needs
	dynamic og tags, add the relevant code here and populate the $_SESSION['og_tags'] variables. Sable will check these
	variables (index.php) just before setting the meta tags (in sable_header.php) and will use these session values if they are
	set. Each page call destroys these variables immediately to avoid clashes and confusion.
	
	We do it this way because the page itself will be too late for the META tags and won't be created.
***/
if ($_SESSION['current_dir'] === 'properties')
{
	if ($_SESSION['current_page'] === 'index.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select property_id, property_name, property_logo, property_description, image_file 
		from property 
		inner join images on images.album_id = property.album_id
		where property_active > 0
		order by property_order 
		limit 0,1'; //1 image is enough
	}
	
	if ($_SESSION['current_page'] === 'property.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select property_id, property_name, property_logo, property_description, image_file 
		from property 
		inner join images on images.album_id = property.album_id
		where property_id = '.SableSystem::sableDecode($_SESSION['caller']['args'][1]).' 
		limit 0,1'; //1 image is enough		
	}
	
	$row = $sableDB->getRow($sql);
	$ogurl = SABLE_URL_ROOT.'properties/'.$row['property_id'].'/'.SableGeneralFunctions::getSEOFriendlyURLName($row['property_name']);
	$_SESSION['og_tags']['title']	= $row['property_name'];
	$_SESSION['og_tags']['url']		= $ogurl;
	$_SESSION['og_tags']['image']	= $row['image_file'];
	$_SESSION['og_tags']['desc']	= $row['property_description'];
}

if ($_SESSION['current_dir'] === 'restaurants')
{
	if ($_SESSION['current_page']=='index.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select restaurant_id, restaurant_name, restaurant_logo, restaurant_description, image_file 
		from restaurant 
		inner join images on images.album_id = restaurant.album_id
        where restaurant_active > 0
		order by restaurant_order 
		limit 0,1'; //1 image is enough
	}
	
	if ($_SESSION['current_page']=='restaurant.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select restaurant_id, restaurant_name, restaurant_logo, restaurant_description, image_file 
		from restaurant 
		inner join images on images.album_id = restaurant.album_id
		where restaurant_id = '.SableSystem::sableDecode($_SESSION['caller']['args'][1]).' 
		limit 0,1'; //1 image is enough
	}	
	
	$row = $sableDB->getRow($sql);
	$ogurl = SABLE_URL_ROOT.'restaurant/'.$row['restaurant_id'].'/'.SableGeneralFunctions::getSEOFriendlyURLName($row['restaurant_name']);
	$_SESSION['og_tags']['title']	= $row['restaurant_name'];
	$_SESSION['og_tags']['url']		= $ogurl;
	$_SESSION['og_tags']['image']	= $row['restaurant_logo'];
	$_SESSION['og_tags']['image']	= $row['image_file'];
	$_SESSION['og_tags']['desc']	= $row['restaurant_description'];	
}

if ($_SESSION['current_dir'] === 'packages')
{
	if ($_SESSION['current_page']=='index.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select package_id, package_name, package_image, package_description 
		from package 
        where package_enabled > 0
		order by package_id 
		limit 0,1'; //1 image is enough
	}
	
	if ($_SESSION['current_page']=='package.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select package_id, package_name, package_image, package_description 
		from package  
		where package_id = '.SableSystem::sableDecode($_SESSION['caller']['args'][1]).' 
		limit 0,1'; //1 image is enough
	}	
	
	$row = $sableDB->getRow($sql);
	$ogurl = SABLE_URL_ROOT.'packages/'.$row['package_id'].'/'.SableGeneralFunctions::getSEOFriendlyURLName($row['package_name']);
	$_SESSION['og_tags']['title']	= $row['package_name'];
	$_SESSION['og_tags']['url']		= $ogurl;
	$_SESSION['og_tags']['image']	= $row['package_image'];
	$_SESSION['og_tags']['desc']	= $row['package_description'];	
}

if ($_SESSION['current_dir'] === 'partners')
{
	if ($_SESSION['current_page']=='index.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select partner_id, partner_name, partner_logo, partner_text, image_file 
		from partner 
		left join images on images.album_id = partner.album_id
        where partner_enabled > 0
		order by partner_id 
		limit 0,1'; //1 record is enough
	}
	
	if ($_SESSION['current_page']=='partner.php')
	{
		//Setup custom OG Tags:	
		$sql = 
		'select partner_id, partner_name, partner_logo, partner_text, image_file 
		from partner  
		left join images on images.album_id = partner.album_id
		where partner_id = '.SableSystem::sableDecode($_SESSION['caller']['args'][1]).' 
		limit 0,1'; //1 image is enough
	}	
	
	$row = $sableDB->getRow($sql);
	$ogurl = SABLE_URL_ROOT.'partners/'.$row['partner_id'].'/'.SableGeneralFunctions::getSEOFriendlyURLName($row['partner_name']);
	$_SESSION['og_tags']['title']	= $row['partner_name'];
	$_SESSION['og_tags']['url']		= $ogurl;
	$_SESSION['og_tags']['image']	= $row['image_file'] ? $row['image_file'] : $row['partner_logo'];
	$_SESSION['og_tags']['desc']	= $row['partner_name'];//$row['partner_text'];	
}

if ($_SESSION['current_dir'] === 'specials')
{
	if ($_SESSION['current_page']=='index.php')
	{
		//Setup custom OG Tags:	
		$cdate = date('Y-m-d');
		$sql = 
		'select special_id, special_title, special_image, special_text 
		from special 
		where (special_enabled > 0) 
		and ((DATE(special_start_date) <= "'.$cdate.'") and (DATE(special_end_date) >= "'.$cdate.'")) 
		order by special_order
		limit 0,1'; //1 record is enough
	}	
	
	$row = $sableDB->getRow($sql);
	$ogurl = SABLE_URL_ROOT.'specials/'.$row['special_id'].'/'.SableGeneralFunctions::getSEOFriendlyURLName($row['special_title']);
	$_SESSION['og_tags']['title']	= $row['special_title'];
	$_SESSION['og_tags']['url']		= $ogurl;
	$_SESSION['og_tags']['image']	= $row['special_image'];
	$_SESSION['og_tags']['desc']	= $row['special_text'];	
}

?>