$(document).ready(function() {
// Fetch Students based on selected SchoolID and class
$('#class, #SchoolID').on('change', function() {
var schoolID = $('#SchoolID').val();
var classID = $('#class').val();
if (schoolID && classID) {
$.post('fetch_students.php', {
action: 'fetch_students_with_null_tests',
class: classID,
SchoolID: schoolID
}, function(data) {
console.log('Raw response:', data);
try {
var parsedData = typeof data === 'string' ? JSON.parse(data.trim()) : data;
var students = parsedData.students || [];
var rows = '';
if (students.length === 0) {
rows = 'لا ŁŁŲ¬ŲÆ طلاب';
} else {
students.forEach(function(student) {
rows += '';
rows += '' + student.Name + '';
for (var i = 1; i <= 13; i++) {
let maxValue = [5,5,5,5,5,5,3,2,5,2,3,5,10][i-1];
rows += `
`;
}
rows += '';
});
}
$('#student-table-body').html(rows);
} catch (e) {
console.error('Error parsing response:', e, data);
alert("Ų®Ų·Ų£ ŁŁ ŲŖŲŁ…ŁŁ„ البŁŲ§Ł†Ų§ŲŖ. ŁŲ±Ų¬Ł‰ المŲŲ§ŁŁ„Ų© Ł…Ų±Ų© أخرى.");
}
}).fail(function(xhr, status, error) {
console.error('AJAX Error:', status, error);
alert("Ų®Ų·Ų£ ŁŁ الاتصال بالخادم. ŁŲ±Ų¬Ł‰ المŲŲ§ŁŁ„Ų© Ł…Ų±Ų© أخرى.");
});
} else {
$('#student-table-body').html('');
}
});
function validateInput(input, max) {
const value = parseInt(input.value);
if (isNaN(value) || value < 0 || value > max) {
alert(`Ų§Ł„Ł‚ŁŁ…Ų© ŁŲ¬ŲØ Ų£Ł† ŲŖŁŁŁ† ŲØŁŁ† 0 Ł ${max}`);
input.value = '';
}
}
});