forked from fisharebest/webtrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_site_change.php
297 lines (280 loc) · 10.6 KB
/
admin_site_change.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
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
<?php
// Change log viewer.
//
// webtrees: Web based Family History software
// Copyright (C) 2013 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
define('WT_SCRIPT_NAME', 'admin_site_change.php');
require './includes/session.php';
$controller=new WT_Controller_Page();
$controller
->requireManagerLogin()
->setPageTitle(WT_I18N::translate('Changes'));
require WT_ROOT.'includes/functions/functions_edit.php';
$statuses=array(
'' =>'',
'accepted'=>/* I18N: the status of an edit accepted/rejected/pending */ WT_I18N::translate('accepted'),
'rejected'=>/* I18N: the status of an edit accepted/rejected/pending */ WT_I18N::translate('rejected'),
'pending' =>/* I18N: the status of an edit accepted/rejected/pending */ WT_I18N::translate('pending' ),
);
$earliest=WT_DB::prepare("SELECT DATE(MIN(change_time)) FROM `##change`")->execute(array())->fetchOne();
$latest =WT_DB::prepare("SELECT DATE(MAX(change_time)) FROM `##change`")->execute(array())->fetchOne();
// Filtering
$action = WT_Filter::get('action');
$from = WT_Filter::get('from', '\d\d\d\d-\d\d-\d\d', $earliest);
$to = WT_Filter::get('to', '\d\d\d\d-\d\d-\d\d', $latest);
$type = WT_Filter::get('type', 'accepted|rejected|pending');
$oldged = WT_Filter::get('oldged');
$newged = WT_Filter::get('newged');
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$user = WT_Filter::get('user');
if (WT_USER_IS_ADMIN) {
// Administrators can see all logs
$gedc = WT_Filter::get('gedc');
} else {
// Managers can only see logs relating to this gedcom
$gedc = WT_GEDCOM;
}
$query=array();
$args =array();
if ($from) {
$query[]='change_time>=?';
$args []=$from;
}
if ($to) {
$query[]='change_time<TIMESTAMPADD(DAY, 1 , ?)'; // before end of the day
$args []=$to;
}
if ($type) {
$query[]='status=?';
$args []=$type;
}
if ($oldged) {
$query[]="old_gedcom LIKE CONCAT('%', ?, '%')";
$args []=$oldged;
}
if ($newged) {
$query[]="new_gedcom LIKE CONCAT('%', ?, '%')";
$args []=$newged;
}
if ($xref) {
$query[]="xref = ?";
$args []=$xref;
}
if ($user) {
$query[]="user_name LIKE CONCAT('%', ?, '%')";
$args []=$user;
}
if ($gedc) {
$query[]="gedcom_name LIKE CONCAT('%', ?, '%')";
$args []=$gedc;
}
$SELECT1=
"SELECT SQL_CACHE SQL_CALC_FOUND_ROWS change_time, status, xref, old_gedcom, new_gedcom, IFNULL(user_name, '<none>') AS user_name, IFNULL(gedcom_name, '<none>') AS gedcom_name".
" FROM `##change`".
" LEFT JOIN `##user` USING (user_id)". // user may be deleted
" LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
$SELECT2=
"SELECT COUNT(*) FROM `##change`".
" LEFT JOIN `##user` USING (user_id)". // user may be deleted
" LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
if ($query) {
$WHERE=" WHERE ".implode(' AND ', $query);
} else {
$WHERE='';
}
switch($action) {
case 'delete':
$DELETE=
"DELETE `##change` FROM `##change`".
" LEFT JOIN `##user` USING (user_id)". // user may be deleted
" LEFT JOIN `##gedcom` USING (gedcom_id)". // gedcom may be deleted
$WHERE;
WT_DB::prepare($DELETE)->execute($args);
break;
case 'export':
Zend_Session::writeClose();
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="webtrees-changes.csv"');
$rows=WT_DB::prepare($SELECT1.$WHERE.' ORDER BY change_id')->execute($args)->fetchAll();
foreach ($rows as $row) {
$row->old_gedcom = str_replace('"', '""', $row->old_gedcom);
$row->old_gedcom = str_replace("\n", '""', $row->old_gedcom);
$row->new_gedcom = str_replace('"', '""', $row->new_gedcom);
$row->new_gedcom = str_replace("\n", '""', $row->new_gedcom);
echo
'"', $row->change_time, '",',
'"', $row->status, '",',
'"', $row->xref, '",',
'"', $row->old_gedcom, '",',
'"', $row->new_gedcom, '",',
'"', str_replace('"', '""', $row->user_name), '",',
'"', str_replace('"', '""', $row->gedcom_name), '"',
"\n";
}
exit;
case 'load_json':
Zend_Session::writeClose();
$iDisplayStart = WT_Filter::getInteger('iDisplayStart');
$iDisplayLength = WT_Filter::getInteger('iDisplayLength');
set_user_setting(WT_USER_ID, 'admin_site_change_page_size', $iDisplayLength);
if ($iDisplayLength>0) {
$LIMIT = " LIMIT " . $iDisplayStart . ',' . $iDisplayLength;
} else {
$LIMIT = "";
}
$iSortingCols = WT_Filter::getInteger('iSortingCols');
if ($iSortingCols) {
$ORDER_BY=' ORDER BY ';
for ($i=0; $i<$iSortingCols; ++$i) {
// Datatables numbers columns 0, 1, 2, ...
// MySQL numbers columns 1, 2, 3, ...
switch (WT_Filter::get('sSortDir_'.$i)) {
case 'asc':
if (WT_Filter::getInteger('iSortCol_'.$i)==0) {
$ORDER_BY.='change_id ASC '; // column 0 is "timestamp", using change_id gives the correct order for events in the same second
} else {
$ORDER_BY.=(1 + WT_Filter::getInteger('iSortCol_'.$i)).' ASC ';
}
break;
case 'desc':
if (WT_Filter::getInteger('iSortCol_'.$i)==0) {
$ORDER_BY.='change_id DESC ';
} else {
$ORDER_BY.=(1 + WT_Filter::getInteger('iSortCol_'.$i)).' DESC ';
}
break;
}
if ($i<$iSortingCols-1) {
$ORDER_BY.=',';
}
}
} else {
$ORDER_BY='1 DESC';
}
// This becomes a JSON list, not array, so need to fetch with numeric keys.
$aaData=WT_DB::prepare($SELECT1.$WHERE.$ORDER_BY.$LIMIT)->execute($args)->fetchAll(PDO::FETCH_NUM);
foreach ($aaData as &$row) {
$row[1]=WT_I18N::translate($row[1]);
$row[2]='<a href="gedrecord.php?pid='.$row[2].'&ged='.$row[6].'" target="_blank">'.$row[2].'</a>';
$row[3]='<pre>'.WT_Filter::escapeHtml($row[3]).'</pre>';
$row[4]='<pre>'.WT_Filter::escapeHtml($row[4]).'</pre>';
}
// Total filtered/unfiltered rows
$iTotalDisplayRecords=WT_DB::prepare("SELECT FOUND_ROWS()")->fetchColumn();
$iTotalRecords=WT_DB::prepare($SELECT2.$WHERE)->execute($args)->fetchColumn();
header('Content-type: application/json');
echo json_encode(array( // See http://www.datatables.net/usage/server-side
'sEcho' => WT_Filter::getInteger('sEcho'), // Always an integer
'iTotalRecords' => $iTotalRecords,
'iTotalDisplayRecords' => $iTotalDisplayRecords,
'aaData' => $aaData
));
exit;
}
$controller
->pageHeader()
->addExternalJavascript(WT_JQUERY_DATATABLES_URL)
->addInlineJavascript('
var oTable=jQuery("#log_list").dataTable( {
"sDom": \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "'.WT_SERVER_NAME.WT_SCRIPT_PATH.WT_SCRIPT_NAME.'?action=load_json&from='.$from.'&to='.$to.'&type='.$type.'&oldged='.rawurlencode($oldged).'&newged='.rawurlencode($newged).'&xref='.rawurlencode($xref).'&user='.rawurlencode($user).'&gedc='.rawurlencode($gedc).'",
'.WT_I18N::datatablesI18N(array(10,20,50,100,500,1000,-1)).',
"bJQueryUI": true,
"bAutoWidth":false,
"aaSorting": [[ 0, "desc" ]],
"iDisplayLength": '.get_user_setting(WT_USER_ID, 'admin_site_change_page_size', 10).',
"sPaginationType": "full_numbers",
"aoColumns": [
/* Timestamp */ {},
/* Status */ {},
/* Record */ {},
/* Old data */ {"sClass":"raw_gedcom"},
/* New data */ {"sClass":"raw_gedcom"},
/* User */ {},
/* Family tree */ {}
]
});
');
$url=
WT_SCRIPT_NAME.'?from='.rawurlencode($from).
'&to='.rawurlencode($to).
'&type='.rawurlencode($type).
'&oldged='.rawurlencode($oldged).
'&newged='.rawurlencode($newged).
'&xref='.rawurlencode($xref).
'&user='.rawurlencode($user).
'&gedc='.rawurlencode($gedc);
$users_array=array_combine(get_all_users(), get_all_users());
uksort($users_array, 'strnatcasecmp');
echo
'<form name="changes" method="get" action="'.WT_SCRIPT_NAME.'">',
'<input type="hidden" name="action", value="show">',
'<table class="site_change">',
'<tr>',
'<td colspan="6">',
// I18N: %s are both user-input date fields
WT_I18N::translate('From %s to %s', '<input class="log-date" name="from" value="'.WT_Filter::escapeHtml($from).'">', '<input class="log-date" name="to" value="'.WT_Filter::escapeHtml($to).'">'),
'</td>',
'</tr><tr>',
'<td>',
WT_I18N::translate('Status'), '<br>', select_edit_control('type', $statuses, null, $type, ''),
'</td>',
'<td>',
WT_I18N::translate('Record'), '<br><input class="log-filter" name="xref" value="', WT_Filter::escapeHtml($xref), '"> ',
'</td>',
'<td>',
WT_I18N::translate('Old data'), '<br><input class="log-filter" name="oldged" value="', WT_Filter::escapeHtml($oldged), '"> ',
'</td>',
'<td>',
WT_I18N::translate('New data'), '<br><input class="log-filter" name="newged" value="', WT_Filter::escapeHtml($newged), '"> ',
'</td>',
'<td>',
WT_I18N::translate('User'), '<br>', select_edit_control('user', $users_array, '', $user, ''),
'</td>',
'<td>',
WT_I18N::translate('Family tree'), '<br>', select_edit_control('gedc', WT_Tree::getNameList(), '', $gedc, WT_USER_IS_ADMIN ? '' : 'disabled'),
'</td>',
'</tr><tr>',
'<td colspan="6">',
'<input type="submit" value="', WT_I18N::translate('Filter'), '">',
'<input type="submit" value="', WT_I18N::translate('Export'), '" onclick="document.changes.action.value=\'export\';return true;" ', ($action=='show' ? '' : 'disabled="disabled"'),'>',
'<input type="submit" value="', WT_I18N::translate('Delete'), '" onclick="if (confirm(\'', WT_Filter::escapeHtml(WT_I18N::translate('Permanently delete these records?')) , '\')) {document.changes.action.value=\'delete\';return true;} else {return false;}" ', ($action=='show' ? '' : 'disabled="disabled"'),'>',
'</td>',
'</tr>',
'</table>',
'</form>';
if ($action) {
echo
'<br>',
'<table id="log_list">',
'<thead>',
'<tr>',
'<th>', WT_I18N::translate('Timestamp'), '</th>',
'<th>', WT_I18N::translate('Status'), '</th>',
'<th>', WT_I18N::translate('Record'), '</th>',
'<th>', WT_I18N::translate('Old data'), '</th>',
'<th>', WT_I18N::translate('New data'), '</th>',
'<th>', WT_I18N::translate('User'), '</th>',
'<th>', WT_I18N::translate('Family tree'), '</th>',
'</tr>',
'</thead>',
'<tbody>',
'</tbody>',
'</table>';
}