0) { $errors[] = 'The uploaded file exceeds the server limit (post_max_size). Please try a smaller file or contact admin.'; } else { $action = $_POST['action'] ?? ''; $id = isset($_POST['id']) ? (int)$_POST['id'] : 0; try { if ($action === 'create_document') { library_create_document($_POST, $_FILES['document_file'] ?? [], $_FILES['cover_file'] ?? []); library_set_flash('success', library_trans('document_created_success')); header('Location: /admin_documents.php'); exit; } elseif ($action === 'update_document') { if (!$id) { throw new RuntimeException(library_trans('invalid_document_id')); } library_update_document($id, $_POST, $_FILES['document_file'] ?? [], $_FILES['cover_file'] ?? []); library_set_flash('success', library_trans('document_updated_success')); header('Location: /admin_documents.php'); exit; } elseif ($action === 'delete_document') { if (!$id) { throw new RuntimeException(library_trans('invalid_document_id')); } library_delete_document($id); library_set_flash('success', library_trans('document_deleted_success')); header('Location: /admin_documents.php'); exit; } } catch (Throwable $exception) { $errors[] = $exception->getMessage(); error_log('AdminDocuments Error: ' . $exception->getMessage()); } } } // Search & Pagination Logic $page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1; $limit = 10; $offset = ($page - 1) * $limit; $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $result = library_fetch_documents_paginated(false, ['q' => $search], $limit, $offset); $documents = $result['data']; $totalDocuments = $result['total']; $totalPages = (int)ceil($totalDocuments / $limit); $categories = library_get_categories(); $allSubcategories = library_get_subcategories(null); $types = library_get_types(); $lang = library_get_language(); admin_render_header(library_trans('material_entry'), 'documents'); ?>

# Cover

1): ?>