<?php
session_start();
ob_start(); // Start output buffering
error_reporting(E_ALL);
ini_set('display_errors', 1);
include "../include/config.php";
$userlogin=$_SESSION['email'];
$userrole=$_SESSION['role'];
$intake=$_SESSION['department'];
$studentInitial = 'S';
   

if (isset($_SESSION['email'])){?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Signika+Negative:wght@300..700&family=Source+Sans+Pro&display=swap" rel="stylesheet">
    <link rel="icon" href="favicon.png" type="image/png">
    <meta name="theme-color" content="var(--primary)">
    <!-- Add this in the <head> section of your HTML -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
</head> 
</head>
<style>
        body{
        padding: 0px;
        margin:0px;
        
  font-size:17px;
  width:100%;
  background:;
    }
    a{
    text-decoration:none !important;
    }
   /* Overlay */
    .overlay {
      position: fixed;
      top: 0; left: 0;
      width: 100%; height: 100%;
      background: rgba(0,0,0,0.4);
      z-index: 1040;
      display: none;
    }
    a{
        text-decoration:none;
color:gray;
    }
    a:hover{
                text-decoration:none;
color:gray;
    }
    .overlay.active { display: block; }

    /* Student Header */
    .student-header {
      background: white;
      margin: 15px auto;
      padding: 15px;
      border-radius: 5px;
      max-width: 1000px;
      box-shadow: 0px 3px 8px rgba(0,0,0,0.1);
    }
    .student-header img {
      width: 90px;
      height: 90px;
      border-radius: 50%;
      object-fit: cover;
      border: 3px solid var(--primary);
    }
    .student-header i{
      color:var(--primary);
    }

    /* Payment Progress */
    .payment-progress {
      background: #f9f9f9;
      padding: 15px;
      border-radius: 12px;
      text-align: center;
      box-shadow: 0px 2px 6px rgba(0,0,0,0.05);
    }

    /* Cards */
    .card-custom {
      background: white;
      border-radius: 16px;
      padding: 20px;
      text-align: center;
      box-shadow: 0px 3px 8px rgba(0,0,0,0.1);
      transition: 0.3s;
    }
  
    .card-custom:hover {
      transform: translateY(-4px);
      box-shadow: 0px 6px 14px rgba(0,0,0,0.15);
    }
    .icon-box {
      width: 55px;
      height: 55px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24px;
      margin: 0 auto 10px;
      background: #f0f0f0;
      color: var(--primary);
    }

    /* Updates */
    .section-title {
      font-weight: 600;
      margin: 20px 0 12px;
      font-size: 18px;
      color: #333;
    }

    .update-list .list-group-item {
      border: none;
      border-radius: 12px;
      margin-bottom: 12px;
      box-shadow: 0px 2px 6px rgba(0,0,0,0.05);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .update-list .btn-sm {
      font-size: 12px;
      padding: 4px 8px;
    }
   .content{
       margin-left:200px;
   }
   .col-6 h6{
       color:black;
   }
</style>
<body>
<?php include "../include/nav.php";?>

  
      
<div class="content" style="padding:20px">
    <br>    

    <?php
// Get counts from database
$student_count = $conn->query("SELECT COUNT(*) as total FROM students  ")->fetch_assoc()['total'];
$staff_count = $conn->query("SELECT COUNT(*) as total FROM staff ")->fetch_assoc()['total'];
$programs_count = $conn->query("SELECT COUNT(*) as total FROM programs")->fetch_assoc()['total'];
$catalogue_count = $conn->query("SELECT COUNT(*) as total FROM catalogue")->fetch_assoc()['total'];

// Get admin name
$admin_name = "Administrator"; // Default name


// Get current time for greeting
$hour = date('H');
if ($hour < 12) {
    $greeting = '<i class="bi bi-brightness-alt-high"></i> Good morning';
} elseif ($hour < 17) {
    $greeting = '<i class="bi bi-brightness-high"></i> Good afternoon';
} else {
    $greeting = '<i class="bi bi-moon"></i> Good evening';
}



?>


<div style="padding: 20px; background: var(--primary) ; color: white; border-radius: 10px; margin-bottom: 25px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
    <div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">
        <div>
            <h2 style="margin: 0; font-weight: 600; font-size: 28px;"><?php echo $greeting; ?>, <span style="color: #ffd700;"><?php echo $admin_name; ?></span>!</h2>
            <p style="margin: 5px 0 0; opacity: 0.9; font-size: 16px;">Welcome to your administration dashboard</p>
        </div>
        <div style="background: rgba(255, 255, 255, 0.15); padding: 10px 15px; border-radius: 8px; backdrop-filter: blur(5px);">
            <p style="margin: 0; font-size: 14px; display: flex; align-items: center;">
                <i class="fa fa-calendar" style="margin-right: 8px;"></i>
                <?php echo date('l, F j, Y'); ?>
            </p>
        </div>
    </div>
</div>


<script>
// Add hover effects to cards
document.addEventListener('DOMContentLoaded', function() {
    const cards = document.querySelectorAll('div[style*="box-shadow: 0 4px 8px rgba(0,0,0,0.08)"]');
    
    cards.forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-5px)';
            this.style.boxShadow = '0 8px 16px rgba(0,0,0,0.12)';
        });
        
        card.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0)';
            this.style.boxShadow = '0 4px 8px rgba(0,0,0,0.08)';
        });
    });
});
</script>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    <?php 
if(!$userrole=="Finance"){?>
    <?PHP include "header.php";?>
<?php } else { ?>
    <?PHP include "header_finance.php";?>
<?php } ?>

