Ongoing webgui work
This commit is contained in:
+107
-23
@@ -14,6 +14,11 @@ $pagetitle = _('Documents');
|
||||
$id = gpc_get_int($_REQUEST, 'id', 0);
|
||||
$page = gpc_get_int($_REQUEST, 'p', 1);
|
||||
|
||||
$opt_doctype = db_load_enum('document', 'doctype', true, true);
|
||||
asort($opt_doctype);
|
||||
$opt_reftype = db_load_enum('docref', 'reftype', true, true);
|
||||
asort($opt_reftype);
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
|
||||
switch ($submit = form_get_action()) {
|
||||
@@ -27,7 +32,8 @@ switch ($submit = form_get_action()) {
|
||||
|
||||
case 'filter':
|
||||
$flt = array();
|
||||
$flt['doctype'] = gpc_get_string($_POST, 'flt_doctype');
|
||||
$flt['doctype'] = gpc_get_enum($_POST, 'flt_doctype', array_keys($opt_doctype));
|
||||
$flt['reftype'] = gpc_get_enum($_POST, 'flt_reftype', array_merge(array_keys($opt_reftype), ['none']));
|
||||
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
|
||||
db_save_filter($flt, 209);
|
||||
$action = ACT_DEFAULT;
|
||||
@@ -155,9 +161,10 @@ switch ($submit = form_get_action()) {
|
||||
|
||||
case 'addref':
|
||||
$opt_reftype = db_load_enum('docref', 'reftype');
|
||||
$refid = gpc_get_int($_POST, 'refid');
|
||||
$reftype = gpc_get_enum($_POST, 'reftype', $opt_reftype, 'equipment');
|
||||
$sql = "INSERT INTO docref "
|
||||
$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)";
|
||||
@@ -165,7 +172,8 @@ switch ($submit = form_get_action()) {
|
||||
$sth->bindValue(':docid', $id, PDO::PARAM_INT);
|
||||
$sth->bindValue(':refid', $refid, PDO::PARAM_INT);
|
||||
$sth->bindValue(':reftype', $reftype, PDO::PARAM_STR);
|
||||
$sth->execute();
|
||||
$sth->execute(); */
|
||||
db_exec_insert('docref', $p);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
@@ -194,23 +202,24 @@ require 'header.php';
|
||||
if ($action == ACT_DEFAULT):
|
||||
// ========== VARIANT: default behavior =======================================
|
||||
|
||||
// All documents
|
||||
page_caption_search($pagetitle);
|
||||
|
||||
$flt = db_get_filter($user->id, 209);
|
||||
$opt_doctype = db_load_enum('document', 'doctype', true, true);
|
||||
/* TODO show all documents which
|
||||
- are completely unbound: no docref available
|
||||
- assigned to the current boat: docref with doctype vessel
|
||||
- are assigned to an equipment or project of current vesseö
|
||||
There can be multiple docref entries for a document,
|
||||
behavior still needs to be clarified. */
|
||||
|
||||
$w = array();
|
||||
$p = array();
|
||||
if ($flt->doctype != 'all') {
|
||||
if (isset($flt->doctype) and $flt->doctype != 'all') {
|
||||
$w[] = 'doctype=:doctype';
|
||||
$p[':doctype'] = $flt->doctype;
|
||||
}
|
||||
if (isset($flt->reftype) and $flt->reftype != 'all') {
|
||||
if ($flt->reftype == 'none') {
|
||||
$w[] = 'reftype IS NULL';
|
||||
} else {
|
||||
$w[] = 'reftype=:reftype';
|
||||
$p[':reftype'] = $flt->reftype;
|
||||
}
|
||||
}
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = '(filename LIKE :txt OR title LIKE :txt OR remarks LIKE :txt)';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
@@ -219,17 +228,34 @@ if (strlen($flt->txt) > 1) {
|
||||
$where = join(' AND ', $w);
|
||||
$order = ' ORDER BY docid';
|
||||
|
||||
// get total recond count for pagination and limit
|
||||
$sql = "SELECT COUNT(*) FROM document LEFT OUTER JOIN docref USING (docid)";
|
||||
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));
|
||||
}
|
||||
$numrows = $sth->fetchColumn();
|
||||
$lastpage = ceil($numrows/$g_rows_pp);
|
||||
$page = gpc_get_int($_REQUEST, 'p', 1);
|
||||
|
||||
$sql = "SELECT d.docid, d.doctype, d.filename, d.title, COUNT(r.drid) AS refcount "
|
||||
. "FROM document AS d LEFT OUTER JOIN docref AS r USING (docid)";
|
||||
if ($where) $sql .= ' WHERE ' . $where;
|
||||
$sql .= " GROUP BY d.docid, d.doctype, d.filename, d.title";
|
||||
if ($order) $sql .= $order;
|
||||
|
||||
// if pagination:
|
||||
$sql .= ' LIMIT ' . ($page - 1) * $g_rows_pp . ',' . $g_rows_pp;
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute($p);
|
||||
$res = $sth->fetchAll();
|
||||
|
||||
echo "<h1>$pagetitle</h1>\n";
|
||||
|
||||
// Filter
|
||||
$opt_special = array(
|
||||
'all' => _('― all ―'),
|
||||
@@ -251,6 +277,19 @@ foreach ($opt_special + $opt_doctype as $k => $v) {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<label for="flt_reftype"><?=_('Ref.-Type')?></label>
|
||||
<select id="flt_reftype" name="flt_reftype">
|
||||
<?php
|
||||
$opt_special['none'] = _('― none ―');
|
||||
foreach ($opt_special + $opt_reftype as $k => $v) {
|
||||
echo '<option value="', $k,'"';
|
||||
if ($k == $flt->reftype) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '>', $v, '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<label for="flt_txt">Text</label>
|
||||
<input type="text" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt?>">
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
|
||||
@@ -259,6 +298,11 @@ foreach ($opt_special + $opt_doctype as $k => $v) {
|
||||
</form>
|
||||
|
||||
<?php
|
||||
// Pagination on top
|
||||
$pagination = get_pagination($g_scriptname, '', $page, $lastpage);
|
||||
echo $pagination;
|
||||
|
||||
// Data
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo "<tr>";
|
||||
@@ -290,6 +334,8 @@ echo '<tr><td colspan="6">', sprintf(_('%d records'), count($res)), '</td></tr>'
|
||||
echo "</tfoot>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo $pagination;
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
|
||||
elseif ($action == ACT_ADD):
|
||||
@@ -300,11 +346,11 @@ echo '<h2>', _('Add Document'), "</h2>\n";
|
||||
<form method="post" enctype="multipart/form-data" 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" value="<?=$title?>">
|
||||
<input type="text" class="form-control" id="title" name="title" value="<?=$title ?? ''?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$remarks?></textarea>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$remarks ?? ''?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="files" class="form-label"><?=_('Document')?></label>
|
||||
@@ -356,9 +402,29 @@ echo '<tr><th scope="row" style="width:20%">', _('Document type'),"</th><td>", $
|
||||
if ($document->doctype == 'picture') {
|
||||
$techname = sprintf('pic-%06d.%s', $document->docid, $document->extension);
|
||||
echo '<tr><th scope="row">', _('Preview'), '</th><td>';
|
||||
echo '<a href="dl.php?id=', $document->docid, '" target="_blank">';
|
||||
// echo '<a href="dl.php?id=', $document->docid, '" target="_blank">';
|
||||
|
||||
echo '<div class="image-gallery">';
|
||||
echo '<a href="#" data-bs-toggle="modal" data-bs-target="#imageModal">';
|
||||
echo '<img width="', $g_thumb_size, '" src="dl.php?id=', $document->docid, '" alt="', $document->title, '">';
|
||||
echo '</a>';
|
||||
echo '</div>'; // gallery
|
||||
?>
|
||||
<div class="modal fade" id="imageModal" tabindex="-1" aria-labelledby="imageModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<img src="dl.php?id=<?=$document->docid ?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
// echo '</a>';
|
||||
echo "</td></tr>\n";
|
||||
} elseif (($document->doctype == 'drawing')) {
|
||||
$techname = sprintf('drw-%06d.%s', $document->docid, $document->extension);
|
||||
@@ -391,7 +457,7 @@ echo "</table>\n";
|
||||
echo "</div>\n", '<div class="col text-center">', "\n"; // column break
|
||||
|
||||
if ($document->mimetype == 'application/pdf') {
|
||||
echo '<img src="dl.php?id=', $document->docid, '&p=', $page, '&t=l" alt="PDF-Preview">', "\n";
|
||||
echo '<img id="preview" src="dl.php?id=', $document->docid, '&p=', $page, '&t=l" alt="PDF-Preview">', "\n";
|
||||
if ($document->pages > 1) {
|
||||
$pagination = get_pagination($g_scriptname, 'f=view&id='.$id, $page, $document->pages, true);
|
||||
echo $pagination;
|
||||
@@ -407,6 +473,18 @@ form_view_buttons($g_scriptname, $id);
|
||||
echo '<h3>', _('Document references'), "</h3>\n";
|
||||
$references = array();
|
||||
|
||||
// Vessel
|
||||
$vids = array();
|
||||
$sql = "SELECT drid, reftype, refid, vesselname AS target "
|
||||
. "FROM docref INNER JOIN vessel ON (docref.reftype='vessel' AND docref.refid=vessel.vid) "
|
||||
. "WHERE docid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
$references[] = $row;
|
||||
$vids[] = $row['refid'];
|
||||
}
|
||||
|
||||
// Equipment
|
||||
$eids = array();
|
||||
$sql = "SELECT drid, reftype, refid, ename AS target "
|
||||
@@ -458,6 +536,9 @@ echo "</table>\n";
|
||||
// New references
|
||||
echo '<h4>', _('Add new reference'), "</h4>\n";
|
||||
|
||||
// enum('vessel','box','equipment','project','task','user','company')
|
||||
//
|
||||
|
||||
// Equipment options
|
||||
// Do not include equipment that has already been referenced in the list!
|
||||
$opt_equipment = array();
|
||||
@@ -470,7 +551,7 @@ foreach ($sth->fetchAll() as $row) {
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<form class="mb-3" method="post" action="<?=$g_scriptname?>">
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<input type="hidden" name="reftype" value="equipment">
|
||||
<label for="eid"><?=_('Equipment')?></label>
|
||||
@@ -485,19 +566,22 @@ foreach ($opt_equipment as $k => $v) {
|
||||
</form>
|
||||
|
||||
<?php
|
||||
// Company options
|
||||
// Do not include compamies that have already been referenced in this list
|
||||
|
||||
$opt_company = array();
|
||||
$sql = "SELECT compid, compname FROM company ORDER BY compname";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
if (!in_array($row['eid'], $compids)) {
|
||||
if (!in_array($row['compid'], $compids)) {
|
||||
$opt_company[$row['compid']] = $row['compname'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<form class="mb-3" method="post" action="<?=$g_scriptname?>">
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<input type="hidden" name="reftype" value="company">
|
||||
<label for="compid"><?=_('Company')?></label>
|
||||
|
||||
Reference in New Issue
Block a user