File "review-20260511150033.php"

Full Path: /home/alphpwcp/previewstream.online/old/admin/review-20260511150033.php
File size: 4 KB
MIME-type: text/x-php
Charset: utf-8

<?php
header('Content-Type: text/html; charset=utf-8');
session_start();
include 'db.php';

$id = $_GET['id'] ?? 0;

// Fetch company (now also fetch description)
$stmt = $pdo->prepare("
  SELECT c.*, cat.name AS category
  FROM companies c
  LEFT JOIN categories cat ON c.category_id = cat.id
  WHERE c.id=?
");
$stmt->execute([$id]);
$company = $stmt->fetch();

if (!$company) { die("Company not found. <a href='index.php'>Back to home</a>"); }

// Add new review
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_SESSION['user_id'])) {
    $rating = $_POST['rating'];
    $comment = $_POST['review_text'];
    $pdo->prepare('INSERT INTO reviews (user_id, company_id, rating, comment) VALUES (?,?,?,?)')
        ->execute([$_SESSION['user_id'], $id, $rating, $comment]);
    header("Location: review.php?id=$id");
    exit;
}

// Fetch reviews
$stmt = $pdo->prepare("
  SELECT r.*, u.username, u.profile_image AS user_image 
  FROM reviews r
  LEFT JOIN users u ON r.user_id = u.id
  WHERE r.company_id=?
  ORDER BY r.id DESC
");
$stmt->execute([$id]);
$reviews = $stmt->fetchAll();

// Stats
$stmt = $pdo->prepare("SELECT ROUND(AVG(rating),1) AS avg_rating, MAX(rating) AS highest_rating, COUNT(*) AS total_reviews FROM reviews WHERE company_id=?");
$stmt->execute([$id]);
$stats = $stmt->fetch();

// Latest reviews
$latestReviews = $pdo->query("
  SELECT r.comment, r.rating, u.username, c.name AS company_name
  FROM reviews r
  JOIN users u ON r.user_id = u.id
  JOIN companies c ON r.company_id = c.id
  ORDER BY r.id DESC
  LIMIT 5
")->fetchAll();

// Top rated companies
$topCompanies = $pdo->query("
  SELECT c.id, c.name, c.image, ROUND(AVG(r.rating),1) AS avg_rating
  FROM companies c
  JOIN reviews r ON c.id = r.company_id
  GROUP BY c.id
  HAVING COUNT(r.id) >= 1
  ORDER BY avg_rating DESC
  LIMIT 5
")->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?= htmlspecialchars($company['name']) ?> - Review Stream</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Sans-serif fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Raleway&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif&display=swap" rel="stylesheet">


<!-- Favicon -->
<link rel="icon" href="/favicon.png" type="image/png" />



<style>
  body {
    margin: 0;
    padding: 0; /* removed huge padding */
    font-family: Arial, sans-serif;
    background: #f5f5f5;
	padding-bottom: 200px !important;
  }
  .container { max-width: 1200px; margin: auto; padding: 20px; }
  .content-layout { display: flex; gap: 20px; flex-wrap: wrap; }
  .main-content { flex: 3; min-width: 250px; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
  .sidebar { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 15px; }
  .sidebar-card { background: #fff; padding: 12px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
  .star-box {
    display: inline-block;
    width: 22px;
    height: 22px;
    margin-right: 2px;
    background-color: #d3d3d3;
    color: white;
    text-align: center;
    line-height: 22px;
    font-size: 14px;
    border-radius: 3px;
  }
  .star-box.filled {
    background-color: #00b67a;
  }
  .about-company {
    background: #fafafa;
    margin-top: 25px;
    padding: 15px;
    border-left: 4px solid #00b67a;
    border-radius: 6px;
  }
  .about-company h3 {
    margin-top: 0;
    color: #333;
  }
  .topbar {
    background