More webgui development

This commit is contained in:
2024-04-30 19:38:28 +02:00
parent c3b5ef95a9
commit 0c09ce2916
21 changed files with 1056 additions and 155 deletions
+43 -40
View File
@@ -18,85 +18,88 @@
*/
require 'globals.inc';
require 'lib/fileutils.inc';
$docid = gpc_get_int($_GET, 'id');
if (! isset($docid)) {
exit(1);
}
$page = gpc_get_int($_REQUEST, 'p', 1);
$thumb = gpc_get_string($_GET, 't', 1);
$size = array ('s' => 120, 'm' => 240, 'l' => '320');
if (!array_key_exists($thumb, $size)) {
unset($thumb);
}
$sql = "SELECT doctype, docsize, mimetype, hash, extension, filename FROM document WHERE docid=?";
$sql = "SELECT doctype, docsize, mimetype, hash, extension, filename, pages FROM document WHERE docid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$docid]);
$row = $sth->fetch();
$dtmap = array(
'generic' => 'doc',
'manual' => 'man',
'invoice' => 'inv',
'picture' => 'pic',
'drawing' => 'drw');
$doc = $sth->fetch(PDO::FETCH_OBJ);
// alter Dateiname
// $ofn = sprintf("%s-%s.%s", $dtmap[$row['doctype']], $row['hash'], $row['extension'])
$file = sprintf("%s/%s-%s.%s", $g_doc_basepath, $dtmap[$row['doctype']], $row['hash'], $row['extension']);
if (file_exists($file)) {
// $file = sprintf("%s/%s-%s.%s", $g_doc_basepath, $g_doc_typemap[$row['doctype']], $row['hash'], $row['extension']);
/*if (file_exists($file)) {
// Hash-Dateinamen: Umbenennen in neues Format
// document-format: ttt-nnnnnn.eee
// thumbnail-format: ttt-nnnnnn-ppp-s.eee
$fnew = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $dtmap[$row['doctype']], $docid, $row['extension']);
$fnew = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $g_doc_typemap[$row['doctype']], $docid, $row['extension']);
rename($file, $fnew);
$file = $fnew;
} else {
$file = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $dtmap[$row['doctype']], $docid, $row['extension']);
}
} else { */
$file = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $g_doc_typemap[$doc->doctype], $docid, $doc->extension);
// }
if (isset($thumb)) {
$page = 1; // could be variable in future
if ($row['mimetype'] == 'application/pdf') {
// PDF creates PNG-thumbnails
$thumbname = sprintf('%s-%06d-%03d-%s.png', $dtmap[$row['doctype']], $docid, $page, $thumb);
} else {
$thumbname = sprintf('%s-%06d-%03d-%s.%s', $dtmap[$row['doctype']], $docid, $page, $thumb, $row['extension']);
if ($page < 1) {
$page = 1;
} elseif ($page > $doc->pages) {
$page = $doc->pages;
}
$thumbpath = $g_doc_basepath . '/thumb/' . $thumbname;
if (!file_exists($thumbpath)) {
list($width, $height) = getimagesize($file);
$factor = $size[$thumb] / max($width, $height);
// scale down
if ($row['mimetype'] == 'image/jpeg') {
$orig = imagecreatefromjpeg($file);
$scaled = imagescale($orig, $width * $factor, $height * $factor, IMG_BICUBIC);
imagejpeg($scaled, $thumbpath, 85);
$file = $thumbpath;
$filename = $thumbname;
$fsize = 0; // let's calc later
} elseif ($row['mimetype'] == 'image/png') {
$orig = imagecreatefrompng($file);
} elseif ($row['mimetype'] == 'application/pdf') {
// create preview image from first page of png
// mutool draw -o <thumb>.png -w <width> <filename>.pdf <page>
if ($doc->mimetype == 'application/pdf') {
// PDF creates PNG-thumbnails
$thumbname = sprintf('%s-%06d-%03d-%s.png', $g_doc_typemap[$doc->doctype], $docid, $page, $thumb);
$thumbpath = $g_doc_basepath . '/thumb/' . $thumbname;
if (!file_exists($thumbpath)) {
exec("/usr/bin/mutool draw -o {$thumbpath} -w {$size[$thumb]} $file $page", $output, $retval);
}
} else {
$thumbname = sprintf('%s-%06d-%03d-%s.%s', $g_doc_typemap[$doc->doctype], $docid, $page, $thumb, $doc->extension);
$thumbpath = $g_doc_basepath . '/thumb/' . $thumbname;
if (!file_exists($thumbpath)) {
list($width, $height) = getimagesize($file);
$factor = $size[$thumb] / max($width, $height);
// scale down
if ($doc->mimetype == 'image/jpeg') {
$orig = imagecreatefromjpeg($file);
$scaled = imagescale($orig, $width * $factor, $height * $factor, IMG_BICUBIC);
imagejpeg($scaled, $thumbpath, 85);
$file = $thumbpath;
$filename = $thumbname;
$fsize = 0; // let's calc later
} elseif ($doc->mimetype == 'image/png') {
$orig = imagecreatefrompng($file);
} elseif ($doc_>mimetype == 'image/xml+svg') {
// TODO anything here?
}
}
}
$file = $thumbpath;
$filename = $thumbname;
$fsize = 0; // let's calc later
} else {
// normal
$filename = $row['filename'];
$fsize = $row['docsize'];
$filename = $doc->filename;
$fsize = $doc->docsize;
}
if (file_exists($file)) {
// send file to caller
header('Content-Description: File Transfer');
header('Content-Type: ' . $row['mimetype']);
header('Content-Type: ' . $doc->mimetype);
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');