Webgui programming

This commit is contained in:
2025-05-09 10:22:08 +02:00
parent c293ca1caa
commit fb93c83388
11 changed files with 340 additions and 85 deletions
+16 -27
View File
@@ -1,7 +1,7 @@
<?php
/******************************************************************************
* YMS - Yacht Management Software
* Copyright (C) 2024 Thomas Hooge
* Copyright (C) 2024-2025 Thomas Hooge
*
* SPDX-License-Identifier: WTFPL
******************************************************************************/
@@ -17,6 +17,7 @@ $opt_user = array();
foreach ($sth->fetchAll() as $row) {
$opt_user[$row['userid']] = $row['displayname'];
}
$opt_state = db_load_enum('project', 'projstate', true, true);
// ========== ACTIONS START ===================================================
@@ -37,11 +38,11 @@ switch ($submit = form_get_action()) {
break;
case 'insert':
$p['vid'] = $user->id;
$p[':vid'] = $user->vid;
$p[':projname'] = gpc_get_string($_POST, 'projname');
$p[':responsible'] = gpc_get_int($_POST, 'responsible');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
$id = db_exec_insert('company', $p);
$id = db_exec_insert('project', $p);
$action = ACT_VIEW;
break;
@@ -50,6 +51,7 @@ switch ($submit = form_get_action()) {
$p[':projname'] = gpc_get_string($_POST, 'projname');
$p[':startdate'] = gpc_get_date($_POST, 'startdate');
$p[':duration'] = gpc_get_int($_POST, 'duration');
$p[':projstate'] = gpc_get_string($_POST, 'projstate');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('project', $p, 'projid');
$action = ACT_VIEW;
@@ -121,9 +123,10 @@ echo "<h1>", _('Generic Tasks'), "</h1>\n";
echo "<p>", _('Tasks not assigned to any project'), "</p>\n";
$sql = "SELECT taskid, taskname "
. "FROM task "
. "WHERE projid IS NULL "
. "WHERE vid=? AND projid IS NULL "
. "ORDER BY taskid";
$sth = $pdo->query($sql);
$sth = $pdo->prepare($sql);
$sth->execute([$user->vid]);
$res = $sth->fetchAll();
echo '<table class="table table-striped">', "\n";
echo "<thead>\n";
@@ -156,16 +159,9 @@ echo '<h2>', _('Add Project'), "</h2>\n";
<label for="projname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="projname" name="projname">
</div>
<div class="mb-3">
<label for="responsible" class="form-label"><?=_('Responsible')?></label>
<select name="responsible" class="form-control">
<?php
foreach ($opt_user as $k => $v) {
echo '<option value="', $k ,'">', $v, "</option>\n";
}
form_create_select('responsible', _('Responsible'), $opt_user, $project->responsible);
?>
</select>
</div>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"></textarea>
@@ -178,7 +174,7 @@ foreach ($opt_user as $k => $v) {
elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record =====================================
$sql = "SELECT projname, startdate, duration, responsible, remarks "
$sql = "SELECT projname, startdate, duration, responsible, projstate, remarks "
. "FROM project "
. "WHERE projid=?";
$sth = $pdo->prepare($sql);
@@ -190,6 +186,7 @@ echo '<tr><th scope="row" style="width:20%">', _('Name'),"</th><td>", $project->
echo '<tr><th scope="row">', _('Responsible'),"</th><td>", $opt_user[$project->responsible], "</td></tr>\n";
echo '<tr><th scope="row">', _('Start date'),"</th><td>", $project->startdate, "</td></tr>\n";
echo '<tr><th scope="row">', _('Duration'),"</th><td>", $project->duration, "</td></tr>\n";
echo '<tr><th scope="row">', _('State'),"</th><td>", $project->projstate, "</td></tr>\n";
echo '<tr><th scope="row">', _('Remarks'),"</th><td>", $project->remarks, "</td></tr>\n";
echo "</table>\n";
@@ -223,7 +220,7 @@ elseif ($action == ACT_EDIT):
echo '<h2>', _('Edit Project'), "</h2>\n";
$sql = "SELECT projname, responsible, startdate, duration, remarks "
$sql = "SELECT projname, responsible, startdate, duration, projstate, remarks "
. "FROM project "
. "WHERE projid=?";
$sth = $pdo->prepare($sql);
@@ -237,20 +234,9 @@ $project = $sth->fetch(PDO::FETCH_OBJ);
<label for="projname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="projname" name="projname" value="<?=$project->projname ?>">
</div>
<div class="mb-3">
<label for="responsible" class="form-label"><?=_('Responsible')?></label>
<select name="responsible" class="form-control">
<?php
foreach ($opt_user as $k => $v) {
echo '<option value="', $k ,'"';
if ($project->responsible == $k) {
echo ' selected';
}
echo '>', $v, "</option>\n";
}
form_create_select('responsible', _('Responsible'), $opt_user, $project->responsible);
?>
</select>
</div>
<div class="mb-3">
<label for="startdate"><?=_('Startdate')?></label>
<input type="date" class="form-control" id="startdate" name="startdate" value="<?=$project->startdate ?>">
@@ -259,6 +245,9 @@ foreach ($opt_user as $k => $v) {
<label for="duration"><?=_('Duration, days')?></label>
<input type="number" class="form-control" id="duration" name="duration" min="1" value="<?=$project->duration ?>">
</div>
<?php
form_create_select('projstate', _('Status'), $opt_state, $project->projstate);
?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$project->remarks ?></textarea>