BMLT Root Server
csv.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************************/
3 /** \file client_interface/csv/index.php
4 
5  \brief This file is a very simple interface that is designed to return
6  a basic CSV (Comma-Separated Values) string, in response to a search.
7  In order to use this, you need to call: <ROOT SERVER BASE URI>/client_interface/csv/
8  with the same parameters that you would send to an advanced search. The results
9  will be returned as a CSV file.
10 
11  This file can be called from other servers.
12 
13  This file is part of the Basic Meeting List Toolbox (BMLT).
14 
15  Find out more at: https://bmlt.app
16 
17  BMLT is free software: you can redistribute it and/or modify
18  it under the terms of the MIT License.
19 
20  BMLT is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  MIT License for more details.
24 
25  You should have received a copy of the MIT License along with this code.
26  If not, see <https://opensource.org/licenses/MIT>.
27 */
28 
29 require_once(dirname(__FILE__).'/../../server/shared/classes/comdef_utilityclasses.inc.php');
30 require_once(dirname(__FILE__).'/../../server/c_comdef_server.class.php');
31 require_once(dirname(__FILE__).'/../../server/shared/Array2Json.php');
32 require_once(dirname(__FILE__).'/../../server/shared/Array2XML.php');
33 
34 /*******************************************************************/
35 /**
36  \brief Queries the local server, and returns processed CSV data
37 
38  This requires that the "switcher=" parameter be set in the GET or
39  POST parameters:
40  - 'GetSearchResults'
41  This returns the search results.
42 
43  \returns CSV data, with the first row a key header.
44 */
45 function parse_redirect(
46  &$server ///< A reference to an instance of c_comdef_server
47 ) {
48  $result = null;
49  $http_vars = array_merge_recursive($_GET, $_POST);
50 
51  $port = $_SERVER['SERVER_PORT'] ;
52  // IIS puts "off" in the HTTPS field, so we need to test for that.
53  $https = (!empty($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] !== 'off') || ($port == 443)));
54  $server_path = $_SERVER['SERVER_NAME'];
55  $my_path = dirname(dirname(dirname($_SERVER['SCRIPT_NAME'])));
56  $server_path .= trim((($https && ($port != 443)) || (!$https && ($port != 80))) ? ':'.$port : '', '/');
57  $http_vars['bmlt_root'] = 'http'.($https ? 's' : '').'://'.$server_path.$my_path;
58 
59  $langs = array ( $server->GetLocalLang() );
60  $localized_strings = c_comdef_server::GetLocalStrings();
61 
62  if (isset($http_vars['lang_enum'])) {
63  if (!is_array($http_vars['lang_enum'])) {
64  $langs = array ( trim($http_vars['lang_enum']) );
65  } else {
66  $langs = $http_vars['lang_enum'];
67  }
68  }
69 
70  if (!isset($http_vars['switcher'])) {
71  $http_vars['switcher'] = '';
72  }
73 
74  switch ($http_vars['switcher']) {
75  case 'GetSearchResults':
76  $meanLocationData = array();
77  $formats_ar = array();
78 
79  if (isset($http_vars['xml_data'])) {
80  $result2 = GetSearchResults($http_vars, $formats_ar, $meanLocationData);
81  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
82 
83  $blueMeanieXML = '<search_average>';
84  $blueMeanieXML .= '<location>';
85  $blueMeanieXML .= '<latitude>'.$meanLocationData['search_average']['location']['latitude'].'</latitude>';
86  $blueMeanieXML .= '<longitude>'.$meanLocationData['search_average']['location']['longitude'].'</longitude>';
87  $blueMeanieXML .= '</location>';
88  $blueMeanieXML .= '<radius>';
89  $blueMeanieXML .= '<miles>'.$meanLocationData['search_average']['radius']['miles'].'</miles>';
90  $blueMeanieXML .= '<kilometers>'.$meanLocationData['search_average']['radius']['kilometers'].'</kilometers>';
91  $blueMeanieXML .= '</radius>';
92  $blueMeanieXML .= '</search_average>';
93  $blueMeanieXML .= '<search_center>';
94  $blueMeanieXML .= '<location>';
95  $blueMeanieXML .= '<latitude>'.$meanLocationData['search_center']['location']['latitude'].'</latitude>';
96  $blueMeanieXML .= '<longitude>'.$meanLocationData['search_center']['location']['longitude'].'</longitude>';
97  $blueMeanieXML .= '</location>';
98  $blueMeanieXML .= '<radius>';
99  $blueMeanieXML .= '<miles>'.$meanLocationData['search_center']['radius']['miles'].'</miles>';
100  $blueMeanieXML .= '<kilometers>'.$meanLocationData['search_center']['radius']['kilometers'].'</kilometers>';
101  $blueMeanieXML .= '</radius>';
102  $blueMeanieXML .= '</search_center>';
103 
104  if (!isset($http_vars['getMeanLocationData'])) {
105  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', trim(strtolower($_SERVER['SERVER_NAME'])).(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetSearchResults.php'));
106  $result .= "<meetings xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
107  $result .= TranslateToXML($result2);
108  if ((isset($http_vars['get_used_formats']) || isset($http_vars['get_formats_only'])) && $formats_ar && is_array($formats_ar) && count($formats_ar)) {
109  if (isset($http_vars['get_formats_only'])) {
110  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
111  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', trim(strtolower($_SERVER['SERVER_NAME'])).(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetFormats.php'));
112  $result .= "<formats xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
113  } else {
114  $result .= "<formats>";
115  }
116  $result3 = GetFormats($server, $langs, $formats_ar);
117  $result .= TranslateToXML($result3);
118  $result .= "</formats>";
119  }
120 
121  if (!isset($http_vars['get_formats_only'])) {
122  $result .= "<locationInfo>";
123  $result .= $blueMeanieXML;
124  $result .= "</locationInfo>";
125  $result .= "</meetings>";
126  }
127  } else {
128  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', trim(strtolower($_SERVER['SERVER_NAME'])).(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetMeetingLocationInfo.php'));
129  $result .= "<locationInfo xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
130  $result .= $blueMeanieXML;
131  $result .= "</locationInfo>";
132  }
133  } elseif (isset($http_vars['gpx_data'])) {
134  $result2 = GetSearchResults($http_vars, $formats_ar);
135  $result2 = returnArrayFromCSV(explode("\n", $result2));
136  if (is_array($result2) && count($result2)) {
137  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
138  $result .= "<gpx version=\"1.0\" xmlns=\"http://".htmlspecialchars(trim(strtolower($_SERVER['SERVER_NAME'])))."\" xmlns:xsn=\"http://www.w3.org/2001/XMLSchema-instance\" xsn:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">";
139 
140  $minlng = 361;
141  $minlat = 361;
142  $maxlng = -361;
143  $maxlat = -361;
144 
145  foreach ($result2 as $meeting) {
146  $lng = floatval($meeting['longitude']);
147  $lat = floatval($meeting['latitude']);
148 
149  if ($lng || $lat) {
150  $minlng = min($minlng, $lng);
151  $minlat = min($minlat, $lat);
152  $maxlng = max($maxlng, $lng);
153  $maxlat = max($maxlat, $lat);
154  }
155  }
156 
157  $result .= '<bounds minlat="'.htmlspecialchars($minlat).'" minlon="'.htmlspecialchars($minlng).'" maxlat="'.htmlspecialchars($maxlat).'" maxlon="'.htmlspecialchars($maxlng).'"/>';
158 
159  foreach ($result2 as $meeting) {
160  $desc = prepareSimpleLine($meeting);
161 
162  $name = c_comdef_htmlspecialchars(trim(stripslashes($meeting['meeting_name'])));
163  if (!$name) {
164  $name = "NA Meeting";
165  }
166 
167  $lng = floatval($meeting['longitude']);
168  $lat = floatval($meeting['latitude']);
169  $type = 'NA Meeting';
170 
171  if ($lng || $lat) {
172  $result .= '<wpt lat="'.htmlspecialchars($lat).'" lon="'.htmlspecialchars($lng).'">';
173  $result .= '<name><![CDATA['.htmlspecialchars($name).']]></name>';
174  if ($desc) {
175  $result .= '<desc><![CDATA['.htmlspecialchars($desc).']]></desc>';
176  }
177 
178  $result .= '<type><![CDATA['.htmlspecialchars($type).']]></type>';
179  $result .= '<sym>Diamond, Blue</sym>';
180  $result .= '</wpt>';
181  }
182  }
183 
184  $result .= '</gpx>';
185  }
186  } elseif (isset($http_vars['kml_data'])) {
187  $result2 = GetSearchResults($http_vars, $formats_ar);
188  $result2 = returnArrayFromCSV(explode("\n", $result2));
189  if (is_array($result2) && count($result2)) {
190  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
191  $result .= '<kml xmlns="http://www.opengis.net/kml/2.2">';
192  $result .= '<Document>';
193 
194  foreach ($result2 as $meeting) {
195  $desc = prepareSimpleLine($meeting);
196  $address = prepareSimpleLine($meeting, false);
197 
198  $name = c_comdef_htmlspecialchars(trim(stripslashes($meeting['meeting_name'])));
199 
200  if (!$name) {
201  $name = "NA Meeting";
202  }
203 
204  $lng = floatval($meeting['longitude']);
205  $lat = floatval($meeting['latitude']);
206 
207  if ($lng || $lat) {
208  $result .= '<Placemark>';
209  $result .= '<name>'.htmlspecialchars($name).'</name>';
210 
211  if ($address) {
212  $result .= '<address>'.$address.'</address>';
213  }
214 
215  if ($desc) {
216  $result .= '<description>'.$desc.'</description>';
217  }
218 
219  $result .= '<Point>';
220  $result .= '<coordinates>';
221  $result .= htmlspecialchars($lng).','.htmlspecialchars($lat).',0';
222  $result .= '</coordinates>';
223  $result .= '</Point>';
224  $result .= '</Placemark>';
225  }
226  }
227 
228  $result .= '</Document>';
229  $result .= '</kml>';
230  }
231  } elseif (isset($http_vars['poi_data'])) {
232  $result2 = GetSearchResults($http_vars, $formats_ar);
233  $result2 = returnArrayFromCSV(explode("\n", $result2));
234  if (is_array($result2) && count($result2)) {
235  $result = "lon,lat,name,desc\n";
236  foreach ($result2 as $meeting) {
237  $desc = htmlspecialchars_decode(prepareSimpleLine($meeting));
238 
239  $name = trim(stripslashes($meeting['meeting_name']));
240 
241  if (!$name) {
242  $name = "NA Meeting";
243  }
244 
245  $name = addcslashes($name, '"');
246  $desc = addcslashes($desc, '"');
247 
248  $lng = floatval($meeting['longitude']);
249  $lat = floatval($meeting['latitude']);
250 
251  if ($lng || $lat) {
252  $result .= '"'.$lng.'","'.$lat.'","'.$name.'","'.$desc.'"'."\n";
253  }
254  }
255  }
256  } elseif (isset($http_vars['json_data'])) {
257  $result = TranslateToJSON(GetSearchResults($http_vars, $formats_ar, $meanLocationData));
258  if ((isset($http_vars['get_used_formats']) || isset($http_vars['get_formats_only']))) {
259  if (isset($http_vars['get_formats_only'])) {
260  $format_list = '[]';
261  if (isset($formats_ar) && is_array($formats_ar) && count($formats_ar)) {
262  $format_list = TranslateToJSON(GetFormats($server, $langs, $formats_ar));
263  }
264 
265  $result = '{"formats":'.$format_list.'}';
266  } else {
267  if (isset($http_vars['appendMeanLocationData'])) {
268  $result = '{"meetings":'.$result.',"formats":'.TranslateToJSON(GetFormats($server, $langs, $formats_ar)).',"locationInfo":'.array2json($meanLocationData).'}';
269  } else {
270  $format_list = '[]';
271  if (isset($formats_ar) && is_array($formats_ar) && count($formats_ar)) {
272  $format_list = TranslateToJSON(GetFormats($server, $langs, $formats_ar));
273  }
274 
275  $result = '{"meetings":'.$result.',"formats":'.$format_list.'}';
276  }
277  }
278  } else {
279  if (isset($http_vars['getMeanLocationData']) && is_array($meanLocationData) && count($meanLocationData)) {
280  if (isset($http_vars['appendMeanLocationData'])) {
281  $result = '{"meetings":'.$result.',"locationInfo":'.array2json($meanLocationData).'}';
282  } else {
283  $result = array2json(array ( 'locationInfo' => $meanLocationData ));
284  }
285  }
286  }
287  } else {
288  $result2 = GetSearchResults($http_vars, $formats_ar);
289 
290  if (isset($http_vars['get_formats_only'])) {
291  $result2 = GetFormats($server, $langs, $formats_ar);
292 
293  if (!$result2) {
294  $result2 = '[]';
295  }
296  }
297 
298  $result = $result2;
299  }
300  break;
301 
302  case 'GetFormats':
303  $result2 = GetFormats($server, $langs);
304 
305  if (isset($http_vars['xml_data'])) {
306  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
307  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', $_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetFormats.php'));
308  $result .= "<formats xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
309  $result .= TranslateToXML($result2);
310  $result .= "</formats>";
311  } elseif (isset($http_vars['json_data'])) {
312  $result = TranslateToJSON($result2);
313  if (!$result) {
314  $result = '[]';
315  }
316  } else {
317  $result = $result2;
318  }
319  break;
320 
321  case 'GetServiceBodies':
322  $recursive = false;
323  if (isset($http_vars['recursive']) && $http_vars['recursive'] == '1') {
324  $recursive = true;
325  }
326  $services = null;
327  if (isset($http_vars['services'])) {
328  $services = is_array($http_vars['services']) ? $http_vars['services'] : array($http_vars['services']);
329  }
330  $result2 = GetServiceBodies($server, $services, $recursive);
331 
332  if (isset($http_vars['xml_data'])) {
333  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
334  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', $_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetServiceBodies.php'));
335  $result .= "<serviceBodies xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
336  $result .= TranslateToXML($result2);
337  $result .= "</serviceBodies>";
338  } elseif (isset($http_vars['json_data'])) {
339  $result = TranslateToJSON($result2);
340  if (!$result) {
341  $result = '[]';
342  }
343  } else {
344  $result = $result2;
345  }
346  break;
347 
348  case 'GetChanges':
349  $start_date = null;
350  $end_date = null;
351  $meeting_id = null;
352  $service_body_id = null;
353  $meetings_only = true;
354 
355  if (isset($http_vars['start_date'])) {
356  $start_date = strtotime(trim($http_vars['start_date']));
357  }
358 
359  if (isset($http_vars['end_date'])) {
360  $end_date = strtotime(trim($http_vars['end_date']));
361  }
362 
363  if (isset($http_vars['meeting_id'])) {
364  $meeting_id = intval($http_vars['meeting_id']);
365  }
366 
367  if (isset($http_vars['service_body_id'])) {
368  $service_body_id = intval($http_vars['service_body_id']);
369  }
370 
371  $result2 = GetChanges($http_vars, $start_date, $end_date, $meeting_id, $service_body_id);
372 
373  if (isset($http_vars['xml_data'])) {
374  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', $_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetChanges.php'));
375  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><changes xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">".TranslateToXML($result2)."</changes>";
376  } elseif (isset($http_vars['json_data'])) {
377  $result = TranslateToJSON($result2);
378  if (!$result) {
379  $result = '[]';
380  }
381  } else {
382  $result = $result2;
383  }
384  break;
385 
386  case 'GetServerInfo':
387  $result2 = GetServerInfo();
388  if (isset($http_vars['xml_data'])) {
389  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
390  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', $_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/ServerInfo.php'));
391  $result .= "<serverInfo xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
392  $result .= TranslateToXML($result2);
393  $result .= "</serverInfo>";
394  } elseif (isset($http_vars['json_data'])) {
395  $result = TranslateToJSON($result2);
396  } else {
397  $result = $result2;
398  }
399  break;
400 
401  case 'GetNAWSDump':
403  break;
404 
405  case 'GetCoverageArea':
406  $result2 = GetCoverageArea();
407  if (isset($http_vars['xml_data'])) {
408  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
409  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', $_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetCoverageArea.php'));
410  $result .= "<coverageArea xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
411  $result .= TranslateToXML($result2);
412  $result .= "</coverageArea>";
413  } elseif (isset($http_vars['json_data'])) {
414  $result = TranslateToJSON($result2);
415  } else {
416  $result = $result2;
417  }
418  break;
419 
420  case 'GetFieldKeys':
422 
423  if (isset($keys) && is_array($keys) && count($keys)) {
424  $result2 = array ('"key","description"');
425 
426  foreach ($keys as $key) {
427  if (($key['visibility'] != 1) && ($key['key'] != 'published') && ($key['key'] != 'shared_group_id_bigint')) {
428  $result2[] = '"'.$key['key'].'","'.$key['field_prompt'].'"';
429  }
430  }
431 
432  $result2 = implode("\n", $result2);
433 
434  if (isset($http_vars['xml_data'])) {
435  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
436  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', $_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetFieldKeys.php'));
437  $result .= "<fields xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
438  $result .= TranslateToXML($result2);
439  $result .= "</fields>";
440  } elseif (isset($http_vars['json_data'])) {
441  $result = TranslateToJSON($result2);
442  } else {
443  $result = $result2;
444  }
445  }
446  break;
447 
448  case 'GetFieldValues':
449  $meeting_key = trim($http_vars['meeting_key']);
450  $values = c_comdef_meeting::GetAllValuesForKey($meeting_key);
451  if (isset($values) && is_array($values) && count($values)) {
452  $result2 = array ('"'.$meeting_key.'","ids"');
453 
454  foreach ($values as $value => $ids) {
455  if (($meeting_key == 'formats') && isset($http_vars['specific_formats']) && trim($http_vars['specific_formats'])) {
456  $targeted_formats = explode(',', trim($http_vars['specific_formats']));
457  if (is_array($targeted_formats) && count($targeted_formats)) {
458  $targeted_formats = array_map(intval, $targeted_formats);
459  $these_formats = explode("\t", $value);
460 
461  if (is_array($these_formats) && count($these_formats)) {
462  $these_formats = array_map(intval, $these_formats);
463  $value = array_intersect($these_formats, $targeted_formats);
464  if (isset($http_vars['all_formats'])) {
465  $diff = array_diff($targeted_formats, $value);
466  if (isset($diff) && is_array($diff) && count($diff)) {
467  continue;
468  }
469  }
470 
471  if (!count($value)) {
472  continue;
473  } else {
474  $value = implode("\t", $value);
475  }
476  } else {
477  continue;
478  }
479  } else {
480  break;
481  }
482  } elseif ($meeting_key == 'worldid_mixed') {
483  if ($value != 'NULL') {
484  $value = trim($value);
485  }
486  }
487 
488  $ids = explode('\t', $ids);
489  $ids = trim(implode("\t", $ids));
490  $result2[] = '"'.$value.'","'.$ids.'"';
491  }
492 
493  $result3 = array();
494 
495  foreach ($result2 as $resultRow) {
496  list ( $key, $value ) = explode(',', $resultRow);
497 
498  $value = explode("\t", trim($value, '"'));
499  $oldValue = explode("\t", array_key_exists($key, $result3) ? $result3[$key] : "");
500  $value = array_unique(array_merge($value, $oldValue));
501  asort($value);
502  $value = trim(implode("\t", $value));
503  $result3[$key] = $value;
504  }
505 
506  $result2 = array();
507  foreach ($result3 as $key => $value) {
508  $key = str_replace('&APOS&', ',', trim($key, '"'));
509 
510  $result2[] = "\"$key\",\"$value\"";
511  }
512 
513  $result2 = implode("\n", $result2);
514  }
515 
516  if (isset($http_vars['xml_data'])) {
517  $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
518  $xsd_uri = 'http://'.htmlspecialchars(str_replace('/client_interface/xml', '/client_interface/xsd', $_SERVER['SERVER_NAME'].(($_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').dirname($_SERVER['SCRIPT_NAME']).'/GetFieldValues.php'));
519  $result .= "<fields xmlns=\"http://".$_SERVER['SERVER_NAME']."\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://".$_SERVER['SERVER_NAME']." $xsd_uri\">";
520  $result .= str_replace("\t", ',', TranslateToXML($result2));
521  $result .= "</fields>";
522  } elseif (isset($http_vars['json_data'])) {
523  $result = TranslateToJSON($result2);
524  } else {
525  $result = str_replace("\t", ',', $result2);
526  }
527  break;
528 
529  default:
530  $result = HandleDefault($http_vars);
531  break;
532  }
533 
534  return $result;
535 }
536 
537 /*******************************************************************/
538 /**
539  \brief This returns a string, with the meeting's daya, time and location data in a simple string.
540 
541  \returns a string, containing the meeting day, time and location summary.
542 */
544  $meeting, /**< An associative array of meeting data */
545  $withDate = true /**< If false (default is true), the weekday and time will not be added. */
546 ) {
547  $localized_strings = c_comdef_server::GetLocalStrings();
548 
549  $location_borough = array_key_exists('location_city_subsection', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_city_subsection']))) : "";
550  $location_neighborhood = array_key_exists('location_neighborhood', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_neighborhood']))) : "";
551  $location_province = array_key_exists('location_province', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_province']))) : "";
552  $location_nation = array_key_exists('location_nation', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_nation']))) : "";
553  $location_postal_code_1 = array_key_exists('location_postal_code_1', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_postal_code_1']))) : "";
554  $location_text = array_key_exists('location_text', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_text']))) : "";
555  $street = array_key_exists('location_street', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_street']))) : "";
556  $info = array_key_exists('location_info', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_info']))) : "";
557  $town = array_key_exists('location_municipality', $meeting) ? c_comdef_htmlspecialchars(trim(stripslashes($meeting['location_municipality']))) : "";
558  $desc = $withDate ? '' : $location_text;
559 
560  if ($location_borough) {
561  $town = $location_borough;
562  }
563 
564  if ($location_province) {
565  $town = "$town, $location_province";
566  }
567 
568  if ($location_postal_code_1) {
569  $town = "$town, $location_postal_code_1";
570  }
571 
572  if ($location_nation) {
573  $town = "$town, $location_nation";
574  }
575 
576  if ($withDate && $location_neighborhood) {
577  $town = "$town ($location_neighborhood)";
578  }
579 
580  if ($street) {
581  if ($desc) {
582  $desc .= ", ";
583  }
584  $desc .= $street;
585  }
586 
587  if ($town) {
588  if ($desc) {
589  $desc .= ", ";
590  }
591  $desc .= $town;
592  }
593 
594  if ($withDate && $info) {
595  if ($desc) {
596  $desc .= " ($info)";
597  } else {
598  $desc = $info;
599  }
600  }
601 
602  $weekday = intval(trim(stripslashes($meeting['weekday_tinyint'])));
603  $time = date($localized_strings['time_format'], strtotime($meeting['start_time']));
604  $weekday = $localized_strings['comdef_server_admin_strings']['meeting_search_weekdays_names'][$weekday];
605 
606  $ret = null;
607 
608  if ($withDate && $weekday) {
609  $ret = $weekday;
610  }
611 
612  if ($withDate && $time) {
613  if ($ret) {
614  $ret .= ', ';
615  }
616 
617  $ret .= $time;
618  }
619 
620  if ($ret) {
621  $ret .= ', ';
622  }
623 
624  $ret .= $desc;
625 
626  return $ret;
627 }
628 
629 /*******************************************************************/
630 /**
631  \brief
632 */
634  $in_http_Vars, ///< The ID of the Service Body to dump
635  $in_server ///< The Root Server instance
636 ) {
637  $sb = $in_server->GetServiceBodyByIDObj(intval($in_http_Vars['sb_id']));
638 
639  if ($sb) {
640  require_once(dirname(__FILE__).'/search_results_csv.php');
641  $service_bodies = array ( 'services' => c_comdef_server::GetServiceBodyHierarchyIDs(intval($in_http_Vars['sb_id'])) );
642 
643  $cc = preg_replace('|[\W]|', '_', strtoupper(trim($sb->GetWorldID())));
644 
645  if (preg_match('|^_+$|', $cc)) {
646  $cc = '';
647  }
648 
649  $filename = preg_replace('|[\W]|', '_', strtolower(trim($sb->GetLocalName())));
650 
651  if (preg_match('|^_+$|', $filename)) {
652  $filename = '';
653  }
654 
655  $filename .= date('_Y_m_d_H_i_s');
656 
657  if ($cc) {
658  $filename = "$cc"."_$filename";
659  }
660 
661  $sb_array = array("services" => array(), "advanced_published" => 0);
662 
663  // Make sure we all have NAWS IDs.
664  foreach ($service_bodies["services"] as $sbID) {
665  $service_body_object = $in_server->GetServiceBodyByIDObj($sbID);
666  if ($service_body_object && $service_body_object->GetWorldID()) {
667  $sb_array["services"][] = $sbID;
668  }
669  }
670  header("Content-Disposition: attachment; filename=BMLT_$filename.csv");
671  return ReturnNAWSFormatCSV($sb_array, $in_server);
672  }
673 }
674 
675 /*******************************************************************/
676 /**
677  \brief This returns an associative array from the given CSV, which is an array of lines, and the top line is the field names.
678 
679  \returns an associative array. Each main element will be one line, and each line will be an associative array of fields. If a field is not present in the line, it is not included.
680 */
681 function returnArrayFromCSV( $inCSVArray ///< A array of CSV data, split as lines (each element is a single text line of CSV data). the first line is the header (array keys).
682 )
683 {
684  $ret = null;
685 
686  $desc_line = $inCSVArray[0]; // Get the field names.
687  $desc_line = explode('","', trim($desc_line, '"'));
688 
689  for ($index = 1; $index < count($inCSVArray); $index++) {
690  $interim_line = explode('","', trim($inCSVArray[$index], '"'));
691 
692  if ($interim_line && count($interim_line)) {
693  $result = null;
694 
695  $interim_line = array_combine($desc_line, $interim_line);
696 
697  foreach ($interim_line as $key => $value) {
698  $value = trim($value);
699 
700  if ($value) {
701  $result[$key] = $value;
702  }
703  }
704 
705  if (is_array($result) && count($result)) {
706  $ret[] = $result;
707  }
708  }
709  }
710 
711  return $ret;
712 }
713 
714 /*******************************************************************/
715 /**
716  \brief Calculates the distance, in Km, between two long/lat pairs.
717  This uses the Haversine formula.
718  Cribbed from here: http://blog.voltampmedia.com/2011/12/17/php-implementation-of-haversine-computation/
719 
720  \returns A floating-point, positive number. The distance, in miles.
721 */
723  $lat_1, ///< The latitude of the first point, in degrees.
724  $long_1, ///< The longitude of the first point, in degrees.
725  $lat_2, ///< The latitude of the second point, in degrees.
726  $long_2 ///< The longitude of the second point, in degrees.
727 ) {
728  $sin_lat = sin(deg2rad($lat_2 - $lat_1) / 2.0);
729  $sin2_lat = $sin_lat * $sin_lat;
730 
731  $sin_long = sin(deg2rad($long_2 - $long_1) / 2.0);
732  $sin2_long = $sin_long * $sin_long;
733 
734  $cos_lat_1 = cos($lat_1);
735  $cos_lat_2 = cos($lat_2);
736 
737  $sqrt = sqrt($sin2_lat + ($cos_lat_1 * $cos_lat_2 * $sin2_long));
738 
739  $earth_radius = 3963.1676; // in miles
740 
741  $distance = 2.0 * $earth_radius * asin($sqrt);
742 
743  return $distance;
744 }
745 
746 /*******************************************************************/
747 /**
748  \brief This returns the search results, in whatever form was requested.
749 
750  \returns CSV data, with the first row a key header.
751 */
753  $in_http_vars, ///< The HTTP GET and POST parameters.
754  &$formats_ar = null, ///< This will return the formats used in this search.
755  &$meanLocationData = null ///< This is a passed in receptacle for some location data calculations.
756 ) {
757  if (!( isset($in_http_vars['geo_width']) && $in_http_vars['geo_width'] ) && isset($in_http_vars['bmlt_search_type']) && ($in_http_vars['bmlt_search_type'] == 'advanced') && isset($in_http_vars['advanced_radius']) && isset($in_http_vars['advanced_mapmode']) && $in_http_vars['advanced_mapmode'] && ( floatval($in_http_vars['advanced_radius'] != 0.0) ) && isset($in_http_vars['lat_val']) && isset($in_http_vars['long_val']) && ( (floatval($in_http_vars['lat_val']) != 0.0) || (floatval($in_http_vars['long_val']) != 0.0) )) {
758  $in_http_vars['geo_width'] = $in_http_vars['advanced_radius'];
759  } elseif (!( isset($in_http_vars['geo_width']) && $in_http_vars['geo_width'] ) && isset($in_http_vars['bmlt_search_type']) && ($in_http_vars['bmlt_search_type'] == 'advanced')) {
760  $in_http_vars['lat_val'] = null;
761  $in_http_vars['long_val'] = null;
762  } elseif (!isset($in_http_vars['geo_loc']) || $in_http_vars['geo_loc'] != 'yes') {
763  if (!isset($in_http_vars['geo_width'])) {
764  $in_http_vars['geo_width'] = 0;
765  }
766  }
767 
768  require_once(dirname(__FILE__).'/search_results_csv.php');
769  $geocode_results = null;
770  $ignore_me = null;
771  $meeting_objects = array();
772  $result = DisplaySearchResultsCSV($in_http_vars, $ignore_me, $geocode_results, $meeting_objects);
773  $locationData = array ( );
774 
775  if (is_array($meeting_objects) && count($meeting_objects)) {
776  foreach ($meeting_objects as $one_meeting) {
777  if (isset($in_http_vars['getMeanLocationData']) || (isset($meanLocationData)&& is_array($meanLocationData))) {
778  $locationData[] = array ( 'long' => floatval($one_meeting->GetMeetingDataValue('longitude')), 'lat' => floatval($one_meeting->GetMeetingDataValue('latitude')) );
779  }
780 
781  if (is_array($formats_ar)) {
782  $formats = $one_meeting->GetMeetingDataValue('formats');
783 
784  foreach ($formats as $format) {
785  if ($format && ($format instanceof c_comdef_format)) {
786  $format_shared_id = $format->GetSharedID();
787  $formats_ar[$format_shared_id] = $format;
788  }
789  }
790  }
791  }
792  }
793 
794  if (count($locationData)) { // If the caller just wants an average location report, then give them that.
795  $avgLong = 0.0;
796  $avgLat = 0.0;
797  $minLong = 1000.0;
798  $maxLong = -1000.0;
799  $minLat = 1000.0;
800  $maxLat = -1000.0;
801 
802  foreach ($locationData as $location) {
803  $avgLong += $location['long'];
804  $avgLat += $location['lat'];
805  $minLong = min($minLong, $location['long']);
806  $maxLong = max($maxLong, $location['long']);
807  $minLat = min($minLat, $location['lat']);
808  $maxLat = max($maxLat, $location['lat']);
809  }
810 
811  $avgLong = $avgLong / floatVal(count($locationData));
812  $avgLat = $avgLat / floatVal(count($locationData));
813  $centerLat = ($maxLat + $minLat) / 2.0;
814  $centerLong = ($maxLong + $minLong) / 2.0;
815 
816  $d1 = calcDistanceInMiles($avgLat, $avgLong, $maxLat, $maxLong);
817  $d2 = calcDistanceInMiles($avgLat, $avgLong, $minLat, $minLong);
818  $d3 = calcDistanceInMiles($avgLat, $avgLong, $minLat, $maxLong);
819  $d4 = calcDistanceInMiles($avgLat, $avgLong, $maxLat, $minLong);
820 
821  $avg_radiusMi = max($d1, $d2, $d3, $d4);
822  $avg_radiusKm = $avg_radiusMi * 1.60934;
823 
824  $hard_radiusMi = calcDistanceInMiles($centerLat, $centerLong, $maxLat, $maxLong);
825  $hard_radiusKm = $hard_radiusMi * 1.60934;
826 
827  if (isset($meanLocationData) && is_array($meanLocationData)) {
828  $meanLocationData = array ( 'search_average' => array ( 'location' => array ( 'latitude' => $avgLat, 'longitude' => $avgLong, ), 'radius' => array ( 'miles' => $avg_radiusMi, 'kilometers' => $avg_radiusKm ) ),
829  'search_center' => array ( 'location' => array ( 'latitude' => $centerLat, 'longitude' => $centerLong, ), 'radius' => array ( 'miles' => $hard_radiusMi, 'kilometers' => $hard_radiusKm ) ));
830  }
831 
832  if (isset($in_http_vars['getMeanLocationData'])) {
833  $result = '"average_center_latitude","average_center_longitude","average_radius_mi","average_radius_km","search_center_latitude","search_center_longitude","search_center_radius_mi","search_center_radius_km"'."\n";
834  $result .= '"'.$avgLat.'","'.$avgLong.'","'.$avg_radiusMi.'","'.$avg_radiusKm.'","'.$centerLat.'","'.$centerLong.'","'.$hard_radiusMi.'","'.$hard_radiusKm.'"';
835  }
836  }
837 
838  if (!isset($in_http_vars['getMeanLocationData']) && isset($in_http_vars['data_field_key']) && $in_http_vars['data_field_key']) {
839  // At this point, we have everything in a CSV. We separate out just the field we want.
840  $temp_keyed_array = array();
841  $result = explode("\n", $result);
842  $keys = array_shift($result);
843  $keys = explode("\",\"", trim($keys, '"'));
844  $the_keys = explode(',', $in_http_vars['data_field_key']);
845 
846  $result2 = array();
847  foreach ($result as $row) {
848  if ($row) {
849  $index = 0;
850  $row = explode('","', trim($row, '",'));
851  $row_columns = array();
852  foreach ($row as $column) {
853  if (!$column) {
854  $column = ' ';
855  }
856  if (in_array($keys[$index++], $the_keys)) {
857  array_push($row_columns, $column);
858  }
859  }
860  $result2[$row[0]] = '"'.implode('","', $row_columns).'"';
861  }
862  }
863 
864  $the_keys = array_intersect($keys, $the_keys);
865  $result = '"'.implode('","', $the_keys)."\"\n".implode("\n", $result2);
866  }
867  return $result;
868 }
869 
870 /*******************************************************************/
871 /** \brief Returns a set of two coordinates that define a rectangle
872  that encloses all of the meetings.
873 
874  \returns a dictionary, with the two coordinates.
875 */
876 function GetCoverageArea()
877 {
879  $ret = null;
880 
881  if (isset($result) && is_array($result) && count($result)) {
882  $ret = array ( '"nw_corner_longitude","nw_corner_latitude","se_corner_longitude","se_corner_latitude"' );
883  $ret[1] = '"'.strval($result["nw_corner"]["longitude"]).'","'.strval($result["nw_corner"]["latitude"]).'","'.strval($result["se_corner"]["longitude"]).'","'.strval($result["se_corner"]["latitude"]).'"';
884  $ret = implode("\n", $ret);
885  }
886 
887  return $ret;
888 }
889 
890 /*******************************************************************/
891 /**
892  \brief This returns the complete formats table.
893 
894  \returns CSV data, with the first row a key header.
895 */
896 function GetFormats(
897  &$server, ///< A reference to an instance of c_comdef_server
898  $in_lang = null, ///< The language of the formats to be returned.
899  $in_formats = null //< If supplied, an already-fetched array of formats.
900 ) {
901  $my_keys = array ( 'key_string',
902  'name_string',
903  'description_string',
904  'lang',
905  'id',
906  'world_id',
907  'root_server_uri',
908  'format_type_enum',
909  );
910 
911  $ret = null;
912 
913  $formats_obj = $server->GetFormatsObj();
914  if ($formats_obj instanceof c_comdef_formats) {
915  $langs = $server->GetFormatLangs();
916  $used_formats = $server->GetUsedFormatIDs();
917  if (isset($in_lang) && is_array($in_lang) && count($in_lang)) {
918  $langs2 = array();
919  foreach ($in_lang as $key) {
920  if (array_key_exists($key, $langs)) {
921  $langs2[$key] = $langs[$key];
922  }
923  }
924 
925  $langs = $langs2;
926  } elseif (array_key_exists($in_lang, $langs)) {
927  $langs = array ( $in_lang => $langs[$in_lang] );
928  }
929 
930  $ret .= '"'.implode('","', $my_keys)."\"\n";
931  foreach ($langs as $key => $value) {
932  if ($in_formats) {
933  $format_array = $in_formats;
934  } else {
935  $format_array = $formats_obj->GetFormatsByLanguage($key);
936  }
937 
938  if (is_array($format_array) && count($format_array)) {
939  foreach ($format_array as $format) {
940  if ($format instanceof c_comdef_format) {
941  $localized_format = $server->GetOneFormat($format->GetSharedID(), $key);
942  if ($localized_format instanceof c_comdef_format) {
943  $line = '';
944  foreach ($my_keys as $ky) {
945  if ($line) {
946  $line .= ',';
947  }
948 
949  $val = '';
950 
951  switch ($ky) {
952  case 'lang':
953  $val = $key;
954  break;
955 
956  case 'id':
957  $val = $localized_format->GetSharedID();
958  break;
959 
960  case 'key_string':
961  $val = $localized_format->GetKey();
962  break;
963 
964  case 'name_string':
965  $val = $localized_format->GetLocalName();
966  break;
967 
968  case 'description_string':
969  $val = $localized_format->GetLocalDescription();
970  break;
971 
972  case 'world_id':
973  $val = $localized_format->GetWorldID();
974  break;
975 
976  case 'root_server_uri':
977  $val = dirname(dirname(GetURLToMainServerDirectory(true)));
978  break;
979 
980  case 'format_type_enum':
981  $val = $localized_format->GetFormatType();
982  break;
983  }
984 
985  $line .= '"'.str_replace('"', '\"', trim($val)).'"';
986  }
987 
988  if (in_array($localized_format->GetSharedID(), $used_formats)) {
989  $ret .= "$line\n";
990  }
991  }
992  }
993  }
994  }
995  }
996  }
997 
998  return $ret;
999 }
1000 
1001 /*******************************************************************/
1002 /**
1003  \brief This returns the complete Service bodies table.
1004 
1005  \returns CSV data, with the first row a key header.
1006 */
1008  &$server, ///< A reference to an instance of c_comdef_server
1009  $services = null,
1010  $recursive = false
1011 ) {
1012  $ret = array ();
1013  $localized_strings = c_comdef_server::GetLocalStrings();
1014 
1015  $ret[0] = '"id","parent_id","name","description","type","url","helpline","world_id"';
1016 
1017  if ($localized_strings['include_service_body_email_in_semantic']) {
1018  $ret[0] .= ',"contact_email"';
1019  }
1020 
1021  $servicesInclude = array();
1022  $servicesExclude = array();
1023  if ($services) {
1024  foreach ($services as $id) {
1025  if (substr($id, 0, 1) == "-") {
1026  array_push($servicesExclude, substr($id, 1));
1027  } else {
1028  array_push($servicesInclude, $id);
1029  }
1030  }
1031  }
1032 
1033  if ($recursive) {
1034  $servicesInclude = array_merge($servicesInclude, GetChildServiceBodies($server, $servicesInclude));
1035  $servicesExclude = array_merge($servicesExclude, GetChildServiceBodies($server, $servicesExclude));
1036  }
1037 
1038  try {
1039  $array_obj = $server->GetServiceBodyArray();
1040  if (is_array($array_obj) && count($array_obj)) {
1041  foreach ($array_obj as &$sb) {
1042  if ($sb instanceof c_comdef_service_body) {
1043  if (count($servicesInclude) && !in_array($sb->GetID(), $servicesInclude)) {
1044  continue;
1045  }
1046  if (count($servicesExclude) && in_array($sb->GetID(), $servicesExclude)) {
1047  continue;
1048  }
1049  $row = array();
1050  $row[] = $sb->GetID();
1051  $row[] = $sb->GetOwnerID();
1052  $row[] = $sb->GetLocalName();
1053  $description = preg_replace('|[^\S]+?|', " ", $sb->GetLocalDescription());
1054  $row[] = $description;
1055  $row[] = $sb->GetSBType();
1056  $row[] = $sb->GetURI();
1057  $row[] = trim($sb->GetHelpline());
1058  $row[] = $sb->GetWorldID();
1059  if ($localized_strings['include_service_body_email_in_semantic']) {
1060  $row[] = trim($sb->GetContactEmail());
1061  }
1062  $row = '"'.implode('","', $row).'"';
1063  $ret[] = $row;
1064  }
1065  }
1066  }
1067  } catch (Exception $e) {
1068  }
1069 
1070  return implode("\n", $ret);
1071 }
1072 
1073 function GetChildServiceBodies($server, $parents)
1074 {
1075  $ret = array();
1076  $children = $parents;
1077  while (count($children)) {
1078  $newChildren = array();
1079  foreach ($server->GetServiceBodyArray() as $serviceBody) {
1080  if (in_array($serviceBody->GetOwnerID(), $children) && !in_array($serviceBody->GetID(), $ret)) {
1081  array_push($newChildren, $serviceBody->GetID());
1082  array_push($ret, $serviceBody->GetID());
1083  }
1084  }
1085  $children = $newChildren;
1086  }
1087  return $ret;
1088 }
1089 
1090 /*******************************************************************/
1091 /**
1092  \brief This returns a line of server info.
1093 
1094  \returns CSV data, with the first row a key header.
1095 */
1096 function GetServerInfo()
1097 {
1098  require(dirname(__FILE__).'/../../server/config/get-config.php');
1099  $ret = '';
1100  $version_array = GetServerVersion();
1101  $version_num = (intval($version_array[0]) * 1000000) + (intval($version_array[1]) * 1000) + intval($version_array[2]);
1102  $version_string = strval($version_array[0]).'.'.strval($version_array[1]).'.'.strval($version_array[2]);
1103  $lang_array = c_comdef_server::GetServerLangs();
1104  $lang_string = implode(',', array_keys($lang_array));
1105  $localStrings = c_comdef_server::GetLocalStrings();
1106  $default_lang = strval($localStrings['enum']);
1107  $canAdmin = isset($g_enable_semantic_admin) && $g_enable_semantic_admin ? '1' : '0';
1108  $centerLongLatZoom = implode(',', $localStrings['search_spec_map_center']);
1109  $canEmail = isset($g_enable_email_contact) && $g_enable_email_contact ? '1' : '0';
1110  $includeServiceBodiesOnEmails = isset($include_service_body_admin_on_emails) && $include_service_body_admin_on_emails ? '1' : '0';
1111  $changeDepth = strVal(intval($change_depth_for_meetings));
1112  $dbVersion = c_comdef_server::GetDatabaseVersion();
1113  $availableFields = "";
1115  $meeting_time_zones_enabled = $localStrings['meeting_time_zones_enabled'] ? '1' : '0';
1116 
1117  foreach ($keys as $key) {
1118  if (($key['visibility'] != 1) && ($key['key'] != 'published') && ($key['key'] != 'shared_group_id_bigint')) {
1119  if ($availableFields != "") {
1120  $availableFields .= ',';
1121  }
1122 
1123  $availableFields .= $key['key'];
1124  }
1125  }
1126 
1127  $ret = '"version","versionInt","langs","nativeLang","centerLongitude","centerLatitude","centerZoom","defaultDuration","regionBias","charSet","distanceUnits","semanticAdmin","emailEnabled","emailIncludesServiceBodies","changesPerMeeting","meeting_states_and_provinces","meeting_counties_and_sub_provinces","available_keys","google_api_key","dbVersion","dbPrefix","meeting_time_zones_enabled"'."\n";
1128  $ret .= '"'.$version_string.'","'.strval($version_num).'","'.$lang_string.'","'.$default_lang.'",';
1129  $ret .= '"'.strval($localStrings['search_spec_map_center']['longitude']).'","'.strval($localStrings['search_spec_map_center']['latitude']).'",';
1130  $ret .= '"'.strval($localStrings['search_spec_map_center']['zoom']).'","'.$localStrings['default_duration_time'].'",';
1131  $ret .= '"'.$localStrings['region_bias'].'","'.$localStrings['charset'].'","'.$localStrings['dist_units'].'","'.$canAdmin.'",';
1132  $ret .= '"'.$canEmail.'","'.$includeServiceBodiesOnEmails.'","'.$changeDepth.'","'.implode(',', $localStrings['meeting_states_and_provinces']).'","'.implode(',', $localStrings['meeting_counties_and_sub_provinces']).'","'.str_replace('"', '\"', $availableFields).',root_server_uri,format_shared_id_list","'.$localStrings['google_api_key'].'","'.$dbVersion.'","'.$localStrings['dbPrefix'].'","'.$meeting_time_zones_enabled.'"';
1133 
1134  return $ret;
1135 }
1136 
1137 /*******************************************************************/
1138 /**
1139  \brief Returns the server version in an array.
1140 
1141  \returns an array of integers, with [0] being the main version, [1] being the minor version, and [2] being the fix version.
1142 */
1144 {
1145  $ret = array ( 0 );
1146 
1147  $xml = file_get_contents(dirname(dirname(__FILE__)).'/serverInfo.xml');
1148 
1149  if ($xml) {
1150  $info_file = new DOMDocument;
1151  if ($info_file instanceof DOMDocument) {
1152  if (@$info_file->loadXML($xml)) {
1153  $has_info = $info_file->getElementsByTagName("bmltInfo");
1154 
1155  if (($has_info instanceof domnodelist) && $has_info->length) {
1156  $nodeVal = $has_info->item(0)->nodeValue;
1157  $ret = explode('.', $nodeVal);
1158  }
1159  }
1160  }
1161  }
1162 
1163  if (!isset($ret[1])) {
1164  $ret[1] = '0';
1165  }
1166 
1167  if (!isset($ret[2])) {
1168  $ret[1] = '0';
1169  }
1170 
1171  $ret[0] = intval($ret[0]);
1172  $ret[1] = intval($ret[1]);
1173  $ret[2] = intval($ret[2]);
1174 
1175  return $ret;
1176 }
1177 
1178 /*******************************************************************/
1179 /**
1180  \brief This returns change records.
1181 
1182  \returns CSV data, with the first row a key header.
1183 */
1184 function GetChanges(
1185  $in_http_vars, ///< The HTTP GET/POST query.
1186  $in_start_date = null, ///< Optional. A start date (In PHP time() format). If supplied, then only changes on, or after this date will be returned.
1187  $in_end_date = null, ///< Optional. An end date (In PHP time() format). If supplied, then only changes that occurred on, or before this date will be returned.
1188  $in_meeting_id = null, ///< Optional. If supplied, an ID for a particular meeting. Only changes for that meeting will be returned.
1189  $in_sb_id = null ///< Optional. If supplied, an ID for a particular Service body. Only changes for that Service body will be returned.
1190 ) {
1191  $ret = null;
1192 
1193  try {
1194  $change_objects = c_comdef_server::GetChangesFromIDAndType('c_comdef_meeting', null, $in_start_date, $in_end_date);
1195  if ($change_objects instanceof c_comdef_changes) {
1196  $obj_array = $change_objects->GetChangesObjects();
1197 
1198  if (is_array($obj_array) && count($obj_array)) {
1199  set_time_limit(max(30, intval(count($obj_array) / 20))); // Change requests can take a loooong time...
1200  $localized_strings = c_comdef_server::GetLocalStrings();
1201  include(dirname(__FILE__).'/../../server/config/get-config.php');
1202  $ret = '"date_int","date_string","change_type","change_id","meeting_id","meeting_name","user_id","user_name","service_body_id","service_body_name","meeting_exists","details","json_data"'."\n";
1203 
1204  // If they specify a Service body, we also look in "child" Service bodies, so we need to produce a flat array of IDs.
1205  if (isset($in_sb_id) && $in_sb_id) {
1206  global $bmlt_array_gather;
1207 
1208  $bmlt_array_gather = array();
1209 
1210  /************************************************//**
1211  * This little internal function will simply fill *
1212  * the $bmlt_array_gather array with a linear set of *
1213  * Service body IDs that can be used for a quick *
1214  * comparison, later on. It is a callback function. *
1215  ****************************************************/
1216  function bmlt_at_at(
1217  $in_value,
1218  $in_key
1219  ) {
1220  global $bmlt_array_gather;
1221 
1222  if ($in_value instanceof c_comdef_service_body) {
1223  array_push($bmlt_array_gather, $in_value->GetID());
1224  }
1225  }
1226  $tmp = c_comdef_server::GetServer()->GetNestedServiceBodyArray($in_sb_id);
1227  array_walk_recursive($tmp, 'bmlt_at_at');
1228 
1229  if (is_array($bmlt_array_gather) && count($bmlt_array_gather)) {
1230  $in_sb_id = $bmlt_array_gather;
1231  } else {
1232  $in_sb_id = array ( $in_sb_id );
1233  }
1234  }
1235 
1236  foreach ($obj_array as $change) {
1237  $change_type = $change->GetChangeType();
1238  $date_int = intval($change->GetChangeDate());
1239  $change_id = intval($change->GetID());
1240  $date_string = date($change_date_format, $date_int);
1241  $json_data = '';
1242 
1243  if ($change instanceof c_comdef_change) {
1244  $b_obj = $change->GetBeforeObject();
1245  $a_obj = $change->GetAfterObject();
1246  $meeting_id = intval($change->GetBeforeObjectID());
1247  $sb_a = intval(($a_obj instanceof c_comdef_meeting) ? $a_obj->GetServiceBodyID() : 0);
1248  $sb_b = intval(($b_obj instanceof c_comdef_meeting) ? $b_obj->GetServiceBodyID() : 0);
1249  $sb_c = intval($change->GetServiceBodyID());
1250 
1251  if (!$meeting_id) {
1252  $meeting_id = intval($change->GetAfterObjectID());
1253  }
1254 
1255  if ((intval($in_meeting_id) && intval($in_meeting_id) == intval($meeting_id)) || !intval($in_meeting_id)) {
1256  $meeting_name = '';
1257  $user_name = '';
1258 
1259  if (!is_array($in_sb_id) || !count($in_sb_id) || in_array($sb_a, $in_sb_id) || in_array($sb_b, $in_sb_id) || in_array($sb_c, $in_sb_id)) {
1260  $sb_id = (intval($sb_c) ? $sb_c : (intval($sb_b) ? $sb_b : $sb_a));
1261  $meeting = (null != $b_obj) ? $b_obj : $a_obj;
1262 
1263  // Using str_replace, because preg_replace is pretty expensive. However, I don't think this buys us much.
1264  if ($b_obj instanceof c_comdef_meeting) {
1265  $meeting_name = str_replace('"', "'", str_replace("\n", " ", str_replace("\r", " ", $b_obj->GetMeetingDataValue('meeting_name'))));
1266  } elseif ($a_obj instanceof c_comdef_meeting) {
1267  $meeting_name = str_replace('"', "'", str_replace("\n", " ", str_replace("\r", " ", $a_obj->GetMeetingDataValue('meeting_name'))));
1268  }
1269 
1270  $user_id = intval($change->GetUserID());
1271 
1272  $user = c_comdef_server::GetUserByIDObj($user_id);
1273 
1274  if ($user instanceof c_comdef_user) {
1275  $user_name = htmlspecialchars($user->GetLocalName());
1276  }
1277 
1279 
1280  if ($sb instanceof c_comdef_service_body) {
1281  $sb_name = htmlspecialchars($sb->GetLocalName());
1282  }
1283 
1284  $meeting_exists = 0;
1285 
1287  $meeting_exists = 1;
1288  }
1289 
1290  $details = '';
1291  $desc = $change->DetailedChangeDescription();
1292 
1293  if ($desc && isset($desc['details']) && is_array($desc['details'])) {
1294  // We need to prevent double-quotes, as they are the string delimiters, so we replace them with single-quotes.
1295  $details = str_replace('"', "'", str_replace("\n", " ", str_replace("\r", " ", implode(" ", $desc['details']))));
1296  }
1297 
1298  $change_line = array();
1299 
1300  if ($date_int) {
1301  $change_line['date_int'] = $date_int;
1302  } else {
1303  $change_line['date_int'] = 0;
1304  }
1305 
1306  if ($date_string) {
1307  $change_line['date_string'] = $date_string;
1308  } else {
1309  $change_line['date_string'] = '';
1310  }
1311 
1312  if ($change_type) {
1313  $change_line['change_type'] = $change_type;
1314  } else {
1315  $change_line['change_type'] = '';
1316  }
1317 
1318  if ($change_id) {
1319  $change_line['change_id'] = $change_id;
1320  } else {
1321  $change_line['change_id'] = 0;
1322  }
1323 
1324  if ($meeting_id) {
1325  $change_line['meeting_id'] = $meeting_id;
1326  } else {
1327  $change_line['meeting_id'] = 0;
1328  }
1329 
1330  if ($meeting_name) {
1331  $change_line['meeting_name'] = $meeting_name;
1332  } else {
1333  $change_line['meeting_name'] = '';
1334  }
1335 
1336  if ($user_id) {
1337  $change_line['user_id'] = $user_id;
1338  } else {
1339  $change_line['user_id'] = 0;
1340  }
1341 
1342  if ($user_name) {
1343  $change_line['user_name'] = $user_name;
1344  } else {
1345  $change_line['user_name'] = '';
1346  }
1347 
1348  if ($sb_id) {
1349  $change_line['service_body_id'] = $sb_id;
1350  } else {
1351  $change_line['service_body_id'] = '';
1352  }
1353 
1354  if ($sb_name) {
1355  $change_line['service_body_name'] = $sb_name;
1356  } else {
1357  $change_line['service_body_name'] = '';
1358  }
1359 
1360  $change_line['meeting_exists'] = $meeting_exists;
1361 
1362  if ($details) {
1363  $change_line['details'] = $details;
1364  } else {
1365  $change_line['details'] = '';
1366  }
1367 
1368  $json_data = MakeJSONDataObject($b_obj, 'before');
1369 
1370  if (($json_data != '') && ($a_obj instanceof c_comdef_meeting)) {
1371  $json_data .= ',';
1372  }
1373 
1374  $json_data .= MakeJSONDataObject($a_obj, 'after');
1375 
1376  $change_line['json_data'] = '{'.str_replace('"', '&quot;', $json_data).'}';
1377 
1378  $ret .= '"'.implode('","', $change_line)."\"\n";
1379  }
1380  }
1381  }
1382  }
1383  }
1384  }
1385  } catch (Exception $e) {
1386  }
1387 
1388  return $ret;
1389 }
1390 
1391 /*******************************************************************/
1392 /**
1393  \brief Converts a given c_comdef_meeting object to a JSON object string.
1394 
1395  \returns A string, containing the JSON Data. It is blank if no JSON Data.
1396 */
1398  $in_meeting_object, ///< The c_comdef_meeting object to be converted.
1399  $in_object_name ///< A name for the returned object.
1400 ) {
1401  $json_data = '';
1402 
1403  if ($in_meeting_object instanceof c_comdef_meeting) {
1404  $keys = $in_meeting_object->GetMeetingDataKeys();
1405 
1406  foreach ($keys as $key) {
1407  if ($key) {
1408  $value = $in_meeting_object->GetMeetingDataValue($key);
1409 
1410  if ($value) {
1411  if ($key == 'formats') {
1412  $val_temp = array();
1413  $values = $value;
1414 
1415  foreach ($values as $format) {
1416  if ($format instanceof c_comdef_format) {
1417  $val_temp[] = $format->GetKey();
1418  }
1419  }
1420 
1421  $value = $val_temp;
1422  }
1423 
1424  if (is_array($value)) {
1425  if (count($value)) {
1426  for ($c = 0; $c < count($value); $c++) {
1427  $val = json_encode(trim($value[$c], '"'));
1428  $val = str_replace('&quot;', '"', $val);
1429  $val = str_replace('&amp;', '&', $val);
1430  $val = trim(preg_replace("|\s+|", ' ', $val), '"');
1431  $value[$c] = trim($val, "\\");
1432  }
1433 
1434  if ($json_data) {
1435  $json_data .= ',';
1436  }
1437 
1438  $json_data .= '"'.$key.'":'.'["'.implode('","', $value).'"]';
1439  }
1440  } else {
1441  $value = trim($value, "\\");
1442  $value = preg_replace("|^\"\"|", "\"&quot;", $value);
1443  $value = trim(json_encode($value), '"');
1444  $value = str_replace('&quot;', '"', $value);
1445  $value = str_replace('&amp;', '&', $value);
1446  $value = trim(preg_replace("|\s+|", ' ', $value), '\\');
1447  $value = trim($value, '"');
1448  if ($json_data) {
1449  $json_data .= ',';
1450  }
1451  $json_data .= '"'.$key.'":"'.$value.'"';
1452  }
1453  }
1454  }
1455  }
1456 
1457  if ($json_data && $in_object_name) {
1458  $json_data = '"'.$in_object_name.'":{'.$json_data.'}';
1459  }
1460  }
1461 
1462  return $json_data;
1463 }
1464 
1465 /*******************************************************************/
1466 /**
1467  \brief Handles no command supplied (error)
1468 
1469  \returns English error string (not XML).
1470 */
1471 function HandleDefault(
1472  $in_http_vars ///< The HTTP GET and POST parameters.
1473 ) {
1474  return "You must supply one of the following: 'switcher=GetSearchResults', 'switcher=GetFormats', 'switcher=GetChanges', 'switcher=GetNAWSDump', 'switcher=GetFieldKeys', 'switcher=GetFieldValues' or 'switcher=GetServiceBodies'.";
1475 }
1476 
1477 /*******************************************************************/
1478 /**
1479  \brief Handles no server available (error).
1480 
1481  \returns null;
1482 */
1483 function HandleNoServer()
1484 {
1485  return null;
1486 }
1487 
1488 /*******************************************************************/
1489 /**
1490  \brief Translates CSV to JSON.
1491 
1492  \returns a JSON string, with all the data in the CSV.
1493 */
1494 function TranslateToJSON( $in_csv_data ///< An array of CSV data, with the first element being the field names.
1495  )
1496 {
1497  $temp_keyed_array = array();
1498  $in_csv_data = explode("\n", $in_csv_data);
1499  $keys = array_shift($in_csv_data);
1500  $keys = explode("\",\"", trim($keys, '"'));
1501 
1502  foreach ($in_csv_data as $row) {
1503  if ($row) {
1504  $line = null;
1505  $index = 0;
1506  $row = explode('","', trim($row, '",'));
1507  foreach ($row as $column) {
1508  if (isset($column)) {
1509  $key = $keys[$index++];
1510  $value = str_replace("\t", ',', trim($column));
1511 
1512  if ($key == "json_data") {
1513  $value = trim($value, '"');
1514  $value = str_replace('&quot;', '"', $value);
1515  }
1516 
1517  $line[$key] = $value;
1518  }
1519  }
1520  array_push($temp_keyed_array, $line);
1521  }
1522  }
1523 
1524  $out_json_data = str_replace('\\\\"', '"', array2json($temp_keyed_array)); // HACK ALERT: TranslateToJSON does whacky things with my escaped quotes, so I undo that here.
1525 
1526  return $out_json_data;
1527 }
1528 
1529 /*******************************************************************/
1530 /**
1531  \brief Translates CSV to XML.
1532 
1533  \returns an XML string, with all the data in the CSV.
1534 */
1535 function TranslateToXML( $in_csv_data ///< An array of CSV data, with the first element being the field names.
1536  )
1537 {
1538  $temp_keyed_array = array();
1539  $in_csv_data = explode("\n", $in_csv_data);
1540  $keys = array_shift($in_csv_data);
1541  $keys = rtrim(ltrim($keys, '"'), '",');
1542  $keys = preg_split('/","/', $keys);
1543 
1544  foreach ($in_csv_data as $row) {
1545  if ($row) {
1546  $line = null;
1547  $index = 0;
1548  $row_t = rtrim(ltrim($row, '"'), '",');
1549  $row_t = preg_split('/","/', $row_t);
1550  foreach ($row_t as $column) {
1551  if (isset($column)) {
1552  $line[$keys[$index++]] = trim($column);
1553  }
1554  }
1555  array_push($temp_keyed_array, $line);
1556  }
1557  }
1558 
1559  $out_xml_data = array2xml($temp_keyed_array, 'not_used', false);
1560  // HACK ALERT: Undoing the poopiness done by TranslateToXML.
1561  $out_xml_data = str_replace("&aamp;quot;", "&quot;", $out_xml_data);
1562  $out_xml_data = str_replace("&amp;quot;", "&quot;", $out_xml_data);
1563  $out_xml_data = str_replace("\\&quot;", "&quot;", $out_xml_data);
1564  $out_xml_data = str_replace("&ququot;", "&quot;", $out_xml_data);
1565 
1566  return $out_xml_data;
1567 }
static GetLocalStrings($in_lang_enum=null)
This gets the appropriate language files, and puts all the the strings into an associative array...
static GetServerLangs()
Get the local readable string for the server languages.
A Class for Service Body Objects.
A class to hold a single meeting object.
function htmlspecialchars_decode(string, quote_style)
CSVHandleNawsDump($in_http_Vars, $in_server)
Definition: csv.php:633
static GetServiceBodyHierarchyIDs($in_service_body_id_bigint)
Return the IDs of an entire Service body hierarchy.
This class handles BMLT users. One instance is created for each user on the server.
TranslateToXML($in_csv_data)
Translates CSV to XML.
Definition: csv.php:1535
$ret
Definition: contact.php:226
array2xml($array, $name= 'array', $beginning=true)
array2xml() will convert any given array into a XML structure.
Definition: Array2XML.php:38
ReturnNAWSFormatCSV($in_http_vars, &$server)
Returns the CSV file in NAWS format.
GetServiceBodies(&$server, $services=null, $recursive=false)
This returns the complete Service bodies table.
Definition: csv.php:1007
$meeting_id
Definition: contact.php:227
HandleDefault($in_http_vars)
Handles no command supplied (error)
Definition: csv.php:1471
GetFormats(&$server, $in_lang=null, $in_formats=null)
This returns the complete formats table.
Definition: csv.php:896
A Class for Format Codes.
static GetCoverageArea()
Returns a set of two coordinates that define a rectangle that encloses all of the meetings...
static GetAllValuesForKey($inKey)
Returns an array of values for the given key.
static GetFullTemplate()
Returns an array that provides a template for all tables.
GetServerInfo()
This returns a line of server info.
Definition: csv.php:1096
Include the format class.
global $http_vars
Definition: index.php:21
static GetUserByIDObj($in_user_id_bigint)
Get the object for a single user, given an ID.
GetSearchResults($in_http_vars, &$formats_ar=null, &$meanLocationData=null)
This returns the search results, in whatever form was requested.
Definition: csv.php:752
c_comdef_htmlspecialchars($in_string)
This function creates a displayable string.
global $default_lang
$server
Definition: GetLangs.php:25
A Class for Change Record Objects.
array2json($arr)
Encodes a given associative array into a JSON object string.
Definition: Array2Json.php:41
A class to hold a collection of c_comdef_change objects.
GetURLToMainServerDirectory($inAllowHTTPS=true)
Returns a URL (HTTP) to the main_server directory (or renamed).
GetChanges($in_http_vars, $in_start_date=null, $in_end_date=null, $in_meeting_id=null, $in_sb_id=null)
This returns change records.
Definition: csv.php:1184
static GetServiceBodyByIDObj($in_service_body_id_bigint)
Get the object for a single service body, given an ID.
DisplaySearchResultsCSV($in_http_vars, &$return_array=null, &$return_geocode=null, &$return_results=null, $in_supress_hidden_concat=false, $in_editor_only=false)
This function does a search, then builds a CSV result, with each row being a meeting. The first row is a row of keys.
prepareSimpleLine($meeting, $withDate=true)
This returns a string, with the meeting&#39;s daya, time and location data in a simple string...
Definition: csv.php:543
GetChildServiceBodies($server, $parents)
Definition: csv.php:1073
returnArrayFromCSV($inCSVArray)
This returns an associative array from the given CSV, which is an array of lines, and the top line is...
Definition: csv.php:681
GetServerVersion()
Returns the server version in an array.
Definition: csv.php:1143
TranslateToJSON($in_csv_data)
Translates CSV to JSON.
Definition: csv.php:1494
static GetChangesFromIDAndType($in_type, $in_id=null, $in_start_date=null, $in_end_date=null)
Gets a list of all change objects of a certain type, or only one, if the change affects a certain cla...
parse_redirect(&$server)
Queries the local server, and returns processed CSV data.
Definition: csv.php:45
calcDistanceInMiles($lat_1, $long_1, $lat_2, $long_2)
Calculates the distance, in Km, between two long/lat pairs. This uses the Haversine formula...
Definition: csv.php:722
$https
Definition: installer.php:72
static GetOneMeeting($in_id_bigint, $test_only=false)
Given an ID for a meeting, it returns one instance.
MakeJSONDataObject($in_meeting_object, $in_object_name)
Converts a given c_comdef_meeting object to a JSON object string.
Definition: csv.php:1397
GetCoverageArea()
Returns a set of two coordinates that define a rectangle that encloses all of the meetings...
Definition: csv.php:876
HandleNoServer()
Handles no server available (error).
Definition: csv.php:1483
$_GET['switcher']