separated mode codes in to own files

The PHP code for different modes has been separated
in to its own files which are then included by index.php.