10 define(
'CH_WMAP_CAT_HOME',
'home');
11 define(
'CH_WMAP_CAT_ENTRY',
'entry');
12 define(
'CH_WMAP_CAT_EDIT',
'edit');
29 parent::__construct();
30 $this->_sPrefix = $oConfig->getDbPrefix();
35 return $this->
query (
"INSERT INTO `" . $this->_sPrefix .
"locations` SET `id` = '$iId', `part` = '$sPart', `ts` = UNIX_TIMESTAMP(), `lat` = '$fLat', `lng` = '$fLng', `zoom` = '$iZoom', `type` = '$iType' ON DUPLICATE KEY UPDATE `ts` = UNIX_TIMESTAMP(), `lat` = '$fLat', `lng` = '$fLng', `zoom` = '$iZoom', `type` = '$iType'");
40 return $this->
query (
"DELETE FROM `" . $this->_sPrefix .
"locations` WHERE `id` = '$iId' AND `part` = '$sPart' LIMIT 1");
45 return $this->
query (
"UPDATE `" . $this->_sPrefix .
"locations` SET `privacy` = '$mixedPrivacy' WHERE `id` = '$iId'");
48 function insertLocation (
$iId, $sPart,
$sTitle, $sUri, $fLat, $fLng, $iMapZoom, $sMapType, $sAddress, $sCity,
$sCountry, $mixedPrivacy =
CH_WMAP_PRIVACY_DEFAULT, $isFailed = 0)
52 $sFields .=
", `address` = '$sAddress' ";
55 $sFields .=
", `city`= '$sCity' ";
57 return $this->
query (
"INSERT INTO `" . $this->_sPrefix .
"locations` SET `id` = '$iId', `part` = '$sPart', `lat` = '$fLat', `lng` = '$fLng', `zoom` = '$iMapZoom', `type` = '$sMapType', `country`= '$sCountry', `title`= '$sTitle', `uri`= '$sUri', `ts` = UNIX_TIMESTAMP(), `privacy` = '$mixedPrivacy', `failed` = '$isFailed' $sFields ON DUPLICATE KEY UPDATE `lat` = '$fLat', `lng` = '$fLng', `zoom` = '$iMapZoom', `type` = '$sMapType', `country`= '$sCountry', `ts` = UNIX_TIMESTAMP(), `privacy` = '$mixedPrivacy', `failed` = '$isFailed' $sFields");
63 foreach ($this->_aParts
as $sPart => $aPart) {
65 if ($aPart[
'join_field_country'])
66 $sFields .=
", `p`.`{$aPart['join_field_country']}` AS `country` ";
67 if ($aPart[
'join_field_city'])
68 $sFields .=
", `p`.`{$aPart['join_field_city']}` AS `city` ";
69 if ($aPart[
'join_field_state'])
70 $sFields .=
", `p`.`{$aPart['join_field_state']}` AS `state` ";
71 if ($aPart[
'join_field_zip'])
72 $sFields .=
", `p`.`{$aPart['join_field_zip']}` AS `zip` ";
73 if ($aPart[
'join_field_address'])
74 $sFields .=
", `p`.`{$aPart['join_field_address']}` AS `address` ";
75 if ($aPart[
'join_field_latitude'])
76 $sFields .=
", `p`.`{$aPart['join_field_latitude']}` AS `latitude` ";
77 if ($aPart[
'join_field_longitude'])
78 $sFields .=
", `p`.`{$aPart['join_field_longitude']}` AS `longitude` ";
79 if ($aPart[
'join_field_privacy'])
80 $sFields .=
", `p`.`{$aPart['join_field_privacy']}` AS `privacy` ";
82 $sSql =
"SELECT '$sPart' AS `part`, `p`.`{$aPart['join_field_id']}` AS `id`, `p`.`{$aPart['join_field_title']}`
83 AS `title`, `p`.`{$aPart['join_field_uri']}` AS `uri` $sFields FROM `{$aPart['join_table']}` AS `p`
84 LEFT JOIN `" . $this->_sPrefix .
"locations` AS `m` ON (`m`.`id` = `p`.`{$aPart['join_field_id']}` AND `m`.`part` = '$sPart')
85 WHERE ISNULL(`m`.`id`) LIMIT $iLimit";
87 $a = $this->
getAll ($sSql);
88 $aRet = array_merge ($aRet, $a);
95 $sPart = $aPart[
'part'];
98 if ($aPart[
'join_field_country'])
99 $sFields .=
", `p`.`{$aPart['join_field_country']}` AS `country` ";
100 if ($aPart[
'join_field_city'])
101 $sFields .=
", `p`.`{$aPart['join_field_city']}` AS `city` ";
102 if ($aPart[
'join_field_state'])
103 $sFields .=
", `p`.`{$aPart['join_field_state']}` AS `state` ";
104 if ($aPart[
'join_field_zip'])
105 $sFields .=
", `p`.`{$aPart['join_field_zip']}` AS `zip` ";
106 if ($aPart[
'join_field_address'])
107 $sFields .=
", `p`.`{$aPart['join_field_address']}` AS `address` ";
108 if ($aPart[
'join_field_latitude'])
109 $sFields .=
", `p`.`{$aPart['join_field_latitude']}` AS `latitude` ";
110 if ($aPart[
'join_field_longitude'])
111 $sFields .=
", `p`.`{$aPart['join_field_longitude']}` AS `longitude` ";
112 if ($aPart[
'join_field_privacy'])
113 $sFields .=
", `p`.`{$aPart['join_field_privacy']}` AS `privacy` ";
115 $sSql =
"SELECT '$sPart' AS `part`, `p`.`{$aPart['join_field_id']}` AS `id`, `p`.`{$aPart['join_field_title']}` AS `title`, `p`.`{$aPart['join_field_uri']}` AS `uri`, `p`.`{$aPart['join_field_author']}` AS `author_id`, `l`.`lat`, `l`.`lng`, `l`.`zoom`, `l`.`type` $sFields
116 FROM `{$aPart['join_table']}` AS `p`
117 LEFT JOIN `" . $this->_sPrefix .
"locations` AS `l` ON (`l`.`id` = `p`.`{$aPart['join_field_id']}` AND `l`.`part` = '$sPart')
118 WHERE `p`.`{$aPart['join_field_id']}` = ? " . ($bProcessHidden ? $aPart[
'join_where'] :
'') .
" LIMIT 1";
120 return $this->
getRow ($sSql, [$iEntryId]);
126 if ($isClearFailedOnly) {
127 $sWhere =
" AND `failed` != 0 ";
129 if (
$ret = $this->
query (
"DELETE FROM `" . $this->_sPrefix .
"locations` WHERE `part` = '$sPart' $sWhere")) {
130 $this->
query (
"OPTIMIZE TABLE `" . $this->_sPrefix .
"locations`");
137 return $this->
getRow(
"SELECT `m`.`id`, `m`.`part`, `m`.`lat`, `m`.`lng`, `m`.`zoom`, `m`.`type`, `m`.`address`, `m`.`country`, `m`.`allow_view_location_to`
138 FROM `" . $this->_sPrefix .
"locations` AS `m` WHERE `m`.`failed` = 0 AND `p`.`Status` = 'Active'
139 AND `m`.`id` = ? AND `m`.`part` = ? LIMIT 1", [
$iProfileId, $sPart]);
142 function getLocationsByBounds($sPart, $fLatMin, $fLatMax, $fLngMin, $fLngMax, $aCustomParts, $mixedPrivacyIds =
'')
146 $sWhere = $this->
_getLatLngWhere ($fLatMin, $fLatMax, $fLngMin, $fLngMax);
148 $sWhere .=
" AND `m`.`part` = '$sPart' ";
150 $sWhere .= $sCustomPartsCondition;
154 return $this->
getAll(
"SELECT `m`.`id`, `m`.`part`, `m`.`title`, `m`.`uri`, `m`.`lat`, `m`.`lng` FROM `" . $this->_sPrefix .
"locations` AS `m` WHERE `m`.`failed` = 0 $sWhere ORDER BY `m`.`id` DESC LIMIT 100");
159 $sWhere =
" AND `m`.`lat` < $fLatMax AND `m`.`lat` > $fLatMin ";
160 if ($fLngMin < $fLngMax)
161 $sWhere .=
" AND `m`.`lng` < $fLngMax AND `m`.`lng` > $fLngMin ";
163 $sWhere .=
" AND ((`m`.`lng` < $fLngMax AND `m`.`lng` > -180) OR (`m`.`lng` < 180 AND `m`.`lng` > $fLngMin)) ";
169 return $this->
getOne(
"SELECT `ID` FROM `sys_options_cats` WHERE `name` = '$s' LIMIT 1");
174 return $this->
getAllWithKey (
"SELECT * FROM `" . $this->_sPrefix .
"parts` WHERE `enabled` != 0",
'part');
179 return $this->
query (
"UPDATE `" . $this->_sPrefix .
"parts` SET `enabled` = '{$isEnable}' WHERE `part` = '$sPart'");
184 $sQuery =
"INSERT INTO `" . $this->_sPrefix .
"parts` SET ";
185 foreach ($aOptions
as $sField => $sValue)
186 $sQuery .=
"`$sField` = {$this->escape($sValue)},";
187 $sQuery = trim ($sQuery,
', ');
188 if (!$this->
query($sQuery))
201 $sQuery =
"UPDATE `" . $this->_sPrefix .
"parts` SET ";
202 foreach ($aOptions
as $sField => $sValue)
203 $sQuery .=
"`$sField` = {$this->escape($sValue)},";
204 $sQuery = trim ($sQuery,
', ');
205 $sQuery .=
" WHERE `part` = ?";
206 if (!$this->
query($sQuery, [$sPart]))
215 return $this->
query (
"DELETE FROM `" . $this->_sPrefix .
"parts` WHERE `part` = '$sPart'");
222 foreach ($this->_aParts
as $sPart => $a) {
223 if (!isset($aCustomParts[$sPart]))
225 $sPatrsCounts .=
" , COUNT(DISTINCT `pm_$sPart`.`id`) AS `num_$sPart` ";
226 $sPartsJoin .=
" LEFT JOIN `" . $this->_sPrefix .
"locations` AS `pm_$sPart` ON (`pm_$sPart`.`failed` = 0 AND `pm_$sPart`.`id` = `pm`.`id` AND `pm_$sPart`.`part` = `pm`.`part` AND `pm_$sPart`.`part` = '$sPart') \n";
228 return array ($sPatrsCounts, $sPartsJoin);
234 foreach ($aCustomParts
as $sPart)
235 $sRet .=
"`$sTableAlias`.`part` = '$sPart' OR ";
236 $sRet = substr ($sRet, 0, -4);
243 if (!$mixedPrivacyIds)
245 if (!is_array($mixedPrivacyIds))
246 $mixedPrivacyIds = array ($mixedPrivacyIds);
248 foreach ($mixedPrivacyIds
as $iPrivacyId)
249 $sRet .=
"`$sTableAlias`.`privacy` = '$iPrivacyId' OR ";
250 $sRet = substr ($sRet, 0, -4);
257 foreach ($this->_aCategs
as $sType => $sCateg) {
258 $sCateg = str_replace(
'{Part}', ucfirst($sPart), $sCateg);
262 $this->
query(
"DELETE FROM `sys_options_cats` WHERE `ID` = " . $iCategId);
263 $this->
query(
"DELETE FROM `sys_options` WHERE `kateg` = " . $iCategId);
266 $sHiddenSettingsSql =
"DELETE FROM `sys_options` WHERE `Name` = 'ch_wmap_home_{part}_lat' OR `Name` = 'ch_wmap_home_{part}_lng' OR `Name` = 'ch_wmap_home_{part}_zoom' OR `Name` = 'ch_wmap_home_{part}_map_type'";
267 $sHiddenSettingsSql = str_replace(
'{part}', $sPart, $sHiddenSettingsSql);
268 $this->
query($sHiddenSettingsSql);
276 'ch_wmap_{type}_{part}_control_type' => array (
277 'title' =>
'Map control type',
279 'values' =>
'none,small,large',
282 'ch_wmap_{type}_{part}_is_type_control' => array (
283 'title' =>
'Display map type controls',
284 'type' =>
'checkbox',
288 'ch_wmap_{type}_{part}_is_scale_control' => array (
289 'title' =>
'Display map scale control',
290 'type' =>
'checkbox',
294 'ch_wmap_{type}_{part}_is_overview_control' => array (
295 'title' =>
'Display map overview control',
296 'type' =>
'checkbox',
300 'ch_wmap_{type}_{part}_is_map_dragable' => array (
301 'title' =>
'Is map dragable?',
302 'type' =>
'checkbox',
306 'ch_wmap_{type}_{part}_zoom' => array (
307 'title' =>
'Default zoom',
312 'ch_wmap_{type}_{part}_map_type' => array (
313 'title' =>
'Default map type',
315 'values' =>
'normal,satellite,hybrid,terrain',
320 $iOrderCateg = $this->
getOne(
"SELECT `menu_order` FROM `sys_options_cats` ORDER BY `menu_order` DESC LIMIT 1");
322 foreach ($this->_aCategs
as $sType => $sCateg) {
324 $sCateg = str_replace(
'{Part}', ucfirst($sPart), $sCateg);
325 if (!$this->
query(
"INSERT INTO `sys_options_cats` SET `name` = {$this->escape($sCateg)}, `menu_order` = " . (++$iOrderCateg)))
328 $iCategId = $this->
lastId();
339 $bRes = $this->
query(
"INSERT INTO `sys_options` SET
345 `order_in_kateg` = ?,
346 `AvailableValues` = ?",
365 $sHiddenSettingsSql =
"INSERT INTO `sys_options` (`Name`, `VALUE`, `kateg`, `desc`, `Type`, `check`, `err_text`, `order_in_kateg`, `AvailableValues`) VALUES
366 ('ch_wmap_home_{part}_lat', '20', {categ_id}, 'Home map latitude: {Part}', 'digit', '', '', '0', ''),
367 ('ch_wmap_home_{part}_lng', '35', {categ_id}, 'Home map longitude: {Part}', 'digit', '', '', '0', ''),
368 ('ch_wmap_home_{part}_zoom', '2', {categ_id}, 'Home map zoom: {Part}', 'digit', '', '', '0', ''),
369 ('ch_wmap_home_{part}_map_type', 'normal', {categ_id}, 'Home map type: {Part}', 'digit', '', '', '0', '')";
371 $sHiddenSettingsSql = str_replace(
'{part}', $sPart, $sHiddenSettingsSql);
372 $sHiddenSettingsSql = str_replace(
'{Part}', ucfirst($sPart), $sHiddenSettingsSql);
373 $sHiddenSettingsSql = str_replace(
'{categ_id}', $iCategHiddenId, $sHiddenSettingsSql);
375 if (!$this->
query($sHiddenSettingsSql))