Fix synchronize rates for multicurrency module
This commit is contained in:
parent
a6fa3a4c25
commit
a33472942d
@ -119,6 +119,21 @@ elseif ($action == 'update_currency')
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($action == 'synchronize')
|
||||
{
|
||||
$response = GETPOST('response');
|
||||
$response = json_decode($response);
|
||||
|
||||
if ($response->success)
|
||||
{
|
||||
MultiCurrency::syncRates($response);
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($langs->trans('multicurrency_syncronize_error', $reponse->error->info), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$TCurrency = array();
|
||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE entity = '.$conf->entity;
|
||||
@ -139,9 +154,7 @@ if ($resql)
|
||||
*/
|
||||
|
||||
$page_name = "MultiCurrency";
|
||||
$morejs = array('/multicurrency/js/currencylayer.js.php');
|
||||
|
||||
llxHeader('', $langs->trans($page_name), '', '', '', '', $morejs);
|
||||
llxHeader('', $langs->trans($page_name));
|
||||
|
||||
// Subheader
|
||||
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">'
|
||||
@ -228,7 +241,14 @@ print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("CurrencyLayerAccount").'</td>'."\n";
|
||||
print '<td align="center" width="20"> </td>';
|
||||
print '<td align="right" width="100">'.$langs->trans("Value").' <input type="button" id="bt_sync" class="button" onclick="javascript:syncronize_rates();" value="'.$langs->trans('Synchronize').'" /></td>'."\n";
|
||||
print '<td align="right" width="100">';
|
||||
print '<form id="form_sync" action="" method="POST">';
|
||||
print '<input type="hidden" name="action" value="synchronize" />';
|
||||
print '<textarea id="response" class="hideobject" name="response"></textarea>';
|
||||
print $langs->trans("Value").' <input type="button" id="bt_sync" class="button" onclick="javascript:getRates();" value="'.$langs->trans('Synchronize').'" />';
|
||||
print '</form>';
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
@ -311,6 +331,26 @@ foreach ($TCurrency as &$currency)
|
||||
|
||||
print '</table>';
|
||||
|
||||
|
||||
|
||||
print '
|
||||
<script type="text/javascript">
|
||||
function getRates()
|
||||
{
|
||||
$("#bt_sync").attr("disabled", true);
|
||||
var url_sync = "http://apilayer.net/api/live?access_key='.$conf->global->MULTICURRENCY_APP_ID.'&format=1'.(!empty($conf->global->MULTICURRENCY_APP_SOURCE) ? '&source='.$conf->global->MULTICURRENCY_APP_SOURCE : '').'";
|
||||
|
||||
$.ajax({
|
||||
url: url_sync,
|
||||
dataType: "jsonp"
|
||||
}).done(function(response) {
|
||||
$("#response").val(JSON.stringify(response));
|
||||
$("#form_sync").submit();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
';
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/* <one line to give the program's name and a brief idea of what it does.>
|
||||
* Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
if (! defined('NOREQUIREHOOK')) define('NOREQUIREHOOK','1');
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
|
||||
|
||||
$sync_response = GETPOST('sync_response');
|
||||
|
||||
if (!empty($sync_response))
|
||||
{
|
||||
$sync_response = json_decode($sync_response);
|
||||
MultiCurrency::syncRates($sync_response);
|
||||
}
|
||||
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
/* <one line to give the program's name and a brief idea of what it does.>
|
||||
* Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
include '../../main.inc.php';
|
||||
$langs->load('errors');
|
||||
|
||||
?>
|
||||
|
||||
function getXMLHttpRequest()
|
||||
{
|
||||
var xhr = null;
|
||||
if (window.XMLHttpRequest || window.ActiveXObject)
|
||||
{
|
||||
if (window.ActiveXObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
xhr = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
xhr = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xhr = new XMLHttpRequest();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (typeof $ !== "undefined") $.jnotify("<?php echo $langs->transnoentitiesnoconv('multicurrency_error_browser_incompatible'); ?>", "error");
|
||||
else alert("<?php echo $langs->transnoentitiesnoconv('multicurrency_error_browser_incompatible'); ?>");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return xhr;
|
||||
}
|
||||
|
||||
function request(url, callback)
|
||||
{
|
||||
var xhr = getXMLHttpRequest();
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
|
||||
{
|
||||
callback(xhr.responseText);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
xhr.open("GET", url, true);
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function syncronize_rates()
|
||||
{
|
||||
document.getElementById("bt_sync").disabled = true;
|
||||
var url_sync = "http://apilayer.net/api/live?access_key=<?php echo $conf->global->MULTICURRENCY_APP_ID; ?>&format=1<?php if (!empty($conf->global->MULTICURRENCY_APP_SOURCE)) echo '&source='.$conf->global->MULTICURRENCY_APP_SOURCE; ?>";
|
||||
request(url_sync, update_rates);
|
||||
}
|
||||
|
||||
function update_rates(responseText)
|
||||
{
|
||||
var response = JSON.parse(responseText);
|
||||
if (response.success)
|
||||
{
|
||||
var url = "<?php echo DOL_URL_ROOT; ?>/multicurrency/ajax/updaterates.php?sync_response="+JSON.stringify(response);
|
||||
request(url, reloadpage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (typeof $ !== "undefined") $.jnotify("<?php echo $langs->transnoentitiesnoconv('multicurrency_syncronize_error'); ?>: "+response.error.info, "error");
|
||||
else alert("<?php echo $langs->transnoentitiesnoconv('multicurrency_syncronize_error'); ?>: "+response.error.info);
|
||||
}
|
||||
}
|
||||
|
||||
function reloadpage(responseText)
|
||||
{
|
||||
document.getElementById("bt_sync").disabled = false;
|
||||
window.location.href = window.location.pathname;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user