18 require_once SQ_PACKAGES_PATH.
'/cms/page_templates/page_asset_listing/page_asset_listing.inc';
43 parent::__construct($assetid);
44 $this->_ser_attrs = TRUE;
62 if (!parent::_createAdditional($link))
return FALSE;
79 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
81 $bodycopy->setAttrValue(
'name', $name);
82 $content_type =
'content_type_raw_html';
87 'attributes' => Array (
88 'content_type' => $content_type,
90 'content' => $content,
95 'link_type' => SQ_LINK_TYPE_2,
101 if (!$bodycopy->create($copy_link, $bc_data)) {
118 $allowed_link[
'asset'][
'card'] =
'M';
119 $allowed_link[
'asset'][
'exclusive'] = FALSE;
121 $links[SQ_LINK_TYPE_1] = $allowed_link;
122 $links[SQ_LINK_TYPE_2] = $allowed_link;
123 $links[SQ_LINK_TYPE_3] = $allowed_link;
124 $links[SQ_LINK_NOTICE] = $allowed_link;
141 foreach ($root_nodes as $root_assetid) {
142 $hash_str .= $root_assetid;
144 $hash = md5($hash_str);
160 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
161 $result = $cm->loadFromCache($this->
id, $this->
type(), $cache_key, FALSE);
165 if ($result === FALSE)
return FALSE;
167 $result = unserialize($result);
179 private function cacheResultSet(Array $result, $cache_key=
'')
181 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
182 $r = $cm->saveToCache($this->
id, $this->
type(), $cache_key, serialize($result), FALSE);
195 $api_key = $this->
attr(
'api_key');
196 $this->api_key = $api_key;
197 $lat = $this->
attr(
'default_latitude');
198 $lng = $this->
attr(
'default_longitude');
199 $zoom_level = $this->
attr(
'default_zoom_level');
200 $map_type = $this->
attr(
'default_map_type');
201 $use_google_marker = $this->
attr(
'use_google_marker_icon');
203 if (!$use_google_marker)
204 $icon_url = $this->
attr(
'default_marker_icon');
205 $icon_width = $this->
attr(
'default_icon_width');
206 $icon_height = $this->
attr(
'default_icon_height');
207 $default_icon_size = $this->
attr(
'default_icon_size');
208 if ($default_icon_size) {
213 $description =
'defaultlocation';
214 $keywords_list = $this->
attr(
'asset_types_keywords');
215 $street_view = $this->
attr(
'enable_street_view');
216 $create_location = $this->
attr(
'enable_create_location');
224 if ($dynamic_lat && $dynamic_lng) {
229 if (!empty($dynamic_zoom_level)) $zoom_level = $dynamic_zoom_level;
230 if (!empty($dynamic_desc)) $description = $dynamic_desc;
231 if (!empty($dynamic_map_type)) $map_type = $dynamic_map_type;
236 $bodycopy_popup_window = $this->
getBodycopy(
'Popup Window');
237 $keywords = $bodycopy_popup_window->getKeywords();
239 $root_node_id = $this->
attr(
'root_assetid');
243 $exclude_assets = $this->
attr(
'exclude_assets');
246 $exclude_root_nodes = $this->
attr(
'exclude_root_nodes');
247 foreach($exclude_root_nodes as $key => $value) {
248 $exclude_children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($value);
249 $exclude_assets += array_keys($exclude_children);
252 if (!empty($exclude_assets)) {
253 foreach ($exclude_assets as $index => $assetid) {
254 if (isset($res[$assetid])) {
255 unset($res[$assetid]);
266 $assets_parent = Array();
268 $toggle_root_nodes = $this->
attr(
'toggle_root_nodes');
271 if ($toggle_root_nodes) {
272 foreach ($root_nodes as $root_assetid) {
274 if (!empty($children)) {
275 foreach ($children as $child_info) {
276 $assets_parent[$child_info[
'minorid']][] = $root_assetid;
282 $locations_info = Array();
283 $address_keyword = FALSE;
284 $listing_ldap_user = FALSE;
287 $node_info = Array();
289 foreach ($res as $child_assetid => $asset_type)
292 $child_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($child_assetid);
293 $child_asset_type = $child_asset->type();
295 $child_address = NULL;
296 if ($child_asset->type() ==
'google_map_location') {
297 $child_title = $child_asset->attr(
'name');
298 $child_latitude = $child_asset->attr(
'latitude');
299 $child_longitude = $child_asset->attr(
'longitude');
300 $child_icon_url = $child_asset->attr(
'icon_url');
301 $child_description = $child_asset->attr(
'description');
303 $child_title = $child_asset->getKeywordReplacement(str_replace(
'%',
'', $keywords_list[$child_asset_type][
'name_keyword']));
304 if (is_array($child_title)) {
305 $child_title = implode(
' ', $child_title);
308 $child_latitude = $child_asset->getKeywordReplacement(str_replace(
'%',
'', $keywords_list[$child_asset_type][
'latitude_keyword']));
309 $child_longitude = $child_asset->getKeywordReplacement(str_replace(
'%',
'', $keywords_list[$child_asset_type][
'longitude_keyword']));
311 $child_description = $child_asset->getKeywordReplacement(str_replace(
'%',
'', $keywords_list[$child_asset_type][
'description_keyword']));
312 $address_keyword = array_get_index($keywords_list[$child_asset_type],
'address_keyword', NULL);
313 if ($address_keyword) {
318 $loc_index = $child_assetid;
322 if ($address_keyword && !is_int($child_assetid) && $ldap_user) {
323 $loc_index = $child_asset->getKeywordReplacement(
'asset_attribute_uid');
326 $locations_info[$loc_index][
'title']= $child_title;
327 $locations_info[$loc_index][
'lat'] = $child_latitude;
328 $locations_info[$loc_index][
'lng'] = $child_longitude;
329 $locations_info[$loc_index][
'icon'] = !empty($child_icon_url) ? $child_icon_url : $icon_url;
330 $locations_info[$loc_index][
'desc'] = $child_description;
331 if ($address_keyword) {
332 $locations_info[$loc_index][
'addr'] = $child_address;
335 $index = $child_asset->id;
336 $asset_types_list = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeHierarchy(
'ldap_user'));
337 $asset_types_list[] =
'ldap_user';
338 $listing_ldap_user = in_array($child_asset_type, $asset_types_list);
339 if ($listing_ldap_user) {
340 $index = $child_asset->getKeywordReplacement(
'asset_attribute_uid');
342 $locations_info[$loc_index][
'index'] = $index;
345 if (empty($child_latitude) || empty($child_longitude)) {
347 if (!empty($cached_result) && isset($cached_result[$index])) {
349 if (isset($locations_info[$loc_index][
'lat'])) {
350 $locations_info[$loc_index][
'lat'] = $cached_result[$index][
'lat'];
352 if (isset($locations_info[$loc_index][
'lng'])) {
353 $locations_info[$loc_index][
'lng'] = $cached_result[$index][
'lng'];
358 $cached_result[$index] = $result;
359 if ($result !== FALSE) {
360 $locations_info[$loc_index][
'lat'] = $cached_result[$index][
'lat'];
361 $locations_info[$loc_index][
'lng'] = $cached_result[$index][
'lng'];
363 $this->cacheResultSet($cached_result, $cache_key);
369 $replacements = Array();
370 foreach ($keywords as $word) {
372 $replacements[$word] = $child_asset->getKeywordReplacement($asset_keyword);
375 $bodycopy_popup_window->setKeywordReplacements($replacements);
377 $bodycopy_popup_window->printBody();
378 $popup_html = ob_get_contents();
381 $locations_info[$loc_index][
'html'] = $popup_html;
388 <script src=
"<?php echo (current_protocol()); ?>://maps.googleapis.com/maps/api/js?key=<?php echo $api_key; ?>&sensor=false" type=
"text/javascript"></script>
389 <script
type=
"text/javascript">
391 <?php
if (!empty($popup_html)) {
392 $popup_html = preg_replace(
'/(\r\n|\r|\n)/s',
'', $popup_html);
394 var popup_html =
'<?php echo preg_replace("/'/
", "\
'", $popup_html); ?>';
396 var centerLatitude = <?php echo (
float) $lat; ?>;
397 var centerLongitude = <?php echo (
float) $lng; ?>;
398 var desc =
'<?php echo $description; ?>';
399 var zoomLevel = <?php echo (
int) $zoom_level; ?>;
400 var map_type = google.maps.MapTypeId.<?php echo $map_type; ?>;
401 var icon_url =
'<?php echo $icon_url; ?>';
402 var icon_width = <?php echo $icon_width; ?>;
403 var icon_height = <?php echo $icon_height; ?>;
410 var allMarkerList = {};
411 var allDisplayingMarker = {};
412 var markerTypes = {};
413 var markerRootNodes = {};
414 var addressList = [];
415 var cache_home_url =
'<?php echo $this->getUrl(); ?>';
416 var cache_key =
'<?php echo $cache_key; ?>';
418 var current_marker = null;
419 var current_listener = null;
420 var current_listener_name =
'navigate_tool';
424 $geocoder = $this->
attr(
'enable_geocoder');
427 geocoder =
new google.maps.Geocoder();
435 <script type=
"text/javascript" src=
"<?php echo sq_web_path('data').'/asset_types/google_map/js/map_lib.js'?>"></script>
443 if (!empty($locations_info)) {
445 <script type=
"text/javascript">
451 var newPolylines = [];
457 $asset_types = $this->
attr(
'types');
458 foreach ($asset_types as $type_code => $inherit) {
460 markerTypes[
'<?php echo $type_code; ?>'] = { toggle:
true };
464 if ($toggle_root_nodes) {
465 foreach ($root_nodes as $root_assetid) {
467 markerRootNodes[
'<?php echo $root_assetid; ?>'] = { toggle:
true };
472 foreach ($locations_info as $child_assetid => $location_info) {
474 if ( empty($location_info[
'lat']) || empty($location_info[
'lng'])) {
479 $popup_content = isset($location_info[
'html']) && !empty($location_info[
'html']) ? $location_info[
'html'] : $location_info[
'desc'];
480 $html = str_replace(
'',
'', preg_replace(
"/'/",
"\'", $popup_content));
481 $html = preg_replace(
'/(\r\n|\r|\n)/s',
'<br />', $html);
482 $title = preg_replace(
'/\s/',
'_', $location_info[
'title']);
483 $title = preg_replace(
'/(\'|\.)/',
'_', $title);
484 $location_lat = (float) $location_info[
'lat'];
485 $location_lng = (float) $location_info[
'lng'];
486 if (isset($cached_result[$child_assetid])) {
487 $location_lat = $cached_result[$child_assetid][
'lat'];
488 $location_lng = $cached_result[$child_assetid][
'lng'];
492 var marker = addMarker(
'<?php echo $title ?>' ,<?php echo $location_lat; ?>, <?php echo $location_lng; ?>,
'<?php echo $location_info['icon
']; ?>',
'<?php echo $html;?>', <?php echo $street_view ?
'true' :
'false'; ?>);
494 if ($toggle_root_nodes && !$listing_ldap_user) {
495 if (isset($assets_parent[$child_assetid])) {
499 markerRootNodes[
'<?php echo $assets_parent[$child_assetid][0]; ?>'][
'<?php echo $child_assetid;?>'] = marker;
504 allMarkerList[
'<?php echo $child_assetid; ?>'] = marker;
506 if (!$listing_ldap_user) {
510 markerTypes[
'<?php echo $res[$child_assetid][0]['type_code
']; ?>'][
'<?php echo $child_assetid;?>'] = marker;
516 if ($dynamic_lat && $dynamic_lng) {
518 var marker = addMarker(
'center', <?php echo (
float) $dynamic_lat; ?>, <?php echo (
float) $dynamic_lng; ?>);
525 if ($create_location) {
546 $multiple_keywords = extract_keywords($combination);
547 $replacements = Array();
548 foreach ($multiple_keywords as $keyword) {
549 $replacements[$keyword] = $asset->getKeywordReplacement($keyword);
552 replace_keywords($combination, $replacements);
570 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $name,
'major');
571 if (empty($link))
return $null;
572 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
588 $dynamic_vars = $this->
attr(
'dynamic_vars');
589 if (!isset($dynamic_vars[$variable_name]))
return '';
592 $value = $parameter_map->getParameterValue($variable_name);
595 $value = array_get_index($dynamic_vars, $variable_name,
'');
612 $keywords = parent::_getContentsKeywords();
613 $keywords[
'location_name'] = translate(
'google_map_name_keyword');
614 $keywords[
'location_latitude'] = translate(
'google_map_latitude_keyword');
615 $keywords[
'location_longitude'] = translate(
'google_map_longitude_keyword');
616 $keywords[
'location_description'] = translate(
'google_map_description_keyword');
617 $keywords[
'location_icon_url'] = translate(
'google_map_icon_url_keyword');
618 $keywords[
'google_map'] = translate(
'google_map_initialisation');
620 $keywords[
'street_view'] = translate(
'google_map_street_view');
621 $keywords[
'toggle_street_view_window'] = translate(
'google_map_toggle_street_view_window');
622 $keywords[
'toggle_new_address_list']= translate(
'google_map_toggle_new_address_list');
623 $keywords[
'toggle_tool_bar'] = translate(
'google_map_toggle_tool_bar');
624 $keywords[
'tool_bar'] = translate(
'google_map_tool_bar');
625 $keywords[
'toggle_address_finder'] = translate(
'google_map_toggle_address_finder');
627 $keywords[
'toggle_asset_types'] = translate(
'google_map_toggle_asset_types');
628 $keywords[
'toggle_root_nodes'] = translate(
'google_map_toggle_root_nodes');
630 $keywords[
'address_finder'] = translate(
'google_map_address_finder');
631 $keywords[
'new_address_list'] = translate(
'google_map_new_address_list');
632 $keywords[
'asset_builder'] = translate(
'google_map_asset_builder');
634 $keywords[
'get_closest_location'] = translate(
'google_map_get_closest_location');
635 $keywords[
'clear_new_markers'] = translate(
'google_map_clear_new_markers');
636 $keywords[
'map_type_menu'] = translate(
'google_map_map_type_menu');
653 if ($keyword ==
'google_map') {
654 $map_code = $this->
attr(
'map_code');
656 }
else if ($keyword ==
'street_view') {
657 $street_view_code = $this->
attr(
'street_view_code');
658 return $street_view_code;
659 }
else if ($keyword ==
'address_finder') {
660 $street_view_enabled = $this->
attr(
'enable_street_view');
661 $street_view_enabled = $street_view_enabled ?
'true' :
'false';
662 return '<div id="address_finder" class="address_finder_div">
663 <form action="#" onsubmit="findLocationFromAddress(this.address.value, null, null, '.$street_view_enabled.
'); return false">
665 <input type="text" style="width:400px;" name="address" value="" />
666 <input type="submit" value="Find Location" />
670 }
else if ($keyword ==
'new_address_list') {
671 return '<div id="new_address_list" class="new_address_list">
673 }
else if ($keyword ==
'map_type_menu') {
674 $map_menu =
'<ul id="map_menu" class="map_type_menu" style="list-style:none;">
675 <li><button onClick="setMapType(google.maps.MapTypeId.ROADMAP);">ROADMAP</button></li>
676 <li><button onClick="setMapType(google.maps.MapTypeId.SATELLITE);">SATELLITE</button></li>
677 <li><button onClick="setMapType(google.maps.MapTypeId.TERRAIN);">TERRAIN</button></li>
678 <li><button onClick="setMapType(google.maps.MapTypeId.HYBRID);">HYBRID</button></li>';
679 $map_menu .=
'</ul>';
681 }
else if ($keyword ==
'clear_new_markers') {
682 return '<a href="javascript:clearNewMarker(newMarkers);clearNewMarker(newPolylines);">Clear New Markers</a>';
683 }
else if ($keyword ==
'get_closest_location') {
684 return '<a href="javascript:getClosestLocation();">Get Closest Location</a>';
685 }
else if ($keyword ==
'asset_builder') {
686 return '<div id="asset_builder" class="asset_builder_div">NEST YOUR ASSET BUILDER HERE</div>';
687 }
else if ($keyword ==
'toggle_street_view_window') {
688 return '<a href="javascript:toggleDiv(\'street_view\');" id="toggle_street_view">Toggle Street View</a>';
689 }
else if ($keyword ==
'toggle_new_address_list') {
690 return '<a href="javascript:toggleDiv(\'new_address_list\');" id="toggle_new_address_list">Toggle New Address List</a>';
691 }
else if ($keyword ==
'toggle_address_finder') {
692 return '<a href="javascript:toggleDiv(\'address_finder\');" id="toggle_address_finder">Toggle Address Finder</a>';
693 }
else if ($keyword ==
'toggle_tool_bar') {
694 return '<a href="javascript:toggleDiv(\'tool_bar_list\');" id="toggle_tool_bar">Toggle Tool Bar</a>';
695 }
else if ($keyword ==
'tool_bar') {
697 <ul id="tool_bar_list" class="tool_bar" style="list-style:none;">
698 <li><a href="javascript:addListeners(\'navigate\', this.id);" style="color:red;" title="Navigate Map" >
699 <img src="'.sq_web_path(
'data').
'/asset_types/google_map/images/map.png'.
'" style="border-color:red;border:2px solid;" id="navigate_tool" name="navigate_tool"/>
703 <a href="javascript:addListeners(\'add_marker\', this.id);" style="color:white;" title="Add Marker">
704 <img src="'.sq_web_path(
'data').
'/asset_types/google_map/images/arrowdown.png'.
'" style="border-color:white;border:2px solid;" id="add_marker_tool" name="add_marker_tool"/>
708 <a href="javascript:addListeners(\'street_view\', this.id);" style="color:white;" title="Street View">
709 <img src="'.sq_web_path(
'data').
'/asset_types/google_map/images/binocular.png'.
'" style="border-color:white;border:2px solid;" id="street_view_tool" name="street_view_tool"/>
713 }
else if ($keyword ==
'toggle_asset_types') {
714 $asset_types = $this->
attr(
'types');
716 foreach ($asset_types as $type => $inherit) {
717 $result .=
'<a href="javascript:toggleDisplay(markerTypes, \''.$type.
'\')
">Toggle '.ucwords(str_replace('_', ' ', $type)).'</a><br />';
720 } else if ($keyword == 'toggle_root_nodes') {
721 $root_nodes = $this->getRootNodes();
723 foreach ($root_nodes as $root_assetid) {
724 $root_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($root_assetid);
725 $result .= '<a href="javascript:toggleDisplay(markerRootNodes, \
''.$root_assetid.
'\')
">Toggle '.$root_asset->attr('name').'</a><br />';
729 parent::getKeywordReplacement($keyword);
732 }//end getKeywordReplacement()
744 public function getMappedKeyword($type_code, $keyword)
746 $keywords_list = $this->attr('asset_types_keywords');
747 if (isset($keywords_list[$type_code])) {
749 case 'location_name':
750 return str_replace('%', '', $keywords_list[$type_code]['name_keyword']);
752 case 'location_latitude':
753 return str_replace('%', '', $keywords_list[$type_code]['latitude_keyword']);
755 case 'location_longitude':
756 return str_replace('%', '', $keywords_list[$type_code]['longitude_keyword']);
758 case 'location_description':
759 return str_replace('%', '', $keywords_list[$type_code]['description_keyword']);
761 case 'location_icon_url':
762 return str_replace('%', '', $keywords_list[$type_code]['icon_url_keyword']);
768 } else if ($type_code == 'google_map_location') {
770 case 'location_name':
771 return 'asset_attribute_name';
773 case 'location_latitude':
774 return 'asset_attribute_latitude';
776 case 'location_longitude':
777 return 'asset_attribute_longitude';
779 case 'location_description':
780 return 'asset_attribute_description';
782 case 'location_icon_url':
783 return 'asset_attribute_icon_url';
792 }//end getMappedKeyword()
803 function _getDefaultBodycopyContent($bodycopy_code)
805 switch ($bodycopy_code) {
806 case 'page_contents':
809 case 'default_format':
810 return '<a href="javascript:getInfo(\
'%asset_assetid%\');">%asset_name%</a>';
812 return '%location_name% - %location_description%';
815 <fieldset style=
"width:200px;color:black;background:#DDDDDD;">
816 <legend style=
"font-weight:bold;">New Marker</legend>
817 <label
for=
"found">Location</label>
818 <input
type=
"text" id=
"found" style=
"width:100%;"/>
819 <input type=
"hidden" id=
"depth" value=
"" style=
"width:100%;"/>
820 <label
for=
"depth">Who drowned here?</label>
821 <input type=
"text" id=
"icon" style=
"width:100%;"/>
822 <input type=
"hidden" id=
"longitude" value=
"' , lng , '"/>
823 <input type=
"hidden" id=
"latitude" value=
"' , lat , '"/><br />
824 <input type=
"submit" value=
"Add Location" style=
"margin-left:20px;"/>
826 $content = ob_get_contents();
832 parent::_getDefaultBodycopyContent($bodycopy_code);
848 $sql =
'SELECT minorid FROM sq_ast_lnk WHERE majorid = \''.$root_id.
'\' AND minorid IN (\
''.implode(
"', '", $assetids).
'\')
';
850 $query = MatrixDAL::preparePdoQuery($sql);
851 $children = MatrixDAL::executePdoAssoc($query);
853 if (empty($children)) {
854 $root_asset = $GLOBALS['SQ_SYSTEM
']->am->getAsset($root_id);
855 if (implements_interface($root_asset, 'bridge
')) {
856 $children = $root_asset->getChildren($root_id);
857 $children_ids = Array();
858 foreach ($children as $assetid => $type_code_info) {
859 $children_ids[] = Array ('minorid
' => $assetid);
861 $children = $children_ids;
867 }//end find_children()
876 public function getGoogleMapLocationAssetAttributeId()
878 $sql = 'select name, attrid from sq_ast_attr where type_code = \
'google_map_location\' and name IN (\'name\', \'description\', \'latitude\', \'longitude\')';
882 if (!empty($result)) {
884 <script
type=
"text/javascript">
888 foreach ($result as $attr_name => $attr_id_info) {
891 FormEle.<?php echo $attr_name; ?> =
'<?php echo 'google_map_location_0_
'.$attr_id_info[0]['attrid
']; ?>';
913 <script
type=
"text/javascript">
915 var center =
new google.maps.LatLng(centerLatitude, centerLongitude);
916 panoramaOptions = { position:center };
917 myPano =
new google.maps.StreetViewPanorama(document.getElementById(
"street_view"), panoramaOptions);
918 map.setStreetView(myPano);
933 if (empty($this->api_key)) {
934 $this->api_key = $this->
attr(
'api_key');
936 $base_url =
"http://maps.googleapis.com/maps/api/geocode/xml";
937 $request_url = $base_url.
"?address=" . urlencode($address).
'&sensor=false';
939 $geocode_pending = TRUE;
944 while ($geocode_pending) {
948 'RETURNTRANSFER' => 1,
951 $details = fetch_url($request_url, $options);
952 $maps_xml = $details[
'response'];
954 $xml = simplexml_load_string($maps_xml) or die(
"url not loading");
956 $status = (string) $xml->status;
958 if ($status ==
"OK") {
959 $geocode_pending =
false;
960 $result = $xml->result;
962 $coordinates = $result[0]->geometry->location;
964 $lat = (string) $coordinates->lat;
965 $lng = (
string) $coordinates->lng;
974 $geocode_pending = FALSE;
980 if (!empty($lat) && !empty($lng)) {