252 lines
12 KiB
PHP
252 lines
12 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/includes/app.php';
|
|
|
|
function completion_certificate_date_label(string $date): string
|
|
{
|
|
if ($date === '' || strtotime($date) === false) {
|
|
return date('Y/m/d');
|
|
}
|
|
|
|
return date('Y/m/d', strtotime($date));
|
|
}
|
|
|
|
function completion_certificate_decimal_value(float $value): string
|
|
{
|
|
return rtrim(rtrim(number_format($value, 2, '.', ''), '0'), '.');
|
|
}
|
|
|
|
function completion_certificate_message_text(string $template, array $tokens, string $fallback): string
|
|
{
|
|
$message = trim($template);
|
|
if ($message === '') {
|
|
$message = $fallback;
|
|
}
|
|
|
|
return strtr($message, $tokens);
|
|
}
|
|
|
|
$flash = consume_flash();
|
|
$settings = get_app_settings();
|
|
$applicationId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT) ?: 0;
|
|
$requestedCycleId = filter_input(INPUT_GET, 'cycle', FILTER_VALIDATE_INT) ?: 0;
|
|
$studentId = filter_input(INPUT_GET, 'student_id', FILTER_VALIDATE_INT) ?: 0;
|
|
$application = $applicationId > 0 ? get_application($applicationId) : null;
|
|
$isApprovedSchool = $application && (string) $application['status'] === 'approved';
|
|
$cycleContext = ['cycles' => [], 'selected' => null, 'active' => null, 'read_only' => false];
|
|
$selectedCycle = null;
|
|
$selectedCycleId = 0;
|
|
$cycleLabel = 'الدورة الحالية';
|
|
|
|
if ($application && $isApprovedSchool) {
|
|
$cycleContext = resolve_school_cycle_context((int) $application['id'], $application, $requestedCycleId);
|
|
$selectedCycle = $cycleContext['selected'];
|
|
$selectedCycleId = $selectedCycle ? (int) ($selectedCycle['id'] ?? 0) : 0;
|
|
$cycleLabel = $selectedCycle ? (string) ($selectedCycle['cycle_name'] ?? 'الدورة الحالية') : $cycleLabel;
|
|
}
|
|
|
|
$certificate = $isApprovedSchool && $selectedCycleId > 0 && $studentId > 0
|
|
? school_student_certificate_summary((int) $application['id'], $selectedCycleId, $studentId)
|
|
: [
|
|
'student' => null,
|
|
'assessments' => [],
|
|
'has_results' => false,
|
|
'completed_assessments' => 0,
|
|
'active_assessments' => 0,
|
|
'missing_assessments' => 0,
|
|
'absent_assessments' => 0,
|
|
'excused_assessments' => 0,
|
|
'overall_percentage' => 0.0,
|
|
'score_total' => 0.0,
|
|
'max_score_total' => 0.0,
|
|
'latest_assessed_on' => '',
|
|
'performance' => student_certificate_performance_meta(0.0),
|
|
];
|
|
$student = is_array($certificate['student'] ?? null) ? $certificate['student'] : null;
|
|
|
|
if (!$application || !$isApprovedSchool || $selectedCycleId <= 0 || $studentId <= 0 || $student === null) {
|
|
http_response_code(404);
|
|
}
|
|
|
|
$performance = $certificate['performance'] ?? student_certificate_performance_meta(0.0);
|
|
$hasResults = !empty($certificate['has_results']);
|
|
$honor = $hasResults
|
|
? student_completion_certificate_honor_meta((float) ($certificate['overall_percentage'] ?? 0))
|
|
: [
|
|
'key' => 'completion',
|
|
'title' => 'Successful Completion',
|
|
'title_ar' => 'إتمام ناجح',
|
|
'completion_line_ar' => 'أتمّ/أتمّت الدورة بنجاح واستفاد/استفادت من محتواها العلمي.',
|
|
];
|
|
$template = (string) ($settings['completion_certificate_template'] ?? 'modern');
|
|
if (!in_array($template, ['modern', 'classic'], true)) {
|
|
$template = 'modern';
|
|
}
|
|
|
|
$centerName = trim((string) ($application['center_name'] ?? ''));
|
|
if ($centerName === '') {
|
|
$centerName = (string) ($settings['app_name'] ?? project_name());
|
|
}
|
|
$centerLogo = trim((string) ($application['logo'] ?? ''));
|
|
if ($centerLogo === '') {
|
|
$centerLogo = trim((string) ($settings['app_logo'] ?? ''));
|
|
}
|
|
$tagline = trim((string) ($settings['completion_certificate_tagline'] ?? ''));
|
|
if ($tagline === '') {
|
|
$tagline = 'شهادة إتمام وتكريم';
|
|
}
|
|
|
|
$overallPercentage = (float) ($certificate['overall_percentage'] ?? 0);
|
|
$percentageLabel = $hasResults ? completion_certificate_decimal_value($overallPercentage) . '%' : '—';
|
|
$fallbackMessage = sprintf(
|
|
'تشهد إدارة %s بأن الطالب/الطالبة %s قد أتمّ/أتمّت متطلبات %s %s.',
|
|
$centerName,
|
|
(string) ($student['full_name'] ?? 'الطالب/الطالبة'),
|
|
$cycleLabel,
|
|
$honor['title_ar']
|
|
);
|
|
|
|
$bodyMessage = completion_certificate_message_text(
|
|
(string) ($settings['completion_certificate_message'] ?? ''),
|
|
[
|
|
'{student}' => (string) ($student['full_name'] ?? ''),
|
|
'{center}' => $centerName,
|
|
'{cycle}' => $cycleLabel,
|
|
'{performance}' => (string) ($performance['label_ar'] ?? 'مميز'),
|
|
'{honor}' => (string) ($honor['title_ar'] ?? 'بنجاح'),
|
|
'{percentage}' => $hasResults ? completion_certificate_decimal_value($overallPercentage) : '0',
|
|
],
|
|
$fallbackMessage
|
|
);
|
|
|
|
$issueDateLabel = completion_certificate_date_label((string) ($certificate['latest_assessed_on'] ?? ''));
|
|
$studentsUrl = $application ? school_page_url('students.php', (int) $application['id'], $selectedCycleId) : 'students.php';
|
|
$detailedCertificateUrl = $application ? school_page_url('student_certificate.php', (int) $application['id'], $selectedCycleId) . '&student_id=' . urlencode((string) $studentId) : 'student_certificate.php';
|
|
$pageTitle = $student ? 'شهادة إتمام الدورة: ' . (string) $student['full_name'] : 'شهادة إتمام الدورة';
|
|
$pageDescription = 'شهادة إتمام وتكريم قابلة للطباعة تعرض اسم المركز وشعاره ونتيجة الطالب النهائية بتصميم جميل ومختصر.';
|
|
|
|
render_page_start($pageTitle, 'approved', $pageDescription);
|
|
render_flash($flash);
|
|
?>
|
|
<section class="student-certificate-page completion-certificate-page py-4 py-lg-5">
|
|
<div class="container-xl">
|
|
<div class="certificate-toolbar">
|
|
<div>
|
|
<div class="section-title">شهادة الإتمام والتكريم</div>
|
|
<div class="section-subtle">نسخة مختصرة وأنيقة للطباعة، مستقلة عن كشف الدرجات التفصيلي.</div>
|
|
</div>
|
|
<div class="certificate-toolbar-actions">
|
|
<a class="btn btn-outline-secondary" href="<?= e($studentsUrl) ?>">العودة إلى الطلاب</a>
|
|
<?php if ($student): ?>
|
|
<a class="btn btn-outline-secondary" href="<?= e($detailedCertificateUrl) ?>" target="_blank" rel="noopener">كشف الأداء</a>
|
|
<button type="button" class="btn btn-primary" onclick="window.print()">طباعة الشهادة</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?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-primary" href="applications.php?status=approved">المراكز المعتمدة</a>
|
|
</div>
|
|
<?php elseif (!$isApprovedSchool): ?>
|
|
<div class="app-card text-center py-5">
|
|
<div class="empty-title mb-2">الشهادة غير متاحة حالياً</div>
|
|
<p class="text-muted mb-0">يمكن إصدار شهادة الإتمام للمراكز المعتمدة فقط.</p>
|
|
</div>
|
|
<?php elseif ($selectedCycleId <= 0 || !$student): ?>
|
|
<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-primary" href="<?= e($studentsUrl) ?>">العودة إلى سجل الطلاب</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<article class="completion-certificate-card completion-template-<?= e($template) ?>" aria-labelledby="completion-certificate-title">
|
|
<div class="completion-certificate-layer completion-certificate-layer-one" aria-hidden="true"></div>
|
|
<div class="completion-certificate-layer completion-certificate-layer-two" aria-hidden="true"></div>
|
|
|
|
<div class="completion-certificate-inner">
|
|
<header class="completion-certificate-header">
|
|
<div class="completion-branding">
|
|
<?php if ($centerLogo !== ''): ?>
|
|
<img src="<?= e(asset_url($centerLogo)) ?>" alt="شعار <?= e($centerName) ?>" class="completion-brand-logo" width="96" height="96">
|
|
<?php else: ?>
|
|
<div class="completion-brand-logo completion-brand-badge" aria-hidden="true"><?= e(mb_substr($centerName, 0, 1)) ?></div>
|
|
<?php endif; ?>
|
|
<div>
|
|
<div class="completion-overline">Certificate of Completion</div>
|
|
<h1 id="completion-certificate-title" class="completion-certificate-title"><?= e($tagline) ?></h1>
|
|
<p class="completion-certificate-center mb-0"><?= e($centerName) ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="completion-certificate-stamps">
|
|
<span class="completion-stamp"><?= e($cycleLabel) ?></span>
|
|
<span class="completion-stamp completion-stamp-accent"><?= e((string) ($honor['title_ar'] ?? 'بنجاح')) ?></span>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="completion-certificate-content">
|
|
<p class="completion-intro mb-2">تُمنح هذه الشهادة إلى</p>
|
|
<div class="completion-student-name"><?= e((string) ($student['full_name'] ?? '')) ?></div>
|
|
<?php if (!empty($student['student_code'])): ?>
|
|
<div class="completion-student-code">رقم الطالب: <?= e((string) $student['student_code']) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<p class="completion-message"><?= e($bodyMessage) ?></p>
|
|
<p class="completion-honor-line mb-0"><?= e((string) ($honor['completion_line_ar'] ?? '')) ?></p>
|
|
</div>
|
|
|
|
<div class="completion-certificate-grid">
|
|
<section class="completion-summary-card">
|
|
<span class="completion-summary-label">التقدير النهائي</span>
|
|
<div class="performance-pill performance-<?= e((string) ($performance['key'] ?? 'good')) ?> completion-performance-pill">
|
|
<?= e((string) ($performance['label_ar'] ?? 'مميز')) ?>
|
|
</div>
|
|
<div class="completion-honor-title"><?= e((string) ($honor['title_ar'] ?? 'بنجاح')) ?></div>
|
|
<div class="completion-honor-subtitle"><?= e((string) ($honor['title'] ?? 'Successful Completion')) ?></div>
|
|
</section>
|
|
|
|
<section class="completion-meta-grid" aria-label="بيانات الشهادة">
|
|
<div class="completion-meta-item">
|
|
<strong>الدورة</strong>
|
|
<span><?= e($cycleLabel) ?></span>
|
|
</div>
|
|
<div class="completion-meta-item">
|
|
<strong>تاريخ الإصدار</strong>
|
|
<span><?= e($issueDateLabel) ?></span>
|
|
</div>
|
|
<div class="completion-meta-item">
|
|
<strong>نسبة الأداء</strong>
|
|
<span><?= e($percentageLabel) ?></span>
|
|
</div>
|
|
<div class="completion-meta-item">
|
|
<strong>التقييمات المكتملة</strong>
|
|
<span><?= e((string) ((int) ($certificate['completed_assessments'] ?? 0))) ?></span>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<?php if (!$hasResults): ?>
|
|
<div class="completion-note">
|
|
لا توجد تقييمات مرصودة لهذا الطالب بعد، لذلك تم إصدار شهادة إتمام مختصرة بدون مرتبة أداء رقمية.
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<footer class="completion-signature-row">
|
|
<div class="completion-signature-block">
|
|
<strong>مدير/ة المركز</strong>
|
|
<span><?= e((string) ($application['director_name'] ?? $centerName)) ?></span>
|
|
</div>
|
|
<div class="completion-signature-block">
|
|
<strong>اعتماد الشهادة</strong>
|
|
<span><?= e((string) ($honor['title_ar'] ?? 'إتمام ناجح')) ?></span>
|
|
</div>
|
|
</footer>
|
|
</div>
|
|
</article>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
<?php render_page_end(); ?>
|