Elxis CMS Forum
Support => Technical support => Topic started by: Amigamerlin on April 16, 2013, 14:40:31
-
hello to all
I'm facing a strange error with component maps.
The error is:
mysql Errore [1064] : EXECUTE
URI: index2.php?option=com_maps&task=show&id=1&ajax=1
Message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND l.loc2_id IN () AND l.loc1_id = l1.id AND l.loc2_i' at line 5
SELECT l.*, l1.longitude as lon1, l1.latitude as lat1, l2.longitude as lon2, l2.latitude as lat2 FROM elx_map_lines l, elx_map_locations l1, elx_map_locations l2 WHERE l.loc1_id IN () AND l.loc2_id IN () AND l.loc1_id = l1.id AND l.loc2_id = l2.id
PHP Errore [Warning]
URI: index2.php?option=com_maps&task=show&id=1&ajax=1
Path: /components/com_maps/maps.php
Line: 181
Invalid argument supplied for foreach()
But I can't find what's is wrong.
Here the maps.php code
<?php
global $mainframe;
require_once($mainframe->getCfg('absolute_path').'/components/com_maps/maps.html.php');
require_once($mainframe->getCfg('absolute_path').'/administrator/components/com_maps/includes/maps.class.php');
require_once($mainframe->getCfg('absolute_path').'/administrator/components/com_maps/includes/mapsxml.php');
$wtask = trim(mosGetParam($_REQUEST, 'task', ''));
$cmaps = new MapsClass();
class mapsFront {
public $task = '';
public $id = 0;
public $lid = 0;
private $plugin_name = '';
private $tmpl_name = '';
private $ajax = 0;
/*********************/
/* MAGIC CONSTRUCTOR */
/*********************/
public function __construct() {
global $wtask, $cmaps, $task;
$this->task = $task;
$this->id = intval(mosGetParam($_REQUEST, 'id', 0));
$this->lid = intval(mosGetParam($_REQUEST, 'lid', 0));
$this->ajax = intval(mosGetParam($_REQUEST, 'ajax', 0));
}
/*******************/
/* RUN FOREST RUN! */
/*******************/
public function run() {
global $eshop, $my, $mainframe, $cmaps;
switch($this->task) {
case 'show': $this->showLocation(); break;
default: $this->frontpage(); break;
}
}
private function frontpage() {
global $database, $cmaps, $weathers, $mainframe, $weatherparams, $fmanager;
$database->setQuery('SELECT * FROM #__maps WHERE published=1 ORDER BY ordering');
$rows = $database->loadObjectList();
$ctmpl = null;
$tmpl = $cmaps->cfg->get('TEMPLATE', 'default');
if ( file_exists($cmaps->template_path.'/'.$tmpl.'/'.$tmpl.'.php') ) {
require_once($cmaps->template_path.'/'.$tmpl.'/'.$tmpl.'.php');
$tmplClass = 'mapTemplate_'.strtolower($tmpl);
if ( class_exists($tmplClass) ) {
$ctmpl = new $tmplClass();
}
}
if ( isset($ctmpl) && method_exists($ctmpl, 'ListMaps') ) {
$html_text = $ctmpl->ListMaps($rows);
} else {
mapsHTML::listMaps($rows);
}
}
private function showLocation() {
global $database, $cmaps, $mainframe, $Itemid;
$row = new mapdb($database);
$row->load($this->id);
if (!$row->id || !$row->published) {
if (!$ajax) {
mosRedirect(sefRelToAbs('index.php?option=com_maps&Itemid='.$Itemid));
}
return;
}
require_once($cmaps->apath.'/includes/GoogleMapAPI.php');
$map = new GoogleMapAPI('map_'.$row->id);
$mapparams = new mapParameters($row->params, $cmaps->apath.'/xml/maps.xml', 'map');
$map->bindParameters($mapparams);
$map->setWidth($mapparams->get('width', '500px'));
$map->setHeight($mapparams->get('height', '500px'));
$marker_url = $cmaps->getMarkerPath(true);
$active_icon_key = '';
if ($mapparams->get('marker_icon')) {
$active_icon_key = $marker_url.'/'.$mapparams->get('marker_icon');
}
$database->setQuery('SELECT a.*, c.params as cat_params, x.params as location_params
FROM #__map_locations a, #__map_categories c, #__map_xloc x
WHERE a.published = 1 AND
c.published = 1 AND
a.category_id = c.id AND
x.location_id = a.id and
x.map_id = '.$row->id.'
ORDER BY x.ordering');
$locations = $database->loadObjectList();
$ctmpl = null;
$tmpl = $cmaps->cfg->get('TEMPLATE', 'default');
if ( file_exists($cmaps->template_path.'/'.$tmpl.'/'.$tmpl.'.php') ) {
require_once($cmaps->template_path.'/'.$tmpl.'/'.$tmpl.'.php');
$tmplClass = 'mapTemplate_'.strtolower($tmpl);
if ( class_exists($tmplClass) ) {
$ctmpl = new $tmplClass($this->ajax);
}
}
$clat = 0;
$clong = 0;
$lids = array();
foreach ($locations as $loc) {
if ($loc->longitude && $loc->latitude) {
$loc_name = $cmaps->getName($loc);
$html_text = '';
if ( isset($ctmpl) && method_exists($ctmpl, 'InfoWindow') ) {
$html_text = $ctmpl->InfoWindow($loc);
} else {
$html_text = $cmaps->getDescription($loc->id, 'location');
}
$params = new mapParameters($loc->location_params, $cmaps->apath.'/xml/locations.xml', 'location');
$catparams = new mapParameters($loc->cat_params, $cmaps->apath.'/xml/categories.xml', 'category');
$marker_icon = '';
if (($this->lid == $loc->id) && ($active_icon_key != '')) {
$marker_icon = $active_icon_key;
} else if ( $params->get('marker_icon') ) {
$marker_icon = $marker_url.'/'.$params->get('marker_icon');
} else if ( $catparams->get('marker_icon') ) {
$marker_icon = $marker_url.'/'.$catparams->get('marker_icon');
}
$map->addMarkerByCoords($loc->longitude, $loc->latitude, $loc_name, $html_text, '', $marker_icon);
if ( $this->lid == $loc->id ) {
$clat = $loc->latitude;
$clong = $loc->longitude;
}
unset($params, $catparams);
$lids[] = $loc->id;
}
}
/* Polylines */
$database->setQuery('SELECT l.*, l1.longitude as lon1, l1.latitude as lat1, l2.longitude as lon2, l2.latitude as lat2
FROM #__map_lines l,
#__map_locations l1,
#__map_locations l2
WHERE l.loc1_id IN ('.implode(',',$lids).') AND l.loc2_id IN ('.implode(',',$lids).') AND
l.loc1_id = l1.id AND
l.loc2_id = l2.id');
$lines = $database->loadObjectList();
foreach ( $lines as $line ) {
$map->addPolyLineByCoords($line->lon1, $line->lat1, $line->lon2, $line->lat2, false, $line->color, $line->weight, $line->opacity);
}
if ($clat && $clong) {
$map->disableZoomEncompass();
$map->setCenterCoords($clong, $clat);
}
unset($ctmpl);
if ($this->ajax) {
echo $map->getHeaderJS();
echo $map->getMapJS();
echo $map->getOnLoad();
} else {
$mainframe->addCustomHeadTag($map->getHeaderJS());
$mainframe->addCustomHeadTag($map->getMapJS());
$mainframe->addCustomHeadTag($map->getOnLoad());
}
?>
<table border="0" class="map" style="border-spacing: 0;">
<tr>
<td id="map-image" style="width:<?php echo $mapparams->get('width', '500px'); ?>; height:<?php echo $mapparams->get('height', '500px'); ?>; vertical-align: top;">
<?php $map->printMap();?>
</td>
<?php
if ($mapparams->get('legend', 0)) {
$cmaps->convertSize('180px');
$cmaps->convertSize('180%');
$cmaps->convertSize('180');
$legend_size = $cmaps->convertSize($mapparams->get('legend_width', '180px'));
?>
<td id="map-legend_<?php echo $row->id; ?>" class="map-legend" style="width:<?php echo $legend_size; ?>; vertical-align: top;">
<h3><?php echo $cmaps->lng->MAP_LEGEND; ?></h3>
<?php
if ($active_icon_key != '') {
?>
<div id="legend_0" class="legend_row">
<img src="<?php echo $active_icon_key; ?>" /> <?php echo $cmaps->lng->MAP_ACTIVE_LOCATION; ?>
</div>
<?php
}
$database->setQuery('SELECT DISTINCT c.*
FROM #__map_locations a, #__map_categories c, #__map_xloc x
WHERE a.published = 1 AND
c.published = 1 AND
a.category_id = c.id AND
x.location_id = a.id and
x.map_id = '.$row->id.'
ORDER BY c.name');
$legends = $database->loadObjectList();
$params = new mapParameters('', $cmaps->apath.'/xml/categories.xml', 'category');
foreach ($legends as $legend) {
$_params = $params->parse($legend->params);
if ($_params->marker_icon) {
?>
<div id="legend_<?php echo $legend->id; ?>" class="legend_row">
<img src="<?php echo $marker_url.'/'.$_params->marker_icon; ?>" /> <?php echo $cmaps->getName($legend); ?>
</div>
<?php
}
}
?>
</td>
<?php
}?>
</tr>
<?php if ($mapparams->get('sidebar', 0)) { ?>
<tr>
<td colspan="2"<?php $map->printSidebar(); ?></td>
</tr>
<?php } ?>
</table>
<?php
if ( $this->ajax ) {
// echo '<script language="javascript" type="text/javascript" charset="utf-8">'.$map->getOnLoadFunction().';</script>';
exit;
};
unset($row, $mapparams, $map);
}
}
$mapsF = new mapsFront();
$mapsF->run();
unset($mapsF, $cmaps);
?>
Please anyone can help?
PS. I wrote to Andrej Kambalov about but no news from him :-[
Thanks in advance.
-
The wrong is that the query returns no results as no location ids are set. You can not start a foreach loop without first checking that the data is an non-empty array.
Convert this:
foreach ( $lines as $line ) {
$map->addPolyLineByCoords($line->lon1, $line->lat1, $line->lon2, $line->lat2, false, $line->color, $line->weight, $line->opacity);
}
To this:
if ($lines) {
foreach ( $lines as $line ) {
$map->addPolyLineByCoords($line->lon1, $line->lat1, $line->lon2, $line->lat2, false, $line->color, $line->weight, $line->opacity);
}
}
The above change will fix that specific error although the code needs more improvements.
-
The wrong is that the query returns no results as no location ids are set. You can not start a foreach loop without first checking that the data is an non-empty array.
Convert this:
foreach ( $lines as $line ) {
$map->addPolyLineByCoords($line->lon1, $line->lat1, $line->lon2, $line->lat2, false, $line->color, $line->weight, $line->opacity);
}
To this:
if ($lines) {
foreach ( $lines as $line ) {
$map->addPolyLineByCoords($line->lon1, $line->lat1, $line->lon2, $line->lat2, false, $line->color, $line->weight, $line->opacity);
}
}
The above change will fix that specific error although the code needs more improvements.
Ciao Datahell Thank you for your answers.
You are right, this error was generated by empty value. The problem, is now solved, and was generated by the 2009.3 prototype.js that prevent me to insert location inside map. Then the map still remain blank even if I saved it within the location. I solved the problem updating the prototoype.js to the last version.
Thank you for your help.