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