summaryrefslogtreecommitdiff
path: root/admin_trees_manage.php
blob: b134796e6284078fc86c3129dd55a305dfca14a1 (plain)
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
<?php
// UI for online updating of the GEDCOM configuration.
//
// webtrees: Web based Family History software
// Copyright (C) 2015 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

use WT\Auth;
use WT\Theme;
use WT\User;

define('WT_SCRIPT_NAME', 'admin_trees_manage.php');
require './includes/session.php';

$controller = new WT_Controller_Page;
$controller->restrictAccess(Auth::isManager());

switch (WT_Filter::get('action')) {
case 'uploadform':
	$controller->setPageTitle(WT_I18N::translate('Upload family tree'));
	break;
case 'importform':
	$controller->setPageTitle(WT_I18N::translate('Import family tree'));
	break;
default:
	$controller->setPageTitle(WT_I18N::translate('Manage family trees'));
	break;
}

// Don’t allow the user to cancel the request.  We do not want to be left
// with an incomplete transaction.
ignore_user_abort(true);

/**
 * @param integer $gedcom_id
 * @param string  $path      the full path to the (possibly temporary) file.
 * @param string  $filename  the actual filename (no folder).
 *
 * @throws Exception
 */
function import_gedcom_file($gedcom_id, $path, $filename) {
	// Read the file in blocks of roughly 64K.  Ensure that each block
	// contains complete gedcom records.  This will ensure we don’t split
	// multi-byte characters, as well as simplifying the code to import
	// each block.

	$file_data = '';
	$fp = fopen($path, 'rb');

	WT_DB::beginTransaction();
	WT_DB::prepare("DELETE FROM `##gedcom_chunk` WHERE gedcom_id=?")->execute(array($gedcom_id));

	while (!feof($fp)) {
		$file_data .= fread($fp, 65536);
		// There is no strrpos() function that searches for substrings :-(
		for ($pos = strlen($file_data) - 1; $pos > 0; --$pos) {
			if ($file_data[$pos] == '0' && ($file_data[$pos - 1] == "\n" || $file_data[$pos - 1] == "\r")) {
				// We’ve found the last record boundary in this chunk of data
				break;
			}
		}
		if ($pos) {
			WT_DB::prepare(
				"INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)"
			)->execute(array($gedcom_id, substr($file_data, 0, $pos)));
			$file_data = substr($file_data, $pos);
		}
	}
	WT_DB::prepare(
		"INSERT INTO `##gedcom_chunk` (gedcom_id, chunk_data) VALUES (?, ?)"
	)->execute(array($gedcom_id, $file_data));

	WT_Tree::get($gedcom_id)->setPreference('gedcom_filename', $filename);
	WT_DB::commit();
	fclose($fp);
}

// Process POST actions
switch (WT_Filter::post('action')) {
case 'delete':
	$gedcom_id = WT_Filter::postInteger('gedcom_id');
	if (WT_Filter::checkCsrf() && $gedcom_id) {
		WT_Tree::get($gedcom_id)->delete();
	}
	header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME);

	return;
case 'setdefault':
	if (WT_Filter::checkCsrf()) {
		WT_Site::setPreference('DEFAULT_GEDCOM', WT_Filter::post('ged'));
	}
	header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME);

	return;
case 'new_tree':
	$tree_name  = basename(WT_Filter::post('tree_name'));
	$tree_title = WT_Filter::post('tree_title');

	if (WT_Filter::checkCsrf() && $tree_name && $tree_title) {
		WT_Tree::create($tree_name, $tree_title);
	}
	header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?ged=' . $tree_name);

	return;
case 'replace_upload':
	$gedcom_id = WT_Filter::postInteger('gedcom_id');
	// Make sure the gedcom still exists
	if (WT_Filter::checkCsrf() && WT_Tree::get($gedcom_id)) {
		foreach ($_FILES as $FILE) {
			if ($FILE['error'] == 0 && is_readable($FILE['tmp_name'])) {
				import_gedcom_file($gedcom_id, $FILE['tmp_name'], $FILE['name']);
			}
		}
	}

	header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?keep_media' . $gedcom_id . '=' . WT_Filter::postBool('keep_media' . $gedcom_id));

	return;
