1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
<?php
/**
* UI for online updating of the config file.
*
* webtrees: Web based Family History software
* Copyright (C) 2010 webtrees development team.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @version $Id$
*/
define('WT_SCRIPT_NAME', 'editgedcoms.php');
require './includes/session.php';
// The gedcom admin page is for gedcom administrators only!
if (!WT_USER_GEDCOM_ADMIN) {
header('Location: login.php?url=editgedcoms.php');
exit;
}
// Which directory contains our data files?
$INDEX_DIRECTORY=get_site_setting('INDEX_DIRECTORY');
function import_gedcom_file($gedcom_id, $file_name) {
$file_size=filesize($file_name);
$fp=fopen($file_name, 'rb');
WT_DB::exec("START TRANSACTION");
// Cannot use the stream technique at http://php.net/manual/en/pdo.lobs.php
// It doesn't work, probably due to the MySQL bug mentioned below.
//WT_DB::prepare(
// "UPDATE `##gedcom`".
// " SET import_gedcom=?, import_offset=1".
// " WHERE gedcom_id=?"
//)
//->bindParam(1, $fp, PDO::PARAM_LOB)
//->bindParam(2, $gedcom_id, PDO::PARAM_INT)
//->execute();
$max_allowed_packet=WT_DB::prepare("SELECT @@max_allowed_packet")->fetchOne();
WT_DB::prepare(
"UPDATE `##gedcom`".
" SET import_gedcom='', import_offset=1".
" WHERE gedcom_id=?"
)->execute(array($gedcom_id));
// The max_allowed_packet setting in MySQL puts a limit on the size of SQL
// statements that can be received over the network. Due to a bug, it also
// limits the size of blobs that can be processed on the server.
// Setting this value has no effect on upload limits (so we must still
// upload data in chunks smaller than this), but it will allow us to use
// CONCAT(import_gedcom, ?)
// See http://bugs.mysql.com/bug.php?id=22853 (Scheduled to be fixed in MySQL 6)
try {
WT_DB::exec("SET @@max_allowed_packet=".max($file_size*2, $max_allowed_packet));
} catch (PDOException $ex) {
// We can only set this on MySQL 5.1.30 or earlier
}
while (!feof($fp)) {
$data=fread($fp, $max_allowed_packet * 0.75);
WT_DB::prepare(
"UPDATE `##gedcom`".
" SET import_gedcom=CONCAT(import_gedcom, ?)".
" WHERE gedcom_id=?"
)->execute(array($data, $gedcom_id));
}
WT_DB::exec("COMMIT");
fclose($fp);
}
// Process GET actions
switch (safe_GET('action')) {
case 'delete':
$ged=safe_GET('ged');
delete_gedcom(get_id_from_gedcom($ged));
break;
}
// Process POST actions
switch (safe_POST('action')) {
case 'setdefault':
set_site_setting('DEFAULT_GEDCOM', safe_POST('default_ged'));
break;
case 'add_ged':
$ged_name=basename(safe_POST('ged_name'));
$gedcom_id=get_id_from_gedcom($ged_name);
// check it doesn't already exist before we create it
if (!$gedcom_id && file_exists($INDEX_DIRECTORY.$ged_name)) {
$gedcom_id=get_id_from_gedcom($ged_name, true);
import_gedcom_file($gedcom_id, $INDEX_DIRECTORY.$ged_name);
}
header('Location: editgedcoms.php');exit;
break;
case 'new_ged':
$ged_name=basename(safe_POST('ged_name'));
$gedcom_id=get_id_from_gedcom($ged_name);
// check it doesn't already exist before we create it
if (!$gedcom_id) {
$gedcom_id=get_id_from_gedcom($ged_name, true);
// I18N: This should be a common/default/placeholder name of a person. Put slashes around the surname.
$john_doe=i18n::translate('John /DOE/');
$note=i18n::translate('Edit this individual and replace their details with your own');
WT_DB::prepare(
"UPDATE `##gedcom`".
" SET import_gedcom=?, import_offset=1".
" WHERE gedcom_id=?"
)->execute(array("0 HEAD\n0 @I1@ INDI\n1 NAME {$john_doe}\n1 SEX M\n1 BIRT\n2 DATE 1 JAN 1850\n2 NOTE {$note}\n0 TRLR\n", $gedcom_id));
}
break;
case 'upload_ged':
foreach ($_FILES as $FILE) {
if ($FILE['error']==0 && is_readable($FILE['tmp_name'])) {
$ged_name=$FILE['name'];
$gedcom_id=get_id_from_gedcom($ged_name);
// check it doesn't already exist before we create it
if (!$gedcom_id) {
$gedcom_id=get_id_from_gedcom($ged_name, true);
import_gedcom_file($gedcom_id, $FILE['tmp_name']);
}
}
}
header('Location: editgedcoms.php');exit;
break;
case 'replace_upload':
$gedcom_id=safe_POST('gedcom_id');
// Make sure the gedcom still exists
if (get_gedcom_from_id($gedcom_id)) {
foreach ($_FILES as $FILE) {
if ($FILE['error']==0 && is_readable($FILE['tmp_name'])) {
import_gedcom_file($gedcom_id, $FILE['tmp_name']);
}
}
}
header('Location: editgedcoms.php');exit;
break;
case 'replace_import':
$gedcom_id=safe_POST('gedcom_id');
// Make sure the gedcom still exists
if (get_gedcom_from_id($gedcom_id)) {
$ged_name=basename(safe_POST('ged_name'));
import_gedcom_file($gedcom_id, $INDEX_DIRECTORY.$ged_name);
}
header('Location: editgedcoms.php');exit;
break;
}
$gedcoms=WT_DB::prepare(
"SELECT gedcom_id, gedcom_name, import_offset".
" FROM `##gedcom`".
" ORDER BY gedcom_name"
)->fetchAll();
$all_gedcoms=array();
foreach ($gedcoms as $gedcom) {
$all_gedcoms[$gedcom->gedcom_id]=$gedcom->gedcom_name;
}
print_header(i18n::translate('GEDCOM administration'));
echo '<p class="center"><input TYPE="button" VALUE="', i18n::translate('Return to Administration page'), '" onclick="javascript:window.location=\'admin.php\'" /></p>';
echo '<h2 class="center">', i18n::translate('GEDCOM administration'), '</h2>';
// Process GET actions
switch (safe_GET('action')) {
case 'uploadform':
case 'importform':
$gedcom_id=safe_GET('gedcom_id');
$gedcom_name=get_gedcom_from_id($gedcom_id);
// Check it exists
if (!$gedcom_name) {
break;
}
echo '<p>', i18n::translate('This will delete all the genealogical data from <b>%s</b> and replace it with data from another GEDCOM.', $gedcom_name), '</p>';
echo '<form name="replaceform" method="post" enctype="multipart/form-data" action="', WT_SCRIPT_NAME, '" onsubmit="if (document.replaceform.ged_name.value!=\'', htmlspecialchars($gedcom_name), '\') return confirm(\'', htmlspecialchars(i18n::translate('You have selected a GEDCOM with a different name. Is this correct?')), '\'); else return true;">';
echo '<input type="hidden" name="gedcom_id" value="', $gedcom_id, '" />';
if (safe_GET('action')=='uploadform') {
echo '<input type="hidden" name="action" value="replace_upload" />';
echo '<input type="file" name="ged_name" />';
} else {
echo '<input type="hidden" name="action" value="replace_import" />';
$d=opendir($INDEX_DIRECTORY);
$files=array();
while (($f=readdir($d))!==false) {
if (!is_dir($INDEX_DIRECTORY.$f) && is_readable($INDEX_DIRECTORY.$f)) {
$fp=fopen($INDEX_DIRECTORY.$f, 'rb');
$header=fread($fp, 64);
fclose($fp);
if (preg_match('/^('.WT_UTF8_BOM.')?0 *HEAD/', $header)) {
$files[]=$f;
}
}
}
if ($files) {
echo $INDEX_DIRECTORY, '<select name="ged_name" />';
foreach ($files as $file) {
echo '<option value="', htmlspecialchars($file), '"';
if ($file==$gedcom_name) {
echo ' selected="selected"';
}
echo'>', htmlspecialchars($file), '</option>';
}
echo '</select>';
} else {
echo '<p>', i18n::translate('No GEDCOM files found. You need to copy files to the <b>%s</b> directory on your server.', $INDEX_DIRECTORY);
echo '</form>';
echo '<br /><br />';
echo '<form name="cancel" method="get" action="', WT_SCRIPT_NAME, '"><input type="submit" value="', i18n::translate('Cancel'), '" /></form>';
print_footer();
exit;
}
}
echo '<br /><br /><input type="checkbox" name="keep_media', $gedcom_id, '" value="1">';
echo i18n::translate('If you have created media objects in webtrees, and have edited your gedcom off-line using a program that deletes media objects, then check this box to merge the current media objects with the new GEDCOM.');
echo '<br /><br /><input type="submit" value="', i18n::translate('Save'), '" /></form>';
echo '</form>';
echo '<form name="cancel" method="get" action="', WT_SCRIPT_NAME, '"><input type="submit" value="', i18n::translate('Cancel'), '" /></form>';
print_footer();
exit;
}
// List the gedcoms available to this user
foreach ($gedcoms as $gedcom) {
if (userGedcomAdmin(WT_USER_ID, $gedcom->gedcom_id)) {
echo
'<table class="gedcom_table" width="100%">',
'<tr><td class="list_label" width="20%">', i18n::translate('GEDCOM name'),
'</td><td class="list_value"><a href="index.php?ctype=gedcom&ged=', urlencode($gedcom->gedcom_name), '">', htmlspecialchars($gedcom->gedcom_name), ' - ',
htmlspecialchars(get_gedcom_setting($gedcom->gedcom_id, 'title')), '</a>',
'</td></tr><tr><td class="list_label">', i18n::translate('GEDCOM administration'),
'</td><td class="list_value">';
// The third row shows an optional progress bar and a list of maintenance options
if ($gedcom->import_offset>0) {
echo
'<div id="import', $gedcom->gedcom_id, '"></div>',
WT_JS_START,
'$("#import', $gedcom->gedcom_id, '").load("import.php?gedcom_id=', $gedcom->gedcom_id, '&keep_media=', safe_POST('keep_media'.$gedcom->gedcom_id), '");',
WT_JS_END,
'<table border="0" width="100%" id="actions', $gedcom->gedcom_id, '" style="display:none">';
} else {
echo '<table border="0" width="100%" id="actions', $gedcom->gedcom_id, '">';
}
echo
'<tr align="center">',
// configuration
'<td><a href="editconfig_gedcom.php?ged=', urlencode($gedcom->gedcom_name), '">', i18n::translate('Configuration'), '</a>',
help_link('gedcom_configfile'),
'</td>',
// export
'<td><a href="javascript:" onclick="window.open(\'', encode_url("export_gedcom.php?export={$gedcom->gedcom_name}"), '\', \'_blank\',\'left=50,top=50,width=500,height=500,resizable=1,scrollbars=1\');">', i18n::translate('Export'), '</a>',
help_link('export_gedcom'),
'</td>',
// import
'<td><a href="', WT_SCRIPT_NAME, '?action=importform&gedcom_id=', $gedcom->gedcom_id, '">', i18n::translate('Import'), '</a>',
help_link('import_gedcom'),
'</td>',
// download
'<td><a href="downloadgedcom.php?ged=', urlencode($gedcom->gedcom_name),'">', i18n::translate('Download'), '</a>',
help_link('download_gedcom'),
'</td>',
// upload
'<td><a href="', WT_SCRIPT_NAME, '?action=uploadform&gedcom_id=', $gedcom->gedcom_id, '">', i18n::translate('Upload'), '</a>',
help_link('upload_gedcom'),
'</td>',
// delete
'<td><a href="editgedcoms.php?action=delete&ged=', urlencode($gedcom->gedcom_name), '" onclick="return confirm(\''.htmlspecialchars(i18n::translate('Permanently delete the GEDCOM %s and all its settings?', $gedcom->gedcom_name)),'\');">', i18n::translate('Delete'), '</a>',
help_link('delete_gedcom'),
'</td></tr></table></td></tr></table><br />';
}
}
// Options for creating new gedcoms and setting defaults
if (WT_USER_IS_ADMIN) {
echo
'<br/><table class="gedcom_table"><tr>',
'<td class="list_label">', i18n::translate('Default GEDCOM'), help_link('default_gedcom'), '</td>',
'<td class="list_label">', i18n::translate('Add a new GEDCOM'), help_link('add_gedcom'), '</td>',
'<td class="list_label">', i18n::translate('Upload a new GEDCOM'), help_link('upload_gedcom'), '</td>',
'<td class="list_label">', i18n::translate('Create a new GEDCOM'), help_link('add_new_gedcom'), '</td>',
'</tr><tr>',
'<td class="list_value_wrap">',
'<form name="defaultform" method="post" action="', WT_SCRIPT_NAME, '">',
'<input type="hidden" name="action" value="setdefault" />',
'<select name="default_ged" class="header_select" onchange="document.defaultform.submit();">';
$DEFAULT_GEDCOM=get_site_setting('DEFAULT_GEDCOM');
if (empty($DEFAULT_GEDCOM)) {
echo '<option value="" selected="selected"></option>';
}
foreach ($gedcoms as $gedcom) {
echo '<option value="', urlencode($gedcom->gedcom_name), '"';
if ($DEFAULT_GEDCOM==$gedcom->gedcom_name) echo ' selected="selected"';
echo '>', htmlspecialchars($gedcom->gedcom_name), '</option>';
}
echo
'</select>',
'</form></td>',
'<td class="list_value_wrap">',
'<form name="addform" method="post" action="', WT_SCRIPT_NAME, '">',
$INDEX_DIRECTORY,
'<input type="hidden" name="action" value="add_ged" />',
'<select name="ged_name" onchange="document.addform.submit();" />',
'<option>', i18n::translate('Select a file'), '</option>',
$d=opendir($INDEX_DIRECTORY);
$files=false;
while (($f=readdir($d))!==false) {
if (!in_array($f, $all_gedcoms) && !is_dir($INDEX_DIRECTORY.$f) && is_readable($INDEX_DIRECTORY.$f)) {
$fp=fopen($INDEX_DIRECTORY.$f, 'rb');
$header=fread($fp, 64);
fclose($fp);
if (preg_match('/^('.WT_UTF8_BOM.')?0 *HEAD/', $header)) {
echo '<option>', htmlspecialchars($f), '</option>';
$files=true;
}
}
}
echo
'</select>',
'</form>',
'</td>',
'<td class="list_value_wrap">',
'<form name="uploadform" method="post" action="', WT_SCRIPT_NAME, '" enctype="multipart/form-data">',
'<input type="hidden" name="action" value="upload_ged" />',
'<input type="file" name="ged_name" onchange="document.uploadform.submit();" />',
'</form>',
'</td>',
'<td class="list_value_wrap">',
'<form name="createform" method="post" action="', WT_SCRIPT_NAME, '">',
'<input type="hidden" name="action" value="new_ged" />',
'<input name="ged_name" />',
' <input type="submit" value="', i18n::translate('Save') , '"/>',
'</form>',
'</td>',
'</tr></table><br/>';
// display link to PGV-WT transfer wizard on first visit to this page, before any GEDCOM is loaded
if (count($gedcoms)==0 && get_user_count()==1) {
echo
'<div class="center">',
'<a style="color:green; font-weight:bold;" href="pgv_to_wt.php">',
i18n::translate('Click here for PhpGedView to <b>webtrees</b> transfer wizard'),
'</a>',
help_link('PGV_WIZARD'),
'</div>';
}
}
print_footer();
|