xref: /webtrees/resources/views/admin/locations.phtml (revision 8504fb2dd47354cd90fd1b5cad7dd742c5639fef)
1<?php
2
3use Fisharebest\Webtrees\Http\RequestHandlers\MapDataDelete;
4use Fisharebest\Webtrees\Http\RequestHandlers\MapDataList;
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Module\PlaceHierarchyListModule;
7use Fisharebest\Webtrees\View;
8use Fisharebest\Webtrees\Webtrees;
9
10/**
11 * @var array<stdClass>      $active
12 * @var array<string,string> $breadcrumbs
13 * @var int                  $parent_id
14 * @var array<mixed>         $placelist
15 * @var bool                 $show_links
16 * @var string               $title
17 */
18
19?>
20
21<?= view('components/breadcrumbs', ['links' => $breadcrumbs]) ?>
22
23<h1><?= $title ?></h1>
24
25<p>
26    <label>
27        <input id="hide-unused-locations" type="checkbox" data-toggle="collapse" data-target=".unused-location">
28        <?= I18N::translate('Hide unused locations') ?>
29    </label>
30</p>
31
32<table class="table table-bordered table-striped table-sm table-hover wt-table-locations">
33    <thead class="thead-dark">
34        <tr>
35            <th><?= I18N::translate('Place') ?></th>
36            <th><?= I18N::translate('Latitude') ?></th>
37            <th><?= I18N::translate('Longitude') ?></th>
38            <!--
39            <th><?= I18N::translate('Flag') ?> </th>
40            -->
41            <th><?= I18N::translate('Edit') ?></th>
42            <th><?= I18N::translate('Facts and events') ?></th>
43            <th><?= I18N::translate('Delete') ?></th>
44        </tr>
45    </thead>
46
47    <tbody>
48    <?php foreach ($placelist as $place) : ?>
49        <tr class="<?= $active[$place->pl_place] ?? null ? '' : 'unused-location collapse show' ?>">
50            <th scope="row">
51                <a href="<?= e(route(MapDataList::class, ['parent_id' => $place->pl_id])) ?>">
52                    <?= e($place->pl_place) ?>
53                    <?php if ($place->no_coord > 0): ?>
54                        <span class="badge badge-pill badge-secondary">
55                            <?= view('icons/warning') ?>
56                            <?= I18N::number($place->no_coord) ?>
57                            /
58                            <?= I18N::number($place->child_count) ?>
59                        </span>
60                    <?php elseif ($place->child_count > 0): ?>
61                        <span class="badge badge-pill badge-secondary">
62                            <?= I18N::number($place->child_count) ?>
63                        </span>
64                    <?php endif ?>
65                </a>
66            </th>
67
68            <td dir="ltr">
69                <?php if ((string) $place->pl_lati === '') : ?>
70                    <?= view('icons/warning') ?>
71                <?php else : ?>
72                    <?= strtr($place->pl_lati, ['N' => '', 'S' => '-', ',' => '.']) ?>
73                <?php endif ?>
74            </td>
75
76            <td dir="ltr">
77                <?php if ((string) $place->pl_long === '') : ?>
78                    <?= view('icons/warning') ?>
79                <?php else : ?>
80                    <?= strtr($place->pl_long, ['E' => '', 'W' => '-', ',' => '.']) ?>
81                <?php endif ?>
82            </td>
83
84            <!--
85            <td>
86                <?php if (is_file(Webtrees::MODULES_PATH . 'openstreetmap/' . $place->pl_icon)) : ?>
87                    <img src="<?= e(Webtrees::MODULES_PATH . 'openstreetmap/' . $place->pl_icon) ?>" width="25" height="15" alt="<?= I18N::translate('Flag of %s', $place->pl_place) ?>">
88                <?php endif ?>
89            </td>
90            -->
91
92            <td>
93                <a class="btn btn-primary" href="<?= e(route('map-data-edit', ['place_id'  => $place->pl_id, 'parent_id' => $place->pl_parent_id])) ?>" title="<?= I18N::translate('Edit') ?>">
94                    <?= view('icons/edit') ?>
95                    <span class="sr-only">
96                        <?= I18N::translate('Edit') ?>
97                    </span>
98                </a>
99            </td>
100
101            <td>
102                <?php if ($show_links && array_key_exists($place->pl_place, $active)): ?>
103                    <?php if (count($active[$place->pl_place]) === 1): ?>
104                        <a class="btn btn-link" href="<?= e(route(PlaceHierarchyListModule::class, ['tree' => $active[$place->pl_place][0]->tree_name, 'place_id' => $active[$place->pl_place][0]->p_id, 'action2' => 'hierarchy-e'])) ?>">
105                            <?= e($active[$place->pl_place][0]->tree_title) ?>
106                        </a>
107                    <?php else: ?>
108                        <div class="dropdown">
109                            <a class="btn btn-link dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
110                                <?= I18N::plural('%s family tree', '%s family trees', count($active[$place->pl_place]), I18N::number(count($active[$place->pl_place]))) ?>
111                            </a>
112
113                            <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
114                                <?php foreach ($active[$place->pl_place] as $link): ?>
115                                    <a class="dropdown-item" href="<?= e(route(PlaceHierarchyListModule::class, ['tree' => $link->tree_name, 'place_id' => $link->p_id])) ?>">
116                                        <?= e($link->tree_title) ?>
117                                    </a>
118                                <?php endforeach ?>
119                            </div>
120                        </div>
121                    <?php endif ?>
122                <?php endif ?>
123            </td>
124
125            <td>
126                <?php if (!array_key_exists($place->pl_place, $active)): ?>
127                    <form method="post" action="<?= e(route(MapDataDelete::class, ['place_id' => $place->pl_id])) ?>">
128                        <?= csrf_field() ?>
129                        <button type="submit" class="btn btn-danger" aria-label="<?= I18N::translate('delete') ?>" data-confirm="<?= I18N::translate('Remove this location?') ?>">
130                            <?= view('icons/delete') ?>
131                        </button>
132                    </form>
133                <?php endif ?>
134            </td>
135        </tr>
136    <?php endforeach ?>
137    </tbody>
138
139    <tfoot>
140        <tr>
141            <td colspan="7">
142                <a class="btn btn-primary" href="<?= e(route('map-data-edit', ['place_id' => '0', 'parent_id' => $parent_id])) ?>">
143                    <?= view('icons/add') ?>
144                    <?= /* I18N: A button label. */
145                    I18N::translate('add place') ?>
146                </a>
147                <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton"
148                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
149                    <?= view('icons/download') ?>
150                    <?= /* I18N: A button label. */
151                    I18N::translate('export file') ?>
152                </button>
153                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
154                    <a class="dropdown-item" href="<?= e(route('locations-export', ['parent_id' => $parent_id, 'format' => 'csv'])) ?>">
155                        csv
156                    </a>
157                    <a class="dropdown-item" href="<?= e(route('locations-export', ['parent_id' => $parent_id, 'format' => 'geojson'])) ?>">
158                        geoJSON
159                    </a>
160                </div>
161                <a class="btn btn-primary" href="<?= e(route('locations-import', ['parent_id' => $parent_id])) ?>">
162                    <?= view('icons/upload') ?>
163                    <?= /* I18N: A button label. */
164                    I18N::translate('import file') ?>
165                </a>
166            </td>
167        </tr>
168    </tfoot>
169</table>
170
171<?php View::push('javascript') ?>
172<script>
173  'use strict';
174
175  webtrees.persistentToggle("hide-unused-locations");
176</script>
177<?php View::endpush() ?>
178