diff options
Diffstat (limited to 'app/genealogy/search/state')
-rw-r--r-- | app/genealogy/search/state/data.json/index.php | 39 | ||||
-rw-r--r-- | app/genealogy/search/state/index.php | 73 | ||||
-rw-r--r-- | app/genealogy/search/state/results/index.php | 38 |
3 files changed, 150 insertions, 0 deletions
diff --git a/app/genealogy/search/state/data.json/index.php b/app/genealogy/search/state/data.json/index.php new file mode 100644 index 0000000..e0bad67 --- /dev/null +++ b/app/genealogy/search/state/data.json/index.php @@ -0,0 +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) {
+ if (isset($person["birth"]["place"]) && isset($person["birth"]["place"]["state"])) {
+ if (isset($counts[$person["birth"]["place"]["state"]])) {
+ $counts[$person["birth"]["place"]["state"]]++;
+ } else {
+ $counts[$person["birth"]["place"]["state"]] = 1;
+ }
+ if (!in_array($person["birth"]["place"]["state"], $names)) {
+ $names[] = $person["birth"]["place"]["state"];
+ }
+ }
+}
+
+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/app/genealogy/search/state/index.php b/app/genealogy/search/state/index.php new file mode 100644 index 0000000..1976ac9 --- /dev/null +++ b/app/genealogy/search/state/index.php @@ -0,0 +1,73 @@ +<?php $_TITLE = "Recherche par région de naissance"; require_once $_SERVER['DOCUMENT_ROOT'] . "/private/header.php"; ?>
+<div class="container">
+ <h2>Rechercher par région de naissance</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 région
+ </button>
+ <div class="dropdown-menu">
+ <a class="dropdown-item" href="/search/name">Par prénom</a>
+ <a class="dropdown-item" 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 active" href="/search/state">Par région</a>
+ </div>
+ </div>
+ <input onchange="reload();" class="form-control" type="text"
+ placeholder="Commencer à taper une région..."
+ id="search">
+ </div>
+ <script>
+ setInterval(() => {
+ if (document.getElementById("search").value.trim() !== "") {
+ document.getElementById("preview").innerText = "Affiche toutes les personnes nées dans la région " + document.getElementById("search").value;
+ } else {
+ document.getElementById("preview").innerText = "Sélectionnez une région";
+ }
+ }, 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/app/genealogy/search/state/results/index.php b/app/genealogy/search/state/results/index.php new file mode 100644 index 0000000..98e4c54 --- /dev/null +++ b/app/genealogy/search/state/results/index.php @@ -0,0 +1,38 @@ +<?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 (isset($person["birth"]["place"]) && isset($person["birth"]["place"]["state"])) {
+ if ($person["birth"]["place"]["state"] === $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 |