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