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