Add(print_r($_FILES, true)); if (empty($_FILES['files']['tmp_name']) ) { $g_warning->Add(_('No file for upload submitted. Try again by selecting a file first.')); $action = ACT_ADD; break; } $nerr = 0; $file_name = $_FILES['files']['name']; $file_tmp = $_FILES['files']['tmp_name']; $file_type = $_FILES['files']['type']; $file_size = $_FILES['files']['size']; $file_ext = strtolower(end(explode('.', $_FILES['files']['name']))); $file_mimetype = mime_content_type($file_tmp); if (!in_array($file_mimetype, $g_doc_mimetypes)) { $g_error->Add(sprintf(_("Mimetype '%s' not allowed for upload."), $file_mimetype)); $action = ACT_ADD; break; }; if ($file_type != $file_mimetype) { $g_warning->Add(sprintf(_("Mimetype mismatch: '%s'."), $file_type)); } // ok let's go $file_hash = md5_file($file_tmp); $file_timestamp = date('Y-m-d H:i:s', filemtime($file_tmp)); // check if the file already exists, in which case issue // a notice and display the existing document $sth = $pdo->prepare("SELECT docid FROM document WHERE hash=?"); $sth->execute([$file_hash]); $id = $sth->fetchColumn(); if ($id) { $g_warning->Add(_('Document already exists!')); $action = ACT_VIEW; break; } if ($file_size > $g_doc_maxsize) { $g_error->Add(sprintf(_('File to big: %s.%s'), $file_name, $file_type)); break; } switch ($file_mimetype) { case 'application/pdf': $p[':doctype'] = 'generic'; $p[':pages'] = pdf_get_pagecount($file_tmp); $prefix = 'doc'; break; case 'image/svg+xml': $p[':doctype'] = 'drawing'; $prefix = 'drw'; break; case 'image/png': case 'image/jpeg': $p[':doctype'] = 'picture'; $prefix = 'pic'; break; } $p[':mimetype'] = $file_mimetype; $p[':filename'] = $file_name; $p[':extension'] = $file_ext; $p[':hash'] = $file_hash; $p[':doctime'] = $file_timestamp; $p[':docsize'] = $file_size; $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[':doctype'] = gpc_get_string($_POST, 'doctype'); $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; break; case 'delete': // Security token needed! /*if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) { $g_error->Add(_('Delete prohibited, invalid security token!')); $action = ACT_VIEW; break; } unset($_SESSION['token']); */ $sql = "SELECT doctype, extension FROM document WHERE docid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $doc = $sth->fetch(PDO::FETCH_OBJ); // clean thumbs $thumbdir = $g_doc_basepath . '/thumbs/'; $pattern = sprintf('%s-%06d*', $g_doc_typemap[$doctype], $docid); foreach (glob($thumbdir . $pattern) as $f) { // unlink($f); $g_success->Add($f); } // remove document $g_success->Add(_('Deleted document %s'), $docfilename); // sprintf('%s/%s-%06d.%s', $g_doc_basepath, $dtmap[$row['doctype']], $docid, $row['extension']); /* $sth = $pdo->prepare("DELETE FROM document WHERE docid=?"); try { $sth->execute([$id]); } catch (PDOexception $e) { $g_error->Add(sprintf(_('SQL-Error: %s', $e->getMessage()))); }*/ //$action = ACT_DEFAULT; $action = ACT_DELETE; break; case 'addref': $opt_reftype = db_load_enum('docref', 'reftype'); $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 $drid = gpc_get_int($_GET, 'drid'); $sql = "DELETE FROM docref WHERE drid=?"; $sth = $pdo->prepare($sql); $sth->execute([$drid]); $g_message->Add(_('Removed document reference')); $action = ACT_VIEW; break; default: $g_error->Add(sprintf(_('Unknown function!'), $submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== require 'header.php'; // ========== PAGE CONTENT ==================================================== if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= page_caption_search($pagetitle); $flt = db_get_filter($user->id, 209); $w = array(); $p = array(); 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.'%'; } $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(); // Filter $opt_special = array( 'all' => _('― all ―'), ); ?>
', "\n"; echo "\n"; echo "| ', _('Document type')," | ", $document->doctype, " |
|---|---|
| ', _('Preview'), ' | ';
// echo '';
echo ' ';
echo '';
echo ' '; // gallery
?>
';
echo " |
| ', _('Drawing'), ' | '; echo '|
| ', _('PDF'), ' | '; // Download link echo '', $document->title ?? _('Download'), ' (', sprintf(_('%d Pages'), $document->pages), ')'; echo " |
| ', _('Mimetype')," | ", $document->mimetype, " |
| ', _('Filename')," | ", $document->filename, " |
| ', _('File size')," | ", format_filesize($document->docsize), " |
| ', _('Upload date')," | ", $document->doctime, " |
| ', _('Title')," | ", $document->title, " |
| ', _('Remarks')," | ", $document->remarks, " |
', sprintf(_('Record no. %d'), $id), "
\n"; echo 'Dokument: ', $document->filename, "
"; echo 'Title: ', $document->title, "
"; echo '', _('Deleting a document item is final. There is no way back. Only delete if you are absolute sure.'), "
\n"; $_SESSION['token'] = bin2hex(random_bytes(8)); form_delete_buttons($g_scriptname, $id, $_SESSION['token']); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '', _('Unknown function call: Please report to system development!'), "
\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';