Some random red flags:
- There's a class with the name of the application. (Issues: Scope, SRP)
- There's a class with 1708 lines of code. (Scope)
- There's a switch-case statement that runs over 150 LOC (readability, maintainability)
- There's a string parsing function in the same class as transaction processing (Separation of concerns)
- There are segments of code commented out (are they not using source control?)
- There's inlined SQL (maintainability, security)
- There's JSON being generated manually & inline (SoC, DRY)
- There's XML being generated manually & inline (SoC, DRY)
- To sum up function _Route_getStats($path): XML production, JSON production, file writing, business logic, SQL commands, HTTP header fiddling, hard coded paging limits, multiple exit points...
The amount of refactoring needed here to bring this code up to acceptable quality is simply staggering.