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', 'Document created successfully.'); header('Location: /admin_documents.php'); exit; } elseif ($action === 'update_document') { if (!$id) { throw new RuntimeException('Invalid Document ID.'); } library_update_document($id, $_POST, $_FILES['document_file'] ?? [], $_FILES['cover_file'] ?? []); library_set_flash('success', 'Document updated successfully.'); header('Location: /admin_documents.php'); exit; } elseif ($action === 'delete_document') { if (!$id) { throw new RuntimeException('Invalid Document ID.'); } library_delete_document($id); library_set_flash('success', 'Document deleted successfully.'); header('Location: /admin_documents.php'); exit; } } catch (Throwable $exception) { $errors[] = $exception->getMessage(); error_log('AdminDocuments Error: ' . $exception->getMessage()); } } } // Search Logic $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $documents = library_fetch_documents(false); if ($search !== '') { $documents = array_filter($documents, function($doc) use ($search) { return stripos($doc['title_en'] ?? '', $search) !== false || stripos($doc['title_ar'] ?? '', $search) !== false || stripos($doc['author'] ?? '', $search) !== false; }); } $categories = library_get_categories(); $allSubcategories = library_get_subcategories(null); $types = library_get_types(); admin_render_header('Material Entry', 'documents'); ?>
Manage library documents (Material Entry).