| 1 | <?php |
| 2 | require('header.php'); |
| 3 | |
| 4 | include('libs/db.php'); |
| 5 | /** |
| 6 | * Let's use an array as the list of tunables. |
| 7 | * Put in a variable the inclusion of this file: |
| 8 | * $config_var = include('config.php'); |
| 9 | */ |
| 10 | $configs = include('config.php'); |
| 11 | |
| 12 | /** |
| 13 | * [session_start start a unique session for the current browser client] |
| 14 | */ |
| 15 | session_start(); |
| 16 | |
| 17 | //$page = filter_input(INPUT_GET, $_GET['page'], FILTER_SANITIZE_URL); |
| 18 | $page = $_GET['page']; |
| 19 | |
| 20 | if (!isset($page)) { |
| 21 | $page = ""; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * [valid_page validate if the current page is a valid site actions] |
| 26 | * @param [string] $page [the viewed page name] |
| 27 | * @return [string] [the valid matching action or the default action |
| 28 | * if the action name do not exist ] |
| 29 | */ |
| 30 | function valid_page($page_name) |
| 31 | { |
| 32 | global $configs; |
| 33 | |
| 34 | foreach ($configs['actions'] as $action) { |
| 35 | if (strcmp($page_name, $action) === 0) { |
| 36 | // The actions list can't have duplicated entries |
| 37 | return $action; |
| 38 | } |
| 39 | } |
| 40 | // Return the default action |
| 41 | return $configs['actions'][0]; |
| 42 | } |
| 43 | |
| 44 | function display_action($action_name) |
| 45 | { |
| 46 | global $configs; |
| 47 | |
| 48 | $found_action = false; |
| 49 | foreach ($configs['actions'] as $action) { |
| 50 | if (strcmp($action_name, $action) === 0) { |
| 51 | include("$action.php"); |
| 52 | $found_action = true; |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | if (!$found_action) { |
| 57 | echo "Action to display do not exist"; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | $action = valid_page($page); |
| 62 | display_action($action); |
| 63 | |
| 64 | session_destroy(); |
| 65 | |
| 66 | require('footer.html'); |
| 67 | ?> |