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
|
<?php
/**
* Check a GEDCOM file for compliance with the 5.5.1 specification
* and other common errors.
*
* webtrees: Web based Family History software
* Copyright (C) 2010 webtrees development team.
*
* Derived from PhpGedView
* Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
*
* Modifications Copyright (c) 2010 Greg Roach
*
* 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 discretion, 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
*
* @author Nigel Osborne 26 Mar 2007
* @package webtrees
* $Id$
*/
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}
$action =safe_POST ('action' );
$gedcom_id=safe_POST ('gedcom_id', array_keys(get_all_gedcoms()), WT_GED_ID);
$openinnew=safe_POST_bool('openinnew' );
$state =safe_POST ('state', WT_REGEX_UNSAFE, 'XYZ' );
$country =safe_POST ('country', WT_REGEX_UNSAFE, 'XYZ' );
// Must be an admin user to use this module
if (!WT_USER_GEDCOM_ADMIN) {
header("Location: login.php?url=placelist.php");
exit;
}
print_header(i18n::translate('Place Check').' - '.WT_GEDCOM);
$target=$openinnew ? "target='_blank'" : "";
echo "<div align=\"center\" style=\"width: 99%;\"><h1>", i18n::translate('Place Check'), "</h1></div>";
//Start of User Defined options
echo "<table border='0' width='100%' height='100px' overflow='auto';>";
echo "<form method='post' name='placecheck' action='module.php?mod=googlemap&mod_action=placecheck'>";
echo "<tr valign='top'>";
echo "<td>";
echo "<table align='left'>";
echo "<tr><td colspan='2'class='descriptionbox' align='center'><strong>", i18n::translate('PlaceCheck List Options'), "</strong></td></tr>";
//Option box to select gedcom
echo "<tr><td class='descriptionbox'>".i18n::translate('GEDCOM File:')."</td>";
echo "<td class='optionbox'><select name='gedcom_id'>";
foreach (get_all_gedcoms() as $ged_id=>$gedcom) {
echo '<option value="', $ged_id, '"', $ged_id==$gedcom_id?' selected="selected"':'', '>', htmlspecialchars($gedcom), '</option>';
}
echo "</select></td></tr>";
//Option box for 'Open in new window'
echo "<tr><td class='descriptionbox'>".i18n::translate('Open links in')."</td>";
echo "<td class='optionbox'><select name='openinnew'>";
echo "<option value='0' ", $openinnew?" selected='selected'":"", ">".i18n::translate('Same tab/window')."</option>";
echo "<option value='1' ", $openinnew?" selected='selected'":"", ">".i18n::translate('New tab/window')."</option>";
echo "</select></td></tr>";
//Option box to select top level place within Gedcom
echo "<tr><td class='descriptionbox'>", i18n::translate('Top Level Place'), "</td>";
echo "<td class='optionbox'><select name='country'>";
echo "<option value='XYZ' selected='selected'>", i18n::translate('Select Top Level...'), "</option>";
echo "<option value='XYZ'>", i18n::translate('All'), "</option>";
$rows=
WT_DB::prepare("SELECT pl_id, pl_place FROM `##placelocation` WHERE pl_level=0 ORDER BY pl_place")
->fetchAssoc();
foreach ($rows as $id=>$place) {
echo "<option value='{$place}'";
if ($place==$country) {
echo " selected='selected'";
$par_id=$id;
}
echo ">{$place}</option>";
}
echo "</select></td></tr>";
//Option box to select level one place within the selected top level
if ($country!='XYZ') {
echo "<tr><td class='descriptionbox'>", i18n::translate('Level One Place'), "</td>";
echo "<td class='optionbox'><select name='state'>";
echo "<option value='XYZ' selected='selected'>", i18n::translate('Select Next Level...'), "</option>";
echo "<option value='XYZ'>", i18n::translate('All'), "</option>";
$places=
WT_DB::prepare("SELECT pl_place FROM `##placelocation` WHERE pl_parent_id=? ORDER BY pl_place")
->execute(array($par_id))
->fetchOneColumn();
foreach ($places as $place) {
echo "<option value='{$place}'", $place==$state?" selected='selected'":"", ">{$place}</option>";
}
echo "</select></td></tr>";
}
echo "</table>";
echo "</td>";
//Show Filter table
if (!isset ($_POST["matching"])) {$matching=0;} else {$matching=1;}
echo "<td>";
echo "<table>";
echo "<tr><td colspan='2' class='descriptionbox' align='center'>";
echo "<strong>", i18n::translate('List filtering options'), "</strong>", help_link('PLACECHECK_FILTER','googlemap');
echo "</td></tr><tr><td class='descriptionbox'>";
echo i18n::translate('Include fully matched places: '), help_link('PLACECHECK_MATCH','googlemap');
echo "</td><td class='optionbox'><input type=\"checkbox\" name=\"matching\" value=\"active\"";
if($matching==1) {
echo " checked=\"checked\"";
}
echo "></td></tr>";
echo "</table>";
echo "</td>";
//Show Key table
echo "<td rowspan='2'>";
echo "<table align='right'>";
echo "<tr><td colspan='4' align='center' class='descriptionbox'><strong>", i18n::translate('Key to colors used below'), "</strong></td></tr>";
echo "<tr><td class='facts_value error'>", translate_fact('PLAC'), "</td><td class='facts_value error' align='center '><strong>X</strong></td><td align='center' class='facts_value error'><strong>X</strong></td><td class='facts_value'><font size=\"-2\">", i18n::translate('This place and its coordinates do not exist in the GoogleMap tables.'), "</font></td></tr>";
echo "<tr><td class='facts_value'><a>", translate_fact('PLAC'), "</a></td><td class='facts_value error' align='center '><strong>X</strong></td><td align='center' class='facts_value error'><strong>X</strong></td><td class='facts_value'><font size=\"-2\">", i18n::translate('This place exists in the GoogleMap tables, but has no coordinates.'), "</font></td></tr>";
echo "<tr><td class='facts_value'><strong>".i18n::translate('Unknown')."</font></td><td class='facts_value error' align='center '><strong>X</strong></td><td align='center' class='facts_value error'><strong>X</strong></td><td class='facts_value'><font size=\"-2\">", i18n::translate('This place level is blank in your GEDCOM file. It should be added to GoogleMap places as "unknown" with coordinates from its parent level before you add any place to the next level.'), "</font></td></tr>";
echo "<tr><td class='facts_value'><a>".i18n::translate('Unknown')."</a></td><td class='facts_value' align='center'>N55.0</td><td align='center' class='facts_value'>W75.0</td><td class='facts_value'><font size=\"-2\">", i18n::translate('This place level is blank in your GEDCOM file, but exists as "unknown" in the GoogleMap places table with coordinates. No action required until the missing level can be entered.'), "</font></td></tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>";
echo "<input type='submit' value='".i18n::translate('Show')."' $target><input type='hidden' name='action' value='go'>";
echo "</td>";
echo "</tr>";
echo "</form>";
echo "</table>";
echo "<hr />";
switch ($action) {
case 'go':
//Identify gedcom file
echo "<strong>", i18n::translate('Place list for GEDCOM file'), ": </strong>", htmlspecialchars(get_gedcom_setting($gedcom_id, 'title')), "<br /><br />";
//Select all '2 PLAC ' tags in the file and create array
$place_list=array();
$ged_data=WT_DB::prepare("SELECT i_gedcom FROM `##individuals` WHERE i_gedcom LIKE ? AND i_file=?")
->execute(array("%\n2 PLAC %", $gedcom_id))
->fetchOneColumn();
foreach ($ged_data as $ged_datum) {
preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches);
foreach ($matches[1] as $match) {
$place_list[$match]=true;
}
}
$ged_data=WT_DB::prepare("SELECT f_gedcom FROM `##families` WHERE f_gedcom LIKE ? AND f_file=?")
->execute(array("%\n2 PLAC %", $gedcom_id))
->fetchOneColumn();
foreach ($ged_data as $ged_datum) {
preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches);
foreach ($matches[1] as $match) {
$place_list[$match]=true;
}
}
// Unique list of places
$place_list=array_keys($place_list);
// Apply_filter
if ($country=='XYZ') {
$filter='.*$';
} else {
$filter=preg_quote($country).'$';
if ($state!='XYZ') {
$filter=preg_quote($state).', '.$filter;
}
}
$place_list=preg_grep('/'.$filter.'/', $place_list);
//sort the array, limit to unique values, and count them
$place_parts=array();
usort($place_list, "utf8_strcasecmp");
$i=count($place_list);
//calculate maximum no. of levels to display
$x=0;
$max=0;
while ($x<$i) {
$levels=explode(",", $place_list[$x]);
$parts=count($levels);
if ($parts>$max) $max=$parts;
$x++;}
$x=0;
//scripts for edit, add and refresh
?>
<script language="JavaScript" type="text/javascript">
<!--
function edit_place_location(placeid) {
window.open('module.php?mod=googlemap&mod_action=places_edit&action=update&placeid='+placeid+"&"+sessionname+"="+sessionid, '_blank', 'top=50, left=50, width=680, height=550, resizable=1, scrollbars=1');
return false;
}
function add_place_location(placeid) {
window.open('module.php?mod=googlemap&mod_action=places_edit&action=add&placeid='+placeid+"&"+sessionname+"="+sessionid, '_blank', 'top=50, left=50, width=680, height=550, resizable=1, scrollbars=1');
return false;
}
function showchanges() {
window.location='<?php echo $_SERVER["REQUEST_URI"]; ?>&show_changes=yes';
}
//-->
</script>
<?php
//start to produce the display table
$cols=0;
$span=$max*3+3;
echo "<table class='facts_table' width='100%'><tr>";
echo "<td rowspan='3' class='descriptionbox' align='center'><strong>", i18n::translate('GEDCOM File Place Data<br />(2 PLAC tag)'), "</strong></td>";
echo "<td class='descriptionbox' colspan='", $span, "' align='center'><strong>", i18n::translate('GoogleMap Places Table Data'), "</strong></td></tr>";
echo "<tr>";
while ($cols<$max) {
echo "<td class='descriptionbox' colspan='3' align='center'><strong>", PrintReady(i18n::translate('Level')), " ", $cols, "</strong></td>";
$cols++;
}
echo "</tr><tr>";
$cols=0;
while ($cols<$max) {
echo "<td class='descriptionbox' align='center'><strong>", translate_fact('PLAC'), "</strong></td><td class='descriptionbox' align='center'><strong>", i18n::translate('Latitude'), "</strong><td class='descriptionbox' align='center'><strong>", i18n::translate('Longitude'), "</strong></td></td>";
$cols++;
}
echo "</tr>";
$countrows=0;
while ($x<$i) {
$placestr="";
$levels=explode(",", $place_list[$x]);
$parts=count($levels);
$levels=array_reverse($levels);
$placestr.="<a href=\"placelist.php?action=show&";
foreach($levels as $pindex=>$ppart) {
$ppart=urlencode(trim($ppart));
$placestr.="parent[$pindex]=".$ppart."&";
}
$placestr.="level=".count($levels);
$placestr.="\">".$place_list[$x]."</a>";
$gedplace="<tr><td class='facts_value'>".$placestr."</td>";
$z=0;
$y=0;
$id=0;
$level=0;
$matched[$x]=0;// used to exclude places where the gedcom place is matched at all levels
$mapstr_edit="<a href=\"javascript:;\" onclick=\"edit_place_location('";
$mapstr_add="<a href=\"javascript:;\" onclick=\"add_place_location('";
$mapstr3="";
$mapstr4="";
$mapstr5="')\" title='";
$mapstr6="' >";
$mapstr7="')\">";
$mapstr8="</a>";
while ($z<$parts) {
if ($levels[$z]==' ' || $levels[$z]=='')
$levels[$z]="unknown";// GoogleMap module uses "unknown" while GEDCOM uses , ,
$levels[$z]=rtrim(ltrim($levels[$z]));
$placelist=create_possible_place_names($levels[$z], $z+1); // add the necessary prefix/postfix values to the place name
foreach ($placelist as $key=>$placename) {
$row=
WT_DB::prepare("SELECT pl_id, pl_place, pl_long, pl_lati, pl_zoom FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place")
->execute(array($z, $id, $placename))
->fetchOneRow(PDO::FETCH_ASSOC);
if (!empty($row['pl_id'])) {
$row['pl_placerequested']=$levels[$z]; // keep the actual place name that was requested so we can display that instead of what is in the db
break;
}
}
if ($row['pl_id']!='') {
$id=$row['pl_id'];
}
if ($row['pl_place']!='') {
$placestr2=$mapstr_edit.$id."&level=".$level.$mapstr3.$mapstr5.i18n::translate('Zoom=').$row['pl_zoom'].$mapstr6.$row['pl_placerequested'].$mapstr8;
if ($row['pl_place']=='unknown')
$matched[$x]++;
} else {
if ($levels[$z]=="unknown") {
$placestr2=$mapstr_add.$id."&level=".$level.$mapstr3.$mapstr7."<strong>".rtrim(ltrim(i18n::translate('Unknown')))."</strong>".$mapstr8;$matched[$x]++;
} else {
$placestr2=$mapstr_add.$id."&place_name=".urlencode($levels[$z])."&level=".$level.$mapstr3.$mapstr7.'<span class="error">'.rtrim(ltrim($levels[$z])).'</span>'.$mapstr8;$matched[$x]++;
}
}
$plac[$z]="<td class='facts_value'>".$placestr2."</td>\n";
if ($row['pl_lati']=='0'){
$lati[$z]="<td class='facts_value error'><strong>".$row['pl_lati']."</strong></td>";
} else if ($row['pl_lati']!='') {
$lati[$z]="<td class='facts_value'>".$row['pl_lati']."</td>";
} else {
$lati[$z]="<td class='facts_value error' align='center'><strong>X</strong></td>";$matched[$x]++;
}
if ($row['pl_long']=='0'){
$long[$z]="<td class='facts_value error'><strong>".$row['pl_long']."</strong></td>";
} else if ($row['pl_long']!='') {
$long[$z]="<td class='facts_value'>".$row['pl_long']."</td>";
} else {
$long[$z]="<td class='facts_value error' align='center'><strong>X</strong></td>";$matched[$x]++;
}
$level++;
$mapstr3=$mapstr3."&parent[".$z."]=".addslashes(PrintReady($row['pl_placerequested']));
$mapstr4=$mapstr4."&parent[".$z."]=".addslashes(PrintReady(rtrim(ltrim($levels[$z]))));
$z++;
}
if ($matching==1) {
$matched[$x]=1;
}
if ($matched[$x]!=0) {
echo $gedplace;
$z=0;
while ($z<$max) {
if ($z<$parts) {
echo $plac[$z];
echo $lati[$z];
echo $long[$z];
} else {
echo "<td class='facts_value'> </td><td class='facts_value'> </td><td class='facts_value'> </td>";}
$z++;
}
echo "</tr>";
$countrows++;
}
$x++;
}
// echo final row of table
echo "<tr><td colspan=\"2\" class=\"list_label\">", i18n::translate('Total unique places'), ": ", $countrows, "</td></tr></table><br /><br />";
break;
default:
// Do not run until user selects a gedcom/place/etc.
// Instead, show some useful help info.
echo "<p>", i18n::translate('This will list all the places from the selected GEDCOM file. By default this will NOT INCLUDE places that are fully matched between the GEDCOM file and the GoogleMap tables'), "</p><hr />";
break;
}
//echo footers
echo "<hr />";
print_footer();
?>
|