248 lines
8.2 KiB
PHP
248 lines
8.2 KiB
PHP
<?php
|
|
/******************************************************************************
|
|
* YMS - Yacht Management Software
|
|
* Copyright (C) 2024 Thomas Hooge
|
|
*
|
|
* SPDX-License-Identifier: WTFPL
|
|
******************************************************************************/
|
|
|
|
require 'globals.inc';
|
|
$pagetitle = _('Task');
|
|
|
|
$id = gpc_get_int($_REQUEST, 'id', 0);
|
|
|
|
$opt_projects = db_get_opt_proj($user->vid, array(-1 => _('unassigned')));
|
|
$opt_priority = db_load_enum('task', 'priority', 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 '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');
|
|
$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_string($_POST, 'plandate');
|
|
$p[':duedate'] = gpc_get_string($_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'] == 'X') {
|
|
$p[':projid'] = NULL;
|
|
}
|
|
db_exec_update('task', $p, 'taskid');
|
|
$action = ACT_VIEW;
|
|
break;
|
|
|
|
case 'delete':
|
|
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 =======================================
|
|
|
|
echo "<h1>$pagetitle</h1>\n";
|
|
|
|
$sql = "SELECT t.taskid, t.projid, t.taskname, t.priority, p.projname "
|
|
. "FROM task AS t LEFT JOIN project AS p USING (projid) "
|
|
. "WHERE p.projid IS NULL OR p.vid=? "
|
|
. "ORDER BY t.taskid";
|
|
$sth = $pdo->prepare($sql);
|
|
try {
|
|
$sth->execute([$user->vid]);
|
|
} catch (PDOexception $e) {
|
|
$g_error->Add('SQL-Error: '. $e->getMessage());
|
|
}
|
|
$res = $sth->fetchAll();
|
|
|
|
echo '<table class="table table-striped">', "\n";
|
|
echo "<thead>\n";
|
|
echo "<tr>\n";
|
|
echo '<th>#</th>';
|
|
echo '<th>', _('Task'), "</th>";
|
|
echo '<th>', _('Project'), "</th>";
|
|
echo '<th>', _('Priority'), "</th>";
|
|
echo "<th></th>";
|
|
echo "<th></th>\n";
|
|
echo "</tr>\n";
|
|
echo "</thead>\n";
|
|
foreach ($res as $row) {
|
|
echo "<tr>\n";
|
|
echo "<td>", $row['taskid'], "</td>\n";
|
|
echo "<td>", $row['taskname'], "</td>\n";
|
|
echo "<td>", $row['projname'], "</td>\n";
|
|
echo "<td>", ($opt_priority[$row['priority']] ?? ''), "</td>\n";
|
|
// Action buttons
|
|
form_action_buttons($g_scriptname, $row['taskid']);
|
|
echo "</tr>\n";
|
|
}
|
|
// Table summary
|
|
echo "<tfoot>\n";
|
|
echo '<tr><td colspan="6">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
|
|
echo "</tfoot>\n";
|
|
echo "</table>\n";
|
|
|
|
form_add_button($g_scriptname);
|
|
|
|
elseif ($action == ACT_ADD):
|
|
// ========== VARIANT: add record =============================================
|
|
|
|
echo '<h2>', _('Add Task'), "</h2>\n";
|
|
?>
|
|
<form method="post" action="<?=$g_scriptname?>">
|
|
<?php
|
|
// preselect project if parameter is set
|
|
$projid = gpc_get_int($_REQUEST, 'projid');
|
|
$opt_none = [-1 => '― none ―'];
|
|
form_create_select('projid', _('Project'), $opt_none + $opt_projects, $projid);
|
|
?>
|
|
<div class="mb-3">
|
|
<label for="taskname" class="form-label"><?=_('Task')?></label>
|
|
<input type="text" class="form-control" id="taskname" name="taskname" required autofocus>
|
|
</div>
|
|
<div class="container-fluid px-0 my-3">
|
|
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
|
|
<a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a>
|
|
</div>
|
|
</form>
|
|
<?php
|
|
|
|
elseif ($action == ACT_VIEW):
|
|
// ========== VARIANT: view single record =====================================
|
|
|
|
$sql = "SELECT t.taskname, t.priority, t.plandate, t.duedate,"
|
|
. " t.started, t.finished, p.projname "
|
|
. "FROM task AS t LEFT JOIN project AS p USING (projid) "
|
|
. "WHERE taskid=?";
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->execute([$id]);
|
|
$task = $sth->fetch(PDO::FETCH_OBJ);
|
|
|
|
echo '<h2>', _('View Task'), "</h2>\n";
|
|
echo '<table class="table">', "\n";
|
|
echo '<tr><th>', _('Task'),"</th><td>", $task->taskname, "</td></tr>\n";
|
|
echo '<tr><th>', _('Project'),"</th><td>", ($task->projname ?? _('unassigned')), "</td></tr>\n";
|
|
echo '<tr><th>', _('Priority'),"</th><td>", ($task->priority ?? _('none')), "</td></tr>\n";
|
|
echo '<tr><th>', _('Plan date'),"</th><td>", $task->plandate, "</td></tr>\n";
|
|
echo '<tr><th>', _('Due date'),"</th><td>", $task->duedate, "</td></tr>\n";
|
|
echo '<tr><th>', _('Started at'),"</th><td>", $task->started, "</td></tr>\n";
|
|
echo '<tr><th>', _('Finished at'),"</th><td>", $task->finished, "</td></tr>\n";
|
|
echo "</table>\n";
|
|
|
|
form_view_buttons($g_scriptname, $id);
|
|
|
|
echo "<h3>Annotations</h3>";
|
|
|
|
$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 "<p>($n) {$row['annotation']}";
|
|
echo ' <a title="', _('Edit'), '" href="note.php?f=edit&id=', $row['noteid'], '"><i class="bi-pencil"></i></a>';
|
|
echo "</p>\n";
|
|
}
|
|
} else {
|
|
echo '<p>', _('No annotations for this task'), "</p>\n";
|
|
}
|
|
echo '<div class="container-fluid px-0 my-3">', "\n";
|
|
echo '<a href="note.php?f=add&t=task&id=', $id, '" class="btn btn-primary" role="button">';
|
|
echo _('Add note'), "</a>\n";
|
|
echo "</div>\n";
|
|
|
|
echo "<h3>Documents</h3>";
|
|
echo "<p>Not yet implemented</p>";
|
|
|
|
elseif ($action == ACT_EDIT):
|
|
// ========== VARIANT: edit single record =====================================
|
|
|
|
$sql = "SELECT taskname, projid, priority, plandate, duedate, started, finished "
|
|
. "FROM task "
|
|
. "WHERE taskid=?";
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->execute([$id]);
|
|
$task = $sth->fetch(PDO::FETCH_OBJ);
|
|
|
|
echo '<h2>', _('Edit Task'), "</h2>\n";
|
|
|
|
?>
|
|
<form method="post" action="<?=$g_scriptname?>">
|
|
<input type="hidden" name="id" value="<?=$id?>">
|
|
<div class="mb-3">
|
|
<label for="taskname" class="form-label"><?=_('Name')?></label>
|
|
<input type="text" class="form-control" id="taskname" name="taskname" value="<?=$task->taskname ?>">
|
|
</div>
|
|
<?php
|
|
$opt_none = [-1 => '― none ―'];
|
|
form_create_select('projid', _('Project'), $opt_none + $opt_projects, $task->projid);
|
|
form_create_select('priority', _('Priority'), $opt_none + $opt_priority, $task->priority ?? 'X');
|
|
?>
|
|
<div class="mb-3">
|
|
<label for="plandate" class="form-label"><?=_('Plan date')?></label>
|
|
<input type="date" class="form-control" id="plandate" name="plandate" value="<?=$task->plandate ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="duedate" class="form-label"><?=_('Due date')?></label>
|
|
<input type="date" class="form-control" id="duedate" name="duedate" value="<?=$task->duedate ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="started" class="form-label"><?=_('Started at')?></label>
|
|
<input type="datetime-local" class="form-control" id="started" name="started" value="<?=$task->started ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="finished" class="form-label"><?=_('Finished at')?></label>
|
|
<input type="datetime-local" class="form-control" id="finished" name="finished" value="<?=$task->finished ?>">
|
|
</div>
|
|
<?php
|
|
form_edit_buttons($g_scriptname, $id);
|
|
echo "</form>\n";
|
|
|
|
elseif ($action == ACT_DELETE):
|
|
// ========== VARIANT: delete record ==========================================
|
|
|
|
echo '<h2>', _('Delete Task'), "</h2>\n";
|
|
|
|
else:
|
|
// ========== ERROR UNKNOWN VARIANT ===========================================
|
|
|
|
echo '<p>', _('Unknown function call: Please report to system development!'), "</p>\n";
|
|
|
|
endif; // $action == ...
|
|
// ========== END OF VARIANTS =================================================
|
|
|
|
include 'footer.php';
|