<?php
//echo $_POST['zona'];
// echo $_POST['judet'].'<br />';
// echo $_POST['tip_locatie'].'<br />';
// echo $_POST['clasificare'].'<br />';
// echo $_POST['denumire'].'<br />';
// if ($judet == ''){echo 'nu avem judet<br />';}else{echo $judet.'<br />';}
// if ($tip_locatie == ''){echo 'nu avem tip_locatie<br />';}else{echo $tip_locatie.'<br />';}
// if ($clasificare == ''){echo 'nu avem clasificare<br />';}else{echo $clasificare.'<br />';}
// if ($denumire == ''){echo 'nu avem denumire<br />';}else{echo $denumire.'<br />';}

// if ($_POST['zona']){
// $sql = mysql_query("SELECT * FROM `locatie_cazare` WHERE dotari57 = '".$_POST['zona']."' and status = 'ACTIV' ORDER BY nr_vizualizari DESC limit 0,24");
// }
// if ($_POST['judet']){
// $sql = mysql_query("SELECT * FROM `locatie_cazare` WHERE judet = '".$_POST['judet']."' and status = 'ACTIV' ORDER BY nr_vizualizari DESC limit 0,24");
// }
// if ($_POST['localitate']){
// $sql = mysql_query("SELECT * FROM `locatie_cazare` WHERE oras = '".$_POST['localitate']."' or comuna = '".$_POST['localitate']."' or sat = '".$_POST['localitate']."' and status = 'ACTIV'  ORDER BY nr_vizualizari DESC limit 0,24");
// }
// if ($_POST['tip_locatie']){
// $sql = mysql_query("SELECT * FROM `locatie_cazare` WHERE tip_locatie = '".$_POST['tip_locatie']."' and  status = 'ACTIV' ORDER BY nr_vizualizari DESC limit 0,24");
// }
// if ($_POST['clasificare']){
// $sql = mysql_query("SELECT * FROM `locatie_cazare` WHERE clasificare = '".$_POST['clasificare']."' and  status = 'ACTIV' ORDER BY nr_vizualizari DESC limit 0,24");
// }


///////////// start cele mai vizitate /////////////
if ($_POST['zona'] == '' and $_POST['judet'] == '' and $_POST['localitate'] == '' and $_POST['tip_locatie'] == '' and $_POST['clasificare'] == '' and $_POST['submit_cautare'] == ''){
$sql = mysql_query("SELECT * FROM `locatie_cazare` WHERE status = 'ACTIV' ORDER BY nr_vizualizari DESC limit 0,27");
	}else{
if ($_POST['tip_locatie'] != null ){ $tip_locatie .= "tip_locatie = '".$_POST['tip_locatie']."' and";}
if ($_POST['clasificare'] != null ){ $clasificare = "clasificare = '".$_POST['clasificare']."' and";}
if ($_POST['denumire'] != null ){ $denumire = "denumire_locatie like '%".$_POST['denumire']."%' and";}
if ($_POST['judet'] != null ){ $judet = "judet = '".$_POST['judet']."' and ";}
if ($_POST['zona'] != null ){ $zona = "dotari57 = '".$_POST['zona']."' and ";}
if ($_POST['localitate'] != null ){ $localitate = "oras = '".$_POST['localitate']."' or comuna = '".$_POST['localitate']."' or sat = '".$_POST['localitate']."' and ";}

$sql = mysql_query("SELECT * FROM `locatie_cazare` WHERE ".$tip_locatie." ".$clasificare." ".$judet." ".$denumire." ".$zona." ".$localitate." status = 'ACTIV' ORDER BY nr_vizualizari DESC limit 0,27");
}
$rows = mysql_num_rows($sql);
//echo $rows;
if ($rows == '0'){
echo '<p style="width:600px; padding: 20px; margin-top: 100px; margin-left: auto; margin-right: auto; text-align: center; background-color: #C1FFD2; border: solid thin #000000; -webkit-border-radius: .4em; -moz-border-radius: .4em; border-radius: .4em;">
		Nu sunt disponibile unitati de cazare care sa corespunda criteriilor de cautare.
	</p>	';
}
while($locatie = mysql_fetch_row($sql)){

if ($locatie['10'] == null){
		if ($locatie['9'] == null){$loc1 = $locatie['8'];}else{$loc1 = $locatie['9'];}	
			}else{$loc1 = $locatie['10'];}
$loc = str_ireplace($ptr_url, ' ', $loc1);				
$url_loc = str_ireplace($ptr_url, '-', $loc1);	
$url_denumire = str_ireplace($ptr_url, '-', $locatie['6']);	

$sql_foto = mysql_query("SELECT * FROM `foto_locatie` where id_locatie = '".$locatie['0']."' order by id desc limit 0,1 ");
$rows1 = mysql_num_rows($sql_foto);	
//echo $rows1;
if ($rows1 == '0'){
	$foto = '<img id="fotomica" src="../ro-cazare.info/upload/foto_mica/promovare-turistica-gratuit-ro-cazare-138x138.jpg" />';
		}
	while($foto_mica = mysql_fetch_row($sql_foto)){	
if ($rows1 != '0'){
	$foto = '<img id="fotomica" src="http://www.ro-cazare.info/upload/foto_mica/'.$foto_mica['5'].'" />';
		}
}
echo'<div style="margin-left: auto; margin-right: auto;">
<a href="http://'.$title.'/rezerva-cazare/cazare-'.strtolower($locatie['4']).'-'.strtolower($locatie['7']).'-'.strtolower($url_loc).'-'.strtolower($url_denumire).'-'.$locatie['0'].'.html" alt="Apasa pentru a vizualiza locatia - '.ucwords(strtolower($locatie['6'])).' - '.$title.'" title="Apasa pentru a vizualiza locatia - '.ucwords(strtolower($locatie['6'])).' - '.$title.'">';

echo'<fieldset id="fieldsethome">
	 <legend id="legendhome" align="left">'.ucwords(strtolower(wordwrap($locatie['6'], 32, '<br /> '))).'</legend>';
echo'
<table width="100%" border="0" cellspacing = "0">
	<tr>
		<td style="width: 45%; padding: 2px;">'.$foto.'</td>
		<td style="width: 55%; padding: 2px;" >
			'.ucwords(strtolower($locatie['4'])).' 
				<br />
			'.ucwords(strtolower($locatie['5'])).'
				<br />
			'.ucwords(strtolower($locatie['78'])).'
				<br />
			Judet: '.ucwords(strtolower($locatie['7'])).'
				<br />
			'.ucwords(strtolower($loc)).'
		</td>
	</tr>
	
</table>
	</fieldset>
</a></div>';
}
	

///////////// end cele mai vizitate /////////////

?>