This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_trees_download.php
170 lines (160 loc) · 6.93 KB
/
admin_trees_download.php
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
<?php
/**
* Kiwitrees: Web based Family History software
* Copyright (C) 2012 to 2023 kiwitrees.net
*
* Derived from webtrees (www.webtrees.net)
* Copyright (C) 2010 to 2012 webtrees development team
*
* Derived from PhpGedView (phpgedview.sourceforge.net)
* Copyright (C) 2002 to 2010 PGV Development Team
*
* Kiwitrees 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 3 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 Kiwitrees. If not, see <http://www.gnu.org/licenses/>.
*/
define('KT_SCRIPT_NAME', 'admin_trees_download.php');
require './includes/session.php';
require KT_ROOT.'includes/functions/functions_export.php';
$controller = new KT_Controller_Page();
$controller
->setPageTitle(KT_I18N::translate('Export a GEDCOM file'))
->requireManagerLogin();
// Validate user parameters
$action = safe_GET('action', 'download');
$convert = safe_GET('convert', 'yes', 'no');
$zip = safe_GET('zip', 'yes', 'no');
$conv_path = safe_GET('conv_path', KT_REGEX_NOSCRIPT);
$privatize_export = safe_GET('privatize_export', array('none', 'visitor', 'user', 'gedadmin'));
if ($action == 'download') {
$exportOptions = array();
$exportOptions['privatize'] = $privatize_export;
$exportOptions['toANSI'] = $convert;
$exportOptions['path'] = $conv_path;
}
$fileName = KT_GEDCOM;
if ($action == "download" && $zip == "yes") {
require KT_ROOT.'library/pclzip.lib.php';
$temppath = KT_Site::preference('INDEX_DIRECTORY') . "tmp/";
$zipname = "dl" . date("YmdHis") . $fileName . ".zip";
$zipfile = KT_Site::preference('INDEX_DIRECTORY') . $zipname;
$gedname = $temppath . $fileName;
$removeTempDir = false;
if (!is_dir($temppath)) {
$res = mkdir($temppath);
if ($res !== true) {
echo "Error : Could not create temporary path!";
exit;
}
$removeTempDir = true;
}
$gedout = fopen($gedname, "w");
export_gedcom($GEDCOM, $gedout, $exportOptions);
fclose($gedout);
$comment = "Created by " . KT_KIWITREES . " " . KT_VERSION_TEXT . " on " . date("r") . ".";
$archive = new PclZip($zipfile);
$v_list = $archive->create($gedname, PCLZIP_OPT_COMMENT, $comment, PCLZIP_OPT_REMOVE_PATH, $temppath);
if ($v_list == 0) echo "Error : " . $archive->errorInfo(true);
else {
unlink($gedname);
if ($removeTempDir) rmdir($temppath);
header('Location: '. KT_SERVER_NAME . KT_SCRIPT_PATH."downloadbackup.php?fname=" . $zipname);
exit;
}
exit;
}
if ($action == "download") {
Zend_Session::writeClose();
header('Content-Type: text/plain; charset=UTF-8');
// We could open "php://compress.zlib" to create a .gz file or "php://compress.bzip2" to create a .bz2 file
$gedout = fopen('php://output', 'w');
if (strtolower(substr($fileName, -4, 4))!='.ged') {
$fileName.='.ged';
}
header('Content-Disposition: attachment; filename="'.$fileName.'"');
export_gedcom(KT_GEDCOM, $gedout, $exportOptions);
fclose($gedout);
exit;
}
$controller->pageHeader();
?>
<div id="tree-download">
<h2><?php echo $controller->getPageTitle(); ?> - <?php echo $tree->tree_title_html; ?></h2>
<form id="tree-export" method="post" action="admin_trees_export.php">
<?php echo KT_Filter::getCsrf(); ?>
<input type="hidden" name="ged" value="<?php echo $tree->tree_name_url; ?>">
<label><?php echo KT_I18N::translate('A file on the server'); ?></label>
<button id="submit-export" class="btn btn-primary" type="submit" onclick="return modalDialog('admin_trees_export.php?ged=<?php echo $tree->tree_name_url; ?>', '<?php echo KT_I18N::translate('Export'); ?>');">
<i class="fa fa-play"></i>
<?php echo KT_I18N::translate('continue'); ?>
</button>
</form>
<hr>
<form name="convertform" method="get">
<input type="hidden" name="action" value="download">
<input type="hidden" name="ged" value="<?php echo KT_GEDCOM; ?>">
<label><?php echo KT_I18N::translate('A file on your computer'); ?></label>
<div class="input">
<dl>
<dt>
<?php echo KT_I18N::translate('Zip File(s)'); ?>
</dt>
<dd>
<input type="checkbox" name="zip" value="yes">
</dd>
<div class="help_content">
<?php echo KT_I18N::translate('To reduce the size of the download, you can compress the data into a .ZIP file. You will need to uncompress the .ZIP file before you can use it.'); ?>
</div>
<dt>
<?php echo KT_I18N::translate('Apply privacy settings?'); ?>
</dt>
<dd>
<input type="radio" name="privatize_export" value="none" checked="checked"> <?php echo KT_I18N::translate('None'); ?>
<br>
<input type="radio" name="privatize_export" value="gedadmin"> <?php echo KT_I18N::translate('Manager'); ?>
<br>
<input type="radio" name="privatize_export" value="user"> <?php echo KT_I18N::translate('Member'); ?>
<br>
<input type="radio" name="privatize_export" value="visitor"> <?php echo KT_I18N::translate('Visitor'); ?>
</dd>
<div class="help_content">
<?php echo KT_I18N::translate('This option will remove private data from the downloaded GEDCOM file. The file will be filtered according to the privacy settings that apply to each access level. Privacy settings are specified on the GEDCOM configuration page.'); ?>
</div>
<dt>
<?php echo KT_I18N::translate('Convert from UTF-8 to ANSI (ISO-8859-1)'); ?>
</dt>
<dd>
<input type="checkbox" name="convert" value="yes">
</dd>
<div class="help_content">
<?php echo KT_I18N::translate('Kiwitrees uses UTF-8 encoding for accented letters, special characters and non-latin scripts. If you want to use this GEDCOM file with genealogy software that does not support UTF-8, then you can create it using ISO-8859-1 encoding.'); ?>
</div>
<?php if (get_gedcom_setting(KT_GED_ID, 'GEDCOM_MEDIA_PATH')) { ?>
<dt>
<?php echo KT_I18N::translate('Add the GEDCOM media path to filenames'); ?>
</dt>
<dd>
<input type="checkbox" name="conv_path" value="<?php echo KT_Filter::escapeHtml(get_gedcom_setting(KT_GED_ID, 'GEDCOM_MEDIA_PATH')); ?>">
<span dir="auto"><?php echo KT_Filter::escapeHtml($GEDCOM_MEDIA_PATH); ?></span>
</dd>
<div class="help_content">
<?php echo KT_I18N::translate('Media filenames will be prefixed by %s.', '<code dir="ltr">' . KT_Filter::escapeHtml(get_gedcom_setting(KT_GED_ID, 'GEDCOM_MEDIA_PATH')) . '</code>'); ?>
</div>
<?php } ?>
</dl>
<p>
<button class="btn btn-primary clearfloat" type="submit">
<i class="fa fa-play"></i>
<?php echo KT_I18N::translate('continue'); ?>
</button>
</p>
</div>
</form>
</div>