multicurrency_rate.php 21 KB

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