PDA

Zobacz pełną wersję : Moduł tras motocyklowych "Warning: Invalid argument supplied for foreach() in" ?



gregfil
30-03-2013, 16:49
Od 2-ch lat mozolnie tworzę lokalny mały portal motocyklowy. Strona oparta jest na jommla1.5 oraz Community Builder 1.9. A ostatnio znalałem ciekawy komponent który idealnie pasuje do mojej stronki: joomGPStrack. Koponent udałomi się uruchomić z niewielkimi problemami z bazą danych(zmiana: #__ na jos_).
Do tego komponentu jest moduł latest track i z nim mam problemy. Po uruchomieniu modułu wyświetlakomunikat Warning: Invalid argument supplied for foreach() in w pliku deflaut. Proszę opomoc.
Pliki modułu:
default.php


<?php
/**
* @version 1.0 $Id: default.php 803 2009-08-22
* @package joomGPStracks
* @copyright (C) 2009 Michael Pfister
* @license GNU/GPL2

* You should have received a copy of the GNU General Public License
* along with Idoblog; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/** ensure this file is being included by a parent file */
defined('_JEXEC') or die( 'Restricted access' );

if($params->get('style') == 0):
foreach($tracks as $track) {
$link = JRoute::_('index.php?option=com_joomgpstracks&view=tracks&layout=track&id='.$track->id);
echo '<div style="margin-bottom:20px;">';
echo '<img src="http://maps.google.com/staticmap?center='.$track->start_n.','.$track->start_e.'&zoom='.$zoom.'&size='.$width.'x'.$heigth.'&maptype='.$map.'&markers='.$track->start_n.','.$track->start_e.','.$color.'&key='.$apikey.'&sensor=false" >';
echo '<div><a href="'.$link.'">'.$track->title.'</a></div>';
if($params->get('cats') != 0):
echo '<div>'.$track->cat.'</div>';
endif;
if($params->get('distance') != 0):
echo '<div>'.$track->distance.' KM</div>';
endif;
echo '</div></center>';
echo '<hr />';
}
elseif($params->get('style') == 1):
echo '<table><tr>';
foreach($tracks as $track) {
$link = JRoute::_('index.php?option=com_joomgpstracks&view=tracks&layout=track&id='.$track->id);
echo '<td align="center" style="padding: 10px" valign="top">';
echo '<img src="http://maps.google.com/staticmap?center='.$track->start_n.','.$track->start_e.'&zoom='.$zoom.'&size='.$width.'x'.$heigth.'&maptype='.$map.'&markers='.$track->start_n.','.$track->start_e.','.$color.'&key='.$apikey.'&sensor=false" >';
echo '<div><a href="'.$link.'">'.$track->title.'</a></div>';
if($params->get('cats') != 0):
echo '<div>'.$track->cat.'</div>';
endif;
if($params->get('distance') != 0):
echo '<div>'.$track->distance.' KM</div>';
endif;
echo '</td>';
}
echo '</tr></table>';
endif;
?>

Pozostałe pliki to:
helper.php

<?php
/**
* @version 1.0 $Id: helper.php 803 2009-08-22
* @package joomGPStracks
* @copyright (C) 2009 Michael Pfister
* @license GNU/GPL2

* You should have received a copy of the GNU General Public License
* along with Idoblog; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/** ensure this file is being included by a parent file */
defined('_JEXEC') or die( 'Restricted access' );

class modJoomgpstracksLatestHelper {

function getTracks($count) {
global $mainframe;

$db =& JFactory::getDBO();

$query = "SELECT a.*, b.title as cat FROM #__gps_tracks AS a"
. "\n LEFT JOIN #__gps_cats AS b ON b.id=a.catid"
. "\n ORDER BY id DESC"
. "\n LIMIT ".$count
;
$db->setQuery($query);
$result = $db->loadObjectList();

return $result;
}

function getApiKey() {
global $mainframe;

$db =& JFactory::getDBO();

$query = "SELECT apikey FROM #__gps_config"
. "\n WHERE id='1'"
;
$db->setQuery($query);
$result = $db->loadResult();

return $result;
}
}
?>


i mod_joomgps_trac_latest.php

<?php
/**
* @version 1.0 $Id: mod_joomgpstracks_latest.php 803 2009-08-22
* @package joomGPStracks
* @copyright (C) 2009 Michael Pfister
* @license GNU/GPL2

* You should have received a copy of the GNU General Public License
* along with Idoblog; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/** ensure this file is being included by a parent file */
defined('_JEXEC') or die( 'Restricted access' );

require_once (dirname(__FILE__).DS.'helper.php');
$latest = new modJoomgpstracksLatestHelper;

$width = $params->get('width');
$heigth = $params->get('heigth');
$zoom = $params->get('zoom');
$map = $params->get('map');
$color = $params->get('color');
$count = $params->get('count');
$tracks = $latest->getTracks($count);
$apikey = $latest->getApiKey();


require(JModuleHelper::getLayoutPath('mod_joomgpst racks_latest'));

?>


Baza danych:

CREATE TABLE IF NOT EXISTS `jos_gps_cats` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`parent` INT( 10 ) NOT NULL DEFAULT '0',
`title` varchar(30) NOT NULL,
`description` varchar(255) NOT NULL,
`image` varchar(60) NOT NULL,
`ordering` int(10) NOT NULL,
`published` int(10) NOT NULL,
`checked_out` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `jos_gps_config` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`gid` int(10) NOT NULL,
`apikey` varchar(100) NOT NULL,
`unit` varchar(20) NOT NULL,
`type` varchar(30) NOT NULL,
`max_size` int(10) NOT NULL,
`terms` int(10) NOT NULL,
`terms_id` int(10) NOT NULL,
`sort` int(10) NOT NULL,
`map_height` int(10) NOT NULL,
`map_width` int(10) NOT NULL,
`map_type` int(5) NOT NULL,
`charts_width` int(10) NOT NULL,
`charts_heigth` int(10) NOT NULL,
`charts_linec` varchar(6) NOT NULL,
`charts_bg` varchar(6) NOT NULL,
`profile` varchar(5) NOT NULL DEFAULT '0',
`template` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`comment_who` INT( 5 ) NOT NULL DEFAULT '1',
`inform_autor` INT( 5 ) NOT NULL DEFAULT '0',
`captcha` INT( 5 ) NOT NULL DEFAULT '0',
`ordering` VARCHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`comments` INT( 1 ) NOT NULL,
`access` INT( 2 ) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `jos_gps_tracks` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(10) NOT NULL,
`catid` int(10) NOT NULL,
`title` varchar(60) NOT NULL,
`file` varchar(50) NOT NULL,
`terrain` varchar(255) NOT NULL,
`description` text NOT NULL,
`published` int(10) NOT NULL DEFAULT '1',
`date` date NOT NULL DEFAULT '0000-00-00',
`hits` int(10) NOT NULL,
`checked_out` int(10) NOT NULL,
`start_n` varchar(20) NOT NULL,
`start_e` varchar(20) NOT NULL,
`distance` varchar(30) NOT NULL,
`ele_asc` int(10) NOT NULL,
`ele_desc` int(10) NOT NULL,
`level` int(5) NOT NULL,
`access` INT( 2 ) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `jos_gps_votes` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`trackid` int(10) NOT NULL,
`rating` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `jos_gps_terrain` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL,
`published` int(5) NOT NULL,
`checked_out` int(5) NOT NULL,
`ordering` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `jos_gps_comments` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`tid` INT( 10 ) NOT NULL ,
`user` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`title` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`text` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`email` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`homepage` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`published` INT( 5 ) NOT NULL ,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM;

INSERT INTO `jos_gps_config` (`id`, `gid`, `apikey`, `unit`, `type`, `max_size`, `terms`, `terms_id`, `sort`, `map_height`, `map_width`, `map_type`, `charts_width`, `charts_heigth`, `charts_linec`, `charts_bg`, `profile`, `template`, `comment_who`, `inform_autor`, `captcha`, `ordering`, `comments`) VALUES
(1, 18, '', 'Kilometer', 'jpg,png,gif', 200, 1, 46, 10, 400, 600, 0, 600, 180, 'FF0000', '0000CC', 'ku', 'default', 0, 1, 0, 'DESC', 1);

Nie znam się na programowaniu. Moja dotychczasowa styczność z php polegała na wycinaniu i wklejaniu w tabelkach lub ewentualna drobne zmiany które robiłem intuicyjne. Proszę o pomoc.