[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
campus_repo
/
public
/
[
Home
]
File: search.php
<?php if (session_status() === PHP_SESSION_NONE) { session_start(); } require_once __DIR__ . '/../config/config.php'; require_once __DIR__ . '/../src/Database.php'; require_once __DIR__ . '/../src/Utils.php'; $pdo = Database::getConnection(); $query = ''; $results = []; if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['q'])) { $query = trim($_GET['q']); $stmt = $pdo->prepare("SELECT id, title, authors, year, subject_area, file_path FROM documents WHERE status = 'approved' AND (title LIKE ? OR authors LIKE ? OR keywords LIKE ? OR subject_area LIKE ?) ORDER BY year DESC"); $like = "%$query%"; $stmt->execute([$like, $like, $like, $like]); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); } else { // default: tampilkan semua approved $stmt = $pdo->query("SELECT id, title, authors, year, subject_area, file_path FROM documents WHERE status = 'approved' ORDER BY year DESC"); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); } ?> <?php include 'header.php'; ?> <h2>Pencarian Dokumen</h2> <form method="get" action="search.php"> <input type="text" name="q" value="<?= Utils::sanitize($query) ?>" placeholder="Cari judul, penulis, kata kunci..."> <button type="submit">Cari</button> </form> <table border="1" cellpadding="8" cellspacing="0" style="margin-top:20px; width:100%;"> <thead> <tr style="background-color:#eee;"> <th>Judul</th> <th>Penulis</th> <th>Tahun</th> <th>Bidang</th> <th>File</th> </tr> </thead> <tbody> <?php if (count($results) > 0): ?> <?php foreach ($results as $doc): ?> <tr> <td><?= Utils::sanitize($doc['title']) ?></td> <td><?= Utils::sanitize($doc['authors']) ?></td> <td><?= Utils::sanitize($doc['year']) ?></td> <td><?= Utils::sanitize($doc['subject_area']) ?></td> <td><a href="uploads/<?= Utils::sanitize($doc['file_path']) ?>" target="_blank">Download</a></td> </tr> <?php endforeach; ?> <?php else: ?> <tr><td colspan="5">Tidak ada dokumen ditemukan.</td></tr> <?php endif; ?> </tbody> </table> <?php include 'footer.php'; ?>