Submit a New Link
Thank you for your submission! It will be reviewed shortly.
query("SELECT * FROM categories WHERE visibility = 1 ORDER BY display_order ASC, name ASC")->fetchAll(); $subcategories = []; if (!empty($categories)) { $stmt = $pdo->query("SELECT * FROM subcategories ORDER BY name ASC"); while ($row = $stmt->fetch()) { $subcategories[$row['category_id']][] = $row; } } if ($_SERVER["REQUEST_METHOD"] == "POST") { $title = trim($_POST['title'] ?? ''); $url = trim($_POST['url'] ?? ''); $description = trim($_POST['description'] ?? ''); $subcategory_id = $_POST['subcategory_id'] ?? null; if (empty($title)) $errors[] = 'Title is required.'; if (empty($url)) $errors[] = 'URL is required.'; if (!filter_var($url, FILTER_VALIDATE_URL)) $errors[] = 'Invalid URL.'; if (empty($subcategory_id)) $errors[] = 'Subcategory is required.'; if (empty($errors)) { // Determine status based on user role $status = ($_SESSION['user_role'] === 'admin' || $_SESSION['user_role'] === 'power_user') ? 'approved' : 'pending'; // For now, thumbnail is not implemented $thumbnail_url = null; if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['error'] === UPLOAD_ERR_OK) { $uploadedImagePath = ImageProcessor::processAndSaveImage($_FILES['thumbnail']); if ($uploadedImagePath) { $thumbnail_url = $uploadedImagePath; } else { $errors[] = 'Failed to process uploaded image. Please ensure it is a valid image file (JPEG, PNG, GIF).'; } } try { $stmt = $pdo->prepare("INSERT INTO links (user_id, subcategory_id, title, url, description, thumbnail_url, status) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$_SESSION['user_id'], $subcategory_id, $title, $url, $description, $thumbnail_url, $status]); $success = true; } catch (PDOException $e) { $errors[] = "Database error: " . $e->getMessage(); } } } ?>
Thank you for your submission! It will be reviewed shortly.