xref: /webtrees/resources/views/admin/trees-privacy.phtml (revision 9b152ff9230017d2c03aa1bf603a98b18250446d)
1<?php
2
3use Fisharebest\Webtrees\Functions\FunctionsEdit;
4use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Site;
7use Fisharebest\Webtrees\View;
8use Ramsey\Uuid\Uuid;
9
10?>
11
12<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route('manage-trees', ['tree' => $tree->name()]) => I18N::translate('Manage family trees'), $title]]) ?>
13
14<h1><?= $title ?></h1>
15
16<form method="post" action="<?= e(route('tree-privacy-update', ['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(FunctionsEdit::optionsAccessLevels(), 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                maxlength="5"
68                name="MAX_ALIVE_AGE"
69                type="text"
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="individual"><?= I18N::translate('Individual') ?></option>
168                    <option value="family"><?= I18N::translate('Family') ?></option>
169                    <option value="source"><?= I18N::translate('Source') ?></option>
170                    <option value="repository"><?= I18N::translate('Repository') ?></option>
171                    <option value="note"><?= I18N::translate('Note') ?></option>
172                    <option value="media"><?= I18N::translate('Media object') ?></option>
173                </select>
174                <span class="select-record select-individual">
175                    <?= view('components/select-individual', ['name' => 'xref[]', 'id' => Uuid::uuid4()->toString(), 'tree' => $tree]) ?>
176                </span>
177                <span class="select-record select-family d-none">
178                    <?= view('components/select-family', ['name' => 'xref[]', 'id' => Uuid::uuid4()->toString(), 'tree' => $tree, 'disabled' => true]) ?>
179                </span>
180                <span class="select-record select-source d-none">
181                    <?= view('components/select-source', ['name' => 'xref[]', 'id' => Uuid::uuid4()->toString(), 'tree' => $tree, 'disabled' => true]) ?>
182                </span>
183                <span class="select-record select-repository d-none">
184                    <?= view('components/select-repository', ['name' => 'xref[]', 'id' => Uuid::uuid4()->toString(), 'tree' => $tree, 'disabled' => true]) ?>
185                </span>
186                <span class="select-record select-note d-none">
187                    <?= view('components/select-note', ['name' => 'xref[]', 'id' => Uuid::uuid4()->toString(), 'tree' => $tree, 'disabled' => true]) ?>
188                </span>
189                <span class="select-record select-media d-none">
190                    <?= view('components/select-media', ['name' => 'xref[]', 'id' => Uuid::uuid4()->toString(), 'tree' => $tree, 'disabled' => true]) ?>
191                </span>
192            </td>
193            <td>
194                <?= view('components/select', ['name' => 'tag_type[]', 'id' => Uuid::uuid4()->toString(), 'selected' => '', 'options' => $all_tags]) ?>
195            </td>
196            <td>
197                <?= view('components/select', ['name' => 'resn[]', 'id' => Uuid::uuid4()->toString(), 'selected' => 'privacy', 'options' => $privacy_constants]) ?>
198            </td>
199            <td>
200            </td>
201        </tr>
202    </script>
203
204    <table class="table table-bordered table-sm table-hover" id="default-resn">
205        <caption class="sr-only">
206            <?= I18N::translate('Privacy restrictions - these apply to records and facts that do not contain a GEDCOM RESN tag') ?>
207        </caption>
208        <thead>
209            <tr>
210                <th>
211                    <?= I18N::translate('Record') ?>
212                </th>
213                <th>
214                    <?= I18N::translate('Fact or event') ?>
215                </th>
216                <th>
217                    <?= I18N::translate('Access level') ?>
218                </th>
219                <th>
220                    <button class="btn btn-primary" id="add-resn" type="button">
221                <?= view('icons/add') ?>
222                        <?= /* I18N: A button label. */ I18N::translate('add') ?>
223                    </button>
224                </th>
225            </tr>
226        </thead>
227        <tbody>
228            <?php foreach ($privacy_restrictions as $privacy_restriction) : ?>
229                <tr>
230                    <td>
231                        <?php if ($privacy_restriction->record) : ?>
232                            <a href="<?= e($privacy_restriction->record->url()) ?>"><?= $privacy_restriction->record->fullName() ?></a>
233                        <?php elseif ($privacy_restriction->xref) : ?>
234                            <div class="text-danger">
235                                <?= $privacy_restriction->xref ?><?= I18N::translate('This record does not exist.') ?>
236                            </div>
237                        <?php else : ?>
238                            <div class="text-muted">
239                                <?= I18N::translate('All records') ?>
240                            </div>
241                        <?php endif ?>
242                    </td>
243                    <td>
244                        <?php if ($privacy_restriction->tag_label === '') : ?>
245                            <div class="text-muted">
246                                <?= I18N::translate('All facts and events') ?>
247                            </div>
248                        <?php else : ?>
249                            <?= $privacy_restriction->tag_label ?>
250                        <?php endif ?>
251                    </td>
252                    <td>
253                        <?= FunctionsEdit::optionsRestrictionsRule()[$privacy_restriction->resn] ?>
254                    </td>
255                    <td>
256                        <label for="delete-<?= $privacy_restriction->default_resn_id ?>">
257                            <input id="delete-<?= $privacy_restriction->default_resn_id ?>" name="delete[]" type="checkbox" value="<?= $privacy_restriction->default_resn_id ?>">
258                            <?= I18N::translate('Delete') ?>
259                        </label>
260                    </td>
261                </tr>
262            <?php endforeach ?>
263        </tbody>
264    </table>
265
266    <div class="row form-group">
267        <div class="offset-sm-4 col-sm-8">
268            <button type="submit" class="btn btn-primary">
269                <?= view('icons/save') ?>
270                <?= I18N::translate('save') ?>
271            </button>
272
273            <a class="btn btn-secondary" href="<?= route('manage-trees', ['tree' => $tree->name()]) ?>">
274                <?= view('icons/cancel') ?>
275                <?= I18N::translate('cancel') ?>
276            </a>
277            <!-- Coming soon
278            <div class="form-check">
279                <?php if ($count_trees > 1) : ?>
280                <label>
281                    <input type="checkbox" name="all_trees">
282                    <?= /* I18N: Label for checkbox */ I18N::translate('Apply these preferences to all family trees') ?>
283                </label>
284                <?php endif ?>
285            </div>
286            <div class="form-check">
287                <label>
288                    <input type="checkbox" name="new_trees">
289                    <?= /* I18N: Label for checkbox */ I18N::translate('Apply these preferences to new family trees') ?>
290                </label>
291            </div>
292        </div>
293        -->
294        </div>
295
296</form>
297
298<?php View::push('javascript') ?>
299<script>
300    "use strict";
301
302    /**
303     * Hide/show the feedback labels for a privacy option.
304     *
305     * @param sel    the control to change
306     * @param who    "visitors", "members" or "managers"
307     * @param access true or false
308     */
309    function setPrivacyFeedback(sel, who, access) {
310        var formGroup = $(sel).closest(".form-group");
311
312        if (access) {
313            $("." + who, formGroup).addClass("badge-success").removeClass("badge-secondary");
314            $("." + who + " i", formGroup).addClass("fa-check").removeClass("fa-times");
315        } else {
316            $("." + who, formGroup).addClass("badge-secondary").removeClass("badge-success");
317            $("." + who + " i", formGroup).addClass("fa-times").removeClass("fa-check");
318        }
319    }
320
321    /**
322     * Update all the privacy feedback labels.
323     */
324    function updatePrivacyFeedback() {
325        var requireAuthentication    = parseInt($("[name=REQUIRE_AUTHENTICATION]").val(), 10);
326        var showDeadPeople           = parseInt($("[name=SHOW_DEAD_PEOPLE]").val(), 10);
327        var hideLivePeople           = parseInt($("[name=HIDE_LIVE_PEOPLE]").val(), 10);
328        var showLivingNames          = parseInt($("[name=SHOW_LIVING_NAMES]").val(), 10);
329        var showPrivateRelationships = parseInt($("[name=SHOW_PRIVATE_RELATIONSHIPS]").val(), 10);
330
331        setPrivacyFeedback("[name=REQUIRE_AUTHENTICATION]", "visitors", requireAuthentication === 0);
332        setPrivacyFeedback("[name=REQUIRE_AUTHENTICATION]", "members", true);
333
334        setPrivacyFeedback("[name=SHOW_DEAD_PEOPLE]", "visitors", requireAuthentication === 0 && (showDeadPeople >= 2 || hideLivePeople === 0));
335        setPrivacyFeedback("[name=SHOW_DEAD_PEOPLE]", "members", showDeadPeople >= 1 || hideLivePeople === 0);
336
337        setPrivacyFeedback("[name=HIDE_LIVE_PEOPLE]", "visitors", requireAuthentication === 0 && hideLivePeople === 0);
338        setPrivacyFeedback("[name=HIDE_LIVE_PEOPLE]", "members", true);
339
340        setPrivacyFeedback("[name=SHOW_LIVING_NAMES]", "visitors", requireAuthentication === 0 && showLivingNames >= 2);
341        setPrivacyFeedback("[name=SHOW_LIVING_NAMES]", "members", showLivingNames >= 1);
342        setPrivacyFeedback("[name=SHOW_LIVING_NAMES]", "managers", showLivingNames >= 0);
343
344        setPrivacyFeedback("[name=SHOW_PRIVATE_RELATIONSHIPS]", "visitors", requireAuthentication === 0 && showPrivateRelationships >= 1);
345        setPrivacyFeedback("[name=SHOW_PRIVATE_RELATIONSHIPS]", "members", showPrivateRelationships >= 1);
346    }
347
348    // Activate the privacy feedback labels.
349    updatePrivacyFeedback();
350    $("[name=REQUIRE_AUTHENTICATION], [name=HIDE_LIVE_PEOPLE], [name=SHOW_DEAD_PEOPLE], [name=SHOW_LIVING_NAMES], [name=SHOW_PRIVATE_RELATIONSHIPS]").on("change", function () {
351        updatePrivacyFeedback();
352    });
353
354    // Mute a line when it is marked for deletion
355    $("#default-resn").on("click", "input[type=checkbox]", function () {
356        if ($(this).prop("checked")) {
357            $($(this).closest("tr").addClass("text-muted"));
358        } else {
359            $($(this).closest("tr").removeClass("text-muted"));
360        }
361    });
362
363    // Add a new row to the table
364    $("#add-resn").on("click", function () {
365        $("#default-resn tbody").prepend($("#new-resn-template").html());
366
367        // Select2 - same as webtrees.js
368        $("select.select2").select2({
369            escapeMarkup: function (x) {
370                return x;
371            },
372        })
373        .on("select2:unselect", function (evt) {
374            $(evt.delegateTarget).append("<option value=\"\" selected=\"selected\"></option>");
375        });
376
377        // Record type selector
378        $(".record-type-selector").change(function () {
379            $(".select-record", $(this).parent()).addClass('d-none');
380            $(".select-record select", $(this).parent()).prop( "disabled", true);
381            $(".select-" + $(this).val(), $(this).parent()).removeClass('d-none');
382            $(".select-" + $(this).val() + " select", $(this).parent()).prop( "disabled", false);
383        });
384    });
385</script>
386<?php View::endpush() ?>
387