<?php 
include_once('../libs/Smarty.class.php');
include_once('config.php');

header('Content-Type: text/html; charset=UTF-8');
ini_set( 'default_charset', 'UTF-8' );
setlocale(LC_ALL, 'fr_FR');
mb_internal_encoding('UTF-8');

$url = "indexfr.php";
$reviews = array ();
//echo $ip = getRealIpAddr ();
//$myip = (countryCityFromIP ($ip));
$query = "SELECT DISTINCT (district),count(area),urlcity FROM pos where country = 2 GROUP BY `district` ORDER BY count(area) DESC";
//echo $query;   			
$result = mysqli_query($dbh,$query);   
$i = 0;
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
	if ($i % 2) $li = ' class="odd"'; else $li="";
	 $cities .= "<li$li><a href='/fr/".$row['urlcity']."-salons/'>".$row['district']."</a></li>";
	$i ++;
}
//echo $myip['city'];
//echo $cities;

$salons = $gals = array();
// galleries start
$queryg = "SELECT * FROM images where country = 2 order by id DESC limit 0, 3";
//echo $queryc;
$resultg = mysqli_query($dbh,$queryg); // Run the query.
while ($rowg = mysqli_fetch_array($resultg,MYSQLI_ASSOC)){
array_push($gals, $rowg); 
}
// galleries end

//salons start
$querys = "select * from salons where country = 2 order by ID desc Limit 0, 8";
//echo $query;
$results = mysqli_query($dbh,$querys);  
$i = 0;
while ($row = mysqli_fetch_array($results,MYSQLI_ASSOC)){
	$row['fulladdress'] = " ".$row['TypeOfBusiness'].": ".$row['Address'].", ".$row['Postcode'].", ".$row['Town']; 	
	$uname = str_replace(" ","-",$row ['name']);
	$row['url'] = "/salon/$uname/".$row['ID']."/"; 
	if ($i % 2) $row['li'] = ' class="odd clearfix"'; else $row['li'] = "class='even clearfix'";
	$row['icon'] = '<img align="left" style="padding:2px;" src="/images/generic-icon.png" />';
	if (strrpos(strtolower($row['tags']), "hair")) $row['icon'] = '<img align="left" style="padding:2px;" src="/images/hair-icon.png" />';
	if (strrpos(strtolower($row['tags']), "massag")) $row['icon'] = '<img align="left" style="padding:2px;" src="/images/spa-icon.png" />';
	if (strrpos(strtolower($row['tags']), "manicure")) $row['icon'] = '<img align="left" style="padding:2px;" src="/images/manicure-icon.png" />';
	
	array_push($salons, $row); 
	$i++;
}
//print_r ($salons);
//salons end

$base = get_base($dbh,$url);
$extra = get_extra($base['id']);

$smarty = new Smarty;
$smarty->compile_check = false;
$smarty->debugging = false;

$smarty->assign("salons",$salons);

$smarty->assign("mtitle",$base['Mtitle']);
$smarty->assign("Mkey",$base['Mkeyword']);
$smarty->assign("Mdesc",$base['Mdesc']);
$smarty->assign("t0",$base['title']);
$smarty->assign("blub",$base['blub']);
$smarty->assign("convtracking",$base['convtracking']);
$smarty->assign("convcontrol",$base['convcontrol']);
$smarty->assign("phone",$phone);
$smarty->assign("author",$base['author']);

$querye = "SELECT * FROM page_element WHERE pageid = ".$base['id']." and status <> 'D'";
$resulte = mysqli_query($dbh,$querye);   
if ($resulte)
{while ($row = mysqli_fetch_array($resulte,MYSQLI_ASSOC))
{
$name = $row['name'];
$smarty->assign($name,$extra[$name]);
}
}

$queryr = "SELECT * FROM `review` left join salons on salons.id = review.salonid where country = 2 ORDER BY `review`.`id`  DESC limit 0,6";
$resultr = mysqli_query($dbh,$queryr);   
while ($rowr = mysqli_fetch_array($resultr,MYSQLI_ASSOC))
{	
	$uname = str_replace(" ","-",$rowr ['name']);
	$rowr['url'] = "/fr/salon/$uname/".$rowr['salonid']."/"; 
	array_push($reviews, $rowr); 
}	
$smarty->assign("gals",$gals);
$smarty->assign('caturl', $caturl);
$smarty->assign('arr', $arr);
$smarty->assign('treat', $treat);
$smarty->assign('h1', $local);
$smarty->assign('salon', $salon);
$smarty->assign('cities', $cities);
$smarty->assign('reviews', $reviews);
$smarty->assign('menu', $smarty->fetch('menu.tpl')); $smarty->assign('search', $smarty->fetch('msearch.tpl'));
$smarty->display('index.tpl');
$smarty->display('ga.tpl');
?>
