<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.X
 *	LICENSE: FL4HLD2A8696 - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Real Estate Agency
 *	DOMAIN: gevimmo.com
 *	FILE: REQUEST.PHP
 *
 *	The software is a commercial product delivered under single, non-exclusive,
 *	non-transferable license for one domain or IP address. Therefore distribution,
 *	sale or transfer of the file in whole or in part without permission of Flynax
 *	respective owners is considered to be illegal and breach of Flynax License End
 *	User Agreement.
 *
 *	You are not allowed to remove this information from the file without permission
 *	of Flynax respective owners.
 *
 *	Flynax Classifieds Software 2017 |  All copyrights reserved.
 *
 *	http://www.flynax.com/
 *
 ******************************************************************************/

header('Access-Control-Allow-Origin: *');

define('CRON_FILE', true);

require_once('../../includes/config.inc.php');
require_once(RL_INC . 'control.inc.php');

$reefless->loadClass('Json');

// set language
$request_lang = @$_REQUEST['lang'] ?: $config['lang'];
$rlValid->sql($request_lang);

$languages = $rlLang->getLanguagesList();
$rlLang->defineLanguage($request_lang);

$lang = $rlLang->getLangBySide('frontEnd', $request_lang);

// requests handler
$item = $_REQUEST['item'];

switch ($item) {
	case 'getByID':
		$id = (int) $_REQUEST['id'];

		$reefless->loadClass('WeatherForecast', null, 'weatherForecast');
		$forecast = $rlWeatherForecast->updateBox($id);

		if ($forecast) {
			$out['status'] = 'OK';
			$out['results'] = $forecast;
		} else {
			$out['status'] = 'ERROR';
			$out['message'] = 'No forecast data found, please contact Flynax Support';
		}
		
		break;
	
	case 'getByLocation':
		$reefless->loadClass('WeatherForecast', null, 'weatherForecast');
		$forecast = $rlWeatherForecast->get($_REQUEST['location'], 'q');

		if ($forecast) {
			$out['status'] = 'OK';
			$out['results'] = $forecast;
		} else {
			$out['status'] = 'ERROR';
			$out['message'] = 'No forecast data found, please contact Flynax Support';
		}
		
		break;
}

if ($out) {
	if (!empty($out)) {
	    echo $rlJson->encode($out);
	} else {
	    echo null;
	}
}