Completed
Push — 1.7 ( 35206a...5c14a5 )
by Greg
17:33 queued 07:18
created
editnews.php 1 patch
Switch Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -44,44 +44,44 @@
 block discarded – undo
44 44
 $text      = Filter::post('text');
45 45
 
46 46
 switch ($action) {
47
-case 'compose':
48
-	if (Module::getModuleByName('ckeditor')) {
49
-		CkeditorModule::enableEditor($controller);
50
-	}
47
+	case 'compose':
48
+		if (Module::getModuleByName('ckeditor')) {
49
+			CkeditorModule::enableEditor($controller);
50
+		}
51 51
 
52
-	echo '<h3>' . I18N::translate('Add/edit a journal/news entry') . '</h3>';
53
-	echo '<form style="overflow: hidden;" name="messageform" method="post" action="editnews.php?action=save&news_id=' . $news_id . '">';
54
-	if ($news_id) {
55
-		$news = Database::prepare("SELECT news_id AS id, user_id, gedcom_id, UNIX_TIMESTAMP(updated) AS date, subject, body FROM `##news` WHERE news_id=?")->execute(array($news_id))->fetchOneRow(PDO::FETCH_ASSOC);
56
-	} else {
57
-		$news              = array();
58
-		$news['user_id']   = $user_id;
59
-		$news['gedcom_id'] = $gedcom_id;
60
-		$news['date']      = WT_TIMESTAMP;
61
-		$news['subject']   = '';
62
-		$news['body']      = '';
63
-	}
64
-	echo '<input type="hidden" name="user_id" value="' . $news['user_id'] . '">';
65
-	echo '<input type="hidden" name="gedcom_id" value="' . $news['gedcom_id'] . '">';
66
-	echo '<input type="hidden" name="date" value="' . $news['date'] . '">';
67
-	echo '<table>';
68
-	echo '<tr><th style="text-align:start;">' . I18N::translate('Title') . '</th><tr>';
69
-	echo '<tr><td><input type="text" name="title" size="50" dir="auto" autofocus value="' . $news['subject'] . '"></td></tr>';
70
-	echo '<tr><th style="text-align:start;">' . I18N::translate('Content') . '</th></tr>';
71
-	echo '<tr><td>';
72
-	echo '<textarea name="text" class="html-edit" cols="80" rows="10" dir="auto">' . Filter::escapeHtml($news['body']) . '</textarea>';
73
-	echo '</td></tr>';
74
-	echo '<tr><td><input type="submit" value="' . I18N::translate('save') . '"></td></tr>';
75
-	echo '</table>';
76
-	echo '</form>';
77
-	break;
78
-case 'save':
79
-	if ($news_id) {
80
-		Database::prepare("UPDATE `##news` SET subject=?, body=?, updated=FROM_UNIXTIME(?) WHERE news_id=?")->execute(array($title, $text, $date, $news_id));
81
-	} else {
82
-		Database::prepare("INSERT INTO `##news` (user_id, gedcom_id, subject, body, updated) VALUES (NULLIF(?, ''), NULLIF(?, '') ,? ,?, CURRENT_TIMESTAMP)")->execute(array($user_id, $gedcom_id, $title, $text));
83
-	}
52
+		echo '<h3>' . I18N::translate('Add/edit a journal/news entry') . '</h3>';
53
+		echo '<form style="overflow: hidden;" name="messageform" method="post" action="editnews.php?action=save&news_id=' . $news_id . '">';
54
+		if ($news_id) {
55
+			$news = Database::prepare("SELECT news_id AS id, user_id, gedcom_id, UNIX_TIMESTAMP(updated) AS date, subject, body FROM `##news` WHERE news_id=?")->execute(array($news_id))->fetchOneRow(PDO::FETCH_ASSOC);
56
+		} else {
57
+			$news              = array();
58
+			$news['user_id']   = $user_id;
59
+			$news['gedcom_id'] = $gedcom_id;
60
+			$news['date']      = WT_TIMESTAMP;
61
+			$news['subject']   = '';
62
+			$news['body']      = '';
63
+		}
64
+		echo '<input type="hidden" name="user_id" value="' . $news['user_id'] . '">';
65
+		echo '<input type="hidden" name="gedcom_id" value="' . $news['gedcom_id'] . '">';
66
+		echo '<input type="hidden" name="date" value="' . $news['date'] . '">';
67
+		echo '<table>';
68
+		echo '<tr><th style="text-align:start;">' . I18N::translate('Title') . '</th><tr>';
69
+		echo '<tr><td><input type="text" name="title" size="50" dir="auto" autofocus value="' . $news['subject'] . '"></td></tr>';
70
+		echo '<tr><th style="text-align:start;">' . I18N::translate('Content') . '</th></tr>';
71
+		echo '<tr><td>';
72
+		echo '<textarea name="text" class="html-edit" cols="80" rows="10" dir="auto">' . Filter::escapeHtml($news['body']) . '</textarea>';
73
+		echo '</td></tr>';
74
+		echo '<tr><td><input type="submit" value="' . I18N::translate('save') . '"></td></tr>';
75
+		echo '</table>';
76
+		echo '</form>';
77
+		break;
78
+	case 'save':
79
+		if ($news_id) {
80
+			Database::prepare("UPDATE `##news` SET subject=?, body=?, updated=FROM_UNIXTIME(?) WHERE news_id=?")->execute(array($title, $text, $date, $news_id));
81
+		} else {
82
+			Database::prepare("INSERT INTO `##news` (user_id, gedcom_id, subject, body, updated) VALUES (NULLIF(?, ''), NULLIF(?, '') ,? ,?, CURRENT_TIMESTAMP)")->execute(array($user_id, $gedcom_id, $title, $text));
83
+		}
84 84
 
85
-	$controller->addInlineJavascript('window.opener.location.reload();window.close();');
86
-	break;
85
+		$controller->addInlineJavascript('window.opener.location.reload();window.close();');
86
+		break;
87 87
 }
Please login to merge, or discard this patch.
autocomplete.php 1 patch
Switch Indentation   +424 added lines, -424 removed lines patch added patch discarded remove patch
@@ -31,471 +31,471 @@
 block discarded – undo
31 31
 $type = Filter::get('field');
32 32
 
