* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6594 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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),
'iso_code_num' => array('title' => $this->l('ISO code num'), '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),
'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => 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')
.'
'.$this->l('If you change default currency, you will have to manually edit every product price.').'
',
'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 ((isset($_GET['status'.$this->table]) OR isset($_GET['status'])) AND Tools::getValue($this->identifier))
{
if ($this->tabAccess['edit'] === '1')
{
if (Validate::isLoadedObject($object = $this->loadObject()))
{
if ($object->active AND $object->id == Configuration::get('PS_CURRENCY_DEFAULT'))
$this->_errors[] = $this->l('You can\'t disable the default currency');
elseif ($object->toggleStatus())
Tools::redirectAdmin($currentIndex.'&conf=5'.((($id_category = (int)(Tools::getValue('id_category'))) AND Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$this->token);
else
$this->_errors[] = Tools::displayError('An error occurred while updating status.');
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' '.$this->table.' '.Tools::displayError('(cannot load object)');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit 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::refreshCurrencies();
}
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 '
';
}
public function displayForm($isMainTab = true)
{
global $currentIndex;
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
echo '
';
}
}