<?php
require 'vendor/slim/Slim/Slim.php';
require_once 'api/MailContacto.php';
require 'api/PHPMailer-master/PHPMailer-master/PHPMailerAutoload.php';
require_once 'api/language/i18n.class.php';
//require 'api/PHPMailer-master/PHPMailer-master/PHPMailerAutoload.php';
use \Slim\Slim;
session_start();



Slim::registerAutoloader();




function setLang($language)
{
	$i18n = new i18n();
	$i18n->setForcedLang($language);
	$i18n->setCachePath('api/language/langcache/');
	$i18n->setFilePath("api/language/i18n/lang_$language.ini");
	$i18n->init();
}
function startLang()
{
	$i18n = new i18n();
	$language = 'es';
	if(isset($_SESSION['language']))
		$language = $_SESSION['language'];
	$i18n->setForcedLang($language);
	$i18n->setCachePath('api/language/langcache/');
	$i18n->setFilePath("api/language/i18n/lang_$language.ini");
	$i18n->init();
}

$app = new \Slim\Slim();
define('URL_HREF', 'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);

$app->config(array(
    'debug' => true,
    'templates.path' => './templates'
));


$app->get('/', function () use ($app) {
	startLang();
    $app->render('index.php', array('url_href' => URL_HREF));
});
$app->get('/web', function () use ($app) {
	startLang();
    $app->render('index.php', array('url_href' => URL_HREF));
});
$app->get('/en', function () use ($app) {
	$_SESSION['language']='en';
	$language = 'en';
	setLang($language);
    $app->render('index.php', array('url_href' => URL_HREF));
});

$app->get('/es', function () use ($app) {
	$_SESSION['language']='es';
	$language = 'es';
	setLang($language);
    $app->render('index.php', array('url_href' => URL_HREF));
});

$app->get('/conectividad', function () use ($app) {
	startLang();
	$app->render('conectividad.php', array('url_href' => URL_HREF));
});
$app->get('/que-ofrecemos', function () use ($app) {
	startLang();
	$app->render('queOfrecemos.php', array('url_href' => URL_HREF));
});
$app->get('/contacto', function () use ($app) {
	startLang();
	$app->render('contacto.php', array('url_href' => URL_HREF));
});
$app->get('/soporte', function () use ($app) {
	startLang();
	$app->render('soporte.php', array('url_href' => URL_HREF));
});
$app->get('/aviso-privacidad', function () use ($app) {
	startLang();
	$app->render('aviso-privacidad.php', array('url_href' => URL_HREF));
});
$app->get('/sendMail/:datos', function ($datos) use ($app) {
	$mailContacto = new MailContacto();
	parse_str($datos,$data);
	$mailContacto->enviarMail($data);
});
$app->run();
