178 lines
4.9 KiB
PHP
178 lines
4.9 KiB
PHP
<?php
|
|
/******************************************************************************
|
|
* YMS - Yacht Management Software
|
|
* Copyright (C) 2024-2026 Thomas Hooge
|
|
*
|
|
* SPDX-License-Identifier: WTFPL
|
|
******************************************************************************/
|
|
|
|
require 'globals.inc';
|
|
require 'lib/gpc.inc';
|
|
|
|
$pagetitle = _('Checklists');
|
|
|
|
$id = gpc_get_int($_REQUEST, 'id', 0);
|
|
$c = gpc_get_int($_REQUEST, 'c', -1);
|
|
|
|
function create_clitem_form($script, $clid, $formtype, $row=NULL) {
|
|
|
|
// formtype: insert or update
|
|
$update = ($formtype == 'update');
|
|
echo '<form method="post" action="', $script, '">';
|
|
echo '<input type="hidden" name="id" value="', $clid, '">';
|
|
if ($update) {
|
|
echo '<input type="hidden" name="v" value="', $row['checkid'], '">';
|
|
}
|
|
|
|
}
|
|
|
|
// ========== 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[':title'] = gpc_get_string($_POST, 'title');
|
|
$id = db_exec_insert('checklist', $p);
|
|
$action = ACT_VIEW;
|
|
break;
|
|
|
|
case 'update':
|
|
$p[':title'] = gpc_get_string($_POST, 'title');
|
|
$p[':clstate'] = gpc_get_string($_POST, 'clstate');
|
|
$p[':clid'] = $id;
|
|
db_exec_update('checklist', $p, 'clid');
|
|
$action = ACT_VIEW;
|
|
break;
|
|
|
|
case 'delete':
|
|
$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 =======================================
|
|
|
|
echo "<h1>$pagetitle</h1>\n";
|
|
|
|
$sql = "SELECT clid, title, clstate FROM checklist";
|
|
$sth = $pdo->query($sql);
|
|
$res = $sth->fetchAll();
|
|
?>
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th><?=_('Title')?></th>
|
|
<th><?=_('State')?></th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<?php
|
|
foreach ($res as $row) {
|
|
echo "<tr>\n";
|
|
echo '<td>', $row['clid'], "</td>\n";
|
|
echo '<td>', $row['title'], "</td>\n";
|
|
echo '<td>', $row['clstate'], "</td>\n";
|
|
form_action_buttons($g_scriptname, $row['clid']);
|
|
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 Checklist'), "</h2>\n";
|
|
?>
|
|
<form method="post" action="<?=$g_scriptname?>">
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label"><?=_('Title')?></label>
|
|
<input type="text" class="form-control" id="title" name="title">
|
|
</div>
|
|
<?php
|
|
form_new_buttons($g_scriptname);
|
|
echo "</form>\n";
|
|
|
|
elseif ($action == ACT_VIEW):
|
|
// ========== VARIANT: view single record =====================================
|
|
|
|
$sth = $pdo->prepare("SELECT title, clstate FROM checklist WHERE clid=?");
|
|
$sth->execute([$id]);
|
|
$checklist = $sth->fetch(PDO::FETCH_OBJ);
|
|
|
|
?>
|
|
<h2><?=_('View Checklist')?></h2>
|
|
<table class="table">
|
|
<tr><th><?=_('Title')?></th><td><?=$checklist->title ?></td></tr>
|
|
<tr><th><?=_('State')?></th><td><?=get_enum($checklist->clstate)?></td></tr>
|
|
</table>
|
|
<?php
|
|
|
|
/*
|
|
$sql = "SELECT checkname, groupid FROM checkitem";
|
|
|
|
$sql = "SELECT clid, checkid, sort FROM checkref";
|
|
|
|
*/
|
|
|
|
form_view_buttons($g_scriptname, $id);
|
|
|
|
elseif ($action == ACT_EDIT):
|
|
// ========== VARIANT: edit single record =====================================
|
|
|
|
$sth = $pdo->prepare("SELECT title, clstate FROM checklist WHERE clid=?");
|
|
$sth->execute([$id]);
|
|
$checklist = $sth->fetch(PDO::FETCH_OBJ);
|
|
|
|
$opt_clstate = db_load_enum('checklist', 'clstate', true, true);
|
|
|
|
echo '<h2>', _('Edit checklist'), "</h2>\n";
|
|
?>
|
|
<form method="post" action="<?=$g_scriptname?>">
|
|
<input type="hidden" name="id" value="<?=$id?>">
|
|
<div class="mb-3">
|
|
<label for="provname" class="form-label"><?=_('Name')?></label>
|
|
<input type="text" class="form-control" id="title" name="title" value="<?=$checklist->title ?>">
|
|
</div>
|
|
<?php
|
|
form_create_select('clstate', _('State'), $opt_clstate, $checklist->clstate);
|
|
|
|
form_edit_buttons($g_scriptname, $id);
|
|
echo "</form>\n";
|
|
|
|
elseif ($action == ACT_DELETE):
|
|
// ========== VARIANT: delete record ==========================================
|
|
|
|
echo '<h2>', _('Delete checklist'), "</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';
|