From de59e7b432db626bf4a4d6c96f0e1c75a20a6a38 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Wed, 19 Oct 2011 09:29:49 +0000 Subject: [PATCH] [*] BO : #PSFV-94 - added AdminCurrencuesController git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9442 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/tabs/AdminCurrencies.php | 247 --------------- admin-dev/themes/template/form.tpl | 5 + admin-dev/themes/template/options.tpl | 245 ++++++++------- classes/Helper.php | 103 ++++++ classes/HelperForm.php | 3 +- classes/HelperOptions.php | 33 +- .../admin/AdminCurrenciesController.php | 293 ++++++++++++++++++ controllers/admin/AdminImagesController.php | 1 + 8 files changed, 553 insertions(+), 377 deletions(-) delete mode 100644 admin-dev/tabs/AdminCurrencies.php create mode 100644 controllers/admin/AdminCurrenciesController.php diff --git a/admin-dev/tabs/AdminCurrencies.php b/admin-dev/tabs/AdminCurrencies.php deleted file mode 100644 index 3ffec7c49..000000000 --- a/admin-dev/tabs/AdminCurrencies.php +++ /dev/null @@ -1,247 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7300 $ -* @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->_where = 'AND a.`deleted` = 0'; - - $this->optionsList = array( - 'general' => array( - 'title' => $this->l('Currencies options'), - 'fields' => 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() - ), - ), - ), - ); - - parent::__construct(); - } - - public function postProcess() - { - 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(self::$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(self::$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::isSubmit('submitExchangesRates')) - { - if (!$this->_errors[] = Currency::refreshCurrencies()) - Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token); - } - else - parent::postProcess(); - } - - public function updateOptionPsCurrencyDefault($value) - { - Configuration::updateValue('PS_CURRENCY_DEFAULT', $value); - Currency::refreshCurrencies(); - } - - public function displayOptionsList() - { - parent::displayOptionsList(); - - $dir = explode(DIRECTORY_SEPARATOR, dirname(__FILE__)); - for ($i = 0; $i < 2; ++$i) - $adminDir = array_pop($dir); - - echo '

-
-
- '.$this->l('Currency rates').' - -
-

'.$this->l('Update your currencies exchanges rates with a real-time tool').'

-
-
- -
-
-
'; - echo '

-
- '.$this->l('Currency rates update').' -

'.$this->l('Place this URL in crontab or call it manually daily').':
- '.Tools::getShopDomain(true, true). __PS_BASE_URI__.$adminDir.'/cron_currency_rates.php?secure_key='.md5(_COOKIE_KEY_.Configuration::get('PS_SHOP_NAME')).'

-
'; - } - - public function displayForm($isMainTab = true) - { - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - - echo ' -
- '.($obj->id ? '' : '').' -
'.$this->l('Currencies').' - -
- * - '.$this->l('Only letters and the minus character are allowed').'  -

'.$this->l('Will appear on Front Office, e.g., euro, dollar').'...

-
- -
- * -   -

'.$this->l('ISO code, e.g., USD for dollar, EUR for euro').'...

-
- -
- * -   -

'.$this->l('Numeric ISO code, e.g., 840 for dollar, 978 for euro').'...

-
- -
- * -

'.$this->l('Will appear on Front Office, e.g., €, $').'...

-
- -
- * -

'.$this->l('Conversion rate from one unit of your shop\'s default currency (for example, 1€) to this currency. For example, if the default currency is euros and this currency is dollars, type \'1.20\'').' 1€ = $1.20

-
- -
- -

'.$this->l('Applies to all prices, e.g.,').' $1,240.15

-
- -
- getFieldValue($obj, 'decimals') ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'decimals') ? 'checked="checked" ' : '').'/> - -

'.$this->l('Display decimals on prices').'

-
- -
- getFieldValue($obj, 'blank') ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'blank') ? 'checked="checked" ' : '').'/> - -

'.$this->l('Include a blank between sign and price, e.g.,').'
$1,240.15 -> $ 1,240.15