case 'replace_import':
	$gedcom_id = WT_Filter::postInteger('gedcom_id');
	// Make sure the gedcom still exists
	if (WT_Filter::checkCsrf() && WT_Tree::get($gedcom_id)) {
		$tree_name = basename(WT_Filter::post('tree_name'));
		import_gedcom_file($gedcom_id, WT_DATA_DIR . $tree_name, $tree_name);
	}

	header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?keep_media' . $gedcom_id . '=' . WT_Filter::postBool('keep_media' . $gedcom_id));

	return;
}

$default_tree_title  = WT_I18N::translate('My family tree');
$default_tree_name   = 'tree';
$default_tree_number = 1;
$existing_trees      = WT_Tree::getNameList();
while (array_key_exists($default_tree_name . $default_tree_number, $existing_trees)) {
	$default_tree_number++;
}
$default_tree_name .= $default_tree_number;

// Process GET actions
switch (WT_Filter::get('action')) {
case 'uploadform':
case 'importform':
	$controller->pageHeader();

	if (WT_Filter::get('action') === 'uploadform') {
		$controller->setPageTitle(WT_I18N::translate('Upload family tree'));
	} else {
		$controller->setPageTitle(WT_I18N::translate('Import family tree'));
	}

	?>
	<ol class="breadcrumb small">
		<li><a href="admin.php"><?php echo WT_I18N::translate('Control panel'); ?></a></li>
		<li><a href="admin_trees_manage.php"><?php echo WT_I18N::translate('Manage family trees'); ?></a></li>
		<li class="active"><?php echo $controller->getPageTitle(); ?></li>
	</ol>

	<h1><?php echo $controller->getPageTitle(); ?></h1>
	<?php

	$tree = WT_Tree::get(WT_Filter::getInteger('gedcom_id'));
	// Check it exists
	if (!$tree) {
		break;
	}
	echo '<p>', WT_I18N::translate('This will delete all the genealogical data from <b>%s</b> and replace it with data from another GEDCOM file.', $tree->tree_name_html), '</p>';
	// the javascript in the next line strips any path associated with the file before comparing it to the current GEDCOM name (both Chrome and IE8 include c:\fakepath\ in the filename).
	$previous_gedcom_filename = $tree->getPreference('gedcom_filename');
	echo '<form name="replaceform" method="post" enctype="multipart/form-data" action="', WT_SCRIPT_NAME, '" onsubmit="var newfile = document.replaceform.ged_name.value; newfile = newfile.substr(newfile.lastIndexOf(\'\\\\\')+1); if (newfile!=\'', WT_Filter::escapeHtml($previous_gedcom_filename), '\' && \'\' != \'', WT_Filter::escapeHtml($previous_gedcom_filename), '\') return confirm(\'', WT_Filter::escapeHtml(WT_I18N::translate('You have selected a GEDCOM file with a different name.  Is this correct?')), '\'); else return true;">';
	echo '<input type="hidden" name="gedcom_id" value="', $tree->tree_id, '">';
	echo WT_Filter::getCsrf();
	if (WT_Filter::get('action') == 'uploadform') {
		echo '<input type="hidden" name="action" value="replace_upload">';
		echo '<input type="file" name="tree_name">';
	} else {
		echo '<input type="hidden" name="action" value="replace_import">';
		$d = opendir(WT_DATA_DIR);
		$files = array();
		while (($f = readdir($d)) !== false) {
			if (!is_dir(WT_DATA_DIR . $f) && is_readable(WT_DATA_DIR . $f)) {
				$fp = fopen(WT_DATA_DIR . $f, 'rb');
				$header = fread($fp, 64);
				fclose($fp);
				if (preg_match('/^(' . WT_UTF8_BOM . ')?0 *HEAD/', $header)) {
					$files[] = $f;
				}
			}
		}
		if ($files) {
			sort($files);
			echo WT_DATA_DIR, '<select name="tree_name">';
			foreach ($files as $file) {
				echo '<option value="', WT_Filter::escapeHtml($file), '" ';
				if ($file == $previous_gedcom_filename) {
					echo '';
				}
				echo'>', WT_Filter::escapeHtml($file), '</option>';
			}
			echo '</select>';
		} else {
			echo '<p>', WT_I18N::translate('No GEDCOM files found.  You need to copy files to the <b>%s</b> directory on your server.', WT_DATA_DIR);
			echo '</form>';

			return;
		}
	}
	echo '<br><br><input type="checkbox" name="keep_media', $tree->tree_id, '" value="1">';
	echo WT_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 file.');
	echo '<br><br><input type="submit" value="', WT_I18N::translate('continue'), '">';
	echo '</form>';

	return;
}

