diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php
index ff1bdbc07f9..0e78eec6422 100644
--- a/htdocs/projet/class/task.class.php
+++ b/htdocs/projet/class/task.class.php
@@ -812,9 +812,11 @@ class Task extends CommonObjectLine
* @param array $search_array_options Array of search
* @param int $loadextras Fetch all Extrafields on each task
* @param int $loadRoleMode 1= will test Roles on task; 0 used in delete project action
+ * @param string $sortfield Sort field
+ * @param string $sortorder Sort order
* @return array Array of tasks
*/
- public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj = '', $filteronprojstatus = '-1', $morewherefilter = '', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = array(), $includebilltime = 0, $search_array_options = array(), $loadextras = 0, $loadRoleMode = 1)
+ public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj = '', $filteronprojstatus = '-1', $morewherefilter = '', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = array(), $includebilltime = 0, $search_array_options = array(), $loadextras = 0, $loadRoleMode = 1, $sortfield = '', $sortorder = '')
{
global $conf, $hookmanager;
@@ -954,8 +956,11 @@ class Task extends CommonObjectLine
}
}
-
- $sql .= " ORDER BY p.ref, t.rang, t.dateo";
+ if ($sortfield && $sortorder) {
+ $sql .= $this->db->order($sortfield, $sortorder);
+ } else {
+ $sql .= " ORDER BY p.ref, t.rang, t.dateo";
+ }
//print $sql;exit;
dol_syslog(get_class($this)."::getTasksArray", LOG_DEBUG);
diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php
index d3097631a6f..628056f610f 100644
--- a/htdocs/projet/tasks.php
+++ b/htdocs/projet/tasks.php
@@ -124,12 +124,12 @@ $search_array_options = $extrafields->getOptionalsFromPost($taskstatic->table_el
// Default sort order (if not yet defined by previous GETPOST)
-if (!$sortfield) {
+/* if (!$sortfield) {
reset($object->fields); $sortfield="t.".key($object->fields);
} // Set here default search field. By default 1st field in definition. Reset is required to avoid key() to return null.
if (!$sortorder) {
$sortorder = "ASC";
-}
+} */
// Security check
@@ -854,7 +854,7 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third
// Get list of tasks in tasksarray and taskarrayfiltered
// We need all tasks (even not limited to a user because a task to user can have a parent that is not affected to him).
$filteronthirdpartyid = $socid;
- $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0, '', -1, $morewherefilter, 0, 0, $extrafields, 1, $search_array_options);
+ $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0, '', -1, $morewherefilter, 0, 0, $extrafields, 1, $search_array_options, 0, 1, $sortfield, $sortorder);
// We load also tasks limited to a particular user
$tmpuser = new User($db);
@@ -1004,41 +1004,41 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third
print '
';
// print '| '.$langs->trans("Project").' | ';
if (!empty($arrayfields['t.ref']['checked'])) {
- print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '');
+ print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], 't.ref', '', $param, '', $sortfield, $sortorder, '');
}
if (!empty($arrayfields['t.label']['checked'])) {
- print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
+ print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER["PHP_SELF"], "t.label", '', $param, '', $sortfield, $sortorder, '');
}
if (!empty($arrayfields['t.description']['checked'])) {
print_liste_field_titre($arrayfields['t.description']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
}
if (!empty($arrayfields['t.dateo']['checked'])) {
- print_liste_field_titre($arrayfields['t.dateo']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
+ print_liste_field_titre($arrayfields['t.dateo']['label'], $_SERVER["PHP_SELF"], "t.dateo", '', $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['t.datee']['checked'])) {
- print_liste_field_titre($arrayfields['t.datee']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
+ print_liste_field_titre($arrayfields['t.datee']['label'], $_SERVER["PHP_SELF"], "t.datee", '', $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['t.planned_workload']['checked'])) {
- print_liste_field_titre($arrayfields['t.planned_workload']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
+ print_liste_field_titre($arrayfields['t.planned_workload']['label'], $_SERVER["PHP_SELF"], "t.planned_workload", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
}
if (!empty($arrayfields['t.duration_effective']['checked'])) {
- print_liste_field_titre($arrayfields['t.duration_effective']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
+ print_liste_field_titre($arrayfields['t.duration_effective']['label'], $_SERVER["PHP_SELF"], "t.duration_effective", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
}
if (!empty($arrayfields['t.progress_calculated']['checked'])) {
print_liste_field_titre($arrayfields['t.progress_calculated']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
}
if (!empty($arrayfields['t.progress']['checked'])) {
- print_liste_field_titre($arrayfields['t.progress']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
+ print_liste_field_titre($arrayfields['t.progress']['label'], $_SERVER["PHP_SELF"], "t.progress", '', $param, '', $sortfield, $sortorder, 'right ', '', 1);
}
if (!empty($arrayfields['t.progress_summary']['checked'])) {
print_liste_field_titre($arrayfields['t.progress_summary']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ', '', 1);
}
if ($object->usage_bill_time) {
if (!empty($arrayfields['t.tobill']['checked'])) {
- print_liste_field_titre($arrayfields['t.tobill']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
+ print_liste_field_titre($arrayfields['t.tobill']['label'], $_SERVER["PHP_SELF"], "t.tobill", '', $param, '', $sortfield, $sortorder, 'right ');
}
if (!empty($arrayfields['t.billed']['checked'])) {
- print_liste_field_titre($arrayfields['t.billed']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
+ print_liste_field_titre($arrayfields['t.billed']['label'], $_SERVER["PHP_SELF"], "t.billed", '', $param, '', $sortfield, $sortorder, 'right ');
}
}
// Contacts of task, disabled because available by default jsut after
@@ -1049,7 +1049,7 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third
*/
if (!empty($arrayfields['t.budget_amount']['checked'])) {
- print_liste_field_titre($arrayfields['t.budget_amount']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'center ');
+ print_liste_field_titre($arrayfields['t.budget_amount']['label'], $_SERVER["PHP_SELF"], "t.budget_amount", "", $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['c.assigned']['checked'])) {