-
- -
- getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> - - getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> - -
'; - if (Shop::isMultiShopActivated()) - { - echo '
'; - $this->displayAssoShop(); - echo '
'; - } - echo ' -
- -
-
* '.$this->l('Required field').'
-
-
'; - } -} - diff --git a/admin-dev/themes/template/form.tpl b/admin-dev/themes/template/form.tpl index 2148b4416..d8a5da918 100644 --- a/admin-dev/themes/template/form.tpl +++ b/admin-dev/themes/template/form.tpl @@ -204,6 +204,11 @@ {elseif $input.type == 'file'} + {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop} + +
+ {$asso_shop} +
{/if} {if isset($input.required) && $input.required} *{/if} {if isset($input.p)} diff --git a/admin-dev/themes/template/options.tpl b/admin-dev/themes/template/options.tpl index d504a666c..2d0f88d7e 100644 --- a/admin-dev/themes/template/options.tpl +++ b/admin-dev/themes/template/options.tpl @@ -25,130 +25,139 @@ *}
-{foreach $optionsList AS $category => $categoryData} - {if isset($categoryData['top'])}{$categoryData['top']}{/if} -
- {* Options category title *} - - - {if isset($categoryData['title'])}{$categoryData['title']}{else}{l s='Options'}{/if} - - - {* Category description *} - {if (isset($categoryData['description']) && $categoryData['description'])} -

{$categoryData['description']}

- {/if} - - {foreach $categoryData['fields'] AS $key => $field} -
- {if $field['title']} - + {foreach $option_list AS $category => $categoryData} + {if isset($categoryData['top'])}{$categoryData['top']}{/if} +
+ {* Options category title *} + + + {if isset($categoryData['title'])}{$categoryData['title']}{else}{l s='Options'}{/if} + + + {* Category description *} + {if (isset($categoryData['description']) && $categoryData['description'])} +

{$categoryData['description']}

