<?php

/**
 * @package SP Page Builder
 * @author JoomShaper http://www.joomshaper.com
 * @copyright Copyright (c) 2010 - 2017 JoomShaper
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
//no direct accees
defined ('_JEXEC') or die ('resticted aceess');

// is enable or installed sp soccer
$db = JFactory::getDbo();
$db->setQuery("SELECT enabled FROM #__extensions WHERE element = 'com_spsoccer'");
$is_enabled = $db->loadResult();

jimport( 'joomla.application.component.controller' );

if ($is_enabled) {


	if(!function_exists('getSoccerMatches')) {

		function getSoccerMatches() {

			$db = JFactory::getDbo();
			$query = $db->getQuery(true);

			$query
			->select(array('spsoccer_match_id', 'title'))
			->from($db->quoteName('#__spsoccer_matches'))
			->where($db->quoteName('enabled') . ' = ' . $db->quote(1))
			->where($db->quoteName('played_game') . ' = ' . $db->quote(0))
			->order($db->quoteName('ordering') . ' DESC');

			$db->setQuery($query);

			$match_lists = $db->loadObjectList();

		//print_r($polls);
			if (!empty($match_lists)) {
				foreach ($match_lists as $key => $match_list) {
					$maches[$match_list->spsoccer_match_id] = $match_list->title;
				}
			}else{
				$maches['0'] = 'No Upcoming match found';
			}


			return $maches;
		}
	}

	SpAddonsConfig::addonConfig(
		array(
			'type'=>'content',
			'addon_name'=>'sp_upcoming_match',
			'category'=>'Calcio',
			'title'=>JText::_('COM_SPPAGEBUILDER_ADDON_UM'),
			'desc'=>JText::_('COM_SPPAGEBUILDER_ADDON_UM_DESC'),
			'attr'=>array(
				'general' => array(
					'title'=>array(
						'type'=>'text',
						'title'=>JText::_('COM_SPPAGEBUILDER_ADDON_TITLE'),
						'desc'=>JText::_('COM_SPPAGEBUILDER_ADDON_TITLE_DESC'),
						'std'=>'Up coming match.',
						),

					'match'=>array(
						'type'=>'select',
						'title'=>JText::_('COM_SPPAGEBUILDER_ADDON_UM_SELECT_MATCH'),
						'desc'=>JText::_('COM_SPPAGEBUILDER_ADDON_UM_SELECT_MATCH_DESC'),
						'values'=> getSoccerMatches(),
						'std'=>''
						),

					'cd_finished'=>array(
						'type'=>'text',
						'title'=>JText::_('COM_SPPAGEBUILDER_ADDON_CD_FINISHED_TEXT'),
						'desc'=>JText::_('COM_SPPAGEBUILDER_ADDON_CD_FINISHED_TEXT_DESC'),
						'placeholder'=>'This Match is over !',
						),

					'class'=>array(
						'type'=>'text',
						'title'=>JText::_('COM_SPPAGEBUILDER_ADDON_CLASS'),
						'desc'=>JText::_('COM_SPPAGEBUILDER_ADDON_CLASS_DESC'),
						'std'=> ''
						),
				)
			)
		)
	);
}