<div class="overlay" id="overlay"></div>

<?php if($userrole=="Finance" || $userrole == "Superadmin"){ ?>
<!-- Finance/Superadmin Dashboard -->
<div class="dashboard-section">
    <div class="section-header">
        <h3><i class="bi bi-wallet2"></i> Financial Management</h3>
        <p class="section-subtitle">Manage payments, invoices, and financial reports</p>
    </div>
    
    <div class="dashboard-cards-grid">
        <a href="payment.php" class="dashboard-card">
            <div class="card-icon-container bg-primary">
                <i class="bi bi-coin"></i>
            </div>
            <div class="card-content">
                <h4>Payment Collection</h4>
                <p>Collect and process student payments</p>
                <span class="card-badge">Active</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="balance.php" class="dashboard-card">
            <div class="card-icon-container bg-success">
                <i class="bi bi-envelope-paper"></i>
            </div>
            <div class="card-content">
                <h4>Invoice Management</h4>
                <p>Create and send invoices to students</p>
                <span class="card-badge">Active</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="finance_owing.php" class="dashboard-card">
            <div class="card-icon-container bg-warning">
                <i class="bi bi-clipboard-data"></i>
            </div>
            <div class="card-content">
                <h4>Owing Reports</h4>
                <p>View detailed owing reports and analytics</p>
                <span class="card-badge">Reports</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="reminder.php" class="dashboard-card">
            <div class="card-icon-container bg-info">
                <i class="bi bi-bell"></i>
            </div>
            <div class="card-content">
                <h4>Payment Reminders</h4>
                <p>Send automated payment reminders</p>
                <span class="card-badge">Automated</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
    </div>
</div>
<?php } ?>

