1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
| <?php
$codepostal = '';
$communeselect = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['CP'])) {
$codepostal = $_POST['CP'];
}
if (isset($_POST['communeselect'])) {
$communeselect = $_POST['communeselect'];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="style2.css" />
</head>
<body>
<div>
<form name="formCP" method="POST" action="">
<legend><span style="color: red;">*</span>type du logement :</legend>
<div>
<input type="radio" id="maison" name="m_a" value="maison" <?= ($_POST['m_a'] ?? '') === 'maison' ? ' checked' : 'checked' ?> />
<label for="maison">maison</label>
</div>
<div>
<input type="radio" id="appartement" name="m_a" value="appartement" <?= ($_POST['m_a'] ?? '') === 'appartement' ? ' checked' : '' ?> />
<label for="appartement">appartement</label>
</div><br/>
<legend><span style="color: red;">*</span>Nature de la transaction :</legend>
<div>
<input type="radio" id="vente" name="transaction" value="vente" <?= ($_POST['transaction'] ?? '') === 'vente' ? ' checked' : '' ?> />
<label for="vente">vente</label>
</div>
<div>
<input type="radio" id="location" name="transaction" value="location" <?= ($_POST['transaction'] ?? '') === 'location' ? ' checked' : '' ?> />
<label for="location">location</label>
</div><br/>
<label for="annee_construction"> <span style="color: red;">*</span><span>Année de construction</span> :<br/></label>
<select id="annee_construction" name="annee_construction">
<?php $i = ["avant_49","49_97","apres_97"];
for ($j=0;$j<3;$j++) {
echo '<option value="'.$i[$j].'" '.(($_POST['annee_construction'] ?? '') === $i[$j] ? ' selected' : '').">".str_replace('_',' ',$i[$j])." </option>";
}?>
</select><br/><br/>
<legend><span style="color: red;">*</span>Utilisation du gaz :</legend>
<div>
<input type="radio" id="oui" name="gaz" value="oui" <?= ($_POST['gaz'] ?? '') === 'oui' ? ' checked' : '' ?> />
<label for="oui">oui</label>
</div>
<div>
<input type="radio" id="non" name="gaz" value="non" <?= ($_POST['gaz'] ?? '') === 'non' ? ' checked' : '' ?> />
<label for="non">non</label>
</div><br/>
<label for="nb_pieces"> <span style="color: red;">*</span><span> Nombre de pièces</span> :<br/></label>
<input type="number" id="nb_pieces" name="nb_pieces" value="<?= $_POST['nb_pieces'] ?? "0" ?>" /><br/><br/>
<label id="labelselect">Entrer votre Code Postal: </label>
<input type="number" name="CP" class="inputsearch" id="codepostalcommune" placeholder="Code Postal" maxlength="50" size="50" value="<?= $_POST['CP'] ?? '00000'?>"/>
<button id="recherche" name="recherche">Rechercher</button>
<label id="labelselect">Sélectionner votre commune: </label>
<select name="listecommunes">
<?php
if (preg_match('/^(?:0[1-9]|[1-8]\d|9[0-8])\d{3}+$/', $codepostal)) {
$rest_api_url = 'https://geo.api.gouv.fr/communes?codePostal=' . $codepostal;
$json_data = file_get_contents($rest_api_url);
$response_data = json_decode($json_data);
echo ('<option selected="true" disabled="disabled">- Choisir une commune -</option>');
$i = 0;
foreach ($response_data as $user) {
$valeur = $user->nom;
echo '<option value="'.$i.'" '.(($_POST['listecommunes'] ?? '') === $i ? ' selected' : '').">".$valeur." </option>";
$i += 1;
}
} else {
echo ('<option selected="true" disabled="disabled">- Pas de commune -</option>');
}
?>
</select>
<input type="hidden" name="communeselect" /><br/><br/>
<input type="submit" name="calc_prix" value="Envoyer">
</form>
<div class="footer">
<p style="color:aliceblue; margin-left: 20px; font-size: 3em; display: inline;"><?php //echo $communeselect ?></p>
</div>
</div>
<div>
<?php
if (isset($_POST['calc_prix'])) {
$nb_diags = 3;
if
((isset($_POST['transaction'])) && ($_POST['transaction'] == "vente"))
$nb_diags += 2;
else
$nb_diags += 1;
switch ($_POST['annee_construction']) {
case "avant_49" :
$nb_diags += 2;
break;
case "49_97" :
$nb_diags += 1;
break;
default:break;
}
if ((isset($_POST['gaz'])) && ($_POST['gaz']=="oui"))
$nb_diags += 1;
/*
* Biviers, Correnc, Domène, Gières, Grenoble, La Tronche, Le Versoud (idem Domène), Meylan, Montbonnot St Martin (idem Biviers), Murianette (idem Domène), Poisat, Revel (idem Domène), saint Ismier (idem Biviers), saint jean le vieux (idem Domène), saint Martin d'Hères, saint Martin d'Uriage, saint Martin le Vinoux, saint Nazaire les Eymes (idem Biviers), Seyssinet Pariset, Venon (idem Gières), Villard Bonnot (21 communes)
*/
$arr_cp_termites=[38330, 38700, 38420, 38610, 38000, 38700, 38240, 38320, 38400, 38410, 38950, 38170, 38190];
$price_base = ((isset($_POST['m_a'])) && ($_POST['m_a'] == "maison")) ? 110 : 95;
$coef_diag = ((isset($_POST['m_a'])) && ($_POST['m_a'] == "maison")) ? 30 : 25;
switch ($_POST['nb_pieces']) {
case 1:
$price = $price_base + $nb_diags * $coef_diag;
break;
case 2:
$price = $price_base + 5 + $nb_diags * ($coef_diag + 5);
break;
case 3:
$price = $price_base + 10 + $nb_diags * ($coef_diag + 10);
break;
case 4:
$price = $price_base + 15 + $nb_diags * ($coef_diag + 15);
break;
case 5:
$price = $price_base + 20 + $nb_diags * ($coef_diag + 20);
break;
default:
$price = $price_base + 25 + $nb_diags * ($coef_diag + 25);
break;
}
$err="Le nombre de pièces doit être strictement positif";
if (($nb_diags<=0) || ($_POST['nb_pieces']<=0))
echo $err;
else echo "Le prix est ".$price."<br/>";
}
?>
</div>
<script src="script5.js"></script>
</body>
</html> |
Partager