<?php

/*
 * 2007-2012 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 *         DISCLAIMER   * 
 * *************************************** */
/* Do not edit or add to this file if you wish to upgrade Prestashop to newer
 * versions in the future.
 * ****************************************************
 * @category   Belvg
 * @package    Belvg_Background
 * @author    Alexander Simonchik <support@belvg.com>
 * @site    http://module-presta.com
 * @copyright  Copyright (c) 2010 - 2012 BelVG LLC. (http://www.belvg.com)
 * @license    http://store.belvg.com/BelVG-LICENSE-COMMUNITY.txt
 */
 
require(dirname(__FILE__) . '/../../../../config/config.inc.php');
require(dirname(__FILE__) . '/../../../../init.php');

$token = Tools::getValue('token');
$employees = Employee::getEmployees();
$pattern_name = Tools::getValue('pattern_name');
$id_shop = Tools::getValue('context_shop_id');
$id_shop_group = Tools::getValue('context_shop_group_id');

if (!empty($token)) {
    foreach ($employees as $employee) {
        $token_case = Tools::getAdminToken('AdminModules' . (int)Tab::getIdFromClassName('AdminModules') . (int)$employee['id_employee']);
        if ($token == $token_case) {
            Configuration::updateValue('BBP_DEFAULT_PATTERN', $pattern_name, FALSE, $id_shop_group, $id_shop);
            break;
        }
    }

    //Tools::redirectAdmin(__PS_BASE_URI__ . 'adm/index.php?controller=adminmodules&conf=4&configure=belvg_backgroundpages&token=' . $token . '&module_name=belvg_backgroundpages');
}