<?php if($userrole=="Lecturer" || $userrole=="Admin"){ ?>
<!-- Lecturer/Admin Dashboard -->
<div class="dashboard-section">
    <div class="section-header">
        <h3><i class="bi bi-mortarboard"></i> Academic Management</h3>
        <p class="section-subtitle">Manage courses, assignments, and academic content</p>
    </div>
    
    <div class="dashboard-cards-grid">
        <a href="push.php" class="dashboard-card">
            <div class="card-icon-container bg-purple">
                <i class="bi bi-book"></i>
            </div>
            <div class="card-content">
                <h4>Examination Results</h4>
                <p>Upload and manage examination results</p>
                <span class="card-badge">Critical</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="assignment.php" class="dashboard-card">
            <div class="card-icon-container bg-orange">
                <i class="bi bi-pen"></i>
            </div>
            <div class="card-content">
                <h4>Assignment Management</h4>
                <p>Create and grade assignments for all courses</p>
                <span class="card-badge">All Courses</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="notes.php" class="dashboard-card">
            <div class="card-icon-container bg-teal">
                <i class="bi bi-journal-text"></i>
            </div>
            <div class="card-content">
                <h4>Course Notes</h4>
                <p>Upload and manage course materials</p>
                <span class="card-badge">All Courses</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="news.php" class="dashboard-card">
            <div class="card-icon-container bg-indigo">
                <i class="bi bi-megaphone"></i>
            </div>
            <div class="card-content">
                <h4>Notice Board</h4>
                <p>Post news and announcements for students</p>
                <span class="card-badge">News</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
    </div>
</div>
<?php } ?>

<?php if($userrole=="Librarian"){ ?>
<!-- Librarian Dashboard -->
<div class="dashboard-section">
    <div class="section-header">
        <h3><i class="bi bi-book-half"></i> Library Management</h3>
        <p class="section-subtitle">Manage library resources, books, and e-books</p>
    </div>
    
    <div class="dashboard-cards-grid">
        <a href="catelogue.php" class="dashboard-card">
            <div class="card-icon-container bg-brown">
                <i class="bi bi-bookshelf"></i>
            </div>
            <div class="card-content">
                <h4>Library Catalog</h4>
                <p>Browse and manage entire library collection</p>
                <span class="card-badge">All Books</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="issuing.php" class="dashboard-card">
            <div class="card-icon-container bg-blue">
                <i class="bi bi-arrow-left-right"></i>
            </div>
            <div class="card-content">
                <h4>Issue/Return Books</h4>
                <p>Manage book lending and return operations</p>
                <span class="card-badge">Active</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="return_books.php" class="dashboard-card">
            <div class="card-icon-container bg-green">
                <i class="bi bi-check-circle"></i>
            </div>
            <div class="card-content">
                <h4>Book Returns</h4>
                <p>Track and manage book returns</p>
                <span class="card-badge">All</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="elibray.php" class="dashboard-card">
            <div class="card-icon-container bg-cyan">
                <i class="bi bi-laptop"></i>
            </div>
            <div class="card-content">
                <h4>E-Books Management</h4>
                <p>Manage digital library and e-books</p>
                <span class="card-badge">Digital</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
    </div>
</div>
<?php } ?>

<?php if($userrole=="Student Affairs"){ ?>
<!-- Student Affairs Dashboard -->
<div class="dashboard-section">
    <div class="section-header">
        <h3><i class="bi bi-people"></i> Student Affairs Management</h3>
        <p class="section-subtitle">Manage student services, notifications, and support</p>
    </div>
    
    <div class="dashboard-cards-grid">
        <a href="catelogue.php" class="dashboard-card">
            <div class="card-icon-container bg-maroon">
                <i class="bi bi-people-fill"></i>
            </div>
            <div class="card-content">
                <h4>Library Catalogue</h4>
                <p>Access Library Catalogue</p>
                <span class="card-badge">All Books</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-book"></i>
            </div>
        </a>
        
        <a href="students.php" class="dashboard-card">
            <div class="card-icon-container bg-navy">
                <i class="bi bi-folder"></i>
            </div>
            <div class="card-content">
                <h4>Student Records</h4>
                <p>Manage student academic and personal records</p>
                <span class="card-badge">Records</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="send.php" class="dashboard-card">
            <div class="card-icon-container bg-pink">
                <i class="bi bi-broadcast"></i>
            </div>
            <div class="card-content">
                <h4>Notifications</h4>
                <p>Send important messages and announcements</p>
                <span class="card-badge">Broadcast</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
        
        <a href="logout.php" class="dashboard-card">
            <div class="card-icon-container bg-dark">
                <i class="bi bi-headset"></i>
            </div>
            <div class="card-content">
                <h4>Logout</h4>
                <p>Sign out from your Accout</p>
                <span class="card-badge">Logout</span>
            </div>
            <div class="card-arrow">
                <i class="bi bi-arrow-right"></i>
            </div>
        </a>
    </div>
</div>
<?php } ?>