{/if} -
- - {if $field['type'] == 'select'} - + {foreach $field['list'] AS $k => $option} + + {/foreach} + + {elseif $field['type'] == 'bool'} + + + + + + + {elseif $field['type'] == 'radio'} + {foreach $field['choices'] AS $k => $v} + +
{/foreach} - - {elseif $field['type'] == 'bool'} - - - - - - - {elseif $field['type'] == 'radio'} - {foreach $field['choices'] AS $k => $v} - -
- {/foreach} -
- {*{elseif $field['type'] == 'checkbox'} - {foreach $field['choices'] AS $k => $v} - -
- {/foreach} -
+
+ {*{elseif $field['type'] == 'checkbox'} + {foreach $field['choices'] AS $k => $v} + +
+ {/foreach} +
+ *} + {elseif $field['type'] == 'text'} + + {if isset($field['next'])} {$field['next']|strval}{/if} + {elseif $field['type'] == 'password'} + + {if isset($field['next'])} {$field['next']|strval}{/if} + {elseif $field['type'] == 'textarea'} + + {elseif $field['type'] == 'file'} + {if isset($field['thumb']) && $field['thumb'] && $field['thumb']['pos'] == 'before'} + {$field['title']}
+ {/if} + + {* {elseif $field['type'] == 'image'} + + + $i = 0; + foreach ($field['list'] as $theme) + { + '; + if (isset($field['max']) && ($i +1 ) % $field['max'] == 0) + echo ''; + $i++; + } + echo ''; + echo '
+ '; + echo ''; + echo '
'; + echo ''; + echo '
'; *} - {elseif $field['type'] == 'text'} - - {if isset($field['next'])} {$field['next']|strval}{/if} - {elseif $field['type'] == 'password'} - - {if isset($field['next'])} {$field['next']|strval}{/if} - {elseif $field['type'] == 'textarea'} - - {elseif $field['type'] == 'file'} - {if isset($field['thumb']) && $field['thumb'] && $field['thumb']['pos'] == 'before'} - {$field['title']}
+ {elseif $field['type'] == 'textLang'} + {foreach $field['languages'] AS $id_lang => $value} +
+ +
+ {/foreach} + {$field['flags']} + {elseif $field['type'] == 'textareaLang'} + {foreach $field['languages'] AS $id_lang => $value} +
+ +
+ {/foreach} + {$field['flags']} +
+ + {/if} - - {* {elseif $field['type'] == 'image'} - - - $i = 0; - foreach ($field['list'] as $theme) - { - '; - if (isset($field['max']) && ($i +1 ) % $field['max'] == 0) - echo ''; - $i++; - } - echo ''; - echo '
- '; - echo ''; - echo '
'; - echo ''; - echo '
'; - *} - {elseif $field['type'] == 'textLang'} - {foreach $field['languages'] AS $id_lang => $value} -
- + {if isset($field['method'])}$field['method']{/if} + + {if ($field['multishop_default'])} +
+
- {/foreach} - {$field['flags']} - {elseif $field['type'] == 'textareaLang'} - {foreach $field['languages'] AS $id_lang => $value} -
- -
- {/foreach} - {$field['flags']} -
- - - {/if} - {if isset($field['method'])}$field['method']{/if} - - {if ($field['multishop_default'])} -
- + {/if} + {if isset($field['desc'])}

{$field['desc']}

{/if} + {if $field['is_invisible']}

{l s='You can\'t change the value of this configuration field in this shop context'}

{/if} +
+ {/foreach} + {if isset($categoryData['submit'])} +
+
{/if} - {if isset($field['desc'])}

{$field['desc']}

{/if} - {if $field['is_invisible']}

{l s='You can\'t change the value of this configuration field in this shop context'}

{/if} -
+ {if $field['required']} +
* {l s='Required field'}
+ {/if} +

+ {if isset($categoryData['bottom'])}{$categoryData['bottom']}{/if} {/foreach} - -
- -
- {if $field['required']} -
* {l s='Required field'}
- {/if} -
- {if isset($categoryData['bottom'])}{$categoryData['bottom']}{/if} -{/foreach}
diff --git a/classes/Helper.php b/classes/Helper.php index 2a60fbbb1..00571ddb1 100755 --- a/classes/Helper.php +++ b/classes/Helper.php @@ -267,5 +267,108 @@ class HelperCore echo $output; } + protected function displayAssoShop($type = 'shop') + { + if (!Shop::isMultiShopActivated() || (!$this->id && $this->context->shop->getContextType() != Shop::CONTEXT_ALL)) + return; + + if ($type != 'shop' && $type != 'group_shop') + $type = 'shop'; + + $assos = array(); + $sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'` + FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`'; + foreach (Db::getInstance()->executeS($sql) as $row) + $assos[$row['id_'.$type]][] = $row[$this->identifier]; + + $html = << + $().ready(function() + { + // Click on "all shop" + $('.input_all_shop').click(function() + { + var checked = $(this).attr('checked'); + $('.input_group_shop').attr('checked', checked); + $('.input_shop').attr('checked', checked); + }); + + // Click on a group shop + $('.input_group_shop').click(function() + { + $('.input_shop[value='+$(this).val()+']').attr('checked', $(this).attr('checked')); + check_all_shop(); + }); + + // Click on a shop + $('.input_shop').click(function() + { + check_group_shop_status($(this).val()); + check_all_shop(); + }); + + // Initialize checkbox + $('.input_shop').each(function(k, v) + { + check_group_shop_status($(v).val()); + check_all_shop(); + }); + }); + + function check_group_shop_status(id_group) + { + var groupChecked = true; + $('.input_shop[value='+id_group+']').each(function(k, v) + { + if (!$(v).attr('checked')) + groupChecked = false; + }); + $('.input_group_shop[value='+id_group+']').attr('checked', groupChecked); + } + + function check_all_shop() + { + var allChecked = true; + $('.input_group_shop').each(function(k, v) + { + if (!$(v).attr('checked')) + allChecked = false; + }); + $('.input_all_shop').attr('checked', allChecked); + } + +EOF; + + $html .= '
'; + $html .= ' + '; + $html .= ''; + foreach (Shop::getTree() as $groupID => $groupData) + { + $groupChecked = ($type == 'group_shop' && ((isset($assos[$groupID]) && in_array($this->id, $assos[$groupID])) || !$this->id)); + $html .= ''; + $html .= ''; + $html .= ''; + + if ($type == 'shop') + { + $total = count($groupData['shops']); + $j = 0; + foreach ($groupData['shops'] as $shopID => $shopData) + { + $checked = ((isset($assos[$shopID]) && in_array($this->id, $assos[$shopID])) || !$this->id); + $html .= ''; + $html .= ''; + $html .= ''; + $j++; + } + } + } + $html .= '
'.$this->l('Shop').'
'; + return $html; + } + } diff --git a/classes/HelperForm.php b/classes/HelperForm.php index 9e601d7c9..ee9f4983a 100644 --- a/classes/HelperForm.php +++ b/classes/HelperForm.php @@ -75,7 +75,8 @@ class HelperFormCore extends Helper 'requiredFields' => $this->getFieldsRequired(), 'vat_number' => file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php'), 'module_dir' => _MODULE_DIR_, - 'contains_states' => (isset($this->fields_value['id_country']) && isset($this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null + 'contains_states' => (isset($this->fields_value['id_country']) && isset($this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null, + 'asso_shop' => (isset($this->fields_form['asso_shop']) && $this->fields_form['asso_shop']) ? $this->displayAssoShop() : null, )); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl); diff --git a/classes/HelperOptions.php b/classes/HelperOptions.php index 4d25f749f..26c5e999e 100644 --- a/classes/HelperOptions.php +++ b/classes/HelperOptions.php @@ -54,10 +54,16 @@ class HelperOptionsCore extends Helper $tab = Tab::getTab($this->context->language->id, $this->id); foreach ($option_list as $category => $category_data) { + if (!isset($category_data['image'])) + $category_data['image'] = (!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif'; + + if (!isset($category_data['fields'])) + $category_data['fields'] = array(); + foreach ($category_data['fields'] as $key => $field) { - // Field value - $option_list[$category]['fields'][$key]['value'] = $this->getOptionValue($key, $field); + // Set field value + $field['value'] = $this->getOptionValue($key, $field); // Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop) $isDisabled = $isInvisible = false; @@ -71,15 +77,15 @@ class HelperOptionsCore extends Helper else if (Context::shop() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key)) $isDisabled = true; } - $option_list[$category]['fields'][$key]['is_disabled'] = $isDisabled; - $option_list[$category]['fields'][$key]['is_invisible'] = $isInvisible; + $field['is_disabled'] = $isDisabled; + $field['is_invisible'] = $isInvisible; - $option_list[$category]['fields'][$key]['required'] = isset($field['required']) ? $field['required'] : $this->required; + $field['required'] = isset($field['required']) ? $field['required'] : $this->required; // Cast options values if specified if ($field['type'] == 'select' && isset($field['cast'])) foreach ($field['list'] as $option_key => $option) - $option_list[$category]['fields'][$key]['list'][$option_key][$field['identifier']] = $field['cast']($option[$field['identifier']]); + $field['list'][$option_key][$field['identifier']] = $field['cast']($option[$field['identifier']]); // Fill values for all languages for all lang fields if (substr($field['type'], -4) == 'Lang') @@ -93,19 +99,24 @@ class HelperOptionsCore extends Helper $value = Tools::safeOutput(Tools::getValue($key.'_'.$language['id_lang'], Configuration::get($key, $language['id_lang']))); elseif ($field['type'] == 'textareaLang') $value = Configuration::get($key, $language['id_lang']); - $option_list[$category]['fields'][$key]['languages'][$language['id_lang']] = $value; + $field['languages'][$language['id_lang']] = $value; } - $option_list[$category]['fields'][$key]['flags'] = $this->displayFlags($languages, $this->context->language->id, $key, $key, true); + $field['flags'] = $this->displayFlags($languages, $this->context->language->id, $key, $key, true); } // Multishop default value - $option_list[$category]['fields'][$key]['multishop_default'] = (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible); + $field['multishop_default'] = (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible); + + // Assign the modifications back to parent array + $category_data['fields'][$key] = $field; } + // Assign the modifications back to parent array + $option_list[$category] = $category_data; } + $this->context->smarty->assign(array( - 'img_legend' => (!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif', 'current' => $this->currentIndex, - 'optionsList' => $option_list, + 'option_list' => $option_list, 'current_id_lang' => $this->context->language->id, )); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl); diff --git a/controllers/admin/AdminCurrenciesController.php b/controllers/admin/AdminCurrenciesController.php new file mode 100644 index 000000000..ca19b1125 --- /dev/null +++ b/controllers/admin/AdminCurrenciesController.php @@ -0,0 +1,293 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 7300 $ +* @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 AdminCurrenciesControllerCore extends AdminController +{ + public function __construct() + { + $this->table = 'currency'; + $this->className = 'Currency'; + $this->lang = false; + $this->addRowAction('edit'); + $this->addRowAction('delete'); + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + $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->_where = 'AND a.`deleted` = 0'; + + $this->options = array( + 'general' => array( + 'title' => $this->l('Currencies options'), + 'fields' => 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() + ), + ), + ), + 'change' => array( + 'title' => $this->l('Currency rates'), + 'image' => '../img/admin/exchangesrate.gif', + 'description' => $this->l('Update your currencies exchanges rates with a real-time tool'), + 'submit' => array( + 'title' => $this->l('Update currency rates'), + 'class' => 'button', + 'name' => 'SubmitExchangesRates' + ), + ), + 'cron' => array( + 'title' => $this->l('Currency rates update'), + 'image' => '../img/admin/tab-tools.gif', + 'info' => $this->l('Place this URL in crontab or call it manually daily').':
+ '.Tools::getShopDomain(true, true). __PS_BASE_URI__.basename(_PS_ADMIN_DIR_).'/cron_currency_rates.php?secure_key='.md5(_COOKIE_KEY_.Configuration::get('PS_SHOP_NAME')).'

', + ), + ); + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Currencies:'), + 'image' => '../img/admin/money.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Currency:'), + 'name' => 'name', + 'size' => 30, + 'maxlength' => 32, + 'required' => true, + 'hint' => $this->l('Only letters and the minus character are allowed'), + 'p' => $this->l('Will appear on Front Office, e.g., euro, dollar').'...', + ), + array( + 'type' => 'text', + 'label' => $this->l('ISO code:'), + 'name' => 'iso_code', + 'size' => 30, + 'maxlength' => 32, + 'required' => true, + 'p' => $this->l('ISO code, e.g., USD for dollar, EUR for euro').'...', + ), + array( + 'type' => 'text', + 'label' => $this->l('Numeric ISO code:'), + 'name' => 'iso_code_num', + 'size' => 30, + 'maxlength' => 32, + 'required' => true, + 'p' => $this->l('Numeric ISO code, e.g., 840 for dollar, 978 for euro').'...', + ), + array( + 'type' => 'text', + 'label' => $this->l('Symbol:'), + 'name' => 'sign', + 'size' => 3, + 'maxlength' => 8, + 'required' => true, + 'p' => $this->l('Will appear on Front Office, e.g., €, $').'...', + ), + array( + 'type' => 'text', + 'label' => $this->l('Conversion rate:'), + 'name' => 'conversion_rate', + 'size' => 3, + 'maxlength' => 11, + 'required' => true, + 'p' => $this->l('Conversion rate from one unit of your shop\'s default currency (for example, 1€) to this currency. For example, if the default currency is euros and this currency is dollars, type \'1.20\'').' 1€ = $1.20', + ), + array( + 'type' => 'select', + 'label' => $this->l('Formatting:'), + 'name' => 'format', + 'size' => 3, + 'maxlength' => 11, + 'required' => true, + 'p' =>$this->l('Applies to all prices, e.g.,').' $1,240.15', + 'options' => array( + 'query' => array( + array('key' => 1, 'name' => 'X0,000.00 ('.$this->l('as with dollars').')'), + array('key' => 2, 'name' => '0 000,00X ('.$this->l('as with euros').')'), + array('key' => 3, 'name' => 'X0.000,00'), + array('key' => 4, 'name' => '0,000.00X'), + ), + 'name' => 'name', + 'id' => 'key' + ) + ), + array( + 'type' => 'radio', + 'label' => $this->l('Decimals:'), + 'name' => 'decimals', + 'required' => false, + 'class' => 't', + 'is_bool' => true, + 'p' => $this->l('Display decimals on prices'), + 'values' => array( + array( + 'id' => 'decimals_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'decimals_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'radio', + 'label' => $this->l('Blank:'), + 'name' => 'blank', + 'required' => false, + 'class' => 't', + 'is_bool' => true, + 'p' => $this->l('Include a blank between sign and price, e.g.,').'
$1,240.15 -> $ 1,240.15', + 'values' => array( + array( + 'id' => 'blank_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'blank_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'radio', + 'label' => $this->l('Enable:'), + 'name' => 'active', + 'required' => false, + 'class' => 't', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'asso_shop', + 'name' => '' + ) + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ), + 'asso_shop' => Shop::isMultiShopActivated() + ); + parent::__construct(); + } + + public function postProcess() + { + if ($this->action == 'delete') + { + 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(self::$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)'); + } + elseif ($this->action == 'status') + { + 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(self::$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)'); + } + elseif (Tools::isSubmit('submitExchangesRates')) + { + if (!$this->_errors[] = Currency::refreshCurrencies()) + Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token); + } + else + parent::postProcess(); + } + + public function updateOptionPsCurrencyDefault($value) + { + Configuration::updateValue('PS_CURRENCY_DEFAULT', $value); + Currency::refreshCurrencies(); + } + + public function initContent() + { + if ($this->display != 'edit' && $this->display != 'add') + $this->display = 'list'; + + parent::initContent(); + + if ($this->display = 'list') + { + $helper = new HelperOptions(); + $helper->id = $this->id; + $helper->currentIndex = self::$currentIndex; + $this->content .= $helper->generateOptions($this->options); + } + } +} + diff --git a/controllers/admin/AdminImagesController.php b/controllers/admin/AdminImagesController.php index 4d46f3908..0d44adf12 100644 --- a/controllers/admin/AdminImagesController.php +++ b/controllers/admin/AdminImagesController.php @@ -60,6 +60,7 @@ class AdminImagesController extends AdminController 'PS_JPEG_QUALITY' => array('title' => $this->l('JPEG quality'), 'desc' => $this->l('Ranges from 0 (worst quality, smallest file) to 100 (best quality, biggest file)'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), 'PS_PNG_QUALITY' => array('title' => $this->l('PNG quality'), 'desc' => $this->l('Ranges from 9 (worst quality, smallest file) to 0 (best quality, biggest file)'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), ), + 'submit' => array(), ) );