2 require('includes/header.php');
5 include('lib/utils.php');
8 * [session_start start a unique session for the current browser client]
12 $connection = new CustomDB($configs['host'], $configs['username'], $configs['password'], $configs['database']);
14 $page = filter_input(INPUT_GET
, 'page', FILTER_SANITIZE_URL
);
22 * form MUST have an hidden field named 'form' to enable proper routing
24 $form = filter_input(INPUT_POST
, 'form', FILTER_SANITIZE_URL
);
31 function get_action_type() {
32 global $isPage, $isForm;
34 if ($isPage && !$isForm && is_get_request()) {
36 } elseif ($isForm && !$isPage && is_post_request()) {
38 } elseif (!$isPage && !$isForm && is_get_request()){
45 function get_url_action($action_type) {
48 if ($action_type === "page") {
50 } elseif ($action_type === "form") {
52 } elseif ($action_type === "empty") {
54 } elseif ($action_type === "unknown") {
55 die('Cannot get a valid action from URL parameters or form fields');
60 * [validate_url_action validate if the current page is a valid site actions]
61 * @param [string] $page [the viewed page name]
62 * @return [string] [the valid matching action or the default action
63 * if the action name do not exist ]
65 function validate_url_action($action_name)
69 foreach ($configs['actions'] as $action) {
70 if (strcmp($action_name, $action) === 0) {
71 // The actions list can't have duplicated entries
75 // Return the default action
76 return $configs['actions'][0];
79 function display_action($action_name, $action_type)
82 $includes_rpath = 'includes';
84 $found_action = false;
85 foreach ($configs['actions'] as $action) {
86 if (strcmp($action_name, $action) === 0) {
88 if ($action_type === "page" ||
$action_type === "empty") {
89 include($includes_rpath . "/" . $action . ".php");
91 } elseif ($action_type === "form") {
92 include($includes_rpath . "/form" . $action . ".php");
94 echo "Unknown error in action displaying <br>";
100 if (!$found_action) {
101 echo "Action to display do not exist <br>";
105 //password_hash('12345678', PASSWORD_DEFAULT);
107 $action_type = get_action_type();
108 $url_action = get_url_action($action_type);
109 $action = validate_url_action($url_action);
110 display_action($action, $action_type);
112 $connection->close();
116 require('includes/footer.html');