33 33
 switch ($type) {
34
-case 'ASSO': // Associates of an individuals, whose name contains the search terms
35
-	$data = array();
36
-	// Fetch all data, regardless of privacy
37
-	$rows = Database::prepare(
38
-		"SELECT 'INDI' AS type, i_id AS xref, i_gedcom AS gedcom, n_full" .
39
-		" FROM `##individuals`" .
40
-		" JOIN `##name` ON i_id = n_id AND i_file = n_file" .
41
-		" WHERE (n_full LIKE CONCAT('%', REPLACE(:term_1, ' ', '%'), '%') OR n_surn LIKE CONCAT('%', REPLACE(:term_2, ' ', '%'), '%')) AND i_file = :tree_id" .
42
-		" ORDER BY n_full COLLATE :collate"
43
-	)->execute(array(
44
-		'term_1'  => $term,
45
-		'term_2'  => $term,
46
-		'tree_id' => $WT_TREE->getTreeId(),
47
-		'collate' => I18N::collation(),
48
-	))->fetchAll();
49
-
50
-	// Filter for privacy and whether they could be alive at the right time
51
-	$event_date = Filter::get('extra');
52
-	$date       = new Date($event_date);
53
-	$event_jd   = $date->julianDay();
54
-	foreach ($rows as $row) {
55
-		$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
56
-		if ($person->canShow()) {
57
-			if ($event_jd) {
58
-				// Exclude individuals who were born after the event.
59
-				$person_birth_jd = $person->getEstimatedBirthDate()->minimumJulianDay();
60
-				if ($person_birth_jd && $person_birth_jd > $event_jd) {
61
-					continue;
34
+	case 'ASSO': // Associates of an individuals, whose name contains the search terms
35
+		$data = array();
36
+		// Fetch all data, regardless of privacy
37
+		$rows = Database::prepare(
38
+			"SELECT 'INDI' AS type, i_id AS xref, i_gedcom AS gedcom, n_full" .
39
+			" FROM `##individuals`" .
40
+			" JOIN `##name` ON i_id = n_id AND i_file = n_file" .
41
+			" WHERE (n_full LIKE CONCAT('%', REPLACE(:term_1, ' ', '%'), '%') OR n_surn LIKE CONCAT('%', REPLACE(:term_2, ' ', '%'), '%')) AND i_file = :tree_id" .
42
+			" ORDER BY n_full COLLATE :collate"
43
+		)->execute(array(
44
+			'term_1'  => $term,
45
+			'term_2'  => $term,
46
+			'tree_id' => $WT_TREE->getTreeId(),
47
+			'collate' => I18N::collation(),
48
+		))->fetchAll();
49
+
50
+		// Filter for privacy and whether they could be alive at the right time
51
+		$event_date = Filter::get('extra');
52
+		$date       = new Date($event_date);
53
+		$event_jd   = $date->julianDay();
54
+		foreach ($rows as $row) {
55
+			$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
56
+			if ($person->canShow()) {
57
+				if ($event_jd) {
58
+					// Exclude individuals who were born after the event.
59
+					$person_birth_jd = $person->getEstimatedBirthDate()->minimumJulianDay();
60
+					if ($person_birth_jd && $person_birth_jd > $event_jd) {
61
+						continue;
62
+					}
63
+					// Exclude individuals who died before the event.
64
+					$person_death_jd = $person->getEstimatedDeathDate()->maximumJulianDay();
65
+					if ($person_death_jd && $person_death_jd < $event_jd) {
66
+						continue;
67
+					}
62 68
 				}
63
-				// Exclude individuals who died before the event.
64
-				$person_death_jd = $person->getEstimatedDeathDate()->maximumJulianDay();
65
-				if ($person_death_jd && $person_death_jd < $event_jd) {
66
-					continue;
69
+				// Add the age (if we have it) or the lifespan (if we do not).
70
+				$label = $person->getFullName();
71
+				if ($event_jd && $person->getBirthDate()->isOK()) {
72
+					$label .= ', <span class="age">(' . I18N::translate('Age') . ' ' . Date::getAge($person->getBirthDate(), $date, 0) . ')</span>';
73
+				} else {
74
+					$label .= ', <i>' . $person->getLifeSpan() . '</i>';
67 75
 				}
68
-			}
69
-			// Add the age (if we have it) or the lifespan (if we do not).
70
-			$label = $person->getFullName();
71
-			if ($event_jd && $person->getBirthDate()->isOK()) {
72
-				$label .= ', <span class="age">(' . I18N::translate('Age') . ' ' . Date::getAge($person->getBirthDate(), $date, 0) . ')</span>';
73
-			} else {
74
-				$label .= ', <i>' . $person->getLifeSpan() . '</i>';
75
-			}
76
-			$data[$row->xref] = array('value' => $row->xref, 'label' => $label);
77
-		}
78
-	}
79
-	echo json_encode($data);
80
-
81
-	return;
82
-
83
-case 'CEME': // Cemetery fields, that contain the search term
84
-	$data = array();
85
-	// Fetch all data, regardless of privacy
86
-	$rows = Database::prepare(
87
-		"SELECT i_id AS xref, i_gedcom AS gedcom" .
88
-		" FROM `##individuals`" .
89
-		" WHERE i_gedcom LIKE '%\n2 CEME %' AND i_file = :tree_id" .
90
-		" ORDER BY SUBSTRING_INDEX(i_gedcom, '\n2 CEME ', -1) COLLATE :collation"
91
-	)->execute(array(
92
-		'tree_id'   => $WT_TREE->getTreeId(),
93
-		'collation' => I18N::collation(),
94
-	))->fetchAll();
95
-	// Filter for privacy
96
-	foreach ($rows as $row) {
97
-		$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
98
-		if (preg_match('/\n2 CEME (.*' . preg_quote($term, '/') . '.*)/i', $person->getGedcom(), $match)) {
99
-			if (!in_array($match[1], $data)) {
100
-				$data[] = $match[1];
76
+				$data[$row->xref] = array('value' => $row->xref, 'label' => $label);
101 77
 			}
102 78
 		}
103
-	}
104
-	echo json_encode($data);
105
-
106
-	return;
107
-
108
-case 'FAM': // Families, whose name contains the search terms
109
-	$data = array();
110
-	// Fetch all data, regardless of privacy
111
-	$rows = get_FAM_rows($WT_TREE, $term);
112
-	// Filter for privacy
113
-	foreach ($rows as $row) {
114
-		$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
115
-		if ($family->canShowName()) {
116
-			$marriage_year = $family->getMarriageYear();
117
-			if ($marriage_year) {
118
-				$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>');
119
-			} else {
120
-				$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
121
-			}
122
-		}
123
-	}
124
-	echo json_encode($data);
125
-
126
-	return;
127
-
128
-case 'GIVN': // Given names, that start with the search term
129
-	// Do not filter by privacy. Given names on their own do not identify individuals.
130
-	echo json_encode(
131
-		Database::prepare(
132
-			"SELECT DISTINCT n_givn" .
133
-			" FROM `##name`" .
134
-			" WHERE n_givn LIKE CONCAT(:term, '%') AND n_file = :tree_id" .
135
-			" ORDER BY n_givn COLLATE :collation"
79
+		echo json_encode($data);
80
+
81
+		return;
82
+
83
+	case 'CEME': // Cemetery fields, that contain the search term
84
+		$data = array();
85
+		// Fetch all data, regardless of privacy
86
+		$rows = Database::prepare(
87
+			"SELECT i_id AS xref, i_gedcom AS gedcom" .
88
+			" FROM `##individuals`" .
89
+			" WHERE i_gedcom LIKE '%\n2 CEME %' AND i_file = :tree_id" .
90
+			" ORDER BY SUBSTRING_INDEX(i_gedcom, '\n2 CEME ', -1) COLLATE :collation"
136 91
 		)->execute(array(
137
-			'term'      => $term,
138 92
 			'tree_id'   => $WT_TREE->getTreeId(),
139 93
 			'collation' => I18N::collation(),
140
-		))->fetchOneColumn()
141
-	);
142
-
143
-	return;
144
-
145
-case 'INDI': // Individuals, whose name contains the search terms
146
-	$data = array();
147
-	// Fetch all data, regardless of privacy
148
-	$rows = Database::prepare(
149
-		"SELECT i_id AS xref, i_gedcom AS gedcom, n_full" .
150
-		" FROM `##individuals`" .
151
-		" JOIN `##name` ON i_id = n_id AND i_file = n_file" .
152
-		" WHERE (n_full LIKE CONCAT('%', REPLACE(:term_1, ' ', '%'), '%') OR n_surn LIKE CONCAT('%', REPLACE(:term_2, ' ', '%'), '%')) AND i_file = :tree_id" .
153
-		" ORDER BY n_full COLLATE :collation"
154
-	)->execute(array(
155
-		'term_1'    => $term,
156
-		'term_2'    => $term,
157
-		'tree_id'   => $WT_TREE->getTreeId(),
158
-		'collation' => I18N::collation(),
159
-	))->fetchAll();
160
-	// Filter for privacy
161
-	foreach ($rows as $row) {
162
-		$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
163
-		if ($person->canShowName()) {
164
-			$data[] = array('value' => $row->xref, 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>');
165
-		}
166
-	}
167
-	echo json_encode($data);
168
-
169
-	return;
170
-
171
-case 'NOTE': // Notes which contain the search terms
172
-	$data = array();
173
-	// Fetch all data, regardless of privacy
174
-	$rows = get_NOTE_rows($WT_TREE, $term);
175
-	// Filter for privacy
176
-	foreach ($rows as $row) {
177
-		$note = Note::getInstance($row->xref, $WT_TREE, $row->gedcom);
178
-		if ($note->canShowName()) {
179
-			$data[] = array('value' => $note->getXref(), 'label' => $note->getFullName());
180
-		}
181
-	}
182
-	echo json_encode($data);
183
-
184
-	return;
185
-
186
-case 'OBJE':
187
-	$data = array();
188
-	// Fetch all data, regardless of privacy
189
-	$rows = get_OBJE_rows($WT_TREE, $term);
190
-	// Filter for privacy
191
-	foreach ($rows as $row) {
192
-		$media = Media::getInstance($row->xref, $WT_TREE, $row->gedcom);
193
-		if ($media->canShowName()) {
194
-			$data[] = array('value' => $row->xref, 'label' => '<img src="' . $media->getHtmlUrlDirect() . '" width="25"> ' . $media->getFullName());
195
-		}
196
-	}
197
-	echo json_encode($data);
198
-
199
-	return;
200
-
201
-case 'PLAC': // Place names (with hierarchy), that include the search term
202
-	// Do not filter by privacy. Place names on their own do not identify individuals.
203
-	$data = array();
204
-	foreach (Place::findPlaces($term, $WT_TREE) as $place) {
205
-		$data[] = $place->getGedcomName();
206
-	}
207
-	if (!$data && $WT_TREE->getPreference('GEONAMES_ACCOUNT')) {
208
-		// No place found? Use an external gazetteer
209
-		$url =
210
-			"http://api.geonames.org/searchJSON" .
211
-			"?name_startsWith=" . urlencode($term) .
212
-			"&lang=" . WT_LOCALE .
213
-			"&fcode=CMTY&fcode=ADM4&fcode=PPL&fcode=PPLA&fcode=PPLC" .
214
-			"&style=full" .
215
-			"&username=" . $WT_TREE->getPreference('GEONAMES_ACCOUNT');
216
-		// try to use curl when file_get_contents not allowed
217
-		if (ini_get('allow_url_fopen')) {
218
-			$json = file_get_contents($url);
219
-		} elseif (function_exists('curl_init')) {
220
-			$ch = curl_init();
221
-			curl_setopt($ch, CURLOPT_URL, $url);
222
-			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
223
-			$json = curl_exec($ch);
224
-			curl_close($ch);
225
-		} else {
226
-			return $data;
94
+		))->fetchAll();
95
+		// Filter for privacy
96
+		foreach ($rows as $row) {
97
+			$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
98
+			if (preg_match('/\n2 CEME (.*' . preg_quote($term, '/') . '.*)/i', $person->getGedcom(), $match)) {
99
+				if (!in_array($match[1], $data)) {
100
+					$data[] = $match[1];
101
+				}
102
+			}
227 103
 		}
228
-		$places = json_decode($json, true);
229
-		if (isset($places['geonames']) && is_array($places['geonames'])) {
230
-			foreach ($places['geonames'] as $k => $place) {
231
-				$data[] = $place['name'] . ', ' . $place['adminName2'] . ', ' . $place['adminName1'] . ', ' . $place['countryName'];
104
+		echo json_encode($data);
105
+
106
+		return;
107
+
108
+	case 'FAM': // Families, whose name contains the search terms
109
+		$data = array();
110
+		// Fetch all data, regardless of privacy
111
+		$rows = get_FAM_rows($WT_TREE, $term);
112
+		// Filter for privacy
113
+		foreach ($rows as $row) {
114
+			$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
115
+			if ($family->canShowName()) {
116
+				$marriage_year = $family->getMarriageYear();
117
+				if ($marriage_year) {
118
+					$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>');
119
+				} else {
120
+					$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
121
+				}
232 122
 			}
233 123
 		}
234
-	}
235
-	echo json_encode($data);
236
-
237
-	return;
238
-
239
-case 'PLAC2': // Place names (without hierarchy), that include the search term
240
-	// Do not filter by privacy. Place names on their own do not identify individuals.
241
-	echo json_encode(
242
-		Database::prepare(
243
-			"SELECT p_place" .
244
-			" FROM `##places`" .
245
-			" WHERE p_place LIKE CONCAT('%', :term, '%') AND p_file = :tree_id" .
246
-			" ORDER BY p_place COLLATE :collation"
124
+		echo json_encode($data);
125
+
126
+		return;
127
+
128
+	case 'GIVN': // Given names, that start with the search term
129
+		// Do not filter by privacy. Given names on their own do not identify individuals.
130
+		echo json_encode(
131
+			Database::prepare(
132
+				"SELECT DISTINCT n_givn" .
133
+				" FROM `##name`" .
134
+				" WHERE n_givn LIKE CONCAT(:term, '%') AND n_file = :tree_id" .
135
+				" ORDER BY n_givn COLLATE :collation"
136
+			)->execute(array(
137
+				'term'      => $term,
138
+				'tree_id'   => $WT_TREE->getTreeId(),
139
+				'collation' => I18N::collation(),
140
+			))->fetchOneColumn()
141
+		);
142
+
143
+		return;
144
+
145
+	case 'INDI': // Individuals, whose name contains the search terms
146
+		$data = array();
147
+		// Fetch all data, regardless of privacy
148
+		$rows = Database::prepare(
149
+			"SELECT i_id AS xref, i_gedcom AS gedcom, n_full" .
150
+			" FROM `##individuals`" .
151
+			" JOIN `##name` ON i_id = n_id AND i_file = n_file" .
152
+			" WHERE (n_full LIKE CONCAT('%', REPLACE(:term_1, ' ', '%'), '%') OR n_surn LIKE CONCAT('%', REPLACE(:term_2, ' ', '%'), '%')) AND i_file = :tree_id" .
153
+			" ORDER BY n_full COLLATE :collation"
247 154
 		)->execute(array(
248
-			'term'      => $term,
155
+			'term_1'    => $term,
156
+			'term_2'    => $term,
249 157
 			'tree_id'   => $WT_TREE->getTreeId(),
250 158
 			'collation' => I18N::collation(),
251
-		))->fetchOneColumn()
252
-	);
253
-
254
-	return;
255
-
256
-case 'REPO': // Repositories, that include the search terms
257
-	$data = array();
258
-	// Fetch all data, regardless of privacy
259
-	$rows = get_REPO_rows($WT_TREE, $term);
260
-	// Filter for privacy
261
-	foreach ($rows as $row) {
262
-		$record = Repository::getInstance($row->xref, $WT_TREE, $row->gedcom);
263
-		if ($record->canShowName()) {
264
-			foreach ($record->getFacts('NAME') as $fact) {
265
-				$data[] = array('value' => $record->getXref(), 'label' => $fact->getValue());
159
+		))->fetchAll();
160
+		// Filter for privacy
161
+		foreach ($rows as $row) {
162
+			$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
163
+			if ($person->canShowName()) {
164
+				$data[] = array('value' => $row->xref, 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>');
266 165
 			}
267 166
 		}
268
-	}
269
-	echo json_encode($data);
270
-
271
-	return;
272
-
273
-case 'REPO_NAME': // Repository names, that include the search terms
274
-	$data = array();
275
-	// Fetch all data, regardless of privacy
276
-	$rows = get_REPO_rows($WT_TREE, $term);
277
-	// Filter for privacy
278
-	foreach ($rows as $row) {
279
-		$record = Repository::getInstance($row->xref, $WT_TREE, $row->gedcom);
280
-		if ($record->canShowName()) {
281
-			$data[] = strip_tags($record->getFullName());
167
+		echo json_encode($data);
168
+
169
+		return;
170
+
171
+	case 'NOTE': // Notes which contain the search terms
172
+		$data = array();
173
+		// Fetch all data, regardless of privacy
174
+		$rows = get_NOTE_rows($WT_TREE, $term);
175
+		// Filter for privacy
176
+		foreach ($rows as $row) {
177
+			$note = Note::getInstance($row->xref, $WT_TREE, $row->gedcom);
178
+			if ($note->canShowName()) {
179
+				$data[] = array('value' => $note->getXref(), 'label' => $note->getFullName());
180
+			}
282 181
 		}
283
-	}
284
-	echo json_encode($data);
285
-
286
-	return;
287
-
288
-case 'SOUR': // Sources, that include the search terms
289
-	$data = array();
290
-	// Fetch all data, regardless of privacy
291
-	$rows = get_SOUR_rows($WT_TREE, $term);
292
-	// Filter for privacy
293
-	foreach ($rows as $row) {
294
-		$record = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
295
-		if ($record->canShowName()) {
296
-			foreach ($record->getFacts('TITL') as $fact) {
297
-				$data[] = array('value' => $record->getXref(), 'label' => $fact->getValue());
182
+		echo json_encode($data);
183
+
184
+		return;
185
+
186
+	case 'OBJE':
187
+		$data = array();
188
+		// Fetch all data, regardless of privacy
189
+		$rows = get_OBJE_rows($WT_TREE, $term);
190
+		// Filter for privacy
191
+		foreach ($rows as $row) {
192
+			$media = Media::getInstance($row->xref, $WT_TREE, $row->gedcom);
193
+			if ($media->canShowName()) {
194
+				$data[] = array('value' => $row->xref, 'label' => '<img src="' . $media->getHtmlUrlDirect() . '" width="25"> ' . $media->getFullName());
298 195
 			}
299 196
 		}
300
-	}
301
-	echo json_encode($data);
197
+		echo json_encode($data);
302 198
 
303
-	return;
199
+		return;
304 200
 
305
-case 'PAGE': // Citation details, for a given source, that contain the search term
306
-	$data = array();
307
-	$sid  = Filter::get('extra', WT_REGEX_XREF);
308
-	// Fetch all data, regardless of privacy
309
-	$rows = Database::prepare(
310
-		"SELECT i_id AS xref, i_gedcom AS gedcom" .
311
-		" FROM `##individuals`" .
312
-		" WHERE i_gedcom LIKE CONCAT('%\n_ SOUR @', :xref, '@%', REPLACE(:term, ' ', '%'), '%') AND i_file = :tree_id"
313
-	)->execute(array(
314
-		'xref'    => $sid,
315
-		'term'    => $term,
316
-		'tree_id' => $WT_TREE->getTreeId(),
317
-	))->fetchAll();
318
-	// Filter for privacy
319
-	foreach ($rows as $row) {
320
-		$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
321
-		if (preg_match('/\n1 SOUR @' . $sid . '@(?:\n[2-9].*)*\n2 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $person->getGedcom(), $match)) {
322
-			$data[] = $match[1];
201
+	case 'PLAC': // Place names (with hierarchy), that include the search term
202
+		// Do not filter by privacy. Place names on their own do not identify individuals.
203
+		$data = array();
204
+		foreach (Place::findPlaces($term, $WT_TREE) as $place) {
205
+			$data[] = $place->getGedcomName();
323 206
 		}
324
-		if (preg_match('/\n2 SOUR @' . $sid . '@(?:\n[3-9].*)*\n3 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $person->getGedcom(), $match)) {
325
-			$data[] = $match[1];
207
+		if (!$data && $WT_TREE->getPreference('GEONAMES_ACCOUNT')) {
208
+			// No place found? Use an external gazetteer
209
+			$url =
210
+				"http://api.geonames.org/searchJSON" .
211
+				"?name_startsWith=" . urlencode($term) .
212
+				"&lang=" . WT_LOCALE .
213
+				"&fcode=CMTY&fcode=ADM4&fcode=PPL&fcode=PPLA&fcode=PPLC" .
214
+				"&style=full" .
215
+				"&username=" . $WT_TREE->getPreference('GEONAMES_ACCOUNT');
216
+			// try to use curl when file_get_contents not allowed
217
+			if (ini_get('allow_url_fopen')) {
218
+				$json = file_get_contents($url);
219
+			} elseif (function_exists('curl_init')) {
220
+				$ch = curl_init();
221
+				curl_setopt($ch, CURLOPT_URL, $url);
222
+				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
223
+				$json = curl_exec($ch);
224
+				curl_close($ch);
225
+			} else {
226
+				return $data;
227
+			}
228
+			$places = json_decode($json, true);
229
+			if (isset($places['geonames']) && is_array($places['geonames'])) {
230
+				foreach ($places['geonames'] as $k => $place) {
231
+					$data[] = $place['name'] . ', ' . $place['adminName2'] . ', ' . $place['adminName1'] . ', ' . $place['countryName'];
232
+				}
233
+			}
326 234
 		}
327
-	}
328
-	// Fetch all data, regardless of privacy
329
-	$rows = Database::prepare(
330
-		"SELECT f_id AS xref, f_gedcom AS gedcom" .
331
-		" FROM `##families`" .
332
-		" WHERE f_gedcom LIKE CONCAT('%\n_ SOUR @', :xref, '@%', REPLACE(:term, ' ', '%'), '%') AND f_file = :tree_id"
333
-	)->execute(array(
334
-		'xref'    => $sid,
335
-		'term'    => $term,
336
-		'tree_id' => $WT_TREE->getTreeId(),
337
-	))->fetchAll();
338
-	// Filter for privacy
339
-	foreach ($rows as $row) {
340
-		$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
341
-		if (preg_match('/\n1 SOUR @' . $sid . '@(?:\n[2-9].*)*\n2 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $family->getGedcom(), $match)) {
342
-			$data[] = $match[1];
235
+		echo json_encode($data);
236
+
237
+		return;
238
+
239
+	case 'PLAC2': // Place names (without hierarchy), that include the search term
240
+		// Do not filter by privacy. Place names on their own do not identify individuals.
241
+		echo json_encode(
242
+			Database::prepare(
243
+				"SELECT p_place" .
244
+				" FROM `##places`" .
245
+				" WHERE p_place LIKE CONCAT('%', :term, '%') AND p_file = :tree_id" .
246
+				" ORDER BY p_place COLLATE :collation"
247
+			)->execute(array(
248
+				'term'      => $term,
249
+				'tree_id'   => $WT_TREE->getTreeId(),
250
+				'collation' => I18N::collation(),
251
+			))->fetchOneColumn()
252
+		);
253
+
254
+		return;
255
+
256
+	case 'REPO': // Repositories, that include the search terms
257
+		$data = array();
258
+		// Fetch all data, regardless of privacy
259
+		$rows = get_REPO_rows($WT_TREE, $term);
260
+		// Filter for privacy
261
+		foreach ($rows as $row) {
262
+			$record = Repository::getInstance($row->xref, $WT_TREE, $row->gedcom);
263
+			if ($record->canShowName()) {
264
+				foreach ($record->getFacts('NAME') as $fact) {
265
+					$data[] = array('value' => $record->getXref(), 'label' => $fact->getValue());
266
+				}
267
+			}
343 268
 		}
344
-		if (preg_match('/\n2 SOUR @' . $sid . '@(?:\n[3-9].*)*\n3 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $family->getGedcom(), $match)) {
345
-			$data[] = $match[1];
269
+		echo json_encode($data);
270
+
271
+		return;
272
+
273
+	case 'REPO_NAME': // Repository names, that include the search terms
274
+		$data = array();
275
+		// Fetch all data, regardless of privacy
276
+		$rows = get_REPO_rows($WT_TREE, $term);
277
+		// Filter for privacy
278
+		foreach ($rows as $row) {
279
+			$record = Repository::getInstance($row->xref, $WT_TREE, $row->gedcom);
280
+			if ($record->canShowName()) {
281
+				$data[] = strip_tags($record->getFullName());
282
+			}
346 283
 		}
347
-	}
348
-	// array_unique() converts the keys from integer to string, which breaks
349
-	// the JSON encoding - so need to call array_values() to convert them
350
-	// back into integers.
351
-	$data = array_values(array_unique($data));
352
-	echo json_encode($data);
353
-
354
-	return;
355
-
356
-case 'SOUR_TITL': // Source titles, that include the search terms
357
-	$data = array();
358
-	// Fetch all data, regardless of privacy
359
-	$rows = Database::prepare(
360
-		"SELECT s_id AS xref, s_gedcom AS gedcom, s_name" .
361
-		" FROM `##sources`" .
362
-		" WHERE s_name LIKE CONCAT('%', REPLACE(:term, ' ', '%'), '%') AND s_file = :tree_id" .
363
-		" ORDER BY s_name COLLATE :collation"
364
-	)->execute(array(
365
-		'term'      => $term,
366
-		'tree_id'   => $WT_TREE->getTreeId(),
367
-		'collation' => I18N::collation(),
368
-	))->fetchAll();
369
-	// Filter for privacy
370
-	foreach ($rows as $row) {
371
-		$source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
372
-		if ($source->canShowName()) {
373
-			$data[] = $row->s_name;
284
+		echo json_encode($data);
285
+
286
+		return;
287
+
288
+	case 'SOUR': // Sources, that include the search terms
289
+		$data = array();
290
+		// Fetch all data, regardless of privacy
291
+		$rows = get_SOUR_rows($WT_TREE, $term);
292
+		// Filter for privacy
293
+		foreach ($rows as $row) {
294
+			$record = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
295
+			if ($record->canShowName()) {
296
+				foreach ($record->getFacts('TITL') as $fact) {
297
+					$data[] = array('value' => $record->getXref(), 'label' => $fact->getValue());
298
+				}
299
+			}
374 300
 		}
375
-	}
376
-	echo json_encode($data);
377
-
378
-	return;
379
-
380
-case 'SURN': // Surnames, that start with the search term
381
-	// Do not filter by privacy. Surnames on their own do not identify individuals.
382
-	echo json_encode(
383
-		Database::prepare(
384
-			"SELECT DISTINCT n_surname" .
385
-			" FROM `##name`" .
386
-			" WHERE n_surname LIKE CONCAT(:term, '%') AND n_file = :tree_id" .
387
-			" ORDER BY n_surname COLLATE :collation"
301
+		echo json_encode($data);
302
+
303
+		return;
304
+
305
+	case 'PAGE': // Citation details, for a given source, that contain the search term
306
+		$data = array();
307
+		$sid  = Filter::get('extra', WT_REGEX_XREF);
308
+		// Fetch all data, regardless of privacy
309
+		$rows = Database::prepare(
310
+			"SELECT i_id AS xref, i_gedcom AS gedcom" .
311
+			" FROM `##individuals`" .
312
+			" WHERE i_gedcom LIKE CONCAT('%\n_ SOUR @', :xref, '@%', REPLACE(:term, ' ', '%'), '%') AND i_file = :tree_id"
313
+		)->execute(array(
314
+			'xref'    => $sid,
315
+			'term'    => $term,
316
+			'tree_id' => $WT_TREE->getTreeId(),
317
+		))->fetchAll();
318
+		// Filter for privacy
319
+		foreach ($rows as $row) {
320
+			$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
321
+			if (preg_match('/\n1 SOUR @' . $sid . '@(?:\n[2-9].*)*\n2 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $person->getGedcom(), $match)) {
322
+				$data[] = $match[1];
323
+			}
324
+			if (preg_match('/\n2 SOUR @' . $sid . '@(?:\n[3-9].*)*\n3 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $person->getGedcom(), $match)) {
325
+				$data[] = $match[1];
326
+			}
327
+		}
328
+		// Fetch all data, regardless of privacy
329
+		$rows = Database::prepare(
330
+			"SELECT f_id AS xref, f_gedcom AS gedcom" .
331
+			" FROM `##families`" .
332
+			" WHERE f_gedcom LIKE CONCAT('%\n_ SOUR @', :xref, '@%', REPLACE(:term, ' ', '%'), '%') AND f_file = :tree_id"
333
+		)->execute(array(
334
+			'xref'    => $sid,
335
+			'term'    => $term,
336
+			'tree_id' => $WT_TREE->getTreeId(),
337
+		))->fetchAll();
338
+		// Filter for privacy
339
+		foreach ($rows as $row) {
340
+			$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
341
+			if (preg_match('/\n1 SOUR @' . $sid . '@(?:\n[2-9].*)*\n2 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $family->getGedcom(), $match)) {
342
+				$data[] = $match[1];
343
+			}
344
+			if (preg_match('/\n2 SOUR @' . $sid . '@(?:\n[3-9].*)*\n3 PAGE (.*' . str_replace(' ', '.+', preg_quote($term, '/')) . '.*)/i', $family->getGedcom(), $match)) {
345
+				$data[] = $match[1];
346
+			}
347
+		}
348
+		// array_unique() converts the keys from integer to string, which breaks
349
+		// the JSON encoding - so need to call array_values() to convert them
350
+		// back into integers.
351
+		$data = array_values(array_unique($data));
352
+		echo json_encode($data);
353
+
354
+		return;
355
+
356
+	case 'SOUR_TITL': // Source titles, that include the search terms
357
+		$data = array();
358
+		// Fetch all data, regardless of privacy
359
+		$rows = Database::prepare(
360
+			"SELECT s_id AS xref, s_gedcom AS gedcom, s_name" .
361
+			" FROM `##sources`" .
362
+			" WHERE s_name LIKE CONCAT('%', REPLACE(:term, ' ', '%'), '%') AND s_file = :tree_id" .
363
+			" ORDER BY s_name COLLATE :collation"
388 364
 		)->execute(array(
389 365
 			'term'      => $term,
390 366
 			'tree_id'   => $WT_TREE->getTreeId(),
391 367
 			'collation' => I18N::collation(),
392
-		))->fetchOneColumn()
393
-	);
394
-
395
-	return;
396
-
397
-case 'IFSRO':
398
-	$data = array();
399
-	// Fetch all data, regardless of privacy
400
-	$rows = get_INDI_rows($WT_TREE, $term);
401
-	// Filter for privacy
402
-	foreach ($rows as $row) {
403
-		$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
404
-		if ($person->canShowName()) {
405
-			$data[] = array('value' => $person->getXref(), 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>');
368
+		))->fetchAll();
369
+		// Filter for privacy
370
+		foreach ($rows as $row) {
371
+			$source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
372
+			if ($source->canShowName()) {
373
+				$data[] = $row->s_name;
374
+			}
406 375
 		}
407
-	}
408
-	// Fetch all data, regardless of privacy
409
-	$rows = get_SOUR_rows($WT_TREE, $term);
410
-	// Filter for privacy
411
-	foreach ($rows as $row) {
412
-		$source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
413
-		if ($source->canShowName()) {
414
-			$data[] = array('value' => $source->getXref(), 'label' => $source->getFullName());
376
+		echo json_encode($data);
377
+
378
+		return;
379
+
380
+	case 'SURN': // Surnames, that start with the search term
381
+		// Do not filter by privacy. Surnames on their own do not identify individuals.
382
+		echo json_encode(
383
+			Database::prepare(
384
+				"SELECT DISTINCT n_surname" .
385
+				" FROM `##name`" .
386
+				" WHERE n_surname LIKE CONCAT(:term, '%') AND n_file = :tree_id" .
387
+				" ORDER BY n_surname COLLATE :collation"
388
+			)->execute(array(
389
+				'term'      => $term,
390
+				'tree_id'   => $WT_TREE->getTreeId(),
391
+				'collation' => I18N::collation(),
392
+			))->fetchOneColumn()
393
+		);
394
+
395
+		return;
396
+
397
+	case 'IFSRO':
398
+		$data = array();
399
+		// Fetch all data, regardless of privacy
400
+		$rows = get_INDI_rows($WT_TREE, $term);
401
+		// Filter for privacy
402
+		foreach ($rows as $row) {
403
+			$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
404
+			if ($person->canShowName()) {
405
+				$data[] = array('value' => $person->getXref(), 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>');
406
+			}
415 407
 		}
416
-	}
417
-	// Fetch all data, regardless of privacy
418
-	$rows = get_REPO_rows($WT_TREE, $term);
419
-	// Filter for privacy
420
-	foreach ($rows as $row) {
421
-		$repository = Repository::getInstance($row->xref, $WT_TREE, $row->gedcom);
422
-		if ($repository->canShowName()) {
423
-			$data[] = array('value' => $repository->getXref(), 'label' => $repository->getFullName());
408
+		// Fetch all data, regardless of privacy
409
+		$rows = get_SOUR_rows($WT_TREE, $term);
410
+		// Filter for privacy
411
+		foreach ($rows as $row) {
412
+			$source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
413
+			if ($source->canShowName()) {
414
+				$data[] = array('value' => $source->getXref(), 'label' => $source->getFullName());
415
+			}
424 416
 		}
425
-	}
426
-	// Fetch all data, regardless of privacy
427
-	$rows = get_OBJE_rows($WT_TREE, $term);
428
-	// Filter for privacy
429
-	foreach ($rows as $row) {
430
-		$media = Media::getInstance($row->xref, $WT_TREE, $row->gedcom);
431
-		if ($media->canShowName()) {
432
-			$data[] = array('value' => $media->getXref(), 'label' => '<img src="' . $media->getHtmlUrlDirect() . '" width="25"> ' . $media->getFullName());
417
+		// Fetch all data, regardless of privacy
418
+		$rows = get_REPO_rows($WT_TREE, $term);
419
+		// Filter for privacy
420
+		foreach ($rows as $row) {
421
+			$repository = Repository::getInstance($row->xref, $WT_TREE, $row->gedcom);
422
+			if ($repository->canShowName()) {
423
+				$data[] = array('value' => $repository->getXref(), 'label' => $repository->getFullName());
424
+			}
433 425
 		}
434
-	}
435
-	// Fetch all data, regardless of privacy
436
-	$rows = get_FAM_rows($WT_TREE, $term);
437
-	// Filter for privacy
438
-	foreach ($rows as $row) {
439
-		$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
440
-		if ($family->canShowName()) {
441
-			$marriage_year = $family->getMarriageYear();
442
-			if ($marriage_year) {
443
-				$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>');
444
-			} else {
445
-				$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
426
+		// Fetch all data, regardless of privacy
427
+		$rows = get_OBJE_rows($WT_TREE, $term);
428
+		// Filter for privacy
429
+		foreach ($rows as $row) {
430
+			$media = Media::getInstance($row->xref, $WT_TREE, $row->gedcom);
431
+			if ($media->canShowName()) {
432
+				$data[] = array('value' => $media->getXref(), 'label' => '<img src="' . $media->getHtmlUrlDirect() . '" width="25"> ' . $media->getFullName());
433
+			}
434
+		}
435
+		// Fetch all data, regardless of privacy
436
+		$rows = get_FAM_rows($WT_TREE, $term);
437
+		// Filter for privacy
438
+		foreach ($rows as $row) {
439
+			$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
440
+			if ($family->canShowName()) {
441
+				$marriage_year = $family->getMarriageYear();
442
+				if ($marriage_year) {
443
+					$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>');
444
+				} else {
445
+					$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
446
+				}
446 447
 			}
447 448
 		}
448
-	}
449
-	// Fetch all data, regardless of privacy
450
-	$rows = get_NOTE_rows($WT_TREE, $term);
451
-	// Filter for privacy
452
-	foreach ($rows as $row) {
453
-		$note = Note::getInstance($row->xref, $WT_TREE, $row->gedcom);
454
-		if ($note->canShowName()) {
455
-			$data[] = array('value' => $note->getXref(), 'label' => $note->getFullName());
449
+		// Fetch all data, regardless of privacy
450
+		$rows = get_NOTE_rows($WT_TREE, $term);
451
+		// Filter for privacy
452
+		foreach ($rows as $row) {
453
+			$note = Note::getInstance($row->xref, $WT_TREE, $row->gedcom);
454
+			if ($note->canShowName()) {
455
+				$data[] = array('value' => $note->getXref(), 'label' => $note->getFullName());
456
+			}
456 457
 		}
457
-	}
458
-	echo json_encode($data);
459
-
460
-	return;
461
-
462
-case 'IFS':
463
-	$data = array();
464
-	// Fetch all data, regardless of privacy
465
-	$rows = get_INDI_rows($WT_TREE, $term);
466
-	// Filter for privacy
467
-	foreach ($rows as $row) {
468
-		$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
469
-		if ($person->canShowName()) {
470
-			$data[] = array('value' => $person->getXref(), 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>');
458
+		echo json_encode($data);
459
+
460
+		return;
461
+
462
+	case 'IFS':
463
+		$data = array();
464
+		// Fetch all data, regardless of privacy
465
+		$rows = get_INDI_rows($WT_TREE, $term);
466
+		// Filter for privacy
467
+		foreach ($rows as $row) {
468
+			$person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
469
+			if ($person->canShowName()) {
470
+				$data[] = array('value' => $person->getXref(), 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>');
471
+			}
471 472
 		}
472
-	}
473
-	// Fetch all data, regardless of privacy
474
-	$rows = get_SOUR_rows($WT_TREE, $term);
475
-	// Filter for privacy
476
-	foreach ($rows as $row) {
477
-		$source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
478
-		if ($source->canShowName()) {
479
-			$data[] = array('value' => $source->getXref(), 'label' => $source->getFullName());
473
+		// Fetch all data, regardless of privacy
474
+		$rows = get_SOUR_rows($WT_TREE, $term);
475
+		// Filter for privacy
476
+		foreach ($rows as $row) {
477
+			$source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom);
478
+			if ($source->canShowName()) {
479
+				$data[] = array('value' => $source->getXref(), 'label' => $source->getFullName());
480
+			}
480 481
 		}
481
-	}
482
-	// Fetch all data, regardless of privacy
483
-	$rows = get_FAM_rows($WT_TREE, $term);
484
-	// Filter for privacy
485
-	foreach ($rows as $row) {
486
-		$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
487
-		if ($family->canShowName()) {
488
-			$marriage_year = $family->getMarriageYear();
489
-			if ($marriage_year) {
490
-				$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>');
491
-			} else {
492
-				$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
482
+		// Fetch all data, regardless of privacy
483
+		$rows = get_FAM_rows($WT_TREE, $term);
484
+		// Filter for privacy
485
+		foreach ($rows as $row) {
486
+			$family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
487
+			if ($family->canShowName()) {
488
+				$marriage_year = $family->getMarriageYear();
489
+				if ($marriage_year) {
490
+					$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>');
491
+				} else {
492
+					$data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
493
+				}
493 494
 			}
494 495
 		}
495
-	}
496
-	echo json_encode($data);
496
+		echo json_encode($data);
497 497
 
498
-	return;
498
+		return;
499 499
 }
500 500
 
501 501
 /**
Please login to merge, or discard this patch.
admin_media.php 1 patch
Switch Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -85,98 +85,98 @@  discard block
 block discarded – undo
85 85
 ////////////////////////////////////////////////////////////////////////////////
86 86
 
87 87
 switch ($action) {
88
-case 'load_json':
89
-	$search = Filter::get('search');
90
-	$search = $search['value'];
91
-	$start  = Filter::getInteger('start');
92
-	$length = Filter::getInteger('length');
93
-
94
-	switch ($files) {
95
-	case 'local':
96
-		// Filtered rows
97
-		$SELECT1 =
98
-			"SELECT SQL_CALC_FOUND_ROWS TRIM(LEADING :media_path_1 FROM m_filename) AS media_path, m_id AS xref, m_titl, m_file AS gedcom_id, m_gedcom AS gedcom" .
99
-			" FROM  `##media`" .
100
-			" JOIN  `##gedcom_setting` ON (m_file = gedcom_id AND setting_name = 'MEDIA_DIRECTORY')" .
101
-			" JOIN  `##gedcom` USING (gedcom_id)" .
102
-			" WHERE setting_value = :media_folder" .
103
-			" AND   m_filename LIKE CONCAT(:media_path_2, '%')" .
104
-			" AND   (SUBSTRING_INDEX(m_filename, '/', -1) LIKE CONCAT('%', :search_1, '%')" .
105
-			"  OR   m_titl LIKE CONCAT('%', :search_2, '%'))" .
106
-			" AND   m_filename NOT LIKE 'http://%'" .
107
-			" AND   m_filename NOT LIKE 'https://%'";
108
-		$ARGS1 = array(
109
-			'media_path_1' => $media_path,
110
-			'media_folder' => $media_folder,
111
-			'media_path_2' => Filter::escapeLike($media_path),
112
-			'search_1'     => Filter::escapeLike($search),
113
-			'search_2'     => Filter::escapeLike($search),
114
-		);
115
-		// Unfiltered rows
116
-		$SELECT2 =
117
-			"SELECT COUNT(*)" .
118
-			" FROM  `##media`" .
119
-			" JOIN  `##gedcom_setting` ON (m_file = gedcom_id AND setting_name = 'MEDIA_DIRECTORY')" .
120
-			" WHERE setting_value = :media_folder" .
121
-			" AND   m_filename LIKE CONCAT(:media_path_3, '%')" .
122
-			" AND   m_filename NOT LIKE 'http://%'" .
123
-			" AND   m_filename NOT LIKE 'https://%'";
124
-		$ARGS2 = array(
125
-			'media_folder' => $media_folder,
126
-			'media_path_3' => $media_path,
127
-		);
128
-
129
-		if ($subfolders == 'exclude') {
130
-			$SELECT1 .= " AND m_filename NOT LIKE CONCAT(:media_path_4, '%/%')";
131
-			$ARGS1['media_path_4'] = Filter::escapeLike($media_path);
132
-			$SELECT2 .= " AND m_filename NOT LIKE CONCAT(:media_path_4, '%/%')";
133
-			$ARGS2['media_path_4'] = Filter::escapeLike($media_path);
134
-		}
135
-
136
-		$order = Filter::getArray('order');
137
-		$SELECT1 .= " ORDER BY ";
138
-		if ($order) {
139
-			foreach ($order as $key => $value) {
140
-				if ($key > 0) {
141
-					$SELECT1 .= ',';
88
+	case 'load_json':
89
+		$search = Filter::get('search');
90
+		$search = $search['value'];
91
+		$start  = Filter::getInteger('start');
92
+		$length = Filter::getInteger('length');
93
+
94
+		switch ($files) {
95
+			case 'local':
96
+				// Filtered rows
97
+				$SELECT1 =
98
+					"SELECT SQL_CALC_FOUND_ROWS TRIM(LEADING :media_path_1 FROM m_filename) AS media_path, m_id AS xref, m_titl, m_file AS gedcom_id, m_gedcom AS gedcom" .
99
+					" FROM  `##media`" .
100
+					" JOIN  `##gedcom_setting` ON (m_file = gedcom_id AND setting_name = 'MEDIA_DIRECTORY')" .
101
+					" JOIN  `##gedcom` USING (gedcom_id)" .
102
+					" WHERE setting_value = :media_folder" .
103
+					" AND   m_filename LIKE CONCAT(:media_path_2, '%')" .
104
+					" AND   (SUBSTRING_INDEX(m_filename, '/', -1) LIKE CONCAT('%', :search_1, '%')" .
105
+					"  OR   m_titl LIKE CONCAT('%', :search_2, '%'))" .
106
+					" AND   m_filename NOT LIKE 'http://%'" .
107
+					" AND   m_filename NOT LIKE 'https://%'";
108
+				$ARGS1 = array(
109
+					'media_path_1' => $media_path,
110
+					'media_folder' => $media_folder,
111
+					'media_path_2' => Filter::escapeLike($media_path),
112
+					'search_1'     => Filter::escapeLike($search),
113
+					'search_2'     => Filter::escapeLike($search),
114
+				);
115
+				// Unfiltered rows
116
+				$SELECT2 =
117
+					"SELECT COUNT(*)" .
118
+					" FROM  `##media`" .
119
+					" JOIN  `##gedcom_setting` ON (m_file = gedcom_id AND setting_name = 'MEDIA_DIRECTORY')" .
120
+					" WHERE setting_value = :media_folder" .
121
+					" AND   m_filename LIKE CONCAT(:media_path_3, '%')" .
122
+					" AND   m_filename NOT LIKE 'http://%'" .
123
+					" AND   m_filename NOT LIKE 'https://%'";
124
+				$ARGS2 = array(
125
+					'media_folder' => $media_folder,
126
+					'media_path_3' => $media_path,
127
+				);
128
+
129
+				if ($subfolders == 'exclude') {
130
+					$SELECT1 .= " AND m_filename NOT LIKE CONCAT(:media_path_4, '%/%')";
131
+					$ARGS1['media_path_4'] = Filter::escapeLike($media_path);
132
+					$SELECT2 .= " AND m_filename NOT LIKE CONCAT(:media_path_4, '%/%')";
133
+					$ARGS2['media_path_4'] = Filter::escapeLike($media_path);
142 134
 				}
143
-				// Datatables numbers columns 0, 1, 2
144
-				// MySQL numbers columns 1, 2, 3
145
-				switch ($value['dir']) {
146
-				case 'asc':
147
-					$SELECT1 .= ":col_" . $key . " ASC";
148
-					break;
149
-				case 'desc':
150
-					$SELECT1 .= ":col_" . $key . " DESC";
151
-					break;
135
+
136
+				$order = Filter::getArray('order');
137
+				$SELECT1 .= " ORDER BY ";
138
+				if ($order) {
139
+					foreach ($order as $key => $value) {
140
+						if ($key > 0) {
141
+							$SELECT1 .= ',';
142
+						}
143
+						// Datatables numbers columns 0, 1, 2
144
+						// MySQL numbers columns 1, 2, 3
145
+						switch ($value['dir']) {
146
+							case 'asc':
147
+								$SELECT1 .= ":col_" . $key . " ASC";
148
+								break;
149
+							case 'desc':
150
+								$SELECT1 .= ":col_" . $key . " DESC";
151
+								break;
152
+						}
153
+					$ARGS1['col_' . $key] = 1 + $value['column'];
152 154
 				}
153
-				$ARGS1['col_' . $key] = 1 + $value['column'];
155
+			} else {
156
+				$SELECT1 = " 1 ASC";
154 157
 			}
155
-		} else {
156
-			$SELECT1 = " 1 ASC";
157
-		}
158 158
 
159
-		if ($length > 0) {
160
-			$SELECT1 .= " LIMIT :length OFFSET :start";
161
-			$ARGS1['length'] = $length;
162
-			$ARGS1['start']  = $start;
163
-		}
164
-
165
-		$rows = Database::prepare($SELECT1)->execute($ARGS1)->fetchAll();
166
-		// Total filtered/unfiltered rows
167
-		$recordsFiltered = Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
168
-		$recordsTotal    = Database::prepare($SELECT2)->execute($ARGS2)->fetchOne();
159
+			if ($length > 0) {
160
+				$SELECT1 .= " LIMIT :length OFFSET :start";
161
+				$ARGS1['length'] = $length;
162
+				$ARGS1['start']  = $start;
163
+			}
169 164
 
170
-		$data = array();
171
-		foreach ($rows as $row) {
172
-			$media  = Media::getInstance($row->xref, Tree::findById($row->gedcom_id), $row->gedcom);
173
-			$data[] = array(
174
-				mediaFileInfo($media_folder, $media_path, $row->media_path),
175
-				$media->displayImage(),
176
-				mediaObjectInfo($media),
177
-			);
178
-		}
179
-		break;
165
+			$rows = Database::prepare($SELECT1)->execute($ARGS1)->fetchAll();
166
+			// Total filtered/unfiltered rows
167
+			$recordsFiltered = Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
168
+			$recordsTotal    = Database::prepare($SELECT2)->execute($ARGS2)->fetchOne();
169
+
170
+			$data = array();
171
+			foreach ($rows as $row) {
172
+				$media  = Media::getInstance($row->xref, Tree::findById($row->gedcom_id), $row->gedcom);
173
+				$data[] = array(
174
+					mediaFileInfo($media_folder, $media_path, $row->media_path),
175
+					$media->displayImage(),
176
+					mediaObjectInfo($media),
177
+				);
178
+			}
179
+			break;
180 180
 
181 181
 	case 'external':
182 182
 		// Filtered rows
@@ -206,12 +206,12 @@  discard block
 block discarded – undo
206 206
 				// Datatables numbers columns 0, 1, 2
207 207
 				// MySQL numbers columns 1, 2, 3
208 208
 				switch ($value['dir']) {
209
-				case 'asc':
210
-					$SELECT1 .= ":col_" . $key . " ASC";
211
-					break;
212
-				case 'desc':
213
-					$SELECT1 .= ":col_" . $key . " DESC";
214
-					break;
209
+					case 'asc':
210
+						$SELECT1 .= ":col_" . $key . " ASC";
211
+						break;
212
+					case 'desc':
213
+						$SELECT1 .= ":col_" . $key . " DESC";
214
+						break;
215 215
 				}
216 216
 				$ARGS1['col_' . $key] = 1 + $value['column'];
217 217
 			}
Please login to merge, or discard this patch.
admin_site_access.php 1 patch
Switch Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -38,75 +38,75 @@  discard block
 block discarded – undo
38 38
 
39 39
 // Form actions
40 40
 switch (Filter::post('action')) {
41
-case 'save':
42
-	if (Filter::checkCsrf()) {
43
-		$site_access_rule_id = Filter::postInteger('site_access_rule_id');
44
-		$ip_address_start    = Filter::post('ip_address_start', WT_REGEX_IPV4);
45
-		$ip_address_end      = Filter::post('ip_address_end', WT_REGEX_IPV4);
46
-		$user_agent_pattern  = Filter::post('user_agent_pattern');
47
-		$rule                = Filter::post('rule', 'allow|deny|robot');
48
-		$comment             = Filter::post('comment');
49
-		$user_agent_string   = Filter::server('HTTP_USER_AGENT');
50
-		$ip_address          = WT_CLIENT_IP;
51
-
52
-		if ($ip_address_start !== null && $ip_address_end !== null && $user_agent_pattern !== null && $rule !== null) {
53
-			// This doesn't work with named placeholders. The :user_agent_string parameter is not recognised.
54
-			$oops = $rule !== 'allow' && Database::prepare(
55
-				"SELECT INET_ATON(:ip_address) BETWEEN INET_ATON(:ip_address_start) AND INET_ATON(:ip_address_end)" .
56
-				" AND :user_agent_string LIKE :user_agent_pattern"
57
-			)->execute(array(
58
-				'ip_address'         => $ip_address,
59
-				'ip_address_start'   => $ip_address_start,
60
-				'ip_address_end'     => $ip_address_end,
61
-				'user_agent_string'  => $user_agent_string,
62
-				'user_agent_pattern' => $user_agent_pattern,
63
-			))->fetchOne();
64
-
65
-			if ($oops) {
66
-				FlashMessages::addMessage(I18N::translate('You cannot create a rule which would prevent yourself from accessing the website.'), 'danger');
67
-			} elseif ($site_access_rule_id === null) {
68
-				Database::prepare(
69
-					"INSERT INTO `##site_access_rule` (ip_address_start, ip_address_end, user_agent_pattern, rule, comment) VALUES (INET_ATON(:ip_address_start), INET_ATON(:ip_address_end), :user_agent_pattern, :rule, :comment)"
70
-				)->execute(array(
71
-					'ip_address_start'    => $ip_address_start,
72
-					'ip_address_end'      => $ip_address_end,
73
-					'user_agent_pattern'  => $user_agent_pattern,
74
-					'rule'                => $rule,
75
-					'comment'             => $comment,
76
-				));
77
-				FlashMessages::addMessage(I18N::translate('The website access rule has been created.'), 'success');
78
-			} else {
79
-				Database::prepare(
80
-					"UPDATE `##site_access_rule` SET ip_address_start = INET_ATON(:ip_address_start), ip_address_end = INET_ATON(:ip_address_end), user_agent_pattern = :user_agent_pattern, rule = :rule, comment = :comment WHERE site_access_rule_id = :site_access_rule_id"
41
+	case 'save':
42
+		if (Filter::checkCsrf()) {
43
+			$site_access_rule_id = Filter::postInteger('site_access_rule_id');
44
+			$ip_address_start    = Filter::post('ip_address_start', WT_REGEX_IPV4);
45
+			$ip_address_end      = Filter::post('ip_address_end', WT_REGEX_IPV4);
46
+			$user_agent_pattern  = Filter::post('user_agent_pattern');
47
+			$rule                = Filter::post('rule', 'allow|deny|robot');
48
+			$comment             = Filter::post('comment');
49
+			$user_agent_string   = Filter::server('HTTP_USER_AGENT');
50
+			$ip_address          = WT_CLIENT_IP;
51
+
52
+			if ($ip_address_start !== null && $ip_address_end !== null && $user_agent_pattern !== null && $rule !== null) {
53
+				// This doesn't work with named placeholders. The :user_agent_string parameter is not recognised.
54
+				$oops = $rule !== 'allow' && Database::prepare(
55
+					"SELECT INET_ATON(:ip_address) BETWEEN INET_ATON(:ip_address_start) AND INET_ATON(:ip_address_end)" .
56
+					" AND :user_agent_string LIKE :user_agent_pattern"
81 57
 				)->execute(array(
82
-					'ip_address_start'    => $ip_address_start,
83
-					'ip_address_end'      => $ip_address_end,
84
-					'user_agent_pattern'  => $user_agent_pattern,
85
-					'rule'                => $rule,
86
-					'comment'             => $comment,
87
-					'site_access_rule_id' => $site_access_rule_id,
88
-				));
89
-				FlashMessages::addMessage(I18N::translate('The website access rule has been updated.'), 'success');
58
+					'ip_address'         => $ip_address,
59
+					'ip_address_start'   => $ip_address_start,
60
+					'ip_address_end'     => $ip_address_end,
61
+					'user_agent_string'  => $user_agent_string,
62
+					'user_agent_pattern' => $user_agent_pattern,
63
+				))->fetchOne();
64
+
65
+				if ($oops) {
66
+					FlashMessages::addMessage(I18N::translate('You cannot create a rule which would prevent yourself from accessing the website.'), 'danger');
67
+				} elseif ($site_access_rule_id === null) {
68
+					Database::prepare(
69
+						"INSERT INTO `##site_access_rule` (ip_address_start, ip_address_end, user_agent_pattern, rule, comment) VALUES (INET_ATON(:ip_address_start), INET_ATON(:ip_address_end), :user_agent_pattern, :rule, :comment)"
70
+					)->execute(array(
71
+						'ip_address_start'    => $ip_address_start,
72
+						'ip_address_end'      => $ip_address_end,
73
+						'user_agent_pattern'  => $user_agent_pattern,
74
+						'rule'                => $rule,
75
+						'comment'             => $comment,
76
+					));
77
+					FlashMessages::addMessage(I18N::translate('The website access rule has been created.'), 'success');
78
+				} else {
79
+					Database::prepare(
80
+						"UPDATE `##site_access_rule` SET ip_address_start = INET_ATON(:ip_address_start), ip_address_end = INET_ATON(:ip_address_end), user_agent_pattern = :user_agent_pattern, rule = :rule, comment = :comment WHERE site_access_rule_id = :site_access_rule_id"
81
+					)->execute(array(
82
+						'ip_address_start'    => $ip_address_start,
83
+						'ip_address_end'      => $ip_address_end,
84
+						'user_agent_pattern'  => $user_agent_pattern,
85
+						'rule'                => $rule,
86
+						'comment'             => $comment,
87
+						'site_access_rule_id' => $site_access_rule_id,
88
+					));
89
+					FlashMessages::addMessage(I18N::translate('The website access rule has been updated.'), 'success');
90
+				}
90 91
 			}
91 92
 		}
92
-	}
93
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
93
+		header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
94 94
 
95
-	return;
95
+		return;
96 96
 
97
-case 'delete':
98
-	if (Filter::checkCsrf()) {
99
-		$site_access_rule_id = Filter::postInteger('site_access_rule_id');
100
-		Database::prepare(
101
-			"DELETE FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
102
-		)->execute(array(
103
-			'site_access_rule_id' => $site_access_rule_id,
104
-		));
105
-		FlashMessages::addMessage(I18N::translate('The website access rule has been deleted.'), 'success');
106
-	}
107
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
97
+	case 'delete':
98
+		if (Filter::checkCsrf()) {
99
+			$site_access_rule_id = Filter::postInteger('site_access_rule_id');
100
+			Database::prepare(
101
+				"DELETE FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
102
+			)->execute(array(
103
+				'site_access_rule_id' => $site_access_rule_id,
104
+			));
105
+			FlashMessages::addMessage(I18N::translate('The website access rule has been deleted.'), 'success');
106
+		}
107
+		header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
108 108
 
109
-	return;
109
+		return;
110 110
 }
111 111
 
112 112
 // Delete any "unknown" visitors that are now "known".
@@ -128,50 +128,50 @@  discard block
 block discarded – undo
128 128
 
129 129
 $action = Filter::get('action');
130 130
 switch ($action) {
131
-case 'load':
132
-	// AJAX callback for datatables
133
-	$search = Filter::get('search');
134
-	$search = $search['value'];
135
-	$start  = Filter::getInteger('start');
136
-	$length = Filter::getInteger('length');
137
-
138
-	$sql =
139
-		"SELECT SQL_CALC_FOUND_ROWS" .
140
-		" '', INET_NTOA(ip_address_start), ip_address_start, INET_NTOA(ip_address_end), ip_address_end, user_agent_pattern, rule, comment, site_access_rule_id" .
141
-		" FROM `##site_access_rule`";
142
-	$args = array();
143
-
144
-	if ($search) {
145
-		$sql .=
146
-			" WHERE (INET_ATON(:search_1) BETWEEN ip_address_start AND ip_address_end" .
147
-			" OR INET_NTOA(ip_address_start) LIKE CONCAT('%', :search_2, '%')" .
148
-			" OR INET_NTOA(ip_address_end) LIKE CONCAT('%', :search_3, '%')" .
149
-			" OR user_agent_pattern LIKE CONCAT('%', :search_4, '%')" .
150
-			" OR comment LIKE CONCAT('%', :search_5, '%'))";
151
-		$args['search_1'] = Filter::escapeLike($search);
152
-		$args['search_2'] = Filter::escapeLike($search);
153
-		$args['search_3'] = Filter::escapeLike($search);
154
-		$args['search_4'] = Filter::escapeLike($search);
155
-		$args['search_5'] = Filter::escapeLike($search);
156
-	}
131
+	case 'load':
132
+		// AJAX callback for datatables
133
+		$search = Filter::get('search');
134
+		$search = $search['value'];
135
+		$start  = Filter::getInteger('start');
136
+		$length = Filter::getInteger('length');
137
+
138
+		$sql =
139
+			"SELECT SQL_CALC_FOUND_ROWS" .
140
+			" '', INET_NTOA(ip_address_start), ip_address_start, INET_NTOA(ip_address_end), ip_address_end, user_agent_pattern, rule, comment, site_access_rule_id" .
141
+			" FROM `##site_access_rule`";
142
+		$args = array();
143
+
144
+		if ($search) {
145
+			$sql .=
146
+				" WHERE (INET_ATON(:search_1) BETWEEN ip_address_start AND ip_address_end" .
147
+				" OR INET_NTOA(ip_address_start) LIKE CONCAT('%', :search_2, '%')" .
148
+				" OR INET_NTOA(ip_address_end) LIKE CONCAT('%', :search_3, '%')" .
149
+				" OR user_agent_pattern LIKE CONCAT('%', :search_4, '%')" .
150
+				" OR comment LIKE CONCAT('%', :search_5, '%'))";
151
+			$args['search_1'] = Filter::escapeLike($search);
152
+			$args['search_2'] = Filter::escapeLike($search);
153
+			$args['search_3'] = Filter::escapeLike($search);
154
+			$args['search_4'] = Filter::escapeLike($search);
155
+			$args['search_5'] = Filter::escapeLike($search);
156
+		}
157 157
 
158
-	$order = Filter::getArray('order');
159
-	$sql .= ' ORDER BY';
160
-	if ($order) {
161
-		foreach ($order as $key => $value) {
162
-			if ($key > 0) {
163
-				$sql .= ',';
164
-			}
165
-			// Datatables numbers columns 0, 1, 2
166
-			// MySQL numbers columns 1, 2, 3
167
-			switch ($value['dir']) {
168
-			case 'asc':
169
-				$sql .= " :col_" . $key . " ASC";
170
-				break;
171
-			case 'desc':
172
-				$sql .= " :col_" . $key . " DESC";
173
-				break;
174
-			}
158
+		$order = Filter::getArray('order');
159
+		$sql .= ' ORDER BY';
160
+		if ($order) {
161
+			foreach ($order as $key => $value) {
162
+				if ($key > 0) {
163
+					$sql .= ',';
164
+				}
165
+				// Datatables numbers columns 0, 1, 2
166
+				// MySQL numbers columns 1, 2, 3
167
+				switch ($value['dir']) {
168
+					case 'asc':
169
+						$sql .= " :col_" . $key . " ASC";
170
+						break;
171
+					case 'desc':
172
+						$sql .= " :col_" . $key . " DESC";
173
+						break;
174
+				}
175 175
 			$args['col_' . $key] = 1 + $value['column'];
176 176
 		}
177 177
 	} else {
@@ -210,31 +210,31 @@  discard block
 block discarded – undo
210 210
 	));
211 211
 	break;
212 212
 
213
-case 'edit':
214
-case 'create':
215
-	if (Filter::get('action') === 'edit') {
216
-		$controller->setPageTitle(I18N::translate('Edit a website access rule'));
217
-	} else {
218
-		$controller->setPageTitle(I18N::translate('Create a website access rule'));
219
-	}
213
+	case 'edit':
214
+	case 'create':
215
+		if (Filter::get('action') === 'edit') {
216
+			$controller->setPageTitle(I18N::translate('Edit a website access rule'));
217
+		} else {
218
+			$controller->setPageTitle(I18N::translate('Create a website access rule'));
219
+		}
220 220
 
221
-	$controller->pageHeader();
221
+		$controller->pageHeader();
222 222
 
223
-	$site_access_rule = Database::prepare(
224
-		"SELECT site_access_rule_id, INET_NTOA(ip_address_start) AS ip_address_start, INET_NTOA(ip_address_end) AS ip_address_end, user_agent_pattern, rule, comment" .
225
-		" FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
226
-	)->execute(array(
227
-		'site_access_rule_id' => Filter::getInteger('site_access_rule_id'),
228
-	))->fetchOneRow();
223
+		$site_access_rule = Database::prepare(
224
+			"SELECT site_access_rule_id, INET_NTOA(ip_address_start) AS ip_address_start, INET_NTOA(ip_address_end) AS ip_address_end, user_agent_pattern, rule, comment" .
225
+			" FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
226
+		)->execute(array(
227
+			'site_access_rule_id' => Filter::getInteger('site_access_rule_id'),
228
+		))->fetchOneRow();
229 229
 
230
-	$site_access_rule_id = $site_access_rule ? $site_access_rule->site_access_rule_id : null;
231
-	$ip_address_start    = $site_access_rule ? $site_access_rule->ip_address_start : '0.0.0.0';
232
-	$ip_address_end      = $site_access_rule ? $site_access_rule->ip_address_end : '255.255.255.255';
233
-	$user_agent_pattern  = $site_access_rule ? $site_access_rule->user_agent_pattern : '%';
234
-	$rule                = $site_access_rule ? $site_access_rule->rule : 'allow';
235
-	$comment             = $site_access_rule ? $site_access_rule->comment : '';
230
+		$site_access_rule_id = $site_access_rule ? $site_access_rule->site_access_rule_id : null;
231
+		$ip_address_start    = $site_access_rule ? $site_access_rule->ip_address_start : '0.0.0.0';
232
+		$ip_address_end      = $site_access_rule ? $site_access_rule->ip_address_end : '255.255.255.255';
233
+		$user_agent_pattern  = $site_access_rule ? $site_access_rule->user_agent_pattern : '%';
234
+		$rule                = $site_access_rule ? $site_access_rule->rule : 'allow';
235
+		$comment             = $site_access_rule ? $site_access_rule->comment : '';
236 236
 
237
-	?>
237
+		?>
238 238
 	<ol class="breadcrumb small">
239 239
 		<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
240 240
 		<li><a href="admin_site_access.php"><?php echo I18N::translate('Website access rules'); ?></a></li>
@@ -311,12 +311,12 @@  discard block
 block discarded – undo
311 311
 	</form>
312 312
 
313 313
 	<?php
314
-	break;
314
+		break;
315 315
 
316
-default:
317
-	$controller
318
-		->pageHeader()
319
-		->addInlineJavascript('
316
+	default:
317
+		$controller
318
+			->pageHeader()
319
+			->addInlineJavascript('
320 320
 			jQuery.fn.dataTableExt.oSort["unicode-asc" ]=function(a,b) {return a.replace(/<[^<]*>/, "").localeCompare(b.replace(/<[^<]*>/, ""))};
321 321
 			jQuery.fn.dataTableExt.oSort["unicode-desc"]=function(a,b) {return b.replace(/<[^<]*>/, "").localeCompare(a.replace(/<[^<]*>/, ""))};
322 322
 			jQuery(".table-site-access-rules").dataTable({
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 			});
341 341
 		');
342 342
 
343
-	?>
343
+		?>
344 344
 	<ol class="breadcrumb small">
345 345
 		<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
346 346
 		<li class="active"><?php echo $controller->getPageTitle(); ?></li>
@@ -381,5 +381,5 @@  discard block
 block discarded – undo
381 381
 		}
382 382
 	</script>
383 383
 	<?php
384
-	break;
384
+		break;
385 385
 }
Please login to merge, or discard this patch.