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