diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 12eb7c573ce..3dc22b5a589 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -149,7 +149,6 @@ if ($object->fk_project > 0) { } - /* * Actions */ @@ -875,9 +874,11 @@ if ($action == 'confirm_generateinter') { } } + /* * View */ + $form = new Form($db); $formother = new FormOther($db); $formproject = new FormProjets($db); @@ -1304,7 +1305,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser if ($search_year > 0) { $param .= '&search_year='.urlencode($search_year); } - if ($search_user > 0) { + if (!empty($search_user)) { // We keep param if -1 because default value is forced to user id if not set $param .= '&search_user='.urlencode($search_user); } if ($search_task_ref != '') { @@ -1564,6 +1565,9 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql = preg_replace('/,\s*$/', '', $sql); + + $sqlfields = $sql; // $sql fields to remove for count total + $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet as il ON il.rowid = t.invoice_line_id"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as inv ON inv.rowid = il.fk_facture"; @@ -1657,39 +1661,42 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; - $sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $resql = $db->query($sql); - - if (! $resql) { + /* 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); - exit; } - $nbtotalofrecords = $db->num_rows($resql); - 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 than the paging size (filtering), goto and load page 0 $page = 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) { - $num = $nbtotalofrecords; - } else { + + // Complete request and execute it with limit + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { $sql .= $db->plimit($limit + 1, $offset); - - $resql = $db->query($sql); - if (!$resql) { - dol_print_error($db); - exit; - } - - $num = $db->num_rows($resql); } + $resql = $db->query($sql); + if (!$resql) { + dol_print_error($db); + exit; + } + + $num = $db->num_rows($resql); + if ($num >= 0) { if (!empty($projectidforalltimes)) { print ''."\n"; @@ -1870,6 +1877,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser print '
| '.$form->select_dolusers(($search_user > 0 ? $search_user : -1), 'search_user', 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250').' | '; + print ''.$form->select_dolusers(($search_user > 0 ? $search_user : -1), 'search_user', 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth150').' | '; } // Note if (!empty($arrayfields['t.note']['checked'])) { @@ -1977,54 +1985,72 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser } print '||||
| '; + print ' | '; if (($action == 'editline' || $action == 'splitline') && GETPOST('lineid', 'int') == $task_time->rowid) { print ''; print ''; @@ -2092,6 +2124,10 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser } } } + print ' | '; + if (!$i) { + $totalarray['nbfield']++; + } } // Date if (!empty($arrayfields['t.element_date']['checked'])) { @@ -2113,7 +2149,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser // Thirdparty if (!empty($arrayfields['p.fk_soc']['checked'])) { - print ''; + print ' | '; if ($task_time->fk_soc > 0) { if (empty($conf->cache['thridparty'][$task_time->fk_soc])) { $tmpsociete = new Societe($db); @@ -2132,7 +2168,6 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser // Thirdparty alias if (!empty($arrayfields['s.name_alias']['checked'])) { - print ' | '; if ($task_time->fk_soc > 0) { if (empty($conf->cache['thridparty'][$task_time->fk_soc])) { $tmpsociete = new Societe($db); @@ -2141,8 +2176,10 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser } else { $tmpsociete = $conf->cache['thridparty'][$task_time->fk_soc]; } - print $tmpsociete->name_alias; + $valtoshow = $tmpsociete->name_alias; } + print ' | '; + print $valtoshow; print ' | '; if (!$i) { $totalarray['nbfield']++; @@ -2309,6 +2346,9 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser } } print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Value spent @@ -2422,10 +2462,10 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser } } } - } - print ''; - if (!$i) { - $totalarray['nbfield']++; + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } print "'.$langs->trans("Total").' | '; } else { - print ''.$langs->trans("Totalforthispage").' | '; + print ''.$form->textwithpicto($langs->trans("Total"), $langs->trans("Totalforthispage")).' | '; } } elseif ($totalarray['totaldurationfield'] == $i) { print ''.convertSecondToTime($totalarray['totalduration'], 'allhourmin').' | ';