* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7739 $ * @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() { /* 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)); 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)); 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)); 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) { global $currentIndex; Db::getInstance()->Execute('TRUNCATE '._DB_PREFIX_.'module_'.$type.''); 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).', '.(int)($selected).')'; if (sizeof($values)) Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'module_'.$type.' (`id_module`, `id_'.$type.'`) VALUES '.implode(',', $values)); Tools::redirectAdmin($currentIndex.'&conf=4'.'&token='.$this->token); } public function display() { global $cookie; $displayRestrictions = false; $currencies = Currency::getCurrencies(); $countries = Country::getCountries((int)($cookie->id_lang)); $groups = Group::getGroups((int)($cookie->id_lang)); $tokenModules = Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)); echo '

'.$this->l('Payment modules list').'

'; if (isset($this->paymentModules[0])) echo '
'; foreach ($this->paymentModules as $module) if ($module->active) $displayRestrictions= true; if ($displayRestrictions) { echo '

'.$this->l('Payment module restrictions').'

'; $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 '
'; $this->displayModuleRestrictions($groups, $this->l('Groups restrictions'), 'group', $textGroups, 'group'); echo '
'; $this->displayModuleRestrictions($countries, $this->l('Countries restrictions'), 'country', $textCountries, 'world'); } else { echo '
'; echo $this->displayWarning($this->l('No payment module installed')); } } public function displayModuleRestrictions($items, $title, $nameId, $desc, $icon) { global $currentIndex; $irow = 0; echo '
'.$title.'

'.$desc.'

'; foreach ($this->paymentModules as $module) { if ($module->active) { echo ' '; } } echo ' '; foreach ($items as $item) { echo ' '; foreach ($this->paymentModules as $module) { if ($module->active) { if (isset($module->{$nameId})) $value = $module->{$nameId}; else $value = array(); echo ' '; } } echo ' '; } if ($nameId == 'currency') { echo ' '; foreach ($this->paymentModules as $module) if ($module->active) echo ' '; echo ' '; echo ' '; foreach ($this->paymentModules as $module) if ($module->active) echo ' '; echo ' '; } echo '
'.$title.''; if ($nameId != 'currency' OR ($nameId == 'currency' AND $module->currencies_mode == 'checkbox')) echo ' '; echo '  '.$module->name.''; if ($nameId != 'currency' OR ($nameId == 'currency' AND $module->currencies_mode == 'checkbox')) echo ' '; echo '
'.$item['name'].''; 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 ''; else echo '--'; } elseif ($nameId != 'currency' OR ($nameId == 'currency' AND $module->currencies AND $module->currencies_mode == 'checkbox')) echo ' '; elseif ($nameId == 'currency' AND $module->currencies AND $module->currencies_mode == 'radio') echo ' '; elseif ($nameId == 'currency') echo '--'; echo '
'.$this->l('Customer currency').''.(($module->currencies AND $module->currencies_mode == 'radio') ? '{$nameId}) ? ' checked="checked"' : '').' />' : '--').'
'.$this->l('Shop default currency').''.(($module->currencies AND $module->currencies_mode == 'radio') ? '{$nameId}) ? ' checked="checked"' : '').' />' : '--').'

'; } }