-- Registers manage_blocked_names.php in the sidebar under Attendance,
-- alongside the CSV import feature it manages. Idempotent (skips rows
-- that already exist), so safe to run whether or not this is a fresh
-- install.

INSERT INTO `nav_modules` (`module_key`, `label`, `url`, `parent_id`, `display_order`)
SELECT 'attendance_blocked_names', 'Blocked Import Names', 'manage_blocked_names.php', id, 50
FROM `nav_modules` nm
WHERE nm.`module_key` = 'attendance'
AND NOT EXISTS (SELECT 1 FROM `nav_modules` WHERE `module_key` = 'attendance_blocked_names');

INSERT IGNORE INTO `nav_module_roles` (`module_id`, `role`)
SELECT nm.id, r.role FROM `nav_modules` nm
CROSS JOIN (SELECT 'admin' AS role UNION SELECT 'superadmin' UNION SELECT 'hr') r
WHERE nm.`module_key` = 'attendance_blocked_names';
