32 $iDistance = (int)$iDistance;
33 if (is_array($mixedCountry)) {
41 $sZip = substr($sZip, 0, 3);
43 $sZip = strlen($sZip) > 4 ? trim(substr($sZip, 0, -3)) : trim($sZip);
47 if (
'Google' ==
getParam(
'ch_zip_mode') && $this->_oDb->isModule(
'wmap')) {
52 $sAddress =
"$sZip " . str_replace(
'_',
'',
$GLOBALS[
'aPreValues'][
'Country'][
$sCountry][
'LKey']);
58 if (!class_exists(
'RadiusAssistant'))
59 require_once( CH_DIRECTORY_PATH_INC .
'RadiusAssistant.inc.php' );
62 $minLat = $zcdRadius->MinLatitude();
63 $maxLat = $zcdRadius->MaxLatitude();
64 $minLong = $zcdRadius->MinLongitude();
65 $maxLong = $zcdRadius->MaxLongitude();
67 $sWhere =
" `Profiles`.`Country` = '$sCountry' AND `ch_wmap_locations`.`country` = '$sCountry' AND `ch_wmap_locations`.`failed` = 0 AND `ch_wmap_locations`.`lat` >= {$minLat} AND `ch_wmap_locations`.`lat` <= {$maxLat} AND `ch_wmap_locations`.`lng` >= {$minLong} AND `ch_wmap_locations`.`lng` <= {$maxLong} ";
68 $sJoin .=
" INNER JOIN `ch_wmap_locations` ON (`ch_wmap_locations`.`part` = 'profiles' AND `ch_wmap_locations`.`id` = `Profiles`.`ID`) ";
81 $s = $this->
_readFromUrl($this->_server .
"/findNearbyPostalCodes?postalcode={$sZip}&country={$sCountry}&radius={$iDistance}&style={$this->_style}&maxRows={$this->_maxRows}&username=" . trim(
getParam(
'ch_zip_geonames_username')));
93 foreach ($aZips
as $k =>
$s)
94 $aZips[$k] = strtoupper(
$s);
97 $sWhere =
" `Country` = '$sCountry' AND (";
98 foreach ($aZips
as $s)
99 $sWhere .=
" UPPER(IF(LENGTH(`Profiles`.`zip`) > 4,TRIM(SUBSTRING(`Profiles`.`zip`,1,LENGTH(`Profiles`.`zip`)-3)),`Profiles`.`zip`)) = '$s' OR ";
100 $sWhere = substr($sWhere, 0, -4);
103 $sWhere =
" `Country` = '$sCountry' AND (UPPER(SUBSTRING(`Profiles`.`zip`,1,3)) = '" . join (
"' OR UPPER(SUBSTRING(`Profiles`.`zip`,1,3)) = '", $aZips) .
"') ";
105 $sWhere =
" `Country` = '$sCountry' AND (UPPER(`Profiles`.`zip`) = '" . join (
"' OR UPPER(`Profiles`.`zip`) = '", $aZips) .
"') ";
113 foreach ($aWhere
as $k => $v)
114 if (preg_match(
'/`zip`/', $v) || preg_match(
'/`Country`/', $v))
116 $aWhere[] = $sWhere ? $sWhere :
' 0 ';
125 $this->_oTemplate->displayAccessDenied ();
129 $this->_oTemplate->pageStart();
131 $iId = $this->_oDb->getSettingsCategory();
133 echo
MsgBox(
_t(
'_sys_request_page_not_found_cpt'));
134 $this->_oTemplate->pageCodeAdmin (
_t(
'_ch_zip_administration'));
141 if(isset($_POST[
'save']) && isset($_POST[
'cat'])) {
143 $mixedResult =
$oSettings->saveChanges($_POST);
149 if($mixedResult !==
true && !
empty($mixedResult))
155 echo $this->_oTemplate->adminBlock ($this->_oTemplate->parseHtmlByName(
'default_padding',
$aVars),
_t(
'_ch_zip_administration'));
158 'content' =>
_t(
'_ch_zip_help_text'),
160 echo $this->_oTemplate->adminBlock ($this->_oTemplate->parseHtmlByName(
'default_padding',
$aVars),
_t(
'_ch_zip_help'));
162 $this->_oTemplate->addCssAdmin (
'forms_adv.css');
163 $this->_oTemplate->pageCodeAdmin (
_t(
'_ch_zip_administration'));
173 if (function_exists(
'curl_init')) {
176 curl_setopt($curl, CURLOPT_URL,
$sUrl);
177 curl_setopt($curl, CURLOPT_RETURNTRANSFER,
true);
178 curl_setopt($curl, CURLOPT_HEADER,
false);
180 $s = curl_exec($curl);
184 if (
true ===
$s)
$s =
'';
186 $s = @file_get_contents(
$sUrl);
193 if (preg_match(
'/<totalResultsCount>(\d+)<\/totalResultsCount>/',
$s, $m)) {
201 if (preg_match(
'/<lat>([0-9\.-]+)<\/lat>/',
$s, $m)) {
209 if (preg_match(
'/<lng>([0-9\.-]+)<\/lng>/',
$s, $m)) {
217 if (preg_match(
'/<status\s+message="(.*)"\s+value="(\d+)"\s*\/>/',
$s, $m)) {
226 if (!preg_match_all(
'/<postalcode>(.*)<\/postalcode>/',
$s, $m)) {
230 return array_unique($m[1]);
235 if (!preg_match_all(
'/<countryCode>(.*)<\/countryCode>/',
$s, $m)) {
238 return array_unique($m[1]);
253 $sAddress = rawurlencode($sAddress);
255 $sUrl =
"http://maps.googleapis.com/maps/api/geocode/json";
258 'address' => $sAddress,
262 $oData = json_decode(
$s);
266 if (
'OK' != $oData->status)
269 foreach ($oData->results
as $oResult) {
271 $sShortNameCountry =
'';
272 foreach ($oResult->address_components
as $oAddressComponent)
273 if (in_array(
'country', $oAddressComponent->types))
274 $sShortNameCountry = $oAddressComponent->short_name;
276 if (!$sCountryCode || ($sShortNameCountry && $sCountryCode == $sShortNameCountry)) {
277 $fLatitude = $oResult->geometry->location->lat;
278 $fLongitude = $oResult->geometry->location->lng;
279 $sCountryCode = $sShortNameCountry;