Initial commit of the HUGo project web application.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 9 Jan 2018 09:21:55 +0000 (10:21 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 9 Jan 2018 09:21:55 +0000 (10:21 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
13 files changed:
account.php [new file with mode: 0644]
booking.php [new file with mode: 0644]
config.php [new file with mode: 0644]
footer.html [new file with mode: 0644]
header.html [new file with mode: 0644]
header.php [new file with mode: 0644]
home.php [new file with mode: 0644]
index.php [new file with mode: 0644]
libs/db.php [new file with mode: 0644]
login.php [new file with mode: 0644]
register.php [new file with mode: 0644]
search.php [new file with mode: 0644]
styles/airpolytech.css [new file with mode: 0644]

diff --git a/account.php b/account.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/booking.php b/booking.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/config.php b/config.php
new file mode 100644 (file)
index 0000000..dd03f8f
--- /dev/null
@@ -0,0 +1,25 @@
+ <?php
+
+ return array(
+     'host' => 'localhost',
+     'username' => 'fraggle',
+     'password' => '$Love79!',
+     'database' => 'bdVols',
+     'actions' => array (
+         'home',
+         'login',
+         'register',
+         'booking',
+         'search',
+         'account'
+     )
+ );
+
+ /* return array(
+     'host' => $_SERVER['dbHost'],
+     'username' => $_SERVER['dbLogin'],
+     'password' => $_SERVER['dbPass'],
+     'database' => '$_SERVER['dbBd']'
+ ); */
+
+?>
diff --git a/footer.html b/footer.html
new file mode 100644 (file)
index 0000000..70960fb
--- /dev/null
@@ -0,0 +1,5 @@
+<div id="footer">
+    &copy;2018 - Piment Noir
+</div>
+</body>
+</html>
diff --git a/header.html b/header.html
new file mode 100644 (file)
index 0000000..8e523a2
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>Air Polytech</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<link href="https://fonts.googleapis.com/css?family=Encode+Sans+Semi+Condensed" rel="stylesheet">
+<link rel="stylesheet" type="text/css" href="styles/airpolytech.css" />
+</head>
+<body>
+<div id="header">
+    <!-- Put headers stuff here -->
+    Bienvenue sur Air Polytech !
+</div>
diff --git a/header.php b/header.php
new file mode 100644 (file)
index 0000000..e81db37
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+include('header.html');
+function display_menu() {
+    switch ($page) {
+        case "home":
+        break;
+        case "register":
+        break;
+    }
+
+}
+?>
diff --git a/home.php b/home.php
new file mode 100644 (file)
index 0000000..5499ba9
--- /dev/null
+++ b/home.php
@@ -0,0 +1,25 @@
+<?php
+function home()
+{
+    global $configs;
+
+    $connection = new CustomDB($configs['host'], $configs['username'], $configs['password'], $configs['database']);
+    $requete = "SELECT NumCl, NomCl, CodePosteCl, VilleCl FROM CLIENTS";
+    $result = $connection->query($requete);
+    echo "<table border=1>\n";
+    echo "<tr><td>Code_CL</td><td>Nom</td><td>Rue</td><td>Ville</td></tr>\n";
+    while ($ligne = $result->fetch_row()) {
+        $code = htmlentities($ligne[0]);
+        $nom = htmlentities($ligne[1]);
+        $rue = htmlentities($ligne[2]);
+        $ville = htmlentities($ligne[3]);
+        echo "<tr><td>$code</td><td>$nom</td><td>$rue</td><td>$ville</td></tr>\n";
+    }
+    echo "</table>\n";
+    $result->close();
+    $connection->close();
+}
+
+home();
+
+?>
diff --git a/index.php b/index.php
new file mode 100644 (file)
index 0000000..01b3ce3
--- /dev/null
+++ b/index.php
@@ -0,0 +1,61 @@
+<?php
+require('header.php');
+
+include('libs/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');
+
+/**
+ * [session_start start a unique session for the current browser client]
+ */
+session_start();
+
+if (!isset($page)) {
+    $page = "";
+}
+
+/**
+ * [valid_page validate if the current page is a valid site actions]
+ * @param  [string] $page [the viewed page name]
+ * @return [string]       [the valid matching action or the default action
+ *                         if the action name do not exist ]
+ */
+function valid_page($page_name)
+{
+    global $configs;
+
+    foreach ($configs['actions'] as $action) {
+        if ($page_name === $action) {
+            return $action;
+            // The actions list can't have duplicated entries
+            break;
+        } else {
+            return $configs['actions'][0];
+        }
+    }
+}
+
+function display_action($action_name)
+{
+    global $configs;
+
+    foreach ($configs['actions'] as $action) {
+        if ($action_name === $action) {
+            include("$action.php");
+            break;
+        } else {
+            echo "Action to display do not exist";
+        }
+    }
+}
+
+display_action(valid_page($page));
+
+session_destroy();
+
+require('footer.html');
+?>
diff --git a/libs/db.php b/libs/db.php
new file mode 100644 (file)
index 0000000..0f280a4
--- /dev/null
@@ -0,0 +1,116 @@
+<?php
+
+/**
+ * [CustomDB description]
+ */
+class CustomDB
+{
+    private $connection;
+    public $connected;
+    private $current_pquery;
+    private $current_stmt;
+
+    /**
+     * [__construct description]
+     * @param [type] $host     [description]
+     * @param [type] $username [description]
+     * @param [type] $password [description]
+     * @param [type] $dbname   [description]
+     */
+    public function __construct($host, $username, $password, $dbname)
+    {
+        $connection = new mysqli($host, $username, $password, $dbname);
+        $this->connection = $connection;
+
+        if (!$this->connection->connect_errno) {
+            $this->connected = true;
+        } else {
+            die('Fail to connect to the RDBMS');
+        }
+
+        return $this->connection;
+    }
+
+    /**
+     * [close description]
+     * @return [type] [description]
+     */
+    public function close()
+    {
+        if ($this->connected && $this->connection->close()) {
+            $this->connected = false;
+        } else {
+            die('Fail to close the connection to the RDBMS');
+        }
+    }
+
+    /**
+     * [query description]
+     * @param  [type] $sql_query [description]
+     * @return [type]            [description]
+     */
+    public function query($sql_query)
+    {
+        if ($this->connected && !($query_result = $this->connection->query($sql_query))) {
+            echo "Fail to execute the SQL query : " . $sql_query;
+        }
+        return $query_result;
+    }
+
+    /**
+     * [prepare_query description]
+     * @param  [type] $prepared_query [description]
+     * @return [type]                 [description]
+     */
+    public function prepare_query($prepared_query)
+    {
+        $this->current_pquery = $prepared_query;
+        if ($this->connected && !($this->current_stmt = $this->connection->prepare($this->current_pquery))) {
+            // Empty the currently stored prepared query in the failure case
+            $this->current_pquery = "";
+            echo "Fail to prepare SQL query : (" . $this->connection->errno . ") " . $this->connection->error . " - " . $this->current_pquery;
+        }
+        return $this->current_stmt;
+    }
+
+    /**
+     * [prepared_query_bind_param description]
+     * @param  [type] $params [description]
+     * @return [type]         [description]
+     */
+    public function prepared_query_bind_param(...$params)
+    {
+        $rt_val = $this->current_stmt->bind_param($params);
+        if (!$rt_val) {
+            echo "Fail to link parameters to SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery;
+        }
+        return $rt_val;
+    }
+
+    /**
+     * [run_prepared_query description]
+     * @return [type] [description]
+     */
+    public function run_prepared_query()
+    {
+        $rt_val = $this->current_stmt->execute();
+        if (!$rt_val) {
+            echo "Fail to execute SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery;
+        }
+        return $rt_val;
+    }
+
+    /**
+     * [close_prepared_query description]
+     * @return [type] [description]
+     */
+    public function close_prepared_query()
+    {
+        $rt_val = $this->current_stmt->close();
+        if (!$rt_val) {
+            echo "Fail to close SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery;
+        }
+        return $rt_val;
+    }
+}
+?>
diff --git a/login.php b/login.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/register.php b/register.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/search.php b/search.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/styles/airpolytech.css b/styles/airpolytech.css
new file mode 100644 (file)
index 0000000..3093507
--- /dev/null
@@ -0,0 +1,16 @@
+body {
+    background-color: black;
+    color: #eeeeee;
+    font-family: 'Encode Sans Semi Condensed', Arial, Helvetica, Verdana, sans-serif;
+    display: block;
+    margin: 8px;
+}
+
+#footer {
+    text-align: center;
+}
+
+#header {
+    font-size: 44px;
+    text-align: center;
+}