first commit
This commit is contained in:
commit
81473bd9fe
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
# HTID:23459598: DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES BELOW
|
||||||
|
php_value display_errors 1
|
||||||
|
# DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES ABOVE HTID:23459598:
|
|
@ -0,0 +1,237 @@
|
||||||
|
<?php
|
||||||
|
$servername = "localhost";
|
||||||
|
// Your Database name
|
||||||
|
$dbname = "id22388794_esp_data";
|
||||||
|
// Your Database user
|
||||||
|
$username = "id22388794_touchlight";
|
||||||
|
// Your Database user password
|
||||||
|
$password = "N4nd4155#";
|
||||||
|
|
||||||
|
function createOutput($name, $board, $gpio, $state) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO Outputs (name, board, gpio, state)
|
||||||
|
VALUES ('" . $name . "', '" . $board . "', '" . $gpio . "', '" . $state . "')";
|
||||||
|
|
||||||
|
if ($conn->query($sql) === TRUE) {
|
||||||
|
return "New output created successfully";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Error: " . $sql . "<br>" . $conn->error;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteOutput($id) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM Outputs WHERE id='". $id . "'";
|
||||||
|
|
||||||
|
if ($conn->query($sql) === TRUE) {
|
||||||
|
return "Output deleted successfully";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Error: " . $sql . "<br>" . $conn->error;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateOutput($id, $state) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE Outputs SET state='" . $state . "' WHERE id='". $id . "'";
|
||||||
|
|
||||||
|
if ($conn->query($sql) === TRUE) {
|
||||||
|
return "Output state updated successfully";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Error: " . $sql . "<br>" . $conn->error;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAllOutputs() {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT id, name, board, gpio, state FROM Outputs ORDER BY board";
|
||||||
|
if ($result = $conn->query($sql)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAllOutputStates($board) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT gpio, state FROM Outputs WHERE board='" . $board . "'";
|
||||||
|
if ($result = $conn->query($sql)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOutputBoardById($id) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT board FROM Outputs WHERE id='" . $id . "'";
|
||||||
|
if ($result = $conn->query($sql)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateLastBoardTime($board) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE Boards SET last_request=now() WHERE board='". $board . "'";
|
||||||
|
|
||||||
|
if ($conn->query($sql) === TRUE) {
|
||||||
|
return "Output state updated successfully";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Error: " . $sql . "<br>" . $conn->error;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAllBoards() {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT board, last_request FROM Boards ORDER BY board";
|
||||||
|
if ($result = $conn->query($sql)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBoard($board) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT board, last_request FROM Boards WHERE board='" . $board . "'";
|
||||||
|
if ($result = $conn->query($sql)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function createBoard($board) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO Boards (board) VALUES ('" . $board . "')";
|
||||||
|
|
||||||
|
if ($conn->query($sql) === TRUE) {
|
||||||
|
return "New board created successfully";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Error: " . $sql . "<br>" . $conn->error;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteBoard($board) {
|
||||||
|
global $servername, $username, $password, $dbname;
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
// Check connection
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM Boards WHERE board='". $board . "'";
|
||||||
|
|
||||||
|
if ($conn->query($sql) === TRUE) {
|
||||||
|
return "Board deleted successfully";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "Error: " . $sql . "<br>" . $conn->error;
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
include_once('esp-database.php');
|
||||||
|
|
||||||
|
$action = $id = $name = $gpio = $state = "";
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$action = test_input($_POST["action"]);
|
||||||
|
if ($action == "output_create") {
|
||||||
|
$name = test_input($_POST["name"]);
|
||||||
|
$board = test_input($_POST["board"]);
|
||||||
|
$gpio = test_input($_POST["gpio"]);
|
||||||
|
$state = test_input($_POST["state"]);
|
||||||
|
$result = createOutput($name, $board, $gpio, $state);
|
||||||
|
|
||||||
|
$result2 = getBoard($board);
|
||||||
|
if(!$result2->fetch_assoc()) {
|
||||||
|
createBoard($board);
|
||||||
|
}
|
||||||
|
echo $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "No data posted with HTTP POST.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "GET") {
|
||||||
|
$action = test_input($_GET["action"]);
|
||||||
|
if ($action == "outputs_state") {
|
||||||
|
$board = test_input($_GET["board"]);
|
||||||
|
$result = getAllOutputStates($board);
|
||||||
|
if ($result) {
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$rows[$row["gpio"]] = $row["state"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($rows);
|
||||||
|
$result = getBoard($board);
|
||||||
|
if($result->fetch_assoc()) {
|
||||||
|
updateLastBoardTime($board);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ($_GET["action"] == "output_update") {
|
||||||
|
$id = test_input($_GET["id"]);
|
||||||
|
$state = test_input($_GET["state"]); // Check if state is correctly received
|
||||||
|
|
||||||
|
if ($state == 0) {
|
||||||
|
$newState = 1; // Update state based on your logic (if needed)
|
||||||
|
} else {
|
||||||
|
$newState = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = updateOutput($id, $newState);
|
||||||
|
echo $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ($action == "output_delete") {
|
||||||
|
$id = test_input($_GET["id"]);
|
||||||
|
$board = getOutputBoardById($id);
|
||||||
|
if ($row = $board->fetch_assoc()) {
|
||||||
|
$board_id = $row["board"];
|
||||||
|
}
|
||||||
|
$result = deleteOutput($id);
|
||||||
|
$result2 = getAllOutputStates($board_id);
|
||||||
|
if(!$result2->fetch_assoc()) {
|
||||||
|
deleteBoard($board_id);
|
||||||
|
}
|
||||||
|
echo $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "Invalid HTTP request.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_input($data) {
|
||||||
|
$data = trim($data);
|
||||||
|
$data = stripslashes($data);
|
||||||
|
$data = htmlspecialchars($data);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,129 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
if (!isset($_SESSION['user'])) {
|
||||||
|
// Jika sesi tidak ada, arahkan pengguna ke halaman login
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parameter koneksi database
|
||||||
|
$servername = "localhost";
|
||||||
|
$username = "id22388794_touchlight"; // ganti dengan username MySQL Anda
|
||||||
|
$password = "N4nd4155#"; // ganti dengan password MySQL Anda
|
||||||
|
$database = "id22388794_esp_data"; // ganti dengan nama database Anda
|
||||||
|
|
||||||
|
// Membuat koneksi
|
||||||
|
$koneksi = new mysqli($servername, $username, $password, $database);
|
||||||
|
|
||||||
|
// Memeriksa koneksi
|
||||||
|
if ($koneksi->connect_error) {
|
||||||
|
die("Koneksi gagal: " . $koneksi->connect_error);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
include_once('esp-database.php');
|
||||||
|
|
||||||
|
$result = getAllOutputs();
|
||||||
|
$html_buttons = null;
|
||||||
|
if ($result) {
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
if ($row["state"] == "1"){
|
||||||
|
$button_checked = "checked";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$button_checked = "";
|
||||||
|
}
|
||||||
|
$html_buttons .= '<h3>' . $row["name"] . ' - Board '. $row["board"] . ' - GPIO ' . $row["gpio"] . ' (<i><a onclick="deleteOutput(this)" href="javascript:void(0);" id="' . $row["id"] . '">Delete</a></i>)</h3><label class="switch"><input type="checkbox" onchange="updateOutput(this)" id="' . $row["id"] . '" ' . $button_checked . '><span class="slider"></span></label>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result2 = getAllBoards();
|
||||||
|
$html_boards = null;
|
||||||
|
if ($result2) {
|
||||||
|
$html_boards .= '<h3>Boards</h3>';
|
||||||
|
while ($row = $result2->fetch_assoc()) {
|
||||||
|
$row_reading_time = $row["last_request"];
|
||||||
|
// Uncomment to set timezone to - 1 hour (you can change 1 to any number)
|
||||||
|
//$row_reading_time = date("Y-m-d H:i:s", strtotime("$row_reading_time - 1 hours"));
|
||||||
|
|
||||||
|
// Uncomment to set timezone to + 4 hours (you can change 4 to any number)
|
||||||
|
//$row_reading_time = date("Y-m-d H:i:s", strtotime("$row_reading_time + 7 hours"));
|
||||||
|
$html_boards .= '<p><strong>Board ' . $row["board"] . '</strong> - Last Request Time: '. $row_reading_time . '</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" type="text/css" href="esp-style.css">
|
||||||
|
<title>TouchLight Dashboard</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>TouchLight</h2>
|
||||||
|
<a href="logout.php">Logout</a> <!-- Tombol Logout -->
|
||||||
|
<?php echo $html_buttons; ?>
|
||||||
|
<br><br>
|
||||||
|
<?php echo $html_boards; ?>
|
||||||
|
<br><br>
|
||||||
|
<div><form onsubmit="return createOutput();">
|
||||||
|
<h3>Create New Output</h3>
|
||||||
|
<label for="outputName">Name</label>
|
||||||
|
<input type="text" name="name" id="outputName"><br>
|
||||||
|
<label for="outputBoard">Board ID</label>
|
||||||
|
<input type="number" name="board" min="0" id="outputBoard">
|
||||||
|
<label for="outputGpio">GPIO Number</label>
|
||||||
|
<input type="number" name="gpio" min="0" id="outputGpio">
|
||||||
|
<label for="outputState">Initial GPIO State</label>
|
||||||
|
<select id="outputState" name="state">
|
||||||
|
<option value="0">0 = OFF</option>
|
||||||
|
<option value="1">1 = ON</option>
|
||||||
|
</select>
|
||||||
|
<input type="submit" value="Create Output">
|
||||||
|
<p><strong> <img class="warning-icon" src="logo.png" alt="Warning icon" style="vertical-align: middle;"> Note:</strong> </p> In some devices, you might need to refresh the page to see your newly created buttons or to remove deleted buttons.
|
||||||
|
</form></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function updateOutput(element) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var newState = element.checked ? 1 : 0; // Set state based on checkbox checked state
|
||||||
|
xhr.open("GET", "esp-outputs-action.php?action=output_update&id="+element.id+"&state="+newState, true);
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function deleteOutput(element) {
|
||||||
|
var result = confirm("Want to delete this output?");
|
||||||
|
if (result) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("GET", "esp-outputs-action.php?action=output_delete&id="+element.id, true);
|
||||||
|
xhr.send();
|
||||||
|
alert("Output deleted");
|
||||||
|
setTimeout(function(){ window.location.reload(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createOutput(element) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "esp-outputs-action.php", true);
|
||||||
|
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||||
|
alert("Output created");
|
||||||
|
setTimeout(function(){ window.location.reload(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var outputName = document.getElementById("outputName").value;
|
||||||
|
var outputBoard = document.getElementById("outputBoard").value;
|
||||||
|
var outputGpio = document.getElementById("outputGpio").value;
|
||||||
|
var outputState = document.getElementById("outputState").value;
|
||||||
|
var httpRequestData = "action=output_create&name="+outputName+"&board="+outputBoard+"&gpio="+outputGpio+"&state="+outputState;
|
||||||
|
xhr.send(httpRequestData);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,138 @@
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
display: inline-block;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #f7f9fc;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
color: #556b2f;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 30px auto;
|
||||||
|
padding: 0 20px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding-bottom: 25px;
|
||||||
|
transition: all 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
body:hover {
|
||||||
|
box-shadow: 0 16px 32px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
width: 120px;
|
||||||
|
height: 68px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: #dcdcdc;
|
||||||
|
border-radius: 34px;
|
||||||
|
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
|
||||||
|
transition: background-color 0.4s, box-shadow 0.4s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider:before {
|
||||||
|
position: absolute;
|
||||||
|
content: "";
|
||||||
|
height: 52px;
|
||||||
|
width: 52px;
|
||||||
|
left: 8px;
|
||||||
|
bottom: 8px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
transition: transform 0.4s, box-shadow 0.4s;
|
||||||
|
border-radius: 50%;
|
||||||
|
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + .slider {
|
||||||
|
background-color: #7cb342;
|
||||||
|
box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + .slider:before {
|
||||||
|
transform: translateX(52px);
|
||||||
|
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=text], input[type=number], select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 14px 20px;
|
||||||
|
margin: 10px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 2px solid #dcdcdc;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background-color: #fafafa;
|
||||||
|
transition: border-color 0.3s, background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=text]:focus, input[type=number]:focus, select:focus {
|
||||||
|
border-color: #7cb342;
|
||||||
|
background-color: #ffffff;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=submit] {
|
||||||
|
width: 100%;
|
||||||
|
background-color: #7cb342;
|
||||||
|
color: white;
|
||||||
|
padding: 14px 20px;
|
||||||
|
margin: 10px 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
transition: background-color 0.3s, transform 0.3s, box-shadow 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=submit]:hover {
|
||||||
|
background-color: #558b2f;
|
||||||
|
transform: translateY(-3px);
|
||||||
|
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-icon {
|
||||||
|
width: 20px; /* Ukuran ikon */
|
||||||
|
height: 20px;
|
||||||
|
margin-right: 5px; /* Jarak antara ikon dengan teks di sebelah kanan */
|
||||||
|
vertical-align: middle; /* Memastikan ikon berada di tengah vertikal dengan teks */
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
text-align: left;
|
||||||
|
border-radius: 10px;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
padding: 20px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
transition: background-color 0.3s, box-shadow 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
div:hover {
|
||||||
|
background-color: #ffffff;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
|
@ -0,0 +1,244 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" type="text/css" href="esp-style.css">
|
||||||
|
<title>LighTouch Dashboard</title>
|
||||||
|
<style>
|
||||||
|
/* Gaya untuk sidebar */
|
||||||
|
.sidebar {
|
||||||
|
height: 100%;
|
||||||
|
width: 300px; /* Lebar sidebar */
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: -300px; /* Mulai tersembunyi di luar layar */
|
||||||
|
background-color: #1e2a38; /* Warna latar belakang sidebar */
|
||||||
|
color: #fff;
|
||||||
|
padding-top: 30px;
|
||||||
|
transition: left 0.3s ease; /* Transisi animasi */
|
||||||
|
box-shadow: 0 2px 5px rgba(0,0,0,0.3); /* Bayangan untuk sidebar */
|
||||||
|
z-index: 1000; /* Agar sidebar berada di atas konten */
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar h2 {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
color: #f1f1f1; /* Warna teks */
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar a {
|
||||||
|
padding: 15px 20px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 18px;
|
||||||
|
color: #b0bec5; /* Warna tautan */
|
||||||
|
display: block;
|
||||||
|
border-bottom: 1px solid #334755; /* Garis bawah tautan */
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar a:hover {
|
||||||
|
background-color: #334755; /* Warna latar belakang tautan saat hover */
|
||||||
|
color: #fff; /* Warna teks tautan saat hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .exit-button {
|
||||||
|
padding: 15px 20px;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #ff4d4d; /* Warna tombol Exit */
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 5px; /* Sudut membulat tombol */
|
||||||
|
box-shadow: 0 2px 5px rgba(0,0,0,0.3); /* Bayangan tombol */
|
||||||
|
margin-top: 20px; /* Jarak dari menu sebelumnya */
|
||||||
|
margin-bottom: 30px; /* Jarak dari bawah sidebar */
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .exit-button:hover {
|
||||||
|
background-color: #e60000; /* Warna tombol Exit saat hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
.open-btn {
|
||||||
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
left: 20px;
|
||||||
|
font-size: 24px;
|
||||||
|
background: #1e2a38;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 15px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 5px; /* Sudut membulat tombol */
|
||||||
|
box-shadow: 0 2px 5px rgba(0,0,0,0.3); /* Bayangan tombol */
|
||||||
|
z-index: 1001; /* Agar tombol berada di atas konten */
|
||||||
|
}
|
||||||
|
|
||||||
|
.open-btn:hover {
|
||||||
|
background: #334755; /* Warna latar belakang tombol saat hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 15px;
|
||||||
|
right: 15px;
|
||||||
|
font-size: 30px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #b0bec5; /* Warna ikon close */
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn:hover {
|
||||||
|
color: #fff; /* Warna ikon close saat hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
transition: margin-left 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsif untuk tampilan smartphone */
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.sidebar {
|
||||||
|
width: 100%; /* Lebar penuh pada smartphone */
|
||||||
|
left: -100%; /* Mulai tersembunyi di luar layar */
|
||||||
|
}
|
||||||
|
|
||||||
|
.open-btn {
|
||||||
|
font-size: 18px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
transition: none; /* Menghilangkan transisi untuk tampilan mobile */
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .exit-button {
|
||||||
|
position: relative;
|
||||||
|
margin-top: 20px; /* Jarak dari menu sebelumnya */
|
||||||
|
margin-bottom: 20px; /* Jarak dari bawah sidebar */
|
||||||
|
width: calc(100% - 40px); /* Lebar tombol Exit disesuaikan dengan padding */
|
||||||
|
left: 20px;
|
||||||
|
background-color: #ff4d4d; /* Warna tombol Exit */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<button class="open-btn" onclick="toggleSidebar()">☰</button>
|
||||||
|
|
||||||
|
<div id="mySidebar" class="sidebar">
|
||||||
|
<span class="close-btn" onclick="toggleSidebar()">×</span>
|
||||||
|
<h2>Account</h2>
|
||||||
|
<a href="#">Profile</a>
|
||||||
|
<a href="#">Settings</a>
|
||||||
|
<a href="#">Support</a>
|
||||||
|
<button class="exit-button" onclick="window.location.href='logout.php'">Exit</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="main" class="main-content">
|
||||||
|
<h2>LighTouch</h2>
|
||||||
|
<?php echo $html_buttons; ?>
|
||||||
|
<br><br>
|
||||||
|
<?php echo $html_boards; ?>
|
||||||
|
<br><br>
|
||||||
|
<div>
|
||||||
|
<form onsubmit="return createOutput();">
|
||||||
|
<h3>Create New Output</h3>
|
||||||
|
<label for="outputName">Name</label>
|
||||||
|
<input type="text" name="name" id="outputName"><br>
|
||||||
|
<label for="outputBoard">Board ID</label>
|
||||||
|
<input type="number" name="board" min="0" id="outputBoard">
|
||||||
|
<label for="outputGpio">GPIO Number</label>
|
||||||
|
<input type="number" name="gpio" min="0" id="outputGpio">
|
||||||
|
<label for="outputState">Initial GPIO State</label>
|
||||||
|
<select id="outputState" name="state">
|
||||||
|
<option value="0">0 = OFF</option>
|
||||||
|
<option value="1">1 = ON</option>
|
||||||
|
</select>
|
||||||
|
<input type="submit" value="Create Output">
|
||||||
|
<p><strong> <img class="warning-icon" src="logo.png" alt="Warning icon" style="vertical-align: middle;"> Note:</strong> </p>
|
||||||
|
In some devices, you might need to refresh the page to see your newly created buttons or to remove deleted buttons.
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var isHalfOpen = false;
|
||||||
|
|
||||||
|
function toggleSidebar() {
|
||||||
|
var sidebar = document.getElementById("mySidebar");
|
||||||
|
var mainContent = document.getElementById("main");
|
||||||
|
var screenWidth = window.innerWidth;
|
||||||
|
|
||||||
|
if (screenWidth <= 600) {
|
||||||
|
// Jika tampilan pada smartphone
|
||||||
|
if (sidebar.style.left === "0px") {
|
||||||
|
sidebar.style.left = isHalfOpen ? "0" : "-100%"; /* Tutup seluruhnya */
|
||||||
|
isHalfOpen = !isHalfOpen; /* Toggle status separuh terbuka */
|
||||||
|
} else {
|
||||||
|
sidebar.style.left = "0";
|
||||||
|
isHalfOpen = false; /* Set status separuh terbuka ke false saat sidebar dibuka */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Jika tampilan pada desktop
|
||||||
|
if (sidebar.style.left === "0px") {
|
||||||
|
sidebar.style.left = isHalfOpen ? "0" : "-300px"; /* Tutup seluruhnya */
|
||||||
|
isHalfOpen = !isHalfOpen; /* Toggle status separuh terbuka */
|
||||||
|
} else {
|
||||||
|
sidebar.style.left = "0";
|
||||||
|
isHalfOpen = false; /* Set status separuh terbuka ke false saat sidebar dibuka */
|
||||||
|
}
|
||||||
|
mainContent.style.marginLeft = sidebar.style.left === "0px" ? "300px" : "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateOutput(element) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var state = element.checked ? 1 : 0;
|
||||||
|
xhr.open("GET", `esp-outputs-action.php?action=output_update&id=${element.id}&state=${state}`, true);
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteOutput(element) {
|
||||||
|
var result = confirm("Want to delete this output?");
|
||||||
|
if (result) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("GET", `esp-outputs-action.php?action=output_delete&id=${element.id}`, true);
|
||||||
|
xhr.send();
|
||||||
|
xhr.onload = function() {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
alert("Output deleted");
|
||||||
|
setTimeout(function() { window.location.reload(); }, 1000); // Menunggu 1 detik sebelum me-refresh
|
||||||
|
} else {
|
||||||
|
alert("Failed to delete output");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createOutput() {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "esp-outputs-action.php", true);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||||
|
alert("Output created");
|
||||||
|
setTimeout(function() { window.location.reload(); }, 1000); // Menunggu 1 detik sebelum me-refresh
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var outputName = document.getElementById("outputName").value;
|
||||||
|
var outputBoard = document.getElementById("outputBoard").value;
|
||||||
|
var outputGpio = document.getElementById("outputGpio").value;
|
||||||
|
var outputState = document.getElementById("outputState").value;
|
||||||
|
var httpRequestData = `action=output_create&name=${encodeURIComponent(outputName)}&board=${outputBoard}&gpio=${outputGpio}&state=${outputState}`;
|
||||||
|
xhr.send(httpRequestData);
|
||||||
|
|
||||||
|
return false; // Mencegah pengiriman formulir secara default
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
// Periksa apakah sesi sudah dimulai
|
||||||
|
if (session_status() == PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mengatur waktu kedaluwarsa sesi ke 30 menit (1800 detik)
|
||||||
|
$inactive = 1800;
|
||||||
|
if (isset($_SESSION['timeout'])) {
|
||||||
|
$session_life = time() - $_SESSION['timeout'];
|
||||||
|
if ($session_life > $inactive) {
|
||||||
|
session_destroy();
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$_SESSION['timeout'] = time();
|
||||||
|
|
||||||
|
// Parameter koneksi database
|
||||||
|
$servername = "localhost";
|
||||||
|
$username = "id22388794_touchlight"; // ganti dengan username MySQL Anda
|
||||||
|
$password = "N4nd4155#"; // ganti dengan password MySQL Anda
|
||||||
|
$database = "id22388794_esp_data"; // ganti dengan nama database Anda
|
||||||
|
|
||||||
|
// Membuat koneksi
|
||||||
|
$koneksi = new mysqli($servername, $username, $password, $database);
|
||||||
|
|
||||||
|
// Memeriksa koneksi
|
||||||
|
if ($koneksi->connect_error) {
|
||||||
|
die("Koneksi gagal: " . $koneksi->connect_error);
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
include "koneksi.php";
|
||||||
|
|
||||||
|
if(isset($_POST['username'])) {
|
||||||
|
$username = $_POST['username'];
|
||||||
|
$password = md5($_POST['password']);
|
||||||
|
|
||||||
|
$query = mysqli_query($koneksi, "SELECT * FROM user WHERE username='$username' AND password='$password'");
|
||||||
|
|
||||||
|
if(mysqli_num_rows($query) > 0){
|
||||||
|
$data = mysqli_fetch_array($query);
|
||||||
|
$_SESSION['user'] = $data;
|
||||||
|
echo '<script>alert("Welcome, '.$data['nama'].'");
|
||||||
|
location.href="esp-outputs.php";</script>';
|
||||||
|
} else {
|
||||||
|
echo '<script>alert("Username/password does not match.");</script>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login to the website</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form method="post">
|
||||||
|
<table align="center">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<h3>Login User</h3>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Username </td>
|
||||||
|
<td><input type="text" name="username" required></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Password </td>
|
||||||
|
<td><input type="password" name="password" required></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
<p>No Account? <a href="regis.php">Register Here</a></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
?>
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
include 'koneksi.php';
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$username = $_POST['username'];
|
||||||
|
$password = md5($_POST['password']);
|
||||||
|
$nama = $_POST['nama'];
|
||||||
|
|
||||||
|
// Query untuk memasukkan data ke dalam tabel user
|
||||||
|
$sql = "INSERT INTO user (username, password, nama) VALUES ('$username', '$password', '$nama')";
|
||||||
|
|
||||||
|
if (mysqli_query($koneksi, $sql)) {
|
||||||
|
echo '<script>alert("registration successful!"); location.href="login.php";</script>';
|
||||||
|
} else {
|
||||||
|
echo "Error: " . $sql . "<br>" . mysqli_error($koneksi);
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_close($koneksi);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>User Registration</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form method="post">
|
||||||
|
<table align="center">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<h3>User Registration</h3>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Name</td>
|
||||||
|
<td><input type="text" name="nama" required></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Username</td>
|
||||||
|
<td><input type="text" name="username" required></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Password</td>
|
||||||
|
<td><input type="password" name="password" required></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
<button type="submit">registration</button>
|
||||||
|
<p>already have an account?? <a href="login.php">Login Here</a></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* style.css */
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
width: 400px;
|
||||||
|
background: #fff;
|
||||||
|
padding: 40px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-bottom: 30px;
|
||||||
|
font-size: 28px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"], input[type="password"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
margin: 10px 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 6px;
|
||||||
|
background-color: #f8f8f8;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-color: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
padding: 14px 20px;
|
||||||
|
margin: 10px 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
font-size: 18px;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #4CAF50;
|
||||||
|
font-size: 14px;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
color: #45a049;
|
||||||
|
}
|
Loading…
Reference in New Issue