294 lines
16 KiB
PHP
294 lines
16 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || !in_array($_SESSION['role'], ['Admin', 'Teacher', 'Super Admin'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$school_id = $_SESSION['school_id'];
|
|
$success = '';
|
|
$error = '';
|
|
|
|
// Handle Resource Upload
|
|
if (isset($_POST['upload_resource'])) {
|
|
$title = $_POST['title'];
|
|
$description = $_POST['description'];
|
|
$grade = $_POST['grade'];
|
|
$subject = $_POST['subject'];
|
|
$is_public = isset($_POST['is_public']) ? 1 : 0;
|
|
|
|
try {
|
|
$stmt = db()->prepare("INSERT INTO resources (title, description, teacher_id, school_id, grade, subject, is_public) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
$stmt->execute([$title, $description, $user_id, $school_id, $grade, $subject, $is_public]);
|
|
$success = "Resource shared successfully!";
|
|
} catch (PDOException $e) {
|
|
$error = "Failed to share resource: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Handle Forum Post
|
|
if (isset($_POST['create_post'])) {
|
|
$title = $_POST['title'];
|
|
$content = $_POST['content'];
|
|
$is_public = isset($_POST['is_public']) ? 1 : 0;
|
|
|
|
try {
|
|
$stmt = db()->prepare("INSERT INTO forum_posts (title, content, author_id, school_id, is_public) VALUES (?, ?, ?, ?, ?)");
|
|
$stmt->execute([$title, $content, $user_id, $school_id, $is_public]);
|
|
$success = "Topic posted successfully!";
|
|
} catch (PDOException $e) {
|
|
$error = "Failed to post topic: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Fetch Resources (Own school or Public from other schools)
|
|
$resources_query = "
|
|
SELECT r.*, u.email as teacher_email, s.name as school_name
|
|
FROM resources r
|
|
JOIN users u ON r.teacher_id = u.id
|
|
JOIN schools s ON r.school_id = s.id
|
|
WHERE r.school_id = :school_id OR r.is_public = 1
|
|
ORDER BY r.created_at DESC
|
|
";
|
|
$resources_stmt = db()->prepare($resources_query);
|
|
$resources_stmt->execute(['school_id' => $school_id]);
|
|
$resources = $resources_stmt->fetchAll();
|
|
|
|
// Fetch Forum Posts (Own school or Public from other schools)
|
|
$posts_query = "
|
|
SELECT p.*, u.email as author_email, s.name as school_name,
|
|
(SELECT COUNT(*) FROM forum_comments WHERE post_id = p.id) as comment_count
|
|
FROM forum_posts p
|
|
JOIN users u ON p.author_id = u.id
|
|
JOIN schools s ON p.school_id = s.id
|
|
WHERE p.school_id = :school_id OR p.is_public = 1
|
|
ORDER BY p.created_at DESC
|
|
";
|
|
$posts_stmt = db()->prepare($posts_query);
|
|
$posts_stmt->execute(['school_id' => $school_id]);
|
|
$posts = $posts_stmt->fetchAll();
|
|
|
|
$pageTitle = "School Collaboration Hub";
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<div>
|
|
<h2><i class="bi bi-people-fill me-2 text-primary"></i>Collaboration Hub</h2>
|
|
<p class="text-muted small mb-0">Share resources and ideas with your school and the wider community.</p>
|
|
</div>
|
|
<div class="btn-group shadow-sm">
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadModal">
|
|
<i class="bi bi-upload me-2"></i>Share Resource
|
|
</button>
|
|
<button class="btn btn-outline-primary" data-bs-toggle="modal" data-bs-target="#postModal">
|
|
<i class="bi bi-chat-dots me-2"></i>New Topic
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success alert-dismissible fade show shadow-sm" role="alert">
|
|
<i class="bi bi-check-circle-fill me-2"></i><?php echo $success; ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<ul class="nav nav-tabs mb-4 border-0" id="hubTabs" role="tablist">
|
|
<li class="nav-item">
|
|
<button class="nav-link active fw-bold border-0 bg-transparent px-4" id="resources-tab" data-bs-toggle="tab" data-bs-target="#resources" type="button" role="tab">Resources</button>
|
|
</li>
|
|
<li class="nav-item">
|
|
<button class="nav-link fw-bold border-0 bg-transparent px-4" id="forum-tab" data-bs-toggle="tab" data-bs-target="#forum" type="button" role="tab">Discussion Forum</button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tab-content" id="hubTabsContent">
|
|
<!-- Resources Tab -->
|
|
<div class="tab-pane fade show active" id="resources" role="tabpanel">
|
|
<div class="row">
|
|
<?php if (empty($resources)): ?>
|
|
<div class="col-12 text-center py-5 bg-light rounded-4">
|
|
<i class="bi bi-folder2-open display-1 text-muted opacity-25"></i>
|
|
<p class="mt-3 text-muted">No resources shared yet. Be the first!</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($resources as $res): ?>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100 shadow-sm border-0 position-relative">
|
|
<?php if ($res['is_public']): ?>
|
|
<span class="badge bg-success position-absolute top-0 end-0 m-3 shadow-sm">Public</span>
|
|
<?php endif; ?>
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between mb-2">
|
|
<span class="badge bg-light text-dark border"><?php echo htmlspecialchars($res['subject']); ?></span>
|
|
<span class="badge bg-light text-dark border">Grade <?php echo htmlspecialchars($res['grade']); ?></span>
|
|
</div>
|
|
<h5 class="card-title fw-bold"><?php echo htmlspecialchars($res['title']); ?></h5>
|
|
<p class="card-text text-muted small"><?php echo htmlspecialchars($res['description']); ?></p>
|
|
<div class="text-muted smaller mb-0">
|
|
<i class="bi bi-building me-1"></i> <?php echo htmlspecialchars($res['school_name']); ?>
|
|
</div>
|
|
</div>
|
|
<div class="card-footer bg-white border-0 py-3">
|
|
<div class="d-flex align-items-center mb-3">
|
|
<div class="flex-shrink-0">
|
|
<div class="avatar-xs bg-soft-primary text-primary rounded-circle d-flex align-items-center justify-content-center" style="width: 32px; height: 32px; background: rgba(13, 110, 253, 0.1);">
|
|
<?= strtoupper(substr($res['teacher_email'], 0, 1)) ?>
|
|
</div>
|
|
</div>
|
|
<div class="flex-grow-1 ms-2">
|
|
<div class="small fw-bold text-dark"><?php echo explode('@', $res['teacher_email'])[0]; ?></div>
|
|
<div class="text-muted smaller"><?php echo date('M d, Y', strtotime($res['created_at'])); ?></div>
|
|
</div>
|
|
</div>
|
|
<button class="btn btn-sm btn-primary w-100 rounded-pill">
|
|
<i class="bi bi-download me-2"></i>Download
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Forum Tab -->
|
|
<div class="tab-pane fade" id="forum" role="tabpanel">
|
|
<div class="card shadow-sm border-0 rounded-4">
|
|
<div class="list-group list-group-flush rounded-4">
|
|
<?php if (empty($posts)): ?>
|
|
<div class="text-center py-5">
|
|
<i class="bi bi-chat-left-dots display-1 text-muted opacity-25"></i>
|
|
<p class="mt-3 text-muted">Start a conversation with your colleagues.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($posts as $post): ?>
|
|
<div class="list-group-item list-group-item-action py-4 border-0 border-bottom position-relative">
|
|
<?php if ($post['is_public']): ?>
|
|
<span class="badge bg-success-soft text-success border border-success rounded-pill position-absolute top-0 end-0 m-3" style="background: rgba(25, 135, 84, 0.1);">Community</span>
|
|
<?php endif; ?>
|
|
<div class="d-flex w-100 justify-content-between align-items-start pe-5">
|
|
<div class="me-3">
|
|
<h5 class="mb-1 fw-bold"><?php echo htmlspecialchars($post['title']); ?></h5>
|
|
<p class="mb-2 text-muted"><?php echo htmlspecialchars(substr($post['content'], 0, 150)) . '...'; ?></p>
|
|
<div class="small d-flex align-items-center gap-2">
|
|
<span class="text-primary fw-bold"><?php echo explode('@', $post['author_email'])[0]; ?></span>
|
|
<span class="text-muted">• <?php echo htmlspecialchars($post['school_name']); ?></span>
|
|
<span class="text-muted">• <?php echo date('M d, Y', strtotime($post['created_at'])); ?></span>
|
|
</div>
|
|
</div>
|
|
<div class="text-end">
|
|
<span class="badge rounded-pill bg-light text-primary px-3 py-2 border">
|
|
<i class="bi bi-chat-fill me-1"></i> <?php echo $post['comment_count']; ?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Upload Modal -->
|
|
<div class="modal fade" id="uploadModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content border-0 shadow-lg rounded-4">
|
|
<div class="modal-header border-0 pb-0">
|
|
<h5 class="modal-title fw-bold">Share Learning Resource</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<form method="POST">
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label class="form-label">Resource Title</label>
|
|
<input type="text" name="title" class="form-control rounded-3" required placeholder="e.g. Grade 10 Math Exam Prep">
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label">Grade</label>
|
|
<select name="grade" class="form-select rounded-3" required>
|
|
<option value="8">Grade 8</option>
|
|
<option value="9">Grade 9</option>
|
|
<option value="10">Grade 10</option>
|
|
<option value="11">Grade 11</option>
|
|
<option value="12">Grade 12</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label">Subject</label>
|
|
<input type="text" name="subject" class="form-control rounded-3" required placeholder="e.g. Mathematics">
|
|
</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Description</label>
|
|
<textarea name="description" class="form-control rounded-3" rows="3" placeholder="Briefly describe the resource..."></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<div class="form-check form-switch p-3 bg-light rounded-3 border">
|
|
<input class="form-check-input ms-0 me-2" type="checkbox" name="is_public" id="isPublicResource" checked>
|
|
<label class="form-check-label fw-bold" for="isPublicResource">Make Public (School Collaboration)</label>
|
|
<div class="form-text mt-0 ms-0">Allow teachers from other schools to see and download this.</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer border-0">
|
|
<button type="button" class="btn btn-light rounded-pill px-4" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" name="upload_resource" class="btn btn-primary rounded-pill px-4">Upload & Share</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Post Modal -->
|
|
<div class="modal fade" id="postModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content border-0 shadow-lg rounded-4">
|
|
<div class="modal-header border-0 pb-0">
|
|
<h5 class="modal-title fw-bold">Start Discussion Topic</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<form method="POST">
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label class="form-label">Topic Title</label>
|
|
<input type="text" name="title" class="form-control rounded-3" required placeholder="What do you want to discuss?">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Content</label>
|
|
<textarea name="content" class="form-control rounded-3" rows="5" required placeholder="Share your thoughts or ask a question..."></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<div class="form-check form-switch p-3 bg-light rounded-3 border">
|
|
<input class="form-check-input ms-0 me-2" type="checkbox" name="is_public" id="isPublicPost" checked>
|
|
<label class="form-check-label fw-bold" for="isPublicPost">Make Public (School Collaboration)</label>
|
|
<div class="form-text mt-0 ms-0">Allow the wider teaching community to see and reply.</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer border-0">
|
|
<button type="button" class="btn btn-light rounded-pill px-4" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" name="create_post" class="btn btn-primary rounded-pill px-4">Post Topic</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.nav-tabs .nav-link { color: #6c757d; transition: all 0.2s; }
|
|
.nav-tabs .nav-link.active { color: #0d6efd; border-bottom: 3px solid #0d6efd !important; }
|
|
.nav-tabs .nav-link:hover { color: #0d6efd; }
|
|
.smaller { font-size: 0.8rem; }
|
|
.bg-soft-primary { background-color: rgba(13, 110, 253, 0.1); }
|
|
</style>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|