xref: /webtrees/resources/views/admin/trees-privacy.phtml (revision 18db81e28bf6216aa6079ed10d09f50cf17333b1)
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    <!-- REQUIRE_AUTHENTICATION -->
28    <div class="row mb-3">
29        <div class="col-form-label col-sm-4">
30            <label>
31                <?= /* I18N: A configuration setting */ I18N::translate('Show the family tree') ?>
32            </label>
33            <div class="hidden-xs">
34                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
35                <span class="badge members"><?= I18N::translate('members') ?></span>
36            </div>
37        </div>
38        <div class="col-sm-8">
39            <?= view('components/select', ['name' => 'REQUIRE_AUTHENTICATION', 'selected' => $tree->getPreference('REQUIRE_AUTHENTICATION'), 'options' => ['0' => I18N::translate('Show to visitors'), '1' => I18N::translate('Show to members')]]) ?>
40            <div class="form-text">
41                <?= /* 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.') ?>
42            </div>
43        </div>
44    </div>
45
46    <!-- SHOW_DEAD_PEOPLE -->
47    <div class="row mb-3">
48        <div class="col-form-label col-sm-4">
49            <label for="SHOW_DEAD_PEOPLE">
50                <?= /* I18N: A configuration setting */ I18N::translate('Show dead individuals') ?>
51            </label>
52            <div class="hidden-xs">
53                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
54                <span class="badge members"><?= I18N::translate('members') ?></span>
55            </div>
56        </div>
57        <div class="col-sm-8">
58            <?= view('components/select', ['name' => 'SHOW_DEAD_PEOPLE', 'selected' => $tree->getPreference('SHOW_DEAD_PEOPLE'), 'options' => array_slice(Auth::accessLevelNames(), 0, 2, true)]) ?>
59            <div class="form-text">
60                <?= /* I18N: Help text for the “Show dead individuals” configuration setting */ I18N::translate('Set the privacy access level for all dead individuals.') ?>
61            </div>
62        </div>
63    </div>
64
65
66    <!-- MAX_ALIVE_AGE -->
67    <div class="row mb-3">
68        <label class="col-form-label col-sm-4" for="MAX_ALIVE_AGE">
69            <?= I18N::translate('Age at which to assume an individual is dead') ?>
70        </label>
71        <div class="col-sm-8">
72            <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')) ?>">
73            <div class="form-text">
74                <?= /* 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.') ?>
75            </div>
76        </div>
77    </div>
78
79    <!-- HIDE_LIVE_PEOPLE -->
80    <fieldset class="row mb-3">
81        <legend class="col-sm-4 col-form-label">
82            <?= /* I18N: A configuration setting */ I18N::translate('Show living individuals') ?>
83            <div class="hidden-xs">
84                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
85                <span class="badge members"><?= I18N::translate('members') ?></span>
86            </div>
87        </legend>
88
89        <div class="col-sm-8">
90            <?= 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')]]) ?>
91            <div class="form-text">
92                <?= /* 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.') ?>
93            </div>
94        </div>
95    </fieldset>
96
97    <!-- KEEP_ALIVE_YEARS_BIRTH / KEEP_ALIVE_YEARS_DEATH -->
98    <fieldset class="row mb-3">
99        <legend class="col-form-label col-sm-4">
100            <?= /* 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') ?>
101        </legend>
102        <div class="col-sm-8">
103            <?php
104            echo
105                /* I18N: Extend privacy to dead individuals who were… */ I18N::translate(
106                    'born in the last %1$s years or died in the last %2$s years',
107                    '<input type="text" name="KEEP_ALIVE_YEARS_BIRTH" value="' . $tree->getPreference('KEEP_ALIVE_YEARS_BIRTH') . '" size="5" maxlength="3">',
108                    '<input type="text" name="KEEP_ALIVE_YEARS_DEATH" value="' . $tree->getPreference('KEEP_ALIVE_YEARS_DEATH') . '" size="5" maxlength="3">'
109                ) ?>
110            <div class="form-text">
111                <?= /* 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.') ?>
112            </div>
113        </div>
114    </fieldset>
115
116    <!-- SHOW_LIVING_NAMES -->
117    <div class="row mb-3">
118        <div class="col-form-label col-sm-4">
119            <label for="SHOW_LIVING_NAMES">
120                <?= /* I18N: A configuration setting */ I18N::translate('Show names of private individuals') ?>
121            </label>
122            <div class="hidden-xs">
123                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
124                <span class="badge members"><?= I18N::translate('members') ?></span>
125                <span class="badge managers"><?= I18N::translate('managers') ?></span>
126            </div>
127        </div>
128        <div class="col-sm-8">
129            <?= view('components/select', ['name' => 'SHOW_LIVING_NAMES', 'selected' => $tree->getPreference('SHOW_LIVING_NAMES'), 'options' => array_slice(Auth::accessLevelNames(), 0, 3, true)]) ?>
130            <div class="form-text">
131                <?= /* 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.') ?>
132            </div>
133        </div>
134    </div>
135
136    <!-- SHOW_PRIVATE_RELATIONSHIPS -->
137    <div class="row mb-3">
138        <div class="col-form-label col-sm-4">
139            <label for="SHOW_PRIVATE_RELATIONSHIPS">
140                <?= /* I18N: A configuration setting */ I18N::translate('Show private relationships') ?>
141            </label>
142            <div class="hidden-xs">
143                <span class="badge visitors"><?= I18N::translate('visitors') ?></span>
144                <span class="badge members"><?= I18N::translate('members') ?></span>
145            </div>
146        </div>
147        <div class="col-sm-8">
148            <?= 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')]]) ?>
149            <div class="form-text">
150                <?= /* 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.') ?>
151            </div>
152        </div>
153    </div>
154    <h2><?= /* I18N: Privacy restrictions are set by RESN tags in GEDCOM. */ I18N::translate('Privacy restrictions') ?></h2>
155    <p>
156        <?= /* 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.') ?>
157    </p>
158
159    <script id="new-resn-template" type="text/html">
160        <tr>
161            <td class="w-50">
162                <select class="form-select record-type-selector mb-3">
163                    <option value="all"><?= I18N::translate('All records') ?></option>
164                    <option value="individual"><?= I18N::translate('Individual') ?></option>
165                    <option value="family"><?= I18N::translate('Family') ?></option>
166                    <option value="source"><?= I18N::translate('Source') ?></option>
167                    <option value="repository"><?= I18N::translate('Repository') ?></option>
168                    <option value="note"><?= I18N::translate('Note') ?></option>
169                    <option value="media"><?= I18N::translate('Media object') ?></option>
170                </select>
171
172                <div class="select-record select-all">
173                    <div class="d-none">
174                        <select name="xref[]" required="required">
175                            <option selected="selected"></option>
176                        </select>
177                    </div>
178                </div>
179
180                <div class="select-record select-individual d-none">
181                    <?= view('components/select-individual', ['name' => 'xref[]', 'id' => '', 'tree' => $tree, 'disabled' => true, 'required' => 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, 'required' => 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, 'required' => 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, 'required' => 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, 'required' => 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, 'required' => 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="visually-hidden">
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 class="w-50">
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                        <?= Auth::privacyRuleNames()[$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 mb-3">
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(ManageTrees::class, ['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            -->
307        </div>
308    </div>
309
310    <?= csrf_field() ?>
311</form>
312
313<?php View::push('javascript') ?>
314<script>
315  'use strict';
316
317  /**
318   * Hide/show the feedback labels for a privacy option.
319   *
320   * @param sel    the control to change
321   * @param who    "visitors", "members" or "managers"
322   * @param access true or false
323   */
324  function setPrivacyFeedback (sel, who, access) {
325    var formGroup = $(sel).closest('.row');
326
327    if (access) {
328      $('.' + who, formGroup).addClass('bg-success').removeClass('bg-secondary');
329      $('.' + who + ' i', formGroup).addClass('fa-check').removeClass('fa-times');
330    } else {
331      $('.' + who, formGroup).addClass('bg-secondary').removeClass('bg-success');
332      $('.' + who + ' i', formGroup).addClass('fa-times').removeClass('fa-check');
333    }
334  }
335
336  /**
337   * Update all the privacy feedback labels.
338   */
339  function updatePrivacyFeedback () {
340    var requireAuthentication = parseInt($('[name=REQUIRE_AUTHENTICATION]').val(), 10);
341    var showDeadPeople = parseInt($('[name=SHOW_DEAD_PEOPLE]').val(), 10);
342    var hideLivePeople = parseInt($('[name=HIDE_LIVE_PEOPLE]').val(), 10);
343    var showLivingNames = parseInt($('[name=SHOW_LIVING_NAMES]').val(), 10);
344    var showPrivateRelationships = parseInt($('[name=SHOW_PRIVATE_RELATIONSHIPS]').val(), 10);
345
346    setPrivacyFeedback('[name=REQUIRE_AUTHENTICATION]', 'visitors', requireAuthentication === 0);
347    setPrivacyFeedback('[name=REQUIRE_AUTHENTICATION]', 'members', true);
348
349    setPrivacyFeedback('[name=SHOW_DEAD_PEOPLE]', 'visitors', requireAuthentication === 0 && (showDeadPeople >= 2 || hideLivePeople === 0));
350    setPrivacyFeedback('[name=SHOW_DEAD_PEOPLE]', 'members', showDeadPeople >= 1 || hideLivePeople === 0);
351
352    setPrivacyFeedback('[name=HIDE_LIVE_PEOPLE]', 'visitors', requireAuthentication === 0 && hideLivePeople === 0);
353    setPrivacyFeedback('[name=HIDE_LIVE_PEOPLE]', 'members', true);
354
355    setPrivacyFeedback('[name=SHOW_LIVING_NAMES]', 'visitors', requireAuthentication === 0 && showLivingNames >= 2);
356    setPrivacyFeedback('[name=SHOW_LIVING_NAMES]', 'members', showLivingNames >= 1);
357    setPrivacyFeedback('[name=SHOW_LIVING_NAMES]', 'managers', showLivingNames >= 0);
358
359    setPrivacyFeedback('[name=SHOW_PRIVATE_RELATIONSHIPS]', 'visitors', requireAuthentication === 0 && showPrivateRelationships >= 1);
360    setPrivacyFeedback('[name=SHOW_PRIVATE_RELATIONSHIPS]', 'members', showPrivateRelationships >= 1);
361  }
362
363  // Activate the privacy feedback labels.
364  updatePrivacyFeedback();
365  $('[name=REQUIRE_AUTHENTICATION], [name=HIDE_LIVE_PEOPLE], [name=SHOW_DEAD_PEOPLE], [name=SHOW_LIVING_NAMES], [name=SHOW_PRIVATE_RELATIONSHIPS]').on('change', function () {
366    updatePrivacyFeedback();
367  });
368
369  // Mute a line when it is marked for deletion
370  $('#default-resn').on('click', 'input[type=checkbox]', function () {
371    if ($(this).prop('checked')) {
372      $($(this).closest('tr').addClass('text-muted'));
373    } else {
374      $($(this).closest('tr').removeClass('text-muted'));
375    }
376  });
377
378  // Add a new row to the table
379  $('#add-resn').on('click', function () {
380    $('#default-resn tbody').prepend($('#new-resn-template').html());
381
382    document.querySelectorAll('#default-resn tbody tr:first-child select.tom-select')
383      .forEach(element => webtrees.initializeTomSelect(element));
384
385    let row = document.getElementById('default-resn').querySelector('tbody tr');
386    webtrees.initializeIFSRO(row.querySelector('select'), row);
387  });
388</script>
389<?php View::endpush() ?>
390