<?php
session_start();
require_once 'config/database.php';
require_once 'includes/site_settings.php';
require_once 'includes/image_utils.php';
require_once 'includes/sms_helper.php';

$settings=get_all_settings($pdo);$site_name=$settings['site_name']??'বিদ্যালয়';
$admission_open=false;$admission_message='';$admission_dates=null;$dates_set=false;$available_classes=[];
try{$s=$pdo->prepare("SELECT apd.*,c.name class_name,c.section class_section FROM admission_publish_dates apd LEFT JOIN classes c ON apd.class_id=c.id WHERE apd.is_active=1 AND apd.class_id IS NOT NULL ORDER BY apd.id DESC");$s->execute();$csd=$s->fetchAll(PDO::FETCH_ASSOC);
$s=$pdo->prepare("SELECT*FROM admission_publish_dates WHERE is_active=1 AND class_id IS NULL ORDER BY id DESC LIMIT 1");$s->execute();$gd=$s->fetch();
if(!empty($csd)){foreach($csd as$d){$cn=$d['class_name'].($d['class_section']?' - '.$d['class_section']:'');$available_classes[]=['class_id'=>$d['class_id'],'class_name'=>$cn,'start_date'=>$d['start_date'],'end_date'=>$d['end_date']];}
$cl=[];foreach($available_classes as$ci)$cl[]=$ci['class_name'];$admission_message='ভর্তি আবেদন নিম্নলিখিত ক্লাসগুলির জন্য চলছে: '.implode(', ',$cl);$dates_set=true;}
elseif($gd){$admission_dates=$gd;$dates_set=true;$cd=date('Y-m-d');$st=$gd['start_date'];$en=$gd['end_date'];
if($cd<$st){$admission_open=false;$admission_message='ভর্তি আবেদন '.date('d/m/Y',strtotime($st)).' তারিখ থেকে শুরু হবে।';}
elseif($cd>$en){$admission_open=false;$admission_message='ভর্তি আবেদনের সময় শেষ হয়েছে। শেষ তারিখ '.date('d/m/Y',strtotime($en)).'।';}
else{$admission_open=true;$admission_message='ভর্তি আবেদন চলছে।';}}
else{$admission_open=false;$admission_message='এখন পর্যন্ত কোন ভর্তি আবেদনের তারিখ নির্ধারণ করা হয়নি।';}
}catch(Exception$e){$admission_open=false;$admission_message='এখন পর্যন্ত কোন ভর্তি আবেদনের তারিখ নির্ধারণ করা হয়নি।';}

$success_message='';$error_message='';$classes=[];$student_data=null;$student_id=isset($_GET['student_id'])?(int)$_GET['student_id']:0;
if($student_id>0){try{$s=$pdo->prepare("SELECT*FROM students WHERE id=?");$s->execute([$student_id]);$student_data=$s->fetch();}catch(Exception$e){}}
try{$s=$pdo->query("SELECT id,name,section FROM classes WHERE status='active' ORDER BY name ASC");$classes=$s->fetchAll(PDO::FETCH_ASSOC);}catch(Exception$e){$error_message='ক্লাস তালিকা আনতে সমস্যা হয়েছে।';}
$sessions=[];try{$s=$pdo->query("SELECT id,name FROM academic_sessions WHERE status='active' ORDER BY is_current DESC,start_date DESC");$sessions=$s->fetchAll(PDO::FETCH_ASSOC);}catch(Exception$e){}

