vid, array(-1 => _('unassigned'))); $opt_priority = db_load_enum('task', 'priority', true, true); $opt_state = db_load_enum('task', 'taskstate', true, true); // ========== ACTIONS START =================================================== switch ($submit = form_get_action()) { case NULL: break; case 'add': $action = ACT_ADD; break; case 'view': $action = ACT_VIEW; break; case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; case 'filter': $flt = array(); $flt['prio'] = gpc_get_enum($_POST, 'flt_prio', array_merge(array_keys($opt_priority), ['-2', '-1'])); $flt['stat'] = gpc_get_enum($_POST, 'flt_stat', array_merge(array_keys($opt_state), ['-2', '-1'])); $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); db_save_filter($flt, 206); $action = ACT_DEFAULT; break; case 'freset': db_clear_filter(206); $action = ACT_DEFAULT; break; case 'insert': $p[':vid'] = $user->vid; $p[':projid'] = gpc_get_int($_POST, 'projid'); if ($p[':projid'] == -1) { $p[':projid'] = NULL; } $p[':taskname'] = gpc_get_string($_POST, 'taskname'); $p[':responsible'] = $user->id; $id = db_exec_insert('task', $p); $action = ACT_VIEW; break; case 'update': $p[':taskid'] = $id; $p[':projid'] = gpc_get_int($_POST, 'projid'); $p[':plandate'] = gpc_get_date($_POST, 'plandate'); $p[':duedate'] = gpc_get_date($_POST, 'duedate'); if ($p[':projid'] == -1) { $p[':projid'] = NULL; } $p[':taskname'] = gpc_get_string($_POST, 'taskname'); $p[':priority'] = gpc_get_string($_POST, 'priority', 10); if ($p[':priority'] == '-1') { $p[':priority'] = NULL; } $p[':started'] = gpc_get_datetime($_POST, 'started'); $p[':finished'] = gpc_get_datetime($_POST, 'finished'); $p[':taskstate'] = gpc_get_enum($_POST, 'taskstate', array_keys($opt_state)); $p[':responsible'] = gpc_get_int($_POST, 'responsible'); db_exec_update('task', $p, 'taskid'); $action = ACT_VIEW; break; case 'delete': // Only captain is allowed to delete if ($user->role != 'captain') { $g_warning->Add('Only captain is allowed to delete tasks.'); $action = ACT_VIEW; break; } // Security token needed! if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) { $g_error->Add(_('Delete prohibited, invalid security token!')); $action = ACT_VIEW; break; } unset($_SESSION['token']); // get information for possible redirect $sth = $pdo->prepare("SELECT projid FROM task WHERE taskid=?"); $sth->execute([$id]); $task = $sth->fetch(PDO::FETCH_OBJ); if (isset($task->projid)) { $backlink = 'project.php?id='.$task->projid; } // now really delete $sth = $pdo->prepare("DELETE FROM task WHERE taskid=?"); $sth->execute([$id]); $g_success->Add(_('Task deleted')); if (isset($backlink)) { header_location($backlink, ['info' => _('Note deleted.')]); } $action = ACT_DEFAULT; break; default: $g_error->Add(sprintf(_("Unknown function '%s'!"), $submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== require 'header.php'; // ========== PAGE CONTENT ==================================================== if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= page_caption_search($pagetitle); // load filter from db $flt = db_get_filter($user->id, 206, ['txt','prio', 'stat']); $w = array('(t.vid=:vid OR t.vid IS NULL)'); $p = array(':vid' => $user->vid); if (strlen($flt->txt) > 1) { $w[] = '(taskname LIKE :txt)'; $p[':txt'] = '%'.$flt->txt.'%'; } if (strlen($flt->prio) > 2 ) { $w[] = 'priority=:priority'; $p[':priority'] = $flt->prio; } elseif ($flt->prio == -1) { $w[] = 'priority IS NULL'; } if (strlen($flt->stat) > 2 ) { $w[] = 'taskstate=:taskstate'; $p[':taskstate'] = $flt->stat; } $where = join(' AND ', $w); $order = ' ORDER BY t.taskid'; // get total recond count for pagination and limit $sql = "SELECT COUNT(*) FROM task AS t"; if ($where) $sql .= " WHERE $where"; $sth = $pdo->prepare($sql); try { $sth->execute($p); } catch(PDOException $e) { $g_error->Add($e->getMessage()); $g_error->Add($sql); $g_error->Add(print_r($p, true)); $g_error->PrintOut(); } $numrows = $sth->fetchColumn(); $page = gpc_get_int($_REQUEST, 'p', 1); $rows_pp = gpc_get_int($_REQUEST, 'n', $g_rows_pp); $lastpage = ceil($numrows/$rows_pp); $sql = "SELECT t.taskid, t.vid, t.projid, t.taskname, t.priority, t.taskstate," . " p.projname " . "FROM task AS t LEFT JOIN project AS p USING (projid) " . "WHERE $where"; if ($order) $sql .= $order; // if pagination: $sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp; $sth = $pdo->prepare($sql); try { $sth->execute($p); } catch (PDOexception $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); $g_error->Add($sql); $g_error->Add(print_r($p, true)); $g_error->Printout(); } $res = $sth->fetchAll(); ?>
Filter
prio); filter_create_select('flt_stat', _('State'), $g_opt_all + $opt_state, $flt->stat); ?>
', "\n"; echo "\n"; echo "\n"; echo '#'; echo '', _('Task'), ""; echo '', _('Project'), ""; echo '', _('Priority'), ""; echo '', _('Status'), ""; echo ""; echo "\n"; echo "\n"; echo "\n"; $i = ($page - 1) * $rows_pp; $i0 = $i + 1; foreach ($res as $row) { $i++; // record number echo "\n"; // mark generic tasks with braces echo "", $row['vid'] ? $i : "($i)"; echo ''; echo "\n"; echo "", $row['taskname'], "\n"; echo "", $row['projname'], "\n"; echo "", ($opt_priority[$row['priority']] ?? ''), "\n"; echo "", ($opt_state[$row['taskstate']]), "\n"; // Edit current record button echo ""; echo '', "\n"; echo "\n"; echo "\n"; } // Table summary table_rec_summary($i0, $i, $numrows, 6); echo "\n"; // additional pagination at bottom echo $pagination; form_add_button($g_scriptname); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= echo '

