From c736c28ab566d6a6fd147f1642f87e7ac09f0f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Thu, 29 Aug 2013 11:47:11 +0200 Subject: [PATCH] // small ajax.php clean --- admin-dev/ajax.php | 93 +------------------ .../tax_rules/helpers/form/form.tpl | 8 +- .../default/template/helpers/form/form.tpl | 3 +- .../admin/AdminEmployeesController.php | 10 +- js/admin.js | 9 +- 5 files changed, 23 insertions(+), 100 deletions(-) diff --git a/admin-dev/ajax.php b/admin-dev/ajax.php index 8f41e44cb..332cd394d 100644 --- a/admin-dev/ajax.php +++ b/admin-dev/ajax.php @@ -26,45 +26,12 @@ define('_PS_ADMIN_DIR_', getcwd()); include(_PS_ADMIN_DIR_.'/../config/config.inc.php'); + /* Getting cookie or logout */ require_once(_PS_ADMIN_DIR_.'/init.php'); $context = Context::getContext(); -if (Tools::isSubmit('changeParentUrl')) - echo ''; -if (Tools::isSubmit('installBoughtModule')) -{ - $file = false; - while ($file === false OR file_exists(_PS_MODULE_DIR_.$file)) - $file = uniqid(); - $file = _PS_MODULE_DIR_.$file.'.zip'; - $sourceFile = 'http://addons.prestashop.com/iframe/getboughtfile.php?id_order_detail='.Tools::getValue('id_order_detail').'&token='.Tools::getValue('token'); - if (!copy($sourceFile, $file)) - { - if (!($content = file_get_contents($sourceFile))) - die(displayJavascriptAlert('Access denied: Please download your module directly from PrestaShop Addons website')); - elseif (!file_put_contents($file, $content)) - die(displayJavascriptAlert('Local error: your module directory is not writable')); - } - $first6 = fread($fd = fopen($file, 'r'), 6); - if (!strncmp($first6, 'Error:', 6)) - { - $displayJavascriptAlert = displayJavascriptAlert(fread($fd, 1024)); - fclose($fd); - unlink($file); - die($displayJavascriptAlert); - } - fclose($fd); - if (!Tools::ZipExtract($file, _PS_MODULE_DIR_)) - { - unlink($file); - die(displayJavascriptAlert('Cannot unzip file')); - } - unlink($file); - die(displayJavascriptAlert('Module copied to disk')); -} - if (Tools::isSubmit('ajaxReferrers')) { require(_PS_CONTROLLER_DIR_.'admin/AdminReferrersController.php'); @@ -101,39 +68,6 @@ if (Tools::isSubmit('ajaxProductPackItems')) die('['.implode(',', $jsonArray).']'); } -if (Tools::isSubmit('ajaxStates') AND Tools::isSubmit('id_country')) -{ - $states = Db::getInstance()->executeS(' - SELECT s.id_state, s.name - FROM '._DB_PREFIX_.'state s - LEFT JOIN '._DB_PREFIX_.'country c ON (s.`id_country` = c.`id_country`) - WHERE s.id_country = '.(int)(Tools::getValue('id_country')).' AND s.active = 1 AND c.`contains_states` = 1 - ORDER BY s.`name` ASC'); - - if (is_array($states) AND !empty($states)) - { - $list = ''; - if (Tools::getValue('no_empty') != true) - { - $empty_value = (Tools::isSubmit('empty_value')) ? Tools::getValue('empty_value') : '----------'; - $list = ''."\n"; - } - - foreach ($states AS $state) - $list .= ''."\n"; - } - else - $list = 'false'; - - die($list); -} - -if (Tools::getValue('form_language_id')) -{ - if (!($context->cookie->employee_form_lang = (int)(Tools::getValue('form_language_id')))) - die ('Error while updating cookie.'); - die ('Form language updated.'); -} if (Tools::isSubmit('submitTrackClickOnHelp')) { @@ -144,15 +78,6 @@ if (Tools::isSubmit('submitTrackClickOnHelp')) HelpAccess::trackClick($label, $version); } -if (Tools::isSubmit('toggleScreencast')) -{ - if (Validate::isLoadedObject($context->employee)) - { - $context->employee->bo_show_screencast = !$context->employee->bo_show_screencast; - $context->employee->update(); - } -} - if (Tools::isSubmit('getChildrenCategories') && Tools::isSubmit('id_category_parent')) { $children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), Context::getContext()->language->id, null, Tools::getValue('use_shop_context')); @@ -200,17 +125,6 @@ if (Tools::isSubmit('getParentCategoriesId') && $id_category = Tools::getValue(' die(Tools::jsonEncode($output)); } -/* Update attribute */ -if (Tools::isSubmit('ajaxUpdateTaxRule')) -{ - $id_tax_rule = Tools::getValue('id_tax_rule'); - $tax_rules = new TaxRule((int)$id_tax_rule); - $output = array(); - foreach ($tax_rules as $key => $result) - $output[$key] = $result; - die(Tools::jsonEncode($output)); -} - if (Tools::isSubmit('getZones')) { $zones = Zone::getZones(); @@ -223,8 +137,3 @@ if (Tools::isSubmit('getZones')) $array = array('hasError' => false, 'errors' => '', 'data' => $html); die(Tools::jsonEncode($html)); } - -function displayJavascriptAlert($s) -{ - echo ''; -} diff --git a/admin-dev/themes/default/template/controllers/tax_rules/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/tax_rules/helpers/form/form.tpl index 2d5db9490..fd3c1f170 100644 --- a/admin-dev/themes/default/template/controllers/tax_rules/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/tax_rules/helpers/form/form.tpl @@ -60,9 +60,9 @@ $("#states-label").hide(); } else { $.ajax({ - url: "ajax.php", + url: "index.php", cache: false, - data: "ajaxStates=1&id_country="+id_country+"&id_state="+id_state+"&empty_value={l s='All'}", + data: "ajax=1&tab=AdminTaxRulesGroup&token={getAdminToken tab='AdminTaxRulesGroup'}&action=states&id_country="+id_country+"&id_state="+id_state+"&empty_value={l s='All'}", success: function(html){ if (html == "false") { @@ -88,10 +88,10 @@ { $.ajax({ type: 'POST', - url: 'ajax.php', + url: 'index.php', async: true, dataType: 'json', - data: 'ajaxStates=1&ajaxUpdateTaxRule=1&id_tax_rule='+id_tax_rule, + data: 'ajax=1&tab=AdminTaxRulesGroup&token={getAdminToken tab='AdminTaxRulesGroup'}&ajaxStates=1&action=updateTaxRule&id_tax_rule='+id_tax_rule, success: function(data){ $('#tax_rule_form').show(); $('#id_tax_rule').val(data.id); diff --git a/admin-dev/themes/default/template/helpers/form/form.tpl b/admin-dev/themes/default/template/helpers/form/form.tpl index 694486e03..84424ff6f 100644 --- a/admin-dev/themes/default/template/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/helpers/form/form.tpl @@ -432,7 +432,8 @@ }; {/foreach} // we need allowEmployeeFormLang var in ajax request - allowEmployeeFormLang = {$allowEmployeeFormLang}; + allowEmployeeFormLang = {$allowEmployeeFormLang|intval}; + employee_token = '{getAdminToken tab='AdminEmployees'}'; displayFlags(languages, id_language, allowEmployeeFormLang); $(document).ready(function() { diff --git a/controllers/admin/AdminEmployeesController.php b/controllers/admin/AdminEmployeesController.php index 3d69d1a84..945a95ba0 100644 --- a/controllers/admin/AdminEmployeesController.php +++ b/controllers/admin/AdminEmployeesController.php @@ -472,7 +472,15 @@ class AdminEmployeesControllerCore extends AdminController return $res; } - + + protected function ajaxProcessFormLanguage() + { + $this->context->cookie->employee_form_lang = (int)Tools::getValue('form_language_id'); + if (!$this->context->cookie->write()) + die ('Error while updating cookie.'); + die ('Form language updated.'); + } + public function ajaxProcessGetTabByIdProfile() { $id_profile = Tools::getValue('id_profile'); diff --git a/js/admin.js b/js/admin.js index 4e0ffadfd..7904d724b 100644 --- a/js/admin.js +++ b/js/admin.js @@ -183,10 +183,15 @@ function changeFormLanguage(id_language_new, iso_code, employee_cookie) // For multishop checkboxes $('.multishop_lang_'+id_language_new).show().siblings('div[class^=\'multishop_lang_\']').hide(); - $('.language_flags').hide(); if (employee_cookie) - $.post("ajax.php", { form_language_id: id_language_new }); + $.post("index.php", { + action: 'formLanguage', + tab: 'AdminEmployees', + ajax: 1, + token: employee_token, + form_language_id: id_language_new + }); id_language = id_language_new; updateCurrentText();