xref: /webtrees/resources/views/admin/trees-import.phtml (revision 78606cf427772fbdc5222ff607ee23f43078f94b)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
6use Fisharebest\Webtrees\Http\RequestHandlers\ImportGedcomAction;
7use Fisharebest\Webtrees\Http\RequestHandlers\ManageTrees;
8use Fisharebest\Webtrees\I18N;
9use Fisharebest\Webtrees\Registry;
10use Fisharebest\Webtrees\Tree;
11use Fisharebest\Webtrees\View;
12use Illuminate\Support\Collection;
13
14/**
15 * @var string                 $data_folder
16 * @var string                 $default_gedcom_file
17 * @var Collection<int,string> $gedcom_files
18 * @var string                 $gedcom_media_path
19 * @var string                 $title
20 * @var Tree                   $tree
21 */
22
23?>
24
25<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(ManageTrees::class, ['tree' => $tree->name()]) => I18N::translate('Manage family trees'), $title]]) ?>
26
27<h1><?= $title ?></h1>
28
29<div class="alert alert-warning">
30    <?= /* 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())) ?>
31</div>
32
33<form method="post" action="<?= e(route(ImportGedcomAction::class, ['tree' => $tree->name()])) ?>" enctype="multipart/form-data" onsubmit="return checkGedcomImportForm('<?= e(I18N::translate('You have selected a GEDCOM file with a different name. Is this correct?')) ?>');">
34    <input type="hidden" id="gedcom_filename" value="<?= e($default_gedcom_file) ?>">
35
36    <h2><?= I18N::translate('Select a GEDCOM file to import') ?></h2>
37
38    <div class="row mb-3">
39        <label class="col-form-label col-sm-4">
40            <input type="radio" name="source" id="import-client" value="client" checked>
41            <?= I18N::translate('A file on your computer') ?>
42        </label>
43        <div class="col-sm-8">
44            <input id="import-client-file" type="file" name="client_file" class="form-control">
45        </div>
46    </div>
47
48    <div class="row mb-3">
49        <label class="col-form-label col-sm-4">
50            <input type="radio" name="source" id="import-server" value="server">
51            <?= I18N::translate('A file on the server') ?>
52        </label>
53        <div class="col-sm-8">
54            <div class="input-group" dir="ltr">
55                <span class="input-group-text" dir="ltr">
56                    <?= e($data_folder) ?>
57                </span>
58
59                <select name="server_file" class="form-select" dir="ltr" id="import-server-file">
60                    <option selected="selected" value="">&nbsp;</option>
61                    <?php foreach ($gedcom_files as $gedcom_file) : ?>
62                        <option value="<?= e($gedcom_file) ?>" <?= $gedcom_file === $default_gedcom_file ? 'selected' : '' ?>>
63                            <?= e($gedcom_file) ?>
64                        </option>
65                    <?php endforeach ?>
66                    <?php if ($gedcom_files->isEmpty()) : ?>
67                        <option disabled selected>
68                            <?= I18N::translate('No GEDCOM files found.') ?>
69                        </option>
70                    <?php endif ?>
71                </select>
72            </div>
73        </div>
74    </div>
75
76    <hr>
77
78    <h2><?= I18N::translate('Import preferences') ?></h2>
79
80    <div class="row mb-3">
81        <label for="encoding" class="col-sm-3">
82            <?= I18N::translate('Character encoding') ?>
83        </label>
84
85        <div class="col-sm-9">
86            <?= view('components/select', ['name' => 'encoding', 'selected' => '', 'options' => ['' => I18N::translate('automatic')] + Registry::encodingFactory()->list()]) ?>
87        </div>
88    </div>
89
90    <div class="row mb-3">
91        <div class="col-sm-3">
92            <?= /* I18N: A configuration setting */ I18N::translate('Keep media objects') ?>
93        </div>
94
95        <div class="col-sm-9">
96            <div class="form-check">
97                <input type="checkbox" class="form-check-input" name="keep_media" id="keep_media" value="1" <?= $tree->getPreference('keep_media') ? 'checked' : '' ?>>
98                <label for="keep_media" class="form-check-label">
99                    <?= 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.') ?>
100                </label>
101            </div>
102        </div>
103    </div>
104
105    <div class="row mb-3">
106        <div class="col-sm-3">
107            <?= I18N::translate('Add spaces where long lines were wrapped') ?>
108        </div>
109
110        <div class="col-sm-9">
111            <div class="form-check">
112                <input type="checkbox" class="form-check-input" name="WORD_WRAPPED_NOTES" id="WORD_WRAPPED_NOTES" value="1" <?= $tree->getPreference('WORD_WRAPPED_NOTES') ? 'checked' : '' ?>>
113                <label for="WORD_WRAPPED_NOTES" class="form-check-label">
114                    <?= 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.') ?>
115                </label>
116            </div>
117        </div>
118    </div>
119
120    <div class="row mb-3">
121        <label for="GEDCOM_MEDIA_PATH" class="col-sm-3">
122            <?= /* 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') ?>
123        </label>
124
125        <div class="col-sm-9">
126            <input class="form-control" dir="ltr" id="GEDCOM_MEDIA_PATH" maxlength="255" name="GEDCOM_MEDIA_PATH" type="text" value="<?= e($gedcom_media_path) ?>">
127            <div class="form-text">
128                <?= /* 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.') ?>
129                <?= /* 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>') ?>
130            </div>
131        </div>
132    </div>
133
134    <hr>
135
136    <button type="submit" class="btn btn-primary">
137        <?= /* I18N: A button label. */ I18N::translate('continue') ?>
138    </button>
139
140    <?= csrf_field() ?>
141</form>
142
143<?php View::push('javascript') ?>
144<script>
145  function checkGedcomImportForm (message) {
146    let oldFile = $('#gedcom_filename').val();
147    let method = $('input[name=source]:checked').val();
148    let newFile = method === 'server' ? $('#import-server-file').val() : $('#import-client-file').val();
149
150    // Some browsers include c:\fakepath\ in the filename.
151    newFile = newFile.replace(/.*[/\\]/, '');
152    if (newFile !== oldFile && oldFile !== '') {
153      return window.confirm(message);
154    } else {
155      return true;
156    }
157  }
158
159  document.getElementById('import-client-file').addEventListener('focus', function () {
160    document.getElementById('import-client').checked = true;
161  });
162
163  document.getElementById('import-server-file').addEventListener('focus', function () {
164    document.getElementById('import-server').checked = true;
165  });
166</script>
167<?php View::endpush() ?>
168