[*] BO : #PSFV-94 - added AdminPaymentController
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9635 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1,240 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* 2007-2011 PrestaShop
|
|
||||||
*
|
|
||||||
* NOTICE OF LICENSE
|
|
||||||
*
|
|
||||||
* This source file is subject to the Open Software License (OSL 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/osl-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. If you wish to customize PrestaShop for your
|
|
||||||
* needs please refer to http://www.prestashop.com for more information.
|
|
||||||
*
|
|
||||||
* @author PrestaShop SA <contact@prestashop.com>
|
|
||||||
* @copyright 2007-2011 PrestaShop SA
|
|
||||||
* @version Release: $Revision: 7307 $
|
|
||||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
|
||||||
*/
|
|
||||||
|
|
||||||
class AdminPayment extends AdminTab
|
|
||||||
{
|
|
||||||
public $paymentModules = array();
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$shopID = Context::getContext()->shop->getID(true);
|
|
||||||
|
|
||||||
/* Get all modules then select only payment ones*/
|
|
||||||
$modules = Module::getModulesOnDisk();
|
|
||||||
foreach ($modules AS $module)
|
|
||||||
|
|
||||||
if ($module->tab == 'payments_gateways')
|
|
||||||
{
|
|
||||||
if ($module->id)
|
|
||||||
{
|
|
||||||
if(!get_class($module) == 'SimpleXMLElement')
|
|
||||||
$module->country = array();
|
|
||||||
$countries = DB::getInstance()->executeS('SELECT id_country FROM '._DB_PREFIX_.'module_country WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
|
|
||||||
foreach ($countries as $country)
|
|
||||||
$module->country[] = $country['id_country'];
|
|
||||||
|
|
||||||
if(!get_class($module) == 'SimpleXMLElement')
|
|
||||||
$module->currency = array();
|
|
||||||
$currencies = DB::getInstance()->executeS('SELECT id_currency FROM '._DB_PREFIX_.'module_currency WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
|
|
||||||
foreach ($currencies as $currency)
|
|
||||||
$module->currency[] = $currency['id_currency'];
|
|
||||||
|
|
||||||
if(!get_class($module) == 'SimpleXMLElement')
|
|
||||||
$module->group = array();
|
|
||||||
$groups = DB::getInstance()->executeS('SELECT id_group FROM '._DB_PREFIX_.'module_group WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
|
|
||||||
foreach ($groups as $group)
|
|
||||||
$module->group[] = $group['id_group'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$module->country = NULL;
|
|
||||||
$module->currency = NULL;
|
|
||||||
$module->group = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->paymentModules[] = $module;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function postProcess()
|
|
||||||
{
|
|
||||||
if (Tools::isSubmit('submitModulecountry'))
|
|
||||||
$this->saveRestrictions('country');
|
|
||||||
elseif (Tools::isSubmit('submitModulecurrency'))
|
|
||||||
$this->saveRestrictions('currency');
|
|
||||||
elseif (Tools::isSubmit('submitModulegroup'))
|
|
||||||
$this->saveRestrictions('group');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveRestrictions($type)
|
|
||||||
{
|
|
||||||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'module_'.$type.' WHERE id_shop = '.Context::getContext()->shop->getID(true));
|
|
||||||
foreach ($this->paymentModules as $module)
|
|
||||||
if ($module->active AND isset($_POST[$module->name.'_'.$type.'']))
|
|
||||||
foreach ($_POST[$module->name.'_'.$type.''] as $selected)
|
|
||||||
$values[] = '('.(int)$module->id.', '.Context::getContext()->shop->getID(true).', '.(int)$selected.')';
|
|
||||||
if (sizeof($values))
|
|
||||||
Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'module_'.$type.' (`id_module`, `id_shop`, `id_'.$type.'`) VALUES '.implode(',', $values));
|
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&conf=4'.'&token='.$this->token);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function display()
|
|
||||||
{
|
|
||||||
$this->context = Context::getContext();
|
|
||||||
$displayRestrictions = false;
|
|
||||||
|
|
||||||
$currencies = Currency::getCurrencies();
|
|
||||||
$countries = Country::getCountries($this->context->language->id);
|
|
||||||
$groups = Group::getGroups($this->context->language->id);
|
|
||||||
|
|
||||||
$tokenModules = Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)$this->context->employee->id);
|
|
||||||
echo '<h2 class="space">'.$this->l('Payment modules list').'</h2>';
|
|
||||||
if (isset($this->paymentModules[0]))
|
|
||||||
echo '<input type="button" class="button" onclick="document.location=\'index.php?tab=AdminModules&token='.$tokenModules.'&module_name='.$this->paymentModules[0]->name.'&tab_module=payments_gateways\'" value="'.$this->l('Click to see the list of payment modules.').'" /><br>';
|
|
||||||
|
|
||||||
foreach ($this->paymentModules as $module)
|
|
||||||
if ($module->active)
|
|
||||||
$displayRestrictions= true;
|
|
||||||
if ($displayRestrictions)
|
|
||||||
{
|
|
||||||
|
|
||||||
echo '<br /><h2 class="space">'.$this->l('Payment module restrictions').'</h2>';
|
|
||||||
$textCurrencies = $this->l('Please mark the checkbox(es) for the currency or currencies for which you want the payment module(s) to be available.');
|
|
||||||
$textCountries = $this->l('Please mark the checkbox(es) for the country or countries for which you want the payment module(s) to be available.');
|
|
||||||
$textGroups = $this->l('Please mark the checkbox(es) for the groups for which you want the payment module(s) available.');
|
|
||||||
$this->displayModuleRestrictions($currencies, $this->l('Currencies restrictions'), 'currency', $textCurrencies, 'dollar');
|
|
||||||
echo '<br />';
|
|
||||||
$this->displayModuleRestrictions($groups, $this->l('Groups restrictions'), 'group', $textGroups, 'group');
|
|
||||||
echo '<br />';
|
|
||||||
$this->displayModuleRestrictions($countries, $this->l('Countries restrictions'), 'country', $textCountries, 'world');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
echo '<br>';
|
|
||||||
echo $this->displayWarning($this->l('No payment module installed'));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function displayModuleRestrictions($items, $title, $nameId, $desc, $icon)
|
|
||||||
{
|
|
||||||
$irow = 0;
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<form action="'.self::$currentIndex.'&token='.$this->token.'" method="post" id="form_'.$nameId.'">
|
|
||||||
<fieldset>
|
|
||||||
<legend><img src="../img/admin/'.$icon.'.gif" />'.$title.'</legend>
|
|
||||||
<p>'.$desc.'<p>
|
|
||||||
<table cellpadding="0" cellspacing="0" class="table">
|
|
||||||
<tr>
|
|
||||||
<th style="width: 200px">'.$title.'</th>';
|
|
||||||
foreach ($this->paymentModules as $module)
|
|
||||||
{
|
|
||||||
if ($module->active)
|
|
||||||
{
|
|
||||||
echo '
|
|
||||||
<th>';
|
|
||||||
if ($nameId != 'currency' OR ($nameId == 'currency' AND $module->currencies_mode == 'checkbox'))
|
|
||||||
echo '
|
|
||||||
<input type="hidden" id="checkedBox_'.$nameId.'_'.$module->name.'" value="checked">
|
|
||||||
<a href="javascript:checkPaymentBoxes(\''.$nameId.'\', \''.$module->name.'\')" style="text-decoration:none;">';
|
|
||||||
echo '
|
|
||||||
<img src="'.__PS_BASE_URI__.'modules/'.$module->name.'/logo.gif" alt="'.$module->name.'" title="'.$module->displayName.'" />';
|
|
||||||
if ($nameId != 'currency' OR ($nameId == 'currency' AND $module->currencies_mode == 'checkbox'))
|
|
||||||
echo '
|
|
||||||
</a>';
|
|
||||||
echo '
|
|
||||||
</th>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo '
|
|
||||||
</tr>';
|
|
||||||
foreach ($items as $item)
|
|
||||||
{
|
|
||||||
echo '<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
|
|
||||||
<td>'.$item['name'].'</td>';
|
|
||||||
foreach ($this->paymentModules as $module)
|
|
||||||
{
|
|
||||||
if ($module->active)
|
|
||||||
{
|
|
||||||
if (isset($module->{$nameId}))
|
|
||||||
$value = $module->{$nameId};
|
|
||||||
else
|
|
||||||
$value = array();
|
|
||||||
echo '
|
|
||||||
<td style="text-align: center">';
|
|
||||||
|
|
||||||
if ($nameId == 'country' && isset($module->limited_countries) &&
|
|
||||||
count($module->limited_countries))
|
|
||||||
{
|
|
||||||
if (in_array(strtoupper($item['iso_code']), array_map('strtoupper', $module->limited_countries)))
|
|
||||||
echo '<input type="checkbox" name="'.$module->name.'_'.
|
|
||||||
$nameId.'[]" value="'.$item['id_'.$nameId].'"'.
|
|
||||||
(in_array($item['id_'.$nameId.''], $value) ?
|
|
||||||
' checked="checked"' : '').' />';
|
|
||||||
else
|
|
||||||
echo '--';
|
|
||||||
}
|
|
||||||
else if ($nameId != 'currency' OR ($nameId == 'currency' AND $module->currencies AND $module->currencies_mode == 'checkbox'))
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<input type="checkbox" name="'.$module->name.'_'.$nameId.'[]" value="'.$item['id_'.$nameId].'"'.(in_array($item['id_'.$nameId.''], $value) ? ' checked="checked"' : '').' />';
|
|
||||||
elseif ($nameId == 'currency' AND $module->currencies AND $module->currencies_mode == 'radio')
|
|
||||||
echo '
|
|
||||||
<input type="radio" name="'.$module->name.'_'.$nameId.'[]" value="'.$item['id_'.$nameId].'"'.(in_array($item['id_'.$nameId.''], $value) ? ' checked="checked"' : '').' />';
|
|
||||||
elseif ($nameId == 'currency')
|
|
||||||
echo '--';
|
|
||||||
echo '
|
|
||||||
</td>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo '
|
|
||||||
</tr>';
|
|
||||||
}
|
|
||||||
if ($nameId == 'currency')
|
|
||||||
{
|
|
||||||
echo '
|
|
||||||
<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
|
|
||||||
<td>'.$this->l('Customer currency').'</td>';
|
|
||||||
foreach ($this->paymentModules as $module)
|
|
||||||
if ($module->active)
|
|
||||||
echo '
|
|
||||||
<td style="text-align: center">'.(($module->currencies AND $module->currencies_mode == 'radio') ? '<input type="radio" name="'.$module->name.'_'.$nameId.'[]" value="-1"'.(in_array(-1, $module->{$nameId}) ? ' checked="checked"' : '').' />' : '--').'</td>';
|
|
||||||
echo '
|
|
||||||
</tr>';
|
|
||||||
echo '
|
|
||||||
<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
|
|
||||||
<td>'.$this->l('Shop default currency').'</td>';
|
|
||||||
foreach ($this->paymentModules as $module)
|
|
||||||
if ($module->active)
|
|
||||||
echo '
|
|
||||||
<td style="text-align: center">'.(($module->currencies AND $module->currencies_mode == 'radio') ? '<input type="radio" name="'.$module->name.'_'.$nameId.'[]" value="-2"'.(in_array(-2, $module->{$nameId}) ? ' checked="checked"' : '').' />' : '--').'</td>';
|
|
||||||
echo '
|
|
||||||
</tr>';
|
|
||||||
}
|
|
||||||
echo '
|
|
||||||
</table>
|
|
||||||
<div style="text-align:center;"><input type="submit" class="button space" name="submitModule'.$nameId.'" value="'.$this->l('Save restrictions').'" /></div>
|
|
||||||
</fieldset>
|
|
||||||
</form>';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
{*
|
||||||
|
* 2007-2011 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. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision$
|
||||||
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*}
|
||||||
|
|
||||||
|
<h2 class="space">{l s='Payment modules list'}</h2>
|
||||||
|
{if isset($url_modules)}
|
||||||
|
<input type="button" class="button" onclick="document.location='{$url_modules}'" value="{l s='Click to see the list of payment modules.'}" /><br>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
{if $display_restrictions}
|
||||||
|
<br /><h2 class="space">{l s='Payment module restrictions'}</h2>
|
||||||
|
{foreach $lists as $list}
|
||||||
|
{include file='payment/restrictions.tpl'}
|
||||||
|
<br />
|
||||||
|
{/foreach}
|
||||||
|
{else}
|
||||||
|
<br />
|
||||||
|
<div class='warn'>{l s='No payment module installed'}</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
{*
|
||||||
|
* 2007-2011 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. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision$
|
||||||
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*}
|
||||||
|
|
||||||
|
<form action="{$url_submit}" method="post" id="form_{$list['name_id']}">
|
||||||
|
<fieldset>
|
||||||
|
<legend><img src="../img/admin/{$list['icon']}.gif" />{$list['title']}</legend>
|
||||||
|
<p>{$list['desc']}<p>
|
||||||
|
<table cellpadding="0" cellspacing="0" class="table">
|
||||||
|
<tr>
|
||||||
|
<th style="width: 200px">{$list['title']}</th>
|
||||||
|
{foreach $payment_modules as $module}
|
||||||
|
{if $module->active}
|
||||||
|
<th>
|
||||||
|
{if $list['name_id'] != 'currency' || $module->currencies_mode == 'checkbox'}
|
||||||
|
<input type="hidden" id="checkedBox_{$list['name_id']}_{$module->name}" value="checked">
|
||||||
|
<a href="javascript:checkPaymentBoxes('{$list['name_id']}', '{$module->name}')" style="text-decoration:none;">
|
||||||
|
{/if}
|
||||||
|
<img src="{$ps_base_uri}modules/{$module->name}/logo.gif" alt="{$module->name}" title="{$module->displayName}" />
|
||||||
|
{if $list['name_id'] != 'currency' || $module->currencies_mode == 'checkbox'}
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
</th>
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
</tr>
|
||||||
|
{foreach $list['items'] as $item}
|
||||||
|
<tr class="{cycle values=",alt_row"}">
|
||||||
|
<td>{$item['name']}</td>
|
||||||
|
{foreach $payment_modules as $key_module => $module}
|
||||||
|
{if $module->active}
|
||||||
|
<td style="text-align: center">
|
||||||
|
{if !$item['check_list'][$key_module]}
|
||||||
|
--
|
||||||
|
{elseif $list['name_id'] === 'currency'}
|
||||||
|
{if $module->currencies && $module->currencies_mode == 'checkbox'}
|
||||||
|
{$type = 'checkbox'}
|
||||||
|
{elseif $module->currencies && $module->currencies_mode == 'radio'}
|
||||||
|
{$type = 'radio'}
|
||||||
|
{/if}
|
||||||
|
{else}
|
||||||
|
{$type = 'checkbox'}
|
||||||
|
{/if}
|
||||||
|
{if isset($type)}
|
||||||
|
<input type="checkbox" name="{$module->name}_{$list['name_id']}[]" value="{$item[$list['identifier']]}"
|
||||||
|
{if $item['check_list'][$key_module] == 'checked'}checked="checked"{/if}
|
||||||
|
/>
|
||||||
|
{else}
|
||||||
|
--
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
</tr>
|
||||||
|
{/foreach}
|
||||||
|
{if $list['name_id'] === 'currency'}
|
||||||
|
<tr class="{cycle values=",alt_row"}">
|
||||||
|
<td>{l s='Customer currency'}</td>
|
||||||
|
{foreach $payment_modules as $module}
|
||||||
|
{if $module->active}
|
||||||
|
<td style="text-align: center">{if $module->currencies && $module->currencies_mode == 'radio'}<input type="radio" name="{$module->name}_{$list['name_id']}[]" value="-1"{if in_array(-1, $module->$list['name_id'])} checked="checked"{/if} />{else}--{/if}</td>
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
</tr>
|
||||||
|
<tr class="{cycle values=",alt_row"}">
|
||||||
|
<td>{l s='Shop default currency'}</td>
|
||||||
|
{foreach $payment_modules as $module}
|
||||||
|
{if $module->active}
|
||||||
|
<td style="text-align: center">{if $module->currencies && $module->currencies_mode == 'radio'}<input type="radio" name="{$module->name}_{$list['name_id']}[]" value="-2"{if in_array(-2, $module->$list['name_id'])} checked="checked"{/if} />{else}--{/if}</td>
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
</tr>
|
||||||
|
{/if}
|
||||||
|
</table>
|
||||||
|
<div style="text-align:center;"><input type="submit" class="button space" name="submitModule{$list['name_id']}" value="{l s='Save restrictions'}" /></div>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Open Software License (OSL 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/osl-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. If you wish to customize PrestaShop for your
|
||||||
|
* needs please refer to http://www.prestashop.com for more information.
|
||||||
|
*
|
||||||
|
* @author PrestaShop SA <contact@prestashop.com>
|
||||||
|
* @copyright 2007-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision: 7307 $
|
||||||
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
class AdminPaymentControllerCore extends AdminController
|
||||||
|
{
|
||||||
|
public $paymentModules = array();
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$shopID = Context::getContext()->shop->getID(true);
|
||||||
|
|
||||||
|
/* Get all modules then select only payment ones*/
|
||||||
|
$modules = Module::getModulesOnDisk();
|
||||||
|
foreach ($modules AS $module)
|
||||||
|
|
||||||
|
if ($module->tab == 'payments_gateways')
|
||||||
|
{
|
||||||
|
if ($module->id)
|
||||||
|
{
|
||||||
|
if(!get_class($module) == 'SimpleXMLElement')
|
||||||
|
$module->country = array();
|
||||||
|
$countries = DB::getInstance()->executeS('SELECT id_country FROM '._DB_PREFIX_.'module_country WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
|
||||||
|
foreach ($countries as $country)
|
||||||
|
$module->country[] = $country['id_country'];
|
||||||
|
|
||||||
|
if(!get_class($module) == 'SimpleXMLElement')
|
||||||
|
$module->currency = array();
|
||||||
|
$currencies = DB::getInstance()->executeS('SELECT id_currency FROM '._DB_PREFIX_.'module_currency WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
|
||||||
|
foreach ($currencies as $currency)
|
||||||
|
$module->currency[] = $currency['id_currency'];
|
||||||
|
|
||||||
|
if(!get_class($module) == 'SimpleXMLElement')
|
||||||
|
$module->group = array();
|
||||||
|
$groups = DB::getInstance()->executeS('SELECT id_group FROM '._DB_PREFIX_.'module_group WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
|
||||||
|
foreach ($groups as $group)
|
||||||
|
$module->group[] = $group['id_group'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$module->country = NULL;
|
||||||
|
$module->currency = NULL;
|
||||||
|
$module->group = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->paymentModules[] = $module;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postProcess()
|
||||||
|
{
|
||||||
|
if (Tools::isSubmit('submitModulecountry'))
|
||||||
|
$this->saveRestrictions('country');
|
||||||
|
elseif (Tools::isSubmit('submitModulecurrency'))
|
||||||
|
$this->saveRestrictions('currency');
|
||||||
|
elseif (Tools::isSubmit('submitModulegroup'))
|
||||||
|
$this->saveRestrictions('group');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function saveRestrictions($type)
|
||||||
|
{
|
||||||
|
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'module_'.$type.' WHERE id_shop = '.Context::getContext()->shop->getID(true));
|
||||||
|
foreach ($this->paymentModules as $module)
|
||||||
|
if ($module->active AND isset($_POST[$module->name.'_'.$type.'']))
|
||||||
|
foreach ($_POST[$module->name.'_'.$type.''] as $selected)
|
||||||
|
$values[] = '('.(int)$module->id.', '.Context::getContext()->shop->getID(true).', '.(int)$selected.')';
|
||||||
|
|
||||||
|
if (sizeof($values))
|
||||||
|
Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'module_'.$type.' (`id_module`, `id_shop`, `id_'.$type.'`) VALUES '.implode(',', $values));
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&conf=4'.'&token='.$this->token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initContent()
|
||||||
|
{
|
||||||
|
// link to modules page
|
||||||
|
if (isset($this->paymentModules[0]))
|
||||||
|
$token_modules = Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)$this->context->employee->id);
|
||||||
|
|
||||||
|
$display_restrictions = false;
|
||||||
|
foreach ($this->paymentModules as $module)
|
||||||
|
if ($module->active)
|
||||||
|
{
|
||||||
|
$display_restrictions= true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lists = array('currencies' =>
|
||||||
|
array('items' => Currency::getCurrencies(),
|
||||||
|
'title' => $this->l('Currencies restrictions'),
|
||||||
|
'desc' => $this->l('Please mark the checkbox(es) for the currency or currencies for which you want the payment module(s) to be available.'),
|
||||||
|
'name_id' => 'currency',
|
||||||
|
'identifier' => 'id_currency',
|
||||||
|
'icon' => 'dollar',
|
||||||
|
),
|
||||||
|
array('items' => Group::getGroups($this->context->language->id),
|
||||||
|
'title' => $this->l('Groups restrictions'),
|
||||||
|
'desc' => $this->l('Please mark the checkbox(es) for the groups for which you want the payment module(s) available.'),
|
||||||
|
'name_id' => 'group',
|
||||||
|
'identifier' => 'id_group',
|
||||||
|
'icon' => 'group',
|
||||||
|
),
|
||||||
|
array('items' =>Country::getCountries($this->context->language->id),
|
||||||
|
'title' => $this->l('Countries restrictions'),
|
||||||
|
'desc' => $this->l('Please mark the checkbox(es) for the country or countries for which you want the payment module(s) to be available.'),
|
||||||
|
'name_id' => 'country',
|
||||||
|
'identifier' => 'id_country',
|
||||||
|
'icon' => 'world',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($lists as $key_list => $list)
|
||||||
|
{
|
||||||
|
$list['check_list'] = array();
|
||||||
|
foreach ($list['items'] as $key_item => $item)
|
||||||
|
{
|
||||||
|
$name_id = $list['name_id'];
|
||||||
|
foreach ($this->paymentModules as $key_module => $module)
|
||||||
|
{
|
||||||
|
if (isset($module->$name_id) && in_array($item['id_'.$name_id], $module->$name_id))
|
||||||
|
$list['items'][$key_item]['check_list'][$key_module] = 'checked';
|
||||||
|
else
|
||||||
|
$list['items'][$key_item]['check_list'][$key_module] = 'unchecked';
|
||||||
|
|
||||||
|
// If is a country list and the country is limited, remove it from list
|
||||||
|
if ($name_id == 'country'
|
||||||
|
&& isset($module->limited_countries)
|
||||||
|
&& !empty($module->limited_countries)
|
||||||
|
&& !(in_array(strtoupper($item['iso_code']), array_map('strtoupper', $module->limited_countries))))
|
||||||
|
$list['check_list'][$key_module] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// update list
|
||||||
|
$lists[$key_list] = $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->context->smarty->assign(array(
|
||||||
|
'url_modules' => isset($token_modules) ? 'index.php?tab=AdminModules&token='.$token_modules.'&module_name='.$this->paymentModules[0]->name.'&tab_module=payments_gateways' : null,
|
||||||
|
'display_restrictions' => $display_restrictions,
|
||||||
|
'lists' => $lists,
|
||||||
|
'ps_base_uri' => __PS_BASE_URI__,
|
||||||
|
'payment_modules' => $this->paymentModules,
|
||||||
|
'url_submit' => self::$currentIndex.'&token='.$this->token,
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user