28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/multicurrency.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
42$langs->loadLangs(array(
'admin',
'multicurrency'));
50$action =
GETPOST(
'action',
'aZ09');
60if (preg_match(
'/set_([a-z0-9_\-]+)/i', $action, $reg)) {
62 $value =
GETPOST($code,
'alpha');
64 setEventMessages($langs->trans(
"SetupSaved"),
null,
'mesgs');
66 setEventMessages($langs->trans(
"Error"),
null,
'errors');
70if (preg_match(
'/del_([a-z0-9_\-]+)/i', $action, $reg)) {
73 setEventMessages($langs->trans(
"SetupSaved"),
null,
'mesgs');
75 setEventMessages($langs->trans(
"Error"),
null,
'errors');
79if ($action ==
'add_currency') {
82 $langs->loadCacheCurrencies(
'');
84 $code =
GETPOST(
'code',
'alpha');
87 $currency->code = $code;
88 $currency->name = !empty($langs->cache_currencies[$code][
'label']) ? $langs->cache_currencies[$code][
'label'].
' ('.$langs->getCurrencySymbol($code).
')' : $code;
90 if (empty($currency->code) || $currency->code ==
'-1') {
91 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Currency")),
null,
'errors');
95 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Rate")),
null,
'errors');
100 if ($currency->create($user) > 0) {
101 if ($currency->addRate((
float) $rate)) {
102 setEventMessages($langs->trans(
'RecordSaved'), array());
104 setEventMessages($langs->trans(
'ErrorAddRateFail'), array(),
'errors');
107 setEventMessages($langs->trans(
'ErrorAddCurrencyFail'), $currency->errors,
'errors');
110} elseif ($action ==
'update_currency') {
113 if (
GETPOST(
'updatecurrency',
'alpha')) {
114 $fk_multicurrency =
GETPOSTINT(
'fk_multicurrency');
119 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Rate")),
null,
'errors');
123 if ($currency->fetch($fk_multicurrency) > 0) {
124 $result = $currency->updateRate((
float) $rate);
126 setEventMessages(
null, $currency->errors,
'errors');
130 } elseif (
GETPOST(
'deletecurrency',
'alpha')) {
131 $fk_multicurrency =
GETPOSTINT(
'fk_multicurrency');
134 if ($currency->fetch($fk_multicurrency) > 0) {
135 if ($currency->delete($user) > 0) {
136 setEventMessages($langs->trans(
'RecordDeleted'), array());
138 setEventMessages($langs->trans(
'ErrorDeleteCurrencyFail'), array(),
'errors');
142} elseif ($action ==
'setapilayer') {
151 setEventMessages($langs->trans(
"SetupSaved"),
null);
154 $result = $multicurrency->syncRates(0, 0,
'');
156 setEventMessages($langs->trans(
"CurrencyRateSyncSucceed"),
null,
"mesgs");
158 setEventMessages($multicurrency->output,
null,
'errors');
164$TAvailableCurrency = array();
165$sql =
"SELECT code_iso, label, unicode, active FROM ".MAIN_DB_PREFIX.
"c_currencies";
166$resql = $db->query($sql);
168 while ($obj = $db->fetch_object($resql)) {
169 $TAvailableCurrency[$obj->code_iso] = array(
'code' => $obj->code_iso,
'active' => $obj->active);
174$sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"multicurrency WHERE entity = ".((int)
$conf->entity);
175$resql = $db->query($sql);
177 while ($obj = $db->fetch_object($resql)) {
179 $currency->fetch($obj->rowid);
180 $TCurrency[] = $currency;
189$form =
new Form($db);
191$page_name =
"MultiCurrencySetup";
194llxHeader(
'', $langs->trans($page_name), $help_url,
'', 0, 0,
'',
'',
'',
'mod-admin page-multicurrency');
197$linkback =
'<a href="'.dolBuildUrl(DOL_URL_ROOT.
'/admin/modules.php', [
'restore_lastsearch_values' => 1]).
'">'.img_picto($langs->trans(
"BackToModuleList"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"BackToModuleList").
'</span></a>';
203print
dol_get_fiche_head($head,
'settings', $langs->trans($page_name), -1,
"multicurrency");
209print
'<div class="div-table-responsive-no-min">';
210print
'<table class="noborder centpercent">';
211print
'<tr class="liste_titre">';
212print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
213print
'<td class="center">'.$langs->trans(
"Status").
'</td>'.
"\n";
216print
'<tr class="oddeven">';
217print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE").
'</td>';
218print
'<td class="center">';
219if (
$conf->use_javascript_ajax) {
220 print ajax_constantonoff(
'MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE');
222 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
223 print $form->selectarray(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE", $arrval,
getDolGlobalInt(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE"));
228print
'<tr class="oddeven">';
229$tooltip = $langs->trans(
"multicurrency_useOriginTxHelp");
230print
'<td>'.$form->textwithpicto($langs->transnoentitiesnoconv(
"multicurrency_useOriginTx"), $tooltip).
'</td>';
231print
'<td class="center">';
232if (
$conf->use_javascript_ajax) {
233 print ajax_constantonoff(
'MULTICURRENCY_USE_ORIGIN_TX', array(),
null, 0, 0, 0, 2, 0, 1);
235 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
236 print $form->selectarray(
"MULTICURRENCY_USE_ORIGIN_TX", $arrval,
getDolGlobalInt(
"MULTICURRENCY_USE_ORIGIN_TX"));
242 print
'<tr class="oddeven">';
243 print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT").
'</td>';
244 print
'<td class="center">';
245 if (
$conf->use_javascript_ajax) {
246 print ajax_constantonoff(
'MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT');
248 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
249 print $form->selectarray(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT", $arrval,
getDolGlobalInt(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT"));
288print
'<div class="div-table-responsive-no-min">';
289print
'<table class="noborder centpercent nomarginbottom">';
291print
'<tr class="liste_titre">';
292print
'<td>'.$form->textwithpicto($langs->trans(
"CurrenciesUsed"), $langs->transnoentitiesnoconv(
"CurrenciesUsed_help_to_add")).
'</td>'.
"\n";
293print
'<td class="right">'.$langs->trans(
"Rate").
' / '.$langs->getCurrencySymbol(
getDolCurrency()).
'</td>'.
"\n";
296print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'" spellcheck="false">';
297print
'<input type="hidden" name="token" value="'.newToken().
'">';
298print
'<input type="hidden" name="action" value="add_currency">';
300print
'<tr class="oddeven">';
301print
'<td>'.$form->selectCurrency(
'',
'code', 1,
'1').
'</td>';
302print
'<td class="right">';
303print
'<input type="text" name="rate" value="" class="width75 right" placeholder="'.$langs->trans(
'Rate').
'" /> ';
304print
'<input type="submit" class="button button-add smallpaddingimp" value="'.$langs->trans(
"Add").
'">';
311print
'<tr class="oddeven">';
312print
'<td>'.getDolCurrency();
314print $form->textwithpicto(
' ', $langs->trans(
"BaseCurrency"));
316 print img_warning(
'Warning: This code has been disabled into Home - Setup - Dictionaries - Currencies');
319print
'<td class="right">1</td>';
322foreach ($TCurrency as &$currency) {
327 print
'<tr class="oddeven">';
328 print
'<td>'.$currency->code.
' - '.$currency->name;
329 if (!empty($TAvailableCurrency[$currency->code]) && empty($TAvailableCurrency[$currency->code][
'active'])) {
330 print img_warning(
'Warning: The code '.$currency->code.
' has been disabled into Home - Setup - Dictionaries - Currencies');
333 print
'<td class="right">';
334 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'" spellcheck="false">';
335 print
'<input type="hidden" name="token" value="'.newToken().
'">';
336 print
'<input type="hidden" name="action" value="update_currency">';
337 print
'<input type="hidden" name="fk_multicurrency" value="'.$currency->id.
'">';
338 print
'1 '.getDolCurrency().
' = ';
339 print
'<input type="text" name="rate" class="width125 right" value="'.($currency->rate->rate ? $currency->rate->rate :
'').
'"> '.$currency->code.
' ';
340 print
'<input type="submit" name="updatecurrency" class="button button-edit smallpaddingimp" value="'.$langs->trans(
"Modify").
'"> ';
341 print
'<input type="submit" name="deletecurrency" class="button smallpaddingimp" value="'.$langs->trans(
"Delete").
'">';
350 <script type="text/javascript">
353 $("#bt_sync").attr("disabled", true);
365 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'" id="form_sync" spellcheck="false">';
366 print
'<input type="hidden" name="token" value="'.newToken().
'">';
367 print
'<input type="hidden" name="action" value="setapilayer">';
369 print
'<div class="div-table-responsive-no-min">';
370 print
'<table class="noborder centpercent">';
372 $urlforapilayer =
'https://currencylayer.com';
374 $endpointdefault =
'https://api.currencylayer.com/live?access_key=__MULTICURRENCY_APP_KEY__&source=__MULTICURRENCY_APP_SOURCE__';
375 $endpointdefault2 =
'https://api.apilayer.com/currency_data/live?base=__MULTICURRENCY_APP_SOURCE__';
376 $endpointdefaultfrankfurter = MultiCurrency::MULTICURRENCY_APP_ENDPOINT_FRANKFURTER_DEFAULT;
378 $tooltiptext = $langs->trans(
"CurrencyLayerAccount_help_to_synchronize", $urlforapilayer).
'<br><span class="small">';
379 $tooltiptext .=
'<br>- Endpoint for currencylayer:<br>'.$endpointdefault;
380 $tooltiptext .=
'<br>- Endpoint for apilayer:<br>'.$endpointdefault2;
381 $tooltiptext .=
'<br>- Endpoint for Frankfurter (free, no API key needed):<br>'.$endpointdefaultfrankfurter;
382 $tooltiptext .=
'</span><br>';
386 print
'<tr class="liste_titre">';
387 print
'<td>'.$form->textwithpicto($langs->trans(
"CurrencyLayerAccount"), $tooltiptext, 1,
'help',
'valignmiddle', 0, 3,
'tooltipcurrencylayer').
'</td>'.
"\n";
388 print
'<td class="right">';
389 print
'<textarea id="response" class="hideobject" name="response"></textarea>';
390 print
'<input type="submit" name="modify_apilayer" class="button buttongen" value="'.$langs->trans(
"Modify").
'">';
391 print
'<input type="submit" id="bt_sync" name="bt_sync_apilayer" class="button buttongen" value="'.$langs->trans(
'Synchronize').
'"';
392 if ($currentprovider !=
'frankfurter' && !
getDolGlobalString(
'MULTICURRENCY_APP_KEY')) {
393 print
' disabled="disabled"';
398 print
'<tr class="oddeven">';
399 print
'<td>'.$langs->trans(
"multicurrency_appProvider").
'</td>';
400 print
'<td class="right">';
401 print
'<select id="MULTICURRENCY_APP_PROVIDER" name="MULTICURRENCY_APP_PROVIDER" class="flat">';
402 print
'<option value="currencylayer"'.($currentprovider ==
'currencylayer' ?
' selected' :
'').
'>'.$langs->trans(
"multicurrency_providerCurrencyLayer").
'</option>';
403 print
'<option value="frankfurter"'.($currentprovider ==
'frankfurter' ?
' selected' :
'').
'>'.$langs->trans(
"multicurrency_providerFrankfurter").
'</option>';
404 print
'</select> ';
407 print
'<tr class="oddeven">';
408 print
'<td>'.$langs->transnoentitiesnoconv(
"multicurrency_appId").
'</td>';
409 print
'<td class="right">';
410 print
'<input class="width300" type="text" name="MULTICURRENCY_APP_KEY" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_KEY').
'" placeholder="'.($currentprovider ==
'frankfurter' ? $langs->trans(
"multicurrency_appIdNotNeeded") :
'').
'" /> ';
413 print
'<tr class="oddeven">';
414 print
'<td>'.$langs->transnoentitiesnoconv(
"multicurrency_appCurrencySource").
'</td>';
415 print
'<td class="right">';
416 print
'<input type="text" name="MULTICURRENCY_APP_SOURCE" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_SOURCE').
'" size="10" placeholder="USD" /> ';
419 $endpointdefaultforcurrentprovider = ($currentprovider ==
'frankfurter') ? $endpointdefaultfrankfurter :
MultiCurrency::MULTICURRENCY_APP_ENDPOINT_DEFAULT;
421 print
'<tr class="oddeven">';
422 print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_APP_ENDPOINT").
'</td>';
423 print
'<td class="right">';
424 print
'<input class="width500" id="MULTICURRENCY_APP_ENDPOINT" type="text" name="MULTICURRENCY_APP_ENDPOINT" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_ENDPOINT', $endpointdefaultforcurrentprovider).
'" /> ';
428 jQuery(document).ready(function() {
429 var endpointdefaults = {
430 currencylayer: '.json_encode($endpointdefault).
',
431 frankfurter: '.json_encode($endpointdefaultfrankfurter).
'
433 jQuery("#MULTICURRENCY_APP_PROVIDER").on("change", function() {
434 jQuery("#MULTICURRENCY_APP_ENDPOINT").val(endpointdefaults[jQuery(this).val()]);
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
multicurrencyAdminPrepareHead()
Prepare array with list of tabs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.