<?php
 
include_once "authentication.php";

if(isset($_GET['code'])){

	if($_GET['code'] == '1070')
		echo 1;
	else
		echo 0;

}


if(isset($_POST['cp'])){
	
	$zip = $sql->real_escape_string(str_replace(' ','',$_POST['cp']));
	$civic = $sql->real_escape_string($_POST['civic']);
	
	$q_fibre = "SELECT * FROM `fibre` WHERE `zip` = '$zip' AND `terrain` = '$civic'";
	$res_fibre = $sql->query($q_fibre);

	$fibre_find = 0;
	$fibre_result = '';

	if($res_fibre->num_rows > 0){
		$fibre_result .= "Addresse disponible (<b>UN option DOIT être selectionné</b>):<br><br><table class='table table-hover'>";
		while($row_fibre = $res_fibre->fetch_array()){
			
			$opt_input = "<input type='radio' id='opt_addr_{$row_fibre['id']}' name='opt_addr' value='{$row_fibre['id']}'>";
			$tr = "onclick='fibre_sel({$row_fibre['id']})'";
			
			if($row_fibre['sn'] != ''){
				$opt_input = "";
				$tr = "title='Sn déja atrtibué pour cette adresse'";
			}
			
			$boitier = ($row_fibre['boitier_pas_install'] == 1) ? "<span class='alert-warning'>Boitier non installé, ajouter 2 semaines de délais</span>" : '';
			$fibre_result .= "<tr $tr><td>$opt_input</td><td>{$row_fibre['terrain']}</td><td>{$row_fibre['rue']}</td><td>{$row_fibre['ville']}</td><td>{$row_fibre['zip']}</td><td>{$row_fibre['description']}</td><td>$boitier</td></tr>";
		}
		$fibre_result .= "</table>";
	}
	else
		$fibre_result = "<div class='alert alert-danger'>Aucune adresse trouv&eacute;e. Non disponible.</div>";
		
	echo $fibre_result;	
	
}


?>