<?php
/**
 * @copyright  Copyright 2011 metaio GmbH. All rights reserved.
 * @link       http://www.metaio.com
 * @author     Bernhard Heindl, Frank Angermann
 **/

require_once '../config/config.php';
require_once '../library/junaio.class.php';

// Check junaio authentication header
// Settings for the authentication can be found in config.php
if (!Junaio::checkAuthentication()) {
//	header('HTTP/1.0 401 Unauthorized');
	exit;
}

//if issues occur with htaccess, also the path variable can be used
//
//htaccess rewrite enabled:
//Callback URL: http://www.callbackURL.com
//
//htacces diabled:
//Callback URL: http://www.callbackURL.com/?path=
 
if(isset($_GET['path']))
	$path = $_GET['path'];
else
	$path = $_SERVER['REQUEST_URI'];
	
$aUrl = explode('/', $path);

// Include xml generation file, depending on the request
// pois/search -> search.php
// pois/event -> event.php
// channels/subscribe -> subscribe.php

if(in_array('pois', $aUrl))
{
	if(in_array_substr('search', $aUrl))
	{
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
				<results>
					<poi id=\"1\" interactionfeedback=\"none\">
						<name><![CDATA[[Hotel Hello World]]]></name>    
						<description><![CDATA[[This is a beautiful, family hotel and restaurant, just around the corner.
							Special Dinner and Rooms available.]]]></description> 
						<l>51.446485,7.262916,0</l>
						<o>0,0,0</o>
						<mime-type>text/plain</mime-type>    
						<icon>http://dev.junaio.com/publisherDownload/tutorial/icon_map.png</icon> 
						<thumbnail>http://dev.junaio.com/publisherDownload/tutorial/thumb.jpg</thumbnail>
						<phone>555/1234567</phone> 
						<homepage> http://www.hotelaroundthecorner.com </homepage> 
					</poi>
				</results>";
	}
}

// Wrong url
//header('HTTP/1.0 404 Not found');

function in_array_substr($needle, $haystack)
{
	foreach($haystack as $value)
	{
		if(strpos($value, $needle) !== false)
			return true;
	}
	
	return false;	
}
