<?php
if (!isset($pdo)) require_once __DIR__ . '/config/database.php';
if(isset($_GET['ajax_students'])){header('Content-Type: application/json');$q=trim($_GET['q']??'');$page=max(1,(int)($_GET['page']??1));$perPage=20;$offset=($page-1)*$perPage;try{$where='';$params=[];if($q!==''){$where="WHERE (s.first_name LIKE :q1 OR s.last_name LIKE :q2 OR s.roll_number LIKE :q3)";$params[':q1']="%$q%";$params[':q2']="%$q%";$params[':q3']="%$q%";}$cnt=$pdo->prepare("SELECT COUNT(*) FROM students s $where");$cnt->execute($params);$total=(int)$cnt->fetchColumn();$st=$pdo->prepare("SELECT s.first_name,s.last_name,s.roll_number,s.photo,cl.name AS class_name,cl.section FROM students s LEFT JOIN classes cl ON s.class_id=cl.id $where ORDER BY cl.name,cl.section,s.roll_number ASC LIMIT $perPage OFFSET $offset");$st->execute($params);$students=$st->fetchAll(PDO::FETCH_ASSOC);$totalPages=max(1,(int)ceil($total/$perPage));}catch(Exception$e){$students=[];$total=0;$totalPages=1;}echo json_encode(['ok'=>true,'students'=>$students,'total'=>$total,'page'=>$page,'totalPages'=>$totalPages]);exit;}
require_once __DIR__ . '/includes/site_settings.php';
$site_name=get_setting($pdo,'site_name','বিদ্যালয় ম্যানেজমেন্ট');
$contact_address=get_setting($pdo,'contact_address',"কুড়ুলগাছি মাধ্যমিক বিদ্যালয়\nদামুড়হুদা, চুয়াডাঙ্গা, বাংলাদেশ");
$contact_phone=get_setting($pdo,'contact_phone','+8801 ******');
$contact_email=get_setting($pdo,'contact_email','info@school.edu.bd');
$online_exams=[]; try{$s=$pdo->prepare("SELECT o.id,o.name,o.class_id,o.subject_id,o.exam_date,o.start_time,o.end_time,o.duration,o.total_marks,o.pass_marks,o.status,c.name AS class_name,sub.name AS subject_name FROM online_exams o LEFT JOIN classes c ON o.class_id=c.id LEFT JOIN subjects sub ON o.subject_id=sub.id WHERE(o.status='scheduled' OR o.status='ongoing')AND o.exam_date>=CURDATE() ORDER BY o.exam_date ASC,o.start_time ASC LIMIT 10");$s->execute();$online_exams=$s->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
function bn_date($d){return $d?date('d-m-Y',strtotime($d)):'';}
$notices=[]; try{$s=$pdo->prepare("SELECT id,title,content,publish_date FROM notices WHERE status='active' AND publish_date<=CURDATE() AND(expiry_date IS NULL OR expiry_date>=CURDATE()) ORDER BY created_at DESC LIMIT 6");$s->execute();$notices=$s->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
$students=[];$perPage=12;$totalStudents=0;$totalPages=0;$offset=0;$currentPage=max(1,(int)($_GET['page']??1));$nameInput=trim($_GET['name']??'');$rollInput=trim($_GET['roll']??'');$classIdInput=trim($_GET['class']??'');$sessionInput=trim($_GET['session']??'');$view=($_GET['view']??'grid')==='table'?'table':'grid';
if($classIdInput!==''&&!ctype_digit($classIdInput))$classIdInput='';
$is_search=isset($_GET['name'])||isset($_GET['roll'])||isset($_GET['class'])||isset($_GET['session']);
if($is_search){$bq="FROM students s LEFT JOIN classes c ON s.class_id=c.id LEFT JOIN student_subjects ss ON s.id=ss.student_id LEFT JOIN subjects sub ON ss.subject_id=sub.id WHERE s.status='active'";$c=[];$p=[];
if($nameInput!==''){$c[]="(s.first_name LIKE :n1 OR s.last_name LIKE :n2)";$p[':n1']="%$nameInput%";$p[':n2']="%$nameInput%";}
if($rollInput!==''){$c[]="s.roll_number LIKE :r";$p[':r']="%$rollInput%";}
if($classIdInput!==''){$c[]="s.class_id=:cl";$p[':cl']=(int)$classIdInput;}
if($sessionInput!==''){$c[]="s.session=:se";$p[':se']=$sessionInput;}
if(!empty($c))$bq.=' AND '.implode(' AND ',$c);
try{$cs=$pdo->prepare("SELECT COUNT(DISTINCT s.id) $bq");foreach($p as$k=>$v)$cs->bindValue($k,$v,is_int($v)?PDO::PARAM_INT:PDO::PARAM_STR);$cs->execute();$totalStudents=(int)$cs->fetchColumn();}catch(Exception$e){}
if($totalStudents>0){$totalPages=(int)ceil($totalStudents/$perPage);if($currentPage>$totalPages)$currentPage=$totalPages;}else$currentPage=1;$offset=(int)max(0,($currentPage-1)*$perPage);
try{$st=$pdo->prepare("SELECT s.id,s.first_name,s.last_name,s.roll_number,s.photo,c.name AS class_name,c.section,GROUP_CONCAT(sub.name SEPARATOR ', ')AS subjects $bq GROUP BY s.id ORDER BY s.roll_number ASC LIMIT :l OFFSET :o");foreach($p as$k=>$v)$st->bindValue($k,$v,is_int($v)?PDO::PARAM_INT:PDO::PARAM_STR);$st->bindValue(':l',$perPage,PDO::PARAM_INT);$st->bindValue(':o',$offset,PDO::PARAM_INT);$st->execute();$students=$st->fetchAll(PDO::FETCH_ASSOC);}catch(Exception$e){}}else$is_search=false;
$sqp=[];if($nameInput!=='')$sqp['name']=$nameInput;if($rollInput!=='')$sqp['roll']=$rollInput;if($classIdInput!=='')$sqp['class']=$classIdInput;if($sessionInput!=='')$sqp['session']=$sessionInput;$sqp['view']=$view;if($currentPage>1)$sqp['page']=$currentPage;
$bsq=function($o=[])use($sqp){$a=array_merge($sqp,$o);foreach($a as$k=>$v)if($v===''||$v===null)unset($a[$k]);return http_build_query($a);};
$events=[];try{$st=$pdo->query("SHOW TABLES LIKE 'events'");if($st->rowCount()==0)$pdo->exec("CREATE TABLE IF NOT EXISTS events(id INT AUTO_INCREMENT PRIMARY KEY,title VARCHAR(200)NOT NULL,description TEXT NULL,event_date DATE NOT NULL,location VARCHAR(200)NULL,cover_image VARCHAR(255)NULL,status ENUM('upcoming','past','cancelled')DEFAULT 'upcoming',created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");$st=$pdo->query("SELECT*FROM events WHERE status='upcoming' AND event_date>=CURDATE()ORDER BY event_date ASC LIMIT 6");$events=$st->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
$teachers=[];try{$st=$pdo->prepare("SELECT first_name,last_name,designation,photo,phone,qualification,experience_years FROM teachers WHERE status='active' ORDER BY created_at DESC");$st->execute();$teachers=$st->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
$board=[];try{$st=$pdo->query("SHOW TABLES LIKE 'management_board_members'");if($st->rowCount()==0)$pdo->exec("CREATE TABLE IF NOT EXISTS management_board_members(id INT AUTO_INCREMENT PRIMARY KEY,name VARCHAR(150)NOT NULL,designation VARCHAR(150)DEFAULT NULL,board_role VARCHAR(100)DEFAULT NULL,phone VARCHAR(50)DEFAULT NULL,email VARCHAR(120)DEFAULT NULL,photo VARCHAR(255)DEFAULT NULL,order_no INT DEFAULT 0,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");$st=$pdo->prepare("SELECT*FROM management_board_members ORDER BY order_no ASC,id ASC LIMIT 12");$st->execute();$board=$st->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
$messages=[];try{$st=$pdo->prepare("SELECT*FROM messages WHERE is_active=1 ORDER BY message_type,display_order,id");$st->execute();$messages=$st->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
$mt_opts_pub=['principal'=>'প্রধান শিক্ষক','headmaster'=>'অধ্যক্ষ','super'=>'সুপার','chairman'=>'সভাপতি'];
$chairman_name=null;$principal_name=null;
if(!empty($board)){foreach($board as$m){if($m['board_role']==='সভাপতি')$chairman_name=$m['name'];if(in_array($m['board_role'],['অধ্যক্ষ','প্রধান শিক্ষক','ভারপ্রাপ্ত']))$principal_name=$m['name'];}}
if(!empty($messages)){foreach($messages as&$m){if($m['message_type']==='chairman'&&$chairman_name)$m['name']=$chairman_name;if($m['message_type']==='principal'&&$principal_name)$m['name']=$principal_name;}unset($m);usort($messages,function($a,$b){$p=['chairman'=>0,'principal'=>1];$oa=$p[$a['message_type']??'']??999;$ob=$p[$b['message_type']??'']??999;if($oa===$ob){$da=$a['display_order']??0;$db=$b['display_order']??0;return $da===$db?($a['id']??0)<=>($b['id']??0):$da<=>$db;}return $oa<=>$ob;});}
$classes=[];try{$st=$pdo->prepare("SELECT id,name,section FROM classes WHERE status='active' ORDER BY name ASC");$st->execute();$classes=$st->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
$sessions=[];try{$st=$pdo->prepare("SELECT DISTINCT session FROM results WHERE session IS NOT NULL AND session!='' ORDER BY session DESC LIMIT 10");$st->execute();$sr=$st->fetchAll(PDO::FETCH_COLUMN)?:[];$sessions=empty($sr)?range(date('Y'),date('Y')-4):$sr;}catch(Throwable$e){$sessions=range(date('Y'),date('Y')-4);}
$exams=[];try{$st=$pdo->prepare("SELECT DISTINCT name,exam_type FROM exams ORDER BY exam_date DESC LIMIT 20");$st->execute();$exams=$st->fetchAll(PDO::FETCH_ASSOC)?:[];if(empty($exams)){$st=$pdo->prepare("SELECT DISTINCT exam_type FROM results WHERE exam_type IS NOT NULL AND exam_type!='' ORDER BY exam_type");$st->execute();foreach($st->fetchAll(PDO::FETCH_COLUMN)?:[] as$t)$exams[]=['name'=>$t,'exam_type'=>$t];}}catch(Throwable$e){}
if(empty($exams))$exams=[['name'=>'অর্ধবার্ষিক পরীক্ষা','exam_type'=>'half_yearly'],['name'=>'বার্ষিক পরীক্ষা','exam_type'=>'annual'],['name'=>'টেস্ট পরীক্ষা','exam_type'=>'test']];
$gallery_images=[];try{$st=$pdo->prepare("SELECT image_path,title FROM gallery ORDER BY created_at DESC LIMIT 10");$st->execute();$gallery_images=$st->fetchAll(PDO::FETCH_ASSOC)?:[];}catch(Throwable$e){}
$noticeBar=get_setting($pdo,'notice_bar','false');
?><!DOCTYPE html>
<html lang="bn"><head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>স্বাগতম - <?php echo htmlspecialchars($site_name); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
:root{--r:#DC3545;--g:#28A745;--b:#0D6EFD;--y:#FFC107;--w:#fff;--grad:linear-gradient(135deg,var(--g),#1a7a2e)}
body{font-family:'Hind Siliguri','Nirmala UI','Vrinda',sans-serif;background:#f8f9fa;-webkit-font-smoothing:antialiased}
.navbar{background:var(--grad);padding:0;box-shadow:0 2px 10px rgba(0,0,0,.15)}
.navbar .navbar-brand{color:var(--w)!important;font-weight:800;font-size:1.4rem;padding:10px 14px}
.navbar .navbar-brand:hover{color:var(--y)!important}
.nav-link{color:rgba(255,255,255,.9)!important;font-weight:600;padding:12px 14px!important;transition:.3s;border-bottom:3px solid transparent}
.nav-link:hover,.nav-link.active{background:rgba(255,255,255,.1)!important;color:var(--y)!important;border-bottom-color:var(--r)}
.dropdown-menu{border:none;border-radius:0 0 10px 10px;box-shadow:0 6px 20px rgba(0,0,0,.12);border-top:3px solid var(--r);padding:6px 0}
.dropdown-item{color:#333;padding:8px 18px;font-weight:500;border-left:3px solid transparent}
.dropdown-item:hover{background:linear-gradient(90deg,rgba(40,167,69,.08),transparent);color:var(--g);border-left-color:var(--r)}
.btn-login{background:var(--grad);border:none;color:var(--w);font-weight:600;padding:7px 20px;border-radius:25px;transition:.3s}
.btn-login:hover{background:linear-gradient(135deg,#1a7a2e,var(--g));color:var(--y);transform:translateY(-2px)}
.section-title{font-weight:700;color:var(--g);border-bottom:3px solid var(--r);padding-bottom:6px;margin-bottom:14px;display:flex;align-items:center;gap:8px;font-size:1.2rem}
.section-title i{color:var(--r)}.card{border:0;border-radius:10px;box-shadow:0 4px 14px rgba(0,0,0,.07);border-top:3px solid var(--g);transition:.3s;margin-bottom:10px}
.card:hover{transform:translateY(-3px);box-shadow:0 8px 20px rgba(0,0,0,.1);border-top-color:var(--r)}
.card-header{font-weight:700;padding:8px 14px;border-bottom:0}.footer{background:var(--grad);color:var(--w);padding:24px 0;margin-top:30px;border-top:4px solid var(--r)}
.footer a{color:rgba(255,255,255,.7)}.footer a:hover{color:var(--y)}
.scroll-to-top{position:fixed;bottom:24px;right:24px;width:42px;height:42px;background:var(--grad);color:var(--w);border:3px solid var(--r);border-radius:50%;display:none;align-items:center;justify-content:center;font-size:1.2rem;cursor:pointer;z-index:1000;transition:.3s}
.scroll-to-top.show{display:flex}
.notice-bar{background:linear-gradient(90deg,var(--r),#b71c1c);color:var(--w);padding:8px 0;overflow:hidden;border-bottom:2px solid var(--g);white-space:nowrap}
.notice-bar-content{display:inline-flex;animation:scroll-left 40s linear infinite}
.notice-bar-content:hover{animation-play-state:paused}
.notice-item{display:inline-flex;align-items:center;margin-right:36px;font-weight:600;cursor:pointer;padding:3px 12px;border-radius:16px;transition:.3s}
.notice-item:hover{background:rgba(255,255,255,.12)}.notice-item i{color:var(--y);margin-right:6px}
.notice-badge{background:var(--y);color:var(--r);padding:1px 8px;border-radius:10px;font-size:.65rem;font-weight:700;margin-left:6px}
@keyframes scroll-left{0%{transform:translateX(100%)}100%{transform:translateX(-100%)}}
.ntabs{display:flex;flex-wrap:wrap;gap:2px;margin-bottom:12px;border-bottom:2px solid var(--g)}
.ntabs .ntab{padding:7px 14px;font-weight:600;cursor:pointer;border-radius:8px 8px 0 0;transition:.3s;border:0;background:rgba(40,167,69,.07);color:#155724;font-size:.85rem}
.ntabs .ntab:hover{background:rgba(40,167,69,.13)}.ntabs .ntab.active{background:var(--g);color:var(--w)}
.tpc{display:none}.tpc.active{display:block}.form-label{font-weight:600;color:var(--g);margin-bottom:3px;font-size:.85rem}
.form-control:focus,.form-select:focus{border-color:var(--g);box-shadow:0 0 0 .15rem rgba(40,167,69,.15)}
.btn-primary{background:var(--grad);border:none;font-weight:600}
.btn-primary:hover{background:linear-gradient(135deg,#1a7a2e,var(--g));transform:translateY(-2px)}
.btn-outline-primary{color:var(--g);border-color:var(--g)}
.btn-outline-primary:hover,.btn-outline-primary.active{background:var(--g);color:var(--w);border-color:var(--g)}
.in-page-gallery{width:100%;height:300px;background:var(--w);border-radius:10px;overflow:hidden;display:flex;flex-direction:column;border:3px solid var(--g);margin-bottom:10px}
.in-page-gallery-header{background:var(--grad);color:var(--w);font-weight:700;padding:6px;text-align:center;font-size:.85rem}
.gallery-slider{flex-grow:1;position:relative}
.gallery-slide{position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;transition:opacity 1s}
.gallery-slide.active{opacity:1}.gallery-slide img{width:100%;height:100%;object-fit:cover}
.gallery-slide-caption{position:absolute;bottom:0;left:0;right:0;background:rgba(0,0,0,.5);color:var(--w);padding:5px;text-align:center;font-size:.8rem}
.sb-card{border-top:4px solid var(--g);box-shadow:0 5px 15px rgba(0,0,0,.08);margin-bottom:10px}
.sb-card .card-header{background:var(--grad);color:var(--w);padding:7px 12px}.sb-card .card-header h6{font-size:.9rem;margin:0}
.clock-display{font-size:2.5rem;font-weight:700;color:var(--g)}
@media(max-width:991px){.navbar-collapse{background:rgba(40,167,69,.98);padding:12px;margin-top:6px}.nav-link{padding:8px 12px!important;margin:3px 0;border-bottom:none!important}}
</style></head><body>
<?php if(file_exists(__DIR__.'/includes/banner.php'))require_once __DIR__.'/includes/banner.php'; ?>
<?php if(!empty($noticeBar)&&$noticeBar!=='false'): ?><div style="background:#f8d7da;color:#721c24;padding:8px;border-radius:4px;margin:10px 0"><?php echo htmlspecialchars($noticeBar); ?></div><?php endif; ?>
<?php if(!empty($notices)): ?><div class="notice-bar"><div class="notice-bar-content">
<?php foreach($notices as$n): ?><div class="notice-item" onclick="location.href='notice.php?id=<?php echo $n['id']; ?>'"><i class="fas fa-bullhorn"></i><?php echo htmlspecialchars($n['title']); ?><span class="notice-badge">নতুন</span></div><?php endforeach; ?>
</div></div><?php endif; ?>
<nav class="navbar navbar-expand-lg"><div class="container">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNav"><span class="navbar-toggler-icon"><i class="fas fa-bars" style="color:#fff"></i></span></button>
<div class="collapse navbar-collapse" id="mainNav"><ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link active" href="#">হোম</a></li>
<li class="nav-item"><a class="nav-link" href="#sec-notices" onclick="st('sec-notices')">নোটিশ</a></li>
<li class="nav-item"><a class="nav-link" href="#sec-exams" onclick="st('sec-exams')">অনলাইন</a></li>
<li class="nav-item"><a class="nav-link" href="#sec-events" onclick="st('sec-events')">ইভেন্ট</a></li>
<li class="nav-item"><a class="nav-link" href="#sec-board" onclick="st('sec-board')">পর্ষদ</a></li>
<li class="nav-item"><a class="nav-link" data-bs-toggle="modal" data-bs-target="#teachersModal" href="#">শিক্ষক</a></li>
<li class="nav-item dropdown"><a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">অনলাইন শিক্ষা</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="online_learning/virtual_classroom.php">ভার্চুয়াল ক্লাসরুম</a></li>
<li><a class="dropdown-item" href="online_learning/online_exams.php">অনলাইন পরীক্ষা</a></li>
<li><a class="dropdown-item" href="online_learning/assignments.php">অ্যাসাইনমেন্ট</a></li>
<li><a class="dropdown-item" href="online_learning/learning_materials.php">লার্নিং ম্যাটেরিয়ালস</a></li>
</ul></li>
<li class="nav-item"><a class="nav-link" href="#sec-contact">যোগাযোগ</a></li>
<li class="nav-item"><a class="nav-link" href="admission_application.php">ভর্তি আবেদন</a></li>
<li class="nav-item"><a class="nav-link" href="teachers/dashboard.php"><i class="fas fa-chalkboard-teacher me-1"></i>শিক্ষক ড্যাশবোর্ড</a></li>
<li class="nav-item"><a class="btn btn-login ms-lg-2" href="login.php">লগইন</a></li>
</ul></div></div></nav>
<?php if(!empty($messages)): ?><section class="py-2"><div class="container">
<h2 class="section-title"><i class="fas fa-comment-dots"></i> সভাপতি ও অধ্যক্ষের বাণী</h2><div class="row">
<?php foreach($messages as$m): ?><div class="col-md-6 mb-2"><div class="card h-100"><div class="card-body py-2">
<div class="d-flex align-items-center mb-1">
<?php if(!empty($m['photo'])&&file_exists($m['photo'])): ?><img src="<?php echo htmlspecialchars($m['photo']); ?>" style="width:55px;height:55px;object-fit:cover;border-radius:50%;border:3px solid var(--r);margin-right:10px"><?php else: ?><div class="rounded-circle me-2 d-inline-flex align-items-center justify-content-center" style="width:55px;height:55px;background:var(--grad);color:var(--w);font-size:1.3rem;font-weight:700;border:3px solid var(--r)"><?php echo strtoupper(substr($m['title']??$m['name']??'P',0,1)); ?></div><?php endif; ?>
<div><h6 class="mb-0" style="color:var(--g);font-size:.9rem"><?php echo htmlspecialchars($m['title']??''); echo' ('.($mt_opts_pub[$m['message_type']]??$m['message_type']??'').')'; ?></h6></div></div>
<p class="card-text small mb-0"><?php echo nl2br(htmlspecialchars($m['message']??'')); ?></p></div></div></div><?php endforeach; ?>
</div></div></section><?php endif; ?>
<div class="container-fluid py-2" style="background:var(--grad);color:var(--w)"><div class="container"><div class="row align-items-center">
<div class="col-md-9"><h6 class="mb-0"><i class="fas fa-chalkboard-teacher me-1"></i> শিক্ষক ড্যাশবোর্ড</h6></div>
<div class="col-md-3 text-md-end mt-1 mt-md-0"><a href="teachers/dashboard.php" class="btn btn-light btn-sm text-success fw-bold">যান <i class="fas fa-arrow-right ms-1"></i></a></div>
</div></div></div>
<section class="py-2"><div class="container"><div class="row">
<div class="col-md-4 mb-2"><div class="card h-100"><div class="card-header text-white" style="background:var(--b);padding:7px 12px"><h6 class="mb-0"><i class="fas fa-calendar"></i> একাডেমিক ক্যালেন্ডার</h6></div><div class="card-body py-2">
<?php try{$st=$pdo->prepare("SELECT*FROM academic_calendar WHERE(event_date>=CURDATE() OR(event_date<=CURDATE() AND(end_date IS NULL OR end_date>=CURDATE())))AND status='active' ORDER BY event_date ASC LIMIT 5");$st->execute();$cal=$st->fetchAll(PDO::FETCH_ASSOC);}catch(Exception$e){$cal=[];}
$holidays=array_filter($cal,function($e){if($e['event_type']!=='holiday')return false;$t=date('Y-m-d');$ed=$e['event_date'];$end=$e['end_date']?:$ed;return($t>=$ed&&$t<=$end)||($t<$ed);});
$cal_json=json_encode($cal);
if(empty($cal)):?><div class="text-center py-2"><i class="fas fa-calendar-times fa-2x text-muted mb-1"></i><p class="text-muted small mb-0">কোন ইভেন্ট নেই</p></div>
<?php else: if(!empty($holidays)):?><div class="alert alert-danger py-1 small mb-2"><strong><i class="fas fa-umbrella-beach me-1"></i>ছুটি!</strong><?php foreach($holidays as$h):$t=date('Y-m-d');$ed=$h['event_date'];$end=$h['end_date']?:$ed;$a=($t>=$ed&&$t<=$end);?><br><?php echo htmlspecialchars($h['title']); if($a&&$t>$ed)echo' (চলছে)'; else{echo' - '.date('d F',strtotime($ed)); if(!empty($h['end_date'])&&$h['end_date']!=$h['event_date'])echo' থেকে '.date('d F',strtotime($h['end_date']));}?><?php endforeach;?></div><?php endif;?>
<?php foreach($cal as$ev):?><div class="d-flex align-items-center mb-1 pb-1 border-bottom"><div class="me-2 text-center" style="min-width:45px"><div class="rounded text-white py-1 px-1 small" style="background:var(--b)"><div class="fw-bold"><?php echo date('d',strtotime($ev['event_date'])); if(!empty($ev['end_date'])&&$ev['end_date']!=$ev['event_date'])echo'-'.date('d',strtotime($ev['end_date']));?></div><div style="font-size:.6rem"><?php echo date('M',strtotime($ev['event_date']));?></div></div></div><div class="flex-grow-1"><div class="small fw-bold"><?php echo htmlspecialchars($ev['title']);?></div><div class="text-muted small" style="font-size:.7rem"><?php $tl=['holiday'=>'ছুটি','exam'=>'পরীক্ষা','event'=>'ইভেন্ট','other'=>'অন্যান্য'];echo$tl[$ev['event_type']]??'';?></div><div class="d-flex small mt-1" id="countdown-<?php echo $ev['id'];?>"><div class="me-2"><span class="fw-bold" id="days-<?php echo $ev['id'];?>">--</span> ??</div><div class="me-2"><span class="fw-bold" id="hours-<?php echo $ev['id'];?>">--</span> ?</div><div class="me-2"><span class="fw-bold" id="minutes-<?php echo $ev['id'];?>">--</span> ??</div><div><span class="fw-bold" id="seconds-<?php echo $ev['id'];?>">--</span> ??</div></div></div></div><?php endforeach;?>
<div class="text-center mt-1"><a href="academic_calendar_view.php" class="btn btn-outline-primary btn-sm">সম্পূর্ণ ক্যালেন্ডার</a></div><?php endif;?>
</div></div></div>
<div class="col-md-4 mb-2"><div class="card h-100"><div class="card-header text-white" style="background:var(--g);padding:7px 12px"><h6 class="mb-0"><i class="fas fa-clock"></i> বর্তমান সময়</h6></div><div class="card-body text-center py-3">
<div class="clock-display" id="currentTime">--:--:--</div>
<div class="h6 mt-1 text-muted" id="currentDate"></div>
<div class="mt-2"><div class="d-inline-block p-2 bg-light rounded"><div class="d-flex justify-content-between gap-3"><div class="text-center"><div class="h4 mb-0 fw-bold" id="hours">--</div><small class="text-muted">ঘণ্টা</small></div><div class="text-center"><div class="h4 mb-0 fw-bold" id="minutes">--</div><small class="text-muted">মিনিট</small></div><div class="text-center"><div class="h4 mb-0 fw-bold" id="seconds">--</div><small class="text-muted">সেকেন্ড</small></div></div></div></div></div></div></div>
<div class="col-md-4 mb-2"><?php if(!empty($gallery_images)):?><div class="in-page-gallery" style="height:280px"><div class="in-page-gallery-header"><i class="fas fa-images"></i> গ্যালারি</div><div class="gallery-slider">
<?php foreach($gallery_images as$i=>$img):?><div class="gallery-slide<?php echo$i===0?' active':'';?>"><img src="<?php echo htmlspecialchars($img['image_path']);?>" alt="<?php echo htmlspecialchars($img['title']);?>"><div class="gallery-slide-caption"><?php echo htmlspecialchars($img['title']);?></div></div><?php endforeach;?>
</div></div><?php endif;?></div>
</div></div></section><section class="py-2"><div class="container"><div class="row">
<div class="col-lg-4">
<div class="card sb-card"><div class="card-header"><h6><i class="fas fa-laptop me-1"></i>অনলাইন পরীক্ষা</h6></div><div class="card-body text-center py-2"><p class="small mb-1"><?php echo count($online_exams);?> টি পরীক্ষা</p><a href="online_learning/online_exams.php" class="btn btn-primary btn-sm w-100"><i class="fas fa-sign-in-alt me-1"></i>শুরু করুন</a></div></div>
<div class="card sb-card"><div class="card-header" style="background:var(--b)!important"><h6><i class="fas fa-graduation-cap me-1"></i>বোর্ডের ফলাফল</h6></div><div class="card-body text-center py-2"><p class="small mb-1">SSC ব্যাচ ও বোর্ডের ফলাফল</p><a href="jessore_board_ssc_bangla_english_marksheet.php" class="btn btn-sm w-100" style="background:var(--b);border:none;color:var(--w)"><i class="fas fa-search me-1"></i>সার্চ</a></div></div>
<div class="card sb-card"><div class="card-header"><h6><i class="fas fa-user-plus me-1"></i>ভর্তি আবেদন</h6></div><div class="card-body text-center py-2"><p class="small mb-1">এখন আবেদন করুন</p><a href="admission_application.php" class="btn btn-primary btn-sm w-100"><i class="fas fa-clipboard me-1"></i>ফর্ম</a><div class="mt-1 d-flex gap-1"><a href="admission_receipt.php" class="btn btn-outline-secondary btn-sm flex-fill">রশিদ</a><a href="student_login.php" class="btn btn-outline-info btn-sm flex-fill">লগইন</a></div></div></div>
<div class="card sb-card"><div class="card-header" style="background:var(--g)!important"><h6><i class="fas fa-chalkboard-teacher me-1"></i>শিক্ষক ড্যাশবোর্ড</h6></div><div class="card-body py-2"><p class="small">ড্যাশবোর্ডে প্রবেশ করুন</p><a href="teachers/dashboard.php" class="btn btn-sm w-100" style="background:var(--g);border:none;color:var(--w)"><i class="fas fa-arrow-right me-1"></i>ড্যাশবোর্ড</a></div></div>
</div>
<div class="col-lg-8">
<h2 class="section-title text-center" style="font-size:1.2rem;padding:8px;background:var(--grad);color:var(--w);border-radius:8px;border-bottom:none;justify-content:center"><i class="fas fa-search" style="color:var(--w)"></i> ফলাফল সার্চ</h2>
<div class="card" style="border-top:4px solid var(--g)"><div class="card-body p-2">
<div class="ntabs" id="reportTabs">
<button class="ntab active" onclick="rt('result',this)">ফলাফল</button>
<button class="ntab" onclick="rt('separate',this)">রোল ও ক্লাস</button>
<button class="ntab" onclick="rt('jessore',this)">বোর্ডের ফল</button>
<button class="ntab" onclick="rt('fee',this)">ফি</button>
<button class="ntab" onclick="rt('merit',this)">মেধা</button>
</div>
<div class="tpc active" id="rp-result"><form action="public_report.php" method="GET"><div class="row g-1">
<div class="col-4"><input type="text" name="roll" class="form-control form-control-sm" placeholder="রোল" required></div>
<div class="col-4"><select name="class" class="form-select form-select-sm" required><option value="">ক্লাস</option><?php foreach($classes as$c):?><option value="<?php echo htmlspecialchars($c['name']);?>"><?php echo htmlspecialchars($c['name'].($c['section']?' - '.$c['section']:''));?></option><?php endforeach;?></select></div>
<div class="col-4"><select name="session" class="form-select form-select-sm" required><option value="">সেশন</option><?php foreach($sessions as$s):?><option value="<?php echo $s;?>"><?php echo $s;?></option><?php endforeach;?></select></div>
<div class="col-8"><select name="exam" class="form-select form-select-sm" required><option value="">পরীক্ষা</option><?php foreach($exams as$ex):?><option value="<?php echo htmlspecialchars($ex['exam_type']);?>"><?php echo htmlspecialchars($ex['name']);?></option><?php endforeach;?></select></div>
<div class="col-4"><button type="submit" class="btn btn-primary btn-sm w-100"><i class="fas fa-search"></i> সার্চ</button></div>
</div></form></div>
<div class="tpc" id="rp-separate"><form action="public_separate_bangla_english_marksheet.php" method="GET"><div class="row g-1">
<div class="col-4"><input type="text" name="roll" class="form-control form-control-sm" placeholder="রোল" required></div>
<div class="col-4"><select name="class" class="form-select form-select-sm" required><option value="">ক্লাস</option><?php foreach($classes as$c):?><option value="<?php echo htmlspecialchars($c['name']);?>"><?php echo htmlspecialchars($c['name'].($c['section']?' - '.$c['section']:''));?></option><?php endforeach;?></select></div>
<div class="col-4"><select name="session" class="form-select form-select-sm" required><option value="">সেশন</option><?php foreach($sessions as$s):?><option value="<?php echo $s;?>"><?php echo $s;?></option><?php endforeach;?></select></div>
<div class="col-8"><select name="exam" class="form-select form-select-sm" required><option value="">পরীক্ষা</option><?php foreach($exams as$ex):?><option value="<?php echo htmlspecialchars($ex['exam_type']);?>"><?php echo htmlspecialchars($ex['name']);?></option><?php endforeach;?></select></div>
<div class="col-4"><button type="submit" class="btn btn-primary btn-sm w-100"><i class="fas fa-search"></i> সার্চ</button></div>
</div></form></div>
<div class="tpc" id="rp-jessore"><form action="jessore_board_ssc_bangla_english_marksheet.php" method="GET"><div class="row g-1">
<div class="col-4"><input type="text" name="roll" class="form-control form-control-sm" placeholder="রোল" required></div>
<div class="col-4"><select name="class" class="form-select form-select-sm" required><option value="">ক্লাস</option><?php foreach($classes as$c):?><option value="<?php echo htmlspecialchars($c['name']);?>"><?php echo htmlspecialchars($c['name'].($c['section']?' - '.$c['section']:''));?></option><?php endforeach;?></select></div>
<div class="col-4"><select name="session" class="form-select form-select-sm" required><option value="">সেশন</option><?php foreach($sessions as$s):?><option value="<?php echo $s;?>"><?php echo $s;?></option><?php endforeach;?></select></div>
<div class="col-8"><select name="exam" class="form-select form-select-sm" required><option value="">পরীক্ষা</option><?php foreach($exams as$ex):?><option value="<?php echo htmlspecialchars($ex['exam_type']);?>"><?php echo htmlspecialchars($ex['name']);?></option><?php endforeach;?></select></div>
<div class="col-4"><button type="submit" class="btn btn-primary btn-sm w-100"><i class="fas fa-search"></i> সার্চ</button></div>
</div></form></div>
<div class="tpc" id="rp-fee"><form action="public_student_report.php" method="GET"><div class="row g-1">
<div class="col-4"><input type="text" name="roll" class="form-control form-control-sm" placeholder="রোল" required></div>
<div class="col-5"><select name="class" class="form-select form-select-sm" required><option value="">ক্লাস</option><?php foreach($classes as$c):?><option value="<?php echo htmlspecialchars($c['name']);?>"><?php echo htmlspecialchars($c['name'].($c['section']?' - '.$c['section']:''));?></option><?php endforeach;?></select></div>
<div class="col-3"><select name="session" class="form-select form-select-sm" required><option value="">সেশন</option><?php foreach($sessions as$s):?><option value="<?php echo $s;?>"><?php echo $s;?></option><?php endforeach;?></select></div>
<div class="col-12"><button type="submit" class="btn btn-primary btn-sm w-100"><i class="fas fa-search"></i> ফি ও রিপোর্ট</button></div>
</div></form></div>
<div class="tpc" id="rp-merit"><form action="reports/merit_position_pdf.php" method="GET" target="_blank"><div class="row g-1">
<div class="col-4"><select name="class_id" class="form-select form-select-sm" required><option value="">ক্লাস</option><?php foreach($classes as$c):?><option value="<?php echo $c['id'];?>"><?php echo htmlspecialchars($c['name'].($c['section']?' - '.$c['section']:''));?></option><?php endforeach;?></select></div>
<div class="col-4"><select name="session" class="form-select form-select-sm" required><option value="">সেশন</option><?php foreach($sessions as$s):?><option value="<?php echo $s;?>"><?php echo $s;?></option><?php endforeach;?></select></div>
<div class="col-4"><select name="exam_type" class="form-select form-select-sm" required><option value="">পরীক্ষা</option><?php foreach($exams as$ex):?><option value="<?php echo htmlspecialchars($ex['exam_type']);?>"><?php echo htmlspecialchars($ex['name']);?></option><?php endforeach;?></select></div>
<div class="col-12"><button type="submit" class="btn btn-success btn-sm w-100" style="background:var(--g);border:none"><i class="fas fa-file-pdf"></i> মেধা তালিকা</button></div>
</div></form></div>
</div></div>

<h2 class="section-title"><i class="fas fa-user-graduate"></i> শিক্ষার্থী তালিকা</h2>
<div class="card mb-2"><div class="card-body py-2">
<form id="sf" method="GET" action="public_home.php#students" class="row g-1 align-items-end">
<div class="col-md-3"><label class="form-label" style="font-size:.8rem">নাম</label><input type="text" name="name" class="form-control form-control-sm" value="<?php echo htmlspecialchars($nameInput);?>" placeholder="নাম"></div>
<div class="col-md-2"><label class="form-label" style="font-size:.8rem">রোল</label><input type="text" name="roll" class="form-control form-control-sm" value="<?php echo htmlspecialchars($rollInput);?>" placeholder="রোল"></div>
<div class="col-md-2"><label class="form-label" style="font-size:.8rem">ক্লাস</label><select name="class" class="form-select form-select-sm"><option value="">সব</option><?php foreach($classes as$c):?><option value="<?php echo $c['id'];?>"<?php echo($classIdInput!==''&&(int)$classIdInput===(int)$c['id'])?' selected':'';?>><?php echo htmlspecialchars($c['name'].' '.$c['section']);?></option><?php endforeach;?></select></div>
<div class="col-md-2"><label class="form-label" style="font-size:.8rem">সেশন</label><select name="session" class="form-select form-select-sm"><option value="">সব</option><?php foreach($sessions as$s):?><option value="<?php echo $s;?>"<?php echo($sessionInput!==''&&(string)$sessionInput===(string)$s)?' selected':'';?>><?php echo $s;?></option><?php endforeach;?></select></div>
<div class="col-md-3 d-flex gap-1">
<div class="btn-group btn-group-sm"><button type="button" class="btn btn-outline-primary<?php echo $view==='grid'?' active':'';?>" id="gb"><i class="fas fa-th-large"></i></button><button type="button" class="btn btn-outline-primary<?php echo $view==='table'?' active':'';?>" id="tb"><i class="fas fa-list"></i></button></div>
<button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-search"></i></button></div>
<input type="hidden" name="view" id="vi" value="<?php echo htmlspecialchars($view);?>">
<input type="hidden" name="page" id="pi" value="<?php echo $currentPage;?>">
</form></div></div>
<?php $af=[];if($nameInput!=='')$af[]="নাম: ".htmlspecialchars($nameInput);if($rollInput!=='')$af[]="রোল: ".htmlspecialchars($rollInput);if($classIdInput!==''){$cn='';foreach($classes as$c){if((int)$c['id']===(int)$classIdInput){$cn=$c['name'].' - '.$c['section'];break;}}$af[]="ক্লাস: ".htmlspecialchars($cn);}if($sessionInput!=='')$af[]="সেশন: ".htmlspecialchars($sessionInput);if(!empty($af)&&$is_search):?>
<div class="card mb-2" style="border-color:var(--b)"><div class="card-body py-1"><div class="d-flex flex-wrap align-items-center gap-2"><small class="text-muted">ফিল্টার:</small><?php foreach($af as$f):?><span class="badge" style="background:var(--b)"><?php echo $f;?></span><?php endforeach;?><a href="public_home.php#students" class="btn btn-sm btn-outline-danger ms-auto"><i class="fas fa-times"></i>রিসেট</a></div></div></div>
<?php endif;?>
<?php if($is_search):?>
<div id="gv" class="<?php echo $view==='table'?'d-none':'';?>">
<?php if($totalStudents>0):$p1=max(1,$currentPage-1);$p2=min($totalPages,$currentPage+1);$pd=$currentPage<=1;$nd=$currentPage>=$totalPages;?>
<div class="d-flex justify-content-between align-items-center mb-1"><small class="text-muted"><?php echo $totalStudents;?> টি <strong><?php echo min($totalStudents,$offset+1);?>-<?php echo min($totalStudents,$offset+count($students));?></strong></small>
<?php if($totalPages>1):?><div class="d-flex gap-1 align-items-center"><div class="btn-group btn-group-sm"><?php if($pd):?><span class="btn btn-outline-primary disabled"><i class="fas fa-angle-left"></i></span><?php else:?><a class="btn btn-outline-primary" href="public_home.php?<?php echo $bsq(['page'=>$p1]);?>#students"><i class="fas fa-angle-left"></i></a><?php endif;?><?php if($nd):?><span class="btn btn-outline-primary disabled"><i class="fas fa-angle-right"></i></span><?php else:?><a class="btn btn-outline-primary" href="public_home.php?<?php echo $bsq(['page'=>$p2]);?>#students"><i class="fas fa-angle-right"></i></a><?php endif;?></div><select class="form-select form-select-sm sps" style="width:auto;min-width:100px"><?php for($i=1;$i<=$totalPages;$i++):?><option value="<?php echo $i;?>"<?php echo $i===$currentPage?' selected':'';?>>পাতা <?php echo $i;?></option><?php endfor;?></select></div><?php endif;?></div>
<?php endif;?>
<div class="row g-2"><?php if(empty($students)):?><div class="col-12"><div class="alert alert-info py-1 small">কোনো শিক্ষার্থী পাওয়া যায়নি</div></div><?php else: foreach($students as$st):?><div class="col-lg-3 col-md-4 col-sm-6"><div class="card h-100 text-center"><div class="card-body py-2"><?php if(!empty($st['photo'])&&file_exists($st['photo'])):?><img src="<?php echo htmlspecialchars($st['photo']);?>" class="rounded-circle mb-1" style="width:65px;height:65px;object-fit:cover;border:2px solid var(--g)"><?php else:?><div class="rounded-circle d-inline-flex align-items-center justify-content-center mb-1" style="width:65px;height:65px;background:var(--grad);color:var(--w);font-size:1.5rem;font-weight:700;border:2px solid var(--r)"><?php echo strtoupper(substr($st['first_name'],0,1));?></div><?php endif;?><h6 class="card-title mb-0 small" style="color:var(--g)"><?php echo htmlspecialchars($st['first_name'].' '.$st['last_name']);?></h6><small class="text-muted">রোল: <?php echo htmlspecialchars($st['roll_number']);?> | <?php echo htmlspecialchars($st['class_name'].($st['section']?' - '.$st['section']:''));?></small></div></div></div><?php endforeach; endif;?></div></div>
<div id="tv" class="<?php echo $view==='table'?'':'d-none';?>"><div class="card"><div class="card-body p-1"><div class="table-responsive"><table class="table table-striped table-sm mb-0"><thead><tr><th>ছবি</th><th>নাম</th><th>রোল</th><th>ক্লাস</th><th>বিষয়</th></tr></thead><tbody><?php if(empty($students)):?><tr><td colspan="5" class="text-center small">কোনো শিক্ষার্থী পাওয়া যায়নি</td></tr><?php else: foreach($students as$st):?><tr><td><?php if(!empty($st['photo'])&&file_exists($st['photo'])):?><img src="<?php echo htmlspecialchars($st['photo']);?>" class="rounded-circle" style="width:28px;height:28px;object-fit:cover"><?php else:?><div class="rounded-circle d-inline-flex align-items-center justify-content-center" style="width:28px;height:28px;background:var(--grad);color:var(--w);font-weight:700;font-size:.7rem"><?php echo strtoupper(substr($st['first_name'],0,1));?></div><?php endif;?></td><td class="small"><?php echo htmlspecialchars($st['first_name'].' '.$st['last_name']);?></td><td class="small"><?php echo htmlspecialchars($st['roll_number']);?></td><td class="small"><?php echo htmlspecialchars($st['class_name'].($st['section']?' - '.$st['section']:''));?></td><td class="small"><?php echo htmlspecialchars($st['subjects']);?></td></tr><?php endforeach; endif;?></tbody></table></div></div></div></div>
<?php else:?><div class="alert alert-info py-1 small">উপরে ফর্ম ব্যবহার করে সার্চ করুন</div><?php endif;?>

</div></div></div></section>
<div class="container py-1"><div class="ntabs" id="sectionTabs">
<button class="ntab active" onclick="st('sec-notices',this)"><i class="fas fa-bullhorn"></i> নোটিশ</button>
<button class="ntab" onclick="st('sec-exams',this)"><i class="fas fa-laptop"></i> অনলাইন পরীক্ষা</button>
<button class="ntab" onclick="st('sec-events',this)"><i class="fas fa-calendar"></i> ইভেন্ট</button>
<button class="ntab" onclick="st('sec-board',this)"><i class="fas fa-users"></i> পর্ষদ</button>
<button class="ntab" data-bs-toggle="modal" data-bs-target="#teachersModal"><i class="fas fa-chalkboard-teacher"></i> শিক্ষক</button>
<button class="ntab" onclick="st('sec-contact',this)"><i class="fas fa-phone"></i> যোগাযোগ</button>
</div>
<div class="tpc active" id="sec-notices"><div class="row g-2"><?php if(empty($notices)):?><div class="col-12"><div class="alert alert-info py-1 small">কোনো নোটিশ পাওয়া যায়নি</div></div><?php else: foreach($notices as$n):?><div class="col-md-6"><div class="card h-100"><div class="card-body py-2"><h6 style="color:var(--g)" class="mb-1 small"><i class="fas fa-file-alt"></i> <?php echo htmlspecialchars($n['title']);?></h6><small class="text-muted"><i class="far fa-calendar"></i> <?php echo bn_date($n['publish_date']);?></small><p class="card-text small mt-1 mb-1"><?php echo nl2br(htmlspecialchars(mb_substr($n['content'],0,120,'UTF-8')));?>...</p><a href="notice.php?id=<?php echo $n['id'];?>" class="btn btn-primary btn-sm">বিস্তারিত</a></div></div></div><?php endforeach; endif;?></div></div>
<div class="tpc" id="sec-exams"><?php if(empty($online_exams)):?><div class="alert alert-info py-1 small">কোনো পরীক্ষা নেই</div><?php else:?><div class="row g-2"><?php foreach($online_exams as$ex):?><div class="col-md-4"><div class="card h-100"><div class="card-body py-2"><h6 class="small" style="color:var(--g)"><?php echo htmlspecialchars($ex['name']);?></h6><small class="d-block text-muted"><?php echo htmlspecialchars($ex['subject_name']);?> - <?php echo htmlspecialchars($ex['class_name']);?></small><small class="d-block text-muted"><?php echo bn_date($ex['exam_date']);?> | <?php echo $ex['duration'];?> মি</small><span class="badge <?php echo $ex['status']==='ongoing'?'bg-success':'bg-warning';?>"><?php echo $ex['status']==='ongoing'?'চলছে':'নির্ধারিত';?></span></div><div class="card-footer bg-transparent border-top-0 pt-0"><?php if($ex['status']==='ongoing'):?><a href="online_learning/online_exams.php" class="btn btn-primary btn-sm w-100">শুরু করুন</a><?php else:?><a href="online_learning/online_exams.php" class="btn btn-outline-primary btn-sm w-100">বিস্তারিত</a><?php endif;?></div></div></div><?php endforeach;?></div><?php endif;?></div>
<div class="tpc" id="sec-events"><div class="row g-2"><?php if(empty($events)):?><div class="col-12"><div class="alert alert-info py-1 small">কোনো ইভেন্ট নেই</div></div><?php else: foreach($events as$ev):?><div class="col-md-4"><div class="card h-100"><div class="card-body py-2"><div class="d-flex align-items-center mb-1"><div class="me-2 text-center" style="min-width:48px"><div style="background:var(--grad);color:var(--w);padding:6px;border-radius:6px"><div class="fw-bold small"><?php echo date('d',strtotime($ev['event_date']));?></div><div style="font-size:.6rem"><?php echo date('M',strtotime($ev['event_date']));?></div></div></div><h6 class="mb-0 small" style="color:var(--g)"><?php echo htmlspecialchars($ev['title']);?></h6></div><?php if($ev['location']):?><small class="text-muted d-block"><i class="fas fa-map-marker-alt"></i> <?php echo htmlspecialchars($ev['location']);?></small><?php endif;?><p class="card-text small mt-1 mb-0"><?php echo nl2br(htmlspecialchars(mb_substr($ev['description']??'',0,80,'UTF-8')));?>...</p></div></div></div><?php endforeach; endif;?></div></div>
<div class="tpc" id="sec-board"><?php if(empty($board)):?><div class="alert alert-info py-1 small">কোনো পর্ষদ নেই</div><?php else:?><div class="row g-2"><?php foreach($board as$m):?><div class="col-lg-3 col-md-4 col-sm-6"><div class="card h-100 text-center"><div class="card-body py-2"><?php if(!empty($m['photo'])&&file_exists($m['photo'])):?><img src="<?php echo htmlspecialchars($m['photo']);?>" class="rounded-circle mb-1" style="width:65px;height:65px;object-fit:cover;border:2px solid var(--g)"><?php else:?><div class="rounded-circle d-inline-flex align-items-center justify-content-center mb-1" style="width:65px;height:65px;background:var(--grad);color:var(--w);font-size:1.5rem;font-weight:700;border:2px solid var(--r)"><?php echo strtoupper(substr($m['name'],0,1));?></div><?php endif;?><h6 class="small mb-0" style="color:var(--g)"><?php echo htmlspecialchars($m['name']);?></h6><?php if($m['board_role']):?><small class="text-muted d-block"><?php echo htmlspecialchars($m['board_role']);?></small><?php endif;?></div></div></div><?php endforeach;?></div><?php endif;?></div>
<div class="tpc" id="sec-teachers"><?php if(empty($teachers)):?><div class="alert alert-info py-1 small">কোনো শিক্ষক পাওয়া যায়নি</div><?php else:?><div class="row g-2"><?php foreach($teachers as$t):?><div class="col-lg-3 col-md-4 col-sm-6"><div class="card h-100 text-center"><div class="card-body py-2"><?php if(!empty($t['photo'])&&file_exists($t['photo'])):?><img src="<?php echo htmlspecialchars($t['photo']);?>" class="rounded-circle mb-1" style="width:65px;height:65px;object-fit:cover;border:2px solid var(--g)"><?php else:?><div class="rounded-circle d-inline-flex align-items-center justify-content-center mb-1" style="width:65px;height:65px;background:var(--grad);color:var(--w);font-size:1.5rem;font-weight:700;border:2px solid var(--r)"><?php echo strtoupper(substr($t['first_name'],0,1));?></div><?php endif;?><h6 class="small mb-0" style="color:var(--g)"><?php echo htmlspecialchars($t['first_name'].' '.$t['last_name']);?></h6><?php if($t['designation']):?><small class="text-muted d-block"><?php echo htmlspecialchars($t['designation']);?></small><?php endif;?></div></div></div><?php endforeach;?></div><?php endif;?></div>
<div class="tpc" id="sec-contact"><div class="row"><div class="col-md-6 mb-2"><div class="card h-100"><div class="card-body"><h6 style="color:var(--g)"><i class="fas fa-map-marker-alt"></i> ঠিকানা</h6><p class="small"><?php echo nl2br(htmlspecialchars($contact_address));?></p><h6 style="color:var(--g)" class="mt-2"><i class="fas fa-phone"></i> ফোন</h6><p class="small"><?php echo htmlspecialchars($contact_phone);?><br>+8801717861762</p><h6 style="color:var(--g)" class="mt-2"><i class="fas fa-envelope"></i> ইমেইল</h6><p class="small"><?php echo htmlspecialchars($contact_email);?><br>admin@school.edu.bd</p></div></div></div><div class="col-md-6 mb-2"><div class="card h-100"><div class="card-body"><h6 style="color:var(--g)"><i class="fas fa-paper-plane"></i> বার্তা পাঠান</h6><form><div class="mb-1"><input type="text" class="form-control form-control-sm" placeholder="নাম"></div><div class="mb-1"><input type="email" class="form-control form-control-sm" placeholder="ইমেইল"></div><div class="mb-1"><textarea class="form-control form-control-sm" rows="2" placeholder="বার্তা"></textarea></div><button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-paper-plane"></i> পাঠান</button></form></div></div></div></div></div>
</div>
<button class="scroll-to-top" id="scrollToTop" title="উপরে যান"><i class="fas fa-arrow-up"></i></button>
<footer class="footer"><div class="container"><div class="row">
<div class="col-md-5"><h6><i class="fas fa-graduation-cap"></i> <?php echo htmlspecialchars($site_name); ?></h6><p class="mt-2 small">শিক্ষা, শৃঙ্খলা ও মানবিকতার সমন্বয়ে আলোকিত মানুষ তৈরি</p></div>
<div class="col-md-3"><h6>গুরুত্বপূর্ণ লিংক</h6><ul class="list-unstyled mt-2 small"><li><a href="#notices">নোটিশ</a></li><li><a href="#events">ইভেন্ট</a></li><li><a href="#students">শিক্ষার্থী</a></li><li><a href="#contact">যোগাযোগ</a></li><li><a href="teachers/dashboard.php">শিক্ষক ড্যাশবোর্ড</a></li><li><a href="login.php">লগইন</a></li></ul></div>
<div class="col-md-4"><h6>যোগাযোগ</h6><p class="mt-2 small text-white-50"><i class="fas fa-phone"></i> <?php echo htmlspecialchars($contact_phone); ?><br><i class="fas fa-envelope"></i> <?php echo htmlspecialchars($contact_email); ?></p></div>
</div><hr class="my-2" style="border-color:rgba(255,255,255,.15)"><div class="text-center text-white-50 small"><p class="mb-0">&copy; 2025 সর্বস্বত্ব সংরক্ষিত</p></div></div></footer>

<div class="modal fade" id="teachersModal" tabindex="-1"><div class="modal-dialog modal-lg modal-dialog-scrollable"><div class="modal-content">
<div class="modal-header py-2" style="background:var(--g);color:#fff"><h6 class="modal-title"><i class="fas fa-chalkboard-teacher me-1"></i> আমাদের শিক্ষকবৃন্দ</h6><button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button></div>
<div class="modal-body p-3">
<?php if(empty($teachers)):?><div class="alert alert-info py-1 small">কোনো শিক্ষক পাওয়া যায়নি</div>
<?php else:?><div class="row g-3"><?php foreach($teachers as$t):?><div class="col-md-4 col-sm-6"><div class="card h-100 text-center" style="border-top:3px solid var(--g)"><div class="card-body py-3">
<?php if(!empty($t['photo'])&&file_exists($t['photo'])):?><img src="<?=htmlspecialchars($t['photo'])?>" class="rounded-circle mb-2" style="width:80px;height:80px;object-fit:cover;border:3px solid var(--g)">
<?php else:?><div class="rounded-circle d-inline-flex align-items-center justify-content-center mb-2" style="width:80px;height:80px;background:var(--grad);color:#fff;font-size:2rem;font-weight:700;border:3px solid var(--r)"><?=strtoupper(substr($t['first_name'],0,1))?></div>
<?php endif;?>
<h6 class="mb-0" style="color:var(--g);font-size:.88rem"><?=htmlspecialchars($t['first_name'].' '.$t['last_name'])?></h6>
<?php if($t['designation']):?><small class="text-muted d-block mb-1"><?=htmlspecialchars($t['designation'])?></small><?php endif;?>
<div class="mt-1" style="font-size:.72rem;color:#666">
<?php if($t['qualification']):?><div><i class="fas fa-graduation-cap me-1 text-primary"></i><?=htmlspecialchars($t['qualification'])?></div><?php endif;?>
<?php if($t['experience_years']):?><div><i class="fas fa-briefcase me-1 text-success"></i><?=htmlspecialchars($t['experience_years'])?> বছর অভিজ্ঞতা</div><?php endif;?>
<?php if($t['phone']):?><div><i class="fas fa-phone me-1 text-warning"></i><?=htmlspecialchars($t['phone'])?></div><?php endif;?>
</div></div></div></div><?php endforeach;?></div><?php endif;?>
</div></div></div>

<div class="modal fade" id="studentsModal" tabindex="-1"><div class="modal-dialog modal-lg modal-dialog-scrollable"><div class="modal-content">
<div class="modal-header py-2" style="background:var(--b);color:#fff"><h6 class="modal-title"><i class="fas fa-user-graduate me-1"></i> শিক্ষার্থী খুঁজুন</h6><button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button></div>
<div class="modal-body p-3">
<div class="mb-2"><input type="text" id="studentSearchInput" class="form-control form-control-sm" placeholder="নাম, রোল বা ক্লাস দিয়ে খুঁজুন..." autofocus></div>
<div id="studentsModalBody"><div class="text-center py-3 text-muted" style="font-size:.82rem"><i class="fas fa-search me-1"></i>উপরের বক্সে নাম, রোল বা ক্লাস লিখে সার্চ করুন</div></div>
</div>
<div class="modal-footer py-1" id="studentsModalFoot" style="display:none"><div class="d-flex justify-content-between align-items-center w-100"><small id="studentsInfo" class="text-muted"></small><div id="studentsPag"></div></div></div>
</div></div></div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
const s=document.getElementById('scrollToTop');
window.addEventListener('scroll',()=>s.classList.toggle('show',window.pageYOffset>300));
s.addEventListener('click',()=>window.scrollTo({top:0,behavior:'smooth'}));

function rt(id,btn){document.querySelectorAll('#reportTabs .ntab').forEach(b=>b.classList.remove('active'));document.querySelectorAll('[id^="rp-"]').forEach(p=>p.classList.remove('active'));if(btn)btn.classList.add('active');const el=document.getElementById('rp-'+id);if(el)el.classList.add('active');}

function st(id,btn){document.querySelectorAll('#sectionTabs .ntab').forEach(b=>b.classList.remove('active'));document.querySelectorAll('#sectionTabs~.tpc').forEach(p=>p.classList.remove('active'));if(btn)btn.classList.add('active');const el=document.getElementById(id);if(el)el.classList.add('active');}

document.addEventListener('DOMContentLoaded',function(){
var studentsPage=1,studentsTimer=null;
function loadStudentsPage(p,q){
studentsPage=p;
document.getElementById('studentsModalBody').innerHTML='<div class="text-center py-3"><i class="fas fa-spinner fa-spin me-1"></i>লোড হচ্ছে...</div>';
fetch('public_home.php?ajax_students=1&q='+encodeURIComponent(q||'')+'&page='+p).then(function(r){return r.json()}).then(function(d){
if(!d.ok||!d.students||!d.students.length){document.getElementById('studentsModalBody').innerHTML='<div class="alert alert-info py-1 small">কোনো শিক্ষার্থী পাওয়া যায়নি</div>';document.getElementById('studentsModalFoot').style.display='none';return;}
var h='<div class="row g-2">';d.students.forEach(function(s){h+='<div class="col-lg-3 col-md-4 col-sm-6"><div class="card h-100 text-center"><div class="card-body py-2">';h+=s.photo?'<img src="'+s.photo+'" class="rounded-circle mb-1" style="width:55px;height:55px;object-fit:cover;border:2px solid #1565c0">':'<div class="rounded-circle d-inline-flex align-items-center justify-content-center mb-1" style="width:55px;height:55px;background:#1565c0;color:#fff;font-size:1.2rem;font-weight:700">'+s.first_name.charAt(0)+'</div>';h+='<h6 class="mb-0" style="color:#1565c0;font-size:.78rem">'+s.first_name+' '+s.last_name+'</h6>';h+='<small class="text-muted" style="font-size:.68rem">রোল: '+s.roll_number+' | '+(s.class_name||'')+(s.section?' - '+s.section:'')+'</small>';h+='</div></div></div>';});h+='</div>';
document.getElementById('studentsModalBody').innerHTML=h;
var info=document.getElementById('studentsInfo'),pg=document.getElementById('studentsPag');info.textContent='মোট: '+d.total+' জন | পাতা '+d.page+'/'+d.totalPages;
if(d.totalPages>1){var ph='';ph+='<button class="btn btn-sm btn-outline-primary" onclick="loadStudentsPage('+(d.page-1)+',document.getElementById(\'studentSearchInput\').value)" '+(d.page<=1?'disabled':'')+'>আগে</button> ';for(var i=Math.max(1,d.page-2);i<=Math.min(d.totalPages,d.page+2);i++){ph+='<button class="btn btn-sm '+(i===d.page?'btn-primary':'btn-outline-primary')+'" onclick="loadStudentsPage('+i+',document.getElementById(\'studentSearchInput\').value)" style="margin:0 2px">'+i+'</button> ';}
ph+='<button class="btn btn-sm btn-outline-primary" onclick="loadStudentsPage('+(d.page+1)+',document.getElementById(\'studentSearchInput\').value)" '+(d.page>=d.totalPages?'disabled':'')+'>পরে</button>';pg.innerHTML=ph;}
document.getElementById('studentsModalFoot').style.display='flex';
}).catch(function(){document.getElementById('studentsModalBody').innerHTML='<div class="alert alert-danger py-1 small">লোড করা যায়নি</div>';});
}
document.getElementById('studentSearchInput').addEventListener('input',function(){var v=this.value;clearTimeout(studentsTimer);studentsTimer=setTimeout(function(){loadStudentsPage(1,v);},400);});
document.getElementById('studentsModal').addEventListener('show.bs.modal',function(){setTimeout(function(){document.getElementById('studentSearchInput').focus();},300);});
const sf=document.getElementById('sf'),pi=document.getElementById('pi'),gv=document.getElementById('gv'),tv=document.getElementById('tv'),gb=document.getElementById('gb'),tbb=document.getElementById('tb'),ps=document.querySelectorAll('.sps'),si=document.querySelectorAll('input[name="name"],input[name="roll"]'),ss=document.querySelectorAll('select[name="class"],select[name="session"]');
if(gb&&tbb&&gv&&tv){
const pv=localStorage.getItem('studentView')||'grid';
function sv(v){if(v==='table'){gv.classList.add('d-none');tv.classList.remove('d-none');gb.classList.remove('active');tbb.classList.add('active');localStorage.setItem('studentView','table');if(sf)document.getElementById('vi').value='table';}else{tv.classList.add('d-none');gv.classList.remove('d-none');tbb.classList.remove('active');gb.classList.add('active');localStorage.setItem('studentView','grid');if(sf)document.getElementById('vi').value='grid';}}
gb.addEventListener('click',function(){sv('grid');if(sf){pi.value='1';sf.submit();}});
tbb.addEventListener('click',function(){sv('table');if(sf){pi.value='1';sf.submit();}});
sv(pv);}
if(ps.length&&sf)ps.forEach(function(s){s.addEventListener('change',function(){pi.value=s.value;sf.submit();});});
let st2;function hsc(){clearTimeout(st2);st2=setTimeout(function(){if(sf){pi.value='1';sf.submit();}},800);}
if(si.length)si.forEach(function(i){i.addEventListener('input',hsc);});
if(ss.length)ss.forEach(function(s){s.addEventListener('change',function(){if(sf){pi.value='1';sf.submit();}});});
if(sf)sf.addEventListener('keydown',function(e){if(e.key==='Enter'&&e.target.tagName!=='BUTTON'){e.preventDefault();hsc();}});
const slides=document.querySelectorAll('.gallery-slide');
if(slides.length){let cs=0;function ss(i){slides.forEach((s,idx)=>s.classList.toggle('active',idx===i));}function ns(){cs=(cs+1)%slides.length;ss(cs);}ss(0);setInterval(ns,5000);}
});
function uc(){const n=new Date();const h=String(n.getHours()).padStart(2,'0'),m=String(n.getMinutes()).padStart(2,'0'),s=String(n.getSeconds()).padStart(2,'0');const d=n.toLocaleDateString('bn-BD',{weekday:'long',year:'numeric',month:'long',day:'numeric'});document.getElementById('currentTime').textContent=h+':'+m+':'+s;document.getElementById('currentDate').textContent=d;document.getElementById('hours').textContent=h;document.getElementById('minutes').textContent=m;document.getElementById('seconds').textContent=s;}
uc();setInterval(uc,1000);
const ce=<?php echo $cal_json; ?>;
function ucd(){ce.forEach(function(ev){const eid=ev.id,ed=new Date(ev.event_date+'T00:00:00'),now=new Date(),diff=ed-now;if(diff>0){const d=Math.floor(diff/86400000),h=Math.floor((diff%86400000)/3600000),m=Math.floor((diff%3600000)/60000),s=Math.floor((diff%60000)/1000);['days','hours','minutes','seconds'].forEach(function(tp){const el=document.getElementById(tp+'-'+eid);if(el)el.textContent=tp==='days'?d:[h,m,s][['hours','minutes','seconds'].indexOf(tp)].toString().padStart(2,'0');});}else{const el=document.getElementById('countdown-'+eid);if(el)el.innerHTML='<div class="text-muted small">ইভেন্ট শেষ হয়েছে</div>';}});}
ucd();setInterval(ucd,1000);
</script></body></html>
