added old projects
This commit is contained in:
Generated
+7
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "mtr_server_app"
|
||||
version = "0.1.0"
|
||||
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "mtr_server_app"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,285 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 5.2.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: 127.0.0.1
|
||||
-- Generation Time: Apr 04, 2024 at 01:19 AM
|
||||
-- Server version: 10.4.32-MariaDB
|
||||
-- PHP Version: 8.0.30
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!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: `flab_u_less`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `attendance`
|
||||
--
|
||||
|
||||
CREATE TABLE `attendance` (
|
||||
`id` int(11) NOT NULL,
|
||||
`member_id` int(11) DEFAULT NULL,
|
||||
`check_in` datetime DEFAULT NULL,
|
||||
`attendance_type` varchar(255) DEFAULT NULL,
|
||||
`reference_id` int(11) DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `attendance`
|
||||
--
|
||||
|
||||
INSERT INTO `attendance` (`id`, `member_id`, `check_in`, `attendance_type`, `reference_id`) VALUES
|
||||
(401, 1, '2022-01-10 07:50:00', 'Class', 101),
|
||||
(402, 2, '2022-06-18 15:50:00', 'Personal Training', 202),
|
||||
(403, 3, '2022-02-14 09:50:00', 'Class', 103),
|
||||
(404, 4, '2022-03-21 16:50:00', 'Personal Training', 204),
|
||||
(405, 5, '2022-04-22 11:50:00', 'Personal Training', 205);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `booking`
|
||||
--
|
||||
|
||||
CREATE TABLE `booking` (
|
||||
`id` int(11) NOT NULL,
|
||||
`member_id` int(11) DEFAULT NULL,
|
||||
`booking_date` date DEFAULT NULL,
|
||||
`booking_type` varchar(255) DEFAULT NULL,
|
||||
`reference_id` int(11) DEFAULT NULL,
|
||||
`status` varchar(255) DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `booking`
|
||||
--
|
||||
|
||||
INSERT INTO `booking` (`id`, `member_id`, `booking_date`, `booking_type`, `reference_id`, `status`) VALUES
|
||||
(1, 1, '2022-01-03', 'Class', 101, 'Booked'),
|
||||
(2, 2, '2022-06-17', 'Personal Training', 102, 'Cancelled'),
|
||||
(3, 3, '2022-02-03', 'Facility Reservation', 301, 'Booked'),
|
||||
(4, 4, '2022-03-03', 'Class', 102, 'Booked'),
|
||||
(5, 5, '2022-04-03', 'Personal Training', 202, 'Cancelled');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `class`
|
||||
--
|
||||
|
||||
CREATE TABLE `class` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`instructor` varchar(255) DEFAULT NULL,
|
||||
`start_time` datetime DEFAULT NULL,
|
||||
`end_time` datetime DEFAULT NULL,
|
||||
`max_participants` int(11) DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `class`
|
||||
--
|
||||
|
||||
INSERT INTO `class` (`id`, `name`, `instructor`, `start_time`, `end_time`, `max_participants`) VALUES
|
||||
(101, 'Yoga Basics', 'Alice Johnson', '2022-01-10 08:00:00', '2022-01-10 09:00:00', 20),
|
||||
(102, 'Advanced Cycling', 'Bob Brown', '2022-01-11 17:00:00', '2022-01-11 18:30:00', 15),
|
||||
(103, 'Strength Training', 'Daniel Grey', '2022-02-14 10:00:00', '2022-02-14 11:00:00', 10),
|
||||
(104, 'Pilates Beginner', 'Eva Black', '2022-03-15 14:00:00', '2022-03-15 15:00:00', 12),
|
||||
(105, 'Kickboxing', 'Frank White', '2022-04-16 18:00:00', '2022-04-16 19:30:00', 8);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `facility_reservation`
|
||||
--
|
||||
|
||||
CREATE TABLE `facility_reservation` (
|
||||
`id` int(11) NOT NULL,
|
||||
`facility_name` varchar(255) DEFAULT NULL,
|
||||
`reserved_from` datetime DEFAULT NULL,
|
||||
`reserved_to` datetime DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `facility_reservation`
|
||||
--
|
||||
|
||||
INSERT INTO `facility_reservation` (`id`, `facility_name`, `reserved_from`, `reserved_to`) VALUES
|
||||
(301, 'Tennis Court', '2022-01-13 13:00:00', '2022-01-13 15:00:00'),
|
||||
(302, 'Squash Court', '2022-06-19 09:00:00', '2022-06-19 10:00:00'),
|
||||
(303, 'Basketball Court', '2022-02-23 16:00:00', '2022-02-23 18:00:00'),
|
||||
(304, 'Swimming Pool', '2022-03-24 10:00:00', '2022-03-24 12:00:00'),
|
||||
(305, 'Volleyball Court', '2022-04-25 14:00:00', '2022-04-25 16:00:00');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `member`
|
||||
--
|
||||
|
||||
CREATE TABLE `member` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`email` varchar(255) DEFAULT NULL,
|
||||
`phone` varchar(255) DEFAULT NULL,
|
||||
`join_date` date DEFAULT NULL,
|
||||
`membership_status` varchar(255) DEFAULT NULL,
|
||||
`payment_info` varchar(255) DEFAULT NULL,
|
||||
`communication_preferences` varchar(255) DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `member`
|
||||
--
|
||||
|
||||
INSERT INTO `member` (`id`, `name`, `email`, `phone`, `join_date`, `membership_status`, `payment_info`, `communication_preferences`) VALUES
|
||||
(1, 'John Doe', '[email protected]', '123-456-7890', '2022-01-01', 'Active', 'Credit Card', 'Email'),
|
||||
(2, 'Jane Smith', '[email protected]', '098-765-4321', '2022-06-15', 'Inactive', 'PayPal', 'SMS'),
|
||||
(3, 'Emily Clark', '[email protected]', '321-654-9870', '2022-02-01', 'Active', 'Debit Card', 'Email'),
|
||||
(4, 'Michael Brown', '[email protected]', '654-321-0987', '2022-03-01', 'Active', 'Bank Transfer', 'Phone'),
|
||||
(5, 'Olivia Green', '[email protected]', '987-654-3210', '2022-04-01', 'Inactive', 'Cash', 'SMS');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `payment`
|
||||
--
|
||||
|
||||
CREATE TABLE `payment` (
|
||||
`id` int(11) NOT NULL,
|
||||
`member_id` int(11) DEFAULT NULL,
|
||||
`payment_date` date DEFAULT NULL,
|
||||
`amount` float DEFAULT NULL,
|
||||
`payment_method` varchar(255) DEFAULT NULL,
|
||||
`status` varchar(255) DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `payment`
|
||||
--
|
||||
|
||||
INSERT INTO `payment` (`id`, `member_id`, `payment_date`, `amount`, `payment_method`, `status`) VALUES
|
||||
(1, 1, '2022-01-02', 100, 'Credit Card', 'Completed'),
|
||||
(2, 2, '2022-06-16', 50, 'PayPal', 'Pending'),
|
||||
(3, 3, '2022-02-02', 75, 'Debit Card', 'Completed'),
|
||||
(4, 4, '2022-03-02', 80, 'Bank Transfer', 'Completed'),
|
||||
(5, 5, '2022-04-02', 65, 'Cash', 'Pending');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `personal_training_session`
|
||||
--
|
||||
|
||||
CREATE TABLE `personal_training_session` (
|
||||
`id` int(11) NOT NULL,
|
||||
`member_id` int(11) DEFAULT NULL,
|
||||
`trainer` varchar(255) DEFAULT NULL,
|
||||
`start_time` datetime DEFAULT NULL,
|
||||
`end_time` datetime DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `personal_training_session`
|
||||
--
|
||||
|
||||
INSERT INTO `personal_training_session` (`id`, `member_id`, `trainer`, `start_time`, `end_time`) VALUES
|
||||
(201, 1, 'Carol White', '2022-01-12 10:00:00', '2022-01-12 11:00:00'),
|
||||
(202, 2, 'Dave Black', '2022-06-18 16:00:00', '2022-06-18 17:00:00'),
|
||||
(203, 3, 'Gina Blue', '2022-02-20 09:00:00', '2022-02-20 10:00:00'),
|
||||
(204, 4, 'Hank Green', '2022-03-21 17:00:00', '2022-03-21 18:00:00'),
|
||||
(205, 5, 'Ivy Gold', '2022-04-22 12:00:00', '2022-04-22 13:00:00');
|
||||
|
||||
--
|
||||
-- Indexes for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Indexes for table `attendance`
|
||||
--
|
||||
ALTER TABLE `attendance`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `member_id` (`member_id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `booking`
|
||||
--
|
||||
ALTER TABLE `booking`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `member_id` (`member_id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `class`
|
||||
--
|
||||
ALTER TABLE `class`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `facility_reservation`
|
||||
--
|
||||
ALTER TABLE `facility_reservation`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `member`
|
||||
--
|
||||
ALTER TABLE `member`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `payment`
|
||||
--
|
||||
ALTER TABLE `payment`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `member_id` (`member_id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `personal_training_session`
|
||||
--
|
||||
ALTER TABLE `personal_training_session`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `member_id` (`member_id`);
|
||||
|
||||
--
|
||||
-- Constraints for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Constraints for table `attendance`
|
||||
--
|
||||
ALTER TABLE `attendance`
|
||||
ADD CONSTRAINT `attendance_ibfk_1` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`);
|
||||
|
||||
--
|
||||
-- Constraints for table `booking`
|
||||
--
|
||||
ALTER TABLE `booking`
|
||||
ADD CONSTRAINT `booking_ibfk_1` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`);
|
||||
|
||||
--
|
||||
-- Constraints for table `payment`
|
||||
--
|
||||
ALTER TABLE `payment`
|
||||
ADD CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`);
|
||||
|
||||
--
|
||||
-- Constraints for table `personal_training_session`
|
||||
--
|
||||
ALTER TABLE `personal_training_session`
|
||||
ADD CONSTRAINT `personal_training_session_ibfk_1` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`);
|
||||
COMMIT;
|
||||
|
||||
/*!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 */;
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Hello!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Oops!</h1>
|
||||
<p>Sorry, I don't know what you're asking for.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Admin Dashboard</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Admin Dashboard</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="/admin/members.html">Manage Members</a></li>
|
||||
<li><a href="/admin/classes.html">Manage Classes</a></li>
|
||||
<li><a href="/admin/bookings.html">Manage Bookings</a></li>
|
||||
<li><a href="/admin/payments.html">Manage Payments</a></li>
|
||||
<li><a href="/admin/facilities.html">Manage Facilities</a></li>
|
||||
<li><a href="/admin/reports.html">View Reports</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Manage Members</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Manage Members</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Phone</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- Member records will be inserted here dynamically -->
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Reports</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Reports</h1>
|
||||
<section>
|
||||
<h2>Financial Reports</h2>
|
||||
<!-- Financial report content -->
|
||||
</section>
|
||||
<section>
|
||||
<h2>Attendance Reports</h2>
|
||||
<!-- Attendance report content -->
|
||||
</section>
|
||||
<section>
|
||||
<h2>Booking Reports</h2>
|
||||
<!-- Booking report content -->
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Hello!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Yeet!</h1>
|
||||
<p>index.html</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Member Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Member Login</h1>
|
||||
<form action="/login" method="post">
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Member Profile</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Member Profile</h1>
|
||||
<form action="/update-profile" method="post">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
|
||||
<label for="phone">Phone:</label>
|
||||
<input type="tel" id="phone" name="phone" required>
|
||||
|
||||
<label for="communication_preferences">Communication Preferences:</label>
|
||||
<select id="communication_preferences" name="communication_preferences" required>
|
||||
<option value="Email">Email</option>
|
||||
<option value="SMS">SMS</option>
|
||||
<option value="Phone">Phone</option>
|
||||
</select>
|
||||
|
||||
<button type="submit">Update Profile</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Member Registration</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Member Registration</h1>
|
||||
<form action="\scripts\register_member.php" method="post">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
|
||||
<label for="phone">Phone:</label>
|
||||
<input type="tel" id="phone" name="phone" required>
|
||||
|
||||
<label for="join_date">Join Date:</label>
|
||||
<input type="date" id="join_date" name="join_date" required>
|
||||
|
||||
<label for="membership_status">Membership Status:</label>
|
||||
<select id="membership_status" name="membership_status" required>
|
||||
<option value="Active">Active</option>
|
||||
<option value="Inactive">Inactive</option>
|
||||
</select>
|
||||
|
||||
<button type="submit">Register</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Payment History</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Payment History</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Amount</th>
|
||||
<th>Method</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- Payment records will be inserted here dynamically -->
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Make a Payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Make a Payment</h1>
|
||||
<form action="/process-payment" method="post">
|
||||
<label for="amount">Amount:</label>
|
||||
<input type="number" id="amount" name="amount" step="0.01" required>
|
||||
|
||||
<label for="payment_method">Payment Method:</label>
|
||||
<select id="payment_method" name="payment_method" required>
|
||||
<option value="Credit Card">Credit Card</option>
|
||||
<option value="Debit Card">Debit Card</option>
|
||||
<option value="PayPal">PayPal</option>
|
||||
<option value="Bank Transfer">Bank Transfer</option>
|
||||
<option value="Cash">Cash</option>
|
||||
</select>
|
||||
|
||||
<button type="submit">Pay Now</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
$servername = "localhost";
|
||||
$username = "user";
|
||||
$password = "password";
|
||||
$dbname = "flab_u_less";
|
||||
|
||||
// Create connection
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
// Check connection
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// prepare and bind
|
||||
$stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email) VALUES (?, ?, ?)");
|
||||
$stmt->bind_param("sss", $firstname, $lastname, $email);
|
||||
|
||||
// set parameters and execute
|
||||
$firstname = "John";
|
||||
$lastname = "Doe";
|
||||
$email = "[email protected]";
|
||||
$stmt->execute();
|
||||
|
||||
$firstname = "Mary";
|
||||
$lastname = "Moe";
|
||||
$email = "[email protected]";
|
||||
$stmt->execute();
|
||||
|
||||
$firstname = "Julie";
|
||||
$lastname = "Dooley";
|
||||
$email = "[email protected]";
|
||||
$stmt->execute();
|
||||
|
||||
echo "New records created successfully";
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
**to run the web server**
|
||||
1. install [rust](https://www.rust-lang.org/tools/install)
|
||||
2. ```cargo run``` inside directory
|
||||
3. edit files inside `public/`
|
||||
@@ -0,0 +1,46 @@
|
||||
use std::net::TcpListener;
|
||||
use std::net::TcpStream;
|
||||
use std::io::prelude::*;
|
||||
use std::fs;
|
||||
use mtr_server_app::ThreadPool;
|
||||
|
||||
fn main() {
|
||||
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
|
||||
let pool = ThreadPool::new(4);
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let stream = stream.unwrap();
|
||||
|
||||
pool.execute(|| {
|
||||
handle_connection(stream);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_connection(mut stream: TcpStream) {
|
||||
let mut buffer = [0; 1024];
|
||||
stream.read(&mut buffer).unwrap();
|
||||
|
||||
let request = std::str::from_utf8(&buffer).unwrap_or_default();
|
||||
let request_line = request.lines().next().unwrap_or_default();
|
||||
let request_parts: Vec<&str> = request_line.split_whitespace().collect();
|
||||
if request_parts.len() < 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
let requested_path = request_parts[1];
|
||||
let mut path = format!("public{}", requested_path);
|
||||
let status_line = if fs::metadata(&path).is_ok() {
|
||||
"HTTP/1.1 200 OK"
|
||||
} else {
|
||||
path = "./public/404.html".to_string();
|
||||
"HTTP/1.1 404 NOT FOUND"
|
||||
};
|
||||
|
||||
let contents = fs::read_to_string(&path).unwrap_or_else(|_| "Error loading file".to_string());
|
||||
|
||||
let response = format!("{}\r\nContent-Length: {}\r\n\r\n{}", status_line, contents.len(), contents);
|
||||
|
||||
stream.write(response.as_bytes()).unwrap();
|
||||
stream.flush().unwrap();
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
use std::thread;
|
||||
use std::sync::mpsc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
enum Message {
|
||||
NewJob(Job),
|
||||
Terminate
|
||||
}
|
||||
|
||||
pub struct ThreadPool {
|
||||
workers: Vec<Worker>,
|
||||
sender: mpsc::Sender<Message>
|
||||
}
|
||||
|
||||
type Job = Box<dyn FnOnce() + Send + 'static>;
|
||||
|
||||
impl ThreadPool {
|
||||
/// Create a new ThreadPool.
|
||||
///
|
||||
/// The size is the number of threads in the pool.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// The `new` function will panic if the size is zero.
|
||||
pub fn new(size: usize) -> ThreadPool {
|
||||
assert!(size > 0);
|
||||
|
||||
let (sender, receiver) = mpsc::channel();
|
||||
|
||||
let receiver = Arc::new(Mutex::new(receiver));
|
||||
|
||||
let mut workers = Vec::with_capacity(size);
|
||||
|
||||
for id in 0..size {
|
||||
workers.push(Worker::new(id, Arc::clone(&receiver)));
|
||||
}
|
||||
|
||||
ThreadPool{workers, sender}
|
||||
}
|
||||
pub fn execute<F> (&self, f: F)
|
||||
where F : FnOnce() + Send + 'static, {
|
||||
let job = Box::new(f);
|
||||
|
||||
self.sender.send(Message::NewJob(job)).unwrap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Drop for ThreadPool {
|
||||
fn drop (&mut self) {
|
||||
println!("Sending terminate message to all workers.");
|
||||
|
||||
for _ in &self.workers {
|
||||
self.sender.send(Message::Terminate).unwrap();
|
||||
}
|
||||
|
||||
for worker in &mut self.workers {
|
||||
println!("Shutting down Worker {}", worker.id);
|
||||
|
||||
// worker.thread.join().unwrap();
|
||||
if let Some(thread) = worker.thread.take() {
|
||||
thread.join().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Worker {
|
||||
id: usize,
|
||||
thread: Option<thread::JoinHandle<()>>
|
||||
}
|
||||
|
||||
impl Worker {
|
||||
fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Message>>>) -> Worker {
|
||||
let thread = thread::spawn(move || loop {
|
||||
let message = receiver.lock().unwrap().recv().unwrap();
|
||||
|
||||
// println!("Worker {} got a job. Executing...", id);
|
||||
match message {
|
||||
Message::NewJob(job) => {
|
||||
println!("Worker {} got a job. Executing...", id);
|
||||
job();
|
||||
}
|
||||
Message::Terminate => {
|
||||
println!("Worker {} was told to terminate.", id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Worker {
|
||||
id,
|
||||
thread: Some(thread),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user