<style>
/* Dashboard Section Styles */
.dashboard-section {
    margin: 2rem 0;
    padding: 1.5rem;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    animation: fadeIn 0.6s ease-out;
}

.section-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #f0f2f5;
}

.section-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.section-header .section-subtitle {
    color: #718096;
    font-size: 0.95rem;
    margin: 0;
}

/* Dashboard Cards Grid */
.dashboard-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.dashboard-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.dashboard-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #4299e1, #667eea);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.dashboard-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 32px rgba(0,0,0,0.12);
    border-color: #cbd5e0;
}

.dashboard-card:hover::before {
    opacity: 1;
}

/* Card Icon Styles */
.card-icon-container {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.dashboard-card:hover .card-icon-container {
    transform: scale(1.1);
}

/* Card Content Styles */
.card-content {
    flex: 1;
    min-width: 0;
}

.card-content h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.card-content p {
    font-size: 0.875rem;
    color: #718096;
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.card-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: #e2e8f0;
    color: #4a5568;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Card Arrow */
.card-arrow {
    color: #cbd5e0;
    font-size: 1.25rem;
    transition: all 0.3s ease;
}

.dashboard-card:hover .card-arrow {
    color: #4299e1;
    transform: translateX(4px);
}

/* Color Variations */
.bg-primary { background: linear-gradient(135deg, #4299e1, #3182ce); }
.bg-success { background: linear-gradient(135deg, #48bb78, #38a169); }
.bg-warning { background: linear-gradient(135deg, #ed8936, #dd6b20); }
.bg-info { background: linear-gradient(135deg, #4299e1, #3182ce); }
.bg-purple { background: linear-gradient(135deg, #9f7aea, #805ad5); }
.bg-orange { background: linear-gradient(135deg, #ed8936, #dd6b20); }
.bg-teal { background: linear-gradient(135deg, #38b2ac, #319795); }
.bg-indigo { background: linear-gradient(135deg, #667eea, #5a67d8); }
.bg-brown { background: linear-gradient(135deg, #a1887f, #8d6e63); }
.bg-blue { background: linear-gradient(135deg, #4299e1, #3182ce); }
.bg-green { background: linear-gradient(135deg, #48bb78, #38a169); }
.bg-cyan { background: linear-gradient(135deg, #0bc5ea, #00b5d8); }
.bg-maroon { background: linear-gradient(135deg, #e53e3e, #c53030); }
.bg-navy { background: linear-gradient(135deg, #4c51bf, #434190); }
.bg-pink { background: linear-gradient(135deg, #ed64a6, #d53f8c); }
.bg-dark { background: linear-gradient(135deg, #2d3748, #1a202c); }

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .dashboard-section {
        padding: 1rem;
        margin: 1rem 0;
    }
    
    .dashboard-cards-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .dashboard-card {
        padding: 1.25rem;
    }
    
    .card-icon-container {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }
    
    .section-header h3 {
        font-size: 1.25rem;
    }
}

@media (max-width: 576px) {
    .dashboard-card {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .card-content {
        text-align: center;
    }
    
    .card-arrow {
        position: absolute;
        bottom: 1rem;
        right: 1rem;
    }
}
</style>

<script>
// Add animation on page load
document.addEventListener('DOMContentLoaded', function() {
    const sections = document.querySelectorAll('.dashboard-section');
    const cards = document.querySelectorAll('.dashboard-card');
    
    // Animate sections
    sections.forEach((section, index) => {
        section.style.opacity = '0';
        section.style.transform = 'translateY(30px)';
        
        setTimeout(() => {
            section.style.transition = 'all 0.6s cubic-bezier(0.4, 0, 0.2, 1)';
            section.style.opacity = '1';
            section.style.transform = 'translateY(0)';
        }, index * 200);
    });
    
    // Animate cards with staggered delay
    cards.forEach((card, index) => {
        card.style.opacity = '0';
        card.style.transform = 'scale(0.95)';
        
        setTimeout(() => {
            card.style.transition = 'all 0.4s cubic-bezier(0.4, 0, 0.2, 1)';
            card.style.opacity = '1';
            card.style.transform = 'scale(1)';
        }, 300 + (index * 100));
    });
});
</script>
       
       
       <?php
$result = mysqli_query($conn, "SELECT `id`, `title`, `date`, `image` FROM `news` ORDER BY date DESC LIMIT 5");
?>

<div style="display:flex; flex-wrap:wrap; gap:0px; padding:0px; margin-top:10px">

  <!-- News Section -->
  <div style="flex:1; min-width:300px; background:#f9f9f9; padding:15px; border-radius:10px; box-shadow:0 0 10px rgba(0,0,0,0.1);">
    <h2 style="margin-bottom:15px; text-align:; color:#333;">Latest News</h2>
    <ul style="list-style:none; padding:0; margin:0;">
      <?php while($row = mysqli_fetch_assoc($result)) { ?>
        <li style="display:flex; align-items:center; border-bottom:1px solid #ddd; padding:10px 0; gap:10px;">
          
          <!-- Thumbnail -->
          <?php if(!empty($row['image'])) { ?>
            <img src="../../students/img/<?php echo $row['image']; ?>" 
                 alt="thumb" 
                 style="width:60px; height:60px; object-fit:cover; border-radius:8px;">
          <?php } else { ?>
            <div style="width:60px; height:60px; background:#eee; border-radius:8px;"></div>
          <?php } ?>
          
          <!-- News Details -->
          <div style="flex:1;">
            <strong style="color:var(--primary); font-size:14px;"><?php echo $row['title']; ?></strong><br>
            <small style="color:#999;"><?php echo date("d M Y", strtotime($row['date'])); ?></small>
          </div>
          
          <!-- View Button -->
          <a href="viewnews.php?id=<?php echo $row['id']; ?>" 
             style="padding:5px 10px; background:var(--primary); color:#fff; border-radius:5px; text-decoration:none; font-size:12px; white-space:nowrap;">
             View
          </a>
        </li>
      <?php } ?>
    </ul>
  </div>

 
  <div style="flex:1; min-width:300px; background:#fff; padding:15px; border-radius:10px; box-shadow:0 0 10px rgba(0,0,0,0.1);">
    <h2 style="margin-bottom:15px; text-align:; color:#333;">Calendar</h2>
    <iframe src="https://calendar.google.com/calendar/embed?src=en.zambia%23holiday%40group.v.calendar.google.com&ctz=Africa%2FLusaka" 
      style="border:0; width:100%; height:400px; border-radius:0px;" frameborder="0" scrolling="no">
    </iframe>
  </div>

</div>

       
       
       
 


<style>
.card h6 {
    font-weight: 600;
    color: #17cc27;
}


.card:hover {
    transform: translateY(-3px);
    transition: 0.3s;
    box-shadow: 0 6px 15px rgba(0,0,0,0.2);
}


.card img {
    display: block;
    margin: 0 auto 10px auto; 
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}
</style>



 

<?php
if($userrole=="Admin"){?>






      </div>
    </div>
  </div>



  <div class="accordion-item">
 
<div id="collapse3" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
      <div class="accordion-body">
    <div class="calendar">
        <?php echo date('l, F j, Y');  ?>
    </div>
    <div class="form-group">
    <label for="searchInput">Search:</label>
    <input type="text" class="form-control" id="search" placeholder="Search by StudentID">
</div>
<script>
    document.getElementById('search').addEventListener('input', function() {
        var filter = this.value.toLowerCase();  insensitive)
        var rows = document.querySelectorAll('#students tbody tr'); 
        
        rows.forEach(function(row) {
            var cells = row.getElementsByTagName('td');  row
            var matchFound = false;
            
            for (var i = 0; i < cells.length; i++) {
                if (cells[i].textContent.toLowerCase().indexOf(filter) > -1) {
                    matchFound = true;
                    break; 
                }
            }
            
         
            if (matchFound) {
                row.style.display = '';
            } else {
                row.style.display = 'none';
            }
        });
    });
</script>
    <table class="table"  id="students">
        <tr>
          
            
            <th>Name</th>
            <th>Course</th>
            <th>Program</th>
            <th>Action</th>
        </tr>
                <?php
$query=mysqli_query($conn, "select *from students ");
 while($row=mysqli_fetch_array($query)){?>
            <tr>
         
            <td class="date-cell"><?php echo $row['studentname']; ?></td>
           
            <td class="date-cell"><?php echo $row['program']; ?></td>
            <td class="date-cell"><?php echo $row['intake']; ?></td>
             
                <td><a style="color:#17cc27; text-decoration:none;" href="studentedit.php?id=<?php echo $row['id']; ?>" class="download-btn"><i class="fa fa-edit"></i> </a></td>
            </tr>
        <?php } ?>
    </table>

      </div>
    </div>
  </div>









  
        <script>
        

        document.getElementById('paymentForm').addEventListener('submit', function() {
            document.getElementById('loading').style.display = 'block';
            this.querySelector('button[type="submit"]').disabled = true;
        });
    </script>
    </div>
      </div>
    </div>
  </div>



















  
<div class="accordion-item">
        <div id="collapse7" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
      <div class="accordion-body">
    

 

    
</div>
      </div>
      </div>
    </div>
  </div>



</div>
</div>

  
</div>
     <?php
    if (isset($_GET['payid'])) {?>
  <center style=" padding-left:30px; padding-right:30px;">
  <p class="text-danger" tyle="margin-top:-50px; magin-bottom:-6px;"> <?php echo $_GET['payid'];?></p>
 </center>
  <?php
  }
  ?>
   
    

<!-- Add CSS styles to style the calendar -->
<style>
    /* Calendar Table Styling */
    .calendar-table {
        width: 100%;
        border-collapse: collapse;
        margin: 20px 0;
        font-family: Arial, sans-serif;
    }

    /* Table Header Styling */
    .calendar-header {
        background-color: #4CAF50;
        color: white;
        font-weight: bold;
        font-size: 16px;
    }

    .calendar-header-cell {
        padding: 10px;
        width: 14.28%; /* 7 columns, each should be 1/7th of the table */
    }

    /* Styling for regular days */
    .calendar-day {
        text-align: center;
        padding: 15px;
        font-size: 14px;
        cursor: pointer;
        transition: background-color 0.3s;
    }

    /* Highlight today's date */
    .today {
        background-color: #FFD700; /* Golden background */
        color: white; /* White text for contrast */
        font-weight: bold;
        border-radius: 50%; /* Rounded corners */
        box-shadow: 0 0 10px rgba(255, 215, 0, 0.6); /* Glow effect */
    }

    /* Empty cells for days outside the month */
    .calendar-empty {
        background-color: #f4f4f4;
    }

    /* Hover effect for non-today cells */
    .calendar-day:hover {
        background-color: #e0e0e0;
        border-radius: 50%;
    }

    /* Styling for the table borders */
    td, th {
        border: 1px solid #ddd;
        text-align: center;
    }
</style>


</div>

<?php
}
?>

</body>
</html>
<?php
}else {
  header("location:../index.php");
}
?>










  <?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Constants
define('API_KEY', '76d2ea13-10e0-48e7-8e0e-7261bac5ced7');
define('API_SECRET', '0b15eb80a64d3528cbfc6cd76889b7e71af204aa');
define('BASE_URL', 'https://tumeny.herokuapp.com');

// Function to get the authentication token
function getAuthToken(): string {
    $ch = curl_init(BASE_URL . "/api/token");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'apiKey: ' . API_KEY,
        'apiSecret: ' . API_SECRET,
    ]);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);

    if ($error) {
        error_log("Token Error: $error");
        $_SESSION['payment_error'] = "Authentication failed.";
        return '';
    }

    $responseData = json_decode($response, true);
    if (isset($responseData['error'])) {
        $_SESSION['payment_error'] = "Authentication failed.";
        error_log("API Response Error: " . json_encode($responseData));
        return '';
    }

    return $responseData['token'] ?? '';
}

// Function to create a payment
function createPayment($authToken, $paymentData) {
    $ch = curl_init(BASE_URL . "/api/v1/payment");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $authToken,
        'Content-Type: application/json'
    ]);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($paymentData));

    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);

    if ($error) {
        error_log("Payment Error: $error");
        return ['error' => true];
    }

    return json_decode($response, true);
}

// Function to check payment status
function checkPaymentStatus($authToken, $paymentId) {
    $ch = curl_init(BASE_URL . "/api/v1/payment/$paymentId");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $authToken
    ]);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);

    if ($error) {
        error_log("Payment Status Error: $error");
        return ['error' => true];
    }

    return json_decode($response, true);
}

// Function to retry checking payment status
function getPaymentStatusWithRetry($authToken, $paymentId, $maxRetries = 50) {
    $retries = 0;
    while ($retries < $maxRetries) {
        $paymentStatus = checkPaymentStatus($authToken, $paymentId);
        error_log("Retry #$retries - Payment Status: " . json_encode($paymentStatus));

        if (isset($paymentStatus['payment']['status'])) {
            switch ($paymentStatus['payment']['status']) {
                case 'success':
                    $_SESSION['payment_success'] = true;
                    header('Location: success.php');
                    session_write_close();
                    exit;
                case 'failed':
                    $_SESSION['payment_error'] = "Payment failed.";
                    return false;
                case 'pending':
                    sleep(3);
                    $retries++;
                    continue 2;
                default:
                    $_SESSION['payment_error'] = "Unexpected payment status.";
                    return false;
            }
        }

        $retries++;
        sleep(3);
    }

    $_SESSION['payment_error'] = "Payment timed out.";
    return false;
}

// Handle POST request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $authToken = getAuthToken();

    if (!$authToken) {
        $_SESSION['payment_error'] = "Payment failed.";
    } else {
        $paymentData = [
            'description' => $_POST['description'],
            'customerFirstName' => htmlspecialchars(strip_tags(trim($_POST['firstName']))),
            'customerLastName' => htmlspecialchars(strip_tags(trim($_POST['lastName']))),
            'email' => filter_var($_POST['email'], FILTER_SANITIZE_EMAIL),
            'phoneNumber' => htmlspecialchars(strip_tags(trim($_POST['phone']))),
            'amount' => (int)$_POST['amount']
        ];

        $paymentResponse = createPayment($authToken, $paymentData);

        if (isset($paymentResponse['payment']['id'])) {
            $paymentId = $paymentResponse['payment']['id'];
            getPaymentStatusWithRetry($authToken, $paymentId);
        } else {
            $_SESSION['payment_error'] = "Payment creation failed.";
            error_log("Payment Response Error: " . json_encode($paymentResponse));
        }
    }
}

// Clear success flag if it exists
if (isset($_SESSION['payment_success'])) {
    unset($_SESSION['payment_success']);
}
?>



<!-- Modal -->
<div class="modal fade" id="exampleModal33" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Ops </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      <?php
    $query=mysqli_query($conn, "select  *from Admin");
    while($row=mysqli_fetch_array($query)){
      $maxpay=$row['maxpay'];
      $ba=$maxpay-round($per);
      ?>
        <p><strong>Unable to download results. Fees paid are insufficient. Please complete <?php echo round($ba);?>%  payment.
      
        <?php
 }
 ?>   .</strong></p>
       
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
       
      </div>
    </div>
  </div>
</div>
