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