multicurrency_rate.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2012-2016 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2013-2019 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. * Copyright (C) 2013 Jean Heimburger <jean@tiaris.info>
  9. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  10. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  11. * Copyright (C) 2013 Adolfo segura <adolfo.segura@gmail.com>
  12. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  13. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/multicurrency/multicurrency_rate.php
  30. * \ingroup multicurrency
  31. * \brief Page to list multicurrency rate
  32. */
  33. // Load Dolibarr environment
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/multicurrency.lib.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('multicurrency'));
  39. // Get Parameters
  40. $action = GETPOST('action', 'alpha');
  41. $massaction = GETPOST('massaction', 'alpha');
  42. $show_files = GETPOST('show_files', 'int');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. $toselect = GETPOST('toselect', 'array');
  45. $id_rate_selected = GETPOST('id_rate', 'int');
  46. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  47. $search_date_sync = dol_mktime(0, 0, 0, GETPOST('search_date_syncmonth', 'int'), GETPOST('search_date_syncday', 'int'), GETPOST('search_date_syncyear', 'int'));
  48. $search_date_sync_end = dol_mktime(0, 0, 0, GETPOST('search_date_sync_endmonth', 'int'), GETPOST('search_date_sync_endday', 'int'), GETPOST('search_date_sync_endyear', 'int'));
  49. $search_rate = GETPOST('search_rate', 'alpha');
  50. $search_code = GETPOST('search_code', 'alpha');
  51. $multicurrency_code = GETPOST('multicurrency_code', 'alpha');
  52. $dateinput = dol_mktime(0, 0, 0, GETPOST('dateinputmonth', 'int'), GETPOST('dateinputday', 'int'), GETPOST('dateinputyear', 'int'));
  53. $rateinput = price2num(GETPOST('rateinput', 'alpha'));
  54. $optioncss = GETPOST('optioncss', 'alpha');
  55. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  56. $sortfield = GETPOST('sortfield', 'aZ09comma');
  57. $sortorder = GETPOST('sortorder', 'aZ09comma');
  58. $page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0);
  59. if (empty($page) || $page == -1) {
  60. $page = 0;
  61. } // If $page is not defined, or '' or -1
  62. $offset = $limit * $page;
  63. $pageprev = $page - 1;
  64. $pagenext = $page + 1;
  65. if (!$sortfield) $sortfield = "cr.date_sync";
  66. if (!$sortorder) $sortorder = "DESC";
  67. // Initialize technical objects
  68. $object = new CurrencyRate($db);
  69. $form = new Form($db);
  70. $extrafields = new ExtraFields($db);
  71. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
  72. $hookmanager->initHooks(array('EditorRatelist', 'globallist'));
  73. if (empty($action)) {
  74. $action = 'list';
  75. }
  76. // List of fields to search into when doing a "search in all"
  77. $fieldstosearchall = array(
  78. 'cr.date_sync'=>"date_sync",
  79. 'cr.rate'=>"rate",
  80. 'm.code'=>"code",
  81. );
  82. // Definition of fields for lists
  83. $arrayfields = array(
  84. 'cr.date_sync'=>array('label'=>'Date', 'checked'=>1),
  85. 'cr.rate'=>array('label'=>'Rate', 'checked'=>1),
  86. 'm.code'=>array('label'=>'Code', 'checked'=>1),
  87. );
  88. $object->fields = dol_sort_array($object->fields, 'position');
  89. $arrayfields = dol_sort_array($arrayfields, 'position');
  90. // Access control
  91. // TODO Open this page to a given permission so a sale representative can modify change rates. Permission should be added into module multicurrency.
  92. // One permission to read rates (history) and one to add/edit rates.
  93. if (!$user->admin || !isModEnabled("multicurrency")) {
  94. accessforbidden();
  95. }
  96. $error = 0;
  97. /*
  98. * Actions
  99. */
  100. if ($action == "create") {
  101. if (empty($multicurrency_code) || $multicurrency_code == '-1') {
  102. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Currency")), null, "errors");
  103. $error++;
  104. }
  105. if ($rateinput === '0') {
  106. setEventMessages($langs->trans('NoEmptyRate'), null, "errors");
  107. $error++;
  108. } elseif (empty($rateinput)) {
  109. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Rate")), null, "errors");
  110. $error++;
  111. }
  112. if (!$error) {
  113. $currencyRate_static = new CurrencyRate($db);
  114. $currency_static = new MultiCurrency($db);
  115. $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code);
  116. $currencyRate_static->fk_multicurrency = $fk_currency;
  117. $currencyRate_static->entity = $conf->entity;
  118. $currencyRate_static->date_sync = $dateinput;
  119. $currencyRate_static->rate = $rateinput;
  120. $result = $currencyRate_static->create(intval($fk_currency));
  121. if ($result > 0) {
  122. setEventMessages($langs->trans('successRateCreate', $multicurrency_code), null);
  123. } else {
  124. dol_syslog("currencyRate:createRate", LOG_WARNING);
  125. setEventMessages($currencyRate_static->error, $currencyRate_static->errors, 'errors');
  126. }
  127. }
  128. }
  129. if ($action == 'update') {
  130. $currencyRate = new CurrencyRate($db);
  131. $result = $currencyRate->fetch($id_rate_selected);
  132. if ($result > 0) {
  133. $currency_static = new MultiCurrency($db);
  134. $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code);
  135. $currencyRate->date_sync = $dateinput;
  136. $currencyRate->fk_multicurrency = $fk_currency;
  137. $currencyRate->rate = $rateinput;
  138. $res = $currencyRate->update();
  139. if ($res) {
  140. setEventMessages($langs->trans('successUpdateRate'), null);
  141. } else {
  142. setEventMessages($currencyRate->error, $currencyRate->errors, "errors");
  143. }
  144. } else {
  145. setEventMessages($langs->trans('Error'), null, "warnings");
  146. }
  147. }
  148. if ($action == "deleteRate") {
  149. $current_rate = new CurrencyRate($db);
  150. $current_rate->fetch(intval($id_rate_selected));
  151. if ($current_rate) {
  152. $current_currency = new MultiCurrency($db);
  153. $current_currency->fetch($current_rate->fk_multicurrency);
  154. if ($current_currency) {
  155. $delayedhtmlcontent = $form->formconfirm(
  156. $_SERVER["PHP_SELF"].'?id_rate='.$id_rate_selected,
  157. $langs->trans('DeleteLineRate'),
  158. $langs->trans('ConfirmDeleteLineRate', $current_rate->rate, $current_currency->name, $current_rate->date_sync),
  159. 'confirm_delete',
  160. '',
  161. 0,
  162. 1
  163. );
  164. } else {
  165. dol_syslog("Multicurrency::fetch", LOG_WARNING);
  166. }
  167. } else {
  168. setEventMessage($langs->trans('NoCurrencyRateSelected'), "warnings");
  169. }
  170. }
  171. if ($action == "confirm_delete") {
  172. $current_rate = new CurrencyRate($db);
  173. $current_rate->fetch(intval($id_rate_selected));
  174. if ($current_rate) {
  175. $result = $current_rate->delete();
  176. if ($result) {
  177. setEventMessages($langs->trans('successRateDelete'), null);
  178. } else {
  179. setEventMessages($current_rate->error, $current_rate->errors, 'errors');
  180. }
  181. } else {
  182. setEventMessages($langs->trans('NoCurrencyRateSelected'), null, "warnings");
  183. dol_syslog($langs->trans('NoCurrencyRateSelected'), LOG_WARNING);
  184. }
  185. }
  186. if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
  187. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
  188. $parameters = array();
  189. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  190. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  191. if (empty($reshook)) {
  192. // Selection of new fields
  193. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  194. // Purge search criteria
  195. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  196. $sall = "";
  197. $search_date_sync = "";
  198. $search_date_sync_end="";
  199. $search_rate = "";
  200. $search_code = "";
  201. $search_array_options = array();
  202. }
  203. // Mass actions
  204. $objectclass = "CurrencyRate";
  205. $uploaddir = $conf->multicurrency->multidir_output; // define only because core/actions_massactions.inc.php want it
  206. $permissiontoread = $user->admin;
  207. $permissiontodelete = $user->admin;
  208. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  209. }
  210. /*
  211. * View
  212. */
  213. $form = new Form($db);
  214. $title = $langs->trans("CurrencyRate");
  215. $page_name = "MultiCurrencySetup";
  216. $help_url = '';
  217. llxHeader('', $title, $help_url, '');
  218. // Subheader
  219. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  220. print load_fiche_titre($langs->trans($page_name), $linkback);
  221. // Configuration header
  222. $head = multicurrencyAdminPrepareHead();
  223. print dol_get_fiche_head($head, 'ratelist', $langs->trans("ModuleSetup"), -1, "multicurrency");
  224. // ACTION
  225. if (!in_array($action, array("updateRate", "deleteRate"))) {
  226. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
  227. print '<input type="hidden" name="token" value="'.newToken().'">';
  228. print '<div class="div-table-responsive-no-min">';
  229. print '<table class="noborder centpercent"><tr>';
  230. print ' <td>'.$langs->trans('Date').'</td>';
  231. print ' <td>';
  232. print $form->selectDate($dateinput, 'dateinput', 0, 0, 1, '', 1, 1);
  233. print '</td>';
  234. print '<td> '.$langs->trans('Currency').'</td>';
  235. print '<td>'.$form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 1, " code != '".$db->escape($conf->currency)."'", true).'</td>';
  236. print ' <td>'.$langs->trans('Rate').' / '.$langs->getCurrencySymbol($conf->currency).'</td>';
  237. print ' <td><input type="text" min="0" step="any" class="maxwidth75" name="rateinput" value="'.dol_escape_htmltag($rateinput).'"></td>';
  238. print '<td>';
  239. print '<input type="hidden" name="action" value="create">';
  240. print '<input type="submit" class="button button-add small" name="btnCreateCurrencyRate" value="'.$langs->trans('CreateRate').'">';
  241. print '</td>';
  242. print '</tr></table>';
  243. print '</div>';
  244. print '</form>';
  245. print '<br>';
  246. }
  247. $sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.entity, m.code, m.name';
  248. // Add fields from hooks
  249. $parameters = array();
  250. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  251. $sql .= $hookmanager->resPrint;
  252. $sql .= ' FROM '.MAIN_DB_PREFIX.'multicurrency_rate as cr ';
  253. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."multicurrency AS m ON cr.fk_multicurrency = m.rowid";
  254. if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  255. if ($search_date_sync && $search_date_sync_end ) {
  256. $sql .= " AND (cr.date_sync BETWEEN '".$db->idate($search_date_sync)."' AND '".$db->idate($search_date_sync_end)."')";
  257. } elseif ($search_date_sync && !$search_date_sync_end) {
  258. $sql .= natural_search('cr.date_sync', $db->idate($search_date_sync));
  259. }
  260. if ($search_rate) $sql .= natural_search('cr.rate', $search_rate);
  261. if ($search_code) $sql .= natural_search('m.code', $search_code);
  262. $sql .= " WHERE m.code <> '".$db->escape($conf->currency)."'";
  263. // Add where from hooks
  264. $parameters = array();
  265. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  266. $sql .= $hookmanager->resPrint;
  267. $sql .= " GROUP BY cr.rowid, cr.date_sync, cr.rate, m.code, cr.entity, m.code, m.name";
  268. // Add fields from hooks
  269. $parameters = array();
  270. $reshook = $hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook
  271. $sql .= $hookmanager->resPrint;
  272. $sql .= $db->order($sortfield, $sortorder);
  273. $nbtotalofrecords = '';
  274. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  275. $result = $db->query($sql);
  276. if ($result) {
  277. $nbtotalofrecords = $db->num_rows($result);
  278. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  279. $page = 0;
  280. $offset = 0;
  281. }
  282. } else {
  283. setEventMessage($langs->trans('No_record_on_multicurrency_rate'), 'warnings');
  284. }
  285. }
  286. $sql .= $db->plimit($limit + 1, $offset);
  287. $resql = $db->query($sql);
  288. if ($resql) {
  289. $num = $db->num_rows($resql);
  290. $arrayofselected = is_array($toselect) ? $toselect : array();
  291. $param = '';
  292. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  293. $param .= '&contextpage='.urlencode($contextpage);
  294. }
  295. if ($limit > 0 && $limit != $conf->liste_limit) {
  296. $param .= '&limit='.((int) $limit);
  297. }
  298. if ($sall) {
  299. $param .= "&sall=".urlencode($sall);
  300. }
  301. if ($search_date_sync) $param = "&search_date_sync=".$search_date_sync;
  302. if ($search_date_sync_end) $param="&search_date_sync_end=".$search_date_sync_end;
  303. if ($search_rate) $param = "&search_rate=".urlencode($search_rate);
  304. if ($search_code != '') $param.="&search_code=".urlencode($search_code);
  305. // Add $param from extra fields
  306. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  307. if ($user->admin) {
  308. $arrayofmassactions['predelete'] = $langs->trans("Delete");
  309. }
  310. if (in_array($massaction, array('presend', 'predelete'))) {
  311. $arrayofmassactions = array();
  312. }
  313. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  314. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
  315. if ($optioncss != '') {
  316. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  317. }
  318. print '<input type="hidden" name="token" value="'.newToken().'">';
  319. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  320. print '<input type="hidden" name="action" value="list">';
  321. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  322. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  323. print '<input type="hidden" name="page" value="'.$page.'">';
  324. print '<input type="hidden" name="type" value="'.$type.'">';
  325. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_currency.png', 0, $newcardbutton, '', $limit);
  326. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  327. if ($sall) {
  328. foreach ($fieldstosearchall as $key => $val) {
  329. $fieldstosearchall[$key] = $langs->trans($val);
  330. }
  331. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  332. }
  333. // Filter on categories
  334. $moreforfilter = '';
  335. $parameters = array();
  336. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  337. if (empty($reshook)) {
  338. $moreforfilter .= $hookmanager->resPrint;
  339. } else {
  340. $moreforfilter = $hookmanager->resPrint;
  341. }
  342. if ($moreforfilter) {
  343. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  344. print $moreforfilter;
  345. print '</div>';
  346. }
  347. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  348. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  349. if ($massactionbutton) {
  350. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  351. }
  352. print '<div class="div-table-responsive">';
  353. print '<table class="tagtable centpercent nomarginbottom liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  354. // Lines with input filters
  355. print '<tr class="liste_titre_filter">';
  356. // date
  357. if (!empty($arrayfields['cr.date_sync']['checked'])) {
  358. print '<td class="liste_titre" align="left">';
  359. print $form->selectDate(dol_print_date($search_date_sync, "%Y-%m-%d"), 'search_date_sync', 0, 0, 1);
  360. print $form->selectDate(dol_print_date($search_date_sync_end, "%Y-%m-%d"), 'search_date_sync_end', 0, 0, 1);
  361. print '</td>';
  362. }
  363. // code
  364. if (!empty($arrayfields['m.code']['checked'])) {
  365. print '<td class="liste_titre" align="left">';
  366. print $form->selectMultiCurrency($multicurrency_code, 'search_code', 1, " code != '".$conf->currency."'", true);
  367. print '</td>';
  368. }
  369. // rate
  370. if (!empty($arrayfields['cr.rate']['checked'])) {
  371. print '<td class="liste_titre" align="left">';
  372. print '<input class="flat maxwidth75" type="text" name="search_rate" value="'.dol_escape_htmltag($search_rate).'">';
  373. print '</td>';
  374. }
  375. // Fields from hook
  376. $parameters = array('arrayfields'=>$arrayfields);
  377. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  378. print $hookmanager->resPrint;
  379. print '<td class="liste_titre" align="middle">';
  380. $searchpicto = $form->showFilterButtons();
  381. print $searchpicto;
  382. print '</td>';
  383. print '</tr>';
  384. print '<tr class="liste_titre">';
  385. if (!empty($arrayfields['cr.date_sync']['checked'])) {
  386. print_liste_field_titre($arrayfields['cr.date_sync']['label'], $_SERVER["PHP_SELF"], "cr.date_sync", "", $param, "", $sortfield, $sortorder);
  387. }
  388. if (!empty($arrayfields['m.code']['checked'])) {
  389. print_liste_field_titre($arrayfields['m.code']['label'], $_SERVER["PHP_SELF"], "m.code", "", $param, "", $sortfield, $sortorder);
  390. }
  391. if (!empty($arrayfields['cr.rate']['checked'])) {
  392. print_liste_field_titre($arrayfields['cr.rate']['label'], $_SERVER["PHP_SELF"], "cr.rate", "", $param, "", $sortfield, $sortorder);
  393. }
  394. // Hook fields
  395. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  396. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  397. print $hookmanager->resPrint;
  398. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  399. print "</tr>\n";
  400. $i = 0;
  401. $totalarray = array();
  402. while ($i < min($num, $limit)) {
  403. $obj = $db->fetch_object($resql);
  404. print '<tr class="oddeven">';
  405. // USER REQUEST UPDATE FOR THIS LINE
  406. if ($action == "updateRate" && $obj->rowid == $id_rate_selected) {
  407. // var_dump($obj);
  408. print ' <td><input class="minwidth200" name="dateinput" value="'. date('Y-m-d', dol_stringtotime($obj->date_sync)) .'" type="date"></td>';
  409. print '<td>' . $form->selectMultiCurrency($obj->code, 'multicurrency_code', 1, " code != '".$conf->currency."'", true) . '</td>';
  410. print ' <td><input type="text" min ="0" step="any" class="minwidth200" name="rateinput" value="' . dol_escape_htmltag($obj->rate) . '"></td>';
  411. print '<td class="center nowrap ">';
  412. print '<input type="hidden" name="page" value="'.dol_escape_htmltag($page).'">';
  413. print '<input type="hidden" name="id_rate" value="'.dol_escape_htmltag($obj->rowid).'">';
  414. print '<button type="submit" class="button" name="action" value="update">'.$langs->trans("Modify").'</button>';
  415. print '<button type="submit" class="button" name="action" value="cancel">'.$langs->trans("Cancel").'</button>';
  416. print '</td>';
  417. } else {
  418. // date_sync
  419. if (!empty($arrayfields['cr.date_sync']['checked'])) {
  420. print '<td class="tdoverflowmax200">';
  421. print $obj->date_sync;
  422. print "</td>\n";
  423. if (!$i) $totalarray['nbfield']++;
  424. }
  425. // code
  426. if (!empty($arrayfields['m.code']['checked'])) {
  427. print '<td class="tdoverflowmax200">';
  428. print $obj->code;
  429. print ' - <span class="opacitymedium">'.$obj->name.'</span>';
  430. print "</td>\n";
  431. if (! $i) $totalarray['nbfield']++;
  432. }
  433. // rate
  434. if (!empty($arrayfields['cr.rate']['checked'])) {
  435. print '<td class="tdoverflowmax200">';
  436. print $obj->rate;
  437. print "</td>\n";
  438. if (! $i) $totalarray['nbfield']++;
  439. }
  440. // Fields from hook
  441. $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj);
  442. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  443. print $hookmanager->resPrint;
  444. // Action
  445. print '<td class="nowrap" align="center">';
  446. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  447. $selected = 0;
  448. if (in_array($obj->rowid, $arrayofselected)) {
  449. $selected = 1;
  450. }
  451. print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=updateRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('edit', 'edit').'</a>';
  452. print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=deleteRate&token='.newToken().'&id_rate='.$obj->rowid.'">'.img_picto('delete', 'delete').'</a>';
  453. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  454. }
  455. print '</td>';
  456. if (!$i) {
  457. $totalarray['nbfield']++;
  458. }
  459. print "</tr>\n";
  460. $i++;
  461. }
  462. }
  463. $db->free($resql);
  464. print "</table>";
  465. print "</div>";
  466. print '</form>';
  467. } else {
  468. dol_print_error($db);
  469. }
  470. llxFooter();
  471. $db->close();