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