* @copyright PrestaShop
* @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
* @version 1.3
*
*/
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminCurrencies extends AdminTab
{
public function __construct()
{
$this->table = 'currency';
$this->className = 'Currency';
$this->lang = false;
$this->edit = true;
$this->delete = true;
$this->fieldsDisplay = array(
'id_currency' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Currency'), 'width' => 100),
'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'width' => 35),
'sign' => array('title' => $this->l('Symbol'), 'width' => 20, 'align' => 'center', 'orderby' => false, 'search' => false),
'conversion_rate' => array('title' => $this->l('Conversion rate'), 'float' => true, 'align' => 'center', 'width' => 50, 'search' => false));
$this->optionTitle = $this->l('Currencies options');
$this->_fieldsOptions = array(
'PS_CURRENCY_DEFAULT' => array('title' => $this->l('Default currency:'), 'desc' => $this->l('The default currency used in shop'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_currency', 'list' => Currency::getCurrencies()),
);
$this->_where = 'AND a.`deleted` = 0';
parent::__construct();
}
public function postProcess()
{
global $currentIndex;
if (isset($_GET['delete'.$this->table]))
{
if ($this->tabAccess['delete'] === '1')
{
if (Validate::isLoadedObject($object = $this->loadObject()))
{
if ($object->id == Configuration::get('PS_CURRENCY_DEFAULT'))
$this->_errors[] = $this->l('You can\'t delete the default currency');
elseif ($object->delete())
Tools::redirectAdmin($currentIndex.'&conf=1'.'&token='.$this->token);
else
$this->_errors[] = Tools::displayError('an error occurred during deletion');
}
else
$this->_errors[] = Tools::displayError('an error occurred while deleting object').' '.$this->table.' '.Tools::displayError('(cannot load object)');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
elseif (Tools::getValue('submitOptions'.$this->table))
{
foreach ($this->_fieldsOptions as $key => $field)
{
Configuration::updateValue($key, $field['cast'](Tools::getValue($key)));
if ($key == 'PS_CURRENCY_DEFAULT')
{
$currency = new Currency($field['cast'](Tools::getValue($key)));
$currency->conversion_rate = 1;
$currency->update();
}
}
Tools::redirectAdmin($currentIndex.'&conf=6'.'&token='.$this->token);
}
elseif (Tools::isSubmit('submitExchangesRates'))
{
if (!$this->_errors[] = Currency::refreshCurrencies())
Tools::redirectAdmin($currentIndex.'&conf=6'.'&token='.$this->token);
}
else
parent::postProcess();
}
public function displayOptionsList()
{
global $currentIndex;
parent::displayOptionsList();
echo '