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