|
@@ -593,6 +593,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|
|
$parameters = array();
|
|
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
|
|
$sql .= $hookmanager->resPrint;
|
|
|
+
|
|
|
+$sqlfields = $sql;
|
|
|
+
|
|
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
|
|
@@ -868,26 +871,26 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|
|
*/
|
|
|
/* 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);
|
|
|
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords', $sql);
|
|
|
} else {
|
|
|
- $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql);
|
|
|
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT( f.rowid) as nbtotalofrecords', $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);
|
|
|
- if ($resql) {
|
|
|
+ if (! $resql) {
|
|
|
+ dol_print_error($db);
|
|
|
+ } else {
|
|
|
$objforcount = $db->fetch_object($resql);
|
|
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
|
|
- } else {
|
|
|
- dol_print_error($db);
|
|
|
- }
|
|
|
|
|
|
- if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
|
|
- $page = 0;
|
|
|
- $offset = 0;
|
|
|
+ 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);
|
|
|
}
|
|
|
- $db->free($resql);
|
|
|
}
|
|
|
|
|
|
// Complete request and execute it with limit
|