Path : /home/vishqocm/pcib.in/
File Upload :
Current File : /home/vishqocm//pcib.in/instructor-details.php

<?php
// Start session
session_start();

// Include database configuration
require_once 'admin/database/db_config.php';

// Check if database connection is valid
if (!$conn || $conn->connect_error) {
    // Redirect to the database repair tool
    header('Location: admin/database/db_repair.php');
    exit;
}

// Get instructor ID from URL
$instructor_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// If no ID provided, redirect to instructors list
if ($instructor_id <= 0) {
    header('Location: instructors.php');
    exit;
}

// Check which columns exist in the users table
$column_checks = [
    'designation' => $conn->query("SHOW COLUMNS FROM users LIKE 'designation'")->num_rows > 0,
    'expertise' => $conn->query("SHOW COLUMNS FROM users LIKE 'expertise'")->num_rows > 0,
    'bio' => $conn->query("SHOW COLUMNS FROM users LIKE 'bio'")->num_rows > 0
];

// Build query based on column availability
$select_columns = "u.id, u.first_name, u.last_name, u.email, u.phone, u.profile_image, u.role, u.status";

if ($column_checks['bio']) {
    $select_columns .= ", u.bio";
}

if ($column_checks['designation']) {
    $select_columns .= ", u.designation";
}

if ($column_checks['expertise']) {
    $select_columns .= ", u.expertise";
}

// Add the social media fields if they exist
if ($conn->query("SHOW COLUMNS FROM users LIKE 'facebook'")->num_rows > 0) {
    $select_columns .= ", u.facebook";
}

if ($conn->query("SHOW COLUMNS FROM users LIKE 'twitter'")->num_rows > 0) {
    $select_columns .= ", u.twitter";
}

if ($conn->query("SHOW COLUMNS FROM users LIKE 'linkedin'")->num_rows > 0) {
    $select_columns .= ", u.linkedin";
}

if ($conn->query("SHOW COLUMNS FROM users LIKE 'instagram'")->num_rows > 0) {
    $select_columns .= ", u.instagram";
}

$query = "SELECT $select_columns,
         COUNT(DISTINCT c.id) AS course_count,
         COUNT(DISTINCT e.id) AS student_count
         FROM users u
         LEFT JOIN courses c ON c.instructor_id = u.id
         LEFT JOIN enrollments e ON e.course_id = c.id
         WHERE u.id = ? AND u.role = 'instructor' AND u.status = 'active'
         GROUP BY u.id";

$stmt = $conn->prepare($query);
$stmt->bind_param("i", $instructor_id);
$stmt->execute();
$result = $stmt->get_result();

// If instructor not found, redirect to instructors list
if ($result->num_rows === 0) {
    header('Location: instructors.php');
    exit;
}

$instructor = $result->fetch_assoc();

// Create social links array from individual fields
$social_links = [];
if (isset($instructor['facebook']) && !empty($instructor['facebook'])) {
    $social_links['facebook'] = $instructor['facebook'];
}
if (isset($instructor['twitter']) && !empty($instructor['twitter'])) {
    $social_links['twitter'] = $instructor['twitter'];
}
if (isset($instructor['linkedin']) && !empty($instructor['linkedin'])) {
    $social_links['linkedin'] = $instructor['linkedin'];
}
if (isset($instructor['instagram']) && !empty($instructor['instagram'])) {
    $social_links['instagram'] = $instructor['instagram'];
}

// Set old social_links for backward compatibility
$instructor['social_links'] = $social_links;

// Get instructor profile image
$profile_image = !empty($instructor['profile_image']) ? $instructor['profile_image'] : 'assets/images/avatar-placeholder.jpg';

// Set expertise array
$expertise = [];
if (isset($instructor['expertise']) && !empty($instructor['expertise'])) {
    $expertise = array_filter(array_map('trim', explode(',', $instructor['expertise'])));
}

// Get instructor courses
$courses_query = "SELECT c.*, cat.name as category_name
                FROM courses c
                LEFT JOIN categories cat ON c.category = cat.id
                WHERE c.instructor_id = ? AND c.status = 'active'
                ORDER BY c.is_featured DESC, c.id DESC
                LIMIT 6";

