function _tasks(&$db, $id_project, $status, $onlyUseGrid = false)
{
    global $hookmanager, $conf;
    $hookmanager->initHooks(array('scrumboardgettasks'));
    $sql = "SELECT t.rowid,t.fk_task_parent, t.grid_col,t.grid_row,ex.fk_workstation,ex.needed_ressource,p.datee as 'project_date_end', t.note_private\n\t\tFROM " . MAIN_DB_PREFIX . "projet_task t\n\t\tLEFT JOIN " . MAIN_DB_PREFIX . "projet p ON (t.fk_projet=p.rowid)\n\t\tLEFT JOIN " . MAIN_DB_PREFIX . "projet_task_extrafields ex ON (t.rowid=ex.fk_object) ";
    $sqlwhere = array();
    $sqlorder = '';
    if (empty($conf->global->SCRUM_SHOW_TASK_WITHOUT_DURATION)) {
        $sqlwhere[] = " t.planned_workload>0 ";
    }
    if ($status == 'ideas') {
        $sqlwhere[] = " t.progress=0 AND t.datee IS NULL";
    } else {
        if ($status == 'todo') {
            $sqlwhere[] = " t.progress=0";
        } else {
            if ($status == 'inprogress|todo') {
                $sqlwhere[] = " t.progress>=0 AND t.progress<100";
            } else {
                if ($status == 'inprogress') {
                    $sqlwhere[] = " t.progress>0 AND t.progress<100";
                } else {
                    if ($status == 'finish') {
                        $sqlwhere[] = " t.progress=100";
                    }
                }
            }
        }
    }
    if ($id_project) {
        $sqlwhere[] = " t.fk_projet=" . $id_project;
    } else {
        $sqlwhere[] = " p.fk_statut IN (0,1)";
    }
    if ($onlyUseGrid) {
        $sqlwhere[] = " ex.grid_use=1 ";
        if (empty($conf->global->SCRUM_SHOW_TASK_WITHOUT_DURATION)) {
            $sqlwhere[] = " t.planned_workload>0 ";
        }
        $sqlorder = " ORDER BY t.grid_row";
    } else {
        $sqlorder = " ORDER BY rang";
    }
    if (count($sqlwhere) > 0) {
        $sql .= " WHERE " . implode(' AND ', $sqlwhere);
    }
    if (!empty($sqlorder)) {
        $sql .= $sqlorder;
    }
    $parameters = array('action' => '_tasks_before_exec_sql', 'sql' => &$sql, 'status' => $status, 'fk_project' => $id_project, 'onlyUseGrid' => $onlyUseGrid);
    $reshook = $hookmanager->executeHooks('doScrumActions', $parameters);
    $res = $db->query($sql);
    $TTask = array();
    if ($res) {
        while ($obj = $db->fetch_object($res)) {
            $TTask[] = array_merge(_task($db, $obj->rowid), array('status' => $status, 'grid_col' => $obj->grid_col, 'grid_row' => $obj->grid_row, 'fk_workstation' => (int) $obj->fk_workstation, 'fk_task_parent' => (int) $obj->fk_task_parent, 'needed_ressource' => $obj->needed_ressource ? $obj->needed_ressource : 1, 'project_date_end' => strtotime($obj->project_date_end)));
        }
    }
    return $TTask;
}
function _tasks(&$db, $id_project, $status, $onlyUseGrid = false)
{
    $sql = "SELECT t.rowid,t.fk_task_parent, t.grid_col,t.grid_row,ex.fk_workstation,ex.needed_ressource,p.datee as 'project_date_end', t.note_private\n\t\tFROM " . MAIN_DB_PREFIX . "projet_task t \n\t\tLEFT JOIN " . MAIN_DB_PREFIX . "projet p ON (t.fk_projet=p.rowid)\n\t\tLEFT JOIN " . MAIN_DB_PREFIX . "projet_task_extrafields ex ON (t.rowid=ex.fk_object) ";
    if ($status == 'ideas') {
        $sql .= " WHERE t.progress=0 AND t.datee IS NULL";
    } else {
        if ($status == 'todo') {
            $sql .= " WHERE t.progress=0";
        } else {
            if ($status == 'inprogress|todo') {
                $sql .= " WHERE t.progress>=0 AND t.progress<100";
            } else {
                if ($status == 'inprogress') {
                    $sql .= " WHERE t.progress>0 AND t.progress<100";
                } else {
                    if ($status == 'finish') {
                        $sql .= " WHERE t.progress=100 \n\t\t";
                    }
                }
            }
        }
    }
    if ($id_project) {
        $sql .= " AND t.fk_projet=" . $id_project;
    } else {
        $sql .= " AND p.fk_statut IN (0,1)";
    }
    if ($onlyUseGrid) {
        $sql .= " AND ex.grid_use=1 AND t.planned_workload>0\n\t    ORDER BY t.grid_row";
    } else {
        $sql .= " ORDER BY rang";
    }
    $res = $db->query($sql);
    $TTask = array();
    while ($obj = $db->fetch_object($res)) {
        $TTask[] = array_merge(_task($db, $obj->rowid), array('status' => $status, 'grid_col' => $obj->grid_col, 'grid_row' => $obj->grid_row, 'fk_workstation' => (int) $obj->fk_workstation, 'fk_task_parent' => (int) $obj->fk_task_parent, 'needed_ressource' => $obj->needed_ressource ? $obj->needed_ressource : 1, 'project_date_end' => strtotime($obj->project_date_end)));
    }
    return $TTask;
}