if($_SERVER['REQUEST_METHOD']=='POST'){
$class_id=isset($_POST['class_id'])?(int)$_POST['class_id']:0;
if($class_id){$class_admission_open=false;$cd=date('Y-m-d');
if(!empty($available_classes)){foreach($available_classes as$ci){if($ci['class_id']==$class_id){if($cd>=$ci['start_date']&&$cd<=$ci['end_date']){$class_admission_open=true;break;}}}}
if(!$class_admission_open&&$admission_open)$class_admission_open=true;
if(!$class_admission_open)$error_message='নির্বাচিত ক্লাসের জন্য ভর্তি আবেদন বন্ধ রয়েছে।';}
elseif(!$admission_open&&empty($available_classes))$error_message=$admission_message;
if(empty($error_message)){try{$fn=isset($_POST['first_name'])?trim($_POST['first_name']):'';$ln=isset($_POST['last_name'])?trim($_POST['last_name']):'';$fan=isset($_POST['father_name'])?trim($_POST['father_name']):'';$mn=isset($_POST['mother_name'])?trim($_POST['mother_name']):'';
$bd=isset($_POST['birth_day'])?$_POST['birth_day']:'';$bm=isset($_POST['birth_month'])?$_POST['birth_month']:'';$by=isset($_POST['birth_year'])?$_POST['birth_year']:'';$dob=$bd&&$bm&&$by?"$by-$bm-$bd":'';
$gender=isset($_POST['gender'])?$_POST['gender']:'';$religion=isset($_POST['religion'])?$_POST['religion']:'';$phone=isset($_POST['phone'])?trim($_POST['phone']):'';
$fphone=isset($_POST['father_phone'])?trim($_POST['father_phone']):'';$email=isset($_POST['email'])?trim($_POST['email']):'';
$addr=isset($_POST['address'])?trim($_POST['address']):'';$cid=isset($_POST['class_id'])?(int)$_POST['class_id']:0;
$ps=isset($_POST['previous_school'])?trim($_POST['previous_school']):'';$pc=isset($_POST['previous_class'])?trim($_POST['previous_class']):'';
$asid=isset($_POST['applying_session_id'])?(int)$_POST['applying_session_id']:0;$ag=isset($_POST['applying_group'])?trim($_POST['applying_group']):'';
$bg=isset($_POST['blood_group'])?trim($_POST['blood_group']):'';$subs=isset($_POST['subjects'])?$_POST['subjects']:[];
if(empty($fn)||empty($fan)||empty($mn)||empty($bd)||empty($bm)||empty($by)||empty($gender)||empty($religion)||empty($phone)||empty($cid))$error_message='অনুগ্রহ করে সব প্রয়োজনীয় তথ্য পূরণ করুন。';else{$photo_path='';
if(isset($_POST['compressed_photo_data'])&&!empty($_POST['compressed_photo_data'])){$img=$_POST['compressed_photo_data'];if(strpos($img,'data:image')===0)$img=substr($img,strpos($img,',')+1);$img=base64_decode($img);
if($img!==false){$dir=__DIR__.'/uploads/students/';if(!file_exists($dir))mkdir($dir,0777,true);$f='compressed_'.uniqid().'.jpg';if(file_put_contents($dir.$f,$img))$photo_path='/uploads/students/'.$f;else $error_message='ছবি সংরক্ষণ করতে সমস্যা হয়েছে。';}else $error_message='ছবির ডেটা বৈধ নয়。';}
elseif(isset($_POST['captured_photo_data'])&&!empty($_POST['captured_photo_data'])){$img=$_POST['captured_photo_data'];if(strpos($img,'data:image')===0)$img=substr($img,strpos($img,',')+1);$img=base64_decode($img);
if($img!==false){$dir=__DIR__.'/uploads/students/';if(!file_exists($dir))mkdir($dir,0777,true);$f='captured_'.uniqid().'.png';if(file_put_contents($dir.$f,$img)){$photo_path='/uploads/students/'.$f;$r=validate_and_compress_image(['tmp_name'=>$dir.$f,'name'=>$f],$dir,100);if($r['success']){$rp=str_replace(__DIR__,'',$r['path']);if(substr($rp,0,1)!=='/')$rp='/'.$rp;$photo_path=$rp;}}else $error_message='ছবি সংরক্ষণ করতে সমস্যা হয়েছে。';}else $error_message='ছবির ডেটা বৈধ নয়。';}
elseif(isset($_FILES['student_photo'])&&$_FILES['student_photo']['error']==0){$dir=__DIR__.'/uploads/students/';if(!file_exists($dir))mkdir($dir,0777,true);$r=validate_and_compress_image($_FILES['student_photo'],$dir,100);
if($r['success']){$rp=str_replace(__DIR__,'',$r['path']);if(substr($rp,0,1)!=='/')$rp='/'.$rp;$photo_path=$rp;}else $error_message=$r['error'];}
if(empty($error_message)&&!empty($email)){$s=$pdo->prepare("SELECT COUNT(*) FROM admission_applications WHERE email=? AND status!='rejected'");$s->execute([$email]);if($s->fetchColumn()>0)$error_message='এই ইমেইলটি ইতিমধ্যে ব্যবহার করা হয়েছে。';}
if(empty($error_message)){$s=$pdo->prepare("SELECT COUNT(*) FROM admission_applications WHERE phone=? AND status!='rejected'");$s->execute([$phone]);if($s->fetchColumn()>0)$error_message='এই ফোন নম্বরটি ইতিমধ্যে ব্যবহার করা হয়েছে。';}
if(empty($error_message)){$ano='APP'.date('Y').rand(10000,99999);
$s=$pdo->prepare("INSERT INTO admission_applications(first_name,last_name,father_name,mother_name,date_of_birth,gender,religion,blood_group,phone,father_phone,email,present_address,permanent_address,applying_for_class_id,previous_school,previous_class,application_no,password,status,photo_path,applying_for_session,applying_for_group,created_at)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())");
if($s->execute([$fn,$ln,$fan,$mn,$dob,$gender,$religion,$bg,$phone,$fphone,$email,$addr,$addr,$cid,$ps,$pc,$ano,'123456','pending',$photo_path,$asid,$ag])){
if(!empty($subs)){$ss=json_encode($subs);$su=$pdo->prepare("UPDATE admission_applications SET selected_subjects=? WHERE application_no=?");$su->execute([$ss,$ano]);}
$sc=non_musking_config();$sm=$sc['templates']['admission_confirmation']??$sc['tpl_general_message']??'প্রিয় {name}, আপনার ভর্তি আবেদন সফলভাবে জমা দেওয়া হয়েছে। আবেদন নম্বর: {application_no}।';
$sm=str_replace(['{application_no}','{name}','{message}'],[$ano,$fn,'আপনার ভর্তি আবেদন সফলভাবে জমা দেওয়া হয়েছে'],$sm);
$sr=non_musking_send($pdo,[$phone],$sm,['message_type'=>'admission_confirmation','recipient_name'=>$fn,'application_no'=>$ano]);
if(!$sr['success'])error_log('SMS failed: '.$ano.' - '.json_encode($sr));
header("Location: admission_receipt.php?application_no=".$ano);exit();}else $error_message='আবেদন জমা দিতে সমস্যা হয়েছে。';}}
}catch(Exception$e){error_log("Admission error: ".$e->getMessage());$error_message='আবেদন জমা দিতে সমস্যা হয়েছে。';}}}
$is_teacher=isset($_SESSION['user_role'])&&$_SESSION['user_role']==='teacher';$came_from_student=isset($_GET['student_id'])&&(int)$_GET['student_id']>0;
$redirect_url=$is_teacher&&$came_from_student?'teachers/dashboard.php':'index.php';$redirect_text=$is_teacher&&$came_from_student?'ড্যাশবোর্ডে ফিরে যান':'হোমপেজে ফিরে যান';
?><!DOCTYPE html><html lang="bn"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title><?=$student_data?htmlspecialchars($student_data['first_name'].' '.$student_data['last_name']).' -':''?>ভর্তি আবেদন - <?=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{--g:#006747;--r:#F42A41;--p:#6f42c1;--o:#fd7e14;--t:#0dcaf0;--y:#ffc107;--pi:#d63384}body{font-family:'Hind Siliguri',sans-serif;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);min-height:100vh;background-attachment:fixed}.hd{background:linear-gradient(135deg,#f093fb 0%,#f5576c 100%);color:#fff;padding:10px 0;border-bottom:3px solid #ffd700;box-shadow:0 4px 20px rgba(240,147,251,.4)}.hd h1{font-size:1.2rem;font-weight:700;text-shadow:1px 1px 2px rgba(0,0,0,.2)}.hd .btn{border-radius:6px;font-size:.8rem}.crd{background:linear-gradient(135deg,#fefefe,#f3e8ff,#e8f4fd);border-radius:15px;box-shadow:0 8px 32px rgba(0,0,0,.12);border:none;margin-bottom:18px;overflow:hidden;transition:transform .2s,box-shadow .2s}.crd:hover{transform:translateY(-2px);box-shadow:0 12px 40px rgba(0,0,0,.18)}.crd:nth-child(2) .ch{background:linear-gradient(135deg,#667eea,#764ba2)}.crd:nth-child(3) .ch{background:linear-gradient(135deg,#f093fb,#f5576c)}.crd:nth-child(4) .ch{background:linear-gradient(135deg,#4facfe,#00f2fe)}.crd:nth-child(5) .ch{background:linear-gradient(135deg,#43e97b,#38f9d7)}.crd:nth-child(6) .ch{background:linear-gradient(135deg,#fa709a,#fee140)}.crd .ch{background:linear-gradient(135deg,var(--g),#004d35);color:#fff;padding:8px 15px;font-weight:700;font-size:.9rem;text-shadow:1px 1px 2px rgba(0,0,0,.15);letter-spacing:.5px}.crd .cb{padding:12px 15px;background:linear-gradient(180deg,#faf5ff 0%,#f0e6ff 100%)}.st{color:var(--g);border-bottom:2px solid var(--r);padding-bottom:6px;margin-bottom:10px;font-weight:700;font-size:.95rem}.fl{font-weight:600;color:#444;font-size:.82rem;margin-bottom:2px}.fc-i,.fs{border-radius:8px;border:2px solid #e0e6ed;padding:6px 10px;font-size:.82rem;transition:all .3s ease;background:#fff}.fc-i:hover,.fs:hover{border-color:#b3d4fc;background:#fafcff}.fc-i:focus,.fs:focus{border-color:var(--p);box-shadow:0 0 0 4px rgba(111,66,193,.15);background:#fff;transform:scale(1.01)}.btn-p{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border:none;border-radius:8px;padding:8px 28px;font-weight:700;font-size:.9rem;box-shadow:0 4px 15px rgba(102,126,234,.4);transition:all .3s;position:relative;overflow:hidden}.btn-p:hover{box-shadow:0 6px 25px rgba(102,126,234,.5);transform:translateY(-2px)}.btn-p:active{transform:translateY(0)}.i-b{position:relative}.i-b .t-btn,.i-b .a-btn,.i-b .v-btn{position:absolute;z-index:10;padding:2px 8px;font-size:.7rem;border-radius:4px;border:none;cursor:pointer;top:34px;transition:all .2s}.i-b .t-btn{right:110px;background:linear-gradient(135deg,#0d6efd,#6610f2);color:#fff}.i-b .t-btn:hover{transform:scale(1.1);box-shadow:0 2px 8px rgba(13,110,253,.4)}.i-b .a-btn{right:60px;background:linear-gradient(135deg,#198754,#20c997);color:#fff}.i-b .a-btn:hover{transform:scale(1.1);box-shadow:0 2px 8px rgba(25,135,84,.4)}.i-b .v-btn{right:10px;background:linear-gradient(135deg,#fd7e14,#dc3545);color:#fff}.i-b .v-btn:hover{transform:scale(1.1);box-shadow:0 2px 8px rgba(253,126,20,.4)}.i-b .fc-i{padding-right:170px}.vl{width:auto;display:inline-block;font-size:.78rem}.ci{display:none;margin-top:10px;padding:10px;background:linear-gradient(135deg,#f093fb20,#f5576c10);border-radius:10px;border:1px solid #f093fb40}.ci video{width:100%;max-width:280px;border:2px solid var(--p);border-radius:8px;box-shadow:0 4px 12px rgba(111,66,193,.2)}.ci-pt{max-width:200px;border-radius:8px;box-shadow:0 3px 10px rgba(0,0,0,.1)}.sg{display:grid;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));gap:4px;max-height:200px;overflow-y:auto;padding:8px;border:2px solid #dee2e6;border-radius:10px;background:linear-gradient(135deg,#f8f9ff,#eef2ff)}.si{padding:4px 6px;border:1px solid #e0e6ed;border-radius:6px;background:#fff;transition:all .2s}.si:hover{background:linear-gradient(135deg,#e8f4fd,#f0e8ff);border-color:var(--p);transform:translateX(3px)}select.fs option{background:#fff;color:#333}.alert{border-radius:10px;border-left:4px solid}select.fs{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237c4dff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 15 12 9 18 15'%3E%3C/polyline%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 10px center;background-size:14px;-webkit-appearance:none;appearance:none;padding-right:32px}.form-check-input{border-radius:4px!important;border:2px solid #c5cae9!important;width:18px;height:18px;cursor:pointer;transition:all .2s}.form-check-input:hover{border-color:#7c4dff!important;box-shadow:0 0 0 3px rgba(124,77,255,.15)}.form-check-input:checked{background:linear-gradient(135deg,#7c4dff,#448aff)!important;border-color:#7c4dff!important;box-shadow:0 2px 8px rgba(124,77,255,.35)}.form-check-input:checked[type=checkbox]{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3e%3c/svg%3e")}.form-check-label{font-weight:500;color:#333;cursor:pointer;transition:color .2s}.form-check-input:checked+.form-check-label{color:#7c4dff;font-weight:600}.form-check-input:checked~.form-check-label{color:#7c4dff;font-weight:600}.si:has(.form-check-input:checked){background:linear-gradient(135deg,#e8e0ff,#d4edff)!important;border-color:#7c4dff!important;box-shadow:0 2px 8px rgba(124,77,255,.15)}select.fs:focus option:checked{background:linear-gradient(135deg,#7c4dff,#448aff);color:#fff}::selection{background:#7c4dff;color:#fff}::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:#f0e8ff;border-radius:3px}::-webkit-scrollbar-thumb{background:linear-gradient(180deg,#7c4dff,#448aff);border-radius:3px}::-webkit-scrollbar-thumb:hover{background:#6a3de8}@media(max-width:576px){.i-b .fc-i{padding-right:0}.i-b .t-btn,.i-b .a-btn,.i-b .v-btn{position:static;margin:2px}}
</style></head>
<body>
<div class="hd"><div class="container"><div class="d-flex align-items-center justify-content-between"><h1 class="mb-0"><i class="fas fa-user-plus me-1"></i><?=$student_data?htmlspecialchars($student_data['first_name'].' '.$student_data['last_name']).' এর জন্য ভর্তি আবেদন':'ভর্তি আবেদন - '.htmlspecialchars($site_name)?></h1>
<div class="d-flex gap-1"><a href="index.php" class="btn btn-outline-light btn-sm"><i class="fas fa-home"></i></a><?php if($is_teacher&&$came_from_student):?><a href="teachers/dashboard.php" class="btn btn-light btn-sm"><i class="fas fa-arrow-left"></i> ড্যাশবোর্ড</a><?php endif;?></div></div></div></div>
<div class="container py-2">
<?php if($success_message):?><div class="alert alert-success py-1 small alert-dismissible fade show"><?=$success_message?><button type="button" class="btn-close" data-bs-dismiss="alert"></button></div><?php endif;?>
<?php if($error_message):?><div class="alert alert-danger py-1 small alert-dismissible fade show"><?=$error_message?><button type="button" class="btn-close" data-bs-dismiss="alert"></button></div><?php endif;?>
<?php if($student_data):?><div class="alert alert-info py-1 small">আপনি <strong><?=htmlspecialchars($student_data['first_name'].' '.$student_data['last_name'])?></strong> এর জন্য ভর্তি আবেদন ফরম পূরণ করছেন।</div><?php endif;?>
<?php if(!$admission_open&&$admission_message):?><div class="alert alert-warning py-1 small"><?=$admission_message?><?php if($admission_dates):?><br><strong>শিক্ষাবর্ষ:</strong> <?=htmlspecialchars($admission_dates['academic_year'])?> | <strong>সময়কাল:</strong> <?=date('d/m/Y',strtotime($admission_dates['start_date']))?> - <?=date('d/m/Y',strtotime($admission_dates['end_date']))?><?php elseif(!empty($available_classes)):?><br><strong>ভর্তি চলছে:</strong><ul class="mb-0"><?php foreach($available_classes as$ci):?><li><?=htmlspecialchars($ci['class_name'])?> (<?=date('d/m/Y',strtotime($ci['start_date']))?> - <?=date('d/m/Y',strtotime($ci['end_date']))?>)</li><?php endforeach;?></ul><?php endif;?></div><?php endif;?>
<?php if($admission_open||!empty($available_classes)):?><form method="POST" enctype="multipart/form-data">
<div class="crd"><div class="ch"><i class="fas fa-user me-1"></i>ব্যক্তিগত তথ্য</div><div class="cb"><div class="row g-2">
<div class="col-12 d-flex justify-content-end"><div class="mb-1"><label class="fl small">ভাষা</label><select class="form-select form-select-sm vl" onchange="uv(this.value)"><option value="bn-BD" selected>বাংলাদেশি বাংলা</option><option value="en-IN">ভারতীয় ইংরেজি</option></select></div></div>
<div class="col-md-6 i-b"><label class="fl" for="first_name">নাম (ইংরেজিতে) *</label><input type="text" class="form-control fc-i" id="first_name" name="first_name" value="<?=isset($_POST['first_name'])?htmlspecialchars($_POST['first_name']):(isset($student_data['first_name'])?htmlspecialchars($student_data['first_name']):'')?>" required><button type="button" class="t-btn" onclick="tT('first_name')">T</button><button type="button" class="a-btn" onclick="gAI('first_name')">AI</button><button type="button" class="v-btn" onclick="sV('first_name')">🎤</button></div>
<div class="col-md-6 i-b"><label class="fl" for="last_name">নাম (বাংলায়)</label><input type="text" class="form-control fc-i" id="last_name" name="last_name" value="<?=isset($_POST['last_name'])?htmlspecialchars($_POST['last_name']):(isset($student_data['last_name'])?htmlspecialchars($student_data['last_name']):'')?>"><button type="button" class="t-btn" onclick="tT('last_name')">T</button><button type="button" class="a-btn" onclick="gAI('last_name')">AI</button><button type="button" class="v-btn" onclick="sV('last_name')">🎤</button></div>
<div class="col-md-6 i-b"><label class="fl" for="father_name">পিতার নাম *</label><input type="text" class="form-control fc-i" id="father_name" name="father_name" value="<?=isset($_POST['father_name'])?htmlspecialchars($_POST['father_name']):(isset($student_data['father_name'])?htmlspecialchars($student_data['father_name']):'')?>" required><button type="button" class="t-btn" onclick="tT('father_name')">T</button><button type="button" class="a-btn" onclick="gAI('father_name')">AI</button><button type="button" class="v-btn" onclick="sV('father_name')">🎤</button></div>
<div class="col-md-6 i-b"><label class="fl" for="mother_name">মাতার নাম *</label><input type="text" class="form-control fc-i" id="mother_name" name="mother_name" value="<?=isset($_POST['mother_name'])?htmlspecialchars($_POST['mother_name']):(isset($student_data['mother_name'])?htmlspecialchars($student_data['mother_name']):'')?>" required><button type="button" class="t-btn" onclick="tT('mother_name')">T</button><button type="button" class="a-btn" onclick="gAI('mother_name')">AI</button><button type="button" class="v-btn" onclick="sV('mother_name')">🎤</button></div>
<div class="col-12"><label class="fl fw-bold">জন্ম তারিখ *</label></div>
<div class="col-md-2"><label class="fl" for="birth_day">দিন</label><select class="form-select fs" id="birth_day" name="birth_day" required><option value="">দিন</option><?php for($i=1;$i<=31;$i++):$sel=(isset($_POST['birth_day'])&&$_POST['birth_day']==$i)||(isset($student_data['date_of_birth'])&&date('d',strtotime($student_data['date_of_birth']))==$i)?'selected':'';?><option value="<?=$i?>" <?=$sel?>><?=$i?></option><?php endfor;?></select></div>
<div class="col-md-3"><label class="fl" for="birth_month">মাস</label><select class="form-select fs" id="birth_month" name="birth_month" required><option value="">মাস</option><?php $monthList=['01'=>'জানুয়ারী','02'=>'ফেব্রুয়ারী','03'=>'মার্চ','04'=>'এপ্রিল','05'=>'মে','06'=>'জুন','07'=>'জুলাই','08'=>'আগস্ট','09'=>'সেপ্টেম্বর','10'=>'অক্টোবর','11'=>'নভেম্বর','12'=>'ডিসেম্বর'];foreach($monthList as$n=>$na):$sel=(isset($_POST['birth_month'])&&$_POST['birth_month']==$n)||(isset($student_data['date_of_birth'])&&date('m',strtotime($student_data['date_of_birth']))==$n)?'selected':'';?><option value="<?=$n?>" <?=$sel?>><?=$na?></option><?php endforeach;?></select></div>
<div class="col-md-2"><label class="fl" for="birth_year">বছর</label><select class="form-select fs" id="birth_year" name="birth_year" required><option value="">বছর</option><?php $cy=date('Y');for($i=$cy-100;$i<=$cy-5;$i++):$sel=(isset($_POST['birth_year'])&&$_POST['birth_year']==$i)||(isset($student_data['date_of_birth'])&&date('Y',strtotime($student_data['date_of_birth']))==$i)?'selected':'';?><option value="<?=$i?>" <?=$sel?>><?=$i?></option><?php endfor;?></select></div>
<div class="col-md-3 d-flex align-items-end mb-1"><button type="button" class="btn btn-primary w-100 btn-sm" onclick="sVD()">🎤 ভয়েসে তারিখ</button></div>
<div class="col-md-4"><label class="fl" for="religion">ধর্ম *</label><select class="form-select fs" id="religion" name="religion" required><option value="">নির্বাচন করুন</option><option value="islam"<?=(isset($_POST['religion'])&&$_POST['religion']=='islam')||(isset($student_data['religion'])&&$student_data['religion']=='islam')?' selected':''?>>ইসলাম</option><option value="hinduism"<?=(isset($_POST['religion'])&&$_POST['religion']=='hinduism')||(isset($student_data['religion'])&&$student_data['religion']=='hinduism')?' selected':''?>>হিন্দু</option><option value="buddhism"<?=(isset($_POST['religion'])&&$_POST['religion']=='buddhism')||(isset($student_data['religion'])&&$student_data['religion']=='buddhism')?' selected':''?>>বৌদ্ধ</option><option value="christianity"<?=(isset($_POST['religion'])&&$_POST['religion']=='christianity')||(isset($student_data['religion'])&&$student_data['religion']=='christianity')?' selected':''?>>খ্রিস্টান</option><option value="other"<?=(isset($_POST['religion'])&&$_POST['religion']=='other')||(isset($student_data['religion'])&&$student_data['religion']=='other')?' selected':''?>>অন্যান্য</option></select></div>
<div class="col-md-4"><label class="fl" for="gender">লিঙ্গ *</label><select class="form-select fs" id="gender" name="gender" required><option value="">নির্বাচন করুন</option><option value="male"<?=(isset($_POST['gender'])&&$_POST['gender']=='male')||(isset($student_data['gender'])&&$student_data['gender']=='male')?' selected':''?>>পুরুষ</option><option value="female"<?=(isset($_POST['gender'])&&$_POST['gender']=='female')||(isset($student_data['gender'])&&$student_data['gender']=='female')?' selected':''?>>মহিলা</option><option value="other"<?=(isset($_POST['gender'])&&$_POST['gender']=='other')||(isset($student_data['gender'])&&$student_data['gender']=='other')?' selected':''?>>অন্যান্য</option></select></div>
<div class="col-md-4"><label class="fl" for="blood_group">রক্তের গ্রুপ</label><select class="form-select fs" id="blood_group" name="blood_group"><option value="">নির্বাচন করুন</option><?php $bgs=['A+','A-','B+','B-','O+','O-','AB+','AB-'];foreach($bgs as$bg):$sel=(isset($_POST['blood_group'])&&$_POST['blood_group']==$bg)||(isset($student_data['blood_group'])&&$student_data['blood_group']==$bg)?'selected':'';?><option value="<?=$bg?>" <?=$sel?>><?=$bg?></option><?php endforeach;?></select></div>
<div class="col-md-6 i-b"><label class="fl" for="phone">ছাত্র/ছাত্রীর ফোন *</label><input type="tel" class="form-control fc-i" id="phone" name="phone" value="<?=isset($_POST['phone'])?htmlspecialchars($_POST['phone']):(isset($student_data['phone'])?htmlspecialchars($student_data['phone']):'')?>" required><button type="button" class="t-btn" onclick="tT('phone')">T</button><button type="button" class="a-btn" onclick="gAI('phone')">AI</button><button type="button" class="v-btn" onclick="sV('phone')">🎤</button></div>
<div class="col-md-6"><label class="fl" for="father_phone">পিতা/অভিভাবকের ফোন *</label><input type="tel" class="form-control fc-i" id="father_phone" name="father_phone" value="<?=isset($_POST['father_phone'])?htmlspecialchars($_POST['father_phone']):(isset($student_data['guardian_phone'])?htmlspecialchars($student_data['guardian_phone']):'')?>" required></div>
<div class="col-md-6 i-b"><label class="fl" for="email">ইমেইল (ঐচ্ছিক)</label><input type="email" class="form-control fc-i" id="email" name="email" value="<?=isset($_POST['email'])?htmlspecialchars($_POST['email']):(isset($student_data['email'])?htmlspecialchars($student_data['email']):'')?>"><button type="button" class="t-btn" onclick="tT('email')">T</button><button type="button" class="a-btn" onclick="gAI('email')">AI</button><button type="button" class="v-btn" onclick="sV('email')">🎤</button></div>
<div class="col-12 i-b"><label class="fl" for="address">ঠিকানা</label><textarea class="form-control fc-i" id="address" name="address" rows="2"><?=isset($_POST['address'])?htmlspecialchars($_POST['address']):(isset($student_data['address'])?htmlspecialchars($student_data['address']):'')?></textarea><button type="button" class="t-btn" onclick="tT('address')">T</button><button type="button" class="a-btn" onclick="gAI('address')">AI</button><button type="button" class="v-btn" onclick="sV('address')">🎤</button></div>
<div class="col-md-6"><label class="fl" for="student_photo">ছবি (ঐচ্ছিক)</label><input type="file" class="form-control fc-i" id="student_photo" name="student_photo" accept="image/*" onchange="cFS(this)"><div class="form-text small">স্বয়ংক্রিয়ভাবে ১০০ KB এ কম্প্রেস হবে</div><div id="ppc" style="margin-top:6px"></div>
<div class="ci" id="ci"><div class="mb-1"><label class="fl small">ক্যামেরা:</label><select class="form-select form-select-sm fs" id="cst" onchange="tCST()"><option value="user">ওয়েব ক্যাম</option><option value="environment">বাইরের ক্যামেরা</option><option value="highres">উচ্চ রেজোলিউশন</option><option value="wideangle">ওয়াইড এঙ্গেল</option></select></div><video id="vp" autoplay playsinline></video><div class="mt-1"><button type="button" class="btn btn-primary btn-sm" onclick="cP()">ছবি তুলুন</button><button type="button" class="btn btn-secondary btn-sm" onclick="cC()">বন্ধ করুন</button></div><canvas id="cv" style="display:none"></canvas><div id="cpc" style="margin-top:6px"><img id="cp" style="max-width:100%;display:none" /></div><input type="hidden" id="cpd" name="captured_photo_data" /></div>
<div class="mt-1"><button type="button" class="btn btn-outline-primary btn-sm" onclick="oC()">📷 ক্যামেরা</button></div></div></div></div></div>
<div class="crd"><div class="ch"><i class="fas fa-graduation-cap me-1"></i>শিক্ষাগত তথ্য</div><div class="cb"><div class="row g-2">
<div class="col-md-4"><label class="fl" for="class_id">ভর্তি ক্লাস *</label><select class="form-select fs" id="class_id" name="class_id" required><option value="">ক্লাস নির্বাচন করুন</option><?php foreach($classes as$c):$sel=(isset($_POST['class_id'])&&$_POST['class_id']==$c['id'])||(isset($student_data['class_id'])&&$student_data['class_id']==$c['id'])?'selected':'';?><option value="<?=$c['id']?>" <?=$sel?>><?=htmlspecialchars($c['name'].($c['section']?' - '.$c['section']:''))?></option><?php endforeach;?></select></div>
<div class="col-md-4"><label class="fl" for="applying_session_id">সেশন *</label><?php if(!empty($sessions)):?><select class="form-select fs" id="applying_session_id" name="applying_session_id" required><option value="">সেশন</option><?php foreach($sessions as$s):$sel=(isset($_POST['applying_session_id'])&&$_POST['applying_session_id']==$s['id'])?'selected':'';?><option value="<?=$s['id']?>" <?=$sel?>><?=htmlspecialchars($s['name'])?></option><?php endforeach;?></select><?php else:?><input type="text" class="form-control fc-i" id="applying_session_id" name="applying_session_id" value="<?=isset($_POST['applying_session_id'])?htmlspecialchars($_POST['applying_session_id']):(isset($student_data['session'])?htmlspecialchars($student_data['session']):'')?>" placeholder="যেমন: 2025-2026" required><?php endif;?></div>
<div class="col-md-4"><label class="fl" for="applying_group">গ্রুপ (ঐচ্ছিক)</label><select class="form-select fs" id="applying_group" name="applying_group"><option value="">গ্রুপ</option><?php $gs=['Science','Arts','Commerce','General'];foreach($gs as$g):$sel=(isset($_POST['applying_group'])&&$_POST['applying_group']==$g)||(isset($student_data['group_name'])&&$student_data['group_name']==$g)?'selected':'';?><option value="<?=$g?>" <?=$sel?>><?=$g?></option><?php endforeach;?></select></div>
<div class="col-md-6 i-b"><label class="fl" for="previous_class">পূর্ববর্তী ক্লাস (ঐচ্ছিক)</label><input type="text" class="form-control fc-i" id="previous_class" name="previous_class" value="<?=isset($_POST['previous_class'])?htmlspecialchars($_POST['previous_class']):''?>" placeholder="যেমন: পঞ্চম শ্রেণী"><button type="button" class="t-btn" onclick="tT('previous_class')">T</button><button type="button" class="a-btn" onclick="gAI('previous_class')">AI</button><button type="button" class="v-btn" onclick="sV('previous_class')">🎤</button></div>
<div class="col-md-6 i-b"><label class="fl" for="previous_school">পূর্ববর্তী স্কুল (ঐচ্ছিক)</label><input type="text" class="form-control fc-i" id="previous_school" name="previous_school" value="<?=isset($_POST['previous_school'])?htmlspecialchars($_POST['previous_school']):''?>" placeholder="পূর্ববর্তী স্কুলের নাম"><button type="button" class="t-btn" onclick="tT('previous_school')">T</button><button type="button" class="a-btn" onclick="gAI('previous_school')">AI</button><button type="button" class="v-btn" onclick="sV('previous_school')">🎤</button></div>
</div></div></div>
<div class="crd"><div class="ch"><i class="fas fa-book me-1"></i>বিষয় নির্বাচন</div><div class="cb"><div id="sss" style="display:none"><div class="sg" id="sc"><div class="col-12 text-muted small">বিষয় লোড হচ্ছে...</div></div></div><div id="nss" style="display:block"><div class="text-muted small"><i class="fas fa-info-circle"></i> বিষয় নির্বাচনের জন্য প্রথমে ক্লাস নির্বাচন করুন</div></div></div></div>
<div class="crd"><div class="ch"><i class="fas fa-paper-plane me-1"></i>জমা দিন</div><div class="cb"><div class="alert alert-info py-1 small mb-2"><i class="fas fa-info-circle"></i> আবেদন জমা দেওয়ার পর টিম আপনার সাথে যোগাযোগ করবে। সঠিক তথ্য দিন।</div><div class="text-center"><button type="submit" class="btn btn-p"><i class="fas fa-paper-plane me-1"></i>আবেদন জমা দিন</button></div></div></div></form>
<?php else:?><div class="text-center py-5"><i class="fas fa-calendar-times fa-4x text-muted mb-2"></i><h5>ভর্তি আবেদন বন্ধ রয়েছে</h5><p class="text-muted small"><?=$admission_message?></p><a href="<?=$redirect_url?>" class="btn btn-primary btn-sm"><i class="fas fa-arrow-left"></i> <?=$redirect_text?></a></div><?php endif;?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
let cv=null,cs=null,cl='bn-BD';const bm={'জানুয়ারী':'01','ফেব্রুয়ারী':'02','মার্চ':'03','এপ্রিল':'04','মে':'05','জুন':'06','জুলাই':'07','আগস্ট':'08','সেপ্টেম্বর':'09','অক্টোবর':'10','নভেম্বর':'11','ডিসেম্বর':'12'};
function uv(l){cl=l}
function gAI(f){const v={first_name:['জন','আহমেদ','মুহাম্মদ','রহমান'],last_name:['খান','শেখ','হাসান','আলী'],father_name:['মুহাম্মদ আলী','আব্দুল খালেক'],mother_name:['মরিয়ম বেগম','নাজমা বেগম'],birth_day:['1','5','10','15','20','25','30'],birth_month:['01','03','06','09','12'],birth_year:['2010','2012','2014','2016','2018'],email:[f+'@gmail.com',f+'@yahoo.com'],phone:['01XXXXXXXXX','+8801XXXXXXXXX'],address:['ঢাকা','চট্টগ্রাম','খুলনা','সিলেট'],previous_class:['পঞ্চম','ষষ্ঠ','সপ্তম','অষ্টম'],previous_school:['আদর্শ বিদ্যালয়','মডেল স্কুল','হাই স্কুল']};const n=document.getElementById(f).getAttribute('name');if(v[n])document.getElementById(f).value=v[n][Math.floor(Math.random()*v[n].length)]}
function tT(f){const e=document.getElementById(f),v=e.value;if(!v.trim()){alert('টেক্সট লিখুন');return}
const m={রহমান:'Rahman',হাসান:'Hasan',আলী:'Ali',করিম:'Karim',রহিম:'Rahim',খান:'Khan',শেখ:'Sheikh',মিয়া:'Mia',ভূঁইয়া:'Bhuinya',শিকদার:'Shikdar',মুহাম্মদ:'Mohammad',আব্দুল:'Abdul',হামিদ:'Hamid',মরিয়ম:'Morium',বেগম:'Begum',নাজমা:'Nazma',সুলতানা:'Sultana',রহিমা:'Rehima',মোনিরা:'Monira',জাহানারা:'Jahanara',ঢাকা:'Dhaka',চট্টগ্রাম:'Chittagong',খুলনা:'Khulna',রাজশাহী:'Rajshahi',সিলেট:'Sylhet',বরিশাল:'Barisal',ময়মনসিংহ:'Mymensingh',rahman:'রহমান',hasan:'হাসান',ali:'আলী',karim:'করিম',rahim:'রহিম',khan:'খান',sheikh:'শেখ',mia:'মিয়া',bhuinya:'ভূঁইয়া',shikdar:'শিকদার',mohammad:'মুহাম্মদ',abdul:'আব্দুল',hamid:'হামিদ',morium:'মরিয়ম',begum:'বেগম',nazma:'নাজমা',sultana:'সুলতানা',rehima:'রহিমা',monira:'মোনিরা',jahanara:'জাহানারা',dhaka:'ঢাকা',chittagong:'চট্টগ্রাম',khulna:'খুলনা',rajshahi:'রাজশাহী',sylhet:'সিলেট',barisal:'বরিশাল',mymensingh:'ময়মনসিংহ',ahmed:'আহমেদ',john:'জন',jane:'জেন',david:'ডেভিড',robert:'রবার্ট'}
let bc=0,ec=0;for(let c of v){if(/[ঀ-৿]/.test(c))bc++;else if(/[a-zA-Z]/.test(c))ec++}
const ib=bc>ec||(!ec&&/[ঀ-৿]/.test(v));e.value=v.split(/\s+/).map(w=>{const cw=w.replace(/[\p{P}\p{S}]/gu,'').trim();return m[cw]||m[cw.toLowerCase()]||w}).join(' ');alert(ib?'বাংলা→ইংরেজি':'ইংরেজি→বাংলা')}
function sV(f){const e=document.getElementById(f);if(!e||e.type==='file'||e.type==='checkbox'||e.type==='radio'){alert('ভয়েস এই ফিল্ডে সমর্থিত নয়');return}
if(!('webkitSpeechRecognition'in window)&&!('SpeechRecognition'in window)){alert('শুধুমাত্র Chrome ব্রাউজারে কাজ করে');return}
const SR=window.SpeechRecognition||window.webkitSpeechRecognition;let r;try{r=new SR()}catch(er){alert('ভয়েস রিকগনিশন শুরু করতে ব্যর্থ: '+er.message);return}
r.continuous=true;r.interimResults=true;r.lang=cl;
r.onresult=function(ev){let ft='';for(let i=ev.resultIndex;i<ev.results.length;i++){if(ev.results[i].isFinal)ft+=ev.results[i][0].transcript+' '}
if(ft.trim())e.value+=ft.trim()};
let sb=null;r.onerror=function(ev){alert('ভয়েস ত্রুটি: '+ev.error);if(sb)try{sb.remove()}catch(e){}};
try{r.start();sb=document.createElement('button');sb.type='button';sb.className='btn btn-danger btn-sm';sb.textContent='থামান';sb.style.marginTop='3px';sb.onclick=function(){r.stop();try{sb.remove()}catch(e){}};e.parentNode.appendChild(sb)}catch(er){alert('মাইক্রোফোন অ্যাক্সেস সমস্যা: '+er.message)}}
function sVD(){if(!('webkitSpeechRecognition'in window)&&!('SpeechRecognition'in window)){alert('Chrome ব্যবহার করুন');return}
const SR=window.SpeechRecognition||window.webkitSpeechRecognition,r=new SR();r.continuous=false;r.interimResults=false;r.lang=cl;
r.onresult=function(ev){const t=ev.results[0][0].transcript,m=t.match(/(\d{1,2})[\s\/-](\d{1,2})[\s\/-](\d{2,4})|(\d{1,2})\s+(জানুয়ারী|ফেব্রুয়ারী|মার্চ|এপ্রিল|মে|জুন|জুলাই|আগস্ট|সেপ্টেম্বর|অক্টোবর|নভেম্বর|ডিসেম্বর)\s+(\d{4})/i);
if(m){let d,mn,y;if(m[4]){d=m[1]||m[4];mn=bm[m[5]]||'01';y=m[6]}else{d=m[1];mn=m[2];y=m[3];if(y.length<3)y='20'+y}
document.getElementById('birth_year').value=y;document.getElementById('birth_month').value=mn;document.getElementById('birth_day').value=d.padStart(2,'0')}else if(!isNaN(new Date(t).getTime())){const dt=new Date(t);document.getElementById('birth_year').value=dt.getFullYear();document.getElementById('birth_month').value=String(dt.getMonth()+1).padStart(2,'0');document.getElementById('birth_day').value=String(dt.getDate()).padStart(2,'0')}else alert('তারিখ বোঝা যায়নি')};
r.start()}
function cFS(i){const f=i.files[0];if(!f)return;const r=new FileReader();r.onload=function(e){const c=document.getElementById('ppc');c.innerHTML='<img class="img-thumbnail mt-1 ci-pt" src="'+e.target.result+'">';
const img=new Image();img.onload=function(){const cn=document.createElement('canvas'),cx=cn.getContext('2d');let w=img.width,h=img.height,mw=1024,mh=1024;if(w>h){if(w>mw){h*=mw/w;w=mw}}else{if(h>mh){w*=mh/h;h=mh}}cn.width=w;cn.height=h;cx.drawImage(img,0,0,w,h);const d=cn.toDataURL(f.type,0.8);
const hi=document.getElementById('cpd')||document.createElement('input');hi.type='hidden';hi.id='cpd';hi.name='compressed_photo_data';hi.value=d;if(!document.getElementById('cpd'))document.querySelector('form').appendChild(hi)};img.src=e.target.result};r.readAsDataURL(f)}
document.addEventListener('DOMContentLoaded',function(){const cs=document.getElementById('class_id');if(cs){
cs.addEventListener('change',function(){const cid=this.value,ss=document.getElementById('sss'),ns=document.getElementById('nss'),sc=document.getElementById('sc');
if(cid){ss.style.display='block';ns.style.display='none';sc.innerHTML='<div class="text-center small py-2"><span class="spinner-border spinner-border-sm text-primary"></span> লোড হচ্ছে...</div>';
fetch('get_class_subjects.php?class_id='+cid).then(r=>r.json()).then(d=>{if(d.success&&d.subjects&&d.subjects.length>0){let h='';d.subjects.forEach(function(s){h+='<div class="si"><div class="form-check mb-0"><input class="form-check-input" type="checkbox" name="subjects[]" value="'+s.subject_id+'" id="sub_'+s.subject_id+'"><label class="form-check-label small" for="sub_'+s.subject_id+'">'+s.name+' ('+s.code+')</label></div></div>'});sc.innerHTML=h;
<?php if(isset($_POST['subjects'])):?>const sel=<?=json_encode($_POST['subjects'])?>;if(sel.length)sel.forEach(function(id){const cb=document.querySelector('input[name="subjects[]"][value="'+id+'"]');if(cb)cb.checked=true});<?php endif;?>
}else sc.innerHTML='<div class="text-muted small">এই ক্লাসের জন্য কোন বিষয় নেই</div>';}).catch(()=>sc.innerHTML='<div class="text-danger small">বিষয় লোড করতে সমস্যা</div>')}
else{ss.style.display='none';ns.style.display='block';sc.innerHTML=''}});
if(cs.value)cs.dispatchEvent(new Event('change'));else{document.getElementById('nss').style.display='block';document.getElementById('sss').style.display='none'}}});
function oC(){const st=document.getElementById('cst').value;if(!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia){alert('ক্যামেরা সাপোর্ট করে না');return}
document.getElementById('ci').style.display='block';const v=document.getElementById('vp');let c={};if(st==='user')c={video:{facingMode:'user'}};else if(st==='environment')c={video:{facingMode:'environment'}};else if(st==='highres')c={video:{facingMode:'user',width:{min:1920},height:{min:1080}}};else if(st==='wideangle')c={video:{facingMode:'user',width:{ideal:1280},height:{ideal:720}}};else c={video:{facingMode:'user'}};
navigator.mediaDevices.getUserMedia(c).then(s=>{cs=s;v.srcObject=s}).catch(()=>{alert('ক্যামেরা এক্সেস করতে সমস্যা');document.getElementById('ci').style.display='none'})}
function cC(){if(cs){cs.getTracks().forEach(t=>t.stop());cs=null}document.getElementById('ci').style.display='none';document.getElementById('vp').srcObject=null}
function tCST(){alert('ক্যামেরা সেন্সর টাইপ: '+document.getElementById('cst').value)}
function cP(){const v=document.getElementById('vp'),cn=document.getElementById('cv'),cp=document.getElementById('cp'),hi=document.getElementById('cpd');cn.width=v.videoWidth;cn.height=v.videoHeight;cn.getContext('2d').drawImage(v,0,0,cn.width,cn.height);
const d=cn.toDataURL('image/png');const img=new Image();img.onload=function(){const cn2=document.createElement('canvas'),cx=cn2.getContext('2d');let w=img.width,h=img.height,mw=1024,mh=1024;if(w>h){if(w>mw){h*=mw/w;w=mw}}else{if(h>mh){w*=mh/h;h=mh}}cn2.width=w;cn2.height=h;cx.drawImage(img,0,0,w,h);const cd=cn2.toDataURL('image/jpeg',0.8);
cp.src=cd;cp.style.display='block';hi.value=cd;const ppc=document.getElementById('ppc');let pi=document.getElementById('photo-preview');if(!pi){pi=document.createElement('img');pi.id='photo-preview';pi.className='img-thumbnail mt-1';pi.style.maxWidth='200px';ppc.innerHTML='';ppc.appendChild(pi)}pi.src=cd;
fetch(cd).then(r=>r.blob()).then(b=>{const f=new File([b],'photo_'+Date.now()+'.jpg',{type:'image/jpeg'});const dt=new DataTransfer();dt.items.add(f);document.getElementById('student_photo').files=dt.files;document.getElementById('student_photo').dispatchEvent(new Event('change',{bubbles:true}))});
cC();alert('ছবি ক্যাপচার এবং কম্প্রেস করা হয়েছে!')};img.src=d}
</script></body></html>