$courses_stmt = $conn->prepare($courses_query);
$courses_stmt->bind_param("i", $instructor_id);
$courses_stmt->execute();
$courses_result = $courses_stmt->get_result();
$courses = [];

if ($courses_result && $courses_result->num_rows > 0) {
    while ($row = $courses_result->fetch_assoc()) {
        $courses[] = $row;
    }
}

// Include header
include 'includes/header.php';

// Set page title
$page_title = "{$instructor['first_name']} {$instructor['last_name']} - Instructor Profile";
?>

<!-- Instructor Profile Header -->
<div class="instructor-profile-header">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-8">
                <div class="profile-info">
                    <div class="profile-image">
                        <img src="<?php echo $profile_image; ?>" alt="<?php echo htmlspecialchars($instructor['first_name'] . ' ' . $instructor['last_name']); ?>">
                    </div>
                    <div class="profile-content">
                        <h1><?php echo htmlspecialchars($instructor['first_name'] . ' ' . $instructor['last_name']); ?></h1>
                        <p class="designation"><?php echo htmlspecialchars($instructor['designation'] ?? 'Instructor'); ?></p>
                        
                        <div class="profile-stats">
                            <div class="stat-item">
                                <i class="fas fa-book-open"></i>
                                <span><?php echo $instructor['course_count']; ?> Courses</span>
                            </div>
                            <?php if (!empty($expertise)): ?>
                            <div class="stat-item expertise-list">
                                <i class="fas fa-laptop-code"></i>
                                <span>
                                    <?php echo htmlspecialchars(implode(', ', array_slice($expertise, 0, 3))); ?>
                                    <?php if (count($expertise) > 3): ?>
                                        <span class="more-badge">+<?php echo count($expertise) - 3; ?> more</span>
                                    <?php endif; ?>
                                </span>
                            </div>
                            <?php endif; ?>
                        </div>
                        
                        <div class="social-links">
                            <?php if (!empty($social_links['facebook'])): ?>
                                <a href="<?php echo htmlspecialchars($social_links['facebook']); ?>" class="social-icon" target="_blank" title="Facebook">
                                    <i class="fab fa-facebook-f"></i>
                                </a>
                            <?php endif; ?>
                            
                            <?php if (!empty($social_links['twitter'])): ?>
                                <a href="<?php echo htmlspecialchars($social_links['twitter']); ?>" class="social-icon" target="_blank" title="Twitter">
                                    <i class="fab fa-twitter"></i>
                                </a>
                            <?php endif; ?>
                            
                            <?php if (!empty($social_links['linkedin'])): ?>
                                <a href="<?php echo htmlspecialchars($social_links['linkedin']); ?>" class="social-icon" target="_blank" title="LinkedIn">
                                    <i class="fab fa-linkedin-in"></i>
                                </a>
                            <?php endif; ?>
                            
                            <?php if (!empty($social_links['instagram'])): ?>
                                <a href="<?php echo htmlspecialchars($social_links['instagram']); ?>" class="social-icon" target="_blank" title="Instagram">
                                    <i class="fab fa-instagram"></i>
                                </a>
                            <?php endif; ?>
                            
                            <?php if (!empty($social_links['youtube'])): ?>
                                <a href="<?php echo htmlspecialchars($social_links['youtube']); ?>" class="social-icon" target="_blank" title="YouTube">
                                    <i class="fab fa-youtube"></i>
                                </a>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <nav aria-label="breadcrumb" class="instructor-breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                        <li class="breadcrumb-item"><a href="instructors.php">Instructors</a></li>
                        <li class="breadcrumb-item active" aria-current="page"><?php echo htmlspecialchars($instructor['first_name']); ?></li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>

