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