Merge pull request #23009 from atm-maxime/fix_count_in_lists
Fix count in lists
This commit is contained in:
commit
e77aa31e47
@ -346,6 +346,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
|
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
|
||||||
if (!empty($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (!empty($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
|
||||||
@ -480,9 +483,13 @@ $sql .= $hookmanager->resPrint;
|
|||||||
// Count total nb of records with no order and no limits
|
// Count total nb of records with no order and no limits
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$resql = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
} else {
|
} else {
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -216,6 +216,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
||||||
@ -297,21 +300,18 @@ $sql .= !empty($hookmanager->resPrint) ? (" HAVING 1=1 " . $hookmanager->resPrin
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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.
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
|
||||||
*/
|
|
||||||
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
|
||||||
/*$resql = $db->query($sql, 0, 'auto', 1);
|
|
||||||
while ($db->fetch_object($resql)) {
|
|
||||||
$nbtotalofrecords++;
|
|
||||||
}*/
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -305,6 +305,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
||||||
@ -378,22 +381,29 @@ $sql.=$hookmanager->resPrint;
|
|||||||
$sql=preg_replace('/,\s*$/','', $sql);
|
$sql=preg_replace('/,\s*$/','', $sql);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$resql = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
|
|
||||||
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
|
// Complete request and execute it with limit
|
||||||
$num = $nbtotalofrecords;
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
} else {
|
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
@ -405,7 +415,6 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit
|
|||||||
}
|
}
|
||||||
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
}
|
|
||||||
|
|
||||||
// Direct jump if only one record found
|
// Direct jump if only one record found
|
||||||
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
||||||
|
|||||||
@ -105,6 +105,9 @@ llxHeader('', $title);
|
|||||||
|
|
||||||
$sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
|
$sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
|
||||||
$sql .= " u.login, u.lastname, u.firstname";
|
$sql .= " u.login, u.lastname, u.firstname";
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
|
$sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
|
||||||
$sql .= " WHERE 1=1";
|
$sql .= " WHERE 1=1";
|
||||||
$sql .= " AND b.entity IN (".getEntity('bookmark').")";
|
$sql .= " AND b.entity IN (".getEntity('bookmark').")";
|
||||||
@ -116,7 +119,8 @@ if (!$user->admin) {
|
|||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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 */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
@ -125,7 +129,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -427,6 +427,8 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
|
$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_extrafields as ef ON (a.id = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_extrafields as ef ON (a.id = ef.fk_object)";
|
||||||
if (empty($user->rights->societe->client->voir) && !$socid) {
|
if (empty($user->rights->societe->client->voir) && !$socid) {
|
||||||
@ -563,21 +565,18 @@ $sql .= $hookmanager->resPrint;
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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.
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
|
||||||
*/
|
|
||||||
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
|
||||||
/*$resql = $db->query($sql, 0, 'auto', 1);
|
|
||||||
while ($db->fetch_object($resql)) {
|
|
||||||
$nbtotalofrecords++;
|
|
||||||
}*/
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -585,6 +585,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
$sql = preg_replace('/, $/', '', $sql);
|
$sql = preg_replace('/, $/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
$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_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)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
|
||||||
@ -796,13 +799,22 @@ $sql .= ', p.ref DESC';
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -825,6 +825,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
|
||||||
@ -1048,13 +1051,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -195,6 +195,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
|
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
|
||||||
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)";
|
||||||
@ -257,8 +260,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
|
$page = 0;
|
||||||
|
$offset = 0;
|
||||||
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -213,6 +213,9 @@ if ($arrayfields['account']['checked']) {
|
|||||||
$sql = "SELECT v.rowid, v.sens, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank, v.accountancy_code, v.subledger_account, v.fk_projet as fk_project,";
|
$sql = "SELECT v.rowid, v.sens, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank, v.accountancy_code, v.subledger_account, v.fk_projet as fk_project,";
|
||||||
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,";
|
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,";
|
||||||
$sql .= " pst.code as payment_code";
|
$sql .= " pst.code as payment_code";
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
|
$sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
|
||||||
@ -265,11 +268,27 @@ if ($search_all) {
|
|||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|
||||||
$totalnboflines = 0;
|
// Count total nb of records
|
||||||
$resql = $db->query($sql);
|
$nbtotalofrecords = '';
|
||||||
|
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 */
|
||||||
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$totalnboflines = $db->num_rows($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
|
$page = 0;
|
||||||
|
$offset = 0;
|
||||||
|
}
|
||||||
|
$db->free($resql);
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
@ -355,7 +374,7 @@ if ($resql) {
|
|||||||
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
||||||
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
|
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
|
||||||
|
|
||||||
print_barre_liste($langs->trans("MenuVariousPayment"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
|
print_barre_liste($langs->trans("MenuVariousPayment"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
|
||||||
|
|
||||||
if ($search_all) {
|
if ($search_all) {
|
||||||
foreach ($fieldstosearchall as $key => $val) {
|
foreach ($fieldstosearchall as $key => $val) {
|
||||||
|
|||||||
@ -597,6 +597,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
|
||||||
@ -911,21 +914,12 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
|
$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
|
||||||
|
|
||||||
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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);
|
|
||||||
*/
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
if ($sall || $search_user > 0) {
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql);
|
|
||||||
} else {
|
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', '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);
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
@ -934,7 +928,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
@ -942,13 +936,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Complete request and execute it with limit
|
// Complete request and execute it with limit
|
||||||
$sql .= ' ORDER BY ';
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
$listfield = explode(',', $sortfield);
|
|
||||||
$listorder = explode(',', $sortorder);
|
|
||||||
foreach ($listfield as $key => $value) {
|
|
||||||
$sql .= $listfield[$key].' '.($listorder[$key] ? $listorder[$key] : 'DESC').',';
|
|
||||||
}
|
|
||||||
$sql .= ' f.rowid DESC ';
|
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ if (!$sortorder) {
|
|||||||
$sortorder = "DESC";
|
$sortorder = "DESC";
|
||||||
}
|
}
|
||||||
if (!$sortfield) {
|
if (!$sortfield) {
|
||||||
$sortfield = "dp";
|
$sortfield = "bc.date_bordereau";
|
||||||
}
|
}
|
||||||
|
|
||||||
$year = GETPOST("year");
|
$year = GETPOST("year");
|
||||||
@ -94,9 +94,12 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
|
|||||||
|
|
||||||
llxHeader('', $langs->trans("ChequesReceipts"));
|
llxHeader('', $langs->trans("ChequesReceipts"));
|
||||||
|
|
||||||
$sql = "SELECT bc.rowid, bc.ref as ref, bc.date_bordereau as dp,";
|
$sql = "SELECT bc.rowid, bc.ref, bc.date_bordereau,";
|
||||||
$sql .= " bc.nbcheque, bc.amount, bc.statut,";
|
$sql .= " bc.nbcheque, bc.amount, bc.statut,";
|
||||||
$sql .= " ba.rowid as bid, ba.label";
|
$sql .= " ba.rowid as bid, ba.label";
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc,";
|
$sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc,";
|
||||||
$sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
|
$sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
|
||||||
$sql .= " WHERE bc.fk_bank_account = ba.rowid";
|
$sql .= " WHERE bc.fk_bank_account = ba.rowid";
|
||||||
@ -116,14 +119,25 @@ $sql .= dolSqlDateFilter('bc.date_bordereau', 0, $month, $year);
|
|||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|
||||||
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
@ -193,7 +207,7 @@ if ($resql) {
|
|||||||
|
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "bc.ref", "", $param, "", $sortfield, $sortorder);
|
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "bc.ref", "", $param, "", $sortfield, $sortorder);
|
||||||
print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "dp", "", $param, 'align="center"', $sortfield, $sortorder);
|
print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "bc.date_bordereau", "", $param, 'align="center"', $sortfield, $sortorder);
|
||||||
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
|
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
|
||||||
print_liste_field_titre("NbOfCheques", $_SERVER["PHP_SELF"], "bc.nbcheque", "", $param, 'class="right"', $sortfield, $sortorder);
|
print_liste_field_titre("NbOfCheques", $_SERVER["PHP_SELF"], "bc.nbcheque", "", $param, 'class="right"', $sortfield, $sortorder);
|
||||||
print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
|
print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
|
||||||
@ -216,7 +230,7 @@ if ($resql) {
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// Date
|
// Date
|
||||||
print '<td class="center">'.dol_print_date($db->jdate($objp->dp), 'day').'</td>'; // TODO Use date hour
|
print '<td class="center">'.dol_print_date($db->jdate($objp->date_bordereau), 'day').'</td>'; // TODO Use date hour
|
||||||
|
|
||||||
// Bank
|
// Bank
|
||||||
print '<td>';
|
print '<td>';
|
||||||
|
|||||||
@ -195,6 +195,9 @@ if (GETPOST("orphelins", "alpha")) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
|
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
|
||||||
@ -257,16 +260,25 @@ if (GETPOST("orphelins", "alpha")) {
|
|||||||
}
|
}
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|
||||||
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
// if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
if (($page * $limit) > $nbtotalofrecords) {
|
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -112,6 +112,9 @@ $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec";
|
|||||||
$sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
|
$sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
|
||||||
$sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email";
|
$sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email";
|
||||||
$sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
|
$sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
|
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
|
||||||
$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
|
$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
|
||||||
$sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
|
$sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
|
||||||
@ -157,12 +160,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -97,6 +97,9 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
|
|||||||
llxHeader('', $langs->trans("WithdrawalsReceipts"));
|
llxHeader('', $langs->trans("WithdrawalsReceipts"));
|
||||||
|
|
||||||
$sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
|
$sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
|
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
|
||||||
$sql .= " WHERE p.entity IN (".getEntity('invoice').")";
|
$sql .= " WHERE p.entity IN (".getEntity('invoice').")";
|
||||||
if ($type == 'bank-transfer') {
|
if ($type == 'bank-transfer') {
|
||||||
@ -116,12 +119,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -194,6 +194,9 @@ if (isModEnabled('project')) {
|
|||||||
$sql .= " c.libelle as type_label, c.accountancy_code as type_accountancy_code,";
|
$sql .= " c.libelle as type_label, c.accountancy_code as type_accountancy_code,";
|
||||||
$sql .= " ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,";
|
$sql .= " ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,";
|
||||||
$sql .= " SUM(pc.amount) as alreadypayed, pay.code as payment_code";
|
$sql .= " SUM(pc.amount) as alreadypayed, pay.code as payment_code";
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
|
||||||
$sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
|
$sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (cs.fk_account = ba.rowid)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (cs.fk_account = ba.rowid)";
|
||||||
@ -253,11 +256,27 @@ if (isModEnabled('project')) {
|
|||||||
}
|
}
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|
||||||
$totalnboflines = 0;
|
// Count total nb of records
|
||||||
$result = $db->query($sql);
|
$nbtotalofrecords = '';
|
||||||
if ($result) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$totalnboflines = $db->num_rows($result);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
|
$page = 0;
|
||||||
|
$offset = 0;
|
||||||
|
}
|
||||||
|
$db->free($resql);
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
@ -363,7 +382,7 @@ print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
|
|||||||
|
|
||||||
$center = '';
|
$center = '';
|
||||||
|
|
||||||
print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
|
print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $nbtotalofrecords, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
|
||||||
|
|
||||||
if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
|
if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
|
||||||
print '<div class="error">';
|
print '<div class="error">';
|
||||||
|
|||||||
@ -150,6 +150,9 @@ $sql = 'SELECT t.rowid, t.amount, t.label, t.datev, t.datep, t.paye, t.fk_typepa
|
|||||||
$sql.= ' ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,';
|
$sql.= ' ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,';
|
||||||
$sql.= ' t.num_payment, pst.code as payment_code,';
|
$sql.= ' t.num_payment, pst.code as payment_code,';
|
||||||
$sql .= ' SUM(ptva.amount) as alreadypayed';
|
$sql .= ' SUM(ptva.amount) as alreadypayed';
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'tva as t';
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'tva as t';
|
||||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pst ON (t.fk_typepayment = pst.id)';
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pst ON (t.fk_typepayment = pst.id)';
|
||||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON (t.fk_account = ba.rowid)';
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON (t.fk_account = ba.rowid)';
|
||||||
@ -190,16 +193,25 @@ if ($search_status != '' && $search_status >= 0) {
|
|||||||
$sql .= " GROUP BY t.rowid, t.amount, t.label, t.datev, t.datep, t.paye, t.fk_typepayment, t.fk_account, ba.label, ba.ref, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, t.num_payment, pst.code";
|
$sql .= " GROUP BY t.rowid, t.amount, t.label, t.datev, t.datep, t.paye, t.fk_typepayment, t.fk_account, ba.label, ba.ref, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, t.num_payment, pst.code";
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|
||||||
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$resql = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
// if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
if (($page * $limit) > $nbtotalofrecords) {
|
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -392,6 +392,9 @@ if (isModEnabled('mailing')) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
|
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
|
||||||
@ -634,12 +637,22 @@ if ($view == "recent") {
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$resql = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -284,6 +284,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
|
$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
|
||||||
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
|
||||||
@ -450,12 +453,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
|
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -285,6 +285,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d";
|
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
|
||||||
@ -345,12 +348,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -251,6 +251,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
|
$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
|
||||||
if (isModEnabled('project')) {
|
if (isModEnabled('project')) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr on f.fk_projet = pr.rowid";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr on f.fk_projet = pr.rowid";
|
||||||
@ -324,20 +327,18 @@ $sql .= $hookmanager->resPrint;
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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. */
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
/*$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
} else {
|
} else {
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -774,6 +774,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$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_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)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
|
||||||
@ -956,12 +959,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -435,6 +435,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
$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_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)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
|
||||||
@ -701,14 +704,25 @@ $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPri
|
|||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|
||||||
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -160,6 +160,9 @@ if ($reshook < 0) {
|
|||||||
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
}
|
}
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
|
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
|
||||||
if ($catid) {
|
if ($catid) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
||||||
@ -196,15 +199,25 @@ $sql .= $hookmanager->resPrint;
|
|||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|
||||||
// Count total nb of records without orderby and limit
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -304,6 +304,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
|
$sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cp.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cp.rowid = ef.fk_object)";
|
||||||
@ -361,12 +364,22 @@ $sql .= $db->order($sortfield, $sortorder);
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
|||||||
@ -107,8 +107,13 @@ $title = $langs->trans('Loans');
|
|||||||
|
|
||||||
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
|
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
|
||||||
$sql .= " SUM(pl.amount_capital) as alreadypaid";
|
$sql .= " SUM(pl.amount_capital) as alreadypaid";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl";
|
|
||||||
$sql .= " ON l.rowid = pl.fk_loan";
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
|
$sql .= " FROM ".MAIN_DB_PREFIX."loan as l";
|
||||||
|
$linktopl = " LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl ON l.rowid = pl.fk_loan";
|
||||||
|
$sql .= $linktopl;
|
||||||
|
|
||||||
$sql .= " WHERE l.entity = ".$conf->entity;
|
$sql .= " WHERE l.entity = ".$conf->entity;
|
||||||
if ($search_amount) {
|
if ($search_amount) {
|
||||||
$sql .= natural_search("l.capital", $search_amount, 1);
|
$sql .= natural_search("l.capital", $search_amount, 1);
|
||||||
@ -120,23 +125,31 @@ if ($search_label) {
|
|||||||
$sql .= natural_search("l.label", $search_label);
|
$sql .= natural_search("l.label", $search_label);
|
||||||
}
|
}
|
||||||
$sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
|
$sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$resql = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
$sqlforcount = preg_replace('/'.preg_quote($linktopl, '/').'/', '', $sqlforcount);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
|
// Complete request and execute it with limit
|
||||||
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
$num = $nbtotalofrecords;
|
|
||||||
} else {
|
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
@ -148,7 +161,6 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit
|
|||||||
}
|
}
|
||||||
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
}
|
|
||||||
|
|
||||||
// Output page
|
// Output page
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|||||||
@ -282,6 +282,9 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $obje
|
|||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
//$sql .= ", COUNT(rc.rowid) as anotherfield";
|
//$sql .= ", COUNT(rc.rowid) as anotherfield";
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
||||||
//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
|
//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
@ -364,21 +367,9 @@ $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPri
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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.
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
|
||||||
*/
|
|
||||||
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
|
||||||
/*$resql = $db->query($sql, 0, 'auto', 1);
|
|
||||||
while ($db->fetch_object($resql)) {
|
|
||||||
if (empty($nbtotalofrecords)) {
|
|
||||||
$nbtotalofrecords = 1; // We can't make +1 because init value is ''
|
|
||||||
} else {
|
|
||||||
$nbtotalofrecords++;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
@ -387,7 +378,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -229,6 +229,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
||||||
@ -314,22 +317,29 @@ $sql.=$hookmanager->resPrint;
|
|||||||
$sql=preg_replace('/,\s*$/','', $sql);
|
$sql=preg_replace('/,\s*$/','', $sql);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$resql = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
|
|
||||||
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
|
// Complete request and execute it with limit
|
||||||
$num = $nbtotalofrecords;
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
} else {
|
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
@ -341,7 +351,6 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit
|
|||||||
}
|
}
|
||||||
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
}
|
|
||||||
|
|
||||||
// Direct jump if only one record found
|
// Direct jump if only one record found
|
||||||
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
||||||
|
|||||||
@ -224,6 +224,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
||||||
@ -322,22 +325,29 @@ $sql.=$hookmanager->resPrint;
|
|||||||
$sql=preg_replace('/,\s*$/','', $sql);
|
$sql=preg_replace('/,\s*$/','', $sql);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
/// Count total nb of records
|
||||||
|
|
||||||
// Count total nb of records
|
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$resql = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
|
|
||||||
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
|
// Complete request and execute it with limit
|
||||||
$num = $nbtotalofrecords;
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
} else {
|
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
@ -349,7 +359,6 @@ if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit
|
|||||||
}
|
}
|
||||||
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
}
|
|
||||||
|
|
||||||
// Direct jump if only one record found
|
// Direct jump if only one record found
|
||||||
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
||||||
|
|||||||
@ -621,6 +621,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete request and execute it with limit
|
// Complete request and execute it with limit
|
||||||
|
|||||||
@ -619,6 +619,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
|
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
|
||||||
$sql .= " ".MAIN_DB_PREFIX."product as p,";
|
$sql .= " ".MAIN_DB_PREFIX."product as p,";
|
||||||
$sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m";
|
$sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m";
|
||||||
@ -690,24 +693,22 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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.
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
|
||||||
*/
|
|
||||||
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
|
||||||
/*$resql = $db->query($sql, 0, 'auto', 1);
|
|
||||||
while ($db->fetch_object($resql)) {
|
|
||||||
$nbtotalofrecords++;
|
|
||||||
}*/
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -531,6 +531,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
|
$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
|
||||||
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
|
||||||
@ -614,8 +617,22 @@ $sql .= $hookmanager->resPrint;
|
|||||||
|
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
|
$page = 0;
|
||||||
|
$offset = 0;
|
||||||
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
|||||||
@ -488,6 +488,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s.parent = s2.rowid";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s.parent = s2.rowid";
|
||||||
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
@ -723,14 +726,9 @@ $sql .= $hookmanager->resPrint;
|
|||||||
// Count total nb of records with no order and no limits
|
// Count total nb of records with no order and no limits
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
/*$resql = $db->query($sql);
|
|
||||||
if ($resql) {
|
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
|
||||||
} else {
|
|
||||||
dol_print_error($db);
|
|
||||||
}*/
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
|||||||
@ -353,6 +353,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
|
||||||
@ -458,11 +461,17 @@ $sql .= $hookmanager->resPrint;
|
|||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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 */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
} else {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -373,6 +373,9 @@ $parameters = array();
|
|||||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
|
||||||
$sql = preg_replace('/,\s*$/', '', $sql);
|
$sql = preg_replace('/,\s*$/', '', $sql);
|
||||||
|
|
||||||
|
$sqlfields = $sql; // $sql fields to remove for count total
|
||||||
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as u";
|
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as u";
|
||||||
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (u.rowid = ef.fk_object)";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (u.rowid = ef.fk_object)";
|
||||||
@ -481,21 +484,9 @@ $sql .= $hookmanager->resPrint;
|
|||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
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.
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
|
||||||
*/
|
|
||||||
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
|
||||||
/*$resql = $db->query($sql, 0, 'auto', 1);
|
|
||||||
while ($db->fetch_object($resql)) {
|
|
||||||
if (empty($nbtotalofrecords)) {
|
|
||||||
$nbtotalofrecords = 1; // We can't make +1 because init value is ''
|
|
||||||
} else {
|
|
||||||
$nbtotalofrecords++;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
@ -504,7 +495,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user