<!-- Main Content -->
<section class="instructor-detail-content py-5">
    <div class="container">
        <div class="row">
            <!-- Left Column - Bio and Expertise -->
            <div class="col-lg-4 mb-4 mb-lg-0">
                <div class="content-card">
                    <h2 class="section-title">About <?php echo htmlspecialchars($instructor['first_name']); ?></h2>
                    
                    <div class="bio-content">
                        <?php if (!empty($instructor['bio'])): ?>
                            <?php echo nl2br(htmlspecialchars($instructor['bio'])); ?>
                        <?php else: ?>
                            <p>No biography information available for this instructor.</p>
                        <?php endif; ?>
                    </div>
                    
                    <?php if (!empty($expertise)): ?>
                    <div class="expertise-section mt-4">
                        <h3>Expertise & Skills</h3>
                        <div class="expertise-tags">
                            <?php foreach ($expertise as $skill): ?>
                                <span class="expertise-tag"><?php echo htmlspecialchars($skill); ?></span>
                            <?php endforeach; ?>
                        </div>
                    </div>
                    <?php endif; ?>
                    
                    <div class="contact-section mt-4">
                        <h3>Contact</h3>
                        <a href="mailto:<?php echo htmlspecialchars($instructor['email']); ?>" class="contact-button">
                            <i class="fas fa-envelope"></i> Contact Instructor
                        </a>
                    </div>
                </div>
            </div>
            
            <!-- Right Column - Courses -->
            <div class="col-lg-8">
                <div class="content-card">
                    <h2 class="section-title">Courses by <?php echo htmlspecialchars($instructor['first_name']); ?></h2>
                    
                    <?php if (!empty($courses)): ?>
                        <div class="row courses-grid">
                            <?php foreach ($courses as $course): 
                                // Get course image
                                $course_image = !empty($course['image']) ? $course['image'] : 'assets/img/courses/default.jpg';
                            ?>
                            <div class="col-md-6 mb-4">
                                <div class="course-card">
                                    <div class="course-image">
                                        <img src="<?php echo $course_image; ?>" alt="<?php echo htmlspecialchars($course['title']); ?>">
                                        <?php if (isset($course['is_featured']) && $course['is_featured'] == 1): ?>
                                            <div class="featured-badge">
                                                <i class="fas fa-star"></i> Featured
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                    
                                    <div class="course-content">
                                        <div class="course-category">
                                            <?php echo htmlspecialchars($course['category_name'] ?? 'Uncategorized'); ?>
                                        </div>
                                        
                                        <h3 class="course-title">
                                            <a href="course-details.php?id=<?php echo $course['id']; ?>">
                                                <?php echo htmlspecialchars($course['title']); ?>
                                            </a>
                                        </h3>
                                        
                                        <div class="course-meta">
                                            <div class="meta-item">
                                                <i class="fas fa-clock"></i> <?php echo $course['duration'] ?? '8 weeks'; ?>
                                            </div>
                                            <div class="meta-item">
                                                <i class="fas fa-signal"></i> <?php echo $course['level'] ?? 'Beginner'; ?>
                                            </div>
                                        </div>
                                        
                                        <div class="course-price">
                                            ₹<?php echo number_format($course['price'], 0); ?>
                                        </div>
                                        
                                        <a href="course-details.php?id=<?php echo $course['id']; ?>" class="course-details-link">
                                            View Details <i class="fas fa-arrow-right"></i>
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                        
                        <?php if ($instructor['course_count'] > count($courses)): ?>
                            <div class="text-center mt-4">
                                <a href="courses.php?instructor=<?php echo $instructor_id; ?>" class="view-all-button">
                                    View All <?php echo $instructor['course_count']; ?> Courses <i class="fas fa-arrow-right"></i>
                                </a>
                            </div>
                        <?php endif; ?>
                    <?php else: ?>
                        <div class="no-courses-message">
                            <i class="fas fa-book-open"></i>
                            <h3>No Courses Available</h3>
                            <p>This instructor doesn't have any active courses at the moment.</p>
                            <a href="instructors.php" class="btn btn-primary mt-3">Browse Other Instructors</a>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
/* Instructor Profile Header */
.instructor-profile-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    padding: 80px 0;
    color: white;
}

.profile-info {
    display: flex;
    align-items: center;
}

.profile-image {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    overflow: hidden;
    border: 5px solid rgba(255, 255, 255, 0.3);
    margin-right: 30px;
    flex-shrink: 0;
}

