xref: /webtrees/resources/views/admin/trees-privacy.phtml (revision afc2d1902ecd3bf5ad093d4f0c848f540e3f1cc8)
1<?php
2
3use Fisharebest\Webtrees\Auth;
4use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
5use Fisharebest\Webtrees\Http\RequestHandlers\ManageTrees;
6use Fisharebest\Webtrees\Http\RequestHandlers\TreePrivacyAction;
7use Fisharebest\Webtrees\I18N;
8use Fisharebest\Webtrees\Tree;
9use Fisharebest\Webtrees\View;
10
11/**
12 * @var array<string,string> $all_tags
13 * @var int                  $count_trees
14 * @var array<string,string> $privacy_constants
15 * @var array<int,object>    $privacy_restrictions
16 * @var string               $title
17 * @var Tree                 $tree
18 */
19
20?>
21
22<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(ManageTrees::class, ['tree' => $tree->name()]) => I18N::translate('Manage family trees'), $title]]) ?>
23
24<h1><?= $title ?></h1>
25
26<form method="post" action="<?= e(route(TreePrivacyAction::class, ['tree' => $tree->name()])) ?>">
27    <?= csrf_field() ?>
28
29    <!-- REQUIRE_AUTHENTICATION -->
30    <div class="row form-group mb-3">
31        <div class="col-form-label col-sm-4">
32            <label>
33                <?= /* I18N: A configuration setting */ I18N::translate('Show the family tree') ?>
34            </label>
35            <div class="hidden-xs">
36                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
37                <span class="badge members"><?= I18N::translate('members') ?></span>
38            </div>
39        </div>
40        <div class="col-sm-8">
41            <?= view('components/select', ['name' => 'REQUIRE_AUTHENTICATION', 'selected' => $tree->getPreference('REQUIRE_AUTHENTICATION'), 'options' => ['0' => I18N::translate('Show to visitors'), '1' => I18N::translate('Show to members')]]) ?>
42            <div class="form-text">
43                <?= /* I18N: Help text for the “Family tree” configuration setting */ I18N::translate('Enabling this option will force all visitors to sign in before they can view any data on the website.') ?>
44            </div>
45        </div>
46    </div>
47
48    <!-- SHOW_DEAD_PEOPLE -->
49    <div class="row form-group mb-3">
50        <div class="col-form-label col-sm-4">
51            <label for="SHOW_DEAD_PEOPLE">
52                <?= /* I18N: A configuration setting */ I18N::translate('Show dead individuals') ?>
53            </label>
54            <div class="hidden-xs">
55                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
56                <span class="badge members"><?= I18N::translate('members') ?></span>
57            </div>
58        </div>
59        <div class="col-sm-8">
60            <?= view('components/select', ['name' => 'SHOW_DEAD_PEOPLE', 'selected' => $tree->getPreference('SHOW_DEAD_PEOPLE'), 'options' => array_slice(Auth::accessLevelNames(), 0, 2, true)]) ?>
61            <div class="form-text">
62                <?= /* I18N: Help text for the “Show dead individuals” configuration setting */ I18N::translate('Set the privacy access level for all dead individuals.') ?>
63            </div>
64        </div>
65    </div>
66
67
68    <!-- MAX_ALIVE_AGE -->
69    <div class="row form-group mb-3">
70        <label class="col-form-label col-sm-4" for="MAX_ALIVE_AGE">
71            <?= I18N::translate('Age at which to assume an individual is dead') ?>
72        </label>
73        <div class="col-sm-8">
74            <input class="form-control" id="MAX_ALIVE_AGE" min="1" max="9999" name="MAX_ALIVE_AGE" required type="number" value="<?= e($tree->getPreference('MAX_ALIVE_AGE')) ?>">
75            <div class="form-text">
76                <?= /* I18N: Help text for the “Age at which to assume an individual is dead” configuration setting */ I18N::translate('If this individual has any events other than death, burial, or cremation more recent than this number of years, they are considered to be “alive”. Children’s birth dates are considered to be such events for this purpose.') ?>
77            </div>
78        </div>
79    </div>
80
81    <!-- HIDE_LIVE_PEOPLE -->
82    <fieldset class="row form-group mb-3">
83        <legend class="col-sm-4 col-form-label">
84            <?= /* I18N: A configuration setting */ I18N::translate('Show living individuals') ?>
85            <div class="hidden-xs">
86                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
87                <span class="badge members"><?= I18N::translate('members') ?></span>
88            </div>
89        </legend>
90
91        <div class="col-sm-8">
92            <?= view('components/select', ['name' => 'HIDE_LIVE_PEOPLE', 'selected' => $tree->getPreference('HIDE_LIVE_PEOPLE'), 'options' => ['0' => I18N::translate('Show to visitors'), '1' => I18N::translate('Show to members')]]) ?>
93            <div class="form-text">
94                <?= /* I18N: Help text for the “Show living individuals” configuration setting */ I18N::translate('If you show living individuals to visitors, all other privacy restrictions are ignored. Do this only if all the data in your tree is public.') ?>
95            </div>
96        </div>
97    </fieldset>
98
99    <!-- KEEP_ALIVE_YEARS_BIRTH / KEEP_ALIVE_YEARS_DEATH -->
100    <fieldset class="row form-group mb-3">
101        <legend class="col-form-label col-sm-4">
102            <?= /* I18N: A configuration setting. …who were born in the last XX years or died in the    last YY years */ I18N::translate('Extend privacy to dead individuals') ?>
103        </legend>
104        <div class="col-sm-8">
105            <?php
106            echo
107                /* I18N: Extend privacy to dead individuals who were… */ I18N::translate(
108                    'born in the last %1$s years or died in the last %2$s years',
109                    '<input type="text" name="KEEP_ALIVE_YEARS_BIRTH" value="' . $tree->getPreference('KEEP_ALIVE_YEARS_BIRTH') . '" size="5" maxlength="3">',
110                    '<input type="text" name="KEEP_ALIVE_YEARS_DEATH" value="' . $tree->getPreference('KEEP_ALIVE_YEARS_DEATH') . '" size="5" maxlength="3">'
111                ) ?>
112            <div class="form-text">
113                <?= /* I18N: Help text for the “Extend privacy to dead individuals” configuration setting */ I18N::translate('In some countries, privacy laws apply not only to living individuals, but also to those who have died recently. This option will allow you to extend the privacy rules for living individuals to those who were born or died within a specified number of years. Leave these values empty to disable this feature.') ?>
114            </div>
115        </div>
116    </fieldset>
117
118    <!-- SHOW_LIVING_NAMES -->
119    <div class="row form-group mb-3">
120        <div class="col-form-label col-sm-4">
121            <label for="SHOW_LIVING_NAMES">
122                <?= /* I18N: A configuration setting */ I18N::translate('Show names of private individuals') ?>
123            </label>
124            <div class="hidden-xs">
125                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
126                <span class="badge members"><?= I18N::translate('members') ?></span>
127                <span class="badge managers"><?= I18N::translate('managers') ?></span>
128            </div>
129        </div>
130        <div class="col-sm-8">
131            <?= view('components/select', ['name' => 'SHOW_LIVING_NAMES', 'selected' => $tree->getPreference('SHOW_LIVING_NAMES'), 'options' => array_slice(Auth::accessLevelNames(), 0, 3, true)]) ?>
132            <div class="form-text">
133                <?= /* I18N: Help text for the “Show names of private individuals” configuration setting */ I18N::translate('This option will show the names (but no other details) of private individuals. Individuals are private if they are still alive or if a privacy restriction has been added to their individual record. To hide a specific name, add a privacy restriction to that name record.') ?>
134            </div>
135        </div>
136    </div>
137
138    <!-- SHOW_PRIVATE_RELATIONSHIPS -->
139    <div class="row form-group mb-3">
140        <div class="col-form-label col-sm-4">
141            <label for="SHOW_PRIVATE_RELATIONSHIPS">
142                <?= /* I18N: A configuration setting */ I18N::translate('Show private relationships') ?>
143            </label>
144            <div class="hidden-xs">
145                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
146                <span class="badge members"><?= I18N::translate('members') ?></span>
147            </div>
148        </div>
149        <div class="col-sm-8">
150            <?= view('components/select', ['name' => 'SHOW_PRIVATE_RELATIONSHIPS', 'selected' => $tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS'), 'options' => ['0' => I18N::translate('Hide from everyone'), '1' => I18N::translate('Show to visitors')]]) ?>
151            <div class="form-text">
152                <?= /* I18N: Help text for the “Show private relationships” configuration setting */ I18N::translate('This option will retain family links in private records. This means that you will see empty “private” boxes on the pedigree chart and on other charts with private individuals.') ?>
153            </div>
154        </div>
155    </div>
156    <h2><?= /* I18N: Privacy restrictions are set by RESN tags in GEDCOM. */ I18N::translate('Privacy restrictions') ?></h2>
157    <p>
158        <?= /* I18N: Privacy restrictions are RESN tags in GEDCOM. */ I18N::translate('You can set the access for a specific record, fact, or event by adding a restriction to it. If a record, fact, or event does not have a restriction, the following default restrictions will be used.') ?>
159    </p>
160
161    <script id="new-resn-template" type="text/html">
162        <tr>
163            <td>
164                <select class="form-control record-type-selector">
165                    <option value="all"><?= I18N::translate('All records') ?></option>
166                    <option value="individual"><?= I18N::translate('Individual') ?></option>
167                    <option value="family"><?= I18N::translate('Family') ?></option>
168                    <option value="source"><?= I18N::translate('Source') ?></option>
169                    <option value="repository"><?= I18N::translate('Repository') ?></option>
170                    <option value="note"><?= I18N::translate('Note') ?></option>
171                    <option value="media"><?= I18N::translate('Media object') ?></option>
172                </select>
173
174                <div class="select-record select-all">
175                    <input type="hidden" name="xref[]">
176                </div>
177
178                <div class="select-record select-individual d-none">
179                    <?= view('components/select-individual', ['name' => 'xref[]', 'id' => '', 'tree' => $tree, 'disabled' => true]) ?>
180                </div>
181
182                <div class="select-record select-family d-none">
183                    <?= view('components/select-family', ['name' => 'xref[]', 'id' => '', 'tree' => $tree, 'disabled' => true]) ?>
184                </div>
185
186                <div class="select-record select-source d-none">
187                    <?= view('components/select-source', ['name' => 'xref[]', 'id' => '', 'tree' => $tree, 'disabled' => true]) ?>
188                </div>
189
190                <div class="select-record select-repository d-none">
191                    <?= view('components/select-repository', ['name' => 'xref[]', 'id' => '', 'tree' => $tree, 'disabled' => true]) ?>
192                </div>
193
194                <div class="select-record select-note d-none">
195                    <?= view('components/select-note', ['name' => 'xref[]', 'id' => '', 'tree' => $tree, 'disabled' => true]) ?>
196                </div>
197
198                <div class="select-record select-media d-none">
199                    <?= view('components/select-media', ['name' => 'xref[]', 'id' => '', 'tree' => $tree, 'disabled' => true]) ?>
200                </div>
201            </td>
202
203            <td>
204                <?= view('components/select', ['name' => 'tag_type[]', 'id' => '', 'selected' => '', 'options' => $all_tags]) ?>
205            </td>
206
207            <td>
208                <?= view('components/select', ['name' => 'resn[]', 'id' => '', 'selected' => 'privacy', 'options' => $privacy_constants]) ?>
209            </td>
210
211            <td>
212            </td>
213        </tr>
214    </script>
215
216    <table class="table table-bordered table-sm table-hover" id="default-resn">
217        <caption class="visually-hidden">
218            <?= I18N::translate('Privacy restrictions - these apply to records and facts that do not contain a GEDCOM RESN tag') ?>
219        </caption>
220        <thead>
221            <tr>
222                <th>
223                    <?= I18N::translate('Record') ?>
224                </th>
225                <th>
226                    <?= I18N::translate('Fact or event') ?>
227                </th>
228                <th>
229                    <?= I18N::translate('Access level') ?>
230                </th>
231                <th>
232                    <button class="btn btn-primary" id="add-resn" type="button">
233                <?= view('icons/add') ?>
234                        <?= /* I18N: A button label. */ I18N::translate('add') ?>
235                    </button>
236                </th>
237            </tr>
238        </thead>
239        <tbody>
240            <?php foreach ($privacy_restrictions as $privacy_restriction) : ?>
241                <tr>
242                    <td>
243                        <?php if ($privacy_restriction->record) : ?>
244                            <a href="<?= e($privacy_restriction->record->url()) ?>"><?= $privacy_restriction->record->fullName() ?></a>
245                        <?php elseif ($privacy_restriction->xref) : ?>
246                            <div class="text-danger">
247                                <?= $privacy_restriction->xref ?><?= I18N::translate('This record does not exist.') ?>
248                            </div>
249                        <?php else : ?>
250                            <div class="text-muted">
251                                <?= I18N::translate('All records') ?>
252                            </div>
253                        <?php endif ?>
254                    </td>
255                    <td>
256                        <?php if ($privacy_restriction->tag_label === '') : ?>
257                            <div class="text-muted">
258                                <?= I18N::translate('All facts and events') ?>
259                            </div>
260                        <?php else : ?>
261                            <?= $privacy_restriction->tag_label ?>
262                        <?php endif ?>
263                    </td>
264                    <td>
265                        <?= Auth::privacyRuleNames()[$privacy_restriction->resn] ?>
266                    </td>
267                    <td>
268                        <label for="delete-<?= $privacy_restriction->default_resn_id ?>">
269                            <input id="delete-<?= $privacy_restriction->default_resn_id ?>" name="delete[]" type="checkbox" value="<?= $privacy_restriction->default_resn_id ?>">
270                            <?= I18N::translate('Delete') ?>
271                        </label>
272                    </td>
273                </tr>
274            <?php endforeach ?>
275        </tbody>
276    </table>
277
278    <div class="row form-group mb-3">
279        <div class="offset-sm-4 col-sm-8">
280            <button type="submit" class="btn btn-primary">
281                <?= view('icons/save') ?>
282                <?= I18N::translate('save') ?>
283            </button>
284
285            <a class="btn btn-secondary" href="<?= route(ManageTrees::class, ['tree' => $tree->name()]) ?>">
286                <?= view('icons/cancel') ?>
287                <?= I18N::translate('cancel') ?>
288            </a>
289            <!-- Coming soon
290            <div class="form-check">
291                <?php if ($count_trees > 1) : ?>
292                <label>
293                    <input type="checkbox" name="all_trees">
294                    <?= /* I18N: Label for checkbox */ I18N::translate('Apply these preferences to all family trees') ?>
295                </label>
296                <?php endif ?>
297            </div>
298            <div class="form-check">
299                <label>
300                    <input type="checkbox" name="new_trees">
301                    <?= /* I18N: Label for checkbox */ I18N::translate('Apply these preferences to new family trees') ?>
302                </label>
303            </div>
304        </div>
305        -->
306        </div>
307
308</form>
309
310<?php View::push('javascript') ?>
311<script>
312    "use strict";
313
314    /**
315     * Hide/show the feedback labels for a privacy option.
316     *
317     * @param sel    the control to change
318     * @param who    "visitors", "members" or "managers"
319     * @param access true or false
320     */
321    function setPrivacyFeedback(sel, who, access) {
322        var formGroup = $(sel).closest(".form-group");
323
324        if (access) {
325            $("." + who, formGroup).addClass("bg-success").removeClass("bg-secondary");
326            $("." + who + " i", formGroup).addClass("fa-check").removeClass("fa-times");
327        } else {
328            $("." + who, formGroup).addClass("bg-secondary").removeClass("bg-success");
329            $("." + who + " i", formGroup).addClass("fa-times").removeClass("fa-check");
330        }
331    }
332
333    /**
334     * Update all the privacy feedback labels.
335     */
336    function updatePrivacyFeedback() {
337        var requireAuthentication    = parseInt($("[name=REQUIRE_AUTHENTICATION]").val(), 10);
338        var showDeadPeople           = parseInt($("[name=SHOW_DEAD_PEOPLE]").val(), 10);
339        var hideLivePeople           = parseInt($("[name=HIDE_LIVE_PEOPLE]").val(), 10);
340        var showLivingNames          = parseInt($("[name=SHOW_LIVING_NAMES]").val(), 10);
341        var showPrivateRelationships = parseInt($("[name=SHOW_PRIVATE_RELATIONSHIPS]").val(), 10);
342
343        setPrivacyFeedback("[name=REQUIRE_AUTHENTICATION]", "visitors", requireAuthentication === 0);
344        setPrivacyFeedback("[name=REQUIRE_AUTHENTICATION]", "members", true);
345
346        setPrivacyFeedback("[name=SHOW_DEAD_PEOPLE]", "visitors", requireAuthentication === 0 && (showDeadPeople >= 2 || hideLivePeople === 0));
347        setPrivacyFeedback("[name=SHOW_DEAD_PEOPLE]", "members", showDeadPeople >= 1 || hideLivePeople === 0);
348
349        setPrivacyFeedback("[name=HIDE_LIVE_PEOPLE]", "visitors", requireAuthentication === 0 && hideLivePeople === 0);
350        setPrivacyFeedback("[name=HIDE_LIVE_PEOPLE]", "members", true);
351
352        setPrivacyFeedback("[name=SHOW_LIVING_NAMES]", "visitors", requireAuthentication === 0 && showLivingNames >= 2);
353        setPrivacyFeedback("[name=SHOW_LIVING_NAMES]", "members", showLivingNames >= 1);
354        setPrivacyFeedback("[name=SHOW_LIVING_NAMES]", "managers", showLivingNames >= 0);
355
356        setPrivacyFeedback("[name=SHOW_PRIVATE_RELATIONSHIPS]", "visitors", requireAuthentication === 0 && showPrivateRelationships >= 1);
357        setPrivacyFeedback("[name=SHOW_PRIVATE_RELATIONSHIPS]", "members", showPrivateRelationships >= 1);
358    }
359
360    // Activate the privacy feedback labels.
361    updatePrivacyFeedback();
362    $("[name=REQUIRE_AUTHENTICATION], [name=HIDE_LIVE_PEOPLE], [name=SHOW_DEAD_PEOPLE], [name=SHOW_LIVING_NAMES], [name=SHOW_PRIVATE_RELATIONSHIPS]").on("change", function () {
363        updatePrivacyFeedback();
364    });
365
366    // Mute a line when it is marked for deletion
367    $("#default-resn").on("click", "input[type=checkbox]", function () {
368        if ($(this).prop("checked")) {
369            $($(this).closest("tr").addClass("text-muted"));
370        } else {
371            $($(this).closest("tr").removeClass("text-muted"));
372        }
373    });
374
375    // Add a new row to the table
376    $("#add-resn").on("click", function () {
377        $("#default-resn tbody").prepend($("#new-resn-template").html());
378
379        // Select2 - same as webtrees.js
380        $("#default-resn tbody tr:first select.select2").select2({
381            width: '100%',
382            escapeMarkup: function (x) {
383                return x;
384            },
385        })
386        .on("select2:unselect", function (evt) {
387            $(evt.delegateTarget).append("<option value=\"\" selected=\"selected\"></option>");
388        });
389
390        // Record type selector
391        $(".record-type-selector").change(function () {
392            const container = $(this).closest("td");
393            $(".select-record", container).addClass('d-none');
394            $(".select-record select", container).prop( "disabled", true);
395            $(".select-record input", container).prop( "disabled", true);
396            $(".select-" + $(this).val(), container).removeClass('d-none');
397            $(".select-" + $(this).val() + " select", container).prop( "disabled", false);
398            $(".select-" + $(this).val() + " input", container).prop( "disabled", false);
399        });
400    });
401</script>
402<?php View::endpush() ?>
403