diff options
Diffstat (limited to 'search/lastname')
-rw-r--r-- | search/lastname/data.json/index.php | 76 | ||||
-rw-r--r-- | search/lastname/index.php | 144 | ||||
-rw-r--r-- | search/lastname/results/index.php | 70 |
3 files changed, 145 insertions, 145 deletions
diff --git a/search/lastname/data.json/index.php b/search/lastname/data.json/index.php index 861b791..a6c0daa 100644 --- a/search/lastname/data.json/index.php +++ b/search/lastname/data.json/index.php @@ -1,39 +1,39 @@ -<?php - -require_once $_SERVER['DOCUMENT_ROOT'] . "/../session.php"; - -/** @var string $_FULLNAME - * @var string $_USER - * @var array $_PROFILE - * @var array $_CONFIG - */ - -$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/data/people.json"), true); - -header("Content-Type: application/json"); - -$arr = []; -$names = []; -$counts = []; - -foreach ($data as $id => $person) { - $name = ucfirst(strtolower($person["famname"])); - - if (isset($counts[$name])) { - $counts[$name]++; - } else { - $counts[$name] = 1; - } - if (!in_array($name, $names)) { - $names[] = $name; - } -} - -foreach ($names as $name) { - $arr[] = [ - 'name' => $name, - 'occurrences' => $counts[$name] . " personne" . ($counts[$name] > 1 ? "s" : "") - ]; -} - +<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/../session.php";
+
+/** @var string $_FULLNAME
+ * @var string $_USER
+ * @var array $_PROFILE
+ * @var array $_CONFIG
+ */
+
+$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/data/people.json"), true);
+
+header("Content-Type: application/json");
+
+$arr = [];
+$names = [];
+$counts = [];
+
+foreach ($data as $id => $person) {
+ $name = ucfirst(strtolower($person["famname"]));
+
+ if (isset($counts[$name])) {
+ $counts[$name]++;
+ } else {
+ $counts[$name] = 1;
+ }
+ if (!in_array($name, $names)) {
+ $names[] = $name;
+ }
+}
+
+foreach ($names as $name) {
+ $arr[] = [
+ 'name' => $name,
+ 'occurrences' => $counts[$name] . " personne" . ($counts[$name] > 1 ? "s" : "")
+ ];
+}
+
echo(json_encode($arr));
\ No newline at end of file diff --git a/search/lastname/index.php b/search/lastname/index.php index 1b932f0..5e3717d 100644 --- a/search/lastname/index.php +++ b/search/lastname/index.php @@ -1,73 +1,73 @@ -<?php $_TITLE = "Recherche par prénom"; require_once $_SERVER['DOCUMENT_ROOT'] . "/private/header.php"; ?> -<div class="container"> - <h2>Rechercher par nom</h2> - <p id="preview">Patientez...</p> - <script src="/dllib/jquery.flexdatalist.min.js"></script> - <div class="input-group mt-3 mb-3"> - <div class="input-group-prepend"> - <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> - Par nom - </button> - <div class="dropdown-menu"> - <a class="dropdown-item" href="/search/name">Par prénom</a> - <a class="dropdown-item active" href="/search/lastname">Par nom</a> - <a class="dropdown-item" href="/search/birth">Par date de naissance</a> - <a class="dropdown-item" href="/search/death">Par date de décès</a> - <a class="dropdown-item" href="/search/marriage">Par date de mariage</a> - <a class="dropdown-item" href="/search/city">Par ville</a> - <a class="dropdown-item" href="/search/dept">Par département</a> - <a class="dropdown-item" href="/search/state">Par région</a> - </div> - </div> - <input onchange="reload();" class="form-control" type="text" - placeholder="Commencer à taper un nom..." - id="search"> - </div> - <script> - setInterval(() => { - if (document.getElementById("search").value.trim() !== "") { - document.getElementById("preview").innerText = "Affiche toutes les personnes nommées " + document.getElementById("search").value; - } else { - document.getElementById("preview").innerText = "Sélectionnez un nom"; - } - }, 100) - - function reload() { - window.fetch("./results/?q=" + encodeURI(document.getElementById("search").value.trim())).then((a) => { - a.text().then((b) => { - document.getElementById("results").innerHTML = b; - }) - }) - } - - window.addEventListener("load", () => { - i = Math.random().toString().substr(2); - document.getElementById('search').classList.add(i); - $('#search.' + i).flexdatalist({ - cache: false, - minLength: 0, - selectionRequired: true, - visibleProperties: ["name","occurrences"], - searchIn: 'name', - data: "data.json" - }); - }) - </script> - <style> - .flexdatalist-results li { - cursor: pointer; - } - .flexdatalist-results li .item-occurrences { - color: rgba(0, 0, 0, .25); - } - .flexdatalist-results li:hover { - opacity: .75; - } - .flexdatalist-results li:active { - opacity: .5; - } - </style> - <div id="results"></div> -</div> -<br> +<?php $_TITLE = "Recherche par prénom"; require_once $_SERVER['DOCUMENT_ROOT'] . "/private/header.php"; ?>
+<div class="container">
+ <h2>Rechercher par nom</h2>
+ <p id="preview">Patientez...</p>
+ <script src="/dllib/jquery.flexdatalist.min.js"></script>
+ <div class="input-group mt-3 mb-3">
+ <div class="input-group-prepend">
+ <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
+ Par nom
+ </button>
+ <div class="dropdown-menu">
+ <a class="dropdown-item" href="/search/name">Par prénom</a>
+ <a class="dropdown-item active" href="/search/lastname">Par nom</a>
+ <a class="dropdown-item" href="/search/birth">Par date de naissance</a>
+ <a class="dropdown-item" href="/search/death">Par date de décès</a>
+ <a class="dropdown-item" href="/search/marriage">Par date de mariage</a>
+ <a class="dropdown-item" href="/search/city">Par ville</a>
+ <a class="dropdown-item" href="/search/dept">Par département</a>
+ <a class="dropdown-item" href="/search/state">Par région</a>
+ </div>
+ </div>
+ <input onchange="reload();" class="form-control" type="text"
+ placeholder="Commencer à taper un nom..."
+ id="search">
+ </div>
+ <script>
+ setInterval(() => {
+ if (document.getElementById("search").value.trim() !== "") {
+ document.getElementById("preview").innerText = "Affiche toutes les personnes nommées " + document.getElementById("search").value;
+ } else {
+ document.getElementById("preview").innerText = "Sélectionnez un nom";
+ }
+ }, 100)
+
+ function reload() {
+ window.fetch("./results/?q=" + encodeURI(document.getElementById("search").value.trim())).then((a) => {
+ a.text().then((b) => {
+ document.getElementById("results").innerHTML = b;
+ })
+ })
+ }
+
+ window.addEventListener("load", () => {
+ i = Math.random().toString().substr(2);
+ document.getElementById('search').classList.add(i);
+ $('#search.' + i).flexdatalist({
+ cache: false,
+ minLength: 0,
+ selectionRequired: true,
+ visibleProperties: ["name","occurrences"],
+ searchIn: 'name',
+ data: "data.json"
+ });
+ })
+ </script>
+ <style>
+ .flexdatalist-results li {
+ cursor: pointer;
+ }
+ .flexdatalist-results li .item-occurrences {
+ color: rgba(0, 0, 0, .25);
+ }
+ .flexdatalist-results li:hover {
+ opacity: .75;
+ }
+ .flexdatalist-results li:active {
+ opacity: .5;
+ }
+ </style>
+ <div id="results"></div>
+</div>
+<br>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/private/footer.php"; ?>
\ No newline at end of file diff --git a/search/lastname/results/index.php b/search/lastname/results/index.php index 80bc75b..bfb80f7 100644 --- a/search/lastname/results/index.php +++ b/search/lastname/results/index.php @@ -1,36 +1,36 @@ -<?php - -require_once $_SERVER['DOCUMENT_ROOT'] . "/../session.php"; - -/** @var string $_FULLNAME - * @var string $_USER - * @var array $_PROFILE - * @var array $_CONFIG - */ - -$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/data/people.json"), true); - -if (isset($_GET['q']) && trim($_GET['q']) !== "") { - $q = $_GET['q']; -} else { - die(); -} - -$results = []; - -foreach ($data as $id => $person) { - if (ucfirst(strtolower($person["famname"])) === ucfirst(strtolower($q))) { - $results[] = $id; - } -} -if (count($results) === 0): ?> -<ul class="list-group"> - <li class="list-group-item">Aucun résultat correspondant</li> -</ul> -<?php else: ?> -<div class="list-group"> - <?php foreach ($results as $result): $p = $data[$result]; ?> - <a href="/person/?_=<?= $result ?>" class="list-group-item list-group-item-action"><?= $p["famname"] ?> <?= $p["surname"] ?> <span class="text-muted">#<?= $result ?></span></a> - <?php endforeach; ?> -</div> +<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/../session.php";
+
+/** @var string $_FULLNAME
+ * @var string $_USER
+ * @var array $_PROFILE
+ * @var array $_CONFIG
+ */
+
+$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/data/people.json"), true);
+
+if (isset($_GET['q']) && trim($_GET['q']) !== "") {
+ $q = $_GET['q'];
+} else {
+ die();
+}
+
+$results = [];
+
+foreach ($data as $id => $person) {
+ if (ucfirst(strtolower($person["famname"])) === ucfirst(strtolower($q))) {
+ $results[] = $id;
+ }
+}
+if (count($results) === 0): ?>
+<ul class="list-group">
+ <li class="list-group-item">Aucun résultat correspondant</li>
+</ul>
+<?php else: ?>
+<div class="list-group">
+ <?php foreach ($results as $result): $p = $data[$result]; ?>
+ <a href="/person/?_=<?= $result ?>" class="list-group-item list-group-item-action"><?= $p["famname"] ?> <?= $p["surname"] ?> <span class="text-muted">#<?= $result ?></span></a>
+ <?php endforeach; ?>
+</div>
<?php endif; ?>
\ No newline at end of file |