include dirname(__FILE__) . '/../../../config/config.inc.php';
include dirname(__FILE__) . '/../classes/EbayCategorySpecific.php';
include dirname(__FILE__) . '/../classes/EbayCategoryCondition.php';
if (!Tools::getValue('token') || Tools::getValue('token') != Configuration::get('EBAY_SECURITY_TOKEN')) {
    die('ERROR : INVALID TOKEN');
}
function loadItemsMap($row)
{
    return $row['id'];
}
/* Fix for limit db sql request in time */
sleep(1);
$category = new EbayCategory((int) Tools::getValue('ebay_category'));
if (!Configuration::get('EBAY_SPECIFICS_LAST_UPDATE') || Configuration::get('EBAY_SPECIFICS_LAST_UPDATE') < date('Y-m-d\\TH:i:s', strtotime('-3 days')) . '.000Z') {
    $res = EbayCategorySpecific::loadCategorySpecifics();
    $res &= EbayCategoryCondition::loadCategoryConditions();
    if ($res) {
        Configuration::updateValue('EBAY_SPECIFICS_LAST_UPDATE', date('Y-m-d\\TH:i:s.000\\Z'), false, 0, 0);
    }
}
$item_specifics = $category->getItemsSpecifics();
$item_specifics_ids = array_map('loadItemsMap', $item_specifics);
if (count($item_specifics_ids)) {
    $sql = 'SELECT `id_ebay_category_specific_value` as id, `id_ebay_category_specific` as specific_id, `value`
		FROM `' . _DB_PREFIX_ . 'ebay_category_specific_value`
		WHERE `id_ebay_category_specific` in (' . implode(',', $item_specifics_ids) . ')';
    $item_specifics_values = DB::getInstance()->executeS($sql);
} else {
    $item_specifics_values = array();
}
foreach ($item_specifics as &$item_specific) {
if (!Tools::getValue('token') || Tools::getValue('token') != Configuration::get('EBAY_SECURITY_TOKEN')) {
    die('ERROR : INVALID TOKEN');
}
$id_ebay_profile = (int) Tools::getValue('profile');
$ebay_profile = new EbayProfile($id_ebay_profile);
function loadItemsMap($row)
{
    return $row['id'];
}
/* Fix for limit db sql request in time */
sleep(1);
$category = new EbayCategory($ebay_profile, (int) Tools::getValue('ebay_category'));
if (!$ebay_profile->getConfiguration('EBAY_SPECIFICS_LAST_UPDATE') || $ebay_profile->getConfiguration('EBAY_SPECIFICS_LAST_UPDATE') < date('Y-m-d\\TH:i:s', strtotime('-3 days')) . '.000Z') {
    $time = time();
    $res = EbayCategorySpecific::loadCategorySpecifics($id_ebay_profile);
    $res &= EbayCategoryCondition::loadCategoryConditions($id_ebay_profile);
    if ($res) {
        $ebay_profile->setConfiguration('EBAY_SPECIFICS_LAST_UPDATE', date('Y-m-d\\TH:i:s.000\\Z'), false);
    }
}
$item_specifics = $category->getItemsSpecifics();
$item_specifics_ids = array_map('loadItemsMap', $item_specifics);
if (count($item_specifics_ids)) {
    $sql = 'SELECT `id_ebay_category_specific_value` as id, `id_ebay_category_specific` as specific_id, `value`
		FROM `' . _DB_PREFIX_ . 'ebay_category_specific_value`
		WHERE `id_ebay_category_specific` in (' . implode(',', $item_specifics_ids) . ')';
    $item_specifics_values = DB::getInstance()->executeS($sql);
} else {
    $item_specifics_values = array();
}
foreach ($item_specifics as &$item_specific) {