require('header.php');
include('lib/db.php');
-/**
- * Let's use an array as the list of tunables.
- * Put in a variable the inclusion of this file:
- * $config_var = include('config.php');
- */
-$configs = include('config.php');
+include('lib/utils.php');
/**
* [session_start start a unique session for the current browser client]
$page = "";
}
+/**
+ * form MUST have an hidden field named 'form' to enable proper routing
+ */
$form = filter_input(INPUT_POST, 'form', FILTER_SANITIZE_URL);
$isForm = true;
if (!isset($form)) {
$form = "";
}
+function get_action_type() {
+ global $isPage, $isForm;
+
+ if ($isPage && !$isForm && is_get_request()) {
+ return "page";
+ } elseif ($isForm && !$isPage && is_post_request()) {
+ return "form";
+ } elseif (!$isPage && !$isForm && is_get_request()){
+ return "empty";
+ } else {
+ return "unknown";
+ }
+}
+
+function get_url_action() {
+ global $page, $form;
+
+ if (get_action_type() === "page") {
+ return $page;
+ } elseif (get_action_type() === "form") {
+ return $form;
+ } elseif (get_action_type() === "empty") {
+ return "";
+ } elseif (get_action_type() === "unknown") {
+ die('Cannot get a valid action from URL parameters');
+ }
+}
+
/**
* [validate_url_action validate if the current page is a valid site actions]
* @param [string] $page [the viewed page name]
return $configs['actions'][0];
}
-function get_action_type() {
- global $page, $form, $isPage, $isForm;
-
- if ($isPage && !$isForm) {
- return "page";
- } elseif ($isForm && !$isPage) {
- return "form";
- } elseif (!$isPage && !$isForm){
- return "empty";
- } else {
- return "unknown";
- }
-}
-
function display_action($action_name)
{
global $configs, $isPage, $isForm;
$found_action = false;
foreach ($configs['actions'] as $action) {
if (strcmp($action_name, $action) === 0) {
+ // HTTP GET case
if (get_action_type() === "page" || get_action_type() === "empty") {
include($action . ".php");
+ // HTTP POST case
} elseif (get_action_type() === "form") {
include("form" . $action . ".php");
} else {
- echo "Impossible error";
+ echo "Unknown error in action displaying";
}
$found_action = true;
break;
}
}
-function get_url_action() {
- global $page, $form, $isPage, $isForm;
-
- if (get_action_type() === "page") {
- return $page;
- } elseif (get_action_type() === "form") {
- return $form;
- } elseif (get_action_type() === "empty") {
- return "";
- } elseif (get_action_type() === "unknown") {
- die('Cannot get a valid action from URL parameters');
- }
-}
-
$url_action = get_url_action();
$action = validate_url_action($url_action);
display_action($action);