More webgui work. Filters e.g.
This commit is contained in:
+98
-30
@@ -22,6 +22,14 @@ switch ($submit = form_get_action()) {
|
||||
case 'edit': $action = ACT_EDIT; break;
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
case 'filter':
|
||||
$flt = array();
|
||||
$flt['doctype'] = gpc_get_string($_POST, 'flt_doctype');
|
||||
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
|
||||
db_save_filter($flt, 209);
|
||||
$action = ACT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 'insert':
|
||||
// WIP New standalone document
|
||||
// debug $g_message->Add(print_r($_FILES, true));
|
||||
@@ -62,21 +70,20 @@ switch ($submit = form_get_action()) {
|
||||
}
|
||||
switch ($file_mimetype) {
|
||||
case 'application/pdf':
|
||||
$file_techname = $g_doc_basepath . '/doc-'.$file_hash.'.'.$file_ext;
|
||||
$doctype = 'generic';
|
||||
// $p['pages'] = pdf_get_pagecount($file_tmp);
|
||||
$p[':doctype'] = 'generic';
|
||||
$p[':pages'] = pdf_get_pagecount($file_tmp);
|
||||
$prefix = 'doc';
|
||||
break;
|
||||
case 'image/svg+xml':
|
||||
$file_techname = $g_doc_basepath . '/drw-'.$file_hash.'.'.$file_ext;
|
||||
$doctype = 'drawing';
|
||||
$p[':doctype'] = 'drawing';
|
||||
$prefix = 'drw';
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/jpeg':
|
||||
$file_techname = $g_doc_basepath . '/pic-'.$file_hash.'.'.$file_ext;
|
||||
$doctype = 'picture';
|
||||
$p[':doctype'] = 'picture';
|
||||
$prefix = 'pic';
|
||||
break;
|
||||
}
|
||||
$p[':doctype'] = $doctype;
|
||||
$p[':mimetype'] = $file_mimetype;
|
||||
$p[':filename'] = $file_name;
|
||||
$p[':extension'] = $file_ext;
|
||||
@@ -86,14 +93,15 @@ switch ($submit = form_get_action()) {
|
||||
$p[':title'] = gpc_get_string($_POST, 'title');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
|
||||
$id = db_exec_insert('document', $p);
|
||||
$file_techname = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $prefix, $id, $file_ext);
|
||||
move_uploaded_file($file_tmp, $file_techname);
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
$p[':docid'] = $id;
|
||||
$p['filename'] = gpc_get_string($_POST, 'filename');
|
||||
$p['title'] = gpc_get_string($_POST, 'title', 40);
|
||||
$p[':filename'] = gpc_get_string($_POST, 'filename');
|
||||
$p[':title'] = gpc_get_string($_POST, 'title', 40);
|
||||
$p['remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
db_exec_update('document', $p, 'docid');
|
||||
$action = ACT_VIEW;
|
||||
@@ -149,6 +157,8 @@ if ($action == ACT_DEFAULT):
|
||||
|
||||
// All documents
|
||||
|
||||
$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
|
||||
@@ -156,31 +166,78 @@ if ($action == ACT_DEFAULT):
|
||||
There can be multiple docref entries for a document,
|
||||
behavior still needs to be clarified. */
|
||||
|
||||
echo "<h1>$pagetitle</h1>\n";
|
||||
$w = array();
|
||||
$p = array();
|
||||
if ($flt->doctype != 'all') {
|
||||
$w[] = 'doctype=:doctype';
|
||||
$p[':doctype'] = $flt->doctype;
|
||||
}
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = '(filename LIKE :txt OR title LIKE :txt OR remarks LIKE :txt)';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
}
|
||||
|
||||
$where = join(' AND ', $w);
|
||||
$order = ' ORDER BY docid';
|
||||
|
||||
$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) "
|
||||
. "GROUP BY d.docid, d.doctype, d.filename, d.title";
|
||||
$sth = $pdo->query($sql);
|
||||
. "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;
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute($p);
|
||||
$res = $sth->fetchAll();
|
||||
|
||||
echo "<h1>$pagetitle</h1>\n";
|
||||
|
||||
// Filter
|
||||
$opt_special = array(
|
||||
'all' => _('― all ―'),
|
||||
);
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<div id="filter" class="card">
|
||||
<div class="card-header">Filter</div>
|
||||
<div class="card-body">
|
||||
<label for="flt_doctype">Type</label>
|
||||
<select id="flt_doctype" name="flt_doctype">
|
||||
<?php
|
||||
foreach ($opt_special + $opt_doctype as $k => $v) {
|
||||
echo '<option value="', $k,'"';
|
||||
if ($k == $flt->doctype) {
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo "<tr>";
|
||||
echo "<th>" . _('ID') . "</th>";
|
||||
echo "<th>" . _('Type') . "</th>";
|
||||
echo "<th>" . _('Filename') . "</th>";
|
||||
echo "<th>" . _('Title') . "</th>";
|
||||
echo "<th>" . _('Links') . "</th>";
|
||||
echo "<th>", _('ID'), "</th>";
|
||||
echo "<th>", _('Type'), "</th>";
|
||||
echo "<th>", _('Filename'), "</th>";
|
||||
echo "<th>", _('Title'), "</th>";
|
||||
echo "<th>", _('Links'), "</th>";
|
||||
echo "<th> </th>";
|
||||
echo "</tr>\n";
|
||||
echo "</thead>\n";
|
||||
foreach ($res as $row) {
|
||||
echo "<tr>\n";
|
||||
echo "<td>". $row['docid'] ."</td>\n";
|
||||
echo "<td>". $row['doctype'] ."</td>\n";
|
||||
echo "<td>". $row['filename'] ."</td>\n";
|
||||
echo "<td>". $row['title'] ."</td>\n";
|
||||
echo "<td>". $row['refcount'] ."</td>\n";
|
||||
echo "<td>", $row['docid'], "</td>\n";
|
||||
echo "<td>", $opt_doctype[$row['doctype']], "</td>\n";
|
||||
echo "<td>", $row['filename'], "</td>\n";
|
||||
echo "<td>", $row['title'], "</td>\n";
|
||||
echo "<td>", $row['refcount'], "</td>\n";
|
||||
// Action buttons
|
||||
echo "<td>";
|
||||
echo '<a title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['docid'], '"><i class="bi-eye"></i></a>', "\n";
|
||||
@@ -252,6 +309,8 @@ $document = $sth->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
echo '<h2>', _('View Document'), "</h2>\n";
|
||||
|
||||
echo '<div class="row">', "\n";
|
||||
echo '<div class="col">', "\n";
|
||||
echo '<table class="table table-borderless">', "\n";
|
||||
echo '<tr><th scope="row" style="width:20%">', _('Document type'),"</th><td>", $document->doctype, "</td></tr>\n";
|
||||
if ($document->doctype == 'picture') {
|
||||
@@ -266,22 +325,30 @@ if ($document->doctype == 'picture') {
|
||||
echo '<tr><th scope="row">', _('Drawing'), '</th>';
|
||||
echo '<td><img src="dl.php?id=', $document->docid, '" alt="', $document->title, '"></td></tr>', "\n";
|
||||
} elseif (($document->doctype == 'generic')) {
|
||||
$techname = 'doc-' . $document->hash . '.' . $document->extension;
|
||||
$techname = sprintf('doc-%06d.%s', $document->docid, $document->extension);
|
||||
if ($document->mimetype == 'application/pdf') {
|
||||
// TODO show preview of previewpage, ctrate thumbnail if needed
|
||||
|
||||
// TODO show preview of previewpage, create thumbnail if needed
|
||||
$pages = pdf_get_pagecount("$g_doc_basepath/$techname");
|
||||
// Download link
|
||||
echo '<tr><th scope="row">', _('PDF'), '</th><td><a href="dl.php?id=', $document->docid, '">', $document->title ?? _('Download'), "</a></td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('PDF'), '</th><td><a href="dl.php?id=', $document->docid, '">', $document->title ?? _('Download'), '</a> (', sprintf(_('%d Pages'), $pages), ")</td></tr>\n";
|
||||
}
|
||||
}
|
||||
echo '<tr><th scope="row">', _('Mimetype'),"</th><td>", $document->mimetype, "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('Filename'),"</th><td>", $document->filename, "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('File size'),"</th><td>", $document->docsize, "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('File size'),"</th><td>", format_filesize($document->docsize), "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('Upload date'),"</th><td>", $document->doctime, "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('Title'),"</th><td>", $document->title, "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('Remarks'),"</th><td>", $document->remarks, "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo "</div>\n", '<div class="col">', "\n"; // column break
|
||||
|
||||
if ($document->mimetype == 'application/pdf') {
|
||||
echo '<img src="dl.php?id=', $document->docid,'&t=l" alt="PDF-Preview">', "\n";
|
||||
}
|
||||
|
||||
echo "</div>\n</div>\n"; // end of columns
|
||||
|
||||
form_view_buttons($g_scriptname, $id);
|
||||
|
||||
|
||||
@@ -306,7 +373,8 @@ foreach ($sth->fetchAll() as $row) {
|
||||
echo "<td>", $row['reftype'], "</td>";
|
||||
echo "<td>", $row['name'], "</td>";
|
||||
echo "<td>";
|
||||
echo '<a title="', _('Remove'), '" href="', $script, '?f=delref&id=', $id, '&drid=', $row['drid'], '"><i class="bi-trash"></i></a>';
|
||||
echo '<a title="', _('View'), '" href="equipment.php?f=view&id=', $row['eid'],'"><i class="bi-eye"></i></a>';
|
||||
echo '<a title="', _('Remove'), '" href="', $g_scriptname, '?f=delref&id=', $id, '&drid=', $row['drid'], '"><i class="bi-trash"></i></a>';
|
||||
echo "</td>";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user