', _('Add Task'), "

\n"; ?>
'― none ―']; form_create_select('projid', _('Project'), $opt_none + $opt_projects, $projid); ?>
prepare($sql); $sth->execute([$id]); $task = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('View Task'), "

\n"; echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Task'),"", $task->taskname, "
', _('Project'),"", ($task->projname ?? _('unassigned')), "
', _('Priority'),"", ($task->priority ?? _('none')), "
', _('Plan date'),"", $task->plandate, "
', _('Due date'),"", $task->duedate, "
', _('Started at'),"", $task->started, "
', _('Finished at'),"", $task->finished, "
', _('Status'),"", $opt_state[$task->taskstate], "
', _('Responsible'),"", $task->displayname, "
\n"; form_view_buttons($g_scriptname, $id); echo '

', _('Annotations'), "

"; $sql = "SELECT noteid, annotation " . "FROM note " . "WHERE notetype='task' AND refid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); if ($sth->rowCount() > 0) { $n = 0; foreach ($sth->fetchAll() as $row) { $n += 1; echo "

($n) ", nl2br($row['annotation']); echo ' '; echo "

\n"; } } else { echo '

', _('No annotations for this task'), "

\n"; } echo '
', "\n"; echo ''; echo _('Add note'), "\n"; echo "
\n"; echo '

', _('Documents'), "

"; echo '

', _('Not yet implemented'), "

"; elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $opt_user = db_get_opt_user($user->id); // only used here $sql = "SELECT taskname, projid, priority, plandate, duedate, started, finished," . " taskstate " . "FROM task " . "WHERE taskid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $task = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Edit Task'), "

\n"; ?>
'― none ―']; form_create_select('projid', _('Project'), $opt_none + $opt_projects, $task->projid); form_create_select('priority', _('Priority'), $opt_none + $opt_priority, $task->priority ?? 'X'); ?>
taskstate); form_create_select('responsible', _('Responsible'), $opt_user, $user->id); form_edit_buttons($g_scriptname, $id); echo "
\n"; elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== $sql = "SELECT taskname FROM task WHERE taskid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $task = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Delete Task'), "

\n"; echo '

', sprintf(_('Task no. %d'), $id), "

\n"; echo '

', $task->taskname, "

"; echo '

', _('Deleting a task item is final. There is no way back. Only delete if you are absolute sure.'), "

\n"; $_SESSION['token'] = bin2hex(random_bytes(8)); form_delete_buttons($g_scriptname, $id, $_SESSION['token']); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '

', _('Unknown function call: Please report to system development!'), "

\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';