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 here
18 $form = filter_input(INPUT_POST
, 'form', FILTER_SANITIZE_URL
);
25 //var_dump($_SESSION);
28 * [get_action_type description]
29 * @return [type] [description]
31 function get_action_type() {
32 global $is_page, $is_form;
34 if ($is_page && !$is_form && is_get_request()) {
36 } elseif ($is_form && !$is_page && is_post_request()) {
38 } elseif (!$is_page && !$is_form && is_get_request()){
46 * [get_url_action description]
47 * @param [type] $action_type [description]
48 * @return [type] [description]
50 function get_url_action($action_type) {
53 if ($action_type === "page") {
55 } elseif ($action_type === "form") {
57 } elseif ($action_type === "empty") {
59 } elseif ($action_type === "unknown") {
60 die('Cannot get a valid action from URL parameters or form fields.');
65 * [validate_url_action validate if the current page is a valid site actions]
66 * @param [string] $page [the viewed page name]
67 * @return [string] [the valid matching action or the default action
68 * if the action name do not exist ]
70 function validate_url_action($action_name)
74 foreach ($configs['actions'] as $action) {
75 if (strcmp($action_name, $action) === 0) {
76 // The actions list can't have duplicated entries
80 // Return the default action
81 return $configs['actions'][0];
85 * [display_action description]
86 * @param [type] $action_name [description]
87 * @param [type] $action_type [description]
88 * @return [type] [description]
90 function display_action($action_name, $action_type)
93 $includes_rpath = 'includes';
95 $found_action = false;
96 foreach ($configs['actions'] as $action) {
97 if (strcmp($action_name, $action) === 0) {
99 if ($action_type === "page" ||
$action_type === "empty") {
100 include($includes_rpath . "/" . $action . ".php");
102 } elseif ($action_type === "form") {
103 include($includes_rpath . "/form" . $action . ".php");
105 echo "Unknown error in action displaying. <br>";
107 $found_action = true;
111 if (!$found_action) {
112 echo "Action to display do not exist. <br>";
116 $action_type = get_action_type();
117 $url_action = get_url_action($action_type);
118 $action = validate_url_action($url_action);
119 display_action($action, $action_type);
121 $connection->close();
123 session_write_close();
125 require('includes/footer.html');