9d22f3e15361790b8c2fe89561b28cc88ebd0cf2
5 include('lib/utils.php');
8 * [session_start start a unique session for the current browser client]
12 $page = filter_input(INPUT_GET
, 'page', FILTER_SANITIZE_URL
);
20 * form MUST have an hidden field named 'form' to enable proper routing
22 $form = filter_input(INPUT_POST
, 'form', FILTER_SANITIZE_URL
);
29 function get_action_type() {
30 global $isPage, $isForm;
32 if ($isPage && !$isForm && is_get_request()) {
34 } elseif ($isForm && !$isPage && is_post_request()) {
36 } elseif (!$isPage && !$isForm && is_get_request()){
43 function get_url_action() {
46 if (get_action_type() === "page") {
48 } elseif (get_action_type() === "form") {
50 } elseif (get_action_type() === "empty") {
52 } elseif (get_action_type() === "unknown") {
53 die('Cannot get a valid action from URL parameters');
58 * [validate_url_action validate if the current page is a valid site actions]
59 * @param [string] $page [the viewed page name]
60 * @return [string] [the valid matching action or the default action
61 * if the action name do not exist ]
63 function validate_url_action($action_name)
67 foreach ($configs['actions'] as $action) {
68 if (strcmp($action_name, $action) === 0) {
69 // The actions list can't have duplicated entries
73 // Return the default action
74 return $configs['actions'][0];
77 function display_action($action_name)
79 global $configs, $isPage, $isForm;
81 $found_action = false;
82 foreach ($configs['actions'] as $action) {
83 if (strcmp($action_name, $action) === 0) {
85 if (get_action_type() === "page" ||
get_action_type() === "empty") {
86 include($action . ".php");
88 } elseif (get_action_type() === "form") {
89 include("form" . $action . ".php");
91 echo "Unknown error in action displaying";
98 echo "Action to display do not exist";
102 $url_action = get_url_action();
103 $action = validate_url_action($url_action);
104 display_action($action);
108 require('footer.html');