More improvements e.g. flags and provision target

This commit is contained in:
2026-08-11 07:48:46 +02:00
parent a3d4825cbd
commit 41556cfe73
22 changed files with 961 additions and 484 deletions
+54 -20
View File
@@ -6,6 +6,14 @@
* SPDX-License-Identifier: WTFPL
******************************************************************************/
/*
doctype icons
generic: file-earmark
image: file-earmark-image
drawing: file-earmark-easel
pdf: file-earmark-pdf
*/
require 'globals.inc';
require 'lib/gpc.inc';
require 'lib/fileutils.inc';
@@ -143,6 +151,12 @@ switch ($submit = form_get_action()) {
break;
case 'delete':
// check user rights
if ($user->role == ROLE_SAILOR) {
$g_error->Add(_('User level allows no deletion!'));
$action = ACT_VIEW;
break;
}
// Security token needed!
if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) {
$g_error->Add(_('Delete prohibited, invalid security token!'));
@@ -189,21 +203,18 @@ switch ($submit = form_get_action()) {
$p[':docid'] = $id;
$p[':refid'] = gpc_get_int($_POST, 'refid');
$p[':reftype'] = gpc_get_enum($_POST, 'reftype', $opt_reftype, 'equipment');
/* $sql = "INSERT INTO docref "
. " (docid, refid, reftype) "
. "VALUES "
. " (:docid, :refid, :reftype)";
$sth = $pdo->prepare($sql);
$sth->bindValue(':docid', $id, PDO::PARAM_INT);
$sth->bindValue(':refid', $refid, PDO::PARAM_INT);
$sth->bindValue(':reftype', $reftype, PDO::PARAM_STR);
$sth->execute(); */
db_exec_insert('docref', $p);
$action = ACT_VIEW;
break;
case 'delref':
// remove only link, not critical so get without token is ok
// check user rights
if ($user->role == ROLE_SAILOR) {
$g_error->Add(_('User level allows no deletion!'));
$action = ACT_VIEW;
break;
}
$drid = gpc_get_int($_GET, 'drid');
$sql = "DELETE FROM docref WHERE drid=?";
$sth = $pdo->prepare($sql);
@@ -582,6 +593,18 @@ foreach ($sth->fetchAll() as $row) {
$compids[] = $row['refid'];
}
// Boxes
$boxids = array();
$sql = "SELECT drid, reftype, refid, CONCAT_WS(' - ', label, NULLIF(content, '')) AS target "
. "FROM docref INNER JOIN box ON (docref.reftype='box' AND docref.refid=box.boxid) "
. "WHERE docid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$id]);
foreach ($sth->fetchAll() as $row) {
$references[] = $row;
$boxids[] = $row['refid'];
}
echo '<table class="table table-sm">', "\n";
echo "<thead>\n";
echo "<tr>";
@@ -600,6 +623,8 @@ foreach ($references as $ref) {
echo '<a title="', _('View'), '" href="equipment.php?f=view&id=', $ref['refid'],'"><i class="bi-eye ms-2"></i></a>';
} elseif ($ref['reftype'] == 'company') {
echo '<a title="', _('View'), '" href="company.php?f=view&id=', $ref['refid'],'"><i class="bi-eye ms-2"></i></a>';
} elseif ($ref['reftype'] == 'box') {
echo '<a title="', _('View'), '" href="box.php?f=view&id=', $ref['refid'],'"><i class="bi-eye ms-2"></i></a>';
}
echo "</td>";
echo "<td>", get_enum($ref['reftype']), "</td>";
@@ -616,18 +641,12 @@ echo '<h4>', _('Add new reference'), "</h4>\n";
// enum('vessel','box','equipment','project','task','user','company')
//
// Reference options
$opt_reference = db_load_enum('docref', 'reftype', lookup:true, as_dict:true);
// Equipment options
// Do not include equipment that has already been referenced in the list!
$opt_equipment = array();
$sql = "SELECT eid, ename FROM equipment WHERE vid=? ORDER BY ename";
$sth = $pdo->prepare($sql);
$sth->execute([$user->vid]);
foreach ($sth->fetchAll() as $row) {
if (!in_array($row['eid'], $eids)) {
$opt_equipment[$row['eid']] = $row['ename'];
}
}
$opt_equipment = db_get_opt_equip($user->vid, exclude:$eids)
?>
<form class="mb-3" method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
@@ -656,8 +675,6 @@ foreach ($sth->fetchAll() as $row) {
$opt_company[$row['compid']] = $row['compname'];
}
}
?>
<form class="mb-3" method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
@@ -673,6 +690,23 @@ foreach ($opt_company as $k => $v) {
<button class="btn btn-sm btn-secondary" name="submit[addref]">Referenzieren</button>
</form>
<?php
// Box options
$opt_box = db_get_opt_box($user->vid, exclude:$boxids)
?>
<form class="mb-3" method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="reftype" value="box">
<label for="eid"><?=_('Box')?></label>
<select class="form-select mb-2" name="refid" id="boxid">
<?php
foreach ($opt_box as $k => $v) {
echo '<option value="', $k, '">', $v, "</option>\n";
}
?>
</select>
<button class="btn btn-sm btn-secondary" name="submit[addref]">Referenzieren</button>
</form>
<?php
// Vessel options
// Do not include vessel that has already been referenced in the list!