attendance
// Enqueue Scripts for Frontend
function enqueue_attendance_scripts() {
wp_enqueue_script(‘attendance-js’, ‘https://cdnjs.cloudflare.com/ajax/libs/tesseract.js/2.1.1/tesseract.min.js’, [], null, true);
}
add_action(‘wp_enqueue_scripts’, ‘enqueue_attendance_scripts’);
// Shortcode to Display Attendance Form and Results
function attendance_tool_shortcode() {
ob_start();
?>
‘No file uploaded’]);
}
$file = $_FILES[‘attendance-file’];
$file_path = $file[‘tmp_name’];
// Use Tesseract OCR or an API for text extraction
require_once ‘vendor/autoload.php’;
$tesseract = new TesseractOCR($file_path);
$text = $tesseract->run();
// Parse Text and Count Attendance
$attendanceData = parse_attendance_text($text);
wp_send_json_success([‘attendanceData’ => $attendanceData]);
}
add_action(‘wp_ajax_process_attendance_file’, ‘process_attendance_file’);
add_action(‘wp_ajax_nopriv_process_attendance_file’, ‘process_attendance_file’);
// Helper Function to Parse Attendance Text
function parse_attendance_text($text) {
$lines = explode(“\n”, $text);
$attendanceData = [];
foreach ($lines as $line) {
// Assuming “Student Name P P A P” format
$parts = preg_split(‘/\s+/’, $line);
if (count($parts) < 2) continue;
$name = array_shift($parts);
$presentDays = array_reduce($parts, function($carry, $item) {
return $carry + ($item === 'P' ? 1 : 0);
}, 0);
$attendanceData[] = [
'name' => $name,
‘presentDays’ => $presentDays
];
}
return $attendanceData;
}