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 function get_action_type() {
26 global $is_page, $is_form;
28 if ($is_page && !$is_form && is_get_request()) {
30 } elseif ($is_form && !$is_page && is_post_request()) {
32 } elseif (!$is_page && !$is_form && is_get_request()){
39 function get_url_action($action_type) {
42 if ($action_type === "page") {
44 } elseif ($action_type === "form") {
46 } elseif ($action_type === "empty") {
48 } elseif ($action_type === "unknown") {
49 die('Cannot get a valid action from URL parameters or form fields.');
54 * [validate_url_action validate if the current page is a valid site actions]
55 * @param [string] $page [the viewed page name]
56 * @return [string] [the valid matching action or the default action
57 * if the action name do not exist ]
59 function validate_url_action($action_name)
63 foreach ($configs['actions'] as $action) {
64 if (strcmp($action_name, $action) === 0) {
65 // The actions list can't have duplicated entries
69 // Return the default action
70 return $configs['actions'][0];
73 function display_action($action_name, $action_type)
76 $includes_rpath = 'includes';
78 $found_action = false;
79 foreach ($configs['actions'] as $action) {
80 if (strcmp($action_name, $action) === 0) {
82 if ($action_type === "page" ||
$action_type === "empty") {
83 include($includes_rpath . "/" . $action . ".php");
85 } elseif ($action_type === "form") {
86 include($includes_rpath . "/form" . $action . ".php");
88 echo "Unknown error in action displaying. <br>";
95 echo "Action to display do not exist. <br>";
99 $action_type = get_action_type();
100 $url_action = get_url_action($action_type);
101 $action = validate_url_action($url_action);
102 display_action($action, $action_type);
104 $connection->close();
106 session_write_close();
108 require('includes/footer.html');