multicurrency_rate.php 21 KB

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