Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5b3fbb4
Installed twig-view, and twig by mistake
JonathanPeterCole Jul 14, 2016
31f6eb2
Merge remote-tracking branch 'refs/remotes/origin/develop' into fe-ba…
JonathanPeterCole Jul 19, 2016
5e2c5de
Merge remote-tracking branch 'refs/remotes/origin/develop' into fe-ba…
JonathanPeterCole Jul 19, 2016
b385ce6
Merge pull request #7 from JonathanPeterCole/develop
JonathanPeterCole Jul 19, 2016
81e27d8
added buttons to html files: sample and sample form to link pages tog…
emdunx Jul 19, 2016
06184c9
added update button
emdunx Jul 19, 2016
9e3d372
Merge pull request #9 from JonathanPeterCole/develop
JonathanPeterCole Jul 19, 2016
0bfc862
added inputs on 'sample_form', and altered dashboard formatting
emdunx Jul 19, 2016
607bddb
changed action.php - now can add to database
emdunx Jul 19, 2016
dcf6266
Merge pull request #10 from JonathanPeterCole/develop
JonathanPeterCole Jul 20, 2016
7fa51f6
Merge pull request #11 from JonathanPeterCole/develop
JonathanPeterCole Jul 20, 2016
365e03d
fixed f5 bug
emdunx Jul 20, 2016
f3f0041
Merge pull request #12 from JonathanPeterCole/fe-basic-templating
Toylore Jul 20, 2016
42b5394
Updated a few files to make style slightly more consistent.
Toylore Jul 20, 2016
d2590a2
The tables are now linked with foreign keys.
JonathanPeterCole Jul 20, 2016
63337e2
added CSS to colour code table rows from database
emdunx Jul 20, 2016
bbe2cf2
Added door checks and updated the file directory.
JonathanPeterCole Jul 20, 2016
1d930e1
Merge remote-tracking branch 'refs/remotes/origin/master' into develop
JonathanPeterCole Jul 20, 2016
9895397
Merged some stuff and broke it. Hopefully fixed now.
Toylore Jul 20, 2016
061278d
Merge branch 'develop' of https://github.com/JonathanPeterCole/PADs i…
emdunx Jul 20, 2016
5a5b1e3
added last update time to server
emdunx Jul 20, 2016
59dac3e
Indented some HTML and made the table smaller. Probably broke some st…
Toylore Jul 21, 2016
ac5501f
Merge branch 'fe-basic-templating' of https://github.com/JonathanPete…
emdunx Jul 21, 2016
bc8f10a
tidied up code
emdunx Jul 21, 2016
6c93c7a
created css style sheet
emdunx Jul 21, 2016
da36ac9
Updated to support new post data.
JonathanPeterCole Jul 21, 2016
ccbd285
Readability improvements and added alarm_event.
JonathanPeterCole Jul 21, 2016
b92eaf6
Fixed a a small mistake that caused an error.
JonathanPeterCole Jul 21, 2016
2b6fd47
Added FLEET table to tables_create.php
Toylore Jul 21, 2016
95c2aa2
Added SMS alerts for Fleet.
JonathanPeterCole Jul 21, 2016
8152188
Merge branch 'fe-basic-templating' of https://github.com/JonathanPete…
JonathanPeterCole Jul 21, 2016
4059c63
Updated status_dash.php for the updated database.
JonathanPeterCole Jul 21, 2016
e4d65eb
Merge remote-tracking branch 'refs/remotes/origin/fe-basic-templating…
JonathanPeterCole Jul 21, 2016
5d3094f
Added an API reference and improved error messages.
JonathanPeterCole Jul 21, 2016
e6d09b8
Updated database designs with the new Fleet table.
JonathanPeterCole Jul 21, 2016
3dfb851
Backup of current data.
JonathanPeterCole Jul 21, 2016
bb90b87
Switched to binary.
JonathanPeterCole Jul 21, 2016
63e1557
Fixed create form, (changed SQL query in action.php to add rows to tb…
emdunx Jul 21, 2016
4891a06
Merge branch 'fe-basic-templating' of https://github.com/JonathanPete…
emdunx Jul 21, 2016
f074b7b
It works holy sh*t 😲
JonathanPeterCole Jul 22, 2016
1026fa5
Tidied up code
emdunx Jul 22, 2016
b17620e
Not only does it work, it works well 👌
JonathanPeterCole Jul 22, 2016
da95935
Updated status_dash for the new database design.
JonathanPeterCole Jul 22, 2016
5c458e6
Merge remote-tracking branch 'refs/remotes/origin/fe-basic-templating…
JonathanPeterCole Jul 22, 2016
cabe4fa
improved css formatting + fixed create form bug
emdunx Jul 22, 2016
1d73cf2
fixed cut off time problem
emdunx Jul 22, 2016
f7a36e6
Merge branch 'fe-basic-templating' of https://github.com/JonathanPete…
emdunx Jul 22, 2016
8ac1c2b
Merge remote-tracking branch 'refs/remotes/origin/fe-basic-templating…
JonathanPeterCole Jul 22, 2016
14a606e
Updated the front end to work with the new database.
JonathanPeterCole Jul 22, 2016
3670bb4
Fixed Door Status showing as 'False' instead of 'Closed'.
JonathanPeterCole Jul 22, 2016
e599f3a
Added the temperature column to the front end.
JonathanPeterCole Jul 22, 2016
2c9acf9
Removed the status fields from the Add Defibrilator form.
JonathanPeterCole Jul 22, 2016
678c2bb
Updates some messages.
JonathanPeterCole Jul 22, 2016
a59735d
Removed out of date procedures in the sample database.
JonathanPeterCole Jul 22, 2016
520f8b1
Updated text messages.
JonathanPeterCole Jul 22, 2016
046db85
Final web changes
JonathanPeterCole Jul 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ dashboard.php [QSA,L]

30 changes: 30 additions & 0 deletions web/api/alarm_event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/* This sends a message and array of phone numbers to the send_sms function.
* The message body of the SMS can be changed on line 24. */

if ($old_alarm_status == 0 && $alarm_status == 1) {
// Include the sms file
//require_once 'send_sms.php';

// Get the phone number array
$phone_numbers = array();
$result = mysqli_query($conn,"SELECT * FROM tbl_fleet");
while ($row = mysqli_fetch_array($result)) {
array_push($phone_numbers, $row['phone_number']);
}

// Get the cabinet location
$cabinet_location = "";
$result = mysqli_query($conn,"SELECT * FROM tbl_cabinets WHERE id='".$cabinet_id."'");
while ($row = mysqli_fetch_array($result)) {
$cabinet_location = $row['location'];
}

// Prepare the message
$message = "Defibrillator fault reported by cabinet ".$cabinet_id." at ".$cabinet_location.".";

// Send the message
if (!empty($phone_numbers)) {
send_sms($message, $phone_numbers);
}
}
30 changes: 30 additions & 0 deletions web/api/defib_event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/* This sends a message and array of phone numbers to the send_sms function.
* The message body of the SMS can be changed on line 32. */

if ($old_defib_removed == 0 && $defib_removed == 1) {
// Include the sms file
//require_once 'send_sms.php';

// Get the phone number array for FLEET
$phone_numbers = array();
$result = mysqli_query($conn,"SELECT * FROM tbl_fleet");
while ($row = mysqli_fetch_array($result)) {
array_push($phone_numbers, $row['phone_number']);
}

// Get the cabinet location
$cabinet_location = "";
$result = mysqli_query($conn,"SELECT * FROM tbl_cabinets WHERE id='".$cabinet_id."'");
while ($row = mysqli_fetch_array($result)) {
$cabinet_location = $row['location'];
}

// Prepare the message
$message = "Defibrillator removed from cabinet ".$cabinet_id." at ".$cabinet_location.".";

// Send the message
if (!empty($phone_numbers)) {
send_sms($message, $phone_numbers);
}
}
34 changes: 34 additions & 0 deletions web/api/door_event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/* This sends a message and array of phone numbers to the send_sms function.
* The message body of the SMS can be changed on line 30. */

if ($old_door_open == 0 && $door_open == 1) {
// Include the sms file
//require_once 'send_sms.php';

// Get the phone number array for guardians
$phone_numbers = array();
$result = mysqli_query($conn,"SELECT * FROM tbl_guardians WHERE cabinet_id='".$cabinet_id."'");
while ($row = mysqli_fetch_array($result)) {
array_push($phone_numbers, $row['phone_number']);
}

// Get the phone number array for FLEET
$result = mysqli_query($conn,"SELECT * FROM tbl_fleet");
while ($row = mysqli_fetch_array($result)) {
array_push($phone_numbers, $row['phone_number']);
}

// Get the cabinet location
$cabinet_location = "";
$result = mysqli_query($conn,"SELECT location FROM tbl_cabinets WHERE id='".$cabinet_id."'");
while ($row = mysqli_fetch_array($result)) {
$cabinet_location = $row['location'];
}

// Prepare the message
$message = "Cabinet ".$cabinet_id." at ".$cabinet_location." has been opened.";

// Send the message
send_sms($message, $phone_numbers);
}
67 changes: 67 additions & 0 deletions web/api/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/* API Reference:
* cabinet_id
* door_open (0 = Closed / 1 = Open)
* defib_removed (0 = In Cabinet / 1 = Removed)
* alarm_status (0 = Working / 1 = Fault)
* temp_status (int value of current temperature)*/

// Add dbconnect and Twilio
include_once ('../database/db_connect.php');
require 'send_sms.php';

// JSON Post Method
$data = file_get_contents("php://input");
$data = json_decode($data, true);

// If data was posted, add it to the status table
if (!empty($data['cabinet_id']) && !empty($data['temp_status'])) {

// Get and echo the post data
$cabinet_id = mysqli_real_escape_string($conn, $data['cabinet_id']);
$door_open = mysqli_real_escape_string($conn, $data['door_open']);
$defib_removed = mysqli_real_escape_string($conn, $data['defib_removed']);
$alarm_status = mysqli_real_escape_string($conn, $data['alarm_status']);
$temp_status = mysqli_real_escape_string($conn, $data['temp_status']);

echo "<p>Cabinet ID: ".$cabinet_id;
echo "<br>Door Open: ".(boolval($door_open) ? 'True' : 'False');
echo "<br>Defib Removed: ".(boolval($defib_removed) ? 'True' : 'False');
echo "<br>Defib Fault: ".(boolval($alarm_status) ? 'True' : 'False');
echo "<br>Temp Status: ".$temp_status."°C</p>";

// Declare and set the old status variables
$old_door_open = "";
$old_defib_removed = "";
$old_alarm_status = "";

$result = mysqli_query($conn,"SELECT * FROM tbl_status WHERE cabinet_id='".$cabinet_id."'
ORDER BY last_update DESC LIMIT 1;");
while ($row = mysqli_fetch_array($result)) {
$old_door_open = $row['door_open'];
$old_defib_removed = $row['defib_removed'];
$old_alarm_status = $row['alarm_status'];
}

// Update the status table with the new entries
$sql = "INSERT INTO tbl_status (cabinet_id, door_open, defib_removed, alarm_status, temp_status)
VALUES ('".$cabinet_id."', '".$door_open."', '".$defib_removed."', '".$alarm_status."', '".$temp_status."')";
if (mysqli_query($conn, $sql)) {
echo "<p>Status update complete.<p>";
} else {
echo "<p>Error: " . $sql . "<br>" . mysqli_error($conn) . "</p>";
}

// Run SMS events
include 'door_event.php';
include 'alarm_event.php';
include 'defib_event.php';

} elseif (!empty($data['cabinet_id'])) {
echo "<p>Missing some JSON post data. The status update could not be completed.</p>";
} else {
echo "<p>No cabinet JSON data received.<p>";
}

// Close the database connection
$conn->close();
5 changes: 2 additions & 3 deletions web/events/send_sms.php → web/api/send_sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ function send_sms($body, $phone_numbers)

$client = new Services_Twilio($AccountSid, $AuthToken);

foreach ($phone_numbers as $send_number)
{
foreach ($phone_numbers as $send_number) {
$message = $client->account->messages->create(array(
"From" => "+441671642020", // From a valid Twilio number
"To" => $send_number, // Text this number
"Body" => $body,
"Body" => $body, // Send this message
));
}

Expand Down
149 changes: 87 additions & 62 deletions web/dashboard.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,49 @@
<?php
<?php

use \Psr\Http\Message\ServerRequestInterface as Request;//shortens path to 'request'
use \Psr\Http\Message\ResponseInterface as Response;//^^to 'Response'
require 'vendor/autoload.php';
$app = new \Slim\App();
use \Psr\Http\Message\ServerRequestInterface as Request; //shortens path to 'request'
use \Psr\Http\Message\ResponseInterface as Response; //^^to 'Response'
require 'vendor/autoload.php';
$app = new \Slim\App();

$app->post('/event', function ($request, $response, $args) {
$data = $request->getParsedBody(); //creates array from data posted by user
return $response->write($data["id"]);
$app->post('/event', function ($request, $response, $args) {
$data = $request->getParsedBody(); //creates array from data posted by user
return $response->write($data["id"]);
});

$config['displayErrorDetails'] = true;
$config['addContentLengthHeader'] = false;
$config['displayErrorDetails'] = true;
$config['addContentLengthHeader'] = false;

$config['db']['host'] = "localhost";
$config['db']['user'] = "root";
$config['db']['pass'] = "password";
$config['db']['dbname'] = "pads_db";//login to database
$config['db']['host'] = "localhost";
$config['db']['user'] = "root";
$config['db']['pass'] = "password";
$config['db']['dbname'] = "pads_db"; //login to database

$app = new \Slim\App(["settings" => $config]);
$app = new \Slim\App(["settings" => $config]);

// Get container
$container = $app->getContainer();

// Assign variables holding the server details required to connect
$servername = "localhost";
$username = "root";
$password = "password";
$dbName = "pads_db";
$portNumber = "3306";

// Get container
$container = $app->getContainer();
// Create aconnection using these variables
$conn = mysqli_connect($servername, $username, $password, $dbName, $portNumber);

// Assign variables holding the server details required to connect
$servername = "localhost";
$username = "root";
$password = "password";
$dbName = "pads_db";

// Create aconnection using these variables
$conn = mysqli_connect($servername, $username, $password, $dbName);

// Check that the connection was successful
if (!$conn) {
// If the connection was not successful, echo a connection error and stop the PHP scripts
die("Connection failed: " . mysqli_connect_error());
// Check that the connection was successful
if (!$conn) {
// If the connection was not successful, echo a connection error and stop the PHP scripts
die("Connection failed: " . mysqli_connect_error());
}


$query = mysqli_query($conn, 'SELECT * FROM tbl_cabinet');


//Register component on container
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('./templates', [
// 'cache' => 'home/pi/PADs/web/cache'
//Register component on container
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('./templates', [
//'cache' => 'home/pi/PADs/web/cache'
'cache' => false
]);

Expand All @@ -56,41 +52,70 @@
$container['request']->getUri()
));

return $view;
};
return $view;
};

// Render Twig template in route
$app->get('/event/{id}', function ($request, $response, $args) {
// Render Twig template in route
$app->get('/event/{id}', function ($request, $response, $args) {

$conn= mysqli_connect("localhost", "root", "password", "pads_db")//creates connection!>
$conn= mysqli_connect("localhost", "root", "password", "pads_db", "3306")//creates connection!>
or die ("Sorry - could not connect to MySQL");

$result = mysqli_query($conn, 'SELECT * FROM tbl_cabinet'); //takes everything from tbl_cabinet, assigns to value $query!>

$tplArray = array();
$query = "SELECT cabs.id, cabs.location, cabs.postcode, SUBTIME(CURRENT_TIMESTAMP(),'1:02:00') cut_off_time,
COALESCE(
(SELECT stats.door_open
FROM tbl_status stats
WHERE stats.cabinet_id = cabs.id ORDER BY stats.last_update DESC LIMIT 1) , 'Not available') door_open,
COALESCE(
(SELECT stats.defib_removed
FROM tbl_status stats
WHERE stats.cabinet_id = cabs.id ORDER BY stats.last_update DESC LIMIT 1) , 'Not available') defib_removed,
COALESCE(
(SELECT stats.alarm_status
FROM tbl_status stats
WHERE stats.cabinet_id = cabs.id ORDER BY stats.last_update DESC LIMIT 1) , 'Not available') alarm_status,
COALESCE(
(SELECT stats.temp_status
FROM tbl_status stats
WHERE stats.cabinet_id = cabs.id ORDER BY stats.last_update DESC LIMIT 1) , 'Not available') temp_status,
COALESCE(
(SELECT stats.last_update
FROM tbl_status stats
WHERE stats.cabinet_id = cabs.id ORDER BY stats.last_update DESC LIMIT 1) , 'Not available') last_update
FROM tbl_cabinets cabs
ORDER BY cabs.id ASC";

$result = mysqli_query($conn, $query); //takes everything from tbl_cabinet, assigns to value $query!>

$tplArray = array();
while ( $row = mysqli_fetch_array ( $result ) )
{
$tplArray[] = array (
'id' => $row ['id'],
'name' => $row ['name']
);
$door_open = (boolval($row['door_open']) ? 'Open' : 'Closed');

$temp_status = ($row['temp_status']."°C");

if ($row ['defib_removed'] == 1) {
$defib_status = "Unavailable";
} elseif ($row ['alarm_status'] == 1) {
$defib_status = "Fault";
} else {
$defib_status = "Available";
}
// ------------------------------------------------------------------------
$tplArray[] = array (
'id' => $row ['id'],
'location' => $row ['location'],
'postcode'=>$row['postcode'],//gets fields from 'select *' to pass to html to display + gives data names
'door_status'=>$door_open,
'defib_status'=>$defib_status,
'last_update'=>$row['last_update'],
'cut_off_time'=>$row['cut_off_time'],
'temp_status'=>$temp_status
);
}


return $this->view->render($response, 'sample.html', //calls sample.html
array('cabinets' => $tplArray)); // 'id' => $args['id'] ]);
});

$app->run();

$app->get('/hello/{name}', function($request, $response, $args) {
return $response->write("Hello ".$args['name']);
});

$app->get('/bye/{name}', function($request, $response, $args) {
return $response->write("Bye ".$args['name']);
});



?>
Loading