if (!WT_Tree::getAll()) {
	echo Theme::theme()->htmlAlert(WT_I18N::translate('Before you can continue, you must create a family tree.'), 'info', true);
}

$controller->pageHeader();

// List the gedcoms available to this user
?>
<ol class="breadcrumb small">
	<li><a href="admin.php"><?php echo WT_I18N::translate('Control panel'); ?></a></li>
	<li class="active"><?php echo WT_I18N::translate('Manage family trees'); ?></li>
</ol>

<h1><?php echo $controller->getPageTitle(); ?></h1>

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
	<?php foreach (WT_Tree::GetAll() as $tree): ?>
	<?php if (Auth::isManager($tree)): ?>
	<div class="panel panel-default">
		<div class="panel-heading" role="tab" id="panel-tree-<?php echo $tree->tree_id; ?>">
			<h2 class="panel-title">
				<i class="fa fa-fw fa-tree"></i>
				<a data-toggle="collapse" data-parent="#accordion" href="#tree-<?php echo $tree->tree_id; ?>" aria-expanded="true" aria-controls="tree-<?php echo $tree->tree_id; ?>">
					<?php echo WT_Filter::escapeHtml($tree->tree_name); ?> — <?php echo WT_Filter::escapeHtml($tree->tree_title); ?>
				</a>
			</h2>
		</div>
		<div id="tree-<?php echo $tree->tree_id; ?>" class="panel-collapse collapse<?php echo $tree->tree_id === WT_GED_ID || $tree->getPreference('imported') === '0' ? ' in' : ''; ?>" role="tabpanel" aria-labelledby="panel-tree-<?php echo $tree->tree_id; ?>">
			<div class="panel-body">
				<?php

		// The third row shows an optional progress bar and a list of maintenance options
		$importing = WT_DB::prepare(
			"SELECT 1 FROM `##gedcom_chunk` WHERE gedcom_id = ? AND imported = '0' LIMIT 1"
		)->execute(array($tree->tree_id))->fetchOne();
		if ($importing) {
			$in_progress = WT_DB::prepare(
				"SELECT 1 FROM `##gedcom_chunk` WHERE gedcom_id = ? AND imported = '1' LIMIT 1"
			)->execute(array($tree->tree_id))->fetchOne();
				?>
				<div id="import<?php echo $tree->tree_id; ?>" class="col-xs-12">
					<div class="progress">
						<?php echo $in_progress ? WT_I18N::translate('Calculating…') : WT_I18N::translate('Deleting old genealogy data…'); ?>
					</div>
				</div>
				<?php
			$controller->addInlineJavascript(
				'jQuery("#import' . $tree->tree_id . '").load("import.php?gedcom_id=' . $tree->tree_id . '&keep_media' . $tree->tree_id . '=' . WT_Filter::get('keep_media' . $tree->tree_id) . '");'
			);
		}
				?>
				<div class="row<?php echo $importing ? ' hidden' : ''; ?>" id="actions<?php echo $tree->tree_id; ?>">
					<div class="col-sm-6 col-md-3">
						<h3>
							<?php echo WT_I18N::translate('Family tree'); ?>
							—
							<a href="index.php?ctype=gedcom&ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
								<?php echo WT_I18N::translate('View'); ?>
							</a>
						</h3>
						<ul class="fa-ul">
							<!-- PREFERENCES -->
							<li>
								<i class="fa fa-li fa-cogs"></i>
								<a href="admin_trees_config.php?action=general&amp;ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Preferences'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- PRIVACY -->
							<li>
								<i class="fa fa-li fa-lock"></i>
								<a href="admin_trees_config.php?action=privacy&amp;ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Privacy'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- HOME PAGE BLOCKS-->
							<li>
								<i class="fa fa-li fa-th-large"></i>
								<a href="index_edit.php?gedcom_id=<?php echo $tree->tree_id; ?>">
									<?php echo WT_I18N::translate('Change the “Home page” blocks'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- DELETE -->
							<li>
								<i class="fa fa-li fa-trash-o"></i>
								<a href="#" onclick="if (confirm('<?php echo WT_Filter::escapeJs(WT_I18N::translate('Are you sure you want to delete “%s”?', $tree->tree_name)); ?>')) document.delete_form<?php echo $tree->tree_id; ?>.submit(); return false;">
									<?php echo WT_I18N::translate('Delete'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
								<form name="delete_form<?php echo $tree->tree_id; ?>" method="POST" action="admin_trees_manage.php">
									<input type="hidden" name="action" value="delete">
									<input type="hidden" name="gedcom_id" value="<?php echo $tree->tree_id; ?>">
									<?php echo WT_Filter::getCsrf(); ?>
									<!-- A11Y - forms need submit buttons, but they look ugly here -->
									<button class="sr-only" onclick="return confirm('<?php echo WT_Filter::escapeJs(WT_I18N::translate('Are you sure you want to delete “%s”?', $tree->tree_name)); ?>')" type="submit">
										<?php echo WT_I18N::translate('Delete'); ?>
									</button>
								</form>
							</li>
							<!-- SET AS DEFAULT -->
							<?php if (count(WT_Tree::getAll()) > 1): ?>
								<li>
									<i class="fa fa-li fa-star"></i>
									<?php if ($tree->tree_name == WT_Site::getPreference('DEFAULT_GEDCOM')): ?>
										<?php echo WT_I18N::translate('Default family tree'); ?>
									<?php else: ?>
										<a href="#" onclick="document.defaultform<?php echo $tree->tree_id; ?>.submit();">
											<?php echo WT_I18N::translate('Set as default'); ?>
											<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
										</a>
										<form name="defaultform<?php echo $tree->tree_id; ?>" method="POST" action="admin_trees_manage.php">
											<input type="hidden" name="action" value="setdefault">
											<input type="hidden" name="ged" value="<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
											<?php echo WT_Filter::getCsrf(); ?>
											<!-- A11Y - forms need submit buttons, but they look ugly here -->
											<button class="sr-only" type="submit">
												<?php echo WT_I18N::translate('Set as default'); ?>
											</button>
										</form>
									<?php endif; ?>
								</li>
							<?php endif; ?>
						</ul>
					</div>
					<div class="col-sm-6 col-md-3">
						<h3>
							<?php echo /* I18N: Individuals, sources, dates, places, etc. */ WT_I18N::translate('Genealogy data'); ?>
						</h3>
						<ul class="fa-ul">
							<!-- MERGE -->
							<li>
								<i class="fa fa-li fa-code-fork"></i>
								<a href="admin_site_merge.php?ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Merge records'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- UPDATE PLACE NAMES -->
							<li>
								<i class="fa fa-li fa-map-marker"></i>
								<a href="admin_trees_places.php?ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Update place names'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- CHECK FOR ERRORS -->
							<li>
								<i class="fa fa-li fa-check"></i>
								<a href="admin_trees_check.php?ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Check for errors'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- RENUMBER -->
							<li>
								<i class="fa fa-li fa-sort-numeric-asc"></i>
								<a href="admin_trees_renumber.php?ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Renumber'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- CHANGES -->
							<li>
								<i class="fa fa-li fa-th-list"></i>
								<a href="admin_site_change.php?gedc=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Changes log'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
						</ul>
					</div>
					<div class="clearfix visible-sm-block"></div>
					<div class="col-sm-6 col-md-3">
						<h3>
							<?php echo WT_I18N::translate('Add unlinked records'); ?>
						</h3>
						<ul class="fa-ul">
							<!-- UNLINKED INDIVIDUAL -->
							<li>
								<i class="fa fa-li fa-user"></i>
								<a href="#" onclick="add_unlinked_indi(); return false;">
									<?php echo WT_I18N::translate('Individual'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- UNLINKED SOURCE -->
							<li>
								<i class="fa fa-li fa-book"></i>
								<a href="#" onclick="addnewsource(''); return false;">
									<?php echo WT_I18N::translate('Source'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- UNLINKED REPOSITORY -->
							<li>
								<i class="fa fa-li fa-university"></i>
								<a href="#" onclick="addnewrepository(''); return false;">
									<?php echo WT_I18N::translate('Repository'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- UNLINKED MEDIA OBJECT -->
							<li>
								<i class="fa fa-li fa-photo"></i>
								<a href="#" onclick="window.open('addmedia.php?action=showmediaform', '_blank', edit_window_specs); return false;">
									<?php echo WT_I18N::translate('Media object'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- UNLINKED NOTE -->
							<li>
								<i class="fa fa-li fa-paragraph"></i>
								<a href="#" onclick="addnewnote(''); return false;">
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
									<?php echo WT_I18N::translate('Shared note'); ?>
								</a>
							</li>
						</ul>
					</div>
					<div class="col-sm-6 col-md-3">
						<h3>
							<?php echo WT_I18N::translate('GEDCOM file'); ?>
						</h3>
						<ul class="fa-ul">
							<!-- DOWNLOAD -->
							<li>
								<i class="fa fa-li fa-download"></i>
								<a href="admin_trees_download.php?ged=<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<?php echo WT_I18N::translate('Download'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- UPLOAD -->
							<li>
								<i class="fa fa-li fa-upload"></i>
								<a href="admin_trees_manage.php?action=uploadform&amp;gedcom_id=<?php echo $tree->tree_id; ?>">
									<?php echo WT_I18N::translate('Upload'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
							<!-- EXPORT -->
							<li>
								<form action="admin_trees_export.php" method="post">
									<?php echo WT_Filter::getCsrf(); ?>
									<input type="hidden" name="ged" value="<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>">
									<i class="fa fa-li fa-file-text"></i>
									<input type="submit" class="hide"><!-- for WCAG2 -->
									<a href="#" onclick="jQuery(this).closest('form').submit();">
										<?php echo WT_I18N::translate('Export'); ?>
									</a>
								</form>
							</li>
							<!-- IMPORT -->
							<li>
								<i class="fa fa-li fa-file-text-o"></i>
								<a href="admin_trees_manage.php?action=importform&amp;gedcom_id=<?php echo $tree->tree_id; ?>">
									<?php echo WT_I18N::translate('Import'); ?>
									<span class="sr-only">
										<?php echo WT_Filter::escapeHtml($tree->tree_name); ?>
									</span>
								</a>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
	</div>
	<?php endif; ?>
	<?php endforeach; ?>
	<?php if (Auth::isAdmin()): ?>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h2 class="panel-title">
				<i class="fa fa-fw fa-plus"></i>
				<a data-toggle="collapse" data-parent="#accordion" href="#create-a-new-family-tree">
					<?php echo WT_I18N::translate('Create a new family tree'); ?>
				</a>
			</h2>
		</div>
		<div id="create-a-new-family-tree" class="panel-collapse collapse<?php echo WT_Tree::getAll() ? '' : ' in'; ?>">
			<div class="panel-body">
				<form role="form" class="form-horizontal" method="POST" action="admin_trees_manage.php">
					<?php echo WT_Filter::getCsrf(); ?>
					<input type="hidden" name="action" value="new_tree">
					<div class="form-group">
						<label for="tree_title" class="col-sm-2 control-label">
							<?php echo WT_I18N::translate('Family tree title'); ?>
						</label>
						<div class="col-sm-10">
							<input
								class="form-control"
								id="tree_title"
								maxlength="255"
								name="tree_title"
								required
								type="text"
								value="<?php echo $default_tree_title; ?>"
							>
						</div>
					</div>
					<div class="form-group">
						<label for="tree_name" class="col-sm-2 control-label">
							<?php echo WT_I18N::translate('URL'); ?>
						</label>
						<div class="col-sm-10">
							<div class="input-group">
								<span class="input-group-addon">
									<?php echo WT_SERVER_NAME, WT_SCRIPT_PATH; ?>?ged=
								</span>
								<input
									class="form-control"
									id="tree_name"
									maxlength="31"
									name="tree_name"
									pattern="[^&lt;&gt;&amp;&quot;#^$.*?{}()\[\]/\\]*"
									required
									type="text"
									value="<?php echo $default_tree_name; ?>"
									>
							</div>
							<p class="small text-muted">
								<?php echo WT_I18N::translate('Avoid spaces and puncutation.  A surname might be a good choice.'); ?>
							</p>
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
							<button type="submit" class="btn btn-primary">
								<i class="fa fa-check"></i>
								<?php echo /* I18N: Button label */ WT_I18N::translate('create'); ?>
							</button>
							<p class="small text-muted">
								<?php echo WT_I18N::translate('After creating the family tree, you will be able to upload or import data from a GEDCOM file.'); ?>
							</p>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<?php endif; ?>
	<!-- display link to PGV-WT transfer wizard on first visit to this page, before any GEDCOM is loaded -->
	<?php if (count(WT_Tree::GetAll()) === 0 && count(User::all()) === 1): ?>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h2 class="panel-title">
			<i class="fa fa-fw fa-magic"></i>
			<a data-toggle="collapse" data-parent="#accordion" href="#pgv-import-wizard">
				<?php echo WT_I18N::translate('PhpGedView to webtrees transfer wizard'); ?>
			</a>
		</h2>
		</div>
		<div id="pgv-import-wizard" class="panel-collapse collapse">
			<div class="panel-body">
				<p>
					<?php echo WT_I18N::translate('The PGV to webtrees wizard is an automated process to assist administrators make the move from a PGV installation to a new webtrees one.  It will transfer all PGV GEDCOM and other database information directly to your new webtrees database.  The following requirements are necessary:'); ?>
				</p>
				<ul>
					<li>
						<?php echo WT_I18N::translate('webtrees’ database must be on the same server as PGV’s'); ?>
					</li>
					<li>
						<?php echo /* I18N: %s is a number */ WT_I18N::translate('PGV must be version 4.2.3, or any SVN up to #%s', WT_I18N::digits(7101)); ?>
					</li>
					<li>
						<?php echo WT_I18N::translate('All changes in PGV must be accepted'); ?>
					</li>
					<li>
						<?php echo WT_I18N::translate('All existing PGV users must have distinct email addresses'); ?>
					</li>
				</ul>
				<p>
					<?php echo WT_I18N::translate('<b>Important note:</b> The transfer wizard is not able to assist with moving media items.  You will need to set up and move or copy your media configuration and objects separately after the transfer wizard is finished.'); ?>
				</p>
				<p>
					<a href="admin_pgv_to_wt.php">
						<?php echo WT_I18N::translate('Click here for PhpGedView to webtrees transfer wizard'); ?>
					</a>
				</p>
			</div>
		</div>
	</div>
	<?php endif; ?>
</div>