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