= e((string) ($center['city'] ?? '')) ?> — = e((string) ($center['director_name'] ?? '')) ?>
0): ?> فتح تقييم هذا المركز أنشئ دورة أولاً0 ? get_application($applicationId) : null;
$isApprovedCenter = $application && (string) ($application['status'] ?? '') === 'approved';
$values = assessment_defaults();
$errors = [];
$cycleContext = ['cycles' => [], 'selected' => null, 'active' => null, 'read_only' => false];
$selectedCycle = null;
$selectedCycleId = 0;
$isCycleReadOnly = false;
$cycleLabel = 'لا توجد دورة بعد';
$buildCenterAssessmentsUrl = static function (int $targetApplicationId = 0, int $targetCycleId = 0, array $extra = []): string {
$params = [];
if ($targetApplicationId > 0) {
$params['id'] = $targetApplicationId;
}
if ($targetCycleId > 0) {
$params['cycle'] = $targetCycleId;
}
foreach ($extra as $key => $value) {
if ($value === '' || $value === null) {
continue;
}
$params[$key] = $value;
}
return 'center_assessments.php' . ($params !== [] ? '?' . http_build_query($params) : '');
};
$buildCenterAssessmentScoreUrl = static function (int $targetApplicationId = 0, int $targetCycleId = 0, int $targetAssessmentId = 0): string {
$params = [];
if ($targetApplicationId > 0) {
$params['id'] = $targetApplicationId;
}
if ($targetCycleId > 0) {
$params['cycle'] = $targetCycleId;
}
if ($targetAssessmentId > 0) {
$params['assessment_id'] = $targetAssessmentId;
}
return 'center_assessment_score_sheet.php' . ($params !== [] ? '?' . http_build_query($params) : '');
};
$buildCenterAssessmentReportUrl = static function (int $targetApplicationId = 0, int $targetCycleId = 0): string {
$params = [];
if ($targetApplicationId > 0) {
$params['id'] = $targetApplicationId;
}
if ($targetCycleId > 0) {
$params['cycle'] = $targetCycleId;
}
return 'center_assessment_report.php' . ($params !== [] ? '?' . http_build_query($params) : '');
};
$buildCenterAssessmentPrintUrl = static function (int $targetApplicationId = 0, int $targetCycleId = 0, int $targetAssessmentId = 0): string {
$params = [];
if ($targetApplicationId > 0) {
$params['id'] = $targetApplicationId;
}
if ($targetCycleId > 0) {
$params['cycle'] = $targetCycleId;
}
if ($targetAssessmentId > 0) {
$params['assessment_id'] = $targetAssessmentId;
}
return 'center_assessment_print_sheet.php' . ($params !== [] ? '?' . http_build_query($params) : '');
};
$buildCenterAssessmentCriteriaUrl = static function (int $targetApplicationId = 0, int $targetCycleId = 0, int $targetAssessmentId = 0): string {
$params = [];
if ($targetApplicationId > 0) {
$params['id'] = $targetApplicationId;
}
if ($targetCycleId > 0) {
$params['cycle'] = $targetCycleId;
}
if ($targetAssessmentId > 0) {
$params['assessment_id'] = $targetAssessmentId;
}
return 'center_assessment_criteria.php' . ($params !== [] ? '?' . http_build_query($params) : '');
};
if ($isApprovedCenter) {
$cycleContext = resolve_school_cycle_context((int) $application['id'], $application, $requestedCycleId);
$selectedCycle = $cycleContext['selected'];
$selectedCycleId = $selectedCycle ? (int) ($selectedCycle['id'] ?? 0) : 0;
$isCycleReadOnly = (bool) ($cycleContext['read_only'] ?? false);
$cycleLabel = $selectedCycle ? (string) ($selectedCycle['cycle_name'] ?? $cycleLabel) : $cycleLabel;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $isApprovedCenter) {
$action = $_POST['action'] ?? 'add';
$assessmentId = filter_input(INPUT_POST, 'assessment_id', FILTER_VALIDATE_INT) ?: 0;
[$values, $errors] = validate_assessment_input($_POST);
if ($selectedCycleId <= 0) {
$errors['form'] = 'يجب إنشاء دورة موسمية لهذا المركز قبل إعداد تقييمات المراكز.';
} elseif ($isCycleReadOnly) {
$errors['form'] = 'الدورة الحالية مؤرشفة للقراءة فقط. اختر دورة نشطة أو أنشئ دورة جديدة.';
}
if ($errors === []) {
try {
if ($action === 'import_global') {
$globalId = filter_input(INPUT_POST, 'global_assessment_id', FILTER_VALIDATE_INT) ?: 0;
if ($globalId > 0) {
import_global_center_assessment_to_center($globalId, (int) $application['id'], $selectedCycleId);
set_flash('success', 'تم إدراج القالب العام مع بنوده بنجاح.');
} else {
set_flash('error', 'يجب اختيار قالب صحيح.');
}
} elseif ($action === 'edit' && $assessmentId > 0) {
update_center_assessment_type_in_cycle((int) $application['id'], $selectedCycleId, $assessmentId, $values);
set_flash('success', 'تم تحديث تقييم المركز بنجاح.');
} else {
create_center_assessment_type_in_cycle((int) $application['id'], $selectedCycleId, $values);
set_flash('success', 'تم حفظ نوع تقييم جديد للمركز داخل الدورة المحددة.');
}
$redirectParams = array_intersect_key($_GET, array_flip(['search', 'category', 'page']));
header('Location: ' . $buildCenterAssessmentsUrl((int) $application['id'], $selectedCycleId, $redirectParams));
exit;
} catch (Throwable $exception) {
$errors['form'] = 'تعذر حفظ تقييم المركز حالياً. يرجى المحاولة مرة أخرى.';
}
}
}
$filters = [
'search' => clean_text($_GET['search'] ?? '', 255),
'category' => clean_text($_GET['category'] ?? '', 80),
];
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT) ?: 1;
$limit = 20;
$offset = ($page - 1) * $limit;
$assessments = $isApprovedCenter && $selectedCycleId > 0 ? list_center_assessments_by_cycle((int) $application['id'], $selectedCycleId, $filters, $limit, $offset) : [];
$totalAssessments = $isApprovedCenter && $selectedCycleId > 0 ? count_center_assessments_by_cycle((int) $application['id'], $selectedCycleId, $filters) : 0;
$metrics = $isApprovedCenter && $selectedCycleId > 0 ? center_assessment_metrics_by_cycle((int) $application['id'], $selectedCycleId) : [
'total' => 0,
'active' => 0,
'inactive' => 0,
'active_weight' => 0.0,
'average_max_score' => 0.0,
'percentage' => 0,
'points' => 0,
'rubric' => 0,
];
$approvedCenterCards = [];
foreach ($approvedCenters as $center) {
$centerId = (int) ($center['id'] ?? 0);
if ($centerId <= 0) {
continue;
}
$centerCycleContext = resolve_school_cycle_context($centerId, $center, 0);
$centerSelectedCycle = $centerCycleContext['selected'] ?? null;
$centerCycleId = $centerSelectedCycle ? (int) ($centerSelectedCycle['id'] ?? 0) : 0;
$approvedCenterCards[] = [
'application' => $center,
'selected_cycle' => $centerSelectedCycle,
'selected_cycle_id' => $centerCycleId,
'url' => $buildCenterAssessmentsUrl($centerId, $centerCycleId),
];
}
$pageTitle = $application && $isApprovedCenter
? 'تقييم المراكز: ' . (string) ($application['center_name'] ?? '') . ($selectedCycle ? ' — ' . $cycleLabel : '')
: 'تقييم المراكز';
$pageDescription = 'إدارة تقييمات إشرافية مستقلة للمراكز المعتمدة حسب الدورة الموسمية، مع البنود، الرصد، والتقرير المجمع.';
render_page_start($pageTitle, 'admin', $pageDescription);
render_flash($flash);
?>
اعتمد مركزاً أولاً من لوحة الطلبات حتى تتمكن من إعداد تقييمات المراكز. = e((string) ($center['city'] ?? '')) ?> — = e((string) ($center['director_name'] ?? '')) ?> ابدأ بتعريف أول نوع تقييم للمركز مثل: الالتزام الإداري، جودة البيئة التعليمية، أو متابعة الخطة.
التقييم
الفئة
الدرجة والوزن
البنود
الحالة
الإجراء
= e((string) ((int) ($assessment['criteria_count'] ?? 0))) ?>
= assessment_active_badge((int) ($assessment['is_active'] ?? 0)) ?>