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');
70if (preg_match(
'/del_([a-z0-9_\-]+)/i', $action, $reg)) {
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)) {
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);
130 } elseif (
GETPOST(
'deletecurrency',
'alpha')) {
131 $fk_multicurrency =
GETPOSTINT(
'fk_multicurrency');
134 if ($currency->fetch($fk_multicurrency) > 0) {
135 if ($currency->delete($user) > 0) {
138 setEventMessages($langs->trans(
'ErrorDeleteCurrencyFail'), array(),
'errors');
142} elseif ($action ==
'setapilayer') {
143 if (GETPOSTISSET(
'modify_apilayer')) {
153 $result = $multicurrency->syncRates(0, 0,
'');
163$TAvailableCurrency = array();
164$sql =
"SELECT code_iso, label, unicode, active FROM ".MAIN_DB_PREFIX.
"c_currencies";
165$resql =
$db->query($sql);
167 while ($obj =
$db->fetch_object($resql)) {
168 $TAvailableCurrency[$obj->code_iso] = array(
'code' => $obj->code_iso,
'active' => $obj->active);
173$sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"multicurrency WHERE entity = ".((int)
$conf->entity);
174$resql =
$db->query($sql);
176 while ($obj =
$db->fetch_object($resql)) {
178 $currency->fetch($obj->rowid);
179 $TCurrency[] = $currency;
190$page_name =
"MultiCurrencySetup";
193llxHeader(
'', $langs->trans($page_name), $help_url,
'', 0, 0,
'',
'',
'',
'mod-admin page-multicurrency');
196$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>';
202print
dol_get_fiche_head($head,
'settings', $langs->trans($page_name), -1,
"multicurrency");
208print
'<div class="div-table-responsive-no-min">';
209print
'<table class="noborder centpercent">';
210print
'<tr class="liste_titre">';
211print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
212print
'<td class="center">'.$langs->trans(
"Status").
'</td>'.
"\n";
215print
'<tr class="oddeven">';
216print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE").
'</td>';
217print
'<td class="center">';
218if (
$conf->use_javascript_ajax) {
219 print ajax_constantonoff(
'MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE');
221 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
222 print $form->selectarray(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE", $arrval,
getDolGlobalInt(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE"));
227print
'<tr class="oddeven">';
228$tooltip = $langs->trans(
"multicurrency_useOriginTxHelp");
229print
'<td>'.$form->textwithpicto($langs->transnoentitiesnoconv(
"multicurrency_useOriginTx"), $tooltip).
'</td>';
230print
'<td class="center">';
231if (
$conf->use_javascript_ajax) {
232 print ajax_constantonoff(
'MULTICURRENCY_USE_ORIGIN_TX', array(),
null, 0, 0, 0, 2, 0, 1);
234 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
235 print $form->selectarray(
"MULTICURRENCY_USE_ORIGIN_TX", $arrval,
getDolGlobalInt(
"MULTICURRENCY_USE_ORIGIN_TX"));
241 print
'<tr class="oddeven">';
242 print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT").
'</td>';
243 print
'<td class="center">';
244 if (
$conf->use_javascript_ajax) {
245 print ajax_constantonoff(
'MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT');
247 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
248 print $form->selectarray(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT", $arrval,
getDolGlobalInt(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT"));
287print
'<div class="div-table-responsive-no-min">';
288print
'<table class="noborder centpercent nomarginbottom">';
290print
'<tr class="liste_titre">';
291print
'<td>'.$form->textwithpicto($langs->trans(
"CurrenciesUsed"), $langs->transnoentitiesnoconv(
"CurrenciesUsed_help_to_add")).
'</td>'.
"\n";
292print
'<td class="right">'.$langs->trans(
"Rate").
' / '.$langs->getCurrencySymbol(
getDolCurrency()).
'</td>'.
"\n";
295print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
296print
'<input type="hidden" name="token" value="'.newToken().
'">';
297print
'<input type="hidden" name="action" value="add_currency">';
299print
'<tr class="oddeven">';
300print
'<td>'.$form->selectCurrency(
'',
'code', 1,
'1').
'</td>';
301print
'<td class="right">';
302print
'<input type="text" name="rate" value="" class="width75 right" placeholder="'.$langs->trans(
'Rate').
'" /> ';
303print
'<input type="submit" class="button button-add smallpaddingimp" value="'.$langs->trans(
"Add").
'">';
310print
'<tr class="oddeven">';
311print
'<td>'.getDolCurrency();
313print $form->textwithpicto(
' ', $langs->trans(
"BaseCurrency"));
315 print
img_warning(
'Warning: This code has been disabled into Home - Setup - Dictionaries - Currencies');
318print
'<td class="right">1</td>';
321foreach ($TCurrency as &$currency) {
326 print
'<tr class="oddeven">';
327 print
'<td>'.$currency->code.
' - '.$currency->name;
328 if (!empty($TAvailableCurrency[$currency->code]) && empty($TAvailableCurrency[$currency->code][
'active'])) {
329 print
img_warning(
'Warning: The code '.$currency->code.
' has been disabled into Home - Setup - Dictionaries - Currencies');
332 print
'<td class="right">';
333 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
334 print
'<input type="hidden" name="token" value="'.newToken().
'">';
335 print
'<input type="hidden" name="action" value="update_currency">';
336 print
'<input type="hidden" name="fk_multicurrency" value="'.$currency->id.
'">';
337 print
'1 '.getDolCurrency().
' = ';
338 print
'<input type="text" name="rate" class="width125 right" value="'.($currency->rate->rate ? $currency->rate->rate :
'').
'"> '.$currency->code.
' ';
339 print
'<input type="submit" name="updatecurrency" class="button button-edit smallpaddingimp" value="'.$langs->trans(
"Modify").
'"> ';
340 print
'<input type="submit" name="deletecurrency" class="button smallpaddingimp" value="'.$langs->trans(
"Delete").
'">';
349 <script type="text/javascript">
352 $("#bt_sync").attr("disabled", true);
364 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'" id="form_sync">';
365 print
'<input type="hidden" name="token" value="'.newToken().
'">';
366 print
'<input type="hidden" name="action" value="setapilayer">';
368 print
'<div class="div-table-responsive-no-min">';
369 print
'<table class="noborder centpercent">';
371 $urlforapilayer =
'https://currencylayer.com';
373 $endpointdefault =
'https://api.currencylayer.com/live?access_key=__MULTICURRENCY_APP_KEY__&source=__MULTICURRENCY_APP_SOURCE__';
374 $endpointdefault2 =
'https://api.apilayer.com/currency_data/live?base=__MULTICURRENCY_APP_SOURCE__';
376 $tooltiptext = $langs->trans(
"CurrencyLayerAccount_help_to_synchronize", $urlforapilayer).
'<br><span class="small">';
377 $tooltiptext .=
'<br>- Endpoint for currencylayer:<br>'.$endpointdefault;
378 $tooltiptext .=
'<br>- Endpoint for apilayer:<br>'.$endpointdefault2;
379 $tooltiptext .=
'</span><br>';
381 print
'<tr class="liste_titre">';
382 print
'<td>'.$form->textwithpicto($langs->trans(
"CurrencyLayerAccount"), $tooltiptext, 1,
'help',
'valignmiddle', 0, 3,
'tooltipcurrencylayer').
'</td>'.
"\n";
383 print
'<td class="right">';
384 print
'<textarea id="response" class="hideobject" name="response"></textarea>';
385 print
'<input type="submit" name="modify_apilayer" class="button buttongen" value="'.$langs->trans(
"Modify").
'">';
386 print
'<input type="submit" id="bt_sync" name="bt_sync_apilayer" class="button buttongen" value="'.$langs->trans(
'Synchronize').
'"';
388 print
' disabled="disabled"';
393 print
'<tr class="oddeven">';
394 print
'<td>'.$langs->transnoentitiesnoconv(
"multicurrency_appId").
'</td>';
395 print
'<td class="right">';
396 print
'<input class="width300" type="text" name="MULTICURRENCY_APP_KEY" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_KEY').
'" /> ';
399 print
'<tr class="oddeven">';
400 print
'<td>'.$langs->transnoentitiesnoconv(
"multicurrency_appCurrencySource").
'</td>';
401 print
'<td class="right">';
402 print
'<input type="text" name="MULTICURRENCY_APP_SOURCE" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_SOURCE').
'" size="10" placeholder="USD" /> ';
405 print
'<tr class="oddeven">';
406 print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_APP_ENDPOINT").
'</td>';
407 print
'<td class="right">';
408 print
'<input class="width500" type="text" name="MULTICURRENCY_APP_ENDPOINT" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_ENDPOINT', MultiCurrency::MULTICURRENCY_APP_ENDPOINT_DEFAULT).
'" /> ';
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.