39669-vm/teachers.php
2026-04-16 06:58:53 +00:00

281 lines
17 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/app.php';
$flash = consume_flash();
$applicationId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT) ?: 0;
$application = $applicationId > 0 ? get_application($applicationId) : null;
$isApprovedSchool = $application && (string) $application['status'] === 'approved';
$values = teacher_defaults();
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $application) {
[$values, $errors] = validate_teacher_input($_POST);
if (!$isApprovedSchool) {
$errors['form'] = 'لا يمكن فتح صفحة المعلمين قبل اعتماد المركز.';
}
if ($errors === []) {
try {
create_teacher((int) $application['id'], $values);
set_flash('success', 'تمت إضافة عضو الفريق بنجاح إلى سجل المدرسة.');
header('Location: teachers.php?id=' . urlencode((string) $application['id']));
exit;
} catch (Throwable $exception) {
$errors['form'] = 'تعذر حفظ بيانات عضو الفريق حالياً. يرجى المحاولة مرة أخرى.';
}
}
}
$teachers = $isApprovedSchool ? list_school_teachers((int) $application['id']) : [];
$metrics = $isApprovedSchool ? school_teacher_metrics((int) $application['id']) : [
'total' => 0,
'active' => 0,
'pending' => 0,
'inactive' => 0,
'email_ready' => 0,
'supervisors' => 0,
];
$studentMetrics = $isApprovedSchool ? school_student_metrics((int) $application['id']) : [
'total' => 0,
'active' => 0,
'waiting' => 0,
'withdrawn' => 0,
'boys' => 0,
'girls' => 0,
];
$pageTitle = $application ? 'فريق المعلمين: ' . (string) $application['center_name'] : 'فريق المعلمين';
$pageDescription = 'صفحة مستقلة لإدارة المعلمين والمشرفين بعد اعتماد المدرسة، مع فصل واضح بين إضافة الكادر وكشف الفريق ومؤشرات الجاهزية.';
if (!$application) {
http_response_code(404);
}
render_page_start($pageTitle, 'approved', $pageDescription);
render_flash($flash);
?>
<section class="py-4 py-lg-5">
<div class="container-xxl">
<?php if (!$application): ?>
<div class="app-card text-center py-5">
<div class="empty-title mb-2">المدرسة غير موجودة</div>
<p class="text-muted mb-3">تحقق من رابط المدرسة أو ارجع إلى قائمة المراكز المعتمدة.</p>
<a class="btn btn-dark" href="applications.php?status=approved">المراكز المعتمدة</a>
</div>
<?php elseif (!$isApprovedSchool): ?>
<div class="page-banner mb-4 mb-lg-5">
<div class="row g-4 align-items-center">
<div class="col-lg-8">
<span class="eyebrow mb-3">الفريق يُفعّل بعد الاعتماد</span>
<h1 class="page-title mb-3"><?= e((string) $application['center_name']) ?></h1>
<p class="page-copy mb-3">تم تجهيز صفحة المعلمين، لكن فتح سجل الفريق مرتبط بتحويل حالة المركز إلى <strong>معتمد</strong> أولاً حتى يبدأ التشغيل وفق الترتيب الإداري الصحيح.</p>
<div class="hero-meta">
<span>الحالة الحالية: <?= e(status_meta((string) $application['status'])['label']) ?></span>
<span>المدينة: <?= e((string) $application['city']) ?></span>
</div>
<div class="cta-stack mt-4">
<a class="btn btn-dark" href="application_detail.php?id=<?= e((string) $application['id']) ?>">العودة لملف الاعتماد</a>
<a class="btn btn-outline-secondary" href="approved_school.php?id=<?= e((string) $application['id']) ?>">صفحة المركز</a>
</div>
</div>
</div>
</div>
<?php else: ?>
<div class="page-banner approved-hero mb-4 mb-lg-5">
<div class="row g-4 align-items-start">
<div class="col-lg-8">
<span class="approved-kicker mb-3">صفحة مستقلة لإدارة الفريق التعليمي</span>
<h1 class="page-title mb-3">فريق المدرسة — <?= e((string) $application['center_name']) ?></h1>
<p class="page-copy mb-3">بعد فتح سجل الطلاب، هذه هي الصفحة المنطقية التالية لبناء الكادر. يمكن هنا إضافة المعلمين والمشرفين والكوادر المساندة مع عزل واضح بين النموذج وكشف الفريق.</p>
<div class="hero-meta">
<span><?= e((string) $application['city']) ?></span>
<span><?= e((string) $metrics['active']) ?> أعضاء مفعلون</span>
<span><?= e((string) $metrics['supervisors']) ?> أدوار إشرافية</span>
</div>
<div class="cta-stack mt-4">
<a class="btn btn-dark" href="approved_school.php?id=<?= e((string) $application['id']) ?>">العودة لصفحة المركز</a>
<a class="btn btn-outline-secondary" href="students.php?id=<?= e((string) $application['id']) ?>">تسجيل الطلاب</a>
<a class="btn btn-outline-secondary" href="application_detail.php?id=<?= e((string) $application['id']) ?>">ملف الاعتماد</a>
</div>
</div>
<div class="col-lg-4">
<div class="app-card approved-note h-100">
<div class="section-title mb-3">ملخص الفريق</div>
<div class="summary-stack mb-3">
<div class="summary-row"><span>إجمالي الكادر</span><strong><?= e((string) $metrics['total']) ?> عضو</strong></div>
<div class="summary-row"><span>جاهزون للتواصل</span><strong><?= e((string) $metrics['email_ready']) ?> ببريد موثق</strong></div>
<div class="summary-row"><span>الطلاب النشطون</span><strong><?= e((string) $studentMetrics['active']) ?> طالب/طالبة</strong></div>
</div>
<p class="section-subtle mb-0">وجود سجل واضح للمعلمين يسهّل لاحقاً ربط الحصص، التقييمات، والمتابعة اليومية لكل مدرسة معتمدة.</p>
</div>
</div>
</div>
</div>
<div class="row g-4 mb-4">
<div class="col-md-6 col-xl-3"><div class="app-card stat-tile"><div class="mini-stat-label">إجمالي الفريق</div><div class="mini-stat-value"><?= e((string) $metrics['total']) ?></div><div class="mini-stat-copy">عدد أعضاء الكادر المسجلين لهذا المركز.</div></div></div>
<div class="col-md-6 col-xl-3"><div class="app-card stat-tile"><div class="mini-stat-label">مفعلون</div><div class="mini-stat-value"><?= e((string) $metrics['active']) ?></div><div class="mini-stat-copy">جاهزون للبدء الفعلي ضمن الخطة التشغيلية.</div></div></div>
<div class="col-md-6 col-xl-3"><div class="app-card stat-tile"><div class="mini-stat-label">بانتظار التفعيل</div><div class="mini-stat-value"><?= e((string) $metrics['pending']) ?></div><div class="mini-stat-copy">يحتاجون استكمال الجدول أو الموافقة النهائية.</div></div></div>
<div class="col-md-6 col-xl-3"><div class="app-card stat-tile"><div class="mini-stat-label">أدوار إشرافية</div><div class="mini-stat-value"><?= e((string) $metrics['supervisors']) ?></div><div class="mini-stat-copy">أعضاء في أدوار إشرافية أو قيادية.</div></div></div>
</div>
<div class="row g-4 align-items-start">
<div class="col-lg-4">
<div class="app-card sidebar-card mb-4">
<div class="section-head mb-3">
<div>
<div class="section-title">إضافة عضو جديد</div>
<div class="section-copy">أضف المعلمين، المشرفين، والمنسقين في صفحة مستقلة للمركز.</div>
</div>
</div>
<?php if (isset($errors['form'])): ?>
<div class="alert alert-danger"><?= e($errors['form']) ?></div>
<?php endif; ?>
<form method="post" class="vstack gap-3" novalidate>
<div>
<label class="form-label" for="full_name">الاسم الكامل</label>
<input class="form-control <?= isset($errors['full_name']) ? 'is-invalid' : '' ?>" id="full_name" name="full_name" value="<?= e($values['full_name']) ?>" required>
<?php if (isset($errors['full_name'])): ?><div class="invalid-feedback"><?= e($errors['full_name']) ?></div><?php endif; ?>
</div>
<div>
<label class="form-label" for="role_title">الدور الوظيفي</label>
<select class="form-select <?= isset($errors['role_title']) ? 'is-invalid' : '' ?>" id="role_title" name="role_title" required>
<option value="">اختر الدور</option>
<?php foreach (teacher_role_options() as $role): ?>
<option value="<?= e($role) ?>" <?= $values['role_title'] === $role ? 'selected' : '' ?>><?= e($role) ?></option>
<?php endforeach; ?>
</select>
<?php if (isset($errors['role_title'])): ?><div class="invalid-feedback"><?= e($errors['role_title']) ?></div><?php endif; ?>
</div>
<div>
<label class="form-label" for="specialization">التخصص / المسار</label>
<input class="form-control" id="specialization" name="specialization" value="<?= e($values['specialization']) ?>" placeholder="مثال: الرياضيات، القرآن، الأنشطة العلمية">
</div>
<div class="row g-3">
<div class="col-md-6">
<label class="form-label" for="phone">الهاتف</label>
<input class="form-control <?= isset($errors['phone']) ? 'is-invalid' : '' ?>" id="phone" name="phone" value="<?= e($values['phone']) ?>" dir="ltr" inputmode="tel">
<?php if (isset($errors['phone'])): ?><div class="invalid-feedback"><?= e($errors['phone']) ?></div><?php endif; ?>
</div>
<div class="col-md-6">
<label class="form-label" for="email">البريد الإلكتروني</label>
<input class="form-control <?= isset($errors['email']) ? 'is-invalid' : '' ?>" id="email" name="email" type="email" value="<?= e($values['email']) ?>" dir="ltr">
<?php if (isset($errors['email'])): ?><div class="invalid-feedback"><?= e($errors['email']) ?></div><?php endif; ?>
</div>
</div>
<div>
<label class="form-label" for="employment_status">الحالة</label>
<select class="form-select <?= isset($errors['employment_status']) ? 'is-invalid' : '' ?>" id="employment_status" name="employment_status">
<?php foreach (teacher_employment_status_map() as $status => $meta): ?>
<option value="<?= e($status) ?>" <?= $values['employment_status'] === $status ? 'selected' : '' ?>><?= e($meta['label']) ?></option>
<?php endforeach; ?>
</select>
<?php if (isset($errors['employment_status'])): ?><div class="invalid-feedback"><?= e($errors['employment_status']) ?></div><?php endif; ?>
</div>
<div>
<label class="form-label" for="notes">ملاحظات</label>
<textarea class="form-control" id="notes" name="notes" rows="4" placeholder="مثال: مسؤول عن مجموعة الصفوف العليا أو بانتظار اعتماد الجدول."><?= e($values['notes']) ?></textarea>
</div>
<div class="d-grid">
<button class="btn btn-dark" type="submit">حفظ عضو الفريق</button>
</div>
</form>
</div>
<div class="app-card sidebar-card">
<div class="section-title mb-3">الخطوة التالية بعد الفريق</div>
<ul class="module-roadmap-list mb-0">
<li><strong>التقييمات والأوزان</strong><span class="section-subtle">بناء أنواع التقييم أصبح الخطوة المنطقية التالية بعد تثبيت الطلاب والمعلمين.</span></li>
<li><strong>غياب الطلاب</strong><span class="section-subtle">يمكن لاحقاً ربط الغياب بالطلاب والفريق المسؤول عن المتابعة اليومية.</span></li>
</ul>
</div>
</div>
<div class="col-lg-8">
<div class="app-card mb-4">
<div class="section-head mb-3">
<div>
<div class="section-title">كشف الفريق التعليمي</div>
<div class="section-copy">جميع المعلمين والمشرفين المرتبطين بهذا المركز فقط.</div>
</div>
<span class="header-chip"><?= e((string) $metrics['email_ready']) ?> بريد جاهز / <?= e((string) $metrics['pending']) ?> بانتظار التفعيل</span>
</div>
<div class="row g-3 mb-3">
<div class="col-md-4"><div class="school-data-item"><strong>إجمالي الفريق</strong><span><?= e((string) $metrics['total']) ?> عضو</span></div></div>
<div class="col-md-4"><div class="school-data-item"><strong>أدوار قيادية</strong><span><?= e((string) $metrics['supervisors']) ?> إشرافي</span></div></div>
<div class="col-md-4"><div class="school-data-item"><strong>مع الطلاب النشطين</strong><span><?= e((string) $studentMetrics['active']) ?> طالب/طالبة</span></div></div>
</div>
<?php if ($teachers === []): ?>
<div class="empty-state text-center p-4">
<div class="empty-title mb-2">لا يوجد أعضاء فريق مسجلون بعد</div>
<p class="text-muted mb-0">ابدأ من النموذج في الجانب الأيمن لإضافة أول معلم أو مشرف إلى سجل المدرسة.</p>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table app-table align-middle">
<thead>
<tr>
<th>الاسم</th>
<th>الدور</th>
<th>التخصص</th>
<th>التواصل</th>
<th>الحالة</th>
<th>الإضافة</th>
</tr>
</thead>
<tbody>
<?php foreach ($teachers as $teacher): ?>
<tr>
<td>
<strong><?= e((string) $teacher['full_name']) ?></strong>
<?php if (!empty($teacher['notes'])): ?><small><?= e((string) $teacher['notes']) ?></small><?php endif; ?>
</td>
<td><?= e((string) $teacher['role_title']) ?></td>
<td><?= e((string) ($teacher['specialization'] ?: '—')) ?></td>
<td>
<strong><?= e((string) ($teacher['phone'] ?: 'بدون هاتف')) ?></strong>
<small><?= e((string) ($teacher['email'] ?: 'بدون بريد إلكتروني')) ?></small>
</td>
<td><?= teacher_employment_status_badge((string) $teacher['employment_status']) ?></td>
<td><?= e(substr((string) $teacher['created_at'], 0, 10)) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
<div class="app-card">
<div class="section-title mb-3">سياق المدرسة</div>
<div class="row g-3">
<div class="col-md-6"><div class="school-data-item"><strong>مدير المركز</strong><span><?= e((string) $application['director_name']) ?></span></div></div>
<div class="col-md-6"><div class="school-data-item"><strong>الطاقة الاستيعابية</strong><span><?= e((string) $application['expected_students']) ?> طالب</span></div></div>
<div class="col-md-6"><div class="school-data-item"><strong>قيد الطلاب الحالي</strong><span><?= e((string) $studentMetrics['total']) ?> طالب/طالبة</span></div></div>
<div class="col-md-6"><div class="school-data-item"><strong>البريد الرسمي</strong><span><?= e((string) $application['email']) ?></span></div></div>
</div>
<div class="cta-stack mt-4">
<a class="btn btn-outline-secondary" href="students.php?id=<?= e((string) $application['id']) ?>">العودة إلى الطلاب</a>
<a class="btn btn-outline-secondary" href="approved_school.php?id=<?= e((string) $application['id']) ?>">صفحة المركز</a>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
</section>
<?php render_page_end(); ?>