SlideShare a Scribd company logo
1
eMetro Emergency Medical Services System Documentation
Team: Kevin O’Neil, Jeff Goldberg
Webserver Maintenance & Security Certificate Class Project
Kevi
Abstract
The eMetro Medical Services dispatch system provides 911 operators a graphical drag-n-drop interface
to dispatch patients to a set of hospitals and provides automated publish-subscribe messaging to ER
hospitals using the Mosquitto MQTT message broker. All dispatch events are recorded in a MySQL
database.
December 8, 2015
eMetro Emergency Medical Services System Documentation
Revision History
Creation Date: 12/8/2015
Last Update: 1/12/2016
2
Table of Contents
Table of Contents........................................................................................................................................3
Introduction.................................................................................................................................................5
Requirements..............................................................................................................................................5
Project Requirements..............................................................................................................................5
Extra Requirements Created by Team.....................................................................................................5
System Model..............................................................................................................................................6
eMetro Block Definition Diagram............................................................................................................6
Dispatcher User Interface............................................................................................................................6
Dispatch Report...................................................................................................................................8
Mosquitto MQTT Message Broker...............................................................................................................9
Installing Mosquitto MQTT....................................................................................................................10
Getting Mosquitto Status & Stopping....................................................................................................11
Mosquitto-Clients..................................................................................................................................12
JQuery User Interface................................................................................................................................12
911 Dispatcher Command Center, PHP.....................................................................................................13
File: testdrag6.php.................................................................................................................................13
File: log.php...........................................................................................................................................16
Windows Share Folder...............................................................................................................................17
Mosquitto MQTT Setup.............................................................................................................................22
Mosquitto Subscriber............................................................................................................................24
Mosquitto Publish..................................................................................................................................24
MQTT Utility (Java)................................................................................................................................25
Database Tools: phpMyAdmin...................................................................................................................28
emetromedical Database...........................................................................................................................29
Dispatch Table.......................................................................................................................................30
Hospital Table........................................................................................................................................31
Database Export....................................................................................................................................31
Database Join.........................................................................................................................................35
Table structure for table hospital..........................................................................................................35
Data Dump for Table Hospital................................................................................................................36
3
Simple Join of Dispatch and Hospital Tables..........................................................................................36
Join Results............................................................................................................................................36
Join Dispatch and Hospital Tables SQL with Added Dispatch DateTimeStamp......................................37
Join Results with Dispatch DateTimeStamp...........................................................................................37
Inner Join Version PHP Code..................................................................................................................37
Online Report Result..............................................................................................................................38
Socket.io....................................................................................................................................................39
Jquery........................................................................................................................................................39
Nodejs server.........................................................................................................................................40
4
Introduction
The eMetro Medical services dispatch screen displays the patient icon representing the patient to be
transported. The 911 dispatcher drags the patient icon to one of the hospital emergency room drop icon
spaces. When the drag patient icon is dragged and dropped on the hospital icon the database is updated
with the dispatch event date, time, patient ID and hospital ID.
Requirements
Project Requirements
ID P-R 1 System must demonstrate use of a web browser interface.
ID P-R 2 System must demonstrate use of PHP.
ID P-R 3 System must demonstrate use of HTML.
ID P-R 4 System must demonstrate use of the Apache Web Server.
ID P-R 5 System must demonstrate use of shell scripting.
ID P-R 6 System must demonstrate use of a database.
ID P-R 7 System must demonstrate use of Linux and Windows share folder.
ID P-R 8 System must demonstrate use of a SQL join query.
Extra Requirements Created by Team
ID P-R 9 System must be able to support 911 operators sending reliable dispatch messages to subscriber
hospitals using MQTT Broker.
ID P-R 10 System must be able to support subscription by hospitals using a MQTT Client.
ID P-R 11 System must be able to show live MQTT Broker monitoring.
ID P-R 12 System must utilize drag-and-drop for ease-of-use user interface (jQuery UI).
ID P-R 13 System must automatically update database when a drag-and-drop action is taken by 911
operator.
ID P-R 14 System must support MQTT Client access to MQTT Broker (Socket.io, Nodejs).
ID P-R 15 System must demonstrate use of Nodejs.
ID P-R 16 System must demonstrate use of Bootstrap Framework.
ID P-R 17 System must demonstrate use of database reporting.
5
ID P-R 18 System must demonstrate use of JSON Callback for database detail.
System Model
eMetro Block Definition Diagram
The eMetro block definition diagram (bdd) below captures the major system components and
stakeholders.
Dispatcher User Interface
The eMetro Medical services dispatch screen displays the patient icon representing the patient to be
transported. The 911 dispatcher drags the patient icon to one of the hospital emergency room drop icon
spaces. When the drag patient icon is dragged and dropped on the hospital icon the database is updated
with the dispatch event date, time, patient ID and hospital ID.
6
When the patient icon is dragged to the hospital icon rectangle the database is updated with dispatch
information and a MQTT command is executed triggering the MQTT message broker to send a message
that the patient has been dispatched, see subscriber window below.
7
Dispatch Report
Pressing “Dispatch Report” button generates a report that is the result of a join between ‘hospital’ and
‘dispatch’ tables to produce a report of 911 operator patient date-time stamped dispatches to which
hospitals.
8
Mosquitto MQTT Message Broker
When the 911 dispatcher drags the patient icon to one of the available ER rooms a message is created
and published to the subscribing ER room. This is depicted in the terminal window for the subscriber
below.
9
Installing Mosquitto MQTT
Mosquitto MQTT is a message broker that supports version 3.1 and 3.1.1 of the MQTT protocol.
http://mosquitto.org
MQTT provides a method of carrying out messaging using a publish/subscribe model. It is lightweight,
both in terms of bandwidth usage and ease of implementation. This makes it particularly useful at the
edge of the network where a sensor or other simple device may be implemented using an arduino for
example.
Install commands:
sudo apt-get install mosquitto
sudo apt-get install mosquito-clients
One recommended install instructions from stackoverflow.
http://stackoverflow.com/questions/27534953/how-do-i-set-up-my-own-mqtt-server-with-mosquitto
sudo apt-get update
sudo apt-get install mosquitto
sudo update-rc.d mosquitto defaults
10
sudo /etc/init.d/mosquitto start
Getting Mosquitto Status & Stopping
sudo /etc/init.d/mosquitto status
sudo /etc/init.d/mosquitto stop
11
Mosquitto-Clients
This is two MQTT version 3.1 command line clients. mosquitto_pub can be used to publish messages to
a broker and mosquitto_sub can be used to subscribe to a topic to receive messages.
JQuery User Interface
The jquery user interface library (jquery-ui.js and other components) is used to support drag and drop
user interface functionality. You can download from jqueryui.com.
http://jqueryui.com/draggable/
12
911 Dispatcher Command Center, PHP
File: testdrag6.php
Functions are to create a 911 drag-n-drop user interface displaying a patient icon and available hospital
emergency rooms. The 911 operator can then drag a patient icon onto a hospital icon and create a
dispatch order and message informing the hospital ER that a patient is being dispatched to their
hospital.
<?php
/**
* Created by PhpStorm.
* User: user01
* Date: 10/29/2015
* Time: 9:15 PM
*/
session_start();
require_once('/var/www/config.php');
function query_db($query){
//need: host, user, password, database
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging error: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
//run the actual query
$result = $link->query($query);
mysqli_close($link);
13
return $result;
}//end function query_db
//DO NOT TOUCH ABOVE THIS LINE - GENERAL DB FUNCTIONS
//START WEB PAGE
?>
<script src="lib/jquery-2.1.4.min.js"></script>
<script>
$( document ).ready(function() {//DOCUMENT IS FULLY LOADED ON CLIENT (BROWSER)
$( "#draggable" ).click(function() {//CHECK FOR CLICK EVENT ON ID
// $.post( "log.php", { ad: "1", action: "1", patientid: "1" } )
// .done(function( data ) {
// alert( "Data Loaded: " + data );
});
});
/* $( "#ad1" ).mouseout(function() {//CHECK FOR HOVER EVENT ON ID
$.post( "log.php", { ad: "1", action: "3" } )
.done(function( data ) {
// alert( "Data Loaded: " + data );
});
});
$( "#ad1" ).mouseover(function() {//CHECK FOR HOVER EVENT ON ID
$.post( "log.php", { ad: "1", action: "2" } )
.done(function( data ) {
// alert( "Data Loaded: " + data );
});
});*/
/* $( "#ad2" ).click(function() {//CHECK FOR CLICK EVENT ON ID
var ad = "2";
$.post( "log.php", { ad: ad, action: "1" } )
.done(function( data ) {
// alert( "Data Loaded: " + data );
});
});
$( "#ad2" ).mouseout(function() {//CHECK FOR HOVER EVENT ON ID
var ad = "2";
$.post( "log.php", { ad: ad, action: "3" } )
.done(function( data ) {
// alert( "Data Loaded: " + data );
});
});
$( "#ad2" ).mouseover(function() {//CHECK FOR HOVER EVENT ON ID
var ad = "2";
$.post( "log.php", { ad: ad, action: "2" } )
.done(function( data ) {
// alert( "Data Loaded: " + data );
});*/
});
// });
</script>
14
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Droppable - Default functionality</title>
<h1> eMetro Emergency Medical Services </h1>
<p>Drag and drop patient icon to one of the hospitals on the right.</p>
<p>Patient will be routed to the emergency room at that hospital.</p>
<a class="btn" href="report.php">
<button class="btn" type="submit">Dispatch Report</button></a>
<!-- <link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">-->
<link rel="stylesheet" href="lib/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<!-- <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>-->
<script src="lib/jquery-ui.js"></script>
<!-- <link rel="stylesheet" href="/resources/demos/style.css">-->
<link rel="stylesheet" href="lib/style.css">
<style>
#draggable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px
10px 10px 0; }
#droppable { width: 300px; height: 500px; padding: 0.5em; float: right; margin:
10px; }
#droppable2 { width: 300px; height: 500px; padding: 0.5em; float: right; margin:
10px; }
</style>
<script>
$(function() {
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Patient routed to Sharp Memorial" );
// Post to database patient routed to Sharp Memorial
$.post( "log.php", { ad: "1", action: "1", hospitalid: "2", patientid: "1" } )
.done(function( data ) {
// alert( "Data Loaded: " + data );
});
}
});
$( "#droppable2" ).droppable({
drop: function( event, ui ) {
$( this )
15
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Patient routed to Sharp Grossmont" );
// Post to database patient routed to Sharp Grossmont
$.post( "log.php", { ad: "1", action: "1", hospitalid: "1", patientid: "1"} )
.done(function( data ) {
// alert( "Data Loaded: " + data );
});
}
});
});
</script>
</head>
<body>
<div id="draggable" class="ui-widget-content">
<img src="ad_repository/pia_picture_w150_h150.png">
<p>Patient K_ONEIL</p>
<p>Assessment: C-spine and internal injuries, auto accident</p>
<p>Current Location: 163 south bound, 1/2 mile south of Balboa Ave. ext</p>
</div>
<div id="droppable" class="ui-widget-header">
<img src="ad_repository/sharp_er.jpg">
<p>No 2: Sharp Memorial Hospital Emergency Room</p>
<br>7901 Frost St, San Diego, CA 92123</br>
<!-- <br>Transfer/Drop here</br>-->
</div>
<div id="droppable2" class="ui-widget-header">
<img src="ad_repository/sharp_grossmont_er.jpg">
<p>No 1: Sharp Grossmont Hospital Emergency Care</p>
<br>5555 Grossmont Center Drive, La Mesa, CA 91942</br>
<!-- <p>Transfer/Drop here</p>-->
</div>
</body>
</html>
File: log.php
Functions are to access emetromedical database and perform dispatch updates. Second function is to
execute a shell command to publish a MQTT message and notify the subscribing hospitals of the patient
dispatches.
<?php
//24-OCT-2015
//file: log.php
session_start();
16
require_once('/var/www/config.php');
function query_db($query){
//need: host, user, password, database
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, "emetromedical");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging error: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
//run the actual query
$result = $link->query($query);
mysqli_close($link);
return $result;
}//end function query_db
//DO NOT TOUCH ABOVE THIS LINE - GENERAL DB FUNCTIONS
$ad = (int)$_POST['ad'];
$action = (int)$_POST['action'];
$hospitalid = (int)$_POST['hospitalid'];
$patientid = (int)$_POST['patientid'];
/*
echo "data stored: ";
echo "ad: ".$ad."<br />";
echo "action:".$action;
*/
$ip=$_SERVER['REMOTE_ADDR'];
// echo "IP address= $ip";
//build query
//action codes: 1=click, 2=mouseover, 3=mouseout
//store: ip, ad, action, timedate
$query = "INSERT INTO dispatch (action, stamp, adid, ipaddr, hospitalid,
patientid) VALUES ('".$action."', now(), '".$ad."', '".$ip."', '".$hospitalid."', '".
$patientid."')";
echo $query;
query_db($query);
$cmd = 'mosquitto_pub -h localhost -t emetro -m /"patient K_ONEIL enroute to: "'.
$hospitalid.'"";';
exec($cmd, $stdout, $stderr);
echo "hi bob";
?>
Windows Share Folder
Instructions
On the Ubuntu server open a terminal window and execute mount command with the root account:
mount -t cifs -o username=ioneil,password=cool //10.103.20.21/share /var/www/html/
17
Must have IP address of Windows machine. You open a command window within Windows.
Execute ‘cmd’ command in Start Window.
18
19
Execute ‘ipconfig’ command.
20
Current IP address for Windows machine is 10.103.26.119.
21
Mosquitto MQTT Setup
Mosquitto MQTT has to be running.
Start Mosquitto by using the ‘mosquitto’ command. This terminal window will show mosquito events
such as when you create a subscriber and publish messages to the broker.
22
23
Mosquitto Subscriber
Open another terminal window with another account besides root.
Execute the ‘mosquitto_sub –h localhost –t emetro’ command. This will subscribe to the topic ‘emetro’
and this terminal window will display messages published to the topic.
Mosquitto Publish
Now execute the publish command: mosquito_pub –h localhost –t emetro –m “hello jeff”
24
As you can see in the prior screen capture the subscriber window has received the “hello jeff” message.
These terminal windows are for subscriber hospitals what will receive MQTT messages when the patient
icon is dropped on the hospital icon.
MQTT Utility (Java)
http://www.eclipse.org/paho/
https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/mqtt-utility/0.4.0/
mqtt-utility-0.4.0.jar is a Java utility for testing MQTT.
Alternatively the Paho Java library jars can be downloaded directly from the following URLs;
https://repo.eclipse.org/content/repositories/paho-releases/ - Official Releases
Execute the Jar file by double clicking on the file.
This executable Java file was stored in the c:/mtn/share/nodejs folder.
25
The 192.168.145.129 address for the Ubuntu server and port 1883 was used to connect to the MQTT
server, see below.
You can create/subscribe to a topic and test sending/publishing messages to the topic with this Java
MQTT utility.
26
Example subject of “emetro” with test message of “hi kevin”
27
Database Tools: phpMyAdmin
MySQL is the database. Log into phpMyAdmin to administrate the database.
28
emetromedical Database
29
Dispatch Table
30
Hospital Table
Database Export
-- phpMyAdmin SQL Dump
-- version 4.4.13.1deb1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 09, 2016 at 09:54 AM
-- Server version: 5.6.27-0ubuntu1
-- PHP Version: 5.6.11-1ubuntu3.1
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
31
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `emetromedical`
--
-- --------------------------------------------------------
--
-- Table structure for table `dispatch`
--
CREATE TABLE IF NOT EXISTS `dispatch` (
`id` int(11) NOT NULL,
`view` datetime NOT NULL,
`click` datetime NOT NULL,
`action` int(11) NOT NULL,
`stamp` datetime NOT NULL,
`adid` int(11) NOT NULL,
`patientid` int(11) NOT NULL,
`hospitalid` int(11) NOT NULL,
`ipaddr` varchar(20) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=251 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `dispatch`
32
--
INSERT INTO `dispatch` (`id`, `view`, `click`, `action`, `stamp`, `adid`, `patientid`, `hospitalid`, `ipaddr`)
VALUES
(237, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-17 20:44:32', 1, 1, 1, '192.168.145.1'),
(238, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-17 20:45:15', 1, 1, 2, '192.168.145.1'),
(239, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-17 20:49:48', 1, 1, 1, '192.168.145.1'),
(240, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-19 17:44:16', 1, 1, 1, '192.168.145.1'),
(241, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 08:39:14', 1, 1, 1, '192.168.145.1'),
(242, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 09:18:54', 1, 1, 2, '192.168.145.1'),
(243, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 13:11:42', 1, 1, 1, '192.168.145.1'),
(244, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 13:57:42', 1, 1, 2, '192.168.145.1'),
(245, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 14:02:54', 1, 1, 1, '192.168.145.1'),
(246, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 14:03:04', 1, 1, 2, '192.168.145.1'),
(247, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-08 21:27:20', 1, 1, 1, '192.168.145.1'),
(248, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-10 17:58:29', 1, 1, 1, '192.168.145.1'),
(249, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-10 17:59:37', 1, 1, 2, '192.168.145.1'),
(250, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2016-01-07 18:46:22', 1, 1, 1, '192.168.145.1');
-- --------------------------------------------------------
--
-- Table structure for table `hospital`
--
CREATE TABLE IF NOT EXISTS `hospital` (
`hospitalid` int(11) NOT NULL,
`name` varchar(40) NOT NULL,
`address1` varchar(30) NOT NULL,
33
`city` varchar(20) NOT NULL,
`zip` int(5) NOT NULL,
`state` varchar(2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `hospital`
--
INSERT INTO `hospital` (`hospitalid`, `name`, `address1`, `city`, `zip`, `state`) VALUES
(1, 'Sharp Grossmont', '5555 Grossmont Center Drive', 'La Mesa', 91942, 'CA'),
(2, 'Sharp Memorial', '7901 Frost Street', 'San Diego', 92123, 'CA'),
(3, 'Scripps Green ', '10666 N. Torrey Pines Rd.', 'La Jolla', 92037, 'CA'),
(4, 'Scripps Memorial Hospital Encinitas', '354 Santa Fe Drive', 'Encinitas', 92024, 'CA'),
(5, 'Scripps Mercy Hospital San Diego', '4077 5th Avenue', 'San Diego', 92103, 'CA');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `dispatch`
--
ALTER TABLE `dispatch`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `hospital`
--
34
ALTER TABLE `hospital`
ADD PRIMARY KEY (`hospitalid`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `dispatch`
--
ALTER TABLE `dispatch`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=251;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Database Join
A second ‘hospital’ table was created to contain hospital address information.
Table structure for table hospital
Column Type Null Default
hospitali
d
int(11) No
name varchar(40) No
address1 varchar(30) No
city varchar(20) No
zip int(5) No
state varchar(2) No
35
Data Dump for Table Hospital
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 91942 CA
2 Sharp Memorial 7901 Frost Street San Diego 92123 CA
3 Scripps Green 10666 N. Torrey Pines Rd. La Jolla 92037 CA
4 Scripps Memorial Hospital Encinitas 354 Santa Fe Drive Encinitas 92024 CA
5 Scripps Mercy Hospital San Diego 4077 5th Avenue San Diego 92103 CA
Simple Join of Dispatch and Hospital Tables
A join between the tables ‘dispatch’ and ‘hospital’:
SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city
FROM dispatch, hospital
WHERE dispatch.hospitalid = hospital.hospitalid
Join Results
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa
2 Sharp Memorial 7901 Frost Street San Diego
2 Sharp Memorial 7901 Frost Street San Diego
2 Sharp Memorial 7901 Frost Street San Diego
2 Sharp Memorial 7901 Frost Street San Diego
2 Sharp Memorial 7901 Frost Street San Diego
36
Join Dispatch and Hospital Tables SQL with Added Dispatch DateTimeStamp
SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city, dispatch.stamp AS Dis
patchDateTimeStamp FROM dispatch, hospitalWHERE dispatch.hospitalid = hospital.hospitalid
Join Results with Dispatch DateTimeStamp
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-11-17 20:44:32
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-11-17 20:49:48
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-11-19 17:44:16
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-05 08:39:14
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-05 13:11:42
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-05 14:02:54
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-08 21:27:20
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-10 17:58:29
1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2016-01-07 18:46:22
2 Sharp Memorial 7901 Frost Street San Diego 2015-11-17 20:45:15
2 Sharp Memorial 7901 Frost Street San Diego 2015-12-05 09:18:54
2 Sharp Memorial 7901 Frost Street San Diego 2015-12-05 13:57:42
2 Sharp Memorial 7901 Frost Street San Diego 2015-12-05 14:03:04
2 Sharp Memorial 7901 Frost Street San Diego 2015-12-10 17:59:37
Inner Join Version PHP Code
<?php
session_start();
require_once('/var/www/config.php');
$records_per_page = 100;
$cur_page = (int)$_GET['cur_page'];
if (!$cur_page || $cur_page == 0){
$cur_page=1;
}
//need: host, user, password, database
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, "emetromedical");
//GET COUNT OF RECORDS
$sql_count = "SELECT count(*) AS COUNT FROM dispatch
37
INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid";
$result1 = $link->query($sql_count);
foreach ($result1 as $row){
$total_records = $row['COUNT'];
}
//join query notes
//SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city,
dispatch.stamp AS DispatchDateTimeStamp
//FROM dispatch, hospital
//WHERE dispatch.hospitalid = hospital.hospitalid
//run the actual query
$sql_query = "SELECT dispatch.hospitalid, hospital.name, hospital.address1,
hospital.city, dispatch.stamp
FROM dispatch
INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid
LIMIT 0,".$records_per_page;
$result = $link->query($sql_query);
//REPORT HEADER
$content = '<table width="100%"><thead><tr>';
$content .= '<td width="20%">ID</td><td width="20%">HospitalName</td><td
width="20%">Address</td><td width="20%">City</td><td
width="20%">DispatchDateTime</td></thead>';
$content .= "<tbody>";
foreach($result as $row){
//COLLECT INFO FROM DB -> ASSIGN TO VARIABLES
$hospitalid = $row['hospitalid'];
$hospitalname = $row['name'];
$address = $row['address1'];
$city = $row['city'];
$dispatchdatetime = $row['stamp'];
//APPEND INFO FROM VARIABLES TO OUTPUT BUFFER/VARIABLE
$content .= "<td>".$hospitalid."</td><td>".$hospitalname."</td><td>".
$address."</td><td>".$city."</td><td>".$dispatchdatetime."</td></tr>";
}
//REPORT FOOTER
$prev_page = $cur_page -1;
$next_page = $cur_page +1;
if ($cur_page > 1){
$pagination = '<a href="report.php?cur_page='.$prev_page.'"><<< Previous</a>';
}
$pagination .= '&nbsp;<a href="report.php?cur_page='.$next_page.'">Next >>></a>';
$pages = ceil($total_records/$records_per_page);
$content .= '<tr><td align="center" colspan=5>'.$pagination.'</td></tr>';
$content .= '<tr><td align="center" colspan=5>Total Pages:'.$pages.'</td></tr>';
$content .= "</tbody></table><hr>";
echo $content;
?>
Online Report Result
38
Socket.io
Download socket.io from:
https://cdn.socket.io/socket.io-1.3.7.js
Load this file into folder on Windows host machine in c:/mtn/share/nodejs folder
socket.io-1.3.7.js
On Ubuntu server load with npm.
Load with “npm install socket.io”.
Jquery
Dowload Jquery from:
http://jquery.com/download/
http://code.jquery.com/jquery-2.1.4.min.js
39
On Windows move this file from the download folder to the mtn/share/nodejs folder.
Nodejs server
On server start nodejs server.
root@ubuntu:/var/www/html/nodejs/server/mqtt2#nodejs server.js
User Registration and Sign in
40
Duplicate Registration
41
Incorrect User ID / Password or Duplicate Sign In
42
Valid Sign In (Administrator jeff01@sdccd.edu)
43
User Signed In
Dispatch Patient to Hospital 2
44
Email Fires Off as a Backup Push Notification
Hospital Receives MOSQUITTO MQTT Message to Terminal
45
Configk.php
(database and other details protected from Internet exposure with placement in
var/www folder) System also uses Config.php (similar without Admin User ID)
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
define("DB_DATABASE", "usersk");
define("DB_USER", "root");
define("DB_HOST", "localhost");
define("DB_PASS", "jeff");
define("PW_SALT", "bwM#2u46x86HR7atksMLe~XJN3jq5D@c#^CmWSB$&VgDvpFhUPd?rKt
%zA9>ZdYT");
$admin = "jeff01@sdccd.edu";
?>
46
rs.php Initial Processing Module
<!DOCTYPE html>
<?php
/**
* File: rs.php
* Jeff Goldberg WSMS
*
* 1/2016
*/
require_once("../config.php");
require_once("rs.html");
session_start();
$email = $_POST['email'];
$pass = $_POST['Password'];
$_SESSION['email'] = $email;
if (isset($email) && $email != "") {
$link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
if ($link->connect_error) {
die(" Error: " . $link->connect_error);
}
47
//encrypted password for compare to db
$salted = (sha1($pass.PW_SALT));
// is user in db and not already logged in?
$sql = 'SELECT * FROM users WHERE email="' . $email . '" AND password="'.$salted.'" AND
created=0;';
$result = $link->query($sql);
$timestamp = date('Y-m-d HH:mm:ss');
$compare = (sha1($password.PW_SALT));
//find user and verify not already signed in
if ($result->num_rows > 0) {
$check_PW = sha1($pass.PW_SALT)
$sql = 'SELECT * FROM users WHERE email="' . $email . '" AND created=0;';
$result = $link->query($sql)->fetch_assoc();
// flag user as signed in
$sql = 'UPDATE users SET created= now() WHERE email="' . $email . '";';
$result = $link->query($sql);
$cmp = `password`;
48
$_SESSION['email'] = $email;
$_POST['email'] = $email;
// invoke testdrag4.php screen
echo "<script
type='text/javascript'>window.top.location='http://localhost/medical/testdrag4.php';</script>"; exit;
} else {
$_POST['email'] = $email;
$_SESSION['email'] = $email;
echo "jeff: ".$_SESSION['email'];
}
?>
signIn.php Similar to rs.php, specific to sign in function(validates data)
49
<!DOCTYPE html>
<?php
/**
* File: signIn.php
* Jeff Goldberg WSMS
*
* 1/2016
*/
require_once("../config.php");
require_once("rs.html");
session_start();
$email = $_POST['email'];
$pass = $_POST['Password'];
$_SESSION['email'] = $email;
if (isset($email) && $email != "") {
$link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
if ($link->connect_error) {
die(" Error: " . $link->connect_error);
50
}
//encrypted password for compare to db
$salted = (sha1($pass.PW_SALT));
// is user in db and not already logged in?
$sql = 'SELECT * FROM users WHERE email="' . $email . '" AND password="'.$salted.'" AND
created=0;';
$result = $link->query($sql);
$timestamp = date('Y-m-d HH:mm:ss');
$compare = (sha1($password.PW_SALT));
//find user and verify not already signed in
if ($result->num_rows > 0) {
$check_PW = sha1($pass.PW_SALT)
$sql = 'SELECT * FROM users WHERE email="' . $email . '" AND created=0;';
$result = $link->query($sql)->fetch_assoc();
// flag user as signed in
$sql = 'UPDATE users SET created= now() WHERE email="' . $email . '";';
$result = $link->query($sql);
$cmp = `password`;
$_SESSION['email'] = $email;
51
$_POST['email'] = $email;
// invoke testdrag.php screen
echo "<script
type='text/javascript'>window.top.location='http://localhost/medical/testdrag4.php';</script>"; exit;
} else {
$_POST['email'] = $email;
$_SESSION['email'] = $email;
echo "jeff: ".$_SESSION['email'];
}
//housekeeping and end session
//$result->close();
//$link->close();
//session_unset();
}
52
?>
<html> <script>
window.alert("Invalid Signin");
</script> </font></html>
rs.html Main HTML Module (uses Bootstrap navbar structure)
<!DOCTYPE html>
<html lang="en">
<head>
<?php session_start(); ?>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come
*after* these tags -->
<title>Response STAT</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Cosmo Theme CSS -->
<link href="spacelab.bootstrap.min.css" rel="stylesheet"
integrity="sha256-IF1P9CSIVOaY4nBb5jATvBGnxMn/4dB9JNTLqdxKN9w= sha512-
UsfHxnPESse3RgYeaoQ7X2yXYSY5f6sB6UT48+F2GhNLqjbPhtwV2WCUQ3eQxeghkbl9PioaTOHNA+T0wN
ki2w=="
53
crossorigin="anonymous">
<!-- Custom styles for this template -->
</head>
<!-- ================ Banner ================ -->
<div class="container under-nav">
<img src="statBanner.jpg" data-toggle="modal" data-target="#outModal" alt="banner"
height="90" width="1140">
</div>
<body style="background-image:url(medical/lib/background.jpg);background-repeat: no-repeat;
background-size: 1400px, 650px, auto;">
<!-- <script src="https://cybermap.kaspersky.com/assets/scripts/widget.js" async defer></script>
****future use -->
<!-- ========== Register modal ========== --><!-- ========== Register modal ========== --><!--
========== Register modal ========== -->
<div class="modal fade" id="registerModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
label="Close"><span
aria-hidden="true">&times;</span></button>
<h1 class="modal-title"><font color="darkblue">Register</h1>
</div>
<div class="modal-body well">
<!-- ================ Form ================ -->
54
<form class="form-horizontal" method="post"
action="registerIndex.php">
<div class="form-group">
<label for="firstName" class="col-sm-4 control-
label">First Name</label>
<div class="col-sm-6">
<input type="text" class="form-control"
name="firstName" id="firstName"
placeholder="First Name"
required autofocus>
</div>
</div>
<div class="form-group">
<label for="lastName" class="col-sm-4 control-
label">Last Name</label>
<div class="col-sm-6">
<input type="text" class="form-control"
name="lastName" id="lastName"
placeholder="Last Name" required>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-4 control-
label">Email</label>
<div class="col-sm-6">
<input type="email" class="form-control"
name="email" placeholder="email" required>
55
</div>
</div>
<div class="form-group">
<label for="Password" class="col-sm-4 control-
label">Password</label>
<div class="col-sm-6">
<input type="password" class="form-control"
name="Password" placeholder="Password"
required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5 col-sm-3">
<button type="submit" class="btn btn-
primary">Register</button>
</div></div>
<div class="form-group">
<div><img src="register.jpg" height="200"
width="585"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div></div></div>
</form>
<!-- /.modal-content -->
</div> </div>
56
<!-- /.modal-dialog -->
</div>
<!-- ========== Log out modal ========= --><!-- ========== Log out modal ========= --><!--
========== Log out modal ========= -->
<div class="modal fade" id="outModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
label="Close"><span
aria-hidden="true">&times;</span></button>
<h1 class="modal-title"><font color="darkblue">Logout</h1></font>
</div>
<div class="modal-body">
<!-- ================ Form ================ -->
<form class="form-horizontal" method="post" action="logout.php"
id="logoutForm">
<div class="form-group">
<label for="email" class="col-sm-4 control-
label"></label>
<!-- <div class="col-sm-4">
<input type="email" class="form-control"
name="email" id="email2" placeholder ="CONFIRM LOGOFF" disabled>
</div> -->
</div>
<div class="form-group">
<div class="col-sm-offset-5">
57
<button type="submit" class="btn btn-
primary">Confirm Logoff</button></br></div>
</div>
<div>
<img src="goodDay.jpg" height="300"
width="560"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div> </form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div></div>
<!-- ========== Batch modal ========= --><!-- ========== Batch modal ========= --><!--
========== Batch modal ========= -->
<div class="modal fade" id="batModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
label="Close"><span
aria-hidden="true">&times;</span></button>
58
<h4 class="modal-title"><font color="darkblue"></h4><h1>Start
Mosquito</h1>
<img src="communication-rules.jpg" height="220" width="568"></div><h4
class="modal-title"><font
color="red">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ems
p;&emsp;<font color="white"> ....</font>Click
</br>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&em
sp;<font color="white">....</font>initiate! </font></h4><h5> </h5><h6></h6> <h5></h5>
<div class="modal-body">
<!-- ================ Form ================ -->
<form class="form-horizontal" method="post" action="batch.php"
id="batForm">
<!--<div class="form-group"> -->
<!-- <label for="email" class="col-sm-4 control-
label">Email</label>
<div class="col-sm-6">
<input type="email" class="form-control"
name="email" value="<?php echo $_SESSION['email'];?>" id="email" disabled>
</div>--><div class="form-group">
<div class="col-sm-offset-5">
<button type="Run" class="btn btn-primary">
<font color="white">Initiate</font></button></br>
<label for="xx" class="col-
sm-4 control-label"><h6><font color="darkblue"> </h6></label></div>
</div>
<div class="form-group">
<label for="command" class="col-sm-3 control-
label"><h6><font color="darkblue"> Admin ONLY => </h6></label>
59
<div class="col-sm-6">
<input type="text" class="form-control"
name="command" id="command" placeholder =" Batch File or Command"</br><font size="2"
color="red">&emsp; <font color="white"> .............</font>NO ENTRY ABOVE</font>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
</div>
</form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- ========== Report modal ========= --><!-- ========== Report modal ========= --><!--
========== Report modal ========= -->
<div class="modal fade" id="reportModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
label="Close"><span
60
aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><font
color="darkblue"></h4><h1>Reporting</h1>
<img src="hr-report.jpg" height="220" width="568"></div><h5>
</h5><h6></h6> <h5></h5>
<div class="modal-body">
<!-- ================ Form ================ -->
<form class="form-horizontal" method="post" action="jreport.php"
id="reportForm">
<div class="form-group">
<div class="col-sm-offset-5">
<button type="Run" class="btn btn-primary">
<font color="white">Dispatch Query</font></button></br></br>
</div>
</div>
</form>
<form class="form-horizontal" method="post"action="kreport.php"
id="reportForm2">
<div class="col-sm-offset-15">
<button type="Run" class="btn btn-primary">
<font color="white">Dispatch Report</font></button></br></br>
</div>
</form>
61
<form class="form-horizontal" method="post" action="ureport.php"
id="reportForm2">
<div class="col-sm-offset-5">
<button type="Run" class="btn btn-primary">
<font color="white">User ID Query</font></button></br></br>
</div>
</form>
<form class="form-horizontal" method="post" action="utreport.php" id="reportForm2">
<div class="col-sm-offset-15">
<button type="Run" class="btn btn-primary">
<font color="white">Logged In Query</font></button></br></br>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
</div>
</form>
</div>
<!-- /.modal-content -->
62
</div>
<!-- /.modal-dialog -->
</div>
<!-- ================ NAV Bar ================ --><!-- ================ NAV Bar
================ --><!-- ================ NAV Bar ================ -->
<!-- ================ NAV Bar ================ --><!-- ================ NAV Bar
================ --><!-- ================ NAV Bar ================ -->
<div class="navbar-wrapper">
<div class="container">
<nav class="navbar navbar-inverse navbar-static-top" id="nav">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-
toggle="collapse" data-target="#navbar"
aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span><span class="icon-
bar"></span>
</button>
<!-- <a class="navbar-brand" href="#">Response STAT</a> -->
<a class="navbar-brand" href="#"><h4></h4</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
63
<li><a href="#" data-toggle="modal" data-
target="#registerModal">Register</a></li>
<li>
<a href="#" id="login" data-toggle="modal"
data-target="#myModal">Sign
In</a>
</li>
<li>
<a href="#" id="logout" data-toggle="modal"
data-target="#outModal"><!--
onclick.= "$.get( 'getemail.php', function( data ) {$('#email').val(data);});$('#email').prop('disabled', true);
$('#email2').val(data);});$('#email2').prop('disabled', true);"--> Logoff</a> </li>
<li><a href="rs.php">Home</a></li><li>
<a href="#" id="bat" data-toggle="modal"
data-
target="#batModal">Skeeter</a> </li>
<li>
<a href="#" id="rpt" data-toggle="modal"
data-
target="#reportModal">Reporting</a> </li>
<!-- <li><a href="batch.php">Batch</a></li> --><a
class="navbar-brand" href="#"><h4><font
color="yellow">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&e
msp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; Emergency
Dispatch </h4></font></span></a>
</ul>
</div>
</div>
</nav>
</div>
64
<!-- ================ Main img ================ --><!-- ================ Main img
================ -->
<div class="container under-nav">
<a id="login" data-toggle="modal" data-target="#myModal"><img
src="jeffstat.jpg"alt="Chopper" height="680" width="1140"></a>
</div>
<!-- ========== Log in modal ========== --><!-- ========== Log in modal ========== --><!--
========== Log in modal ========== -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
label="Close"><span
aria-hidden="true">&times;</span></button>
<h1 class="modal-title"><font color="darkblue">Log in</h1></font>
</div>
<div class="modal-body">
<!-- ================ Form ================ -->
<form class="form-horizontal" method="post" action="signIn.php"
id="loginForm">
<div class="form-group">
<label for="email" class="col-sm-4 control-
label">Email</label>
<div class="col-sm-6">
65
<input type="email" class="form-control"
name="email" id="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="Password" class="col-sm-4 control-
label">Password</label>
<div class="col-sm-6">
<input type="password" class="form-control"
name="Password" id="Password" placeholder="Password"
required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5">
<button type="submit" onclick="var em=$
('#email').val();$('#email2').val(em);" id="jeff" class="btn btn-primary">Sign in</button>
</div>
</div>
<div>
<img src="welcome.jpg" height="200"
width="550"></div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
66
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
</body>
</html>
67
registerIndex.php User Registration (Uses front end edit to prevent SQL Injection
Attacks)
<!DOCTYPE html>
<?php
/**
* registerIndex.php
*
* Jeff Goldberg WSMS 1/2016
*
Register new user
*/
require_once("../config.php");//database config
require_once("rs.html");//Homepage format
session_start();
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$pw = ($_POST['Password']);
/**
* Create a password hash
*
* @param string $password The clear text password
* @param string $salt The salt to use, or null to generate a random one
68
* @param int $N The CPU difficultly (must be a power of 2, > 1)
* @param int $r The memory difficultly
* @param int $p The parallel difficultly
*
* @return string The hashed password
*/
$encrypted = sha1($pw.PW_SALT);
$link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
if ($link->connect_error)
die(" Error: " . $link->connect_error);
// is user already registered in db?
$sql = "SELECT * FROM users WHERE email='" . $email . "'; ";
//register user after verifying all fields entered and not already in db
if ($link->query($sql)->num_rows == 0 && $email != '' && $firstName != '' && $lastName != ''
&& $encrypted != '' ) {
$sql = "INSERT INTO users( username, password, email )
VALUES ( '" .$firstName. "' ,'" . $encrypted . "','" . $email . "' );";
$link->query($sql);
echo("<h1>Registered</h1>");
echo '<script>'; echo 'alert("Registration Successful")'; echo '</script>';
}else{
echo '<label class="text-danger"></label>';
69
echo '<script>'; echo 'alert("Registration Incorrect")'; echo '</script>'; // Not safe:
should
$link->close();
}
?>
</html>
70
logout.php Logout Functionality
<?php
/**
* File: logout.php
*
*/
require_once("../config.php");
require_once("rs.html");
require_once("../scrypt.php");
71
session_start();
print_r($_SESSION);
if ($email !='') {
echo $email."....em..";
}else{
if ($_SESSION['email'] !='') {
echo "SESS jeff:".$_SESSION['email'];
$email = $_SESSION['email'];
}
}
$link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
if ($link->connect_error) {
die(" Error: " . $link->connect_error);
}
// look for matching password in db
$sql = 'SELECT * FROM users WHERE email="' . $email . '";';
$result = $link->query($sql);
72
$compare = (sha1($password.PW_SALT));
// is user signed in?
if ($result->num_rows > 0) {
//$check_PW = sha1($pass.PW_SALT)
$sql = 'SELECT * FROM users WHERE email="' . $email . '" AND created !=0;';
$result = $link->query($sql)->fetch_assoc();
// sign user out
$sql = 'UPDATE users SET created= 0 WHERE email="' . $email . '" AND created !=0;';
$result = $link->query($sql);
$cmp = `password`;
$result = $link->query($sql);
$_POST['email'] = $email;
$_SESSION['email'] = $email;
} else {
$_SESSION['email'] = $email;
$_POST['email'] = $email;
}
?>
73
kreport.php Dispatch Report with Inner Join of Dispatch and Hospital Tables
<?php
session_start();
require_once('/var/www/config.php');
$records_per_page = 100;
$cur_page = (int)$_GET['cur_page'];
if (!$cur_page || $cur_page == 0){
$cur_page=1;
}
74
//need: host, user, password, database
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, "emetromedical");
//GET COUNT OF RECORDS
$sql_count = "SELECT count(*) AS COUNT FROM dispatch
INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid";
$result1 = $link->query($sql_count);
foreach ($result1 as $row){
$total_records = $row['COUNT'];
}
//join query notes
//SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city, dispatch.stamp AS
DispatchDateTimeStamp
//FROM dispatch, hospital
//WHERE dispatch.hospitalid = hospital.hospitalid
//run the actual query
$sql_query = "SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city,
dispatch.stamp
FROM dispatch
INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid
LIMIT 0,".$records_per_page;
$result = $link->query($sql_query);
//REPORT HEADER
$content = '<table width="100%"><thead><tr>';
75
$content .= '<td width="20%">ID</td><td width="20%">HospitalName</td><td
width="20%">Address</td><td width="20%">City</td><td
width="20%">DispatchDateTime</td></thead>';
$content .= "<tbody>";
foreach($result as $row){
//COLLECT INFO FROM DB -> ASSIGN TO VARIABLES
$hospitalid = $row['hospitalid'];
$hospitalname = $row['name'];
$address = $row['address1'];
$city = $row['city'];
$dispatchdatetime = $row['stamp'];
//APPEND INFO FROM VARIABLES TO OUTPUT BUFFER/VARIABLE
$content .= "<td>".$hospitalid."</td><td>".$hospitalname."</td><td>".
$address."</td><td>".$city."</td><td>".$dispatchdatetime."</td></tr>";
}
//REPORT FOOTER
$prev_page = $cur_page -1;
$next_page = $cur_page +1;
if ($cur_page > 1){
$pagination = '<a href="report.php?cur_page='.$prev_page.'"><<< Previous</a>';
}
$pagination .= '&nbsp;<a href="report.php?cur_page='.$next_page.'">Next >>></a>';
$pages = ceil($total_records/$records_per_page);
$content .= '<tr><td align="center" colspan=5>'.$pagination.'</td></tr>';
$content .= '<tr><td align="center" colspan=5>Total Pages:'.$pages.'</td></tr>';
76
$content .= "</tbody></table><hr>";
echo $content;
?>
77
jreport.php Dispatch Table Query
<?php
/* jreport.php Dispatch table query
Jeff Goldberg WSMS 1/2016
return detail by date and timestamp
*/
require_once('database_template.php');
$database = "emetromedical";
$query = "select * from dispatch";
$result = query_db($query, $database);
foreach($result as $row){
$hospitalid = $row['hospitalid'];
//$hospitalname = $row['name']; future use - join tables
//$address = $row['address1'];
//$city = $row['city'];
$dispatchdatetime = $row['stamp'];
$dispatchipaddr = $row['ipaddr'];
$dispatchpatient = $row['patientid'];
78
$options .= '<option id="' . $dispatchdatetime . '">' . $dispatchdatetime . '</option>';
}
//above loop retrieves DB detail
?>
<html>
<head>
<script src="jquery-2.1.4.min.js"></script>
<script>
$( document ).ready(function() {
$("#selector").val("Select Item");//Set dropdown to "Select Item"
$("#selector").change(function() {//generates trigger for calling db
var stamp = $("#selector").children(":selected").attr("id");//gets the value of dropdown
$.get( "inventoryj_callback.php", { stamp: stamp } ) //backend call to db, passing through sku
variable
.done(function( data ) {
console.log(data);
79
var returndata = $.parseJSON(data);//return order is [0]=stamp,[1]=ip,[2]=patient
[3]=hospital,
console.log(' data ');
console.log(data);
console.log(returndata);
utreport.php User Table Query by Timestamp
Reports on all Signed In Users (using JSON Callback to database)
80
<?php
/* utreport.php User table query
Jeff Goldberg WSMS 1/2016
return detail by timestamp
*/
require_once('database_template.php');
$database = "users";
$query = "select * from users";
$result = query_db($query, $database);
foreach($result as $row){
$username = $row['username'];
$email = $row['email'];
$created = $row['created'];
// signed in user will have a positive timestamp
if ($created > 0) {
$options .= '<option id="' . $created . '">' . $username . '</option>';
81
}
}
//above loop retrieves DB detail
?>
<html>
<head>
<script src="jquery-2.1.4.min.js"></script>
<script>
$( document ).ready(function() {
$("#selector").val("Select Item");//Set dropdown to "Select Item"
$("#selector").change(function() {//generates trigger for calling db
var created = $("#selector").children(":selected").attr("id");//gets the value of dropdown
$.get( "usertCallback.php", { created: created } ) //backend call to db, passing through user
signon variable
.done(function( data ) {
var returndata = $.parseJSON(data);//return order is [0]=username,[1]=email,[2]=created
console.log(' data ');
console.log(data);
console.log(returndata);
82
$("#username").val(returndata[0]);
$("#email").val(returndata[1]);
$("#created").val(returndata[2]);
});
});
});
</script>
</head>
<body>
<center><font color=blue><h1>Users Table Query</h1></font></center>
<center><font color=gray><h2>by User Signin Status</h2></font></center><br /><br /><br /><br
/><br />
<!-- Date - select<br /><br /> -->
<center>
<select id="selector"><option id="0" selected="selected">Select Item</option></center><br /><br />
<?php
echo $options;
?>
</select>
<br />
83
<br />
<br />
<br />
User Signin Status:<br /><br /><br />
<font color=blue>
User ID : &emsp; <input id="username" value=""><br /><br />
eMail : &emsp;&emsp;<input id="email" value=""><br /><br />
Signed In:&emsp;<input id="created" value=""><br /><br />
<br /><br /><br /></br><br /><br /><br />
</font>
<div id="imgHolder"></div>
<a class="btn" href="../logout.php">
<button class="btn" type="submit">Close</button></a></br><br /><br /><br /></br><br /><br
/><br /></br><br /><br /><br /></br><br /><br /><br />
</body>
</html>
<?php
usertCallback.php json callback for required detail
// JSON Callback to database for specific row detail
84
//
// Jeff Goldberg WSMS 1/2016
//
// usertCallback.php component of ureport.php
//
require_once('database_template.php');
$database = "users";
$created = $_GET['created'];
$query = "SELECT * FROM users WHERE created ='".$created."'";
$results = query_db($query, $database);
foreach($results as $row){
$aryDetails[0] = $row['username'];
$aryDetails[1] = $row['email'];
$aryDetails[2] = $row['created'];
}
echo json_encode($aryDetails);
?>
85
ureport.php User Table Query
Reports on Registered Users (using JSON Callback to database)
<?php
/* ureport.php User table query
Jeff Goldberg WSMS 1/2016
86
return detail by username
*/
require_once('database_template.php');
$database = "users";
$query = "select * from users";
$result = query_db($query, $database);
foreach($result as $row){
$username = $row['username'];
$email = $row['email'];
$created = $row['created'];
$options .= '<option id="' . $username . '">' . $username . '</option>';
}
//above loop retrieves DB detail
?>
<html>
<head>
<script src="jquery-2.1.4.min.js"></script>
<script>
$( document ).ready(function() {
87
$("#selector").val("Select Item");//Set dropdown to "Select Item"
$("#selector").change(function() {//generates trigger for calling db
var username = $("#selector").children(":selected").attr("id");//gets the value of dropdown
$.get( "userCallback.php", { username: username } ) //backend call to db, passing through sku
variable
.done(function( data ) {
console.log(' pr1-data ');
console.log(data);
var returndata = $.parseJSON(data);//return order is [0]=username,[1]=email,[2]=created
console.log(' data ');
console.log(data);
console.log(returndata);
$("#username").val(returndata[0]);
$("#email").val(returndata[1]);
$("#created").val(returndata[2]);
});
});
});
</script>
</head>
<body>
<center><font color=blue><h1>Users Table Query</h1></font></center>
<center><font color=gray><h2>by User</h2></font></center><br /><br /><br /><br /><br />
<!-- Date - select<br /><br /> -->
88
<center>&emsp;&emsp;&emsp;&emsp;
<select id="selector"><option id="0" selected="selected">Select Item</option></center><br /><br />
<?php
echo $options;
?>
</select>
<br />
<br />
<br />
<br />
&emsp;&emsp; User Details:<br /><br />
<font color=blue>
User:&emsp;&emsp;&emsp;&emsp;<input id="username" value=""><br /><br />
eMail add:&emsp;&emsp;<input id="email" value=""><br /><br />
Signed In:&emsp;&emsp;<input id="created" value=""><br /><br />
<br /><br /><br /></br><br /><br /><br />
</font>
<div id="imgHolder"></div>
<a class="btn" href="../logout.php">
<button class="btn" type="submit">Close</button></a></br><br /><br /><br /></br><br /><br
/><br /></br><br /><br /><br /></br><br /><br /><br />
89
</body>
</html>
userCallback.php json callback for required detail
<?php
// JSON Callback to database for specific row detail
//
// Jeff Goldberg WSMS 1/2016
//
// userCallback.php component of ureport.php
//
require_once('database_template.php');
$database = "users";
$username = $_GET['username'];
$query = "SELECT * FROM users WHERE username ='".$username."'";
$results = query_db($query, $database);
foreach($results as $row){
$aryDetails[0] = $row['username'];
$aryDetails[1] = $row['email'];
$aryDetails[2] = $row['created'];
}
90
echo json_encode($aryDetails);
?>
User Database User Table
Password Salted and Encrypted
91
Batch Processing
92
93
94
95
96
97
Admin User NOT Signed In - BLOCKED
98
Admin Signed In Executes lshw
99

More Related Content

Viewers also liked

Angie's List AP Chemistry and Physics Tutor Plainsboro NJ
Angie's List AP Chemistry and Physics Tutor Plainsboro NJ Angie's List AP Chemistry and Physics Tutor Plainsboro NJ
Angie's List AP Chemistry and Physics Tutor Plainsboro NJ Derek Benson
 
Expansión - Evita que tu cartera se arruine por los prejuicios profesionales
Expansión - Evita que tu cartera se arruine por los prejuicios profesionalesExpansión - Evita que tu cartera se arruine por los prejuicios profesionales
Expansión - Evita que tu cartera se arruine por los prejuicios profesionalesEAE Business School
 
Kako spasiti hrvatsku
Kako spasiti hrvatskuKako spasiti hrvatsku
Kako spasiti hrvatskuJRadojcic
 
Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...
Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...
Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...Javier Trespalacios
 
Advanced social media - Confidence and creativity
Advanced social media - Confidence and creativityAdvanced social media - Confidence and creativity
Advanced social media - Confidence and creativityAntoine Ste-Marie, MBA
 
Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...
Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...
Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...EAE Business School
 
Write Code For The Future You - Tulsa TechFest 2016
Write Code For The Future You - Tulsa TechFest 2016Write Code For The Future You - Tulsa TechFest 2016
Write Code For The Future You - Tulsa TechFest 2016Paul Gower
 
Why 1 is One, 2 is Two, 3 is Three?
Why 1 is One, 2 is Two, 3 is Three?Why 1 is One, 2 is Two, 3 is Three?
Why 1 is One, 2 is Two, 3 is Three?Rakesh Kumar
 
2. diagram. electricity &amp; magnetism.
2.  diagram. electricity &amp; magnetism.2.  diagram. electricity &amp; magnetism.
2. diagram. electricity &amp; magnetism.pablojgd
 
Unit 2. vertebrates and invertebrates animals
Unit 2. vertebrates and invertebrates animalsUnit 2. vertebrates and invertebrates animals
Unit 2. vertebrates and invertebrates animalsisapla37
 

Viewers also liked (12)

Angie's List AP Chemistry and Physics Tutor Plainsboro NJ
Angie's List AP Chemistry and Physics Tutor Plainsboro NJ Angie's List AP Chemistry and Physics Tutor Plainsboro NJ
Angie's List AP Chemistry and Physics Tutor Plainsboro NJ
 
Expansión - Evita que tu cartera se arruine por los prejuicios profesionales
Expansión - Evita que tu cartera se arruine por los prejuicios profesionalesExpansión - Evita que tu cartera se arruine por los prejuicios profesionales
Expansión - Evita que tu cartera se arruine por los prejuicios profesionales
 
Kako spasiti hrvatsku
Kako spasiti hrvatskuKako spasiti hrvatsku
Kako spasiti hrvatsku
 
Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...
Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...
Ecotechsy : Artículo 1.1 - La situación actual de la población, la energí...
 
Advanced social media - Confidence and creativity
Advanced social media - Confidence and creativityAdvanced social media - Confidence and creativity
Advanced social media - Confidence and creativity
 
Cuadro conflictos
Cuadro conflictosCuadro conflictos
Cuadro conflictos
 
Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...
Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...
Murcia es la comunidad que más aumentó su deuda durante el pasado año. Estudi...
 
Write Code For The Future You - Tulsa TechFest 2016
Write Code For The Future You - Tulsa TechFest 2016Write Code For The Future You - Tulsa TechFest 2016
Write Code For The Future You - Tulsa TechFest 2016
 
Why 1 is One, 2 is Two, 3 is Three?
Why 1 is One, 2 is Two, 3 is Three?Why 1 is One, 2 is Two, 3 is Three?
Why 1 is One, 2 is Two, 3 is Three?
 
2. diagram. electricity &amp; magnetism.
2.  diagram. electricity &amp; magnetism.2.  diagram. electricity &amp; magnetism.
2. diagram. electricity &amp; magnetism.
 
Sams 21st
Sams 21stSams 21st
Sams 21st
 
Unit 2. vertebrates and invertebrates animals
Unit 2. vertebrates and invertebrates animalsUnit 2. vertebrates and invertebrates animals
Unit 2. vertebrates and invertebrates animals
 

Similar to Capstone Project Website walkthru - p40

Android Implementation using MQTT Protocol
Android Implementation using MQTT ProtocolAndroid Implementation using MQTT Protocol
Android Implementation using MQTT ProtocolFatih Özlü
 
Built on Pulsar: A Commercial Consent Management System for 80 Million Citizens
Built on Pulsar: A Commercial Consent Management System for 80 Million CitizensBuilt on Pulsar: A Commercial Consent Management System for 80 Million Citizens
Built on Pulsar: A Commercial Consent Management System for 80 Million CitizensStreamNative
 
SMART SALINE BOTTLE USING IOT
SMART SALINE BOTTLE USING IOTSMART SALINE BOTTLE USING IOT
SMART SALINE BOTTLE USING IOTIRJET Journal
 
FIWARE: an open standard platform for smart cities
FIWARE: an open standard platform for smart citiesFIWARE: an open standard platform for smart cities
FIWARE: an open standard platform for smart citiesJuanjo Hierro
 
Internet of things(iot)
Internet of things(iot)Internet of things(iot)
Internet of things(iot)Rakesh Gupta
 
Connecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of ThingsConnecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of ThingsMarkus Van Kempen
 
Message queuing telemetry transport (mqtt) id and other type parameters
Message queuing telemetry transport (mqtt) id and other type parametersMessage queuing telemetry transport (mqtt) id and other type parameters
Message queuing telemetry transport (mqtt) id and other type parametersHamdamboy (함담보이)
 
Alu 9900 wng_nbi_v03
Alu 9900 wng_nbi_v03Alu 9900 wng_nbi_v03
Alu 9900 wng_nbi_v03navaidkhan
 
IRJET- Design and Implementation of Automated System as a Waiter in Restaurant
IRJET- Design and Implementation of Automated System as a Waiter in RestaurantIRJET- Design and Implementation of Automated System as a Waiter in Restaurant
IRJET- Design and Implementation of Automated System as a Waiter in RestaurantIRJET Journal
 
Explore the InitVerse Blockchain - the digital blueprint for future finance.pdf
Explore the InitVerse Blockchain - the digital blueprint for future finance.pdfExplore the InitVerse Blockchain - the digital blueprint for future finance.pdf
Explore the InitVerse Blockchain - the digital blueprint for future finance.pdfInitVerse Blockchain
 
Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...
Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...
Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...InfluxData
 
Smart traffic managment system real time (stmsrt)
Smart traffic managment system real time (stmsrt)Smart traffic managment system real time (stmsrt)
Smart traffic managment system real time (stmsrt)Ayoub Rouzi
 
Industrial Control System Network Cyber Security Monitoring Solution (SCAB)
Industrial Control System Network Cyber Security Monitoring Solution (SCAB)Industrial Control System Network Cyber Security Monitoring Solution (SCAB)
Industrial Control System Network Cyber Security Monitoring Solution (SCAB)Enrique Martin
 
IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...IRJET Journal
 
InduSoft Web Studio and MQTT for Internet of Things Applications
InduSoft Web Studio and MQTT for Internet of Things ApplicationsInduSoft Web Studio and MQTT for Internet of Things Applications
InduSoft Web Studio and MQTT for Internet of Things ApplicationsAVEVA
 
Protocol
ProtocolProtocol
Protocolm_bahba
 
The enterprise differentiator of mq on zos
The enterprise differentiator of mq on zosThe enterprise differentiator of mq on zos
The enterprise differentiator of mq on zosMatt Leming
 
Bit taka bangladeshi country owned crypto currency
Bit taka bangladeshi country owned crypto currencyBit taka bangladeshi country owned crypto currency
Bit taka bangladeshi country owned crypto currencyMohammad Salehin
 

Similar to Capstone Project Website walkthru - p40 (20)

Android Implementation using MQTT Protocol
Android Implementation using MQTT ProtocolAndroid Implementation using MQTT Protocol
Android Implementation using MQTT Protocol
 
ACTAtek unique features
ACTAtek unique featuresACTAtek unique features
ACTAtek unique features
 
Built on Pulsar: A Commercial Consent Management System for 80 Million Citizens
Built on Pulsar: A Commercial Consent Management System for 80 Million CitizensBuilt on Pulsar: A Commercial Consent Management System for 80 Million Citizens
Built on Pulsar: A Commercial Consent Management System for 80 Million Citizens
 
SMART SALINE BOTTLE USING IOT
SMART SALINE BOTTLE USING IOTSMART SALINE BOTTLE USING IOT
SMART SALINE BOTTLE USING IOT
 
FIWARE: an open standard platform for smart cities
FIWARE: an open standard platform for smart citiesFIWARE: an open standard platform for smart cities
FIWARE: an open standard platform for smart cities
 
Internet of things(iot)
Internet of things(iot)Internet of things(iot)
Internet of things(iot)
 
Connecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of ThingsConnecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of Things
 
Message queuing telemetry transport (mqtt) id and other type parameters
Message queuing telemetry transport (mqtt) id and other type parametersMessage queuing telemetry transport (mqtt) id and other type parameters
Message queuing telemetry transport (mqtt) id and other type parameters
 
Alu 9900 wng_nbi_v03
Alu 9900 wng_nbi_v03Alu 9900 wng_nbi_v03
Alu 9900 wng_nbi_v03
 
IRJET- Design and Implementation of Automated System as a Waiter in Restaurant
IRJET- Design and Implementation of Automated System as a Waiter in RestaurantIRJET- Design and Implementation of Automated System as a Waiter in Restaurant
IRJET- Design and Implementation of Automated System as a Waiter in Restaurant
 
Explore the InitVerse Blockchain - the digital blueprint for future finance.pdf
Explore the InitVerse Blockchain - the digital blueprint for future finance.pdfExplore the InitVerse Blockchain - the digital blueprint for future finance.pdf
Explore the InitVerse Blockchain - the digital blueprint for future finance.pdf
 
Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...
Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...
Nilden Tutular, Volkan Balikci, Uygar Zubari [Eldor Corporation] | MQTT - Mac...
 
Smart traffic managment system real time (stmsrt)
Smart traffic managment system real time (stmsrt)Smart traffic managment system real time (stmsrt)
Smart traffic managment system real time (stmsrt)
 
Industrial Control System Network Cyber Security Monitoring Solution (SCAB)
Industrial Control System Network Cyber Security Monitoring Solution (SCAB)Industrial Control System Network Cyber Security Monitoring Solution (SCAB)
Industrial Control System Network Cyber Security Monitoring Solution (SCAB)
 
IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...IRJET- Development of Android Application for Device to Device Communication ...
IRJET- Development of Android Application for Device to Device Communication ...
 
InduSoft Web Studio and MQTT for Internet of Things Applications
InduSoft Web Studio and MQTT for Internet of Things ApplicationsInduSoft Web Studio and MQTT for Internet of Things Applications
InduSoft Web Studio and MQTT for Internet of Things Applications
 
Protocol
ProtocolProtocol
Protocol
 
The enterprise differentiator of mq on zos
The enterprise differentiator of mq on zosThe enterprise differentiator of mq on zos
The enterprise differentiator of mq on zos
 
Design of Remote Video Monitoring and Motion Detection System based on Arm-Li...
Design of Remote Video Monitoring and Motion Detection System based on Arm-Li...Design of Remote Video Monitoring and Motion Detection System based on Arm-Li...
Design of Remote Video Monitoring and Motion Detection System based on Arm-Li...
 
Bit taka bangladeshi country owned crypto currency
Bit taka bangladeshi country owned crypto currencyBit taka bangladeshi country owned crypto currency
Bit taka bangladeshi country owned crypto currency
 

Recently uploaded

Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEHimani415946
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxabhinandnam9997
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxlaozhuseo02
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesSanjeev Rampal
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?Linksys Velop Login
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxGal Baras
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyDamar Juniarto
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shoplaozhuseo02
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理aagad
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfSiskaFitrianingrum
 

Recently uploaded (12)

Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 

Capstone Project Website walkthru - p40

  • 1. 1 eMetro Emergency Medical Services System Documentation Team: Kevin O’Neil, Jeff Goldberg Webserver Maintenance & Security Certificate Class Project Kevi Abstract The eMetro Medical Services dispatch system provides 911 operators a graphical drag-n-drop interface to dispatch patients to a set of hospitals and provides automated publish-subscribe messaging to ER hospitals using the Mosquitto MQTT message broker. All dispatch events are recorded in a MySQL database. December 8, 2015
  • 2. eMetro Emergency Medical Services System Documentation Revision History Creation Date: 12/8/2015 Last Update: 1/12/2016 2
  • 3. Table of Contents Table of Contents........................................................................................................................................3 Introduction.................................................................................................................................................5 Requirements..............................................................................................................................................5 Project Requirements..............................................................................................................................5 Extra Requirements Created by Team.....................................................................................................5 System Model..............................................................................................................................................6 eMetro Block Definition Diagram............................................................................................................6 Dispatcher User Interface............................................................................................................................6 Dispatch Report...................................................................................................................................8 Mosquitto MQTT Message Broker...............................................................................................................9 Installing Mosquitto MQTT....................................................................................................................10 Getting Mosquitto Status & Stopping....................................................................................................11 Mosquitto-Clients..................................................................................................................................12 JQuery User Interface................................................................................................................................12 911 Dispatcher Command Center, PHP.....................................................................................................13 File: testdrag6.php.................................................................................................................................13 File: log.php...........................................................................................................................................16 Windows Share Folder...............................................................................................................................17 Mosquitto MQTT Setup.............................................................................................................................22 Mosquitto Subscriber............................................................................................................................24 Mosquitto Publish..................................................................................................................................24 MQTT Utility (Java)................................................................................................................................25 Database Tools: phpMyAdmin...................................................................................................................28 emetromedical Database...........................................................................................................................29 Dispatch Table.......................................................................................................................................30 Hospital Table........................................................................................................................................31 Database Export....................................................................................................................................31 Database Join.........................................................................................................................................35 Table structure for table hospital..........................................................................................................35 Data Dump for Table Hospital................................................................................................................36 3
  • 4. Simple Join of Dispatch and Hospital Tables..........................................................................................36 Join Results............................................................................................................................................36 Join Dispatch and Hospital Tables SQL with Added Dispatch DateTimeStamp......................................37 Join Results with Dispatch DateTimeStamp...........................................................................................37 Inner Join Version PHP Code..................................................................................................................37 Online Report Result..............................................................................................................................38 Socket.io....................................................................................................................................................39 Jquery........................................................................................................................................................39 Nodejs server.........................................................................................................................................40 4
  • 5. Introduction The eMetro Medical services dispatch screen displays the patient icon representing the patient to be transported. The 911 dispatcher drags the patient icon to one of the hospital emergency room drop icon spaces. When the drag patient icon is dragged and dropped on the hospital icon the database is updated with the dispatch event date, time, patient ID and hospital ID. Requirements Project Requirements ID P-R 1 System must demonstrate use of a web browser interface. ID P-R 2 System must demonstrate use of PHP. ID P-R 3 System must demonstrate use of HTML. ID P-R 4 System must demonstrate use of the Apache Web Server. ID P-R 5 System must demonstrate use of shell scripting. ID P-R 6 System must demonstrate use of a database. ID P-R 7 System must demonstrate use of Linux and Windows share folder. ID P-R 8 System must demonstrate use of a SQL join query. Extra Requirements Created by Team ID P-R 9 System must be able to support 911 operators sending reliable dispatch messages to subscriber hospitals using MQTT Broker. ID P-R 10 System must be able to support subscription by hospitals using a MQTT Client. ID P-R 11 System must be able to show live MQTT Broker monitoring. ID P-R 12 System must utilize drag-and-drop for ease-of-use user interface (jQuery UI). ID P-R 13 System must automatically update database when a drag-and-drop action is taken by 911 operator. ID P-R 14 System must support MQTT Client access to MQTT Broker (Socket.io, Nodejs). ID P-R 15 System must demonstrate use of Nodejs. ID P-R 16 System must demonstrate use of Bootstrap Framework. ID P-R 17 System must demonstrate use of database reporting. 5
  • 6. ID P-R 18 System must demonstrate use of JSON Callback for database detail. System Model eMetro Block Definition Diagram The eMetro block definition diagram (bdd) below captures the major system components and stakeholders. Dispatcher User Interface The eMetro Medical services dispatch screen displays the patient icon representing the patient to be transported. The 911 dispatcher drags the patient icon to one of the hospital emergency room drop icon spaces. When the drag patient icon is dragged and dropped on the hospital icon the database is updated with the dispatch event date, time, patient ID and hospital ID. 6
  • 7. When the patient icon is dragged to the hospital icon rectangle the database is updated with dispatch information and a MQTT command is executed triggering the MQTT message broker to send a message that the patient has been dispatched, see subscriber window below. 7
  • 8. Dispatch Report Pressing “Dispatch Report” button generates a report that is the result of a join between ‘hospital’ and ‘dispatch’ tables to produce a report of 911 operator patient date-time stamped dispatches to which hospitals. 8
  • 9. Mosquitto MQTT Message Broker When the 911 dispatcher drags the patient icon to one of the available ER rooms a message is created and published to the subscribing ER room. This is depicted in the terminal window for the subscriber below. 9
  • 10. Installing Mosquitto MQTT Mosquitto MQTT is a message broker that supports version 3.1 and 3.1.1 of the MQTT protocol. http://mosquitto.org MQTT provides a method of carrying out messaging using a publish/subscribe model. It is lightweight, both in terms of bandwidth usage and ease of implementation. This makes it particularly useful at the edge of the network where a sensor or other simple device may be implemented using an arduino for example. Install commands: sudo apt-get install mosquitto sudo apt-get install mosquito-clients One recommended install instructions from stackoverflow. http://stackoverflow.com/questions/27534953/how-do-i-set-up-my-own-mqtt-server-with-mosquitto sudo apt-get update sudo apt-get install mosquitto sudo update-rc.d mosquitto defaults 10
  • 11. sudo /etc/init.d/mosquitto start Getting Mosquitto Status & Stopping sudo /etc/init.d/mosquitto status sudo /etc/init.d/mosquitto stop 11
  • 12. Mosquitto-Clients This is two MQTT version 3.1 command line clients. mosquitto_pub can be used to publish messages to a broker and mosquitto_sub can be used to subscribe to a topic to receive messages. JQuery User Interface The jquery user interface library (jquery-ui.js and other components) is used to support drag and drop user interface functionality. You can download from jqueryui.com. http://jqueryui.com/draggable/ 12
  • 13. 911 Dispatcher Command Center, PHP File: testdrag6.php Functions are to create a 911 drag-n-drop user interface displaying a patient icon and available hospital emergency rooms. The 911 operator can then drag a patient icon onto a hospital icon and create a dispatch order and message informing the hospital ER that a patient is being dispatched to their hospital. <?php /** * Created by PhpStorm. * User: user01 * Date: 10/29/2015 * Time: 9:15 PM */ session_start(); require_once('/var/www/config.php'); function query_db($query){ //need: host, user, password, database $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging error: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } //run the actual query $result = $link->query($query); mysqli_close($link); 13
  • 14. return $result; }//end function query_db //DO NOT TOUCH ABOVE THIS LINE - GENERAL DB FUNCTIONS //START WEB PAGE ?> <script src="lib/jquery-2.1.4.min.js"></script> <script> $( document ).ready(function() {//DOCUMENT IS FULLY LOADED ON CLIENT (BROWSER) $( "#draggable" ).click(function() {//CHECK FOR CLICK EVENT ON ID // $.post( "log.php", { ad: "1", action: "1", patientid: "1" } ) // .done(function( data ) { // alert( "Data Loaded: " + data ); }); }); /* $( "#ad1" ).mouseout(function() {//CHECK FOR HOVER EVENT ON ID $.post( "log.php", { ad: "1", action: "3" } ) .done(function( data ) { // alert( "Data Loaded: " + data ); }); }); $( "#ad1" ).mouseover(function() {//CHECK FOR HOVER EVENT ON ID $.post( "log.php", { ad: "1", action: "2" } ) .done(function( data ) { // alert( "Data Loaded: " + data ); }); });*/ /* $( "#ad2" ).click(function() {//CHECK FOR CLICK EVENT ON ID var ad = "2"; $.post( "log.php", { ad: ad, action: "1" } ) .done(function( data ) { // alert( "Data Loaded: " + data ); }); }); $( "#ad2" ).mouseout(function() {//CHECK FOR HOVER EVENT ON ID var ad = "2"; $.post( "log.php", { ad: ad, action: "3" } ) .done(function( data ) { // alert( "Data Loaded: " + data ); }); }); $( "#ad2" ).mouseover(function() {//CHECK FOR HOVER EVENT ON ID var ad = "2"; $.post( "log.php", { ad: ad, action: "2" } ) .done(function( data ) { // alert( "Data Loaded: " + data ); });*/ }); // }); </script> 14
  • 15. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Droppable - Default functionality</title> <h1> eMetro Emergency Medical Services </h1> <p>Drag and drop patient icon to one of the hospitals on the right.</p> <p>Patient will be routed to the emergency room at that hospital.</p> <a class="btn" href="report.php"> <button class="btn" type="submit">Dispatch Report</button></a> <!-- <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">--> <link rel="stylesheet" href="lib/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <!-- <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>--> <script src="lib/jquery-ui.js"></script> <!-- <link rel="stylesheet" href="/resources/demos/style.css">--> <link rel="stylesheet" href="lib/style.css"> <style> #draggable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; } #droppable { width: 300px; height: 500px; padding: 0.5em; float: right; margin: 10px; } #droppable2 { width: 300px; height: 500px; padding: 0.5em; float: right; margin: 10px; } </style> <script> $(function() { $( "#draggable" ).draggable(); $( "#droppable" ).droppable({ drop: function( event, ui ) { $( this ) .addClass( "ui-state-highlight" ) .find( "p" ) .html( "Patient routed to Sharp Memorial" ); // Post to database patient routed to Sharp Memorial $.post( "log.php", { ad: "1", action: "1", hospitalid: "2", patientid: "1" } ) .done(function( data ) { // alert( "Data Loaded: " + data ); }); } }); $( "#droppable2" ).droppable({ drop: function( event, ui ) { $( this ) 15
  • 16. .addClass( "ui-state-highlight" ) .find( "p" ) .html( "Patient routed to Sharp Grossmont" ); // Post to database patient routed to Sharp Grossmont $.post( "log.php", { ad: "1", action: "1", hospitalid: "1", patientid: "1"} ) .done(function( data ) { // alert( "Data Loaded: " + data ); }); } }); }); </script> </head> <body> <div id="draggable" class="ui-widget-content"> <img src="ad_repository/pia_picture_w150_h150.png"> <p>Patient K_ONEIL</p> <p>Assessment: C-spine and internal injuries, auto accident</p> <p>Current Location: 163 south bound, 1/2 mile south of Balboa Ave. ext</p> </div> <div id="droppable" class="ui-widget-header"> <img src="ad_repository/sharp_er.jpg"> <p>No 2: Sharp Memorial Hospital Emergency Room</p> <br>7901 Frost St, San Diego, CA 92123</br> <!-- <br>Transfer/Drop here</br>--> </div> <div id="droppable2" class="ui-widget-header"> <img src="ad_repository/sharp_grossmont_er.jpg"> <p>No 1: Sharp Grossmont Hospital Emergency Care</p> <br>5555 Grossmont Center Drive, La Mesa, CA 91942</br> <!-- <p>Transfer/Drop here</p>--> </div> </body> </html> File: log.php Functions are to access emetromedical database and perform dispatch updates. Second function is to execute a shell command to publish a MQTT message and notify the subscribing hospitals of the patient dispatches. <?php //24-OCT-2015 //file: log.php session_start(); 16
  • 17. require_once('/var/www/config.php'); function query_db($query){ //need: host, user, password, database $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, "emetromedical"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging error: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } //run the actual query $result = $link->query($query); mysqli_close($link); return $result; }//end function query_db //DO NOT TOUCH ABOVE THIS LINE - GENERAL DB FUNCTIONS $ad = (int)$_POST['ad']; $action = (int)$_POST['action']; $hospitalid = (int)$_POST['hospitalid']; $patientid = (int)$_POST['patientid']; /* echo "data stored: "; echo "ad: ".$ad."<br />"; echo "action:".$action; */ $ip=$_SERVER['REMOTE_ADDR']; // echo "IP address= $ip"; //build query //action codes: 1=click, 2=mouseover, 3=mouseout //store: ip, ad, action, timedate $query = "INSERT INTO dispatch (action, stamp, adid, ipaddr, hospitalid, patientid) VALUES ('".$action."', now(), '".$ad."', '".$ip."', '".$hospitalid."', '". $patientid."')"; echo $query; query_db($query); $cmd = 'mosquitto_pub -h localhost -t emetro -m /"patient K_ONEIL enroute to: "'. $hospitalid.'"";'; exec($cmd, $stdout, $stderr); echo "hi bob"; ?> Windows Share Folder Instructions On the Ubuntu server open a terminal window and execute mount command with the root account: mount -t cifs -o username=ioneil,password=cool //10.103.20.21/share /var/www/html/ 17
  • 18. Must have IP address of Windows machine. You open a command window within Windows. Execute ‘cmd’ command in Start Window. 18
  • 19. 19
  • 21. Current IP address for Windows machine is 10.103.26.119. 21
  • 22. Mosquitto MQTT Setup Mosquitto MQTT has to be running. Start Mosquitto by using the ‘mosquitto’ command. This terminal window will show mosquito events such as when you create a subscriber and publish messages to the broker. 22
  • 23. 23
  • 24. Mosquitto Subscriber Open another terminal window with another account besides root. Execute the ‘mosquitto_sub –h localhost –t emetro’ command. This will subscribe to the topic ‘emetro’ and this terminal window will display messages published to the topic. Mosquitto Publish Now execute the publish command: mosquito_pub –h localhost –t emetro –m “hello jeff” 24
  • 25. As you can see in the prior screen capture the subscriber window has received the “hello jeff” message. These terminal windows are for subscriber hospitals what will receive MQTT messages when the patient icon is dropped on the hospital icon. MQTT Utility (Java) http://www.eclipse.org/paho/ https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/mqtt-utility/0.4.0/ mqtt-utility-0.4.0.jar is a Java utility for testing MQTT. Alternatively the Paho Java library jars can be downloaded directly from the following URLs; https://repo.eclipse.org/content/repositories/paho-releases/ - Official Releases Execute the Jar file by double clicking on the file. This executable Java file was stored in the c:/mtn/share/nodejs folder. 25
  • 26. The 192.168.145.129 address for the Ubuntu server and port 1883 was used to connect to the MQTT server, see below. You can create/subscribe to a topic and test sending/publishing messages to the topic with this Java MQTT utility. 26
  • 27. Example subject of “emetro” with test message of “hi kevin” 27
  • 28. Database Tools: phpMyAdmin MySQL is the database. Log into phpMyAdmin to administrate the database. 28
  • 31. Hospital Table Database Export -- phpMyAdmin SQL Dump -- version 4.4.13.1deb1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Jan 09, 2016 at 09:54 AM -- Server version: 5.6.27-0ubuntu1 -- PHP Version: 5.6.11-1ubuntu3.1 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; 31
  • 32. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `emetromedical` -- -- -------------------------------------------------------- -- -- Table structure for table `dispatch` -- CREATE TABLE IF NOT EXISTS `dispatch` ( `id` int(11) NOT NULL, `view` datetime NOT NULL, `click` datetime NOT NULL, `action` int(11) NOT NULL, `stamp` datetime NOT NULL, `adid` int(11) NOT NULL, `patientid` int(11) NOT NULL, `hospitalid` int(11) NOT NULL, `ipaddr` varchar(20) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=251 DEFAULT CHARSET=latin1; -- -- Dumping data for table `dispatch` 32
  • 33. -- INSERT INTO `dispatch` (`id`, `view`, `click`, `action`, `stamp`, `adid`, `patientid`, `hospitalid`, `ipaddr`) VALUES (237, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-17 20:44:32', 1, 1, 1, '192.168.145.1'), (238, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-17 20:45:15', 1, 1, 2, '192.168.145.1'), (239, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-17 20:49:48', 1, 1, 1, '192.168.145.1'), (240, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-11-19 17:44:16', 1, 1, 1, '192.168.145.1'), (241, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 08:39:14', 1, 1, 1, '192.168.145.1'), (242, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 09:18:54', 1, 1, 2, '192.168.145.1'), (243, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 13:11:42', 1, 1, 1, '192.168.145.1'), (244, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 13:57:42', 1, 1, 2, '192.168.145.1'), (245, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 14:02:54', 1, 1, 1, '192.168.145.1'), (246, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-05 14:03:04', 1, 1, 2, '192.168.145.1'), (247, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-08 21:27:20', 1, 1, 1, '192.168.145.1'), (248, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-10 17:58:29', 1, 1, 1, '192.168.145.1'), (249, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2015-12-10 17:59:37', 1, 1, 2, '192.168.145.1'), (250, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, '2016-01-07 18:46:22', 1, 1, 1, '192.168.145.1'); -- -------------------------------------------------------- -- -- Table structure for table `hospital` -- CREATE TABLE IF NOT EXISTS `hospital` ( `hospitalid` int(11) NOT NULL, `name` varchar(40) NOT NULL, `address1` varchar(30) NOT NULL, 33
  • 34. `city` varchar(20) NOT NULL, `zip` int(5) NOT NULL, `state` varchar(2) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `hospital` -- INSERT INTO `hospital` (`hospitalid`, `name`, `address1`, `city`, `zip`, `state`) VALUES (1, 'Sharp Grossmont', '5555 Grossmont Center Drive', 'La Mesa', 91942, 'CA'), (2, 'Sharp Memorial', '7901 Frost Street', 'San Diego', 92123, 'CA'), (3, 'Scripps Green ', '10666 N. Torrey Pines Rd.', 'La Jolla', 92037, 'CA'), (4, 'Scripps Memorial Hospital Encinitas', '354 Santa Fe Drive', 'Encinitas', 92024, 'CA'), (5, 'Scripps Mercy Hospital San Diego', '4077 5th Avenue', 'San Diego', 92103, 'CA'); -- -- Indexes for dumped tables -- -- -- Indexes for table `dispatch` -- ALTER TABLE `dispatch` ADD PRIMARY KEY (`id`); -- -- Indexes for table `hospital` -- 34
  • 35. ALTER TABLE `hospital` ADD PRIMARY KEY (`hospitalid`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `dispatch` -- ALTER TABLE `dispatch` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=251; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; Database Join A second ‘hospital’ table was created to contain hospital address information. Table structure for table hospital Column Type Null Default hospitali d int(11) No name varchar(40) No address1 varchar(30) No city varchar(20) No zip int(5) No state varchar(2) No 35
  • 36. Data Dump for Table Hospital 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 91942 CA 2 Sharp Memorial 7901 Frost Street San Diego 92123 CA 3 Scripps Green 10666 N. Torrey Pines Rd. La Jolla 92037 CA 4 Scripps Memorial Hospital Encinitas 354 Santa Fe Drive Encinitas 92024 CA 5 Scripps Mercy Hospital San Diego 4077 5th Avenue San Diego 92103 CA Simple Join of Dispatch and Hospital Tables A join between the tables ‘dispatch’ and ‘hospital’: SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city FROM dispatch, hospital WHERE dispatch.hospitalid = hospital.hospitalid Join Results 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2 Sharp Memorial 7901 Frost Street San Diego 2 Sharp Memorial 7901 Frost Street San Diego 2 Sharp Memorial 7901 Frost Street San Diego 2 Sharp Memorial 7901 Frost Street San Diego 2 Sharp Memorial 7901 Frost Street San Diego 36
  • 37. Join Dispatch and Hospital Tables SQL with Added Dispatch DateTimeStamp SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city, dispatch.stamp AS Dis patchDateTimeStamp FROM dispatch, hospitalWHERE dispatch.hospitalid = hospital.hospitalid Join Results with Dispatch DateTimeStamp 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-11-17 20:44:32 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-11-17 20:49:48 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-11-19 17:44:16 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-05 08:39:14 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-05 13:11:42 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-05 14:02:54 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-08 21:27:20 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2015-12-10 17:58:29 1 Sharp Grossmont 5555 Grossmont Center Drive La Mesa 2016-01-07 18:46:22 2 Sharp Memorial 7901 Frost Street San Diego 2015-11-17 20:45:15 2 Sharp Memorial 7901 Frost Street San Diego 2015-12-05 09:18:54 2 Sharp Memorial 7901 Frost Street San Diego 2015-12-05 13:57:42 2 Sharp Memorial 7901 Frost Street San Diego 2015-12-05 14:03:04 2 Sharp Memorial 7901 Frost Street San Diego 2015-12-10 17:59:37 Inner Join Version PHP Code <?php session_start(); require_once('/var/www/config.php'); $records_per_page = 100; $cur_page = (int)$_GET['cur_page']; if (!$cur_page || $cur_page == 0){ $cur_page=1; } //need: host, user, password, database $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, "emetromedical"); //GET COUNT OF RECORDS $sql_count = "SELECT count(*) AS COUNT FROM dispatch 37
  • 38. INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid"; $result1 = $link->query($sql_count); foreach ($result1 as $row){ $total_records = $row['COUNT']; } //join query notes //SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city, dispatch.stamp AS DispatchDateTimeStamp //FROM dispatch, hospital //WHERE dispatch.hospitalid = hospital.hospitalid //run the actual query $sql_query = "SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city, dispatch.stamp FROM dispatch INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid LIMIT 0,".$records_per_page; $result = $link->query($sql_query); //REPORT HEADER $content = '<table width="100%"><thead><tr>'; $content .= '<td width="20%">ID</td><td width="20%">HospitalName</td><td width="20%">Address</td><td width="20%">City</td><td width="20%">DispatchDateTime</td></thead>'; $content .= "<tbody>"; foreach($result as $row){ //COLLECT INFO FROM DB -> ASSIGN TO VARIABLES $hospitalid = $row['hospitalid']; $hospitalname = $row['name']; $address = $row['address1']; $city = $row['city']; $dispatchdatetime = $row['stamp']; //APPEND INFO FROM VARIABLES TO OUTPUT BUFFER/VARIABLE $content .= "<td>".$hospitalid."</td><td>".$hospitalname."</td><td>". $address."</td><td>".$city."</td><td>".$dispatchdatetime."</td></tr>"; } //REPORT FOOTER $prev_page = $cur_page -1; $next_page = $cur_page +1; if ($cur_page > 1){ $pagination = '<a href="report.php?cur_page='.$prev_page.'"><<< Previous</a>'; } $pagination .= '&nbsp;<a href="report.php?cur_page='.$next_page.'">Next >>></a>'; $pages = ceil($total_records/$records_per_page); $content .= '<tr><td align="center" colspan=5>'.$pagination.'</td></tr>'; $content .= '<tr><td align="center" colspan=5>Total Pages:'.$pages.'</td></tr>'; $content .= "</tbody></table><hr>"; echo $content; ?> Online Report Result 38
  • 39. Socket.io Download socket.io from: https://cdn.socket.io/socket.io-1.3.7.js Load this file into folder on Windows host machine in c:/mtn/share/nodejs folder socket.io-1.3.7.js On Ubuntu server load with npm. Load with “npm install socket.io”. Jquery Dowload Jquery from: http://jquery.com/download/ http://code.jquery.com/jquery-2.1.4.min.js 39
  • 40. On Windows move this file from the download folder to the mtn/share/nodejs folder. Nodejs server On server start nodejs server. root@ubuntu:/var/www/html/nodejs/server/mqtt2#nodejs server.js User Registration and Sign in 40
  • 42. Incorrect User ID / Password or Duplicate Sign In 42
  • 43. Valid Sign In (Administrator jeff01@sdccd.edu) 43
  • 44. User Signed In Dispatch Patient to Hospital 2 44
  • 45. Email Fires Off as a Backup Push Notification Hospital Receives MOSQUITTO MQTT Message to Terminal 45
  • 46. Configk.php (database and other details protected from Internet exposure with placement in var/www folder) System also uses Config.php (similar without Admin User ID) <?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ define("DB_DATABASE", "usersk"); define("DB_USER", "root"); define("DB_HOST", "localhost"); define("DB_PASS", "jeff"); define("PW_SALT", "bwM#2u46x86HR7atksMLe~XJN3jq5D@c#^CmWSB$&VgDvpFhUPd?rKt %zA9>ZdYT"); $admin = "jeff01@sdccd.edu"; ?> 46
  • 47. rs.php Initial Processing Module <!DOCTYPE html> <?php /** * File: rs.php * Jeff Goldberg WSMS * * 1/2016 */ require_once("../config.php"); require_once("rs.html"); session_start(); $email = $_POST['email']; $pass = $_POST['Password']; $_SESSION['email'] = $email; if (isset($email) && $email != "") { $link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE); if ($link->connect_error) { die(" Error: " . $link->connect_error); } 47
  • 48. //encrypted password for compare to db $salted = (sha1($pass.PW_SALT)); // is user in db and not already logged in? $sql = 'SELECT * FROM users WHERE email="' . $email . '" AND password="'.$salted.'" AND created=0;'; $result = $link->query($sql); $timestamp = date('Y-m-d HH:mm:ss'); $compare = (sha1($password.PW_SALT)); //find user and verify not already signed in if ($result->num_rows > 0) { $check_PW = sha1($pass.PW_SALT) $sql = 'SELECT * FROM users WHERE email="' . $email . '" AND created=0;'; $result = $link->query($sql)->fetch_assoc(); // flag user as signed in $sql = 'UPDATE users SET created= now() WHERE email="' . $email . '";'; $result = $link->query($sql); $cmp = `password`; 48
  • 49. $_SESSION['email'] = $email; $_POST['email'] = $email; // invoke testdrag4.php screen echo "<script type='text/javascript'>window.top.location='http://localhost/medical/testdrag4.php';</script>"; exit; } else { $_POST['email'] = $email; $_SESSION['email'] = $email; echo "jeff: ".$_SESSION['email']; } ?> signIn.php Similar to rs.php, specific to sign in function(validates data) 49
  • 50. <!DOCTYPE html> <?php /** * File: signIn.php * Jeff Goldberg WSMS * * 1/2016 */ require_once("../config.php"); require_once("rs.html"); session_start(); $email = $_POST['email']; $pass = $_POST['Password']; $_SESSION['email'] = $email; if (isset($email) && $email != "") { $link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE); if ($link->connect_error) { die(" Error: " . $link->connect_error); 50
  • 51. } //encrypted password for compare to db $salted = (sha1($pass.PW_SALT)); // is user in db and not already logged in? $sql = 'SELECT * FROM users WHERE email="' . $email . '" AND password="'.$salted.'" AND created=0;'; $result = $link->query($sql); $timestamp = date('Y-m-d HH:mm:ss'); $compare = (sha1($password.PW_SALT)); //find user and verify not already signed in if ($result->num_rows > 0) { $check_PW = sha1($pass.PW_SALT) $sql = 'SELECT * FROM users WHERE email="' . $email . '" AND created=0;'; $result = $link->query($sql)->fetch_assoc(); // flag user as signed in $sql = 'UPDATE users SET created= now() WHERE email="' . $email . '";'; $result = $link->query($sql); $cmp = `password`; $_SESSION['email'] = $email; 51
  • 52. $_POST['email'] = $email; // invoke testdrag.php screen echo "<script type='text/javascript'>window.top.location='http://localhost/medical/testdrag4.php';</script>"; exit; } else { $_POST['email'] = $email; $_SESSION['email'] = $email; echo "jeff: ".$_SESSION['email']; } //housekeeping and end session //$result->close(); //$link->close(); //session_unset(); } 52
  • 53. ?> <html> <script> window.alert("Invalid Signin"); </script> </font></html> rs.html Main HTML Module (uses Bootstrap navbar structure) <!DOCTYPE html> <html lang="en"> <head> <?php session_start(); ?> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title>Response STAT</title> <!-- Bootstrap core CSS --> <link href="bootstrap.min.css" rel="stylesheet"> <!-- Bootstrap Cosmo Theme CSS --> <link href="spacelab.bootstrap.min.css" rel="stylesheet" integrity="sha256-IF1P9CSIVOaY4nBb5jATvBGnxMn/4dB9JNTLqdxKN9w= sha512- UsfHxnPESse3RgYeaoQ7X2yXYSY5f6sB6UT48+F2GhNLqjbPhtwV2WCUQ3eQxeghkbl9PioaTOHNA+T0wN ki2w==" 53
  • 54. crossorigin="anonymous"> <!-- Custom styles for this template --> </head> <!-- ================ Banner ================ --> <div class="container under-nav"> <img src="statBanner.jpg" data-toggle="modal" data-target="#outModal" alt="banner" height="90" width="1140"> </div> <body style="background-image:url(medical/lib/background.jpg);background-repeat: no-repeat; background-size: 1400px, 650px, auto;"> <!-- <script src="https://cybermap.kaspersky.com/assets/scripts/widget.js" async defer></script> ****future use --> <!-- ========== Register modal ========== --><!-- ========== Register modal ========== --><!-- ========== Register modal ========== --> <div class="modal fade" id="registerModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria- label="Close"><span aria-hidden="true">&times;</span></button> <h1 class="modal-title"><font color="darkblue">Register</h1> </div> <div class="modal-body well"> <!-- ================ Form ================ --> 54
  • 55. <form class="form-horizontal" method="post" action="registerIndex.php"> <div class="form-group"> <label for="firstName" class="col-sm-4 control- label">First Name</label> <div class="col-sm-6"> <input type="text" class="form-control" name="firstName" id="firstName" placeholder="First Name" required autofocus> </div> </div> <div class="form-group"> <label for="lastName" class="col-sm-4 control- label">Last Name</label> <div class="col-sm-6"> <input type="text" class="form-control" name="lastName" id="lastName" placeholder="Last Name" required> </div> </div> <div class="form-group"> <label for="email" class="col-sm-4 control- label">Email</label> <div class="col-sm-6"> <input type="email" class="form-control" name="email" placeholder="email" required> 55
  • 56. </div> </div> <div class="form-group"> <label for="Password" class="col-sm-4 control- label">Password</label> <div class="col-sm-6"> <input type="password" class="form-control" name="Password" placeholder="Password" required> </div> </div> <div class="form-group"> <div class="col-sm-offset-5 col-sm-3"> <button type="submit" class="btn btn- primary">Register</button> </div></div> <div class="form-group"> <div><img src="register.jpg" height="200" width="585"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data- dismiss="modal">Close</button> </div></div></div> </form> <!-- /.modal-content --> </div> </div> 56
  • 57. <!-- /.modal-dialog --> </div> <!-- ========== Log out modal ========= --><!-- ========== Log out modal ========= --><!-- ========== Log out modal ========= --> <div class="modal fade" id="outModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria- label="Close"><span aria-hidden="true">&times;</span></button> <h1 class="modal-title"><font color="darkblue">Logout</h1></font> </div> <div class="modal-body"> <!-- ================ Form ================ --> <form class="form-horizontal" method="post" action="logout.php" id="logoutForm"> <div class="form-group"> <label for="email" class="col-sm-4 control- label"></label> <!-- <div class="col-sm-4"> <input type="email" class="form-control" name="email" id="email2" placeholder ="CONFIRM LOGOFF" disabled> </div> --> </div> <div class="form-group"> <div class="col-sm-offset-5"> 57
  • 58. <button type="submit" class="btn btn- primary">Confirm Logoff</button></br></div> </div> <div> <img src="goodDay.jpg" height="300" width="560"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data- dismiss="modal">Close</button> </div> </form> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div></div> <!-- ========== Batch modal ========= --><!-- ========== Batch modal ========= --><!-- ========== Batch modal ========= --> <div class="modal fade" id="batModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria- label="Close"><span aria-hidden="true">&times;</span></button> 58
  • 59. <h4 class="modal-title"><font color="darkblue"></h4><h1>Start Mosquito</h1> <img src="communication-rules.jpg" height="220" width="568"></div><h4 class="modal-title"><font color="red">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ems p;&emsp;<font color="white"> ....</font>Click </br>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&em sp;<font color="white">....</font>initiate! </font></h4><h5> </h5><h6></h6> <h5></h5> <div class="modal-body"> <!-- ================ Form ================ --> <form class="form-horizontal" method="post" action="batch.php" id="batForm"> <!--<div class="form-group"> --> <!-- <label for="email" class="col-sm-4 control- label">Email</label> <div class="col-sm-6"> <input type="email" class="form-control" name="email" value="<?php echo $_SESSION['email'];?>" id="email" disabled> </div>--><div class="form-group"> <div class="col-sm-offset-5"> <button type="Run" class="btn btn-primary"> <font color="white">Initiate</font></button></br> <label for="xx" class="col- sm-4 control-label"><h6><font color="darkblue"> </h6></label></div> </div> <div class="form-group"> <label for="command" class="col-sm-3 control- label"><h6><font color="darkblue"> Admin ONLY => </h6></label> 59
  • 60. <div class="col-sm-6"> <input type="text" class="form-control" name="command" id="command" placeholder =" Batch File or Command"</br><font size="2" color="red">&emsp; <font color="white"> .............</font>NO ENTRY ABOVE</font> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data- dismiss="modal">Close</button> </div> </div> </form> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- ========== Report modal ========= --><!-- ========== Report modal ========= --><!-- ========== Report modal ========= --> <div class="modal fade" id="reportModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria- label="Close"><span 60
  • 61. aria-hidden="true">&times;</span></button> <h4 class="modal-title"><font color="darkblue"></h4><h1>Reporting</h1> <img src="hr-report.jpg" height="220" width="568"></div><h5> </h5><h6></h6> <h5></h5> <div class="modal-body"> <!-- ================ Form ================ --> <form class="form-horizontal" method="post" action="jreport.php" id="reportForm"> <div class="form-group"> <div class="col-sm-offset-5"> <button type="Run" class="btn btn-primary"> <font color="white">Dispatch Query</font></button></br></br> </div> </div> </form> <form class="form-horizontal" method="post"action="kreport.php" id="reportForm2"> <div class="col-sm-offset-15"> <button type="Run" class="btn btn-primary"> <font color="white">Dispatch Report</font></button></br></br> </div> </form> 61
  • 62. <form class="form-horizontal" method="post" action="ureport.php" id="reportForm2"> <div class="col-sm-offset-5"> <button type="Run" class="btn btn-primary"> <font color="white">User ID Query</font></button></br></br> </div> </form> <form class="form-horizontal" method="post" action="utreport.php" id="reportForm2"> <div class="col-sm-offset-15"> <button type="Run" class="btn btn-primary"> <font color="white">Logged In Query</font></button></br></br> </div> </form> <div class="modal-footer"> <button type="button" class="btn btn-default" data- dismiss="modal">Close</button> </div> </div> </form> </div> <!-- /.modal-content --> 62
  • 63. </div> <!-- /.modal-dialog --> </div> <!-- ================ NAV Bar ================ --><!-- ================ NAV Bar ================ --><!-- ================ NAV Bar ================ --> <!-- ================ NAV Bar ================ --><!-- ================ NAV Bar ================ --><!-- ================ NAV Bar ================ --> <div class="navbar-wrapper"> <div class="container"> <nav class="navbar navbar-inverse navbar-static-top" id="nav"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data- toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span><span class="icon- bar"></span> </button> <!-- <a class="navbar-brand" href="#">Response STAT</a> --> <a class="navbar-brand" href="#"><h4></h4</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> 63
  • 64. <li><a href="#" data-toggle="modal" data- target="#registerModal">Register</a></li> <li> <a href="#" id="login" data-toggle="modal" data-target="#myModal">Sign In</a> </li> <li> <a href="#" id="logout" data-toggle="modal" data-target="#outModal"><!-- onclick.= "$.get( 'getemail.php', function( data ) {$('#email').val(data);});$('#email').prop('disabled', true); $('#email2').val(data);});$('#email2').prop('disabled', true);"--> Logoff</a> </li> <li><a href="rs.php">Home</a></li><li> <a href="#" id="bat" data-toggle="modal" data- target="#batModal">Skeeter</a> </li> <li> <a href="#" id="rpt" data-toggle="modal" data- target="#reportModal">Reporting</a> </li> <!-- <li><a href="batch.php">Batch</a></li> --><a class="navbar-brand" href="#"><h4><font color="yellow">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&e msp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; Emergency Dispatch </h4></font></span></a> </ul> </div> </div> </nav> </div> 64
  • 65. <!-- ================ Main img ================ --><!-- ================ Main img ================ --> <div class="container under-nav"> <a id="login" data-toggle="modal" data-target="#myModal"><img src="jeffstat.jpg"alt="Chopper" height="680" width="1140"></a> </div> <!-- ========== Log in modal ========== --><!-- ========== Log in modal ========== --><!-- ========== Log in modal ========== --> <div class="modal fade" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria- label="Close"><span aria-hidden="true">&times;</span></button> <h1 class="modal-title"><font color="darkblue">Log in</h1></font> </div> <div class="modal-body"> <!-- ================ Form ================ --> <form class="form-horizontal" method="post" action="signIn.php" id="loginForm"> <div class="form-group"> <label for="email" class="col-sm-4 control- label">Email</label> <div class="col-sm-6"> 65
  • 66. <input type="email" class="form-control" name="email" id="email" placeholder="Email"> </div> </div> <div class="form-group"> <label for="Password" class="col-sm-4 control- label">Password</label> <div class="col-sm-6"> <input type="password" class="form-control" name="Password" id="Password" placeholder="Password" required> </div> </div> <div class="form-group"> <div class="col-sm-offset-5"> <button type="submit" onclick="var em=$ ('#email').val();$('#email2').val(em);" id="jeff" class="btn btn-primary">Sign in</button> </div> </div> <div> <img src="welcome.jpg" height="200" width="550"></div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data- dismiss="modal">Close</button> </div> 66
  • 67. </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> </div> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="bootstrap.min.js"></script> </body> </html> 67
  • 68. registerIndex.php User Registration (Uses front end edit to prevent SQL Injection Attacks) <!DOCTYPE html> <?php /** * registerIndex.php * * Jeff Goldberg WSMS 1/2016 * Register new user */ require_once("../config.php");//database config require_once("rs.html");//Homepage format session_start(); $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $pw = ($_POST['Password']); /** * Create a password hash * * @param string $password The clear text password * @param string $salt The salt to use, or null to generate a random one 68
  • 69. * @param int $N The CPU difficultly (must be a power of 2, > 1) * @param int $r The memory difficultly * @param int $p The parallel difficultly * * @return string The hashed password */ $encrypted = sha1($pw.PW_SALT); $link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE); if ($link->connect_error) die(" Error: " . $link->connect_error); // is user already registered in db? $sql = "SELECT * FROM users WHERE email='" . $email . "'; "; //register user after verifying all fields entered and not already in db if ($link->query($sql)->num_rows == 0 && $email != '' && $firstName != '' && $lastName != '' && $encrypted != '' ) { $sql = "INSERT INTO users( username, password, email ) VALUES ( '" .$firstName. "' ,'" . $encrypted . "','" . $email . "' );"; $link->query($sql); echo("<h1>Registered</h1>"); echo '<script>'; echo 'alert("Registration Successful")'; echo '</script>'; }else{ echo '<label class="text-danger"></label>'; 69
  • 70. echo '<script>'; echo 'alert("Registration Incorrect")'; echo '</script>'; // Not safe: should $link->close(); } ?> </html> 70
  • 71. logout.php Logout Functionality <?php /** * File: logout.php * */ require_once("../config.php"); require_once("rs.html"); require_once("../scrypt.php"); 71
  • 72. session_start(); print_r($_SESSION); if ($email !='') { echo $email."....em.."; }else{ if ($_SESSION['email'] !='') { echo "SESS jeff:".$_SESSION['email']; $email = $_SESSION['email']; } } $link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE); if ($link->connect_error) { die(" Error: " . $link->connect_error); } // look for matching password in db $sql = 'SELECT * FROM users WHERE email="' . $email . '";'; $result = $link->query($sql); 72
  • 73. $compare = (sha1($password.PW_SALT)); // is user signed in? if ($result->num_rows > 0) { //$check_PW = sha1($pass.PW_SALT) $sql = 'SELECT * FROM users WHERE email="' . $email . '" AND created !=0;'; $result = $link->query($sql)->fetch_assoc(); // sign user out $sql = 'UPDATE users SET created= 0 WHERE email="' . $email . '" AND created !=0;'; $result = $link->query($sql); $cmp = `password`; $result = $link->query($sql); $_POST['email'] = $email; $_SESSION['email'] = $email; } else { $_SESSION['email'] = $email; $_POST['email'] = $email; } ?> 73
  • 74. kreport.php Dispatch Report with Inner Join of Dispatch and Hospital Tables <?php session_start(); require_once('/var/www/config.php'); $records_per_page = 100; $cur_page = (int)$_GET['cur_page']; if (!$cur_page || $cur_page == 0){ $cur_page=1; } 74
  • 75. //need: host, user, password, database $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, "emetromedical"); //GET COUNT OF RECORDS $sql_count = "SELECT count(*) AS COUNT FROM dispatch INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid"; $result1 = $link->query($sql_count); foreach ($result1 as $row){ $total_records = $row['COUNT']; } //join query notes //SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city, dispatch.stamp AS DispatchDateTimeStamp //FROM dispatch, hospital //WHERE dispatch.hospitalid = hospital.hospitalid //run the actual query $sql_query = "SELECT dispatch.hospitalid, hospital.name, hospital.address1, hospital.city, dispatch.stamp FROM dispatch INNER JOIN hospital ON dispatch.hospitalid=hospital.hospitalid LIMIT 0,".$records_per_page; $result = $link->query($sql_query); //REPORT HEADER $content = '<table width="100%"><thead><tr>'; 75
  • 76. $content .= '<td width="20%">ID</td><td width="20%">HospitalName</td><td width="20%">Address</td><td width="20%">City</td><td width="20%">DispatchDateTime</td></thead>'; $content .= "<tbody>"; foreach($result as $row){ //COLLECT INFO FROM DB -> ASSIGN TO VARIABLES $hospitalid = $row['hospitalid']; $hospitalname = $row['name']; $address = $row['address1']; $city = $row['city']; $dispatchdatetime = $row['stamp']; //APPEND INFO FROM VARIABLES TO OUTPUT BUFFER/VARIABLE $content .= "<td>".$hospitalid."</td><td>".$hospitalname."</td><td>". $address."</td><td>".$city."</td><td>".$dispatchdatetime."</td></tr>"; } //REPORT FOOTER $prev_page = $cur_page -1; $next_page = $cur_page +1; if ($cur_page > 1){ $pagination = '<a href="report.php?cur_page='.$prev_page.'"><<< Previous</a>'; } $pagination .= '&nbsp;<a href="report.php?cur_page='.$next_page.'">Next >>></a>'; $pages = ceil($total_records/$records_per_page); $content .= '<tr><td align="center" colspan=5>'.$pagination.'</td></tr>'; $content .= '<tr><td align="center" colspan=5>Total Pages:'.$pages.'</td></tr>'; 76
  • 78. jreport.php Dispatch Table Query <?php /* jreport.php Dispatch table query Jeff Goldberg WSMS 1/2016 return detail by date and timestamp */ require_once('database_template.php'); $database = "emetromedical"; $query = "select * from dispatch"; $result = query_db($query, $database); foreach($result as $row){ $hospitalid = $row['hospitalid']; //$hospitalname = $row['name']; future use - join tables //$address = $row['address1']; //$city = $row['city']; $dispatchdatetime = $row['stamp']; $dispatchipaddr = $row['ipaddr']; $dispatchpatient = $row['patientid']; 78
  • 79. $options .= '<option id="' . $dispatchdatetime . '">' . $dispatchdatetime . '</option>'; } //above loop retrieves DB detail ?> <html> <head> <script src="jquery-2.1.4.min.js"></script> <script> $( document ).ready(function() { $("#selector").val("Select Item");//Set dropdown to "Select Item" $("#selector").change(function() {//generates trigger for calling db var stamp = $("#selector").children(":selected").attr("id");//gets the value of dropdown $.get( "inventoryj_callback.php", { stamp: stamp } ) //backend call to db, passing through sku variable .done(function( data ) { console.log(data); 79
  • 80. var returndata = $.parseJSON(data);//return order is [0]=stamp,[1]=ip,[2]=patient [3]=hospital, console.log(' data '); console.log(data); console.log(returndata); utreport.php User Table Query by Timestamp Reports on all Signed In Users (using JSON Callback to database) 80
  • 81. <?php /* utreport.php User table query Jeff Goldberg WSMS 1/2016 return detail by timestamp */ require_once('database_template.php'); $database = "users"; $query = "select * from users"; $result = query_db($query, $database); foreach($result as $row){ $username = $row['username']; $email = $row['email']; $created = $row['created']; // signed in user will have a positive timestamp if ($created > 0) { $options .= '<option id="' . $created . '">' . $username . '</option>'; 81
  • 82. } } //above loop retrieves DB detail ?> <html> <head> <script src="jquery-2.1.4.min.js"></script> <script> $( document ).ready(function() { $("#selector").val("Select Item");//Set dropdown to "Select Item" $("#selector").change(function() {//generates trigger for calling db var created = $("#selector").children(":selected").attr("id");//gets the value of dropdown $.get( "usertCallback.php", { created: created } ) //backend call to db, passing through user signon variable .done(function( data ) { var returndata = $.parseJSON(data);//return order is [0]=username,[1]=email,[2]=created console.log(' data '); console.log(data); console.log(returndata); 82
  • 83. $("#username").val(returndata[0]); $("#email").val(returndata[1]); $("#created").val(returndata[2]); }); }); }); </script> </head> <body> <center><font color=blue><h1>Users Table Query</h1></font></center> <center><font color=gray><h2>by User Signin Status</h2></font></center><br /><br /><br /><br /><br /> <!-- Date - select<br /><br /> --> <center> <select id="selector"><option id="0" selected="selected">Select Item</option></center><br /><br /> <?php echo $options; ?> </select> <br /> 83
  • 84. <br /> <br /> <br /> User Signin Status:<br /><br /><br /> <font color=blue> User ID : &emsp; <input id="username" value=""><br /><br /> eMail : &emsp;&emsp;<input id="email" value=""><br /><br /> Signed In:&emsp;<input id="created" value=""><br /><br /> <br /><br /><br /></br><br /><br /><br /> </font> <div id="imgHolder"></div> <a class="btn" href="../logout.php"> <button class="btn" type="submit">Close</button></a></br><br /><br /><br /></br><br /><br /><br /></br><br /><br /><br /></br><br /><br /><br /> </body> </html> <?php usertCallback.php json callback for required detail // JSON Callback to database for specific row detail 84
  • 85. // // Jeff Goldberg WSMS 1/2016 // // usertCallback.php component of ureport.php // require_once('database_template.php'); $database = "users"; $created = $_GET['created']; $query = "SELECT * FROM users WHERE created ='".$created."'"; $results = query_db($query, $database); foreach($results as $row){ $aryDetails[0] = $row['username']; $aryDetails[1] = $row['email']; $aryDetails[2] = $row['created']; } echo json_encode($aryDetails); ?> 85
  • 86. ureport.php User Table Query Reports on Registered Users (using JSON Callback to database) <?php /* ureport.php User table query Jeff Goldberg WSMS 1/2016 86
  • 87. return detail by username */ require_once('database_template.php'); $database = "users"; $query = "select * from users"; $result = query_db($query, $database); foreach($result as $row){ $username = $row['username']; $email = $row['email']; $created = $row['created']; $options .= '<option id="' . $username . '">' . $username . '</option>'; } //above loop retrieves DB detail ?> <html> <head> <script src="jquery-2.1.4.min.js"></script> <script> $( document ).ready(function() { 87
  • 88. $("#selector").val("Select Item");//Set dropdown to "Select Item" $("#selector").change(function() {//generates trigger for calling db var username = $("#selector").children(":selected").attr("id");//gets the value of dropdown $.get( "userCallback.php", { username: username } ) //backend call to db, passing through sku variable .done(function( data ) { console.log(' pr1-data '); console.log(data); var returndata = $.parseJSON(data);//return order is [0]=username,[1]=email,[2]=created console.log(' data '); console.log(data); console.log(returndata); $("#username").val(returndata[0]); $("#email").val(returndata[1]); $("#created").val(returndata[2]); }); }); }); </script> </head> <body> <center><font color=blue><h1>Users Table Query</h1></font></center> <center><font color=gray><h2>by User</h2></font></center><br /><br /><br /><br /><br /> <!-- Date - select<br /><br /> --> 88
  • 89. <center>&emsp;&emsp;&emsp;&emsp; <select id="selector"><option id="0" selected="selected">Select Item</option></center><br /><br /> <?php echo $options; ?> </select> <br /> <br /> <br /> <br /> &emsp;&emsp; User Details:<br /><br /> <font color=blue> User:&emsp;&emsp;&emsp;&emsp;<input id="username" value=""><br /><br /> eMail add:&emsp;&emsp;<input id="email" value=""><br /><br /> Signed In:&emsp;&emsp;<input id="created" value=""><br /><br /> <br /><br /><br /></br><br /><br /><br /> </font> <div id="imgHolder"></div> <a class="btn" href="../logout.php"> <button class="btn" type="submit">Close</button></a></br><br /><br /><br /></br><br /><br /><br /></br><br /><br /><br /></br><br /><br /><br /> 89
  • 90. </body> </html> userCallback.php json callback for required detail <?php // JSON Callback to database for specific row detail // // Jeff Goldberg WSMS 1/2016 // // userCallback.php component of ureport.php // require_once('database_template.php'); $database = "users"; $username = $_GET['username']; $query = "SELECT * FROM users WHERE username ='".$username."'"; $results = query_db($query, $database); foreach($results as $row){ $aryDetails[0] = $row['username']; $aryDetails[1] = $row['email']; $aryDetails[2] = $row['created']; } 90
  • 91. echo json_encode($aryDetails); ?> User Database User Table Password Salted and Encrypted 91
  • 93. 93
  • 94. 94
  • 95. 95
  • 96. 96
  • 97. 97
  • 98. Admin User NOT Signed In - BLOCKED 98
  • 99. Admin Signed In Executes lshw 99