I have a lot of ajax functions in my php application like this :
$.post('index.php?controller=suivi&action=ajax_intervention_save', {
id: root.find('#id').val(),
begin: begin,
end: end,
}, function(res) {
//if is not an ID
if (res && isNaN(res)) {
error();
SUIVI.showButton();
} else {
displaySuccess("Fiche saved");
}
});
And i want to block the access at my application when i have a maintenance_mode == 1. So i add this condition :
$.post('index.php?controller=suivi&action=ajax_intervention_save', {
id: root.find('#id').val(),
begin: begin,
end: end,
}, function(res) {
if(res === 'MAINTENANCE'){
error(res);
return;
}
//if is not an ID
if (res && isNaN(res)) {
error();
SUIVI.showButton();
} else {
displaySuccess("Fiche saved");
}
});
My problem that I have a lot of functions like this in others files. How can I do to not copy the code res === 'MAINTENANCE' in all functions? I want a way that tells can display 'maintenance mode message for all ajax functions when mode == 1
This is my index.php redirection :
if(\app\models\Config::getValue('maintenance_mode')){
if (Tools::isAjax())
die('MAINTENANCE');
elseif(!isset($_GET['action']) || $_GET['action'] !== 'maintenance'){
header('Location:index.php?module=general&action=maintenance');
}
}
Thanks