27require
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/multicurrency.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
34$langs->loadLangs(array(
'admin',
'multicurrency'));
37if (!$user->admin || !isModEnabled(
'multicurrency')) {
42$action =
GETPOST(
'action',
'aZ09');
50if (preg_match(
'/set_([a-z0-9_\-]+)/i', $action, $reg)) {
52 $value =
GETPOST($code,
'alpha');
60if (preg_match(
'/del_([a-z0-9_\-]+)/i', $action, $reg)) {
69if ($action ==
'add_currency') {
72 $langs->loadCacheCurrencies(
'');
74 $code =
GETPOST(
'code',
'alpha');
77 $currency->code = $code;
78 $currency->name = !empty($langs->cache_currencies[$code][
'label']) ? $langs->cache_currencies[$code][
'label'].
' ('.$langs->getCurrencySymbol($code).
')' : $code;
80 if (empty($currency->code) || $currency->code ==
'-1') {
81 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Currency")),
null,
'errors');
85 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Rate")),
null,
'errors');
90 if ($currency->create($user) > 0) {
91 if ($currency->addRate($rate)) {
97 setEventMessages($langs->trans(
'ErrorAddCurrencyFail'), $currency->errors,
'errors');
100} elseif ($action ==
'update_currency') {
103 if (
GETPOST(
'updatecurrency',
'alpha')) {
104 $fk_multicurrency =
GETPOSTINT(
'fk_multicurrency');
109 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Rate")),
null,
'errors');
113 if ($currency->fetch($fk_multicurrency) > 0) {
114 $result = $currency->updateRate($rate);
120 } elseif (
GETPOST(
'deletecurrency',
'alpha')) {
121 $fk_multicurrency =
GETPOSTINT(
'fk_multicurrency');
124 if ($currency->fetch($fk_multicurrency) > 0) {
125 if ($currency->delete($user) > 0) {
128 setEventMessages($langs->trans(
'ErrorDeleteCurrencyFail'), array(),
'errors');
132} elseif ($action ==
'setapilayer') {
133 if (GETPOSTISSET(
'modify_apilayer')) {
147$TAvailableCurrency = array();
148$sql =
"SELECT code_iso, label, unicode, active FROM ".MAIN_DB_PREFIX.
"c_currencies";
149$resql = $db->query($sql);
151 while ($obj = $db->fetch_object($resql)) {
152 $TAvailableCurrency[$obj->code_iso] = array(
'code' => $obj->code_iso,
'active' => $obj->active);
157$sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"multicurrency WHERE entity = ".((int) $conf->entity);
158$resql = $db->query($sql);
160 while ($obj = $db->fetch_object($resql)) {
162 $currency->fetch($obj->rowid);
163 $TCurrency[] = $currency;
172$form =
new Form($db);
174$page_name =
"MultiCurrencySetup";
177llxHeader(
'', $langs->trans($page_name), $help_url,
'', 0, 0,
'',
'',
'',
'mod-admin page-multicurrency');
180$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
185print
dol_get_fiche_head($head,
'settings', $langs->trans($page_name), -1,
"multicurrency");
188print
'<div class="div-table-responsive-no-min">';
189print
'<table class="noborder centpercent">';
190print
'<tr class="liste_titre">';
191print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
192print
'<td class="center">'.$langs->trans(
"Status").
'</td>'.
"\n";
195print
'<tr class="oddeven">';
196print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE").
'</td>';
197print
'<td class="center">';
198if ($conf->use_javascript_ajax) {
199 print ajax_constantonoff(
'MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE');
201 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
202 print $form->selectarray(
"MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE", $arrval, $conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE);
207print
'<tr class="oddeven">';
208print
'<td>'.$langs->transnoentitiesnoconv(
"multicurrency_useOriginTx").
'</td>';
209print
'<td class="center">';
210if ($conf->use_javascript_ajax) {
211 print ajax_constantonoff(
'MULTICURRENCY_USE_ORIGIN_TX', array(),
null, 0, 0, 0, 2, 0, 1);
213 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
214 print $form->selectarray(
"MULTICURRENCY_USE_ORIGIN_TX", $arrval, $conf->global->MULTICURRENCY_USE_ORIGIN_TX);
220 print
'<tr class="oddeven">';
221 print
'<td>'.$langs->transnoentitiesnoconv(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT").
'</td>';
222 print
'<td class="center">';
223 if ($conf->use_javascript_ajax) {
224 print ajax_constantonoff(
'MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT');
226 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
227 print $form->selectarray(
"MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT", $arrval, $conf->global->MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT);
265print
'<div class="div-table-responsive-no-min">';
266print
'<table class="noborder centpercent nomarginbottom">';
268print
'<tr class="liste_titre">';
269print
'<td>'.$form->textwithpicto($langs->trans(
"CurrenciesUsed"), $langs->transnoentitiesnoconv(
"CurrenciesUsed_help_to_add")).
'</td>'.
"\n";
270print
'<td class="right">'.$langs->trans(
"Rate").
' / '.$langs->getCurrencySymbol($conf->currency).
'</td>'.
"\n";
273print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
274print
'<input type="hidden" name="token" value="'.newToken().
'">';
275print
'<input type="hidden" name="action" value="add_currency">';
277print
'<tr class="oddeven">';
278print
'<td>'.$form->selectCurrency(
'',
'code', 1,
'1').
'</td>';
279print
'<td class="right">';
280print
'<input type="text" name="rate" value="" class="width75 right" placeholder="'.$langs->trans(
'Rate').
'" /> ';
281print
'<input type="submit" class="button button-add smallpaddingimp" value="'.$langs->trans(
"Add").
'">';
288print
'<tr class="oddeven">';
289print
'<td>'.$conf->currency;
290print
' ('.$langs->getCurrencySymbol($conf->currency).
')';
291print $form->textwithpicto(
' ', $langs->trans(
"BaseCurrency"));
292if (!empty($TAvailableCurrency[$conf->currency]) && empty($TAvailableCurrency[$conf->currency][
'active'])) {
293 print
img_warning(
'Warning: This code has been disabled into Home - Setup - Dictionaries - Currencies');
296print
'<td class="right">1</td>';
299foreach ($TCurrency as &$currency) {
300 if ($currency->code == $conf->currency) {
304 print
'<tr class="oddeven">';
305 print
'<td>'.$currency->code.
' - '.$currency->name;
306 if (!empty($TAvailableCurrency[$currency->code]) && empty($TAvailableCurrency[$currency->code][
'active'])) {
307 print
img_warning(
'Warning: The code '.$currency->code.
' has been disabled into Home - Setup - Dictionaries - Currencies');
310 print
'<td class="right">';
311 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
312 print
'<input type="hidden" name="token" value="'.newToken().
'">';
313 print
'<input type="hidden" name="action" value="update_currency">';
314 print
'<input type="hidden" name="fk_multicurrency" value="'.$currency->id.
'">';
315 print
'1 '.$conf->currency.
' = ';
316 print
'<input type="text" name="rate" class="width75 right" value="'.($currency->rate->rate ? $currency->rate->rate :
'').
'" size="13"> '.$currency->code.
' ';
317 print
'<input type="submit" name="updatecurrency" class="button button-edit smallpaddingimp" value="'.$langs->trans(
"Modify").
'"> ';
318 print
'<input type="submit" name="deletecurrency" class="button smallpaddingimp" value="'.$langs->trans(
"Delete").
'">';
327 <script type="text/javascript">
330 $("#bt_sync").attr("disabled", true);
340 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'" id="form_sync">';
341 print
'<input type="hidden" name="token" value="'.newToken().
'">';
342 print
'<input type="hidden" name="action" value="setapilayer">';
344 print
'<div class="div-table-responsive-no-min">';
345 print
'<table class="noborder centpercent">';
347 $urlforapilayer =
'https://currencylayer.com';
349 print
'<tr class="liste_titre">';
350 print
'<td>'.$form->textwithpicto($langs->trans(
"CurrencyLayerAccount"), $langs->trans(
"CurrencyLayerAccount_help_to_synchronize", $urlforapilayer)).
'</td>'.
"\n";
351 print
'<td class="right">';
352 print
'<textarea id="response" class="hideobject" name="response"></textarea>';
353 print
'<input type="submit" name="modify_apilayer" class="button buttongen" value="'.$langs->trans(
"Modify").
'">';
354 print
'<input type="submit" id="bt_sync" name="bt_sync_apilayer" class="button buttongen" value="'.$langs->trans(
'Synchronize').
'" />';
357 print
'<tr class="oddeven">';
358 print
'<td class="fieldrequired"><a target="_blank" rel="noopener noreferrer external" href="'.$urlforapilayer.
'">'.$langs->transnoentitiesnoconv(
"multicurrency_appId").
'</a></td>';
359 print
'<td class="right">';
360 print
'<input type="text" name="MULTICURRENCY_APP_ID" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_ID').
'" size="28" /> ';
363 print
'<tr class="oddeven">';
364 print
'<td>'.$langs->transnoentitiesnoconv(
"multicurrency_appCurrencySource").
'</td>';
365 print
'<td class="right">';
366 print
'<input type="text" name="MULTICURRENCY_APP_SOURCE" value="' .
getDolGlobalString(
'MULTICURRENCY_APP_SOURCE').
'" size="10" placeholder="USD" /> ';
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.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.