xref: /webtrees/resources/views/admin/trees-import.phtml (revision fcfa147e10aaa6c7ff580c29bd6e5b88666befc1)
1<?php
2
3use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
4use Fisharebest\Webtrees\I18N;
5use Fisharebest\Webtrees\View;
6
7?>
8<?php ?>
9
10<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route('manage-trees') => I18N::translate('Manage family trees'), $title]]) ?>
11
12<h1><?= $title ?></h1>
13
14<div class="alert alert-warning">
15    <?= /* I18N: %s is the name of a family tree */ I18N::translate('This will delete all the genealogy data from “%s” and replace it with data from a GEDCOM file.', e($tree->title())) ?>
16</div>
17
18<form method="post" action="<?= e(route('admin-trees-import-action', ['tree' => $tree->name()])) ?>" class="form form-horizontal" enctype="multipart/form-data" onsubmit="return checkGedcomImportForm('<?= e(I18N::translate('You have selected a GEDCOM file with a different name. Is this correct?')) ?>');">
19    <input type="hidden" id="gedcom_filename" value="<?= e($default_gedcom_file) ?>">
20    <?= csrf_field() ?>
21
22    <fieldset class="form-group">
23        <div class="row">
24            <legend class="col-form-label col-sm-3">
25                <?= I18N::translate('Select a GEDCOM file to import') ?>
26            </legend>
27            <div class="col-sm-9">
28                <div class="row form-group">
29                    <label class="col-sm-3">
30                        <input type="radio" name="source" id="import-computer" value="client" checked>
31                        <?= I18N::translate('A file on your computer') ?>
32                    </label>
33                    <div class="col-sm-9">
34                        <div class="btn btn-default">
35                            <input type="file" class="form-control-file" name="tree_name" id="import-computer-file">
36                        </div>
37                    </div>
38                </div>
39                <div class="row">
40                    <label class="col-sm-3">
41                        <input type="radio" name="source" id="import-server" value="server">
42                        <?= I18N::translate('A file on the server') ?>
43                    </label>
44                    <div class="col-sm-9">
45                        <div class="input-group" dir="ltr">
46                            <div class="input-group-prepend">
47                                <span class="input-group-text" dir="ltr">
48                                <?= e($data_folder) ?>
49                                </span>
50                            </div>
51                            <select name="tree_name" class="form-control" dir="ltr" id="import-server-file">
52                                <option value=""></option>
53                                <?php foreach ($gedcom_files as $gedcom_file) : ?>
54                                    <option value="<?= e($gedcom_file) ?>" <?= $gedcom_file === $default_gedcom_file ? 'selected' : '' ?>>
55                                        <?= e($gedcom_file) ?>
56                                    </option>
57                                <?php endforeach ?>
58                                <?php if (empty($gedcom_files)) : ?>
59                                    <option disabled selected>
60                                        <?= I18N::translate('No GEDCOM files found.') ?>
61                                    </option>
62                                <?php endif ?>
63                            </select>
64                        </div>
65                    </div>
66                </div>
67            </div>
68        </div>
69    </fieldset>
70
71    <hr>
72
73    <fieldset class="form-group">
74        <div class="row">
75            <legend class="col-form-label col-sm-3">
76                <?= I18N::translate('Import preferences') ?>
77            </legend>
78            <div class="col-sm-9">
79                <label>
80                    <input type="checkbox" name="keep_media" value="1" <?= $tree->getPreference('keep_media') ? 'checked' : '' ?>>
81                    <?= /* I18N: A configuration setting */ I18N::translate('Keep media objects') ?>
82                </label>
83                <p class="small text-muted">
84                    <?= I18N::translate('If you have created media objects in webtrees, and have subsequently edited this GEDCOM file using genealogy software that deletes media objects, then select this option to merge the current media objects with the new GEDCOM file.') ?>
85                </p>
86                <label>
87                    <input type="checkbox" name="WORD_WRAPPED_NOTES" value="1" <?= $tree->getPreference('WORD_WRAPPED_NOTES') ? 'checked' : '' ?>>
88                    <?= I18N::translate('Add spaces where long lines were wrapped') ?>
89                </label>
90                <p class="small text-muted">
91                    <?= I18N::translate('If you created this GEDCOM file using genealogy software that omits spaces when splitting long lines, then select this option to reinsert the missing spaces.') ?>
92                </p>
93                <label for="GEDCOM_MEDIA_PATH">
94                    <?= /* I18N: A media path (e.g. c:\aaa\bbb\ccc\ddd.jpeg) in a GEDCOM file */ I18N::translate('Remove the GEDCOM media path from filenames') ?>
95                </label>
96                <input
97                    class="form-control"
98                    dir="ltr"
99                    id="GEDCOM_MEDIA_PATH"
100                    maxlength="255"
101                    name="GEDCOM_MEDIA_PATH"
102                    type="text"
103                    value="<?= e($gedcom_media_path) ?>"
104                >
105                <p class="small text-muted">
106                    <?= /* I18N: Help text for the “GEDCOM media path” configuration setting. A “path” is something like “C:\Documents\Genealogy\Photos\John_Smith.jpeg” */ I18N::translate('Some genealogy software creates GEDCOM files that contain media filenames with full paths. These paths will not exist on the web-server. To allow webtrees to find the file, the first part of the path must be removed.') ?>
107                    <?= /* I18N: Help text for the “GEDCOM media path” configuration setting. %s are all folder names */ I18N::translate('For example, if the GEDCOM file contains %1$s and webtrees expects to find %2$s in the media folder, then you would need to remove %3$s.', '<code>C:\\Documents\\family\\photo.jpeg</code>', '<code>family\\photo.jpeg</code>', '<code>C:\\Documents\\</code>') ?>
108                </p>
109            </div>
110        </div>
111    </fieldset>
112
113    <div class="row form-group">
114        <div class="offset-sm-3 col-sm-9">
115            <button type="submit" class="btn btn-primary">
116                <?= /* I18N: A button label. */ I18N::translate('continue') ?>
117            </button>
118        </div>
119    </div>
120</form>
121
122<?php View::push('javascript') ?>
123<script>
124  function checkGedcomImportForm (message) {
125    var oldFile = $('#gedcom_filename').val();
126    var method = $('input[name=source]:checked').val();
127    var newFile = method === 'server' ? $('#import-server-file').val() : $('#import-computer-file').val();
128
129    // Some browsers include c:\fakepath\ in the filename.
130    newFile = newFile.replace(/.*[/\\]/, '');
131    if (newFile !== oldFile && oldFile !== '') {
132      return window.confirm(message);
133    } else {
134      return true;
135    }
136  }
137
138  document.getElementById("import-computer-file").addEventListener("click", function () {
139    document.getElementById("import-computer").checked = true;
140  });
141
142  document.getElementById("import-server-file").addEventListener("focus", function () {
143    document.getElementById("import-server").checked = true;
144  });
145</script>
146<?php View::endpush() ?>
147