// small ajax.php clean

This commit is contained in:
Rémi Gaillard
2013-08-29 11:47:11 +02:00
parent 6d1c8c54af
commit c736c28ab5
5 changed files with 23 additions and 100 deletions

View File

@@ -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 '<script type="text/javascript">parent.parent.document.location.href = "'.addslashes(urldecode(Tools::getValue('changeParentUrl'))).'";</script>';
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 = '<option value="0">'.Tools::htmlentitiesUTF8($empty_value).'</option>'."\n";
}
foreach ($states AS $state)
$list .= '<option value="'.(int)($state['id_state']).'"'.((isset($_GET['id_state']) AND $_GET['id_state'] == $state['id_state']) ? ' selected="selected"' : '').'>'.$state['name'].'</option>'."\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 '<script type="text/javascript">alert(\''.addslashes($s).'\');</script>';
}

View File

@@ -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);

View File

@@ -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() {

View File

@@ -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');

View File

@@ -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();