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

View File

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

View File

@ -12,9 +12,25 @@ function httpGetAsync(theUrl, callback)
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()