<?php
/**
 * 2007-2015 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * No redistribute in other sites, or copy.
 *
 * @author    RSI <rsi@rsi>
 * @copyright 2007-2015 RSI
 * @license   http://localhost
 */

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');
/* Check to security tocken */
if (Tools::substr(Tools::encrypt('countdownspecials/cron'), 0, 10) != Tools::getValue('token') || !Module::isInstalled('countdownspecials'))
	die('Bad token');
include(dirname(__FILE__).'/countdownspecials.php');

$countdownspecials = new CountdownSpecials();
/* Check if the module is enabled */
if ($countdownspecials->active)
{
	/* Check if the requested shop exists */
	if (_PS_VERSION_ > '1.5.0.0')
	{
	$shops = Db::getInstance()->ExecuteS('SELECT id_shop FROM `'._DB_PREFIX_.'shop`');
	$list_id_shop = array();
	foreach ($shops as $shop)
		$list_id_shop[] = (int)$shop['id_shop'];
	$id_shop = (Tools::getIsset(Tools::getValue('id_shop')) && in_array(Tools::getValue('id_shop'), $list_id_shop)) ? (int)Tools::getValue('id_shop') : (int)Configuration::get('PS_SHOP_DEFAULT');
	$countdownspecials->cron = true;
	/* for the main run initiat the sitemap's files name stored in the database */
	if (!Tools::getIsset(Tools::getValue('continue')))
		$countdownspecials->cron((int)$id_shop);
	}
	if (!Tools::getIsset(Tools::getValue('continue')))
		$countdownspecials->cron();
} 