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