Elxis CMS Forum

Support => Technical support => Topic started by: Amigamerlin on April 16, 2013, 14:40:31

Title: Erron on PHP/Mysql ELXIS 2009.3 - Component Com_Maps [SOLVED]
Post 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
Code: [Select]
<?php
global $mainframe;
require_once(
$mainframe->getCfg(&#39;absolute_path&#39;).&#39;/components/com_maps/maps.html.php&#39;);
require_once($mainframe->getCfg(&#39;absolute_path&#39;).&#39;/administrator/components/com_maps/includes/maps.class.php&#39;);
require_once($mainframe->getCfg(&#39;absolute_path&#39;).&#39;/administrator/components/com_maps/includes/mapsxml.php&#39;);

$wtask trim(mosGetParam($_REQUEST, &#39;task&#39;, &#39;&#39;));

$cmaps = new MapsClass();

class 
mapsFront {

public $task = &#39;&#39;;
public $id 0;
public $lid 0;
private $plugin_name = &#39;&#39;;
private $tmpl_name = &#39;&#39;;
private $ajax 0;

/*********************/
/* MAGIC CONSTRUCTOR */
/*********************/
public function __construct() {
global $wtask$cmaps$task;

$this->task $task;
$this->id intval(mosGetParam($_REQUEST, &#39;id&#39;, 0));
$this->lid intval(mosGetParam($_REQUEST, &#39;lid&#39;, 0));
$this->ajax intval(mosGetParam($_REQUEST, &#39;ajax&#39;, 0));
}


/*******************/
/* RUN FOREST RUN! */
/*******************/
public function run() {
global $eshop$my$mainframe$cmaps;

switch($this->task) {
case &#39;show&#39;: $this->showLocation(); break;
default: $this->frontpage(); break;
}
}

private function frontpage() {
global $database$cmaps$weathers$mainframe$weatherparams$fmanager;

$database->setQuery(&#39;SELECT * FROM #__maps WHERE published=1 ORDER BY ordering&#39;);
$rows $database->loadObjectList();

$ctmpl null;

$tmpl $cmaps->cfg->get(&#39;TEMPLATE&#39;, &#39;default&#39;);

if ( file_exists($cmaps->template_path.&#39;/&#39;.$tmpl.&#39;/&#39;.$tmpl.&#39;.php&#39;) ) {
require_once($cmaps->template_path.&#39;/&#39;.$tmpl.&#39;/&#39;.$tmpl.&#39;.php&#39;);

$tmplClass = &#39;mapTemplate_&#39;.strtolower($tmpl);

if ( class_exists($tmplClass) ) {
$ctmpl = new $tmplClass();
}
}

if ( isset($ctmpl) && method_exists($ctmpl, &#39;ListMaps&#39;) ) {
$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(&#39;index.php?option=com_maps&Itemid=&#39;.$Itemid));
}
return;
}

require_once($cmaps->apath.&#39;/includes/GoogleMapAPI.php&#39;);

$map = new GoogleMapAPI(&#39;map_&#39;.$row->id);

$mapparams = new mapParameters($row->params$cmaps->apath.&#39;/xml/maps.xml&#39;, &#39;map&#39;);

$map->bindParameters($mapparams);
$map->setWidth($mapparams->get(&#39;width&#39;, &#39;500px&#39;));
$map->setHeight($mapparams->get(&#39;height&#39;, &#39;500px&#39;));

$marker_url $cmaps->getMarkerPath(true);

$active_icon_key = &#39;&#39;;
if ($mapparams->get(&#39;marker_icon&#39;)) {
$active_icon_key $marker_url.&#39;/&#39;.$mapparams->get(&#39;marker_icon&#39;);
}

$database->setQuery(&#39;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 AND
      c.published AND
  a.category_id c.id AND
  x.location_id a.id and
  x.map_id = &#39;.$row->id.&#39;
ORDER BY x.ordering&#39;);
$locations $database->loadObjectList();

$ctmpl null;

$tmpl $cmaps->cfg->get(&#39;TEMPLATE&#39;, &#39;default&#39;);

if ( file_exists($cmaps->template_path.&#39;/&#39;.$tmpl.&#39;/&#39;.$tmpl.&#39;.php&#39;) ) {
require_once($cmaps->template_path.&#39;/&#39;.$tmpl.&#39;/&#39;.$tmpl.&#39;.php&#39;);

$tmplClass = &#39;mapTemplate_&#39;.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 = &#39;&#39;;

if ( isset($ctmpl) && method_exists($ctmpl, &#39;InfoWindow&#39;) ) {
$html_text $ctmpl->InfoWindow($loc);
} else {
$html_text $cmaps->getDescription($loc->id, &#39;location&#39;);

}

$params = new mapParameters($loc->location_params$cmaps->apath.&#39;/xml/locations.xml&#39;, &#39;location&#39;);
$catparams = new mapParameters($loc->cat_params$cmaps->apath.&#39;/xml/categories.xml&#39;, &#39;category&#39;);

$marker_icon = &#39;&#39;;

if (($this->lid == $loc->id) && ($active_icon_key != &#39;&#39;)) {
$marker_icon $active_icon_key;
} else if ( $params->get(&#39;marker_icon&#39;) ) {
$marker_icon $marker_url.&#39;/&#39;.$params->get(&#39;marker_icon&#39;);
} else if ( $catparams->get(&#39;marker_icon&#39;) ) {
$marker_icon $marker_url.&#39;/&#39;.$catparams->get(&#39;marker_icon&#39;);
}

$map->addMarkerByCoords($loc->longitude$loc->latitude$loc_name$html_text, &#39;&#39;, $marker_icon);

if ( $this->lid == $loc->id ) {
$clat $loc->latitude;
$clong $loc->longitude;
}

unset($params$catparams);

$lids[] = $loc->id;
}
}

/* Polylines */
$database->setQuery(&#39;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 (&#39;.implode(&#39;,&#39;,$lids).&#39;) AND l.loc2_id IN (&#39;.implode(&#39;,&#39;,$lids).&#39;) AND
  l.loc1_id l1.id AND
  l.loc2_id l2.id&#39;);
$lines $database->loadObjectList();

foreach ( $lines as $line ) {
$map->addPolyLineByCoords($line->lon1$line->lat1$line->lon2$line->lat2false$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(&#39;width&#39;, &#39;500px&#39;); ?>; height:<?php echo $mapparams->get(&#39;height&#39;, &#39;500px&#39;); ?>; vertical-align: top;">
<?php $map->printMap();?>
</td>
<?php
if ($mapparams->get(&#39;legend&#39;, 0)) {
$cmaps->convertSize(&#39;180px&#39;);
$cmaps->convertSize(&#39;180%&#39;);
$cmaps->convertSize(&#39;180&#39;);

$legend_size $cmaps->convertSize($mapparams->get(&#39;legend_width&#39;, &#39;180px&#39;));
?>

<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 != &#39;&#39;) {
?>

<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(&#39;SELECT DISTINCT c.*
FROM #__map_locations a, #__map_categories c, #__map_xloc x
WHERE a.published AND
      c.published AND
  a.category_id c.id AND
  x.location_id a.id and
  x.map_id = &#39;.$row->id.&#39;
ORDER BY c.name&#39;);
$legends $database->loadObjectList();

$params = new mapParameters(&#39;&#39;, $cmaps->apath.&#39;/xml/categories.xml&#39;, &#39;category&#39;);
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.&#39;/&#39;.$_params->marker_icon; ?>" /> <?php echo $cmaps->getName($legend); ?>
</div>
<?php
}
}
?>

</td>
<?php
}?>

</tr>
<?php if ($mapparams->get(&#39;sidebar&#39;, 0)) { ?>
<tr>
<td colspan="2"<?php $map->printSidebar(); ?></td>
</tr>
<?php ?>
</table>

        <?php

if ( $this->ajax ) {
// echo &#39;<script language="javascript" type="text/javascript" charset="utf-8">&#39;.$map->getOnLoadFunction().&#39;;</script>&#39;;
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.
Title: Re: Erron on PHP/Mysql ELXIS 2009.3 - Component Com_Maps
Post by: datahell on April 16, 2013, 21:35:08
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.
Title: Re: Erron on PHP/Mysql ELXIS 2009.3 - Component Com_Maps
Post by: Amigamerlin on April 16, 2013, 22:44:16
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.