.profile-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-content h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.designation {
    font-size: 1.2rem;
    opacity: 0.9;
    margin-bottom: 15px;
}

.profile-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-item i {
    opacity: 0.7;
}

.more-badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    margin-left: 5px;
}

.social-links {
    display: flex;
    gap: 15px;
}

.social-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.3s ease;
}

.social-icon:hover {
    background: white;
    color: var(--primary-color);
    transform: translateY(-3px);
}

.instructor-breadcrumb {
    display: flex;
    justify-content: flex-end;
}

.breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
}

.breadcrumb-item a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
}

.breadcrumb-item.active {
    color: white;
}

.breadcrumb-item+.breadcrumb-item::before {
    color: rgba(255, 255, 255, 0.5);
}

/* Content Cards */
.content-card {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    padding: 30px;
    height: 100%;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: #1e293b;
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
}

.bio-content {
    font-size: 1rem;
    line-height: 1.7;
    color: #475569;
}

.expertise-section h3, 
.contact-section h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: #1e293b;
}

.expertise-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.expertise-tag {
    display: inline-block;
    background: #f1f5f9;
    color: #475569;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.875rem;
}

.contact-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

.contact-button:hover {
    background: var(--secondary-color);
    transform: translateY(-3px);
    color: white;
}

/* Courses Grid */
.courses-grid {
    margin-top: 20px;
}

.course-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    height: 100%;
}

.course-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

.course-image {
    position: relative;
    height: 180px;
    overflow: hidden;
}

.course-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: all 0.5s ease;
}

.course-card:hover .course-image img {
    transform: scale(1.05);
}

.featured-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--primary-color);
    color: white;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 5px;
}

.course-content {
    padding: 20px;
}

.course-category {
    display: inline-block;
    background: #f1f5f9;
    color: #64748b;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    margin-bottom: 10px;
}

.course-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 15px;
    line-height: 1.4;
}

.course-title a {
    color: #1e293b;
    text-decoration: none;
    transition: color 0.3s ease;
}

.course-title a:hover {
    color: var(--primary-color);
}

.course-meta {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.875rem;
    color: #64748b;
}

.course-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.course-details-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--primary-color);
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s ease;
}

.course-details-link:hover {
    color: var(--secondary-color);
}

.course-details-link i {
    transition: transform 0.3s ease;
}

.course-details-link:hover i {
    transform: translateX(5px);
}

.view-all-button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--primary-color);
    color: white;
    padding: 12px 25px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

.view-all-button:hover {
    background: var(--secondary-color);
    transform: translateY(-3px);
    color: white;
}

.view-all-button i {
    transition: transform 0.3s ease;
}

.view-all-button:hover i {
    transform: translateX(5px);
}

.no-courses-message {
    text-align: center;
    padding: 50px 0;
    color: #64748b;
}

.no-courses-message i {
    font-size: 3rem;
    margin-bottom: 20px;
    color: #e2e8f0;
}

.no-courses-message h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: #1e293b;
}

/* Responsive Styles */
@media (max-width: 991.98px) {
    .instructor-profile-header {
        padding: 60px 0;
    }
    
    .profile-image {
        width: 120px;
        height: 120px;
        margin-right: 20px;
    }
    
    .profile-content h1 {
        font-size: 2rem;
    }
    
    .instructor-breadcrumb {
        justify-content: flex-start;
        margin-top: 30px;
    }
}

@media (max-width: 767.98px) {
    .instructor-profile-header {
        padding: 40px 0;
    }
    
    .profile-info {
        flex-direction: column;
        text-align: center;
    }
    
    .profile-image {
        margin-right: 0;
        margin-bottom: 20px;
    }
    
    .profile-stats {
        justify-content: center;
    }
    
    .social-links {
        justify-content: center;
    }
    
    .content-card {
        padding: 20px;
    }
}

@media (max-width: 575.98px) {
    .profile-content h1 {
        font-size: 1.75rem;
    }
    
    .designation {
        font-size: 1rem;
    }
    
    .profile-stats {
        flex-direction: column;
        gap: 10px;
    }
}
</style>

<?php
// Include footer
include 'includes/footer.php';
?>