"Department of Emergency Medicine", "Surgery" => "Department of Surgery", "Medicine" => "Department of Medicine", "Women's and Children's Health" => "Department of Women's and Children's Health", "Biomedical Science" => "Department of Biomedical Science", "Population Health & Social Medicine" => "Department of Population Health & Social Medicine", "Clinical Neurosciences" => "Department of Clinical Neurosciences", ]; // Create an array to hold valid department names $validDepartments = []; $specialDeptEmployees = []; // This array will contain employees with their original data $regularDeptEmployees = []; $processedEmployees = []; $employeesInJsonStaff = []; // Keywords for sorting $keywordSort = array( "Senior Associate Dean" => 1, "Chief Operating Officer" => 2, "Senior Executive Director" => 3, "Interim Senior Executive Director" => 4, "Executive Director" => 5, "Senior Director" => 6, "Director of Admissions" => 7, "Director " => 8, "Director," => 9, "Director of " => 10, "Practice Director" => 11, "Associate Director " => 12, "Associate Director, " => 13, "Associate Director of" => 14, "Assistant Director " => 15, "Assistant Director of " => 16, "Assistant Director, Clinical Department Administration" => 17, "Assistant Director," => 18, "Graduate Medical Education Institutional Program Manager" => 19, "Administrative Specialist" => 20, "Senior Residency Program Manager" => 21, "Residency Program Manager" => 22, "Program Manager" => 23, "Manager" => 24, "Nurse Navigator" => 25, "Senior" => 26, "Systems Administrator" => 27, "Longitudinal Integrated Clerkship Administrator" => 28, "Program Evaluation Coordinator" => 29, "Associate Librarian, Senior Medical Librarian" => 30 ); // Function to get the sorting weight based on keywords function getSortWeight($title, $keywordSort) { foreach ($keywordSort as $keyword => $weight) { // Adjust pattern to handle the comma and ensure it matches the beginning of the title $pattern = '/^' . preg_quote($keyword, '/') . '\b/i'; // Case-insensitive match at the start of the title with word boundary if (preg_match($pattern, $title)) { return $weight; } } return PHP_INT_MAX; // If no keyword matches, assign a high weight to sort to the end. } // Iterate through employees and update department names foreach ($files as &$f) { $departments = array_map('trim', explode(', ', $f['department'])); // Split and trim department names by comma // Update department names based on $customDepartmentNames $departments = array_map(function ($department) use ($customDepartmentNames) { return isset($customDepartmentNames[$department]) ? $customDepartmentNames[$department] : $department; }, $departments); // Add the updated department names back to the employee's record $f['department'] = implode(', ', $departments); } // Create a mapping of names to additional data from jsonStaff $nameToDataMapping = []; foreach ($jsonStaff as $staffMember) { $staffName = $staffMember['email']; $nameToDataMapping[$staffName] = $staffMember; } // Separate employees based on the special department unset($f); foreach ($files as $f) { $nameCheck = $f['email']; // Check if the data is found in $nameToDataMapping if (isset($nameToDataMapping[$nameCheck])) { $additionalData = $nameToDataMapping[$nameCheck]; // Update $f with additional data if found $f['first_name'] = $additionalData['first_name']; $f['last_name'] = $additionalData['last_name']; $f['phone'] = $additionalData['phone']; $f['title'] = $additionalData['description']; $f['full_name'] = $additionalData['fullname']; $f['url'] = $additionalData['url']; $f['suffix'] = $additionalData['suffix']; // Add this employee to the $employeesInJsonStaff array $employeesInJsonStaff[] = $f; } else { } $departments = explode(', ', $f['department']); // Split department names by comma // Check if the employee has already been processed $alreadyProcessed = false; foreach ($departments as $department) { if ($department === $specialDepartment) { $specialDeptEmployees[] = $f; $alreadyProcessed = true; // Mark as already processed } else { if (!in_array($f, $processedEmployees)) { $regularDeptEmployees[] = $f; $processedEmployees[] = $f; } if (!in_array($department, $validDepartments)) { $validDepartments[] = $department; } } } } // Create an array to hold unmatched employees in the "Other" department $otherDeptEmployees = []; // Iterate through $jsonStaff to include unmatched employees foreach ($jsonStaff as $staffMember) { $staffEmail = $staffMember['email']; $foundInProcessed = false; $foundInSpecialDept = false; $foundInOtherDept = false; // Check if the email exists in processedEmployees foreach ($processedEmployees as $employee) { if ($employee['email'] == $staffEmail) { $foundInProcessed = true; break; // No need to continue checking } } // Check if the email exists in specialDeptEmployees foreach ($specialDeptEmployees as $employee) { if ($employee['email'] == $staffEmail) { $foundInSpecialDept = true; break; // No need to continue checking } } // Check if the email exists in otherDeptEmployees foreach ($otherDeptEmployees as $employee) { if ($employee['email'] == $staffEmail) { $foundInOtherDept = true; break; // No need to continue checking } } if (!$foundInProcessed && !$foundInSpecialDept) { // Include the employee in the "Other" department $additionalData = $staffMember; // Update the department name to "Other" //$additionalData['department'] = $additionalData['department']; // Set title based on your requirements $additionalData['title'] = $staffMember['description']; $otherDeptEmployees[] = $additionalData; } } // Static Employees: Define your static entries $staticEntries = [ [ 'department' => 'Library Services', // Replace with your static department name 'employees' => [ [ 'email' => 'kebam@health.fau.edu', 'full_name' => 'Michelle Keba Knecht, M.S.', 'first_name' => 'Michelle Keba', 'last_name' => 'Knecht', 'title' => 'Associate Librarian, Senior Medical Librarian, Head of the Medical and Health Sciences Collection & User Services Department', 'phone' => '561-297-0689', 'department' => 'Library Services' // Add more fields as needed ], // Add more static employees for this department [ 'email' => 'tfollin@health.fau.edu', 'full_name' => 'Tiffany Follin', 'first_name' => 'Tiffany', 'last_name' => 'Follin', 'title' => 'Medical Liaison and Outreach Librarian', 'phone' => '561-297-3642', 'department' => 'Library Services' // Add more fields as needed ] // Add more static employees for this department ] ] ]; foreach ($staticEntries as $entry) { $departmentName = $entry['department']; $employeesInDepartment = $entry['employees']; // Add employees to the appropriate department arrays foreach ($employeesInDepartment as $employee) { $staticEmployee = [ 'email' => $employee['email'], 'first_name' => $employee['first_name'], 'last_name' => $employee['last_name'], 'title' => $employee['title'], 'full_name' => $employee['full_name'], 'phone' => $employee['phone'], 'department' => $employee['department'] // Add more fields as needed ]; // Check if the department exists in $validDepartments if (!in_array($departmentName, $validDepartments)) { // Add the department to $validDepartments if it doesn't exist $validDepartments[] = $departmentName; } // Add this static employee to the appropriate department array $processedEmployees[] = $staticEmployee; $regularDeptEmployees[] = $staticEmployee; $employeesInJsonStaff[] = $staticEmployee; } } // Sort the valid departments again $validDepartments = array_values(array_unique($validDepartments)); sort($validDepartments); // Filter valid departments to exclude those with no employees in the final output $validDepartmentsWithEmployees = array_filter($validDepartments, function ($department) use ($regularDeptEmployees, $employeesInJsonStaff) { return array_reduce($regularDeptEmployees, function ($carry, $employee) use ($department, $employeesInJsonStaff) { $departments = array_map('trim', explode(', ', $employee['department'])); $pattern = '/^' . preg_quote($department, '/') . '$/i'; $hasEmployee = in_array($department, $departments) || preg_match($pattern, implode(', ', $departments)); $isInJsonStaff = in_array($employee, $employeesInJsonStaff); return $carry || ($hasEmployee && $isInJsonStaff); }, false); }); // Sort employees within the special department using custom sorting usort($specialDeptEmployees, function ($a, $b) use ($keywordSort) { return getSortWeight($a['title'], $keywordSort) - getSortWeight($b['title'], $keywordSort); }); // Sort the $validDepartmentsWithEmployees array based on the custom department logic //usort($validDepartmentsWithEmployees, function ($a, $b) { // return strcmp(customDepartment($a), customDepartment($b)); //}); // Create select to populate valid department names echo '
'; echo ''; echo '
'; // Display employees from the special department first echo "

$specialDepartment

"; echo ''; $dct = 2; // Loop through valid departments and display their employees foreach ($validDepartments as $department) { // Determine which employees should be displayed in this section $filteredEmployeesForSection = array_filter($regularDeptEmployees, function ($employee) use ($department) { global $employeesInJsonStaff; return in_array($employee, $employeesInJsonStaff); }); // Check if any employees from this department exist in the final output $employeesExistInOutput = array_filter($filteredEmployeesForSection, function ($employee) use ($department) { $departments = array_map('trim', explode(', ', $employee['department'])); return in_array($department, $departments); }); // Display the department and its employees if at least one employee exists in the final output if (!empty($employeesExistInOutput) && $department !== "FAU Medicine" && $department !== "Research and Graduate Programs") { echo '

' . $department . '

'; $dct = $dct + 1; echo ''; } } // Display employees from the "Other" department within a comment block echo ""; ?>