Room research

This commit is contained in:
Adrien Vannson 2021-10-14 22:09:36 +02:00
parent 7d16a1117f
commit a06faec64b
3 changed files with 49 additions and 34 deletions

View File

@ -11,79 +11,78 @@ include 'dbinit.php';
if(isset($_GET["salle"])) { if(isset($_GET["salle"])) {
$idSalle = $_GET["salle"]; $idSalle = $_GET["salle"];
$aliaz = array(); $aliaz = array();
$stmt = $conn->prepare("SELECT nom FROM salleAlias WHERE salleID=?"); $stmt = $conn->prepare("SELECT nom FROM salleAlias WHERE salleID=?");
$stmt->execute([$idSalle]); $stmt->execute([$idSalle]);
$resA = $stmt->fetchAll(); $resA = $stmt->fetchAll();
for($i=0;$i<count($resA);$i++) for($i=0;$i<count($resA);$i++)
$aliaz[$i] = $resA[$i]['nom']; $aliaz[$i] = $resA[$i]['nom'];
$fichiers = array(); $fichiers = array();
$stmt = $conn->prepare("SELECT fichier FROM salleFichier WHERE salleID=?"); $stmt = $conn->prepare("SELECT fichier FROM salleFichier WHERE salleID=?");
$stmt->execute([$idSalle]); $stmt->execute([$idSalle]);
$resF = $stmt->fetchAll(); $resF = $stmt->fetchAll();
for($i=0;$i<count($resF);$i++) for($i=0;$i<count($resF);$i++)
$fichiers[$i] = $resF[$i]['fichier']; $fichiers[$i] = $resF[$i]['fichier'];
$locataires = array(); $locataires = array();
$stmt = $conn->prepare("SELECT personne FROM locataires WHERE salleID=?"); $stmt = $conn->prepare("SELECT personne FROM locataires WHERE salleID=?");
$stmt->execute([$idSalle]); $stmt->execute([$idSalle]);
$resP = $stmt->fetchAll(); $resP = $stmt->fetchAll();
for($i=0;$i<count($resP);$i++) for($i=0;$i<count($resP);$i++)
$locataires[$i] = $resP[$i]['personne']; $locataires[$i] = $resP[$i]['personne'];
$stmt = $conn->prepare("SELECT id, description FROM salles WHERE id=?"); $stmt = $conn->prepare("SELECT id, description FROM salles WHERE id=?");
$stmt->execute([$idSalle]); $stmt->execute([$idSalle]);
$resS = $stmt->fetchAll(); $resS = $stmt->fetchAll();
if(count($resS)==0){ if(count($resS)==0){
echo "404"; echo "404";
}else { }else {
$out = array("id" => $resS[0]["id"], "description" => $resS[0]["description"], "aliaz" => $aliaz, "locataires" => $locataires, "fichiers" => $fichiers); $out = array("id" => $resS[0]["id"], "description" => $resS[0]["description"], "aliaz" => $aliaz, "locataires" => $locataires, "fichiers" => $fichiers);
echo (json_encode($out)); echo (json_encode($out));
} }
} else if (isset($_GET["salleNameSearch"])){ } else if (isset($_GET["research"])) {
$research = $_GET["research"];
$salleNameSearch = $_GET["salleNameSearch"];
$stmt = $conn->prepare("SELECT salleID, nom FROM salleAlias WHERE MATCH nom AGAINST (? IN BOOLEAN MODE)"); $stmt = $conn->prepare("SELECT salleID, nom FROM salleAlias WHERE MATCH nom AGAINST (? IN BOOLEAN MODE)");
$stmt->execute([$salleNameSearch]); $stmt->execute([$research]);
$res = $stmt->fetchAll(); $res = $stmt->fetchAll();
$out = array(); $out = array();
for($i=0;$i<count($res);$i++) for($i=0;$i<count($res);$i++)
$out[$i] = array("salleID" => $res[$i]['salleID'], "nom" => $res[$i]["nom"]); $out[$i] = array("id" => $res[$i]['salleID'], "name" => $res[$i]["nom"]);
echo (json_encode($out)); echo (json_encode($out));
} else if (isset($_GET["salleLocSearch"])) { } else if (isset($_GET["salleLocSearch"])) {
$salleLocSearch = $_GET["salleLocSearch"]; $salleLocSearch = $_GET["salleLocSearch"];
$stmt = $conn->prepare("SELECT salleID, personne FROM `locataires` WHERE MATCH personne AGAINST (? IN BOOLEAN MODE)"); $stmt = $conn->prepare("SELECT salleID, personne FROM `locataires` WHERE MATCH personne AGAINST (? IN BOOLEAN MODE)");
$stmt->execute([$salleLocSearch]); $stmt->execute([$salleLocSearch]);
$res = $stmt->fetchAll(); $res = $stmt->fetchAll();
$out = array(); $out = array();
for($i=0;$i<count($res);$i++) for($i=0;$i<count($res);$i++)
$out[$i] = array("salleID" => $res[$i]['salleID'], "personne" => $res[$i]["personne"]); $out[$i] = array("salleID" => $res[$i]['salleID'], "personne" => $res[$i]["personne"]);
echo (json_encode($out)); echo (json_encode($out));
}else { }else {
echo "Je ne connais pas cette commande ..."; echo "Je ne connais pas cette commande ...";
} }

View File

@ -112,14 +112,14 @@
<hr/> <hr/>
<!-- Research results --> <!-- Research results -->
<table class="table"> <table id="research-results-table" class="table" style="display:none;">
<thead> <thead>
<tr> <tr>
<th scope="col">Nom</th> <th scope="col">Nom</th>
<th scope="col">Occupants</th> <th scope="col">Occupants</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="research-results">
<tr> <tr>
<th scope="row">Amphi B</th> <th scope="row">Amphi B</th>
<td></td> <td></td>

View File

@ -12,9 +12,25 @@ function httpGetAsync(theUrl, callback)
function researchRoom() function researchRoom()
{ {
let text = document.getElementById('research').value; var research = document.getElementById('research').value;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'api/request.php?research='+encodeURI(research), true);
xhr.onload = function() {
var table = document.getElementById('research-results');
table.innerHTML = '';
document.getElementById('research-results-table').style.display = 'block';
res = JSON.parse(xhr.responseText);
for (var i=0; i<res.length; i++) {
table.innerHTML += '<tr><th scope="row">' + res[i].id + '</th><td>' + res[i].name + '</td></tr>';
}
};
xhr.send(null);
} }
function putWaitNetworkScreen() function putWaitNetworkScreen()