diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index b0444b90dcc..8ca3272dd78 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -65,7 +65,7 @@ $hookmanager->initHooks(array('bankcard', 'globalcard')); // Security check $id = GETPOST("id", 'int') ? GETPOST("id", 'int') : GETPOST('ref', 'alpha'); -$fieldid = GETPOST("id") ? 'rowid' : 'ref'; +$fieldid = GETPOST("id", 'int') ? 'rowid' : 'ref'; $result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 02c0ec21e7a..06da94e8e2b 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -856,12 +856,28 @@ $sql .= ' f.rowid DESC '; $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + /* This old and fast method to get and count full list returns all record so use a high amount of memory. $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 + */ + /* The fast and low memory method to get and count full list converts the sql into a sql count */ + if ($sall || $search_product_category > 0 || $search_user > 0) { + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql); + } else { + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid/', '', $sqlforcount); + } + $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount); + + $resql = $db->query($sqlforcount); + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 $page = 0; $offset = 0; } + $db->free($resql); } $sql .= $db->plimit($limit + 1, $offset);