2 require('includes/header.php');
6 $connection = new CustomDB($configs['host'], $configs['username'], $configs['password'], $configs['database']);
8 $page = filter_input(INPUT_GET
, 'page', FILTER_SANITIZE_URL
);
16 * form MUST have an hidden field named 'form' to enable proper routing
18 $form = filter_input(INPUT_POST
, 'form', FILTER_SANITIZE_URL
);
25 //var_dump($_SESSION);
27 function get_action_type() {
28 global $is_page, $is_form;
30 if ($is_page && !$is_form && is_get_request()) {
32 } elseif ($is_form && !$is_page && is_post_request()) {
34 } elseif (!$is_page && !$is_form && is_get_request()){
41 function get_url_action($action_type) {
44 if ($action_type === "page") {
46 } elseif ($action_type === "form") {
48 } elseif ($action_type === "empty") {
50 } elseif ($action_type === "unknown") {
51 die('Cannot get a valid action from URL parameters or form fields.');
56 * [validate_url_action validate if the current page is a valid site actions]
57 * @param [string] $page [the viewed page name]
58 * @return [string] [the valid matching action or the default action
59 * if the action name do not exist ]
61 function validate_url_action($action_name)
65 foreach ($configs['actions'] as $action) {
66 if (strcmp($action_name, $action) === 0) {
67 // The actions list can't have duplicated entries
71 // Return the default action
72 return $configs['actions'][0];
75 function display_action($action_name, $action_type)
78 $includes_rpath = 'includes';
80 $found_action = false;
81 foreach ($configs['actions'] as $action) {
82 if (strcmp($action_name, $action) === 0) {
84 if ($action_type === "page" ||
$action_type === "empty") {
85 include($includes_rpath . "/" . $action . ".php");
87 } elseif ($action_type === "form") {
88 include($includes_rpath . "/form" . $action . ".php");
90 echo "Unknown error in action displaying. <br>";
97 echo "Action to display do not exist. <br>";
101 $action_type = get_action_type();
102 $url_action = get_url_action($action_type);
103 $action = validate_url_action($url_action);
104 display_action($action, $action_type);
106 $connection->close();
108 session_write_close();
110 require('includes/footer.html');