diff --git a/README.md b/README.md deleted file mode 100644 index 10e3779e..00000000 --- a/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# bnu-php-example - -This script is for students at Bucks New Uni learning PHP in the "Open Source Systems" module. It is also a good starter project for anyone who is looking to learn PHP and MySQL. - -## Installation Instructions - -1. Run the SQL commands on your database from "_sql/college.dump" to setup the database tables and initial data -2. Download a copy of the repository files and upload them to your FTP server space in a new folder -3. Update "_includes/dbconnect.inc" with your database login credentials -4. Visit the your project folder in a browser and you should see a login screen - -## Default Login - -The database is initialised with the following user setup: - -- Student ID: 20000000 -- Password: test - -## What does this web app demonstrate? - -- how to use mysqli_ functions to connect to MySQL database -- how you can organise your files and folders in your project (there is no one correct way, but this is one way!) -- how to implement user authentication (login) using the PHP password_verify() function -- how to generate a secure hash of a password (see password_hash.php) -- how to implement a basic templating system (this, in turn, demonstrates how to separate business logic from the presentation layer) -- how to use the \<\<\ + diff --git a/_sql/college.dump b/_sql/college.dump index a232fb42..b394ecfb 100644 --- a/_sql/college.dump +++ b/_sql/college.dump @@ -1,45 +1,45 @@ -CREATE TABLE `module` ( - `modulecode` varchar(10) NOT NULL, - `name` varchar(100) NOT NULL, - `level` int(11) NOT NULL -); - -CREATE TABLE `student` ( - `studentid` varchar(8) NOT NULL, - `password` varchar(100) NOT NULL, - `dob` date NOT NULL, - `firstname` varchar(20) NOT NULL, - `lastname` varchar(20) NOT NULL, - `house` varchar(30) NOT NULL, - `town` varchar(30) NOT NULL, - `county` varchar(30) NOT NULL, - `country` varchar(30) NOT NULL, - `postcode` varchar(10) NOT NULL -); - -CREATE TABLE `studentmodules` ( - `studentid` varchar(8) NOT NULL, - `modulecode` varchar(10) NOT NULL -); - -INSERT INTO `studentmodules` (`studentid`, `modulecode`) VALUES -('20000000', 'CO107'), -('20000000', 'IN251'); - -INSERT INTO `module` (`modulecode`, `name`, `level`) VALUES -('CO106', 'Programming Development', 1), -('CO107', 'Programming Principles', 1), -('IN251', 'Internet Systems Development', 2); - -INSERT INTO `student` (`studentid`, `password`, `dob`, `firstname`, `lastname`, `house`, `town`, `county`, `country`, `postcode`) VALUES -('20000000', '$2y$10$.LJBOl64nZWEVVE/v5mgNuzR01zx1zoyXuGJUa/zp2U.MQxkps3LS', '1974-11-10', 'Jon', 'Smith', '23 Victoria Road', 'High Wycombe', 'Bucks', 'UK', 'HP11 1RT'); - - -ALTER TABLE `module` - ADD PRIMARY KEY (`modulecode`); - -ALTER TABLE `student` - ADD PRIMARY KEY (`studentid`); - -ALTER TABLE `studentmodules` - ADD PRIMARY KEY (`studentid`,`modulecode`); +CREATE TABLE `module` ( + `modulecode` varchar(10) NOT NULL, + `name` varchar(100) NOT NULL, + `level` int(11) NOT NULL +); + +CREATE TABLE `student` ( + `studentid` varchar(8) NOT NULL, + `password` varchar(100) NOT NULL, + `dob` date NOT NULL, + `firstname` varchar(20) NOT NULL, + `lastname` varchar(20) NOT NULL, + `house` varchar(30) NOT NULL, + `town` varchar(30) NOT NULL, + `county` varchar(30) NOT NULL, + `country` varchar(30) NOT NULL, + `postcode` varchar(10) NOT NULL +); + +CREATE TABLE `studentmodules` ( + `studentid` varchar(8) NOT NULL, + `modulecode` varchar(10) NOT NULL +); + +INSERT INTO `studentmodules` (`studentid`, `modulecode`) VALUES +('20000000', 'CO107'), +('20000000', 'IN251'); + +INSERT INTO `module` (`modulecode`, `name`, `level`) VALUES +('CO106', 'Programming Development', 1), +('CO107', 'Programming Principles', 1), +('IN251', 'Internet Systems Development', 2); + +INSERT INTO `student` (`studentid`, `password`, `dob`, `firstname`, `lastname`, `house`, `town`, `county`, `country`, `postcode`) VALUES +('20000000', '$2y$10$.LJBOl64nZWEVVE/v5mgNuzR01zx1zoyXuGJUa/zp2U.MQxkps3LS', '1974-11-10', 'Jon', 'Smith', '23 Victoria Road', 'High Wycombe', 'Bucks', 'UK', 'HP11 1RT'); + + +ALTER TABLE `module` + ADD PRIMARY KEY (`modulecode`); + +ALTER TABLE `student` + ADD PRIMARY KEY (`studentid`); + +ALTER TABLE `studentmodules` + ADD PRIMARY KEY (`studentid`,`modulecode`); diff --git a/addstudent.php b/addstudent.php new file mode 100644 index 00000000..e5f62627 --- /dev/null +++ b/addstudent.php @@ -0,0 +1,74 @@ + + + + + + + Add New Student + + + + + +
+

Add New Student

+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + diff --git a/assignmodule.php b/assignmodule.php index 83653ddc..203f58b8 100644 --- a/assignmodule.php +++ b/assignmodule.php @@ -1,48 +1,65 @@ -The module " . $_POST['selmodule'] . " has been assigned to you

"; - } - else // If a module has not been selected - { - - // Build sql statment that selects all the modules - $sql = "select * from module"; - $result = mysqli_query($conn, $sql); - - $data['content'] .= "
"; - $data['content'] .= "Select a module to assign
"; - $data['content'] .= "
"; - $data['content'] .= ""; - $data['content'] .= "
"; - } - - // render the template - echo template("templates/default.php", $data); - -} else { - header("Location: index.php"); -} - -echo template("templates/partials/footer.php"); - -?> + + + + + +Assign Module + + + + 0) { + // Inform user that the module is already assigned + $data['content'] .= "

You are already assigned to the module " . $_POST['selmodule'] . ".

"; + } else { + // Insert the module assignment since it does not exist + $sql = "INSERT INTO studentmodules VALUES ('" . $_SESSION['id'] . "', '" . $_POST['selmodule'] . "');"; + $result = mysqli_query($conn, $sql); + if ($result) { + $data['content'] .= "

The module " . $_POST['selmodule'] . " has been assigned to you.

"; + } else { + $data['content'] .= "

Error assigning module: " . mysqli_error($conn) . "

"; + } + } + } else { + // If no module has been selected, display the module selection form + $sql = "SELECT * FROM module"; + $result = mysqli_query($conn, $sql); + $data['content'] .= "
"; + $data['content'] .= "Select a module to assign
"; + $data['content'] .= "
"; + $data['content'] .= ""; + $data['content'] .= "
"; + } + + // Render the template with content + echo template("templates/default.php", $data); + +} else { + // Redirect to login page if not logged in + header("Location: index.php"); +} + +echo template("templates/partials/footer.php"); +?> + + diff --git a/authenticate.php b/authenticate.php index 903875a3..e024c46f 100644 --- a/authenticate.php +++ b/authenticate.php @@ -1,24 +1,24 @@ - + diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..d3f5495c --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "fakerphp/faker": "^1.23" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000..0b1a39f6 --- /dev/null +++ b/composer.lock @@ -0,0 +1,202 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "3fb5a307183627a23aeed132a1bec5e1", + "packages": [ + { + "name": "fakerphp/faker", + "version": "v1.23.1", + "source": { + "type": "git", + "url": "https://github.com/FakerPHP/Faker.git", + "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/bfb4fe148adbf78eff521199619b93a52ae3554b", + "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "psr/container": "^1.0 || ^2.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "conflict": { + "fzaninotto/faker": "*" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "doctrine/persistence": "^1.3 || ^2.0", + "ext-intl": "*", + "phpunit/phpunit": "^9.5.26", + "symfony/phpunit-bridge": "^5.4.16" + }, + "suggest": { + "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", + "ext-curl": "Required by Faker\\Provider\\Image to download images.", + "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", + "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", + "ext-mbstring": "Required for multibyte Unicode string functionality." + }, + "type": "library", + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "support": { + "issues": "https://github.com/FakerPHP/Faker/issues", + "source": "https://github.com/FakerPHP/Faker/tree/v1.23.1" + }, + "time": "2024-01-02T13:46:09+00:00" + }, + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-23T14:45:45+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/custom.css b/custom.css new file mode 100644 index 00000000..4d422d7b --- /dev/null +++ b/custom.css @@ -0,0 +1,173 @@ +/* General Styles */ +body { + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 16px; + line-height: 1.5; + color: #333333 ; + background-color: #f8f8f8; + } + + /* Headings */ + h1, h2, h3, h4, h5, h6 { + font-weight: bold; + margin-top: 0; + } + + h1 { + font-size: 36px; + color: #2c3e50; + } + + h2 { + font-size: 30px; + color: #2c3e50; + } + + h3 { + font-size: 24px; + color: #2c3e50; + } + + h4 { + font-size: 18px; + color: #2c3e50; + } + + h5 { + font-size: 16px; + color: #2c3e50; + } + + h6 { + font-size: 14px; + color: #2c3e50; + } + + /* Links */ + a { + color: #2980b9; + text-decoration: none; + } + + a:hover { + color: #3498db; + text-decoration: underline; + } + + /* Buttons */ + .btn { + display: inline-block; + padding: 10px 20px; + background-color: #2980b9; + color: #ffffff; + border-radius: 4px; + text-decoration: none; + transition: background-color 0.3s ease; + } + + .btn:hover { + background-color: #3498db; + } + + /* Forms */ + input[type="text"], + input[type="email"], + input[type="password"], + textarea { + padding: 10px; + border: 1px solid #cccccc; + border-radius: 4px; + width: 100%; + box-sizing: border-box; + font-size: 16px; + } + + input[type="submit"] { + background-color: #2980b9; + color: #ffffff; + border: none; + padding: 10px 20px; + border-radius: 4px; + cursor: pointer; + transition: background-color 0.3s ease; + } + + input[type="submit"]:hover { + background-color: #3498db; + } + + /* Tables */ + table { + width: 100%; + border-collapse: collapse; + margin-bottom: 20px; + } + + th, td { + padding: 10px; + text-align: left; + border-bottom: 1px solid #dddddd; + } + + th { + background-color: #2c3e50; + color: #ffffff; + font-weight: bold; + } + + tr:nth-child(even) { + background-color: #f2f2f2; + } + + /* Form Layouts */ + fieldset { + border: 1px solid #cccccc; + padding: 20px; + margin-bottom: 20px; + } + + legend { + font-weight: bold; + font-size: 18px; + color: #2c3e50; + } + + label { + display: block; + margin-bottom: 5px; + font-weight: bold; + } + + .form-group { + margin-bottom: 15px; + } + + .form-inline .form-group { + display: inline-block; + margin-right: 10px; + } + + /* Main Navigation Styles */ +#main-nav { + background-color: #333; /* Dark background */ + color: #fff; /* White text */ + padding: 1rem; /* Padding around the nav */ + text-align: center; /* Center the navigation links */ +} + +#main-nav a { + color: #ddd; /* Light grey text for links */ + text-decoration: none; /* Remove underline from links */ + margin: 0 10px; /* Space out the links */ + font-weight: bold; /* Make the link text bold */ + transition: color 0.3s ease-in-out; /* Smooth transition for hover effect */ +} + +#main-nav a:hover { + color: #4CAF50; /* Change link color on hover */ +} + +/* Add a custom style for the current/active page link if needed */ +#main-nav a.active { + color: #ff6347; /* Highlight color for the active page */ +} diff --git a/deleteStudents.php b/deleteStudents.php new file mode 100644 index 00000000..b750fb2f --- /dev/null +++ b/deleteStudents.php @@ -0,0 +1,21 @@ +prepare($sql); + $stmt->bind_param("i", $studentid); + $stmt->execute(); + } + echo ""; +} else { + echo ""; +} + +?> diff --git a/details.php b/details.php index 462550a2..4f6e2528 100644 --- a/details.php +++ b/details.php @@ -1,75 +1,91 @@ -Your details have been updated

"; - - } - else { - // Build a SQL statment to return the student record with the id that - // matches that of the session variable. - $sql = "select * from student where studentid='". $_SESSION['id'] . "';"; - $result = mysqli_query($conn,$sql); - $row = mysqli_fetch_array($result); - - // using <<My Details -
- First Name : -
- Surname : -
- Number and Street : -
- Town : -
- County : -
- Country : -
- Postcode : -
- -
- -EOD; - - } - - // render the template - echo template("templates/default.php", $data); - -} else { - header("Location: index.php"); -} - -echo template("templates/partials/footer.php"); - -?> + + + + + + + My Details + + + + +
+

My Details

+ Your details have been updated

"; + } else { + // Build a SQL statement to return the student record with the id that + // matches that of the session variable using prepared statements. + $stmt = $conn->prepare("SELECT * FROM student WHERE studentid = ?"); + $stmt->bind_param("s", $_SESSION['id']); // 's' specifies the variable type => 'string' + + $stmt->execute(); + $result = $stmt->get_result(); + $row = $result->fetch_assoc(); + + // You can continue with your HEREDOC notation or any other operation with $row + // For example, using HEREDOC to build a string with student information: + $data['content'] = << +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +EOD; + } + // render the template + echo template("templates/default.php", $data); + ?> +
+ + + diff --git a/editStudent.php b/editStudent.php new file mode 100644 index 00000000..89767146 --- /dev/null +++ b/editStudent.php @@ -0,0 +1,33 @@ +prepare("SELECT * FROM student WHERE studentid = ?"); + $stmt->bind_param("s", $studentId); + $stmt->execute(); + $result = $stmt->get_result(); + if ($row = $result->fetch_assoc()) { + echo "
"; + echo ""; + // Dynamically create form fields for all student details + foreach ($row as $field => $value) { + if ($field != 'studentid' && $field != 'image_path') { // Skip editing student ID and image path directly + echo ucfirst($field) . ":
"; + } + } + echo "Student Image:

"; + echo ""; + echo "
"; + } else { + echo "Student not found."; + } + $stmt->close(); +} else { + echo "No student ID provided."; +} + +?> diff --git a/logout.php b/logout.php index 29a7a3ce..a07e8c48 100644 --- a/logout.php +++ b/logout.php @@ -1,11 +1,11 @@ - + diff --git a/modules.php b/modules.php index a19e8eed..d1814b96 100644 --- a/modules.php +++ b/modules.php @@ -1,39 +1,54 @@ -"; - $data['content'] .= "Modules"; - $data['content'] .= "CodeTypeLevel"; - // Display the modules within the html table - while($row = mysqli_fetch_array($result)) { - $data['content'] .= " $row[modulecode] $row[name] "; - $data['content'] .= " $row[level] "; - } - $data['content'] .= ""; - - // render the template - echo template("templates/default.php", $data); - - } else { - header("Location: index.php"); - } - - echo template("templates/partials/footer.php"); - -?> + + + + + Assign Module + + + + prepare("SELECT m.modulecode, m.name, m.level FROM studentmodules sm JOIN module m ON m.modulecode = sm.modulecode WHERE sm.studentid = ?"); +$stmt->bind_param("s", $_SESSION['id']); // 's' specifies the variable type => 'string' + +$stmt->execute(); +$result = $stmt->get_result(); + +// prepare page content +$data['content'] .= ""; +$data['content'] .= ""; +$data['content'] .= ""; +// Display the modules within the HTML table +while ($row = $result->fetch_assoc()) { + $data['content'] .= ""; + $data['content'] .= ""; + $data['content'] .= ""; +} +$data['content'] .= "
Modules
CodeNameLevel
" . htmlspecialchars($row['modulecode']) . "" . htmlspecialchars($row['name']) . "" . htmlspecialchars($row['level']) . "
"; + + + // render the template + echo template("templates/default.php", $data); + + } else { + header("Location: index.php"); + } + + echo template("templates/partials/footer.php"); + +?> + + + diff --git a/process_addstudent.php b/process_addstudent.php new file mode 100644 index 00000000..c2ad1fad --- /dev/null +++ b/process_addstudent.php @@ -0,0 +1,64 @@ +real_escape_string($_POST['studentid']); + $password = $conn->real_escape_string($_POST['password']); + // Assume password will be hashed before storage + $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + $dob = $conn->real_escape_string($_POST['dob']); + $firstname = $conn->real_escape_string($_POST['firstname']); + $lastname = $conn->real_escape_string($_POST['lastname']); + $house = $conn->real_escape_string($_POST['house']); + $town = $conn->real_escape_string($_POST['town']); + $county = $conn->real_escape_string($_POST['county']); + $country = $conn->real_escape_string($_POST['country']); + $postcode = $conn->real_escape_string($_POST['postcode']); + $imagePath = ''; // Initialize image path + + // Handle the file upload + if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { + $uploadDir = 'uploads/'; + $fileName = basename($_FILES['image']['name']); + $targetFilePath = $uploadDir . $fileName; + $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); + + // Allow certain file formats + $allowTypes = array('jpg', 'png', 'jpeg', 'gif'); + if (in_array($fileType, $allowTypes)) { + // Upload file to server + if (move_uploaded_file($_FILES['image']['tmp_name'], $targetFilePath)) { + // File upload success, get the uploaded file path + $imagePath = $targetFilePath; + } else { + echo "Sorry, there was an error uploading your file."; + } + } else { + echo "Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload."; + } + } + + // Prepare SQL statement to insert data including image path + $stmt = $conn->prepare("INSERT INTO student (studentid, password, dob, firstname, lastname, house, town, county, country, postcode, image_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->bind_param("sssssssssss", $studentid, $hashedPassword, $dob, $firstname, $lastname, $house, $town, $county, $country, $postcode, $imagePath); + + // Execute the prepared statement + if ($stmt->execute()) { + echo "New record created successfully"; + } else { + echo "Error: " . $stmt->error; + } + + // Close statement + $stmt->close(); +} else { + echo "Invalid request method."; +} + +?> + diff --git a/seed.php b/seed.php new file mode 100644 index 00000000..cf94d07c --- /dev/null +++ b/seed.php @@ -0,0 +1,42 @@ +unique()->numberBetween(20000001, 29999999), + $faker->password, + $faker->date($format = 'Y-m-d', $max = '2003-12-31'), + $faker->firstName, + $faker->lastName, + $faker->streetAddress, + $faker->city, + $faker->state, + $faker->country, + $faker->postcode + ]; + + // Assuming $conn is your database connection variable from dbconnect.inc + $stmt = $conn->prepare($sql); + $stmt->execute($student); + } + + echo "Students inserted successfully."; +} + +?> + + diff --git a/students.php b/students.php new file mode 100644 index 00000000..5bc4b475 --- /dev/null +++ b/students.php @@ -0,0 +1,97 @@ + + + + + + + Student Records + + + + + + +
+

Student Records

+
+ Add +
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + query($sql); + if ($result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + echo ""; + echo ""; + echo ""; + echo ""; // Do not display passwords + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + if (!empty($row["image_path"])) { + echo ""; + } else { + echo ""; + } + echo ""; + echo ""; + } + } else { + echo ""; + } + ?> + +
SelectStudent IDPasswordDate of BirthFirst NameLast NameHouseTownCountyCountryPostcodeImageAction
" . htmlspecialchars($row["studentid"]) . "[Protected]" . htmlspecialchars($row["dob"]) . "" . htmlspecialchars($row["firstname"]) . "" . htmlspecialchars($row["lastname"]) . "" . htmlspecialchars($row["house"]) . "" . htmlspecialchars($row["town"]) . "" . htmlspecialchars($row["county"]) . "" . htmlspecialchars($row["country"]) . "" . htmlspecialchars($row["postcode"]) . "Student ImageNo image availableEdit
No records found
+
+
+ + + diff --git a/templates/login.php b/templates/login.php index 5767ddd5..6daa3d30 100644 --- a/templates/login.php +++ b/templates/login.php @@ -1,12 +1,23 @@ - - - -
- Student ID: - -
- Password: - -
- -
+
+
+
+
+
Login
+
+ +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
diff --git a/templates/partials/header.php b/templates/partials/header.php index 8f797f8c..b11a8cfd 100644 --- a/templates/partials/header.php +++ b/templates/partials/header.php @@ -3,7 +3,9 @@ BNU Student Web Application + + diff --git a/templates/partials/nav.php b/templates/partials/nav.php index 3221efb3..866cb51f 100644 --- a/templates/partials/nav.php +++ b/templates/partials/nav.php @@ -1,9 +1,9 @@ + - diff --git a/updateStudent.php b/updateStudent.php new file mode 100644 index 00000000..557c274a --- /dev/null +++ b/updateStudent.php @@ -0,0 +1,75 @@ + $value) { + if ($key != 'studentid' && $key != 'image') { + $fieldsToUpdate[$key] = $value; + } + } + + // Initialize the SQL parts for updating student details + $sqlSetParts = []; + foreach ($fieldsToUpdate as $field => $value) { + $sqlSetParts[] = "$field = ?"; + } + + // File upload logic + if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { + $allowedTypes = ['jpg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif']; + $fileType = mime_content_type($_FILES['image']['tmp_name']); + + if (in_array($fileType, $allowedTypes)) { + $fileExt = array_search($fileType, $allowedTypes); + $imagePath = 'uploads/' . $studentId . '.' . $fileExt; + + // Create the uploads directory if it doesn't exist + if (!file_exists('uploads')) { + mkdir('uploads', 0777, true); + } + // Move the uploaded file + if (!move_uploaded_file($_FILES['image']['tmp_name'], $imagePath)) { + die("Failed to move uploaded file."); + } + // Add image path to the fields to update + $sqlSetParts[] = "image_path = ?"; + $fieldsToUpdate['image_path'] = $imagePath; + } else { + die("Unsupported file type."); + } + } + + // Finalize and prepare the SQL statement for updating student details + $sql = "UPDATE student SET " . implode(", ", $sqlSetParts) . " WHERE studentid = ?"; + $stmt = $conn->prepare($sql); + $types = str_repeat('s', count($fieldsToUpdate)) . 's'; + $params = array_merge(array_values($fieldsToUpdate), [$studentId]); + $stmt->bind_param($types, ...$params); + + // Execute the update + if ($stmt->execute()) { + echo "Student updated successfully."; + } else { + echo "Error updating record: " . $stmt->error; + } + + // Close the prepared statement + $stmt->close(); +} + +// Redirect back to the student list page +header("Location: students.php"); +exit(); + +?> + + + diff --git a/uploads/20000000.jpg b/uploads/20000000.jpg new file mode 100644 index 00000000..9023d3a7 Binary files /dev/null and b/uploads/20000000.jpg differ diff --git a/uploads/20000000.png b/uploads/20000000.png new file mode 100644 index 00000000..db298171 Binary files /dev/null and b/uploads/20000000.png differ diff --git a/uploads/20140544.png b/uploads/20140544.png new file mode 100644 index 00000000..c83fd1d5 Binary files /dev/null and b/uploads/20140544.png differ diff --git a/uploads/20518553.png b/uploads/20518553.png new file mode 100644 index 00000000..d65e0cc7 Binary files /dev/null and b/uploads/20518553.png differ diff --git a/uploads/21440647.png b/uploads/21440647.png new file mode 100644 index 00000000..3725c062 Binary files /dev/null and b/uploads/21440647.png differ diff --git a/uploads/22194971.png b/uploads/22194971.png new file mode 100644 index 00000000..27db99ac Binary files /dev/null and b/uploads/22194971.png differ diff --git a/uploads/22382346.png b/uploads/22382346.png new file mode 100644 index 00000000..5f29e75e Binary files /dev/null and b/uploads/22382346.png differ diff --git a/uploads/25949943.png b/uploads/25949943.png new file mode 100644 index 00000000..92c28700 Binary files /dev/null and b/uploads/25949943.png differ diff --git a/uploads/27136230.png b/uploads/27136230.png new file mode 100644 index 00000000..84b9aacf Binary files /dev/null and b/uploads/27136230.png differ diff --git a/uploads/28152103.png b/uploads/28152103.png new file mode 100644 index 00000000..33cdd73a Binary files /dev/null and b/uploads/28152103.png differ diff --git "a/uploads/DALL\302\267E 2024-04-05 19.18.52 - Create a cartoon portrait of a student named Lars Cummings, portraying him as a Black individual who is globally conscious and environmentally aware. .png" "b/uploads/DALL\302\267E 2024-04-05 19.18.52 - Create a cartoon portrait of a student named Lars Cummings, portraying him as a Black individual who is globally conscious and environmentally aware. .png" new file mode 100644 index 00000000..bff2b71e Binary files /dev/null and "b/uploads/DALL\302\267E 2024-04-05 19.18.52 - Create a cartoon portrait of a student named Lars Cummings, portraying him as a Black individual who is globally conscious and environmentally aware. .png" differ diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100644 index 00000000..e8ae0475 --- /dev/null +++ b/vendor/autoload.php @@ -0,0 +1,25 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + /** @var \Closure(string):void */ + private static $includeFile; + + /** @var string|null */ + private $vendorDir; + + // PSR-4 + /** + * @var array> + */ + private $prefixLengthsPsr4 = array(); + /** + * @var array> + */ + private $prefixDirsPsr4 = array(); + /** + * @var list + */ + private $fallbackDirsPsr4 = array(); + + // PSR-0 + /** + * List of PSR-0 prefixes + * + * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2'))) + * + * @var array>> + */ + private $prefixesPsr0 = array(); + /** + * @var list + */ + private $fallbackDirsPsr0 = array(); + + /** @var bool */ + private $useIncludePath = false; + + /** + * @var array + */ + private $classMap = array(); + + /** @var bool */ + private $classMapAuthoritative = false; + + /** + * @var array + */ + private $missingClasses = array(); + + /** @var string|null */ + private $apcuPrefix; + + /** + * @var array + */ + private static $registeredLoaders = array(); + + /** + * @param string|null $vendorDir + */ + public function __construct($vendorDir = null) + { + $this->vendorDir = $vendorDir; + self::initializeIncludeClosure(); + } + + /** + * @return array> + */ + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); + } + + return array(); + } + + /** + * @return array> + */ + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + /** + * @return list + */ + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + /** + * @return list + */ + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + /** + * @return array Array of classname => path + */ + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + * + * @return void + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + * + * @return void + */ + public function add($prefix, $paths, $prepend = false) + { + $paths = (array) $paths; + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + $paths = (array) $paths; + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 base directories + * + * @return void + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + * + * @return void + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + * + * @return void + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + * + * @return void + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + * + * @return void + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + + if (null === $this->vendorDir) { + return; + } + + if ($prepend) { + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; + } else { + unset(self::$registeredLoaders[$this->vendorDir]); + self::$registeredLoaders[$this->vendorDir] = $this; + } + } + + /** + * Unregisters this instance as an autoloader. + * + * @return void + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + + if (null !== $this->vendorDir) { + unset(self::$registeredLoaders[$this->vendorDir]); + } + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return true|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + $includeFile = self::$includeFile; + $includeFile($file); + + return true; + } + + return null; + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + /** + * Returns the currently registered loaders keyed by their corresponding vendor directories. + * + * @return array + */ + public static function getRegisteredLoaders() + { + return self::$registeredLoaders; + } + + /** + * @param string $class + * @param string $ext + * @return string|false + */ + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } + + /** + * @return void + */ + private static function initializeIncludeClosure() + { + if (self::$includeFile !== null) { + return; + } + + /** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + */ + self::$includeFile = \Closure::bind(static function($file) { + include $file; + }, null, null); + } +} diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php new file mode 100644 index 00000000..51e734a7 --- /dev/null +++ b/vendor/composer/InstalledVersions.php @@ -0,0 +1,359 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer; + +use Composer\Autoload\ClassLoader; +use Composer\Semver\VersionParser; + +/** + * This class is copied in every Composer installed project and available to all + * + * See also https://getcomposer.org/doc/07-runtime.md#installed-versions + * + * To require its presence, you can require `composer-runtime-api ^2.0` + * + * @final + */ +class InstalledVersions +{ + /** + * @var mixed[]|null + * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array}|array{}|null + */ + private static $installed; + + /** + * @var bool|null + */ + private static $canGetVendors; + + /** + * @var array[] + * @psalm-var array}> + */ + private static $installedByVendor = array(); + + /** + * Returns a list of all package names which are present, either by being installed, replaced or provided + * + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackages() + { + $packages = array(); + foreach (self::getInstalled() as $installed) { + $packages[] = array_keys($installed['versions']); + } + + if (1 === \count($packages)) { + return $packages[0]; + } + + return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); + } + + /** + * Returns a list of all package names with a specific type e.g. 'library' + * + * @param string $type + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackagesByType($type) + { + $packagesByType = array(); + + foreach (self::getInstalled() as $installed) { + foreach ($installed['versions'] as $name => $package) { + if (isset($package['type']) && $package['type'] === $type) { + $packagesByType[] = $name; + } + } + } + + return $packagesByType; + } + + /** + * Checks whether the given package is installed + * + * This also returns true if the package name is provided or replaced by another package + * + * @param string $packageName + * @param bool $includeDevRequirements + * @return bool + */ + public static function isInstalled($packageName, $includeDevRequirements = true) + { + foreach (self::getInstalled() as $installed) { + if (isset($installed['versions'][$packageName])) { + return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false; + } + } + + return false; + } + + /** + * Checks whether the given package satisfies a version constraint + * + * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: + * + * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') + * + * @param VersionParser $parser Install composer/semver to have access to this class and functionality + * @param string $packageName + * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package + * @return bool + */ + public static function satisfies(VersionParser $parser, $packageName, $constraint) + { + $constraint = $parser->parseConstraints((string) $constraint); + $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); + + return $provided->matches($constraint); + } + + /** + * Returns a version constraint representing all the range(s) which are installed for a given package + * + * It is easier to use this via isInstalled() with the $constraint argument if you need to check + * whether a given version of a package is installed, and not just whether it exists + * + * @param string $packageName + * @return string Version constraint usable with composer/semver + */ + public static function getVersionRanges($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + $ranges = array(); + if (isset($installed['versions'][$packageName]['pretty_version'])) { + $ranges[] = $installed['versions'][$packageName]['pretty_version']; + } + if (array_key_exists('aliases', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); + } + if (array_key_exists('replaced', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); + } + if (array_key_exists('provided', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); + } + + return implode(' || ', $ranges); + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['version'])) { + return null; + } + + return $installed['versions'][$packageName]['version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getPrettyVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['pretty_version'])) { + return null; + } + + return $installed['versions'][$packageName]['pretty_version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference + */ + public static function getReference($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['reference'])) { + return null; + } + + return $installed['versions'][$packageName]['reference']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. + */ + public static function getInstallPath($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @return array + * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} + */ + public static function getRootPackage() + { + $installed = self::getInstalled(); + + return $installed[0]['root']; + } + + /** + * Returns the raw installed.php data for custom implementations + * + * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. + * @return array[] + * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} + */ + public static function getRawData() + { + @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + self::$installed = include __DIR__ . '/installed.php'; + } else { + self::$installed = array(); + } + } + + return self::$installed; + } + + /** + * Returns the raw data of all installed.php which are currently loaded for custom implementations + * + * @return array[] + * @psalm-return list}> + */ + public static function getAllRawData() + { + return self::getInstalled(); + } + + /** + * Lets you reload the static array from another file + * + * This is only useful for complex integrations in which a project needs to use + * this class but then also needs to execute another project's autoloader in process, + * and wants to ensure both projects have access to their version of installed.php. + * + * A typical case would be PHPUnit, where it would need to make sure it reads all + * the data it needs from this class, then call reload() with + * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure + * the project in which it runs can then also use this class safely, without + * interference between PHPUnit's dependencies and the project's dependencies. + * + * @param array[] $data A vendor/composer/installed.php data set + * @return void + * + * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $data + */ + public static function reload($data) + { + self::$installed = $data; + self::$installedByVendor = array(); + } + + /** + * @return array[] + * @psalm-return list}> + */ + private static function getInstalled() + { + if (null === self::$canGetVendors) { + self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); + } + + $installed = array(); + + if (self::$canGetVendors) { + foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { + if (isset(self::$installedByVendor[$vendorDir])) { + $installed[] = self::$installedByVendor[$vendorDir]; + } elseif (is_file($vendorDir.'/composer/installed.php')) { + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require $vendorDir.'/composer/installed.php'; + $installed[] = self::$installedByVendor[$vendorDir] = $required; + if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { + self::$installed = $installed[count($installed) - 1]; + } + } + } + } + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require __DIR__ . '/installed.php'; + self::$installed = $required; + } else { + self::$installed = array(); + } + } + + if (self::$installed !== array()) { + $installed[] = self::$installed; + } + + return $installed; + } +} diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE new file mode 100644 index 00000000..f27399a0 --- /dev/null +++ b/vendor/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 00000000..0fb0a2c1 --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,10 @@ + $vendorDir . '/composer/InstalledVersions.php', +); diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php new file mode 100644 index 00000000..be8e1c3f --- /dev/null +++ b/vendor/composer/autoload_files.php @@ -0,0 +1,10 @@ + $vendorDir . '/symfony/deprecation-contracts/function.php', +); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php new file mode 100644 index 00000000..15a2ff3a --- /dev/null +++ b/vendor/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ + array($vendorDir . '/psr/container/src'), + 'Faker\\' => array($vendorDir . '/fakerphp/faker/src/Faker'), +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php new file mode 100644 index 00000000..33ab6413 --- /dev/null +++ b/vendor/composer/autoload_real.php @@ -0,0 +1,50 @@ +register(true); + + $filesToLoad = \Composer\Autoload\ComposerStaticInit662aedcc6781129fa81bbdd533343456::$files; + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; + + require $file; + } + }, null, null); + foreach ($filesToLoad as $fileIdentifier => $file) { + $requireFile($fileIdentifier, $file); + } + + return $loader; + } +} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php new file mode 100644 index 00000000..b6674963 --- /dev/null +++ b/vendor/composer/autoload_static.php @@ -0,0 +1,48 @@ + __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php', + ); + + public static $prefixLengthsPsr4 = array ( + 'P' => + array ( + 'Psr\\Container\\' => 14, + ), + 'F' => + array ( + 'Faker\\' => 6, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Psr\\Container\\' => + array ( + 0 => __DIR__ . '/..' . '/psr/container/src', + ), + 'Faker\\' => + array ( + 0 => __DIR__ . '/..' . '/fakerphp/faker/src/Faker', + ), + ); + + public static $classMap = array ( + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit662aedcc6781129fa81bbdd533343456::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit662aedcc6781129fa81bbdd533343456::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit662aedcc6781129fa81bbdd533343456::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100644 index 00000000..bd3fc284 --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1,198 @@ +{ + "packages": [ + { + "name": "fakerphp/faker", + "version": "v1.23.1", + "version_normalized": "1.23.1.0", + "source": { + "type": "git", + "url": "https://github.com/FakerPHP/Faker.git", + "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/bfb4fe148adbf78eff521199619b93a52ae3554b", + "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "psr/container": "^1.0 || ^2.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "conflict": { + "fzaninotto/faker": "*" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "doctrine/persistence": "^1.3 || ^2.0", + "ext-intl": "*", + "phpunit/phpunit": "^9.5.26", + "symfony/phpunit-bridge": "^5.4.16" + }, + "suggest": { + "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", + "ext-curl": "Required by Faker\\Provider\\Image to download images.", + "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", + "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", + "ext-mbstring": "Required for multibyte Unicode string functionality." + }, + "time": "2024-01-02T13:46:09+00:00", + "type": "library", + "installation-source": "source", + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "support": { + "issues": "https://github.com/FakerPHP/Faker/issues", + "source": "https://github.com/FakerPHP/Faker/tree/v1.23.1" + }, + "install-path": "../fakerphp/faker" + }, + { + "name": "psr/container", + "version": "2.0.2", + "version_normalized": "2.0.2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "time": "2021-11-05T16:47:00+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "installation-source": "source", + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "install-path": "../psr/container" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.4.0", + "version_normalized": "3.4.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "time": "2023-05-23T14:45:45+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "installation-source": "source", + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "install-path": "../symfony/deprecation-contracts" + } + ], + "dev": true, + "dev-package-names": [] +} diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php new file mode 100644 index 00000000..1ec44be9 --- /dev/null +++ b/vendor/composer/installed.php @@ -0,0 +1,50 @@ + array( + 'name' => '__root__', + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'dae7f504c25e03df35c01d04cca5c265f4d8ff9c', + 'type' => 'library', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev' => true, + ), + 'versions' => array( + '__root__' => array( + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'dae7f504c25e03df35c01d04cca5c265f4d8ff9c', + 'type' => 'library', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'fakerphp/faker' => array( + 'pretty_version' => 'v1.23.1', + 'version' => '1.23.1.0', + 'reference' => 'bfb4fe148adbf78eff521199619b93a52ae3554b', + 'type' => 'library', + 'install_path' => __DIR__ . '/../fakerphp/faker', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'psr/container' => array( + 'pretty_version' => '2.0.2', + 'version' => '2.0.2.0', + 'reference' => 'c71ecc56dfe541dbd90c5360474fbc405f8d5963', + 'type' => 'library', + 'install_path' => __DIR__ . '/../psr/container', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'symfony/deprecation-contracts' => array( + 'pretty_version' => 'v3.4.0', + 'version' => '3.4.0.0', + 'reference' => '7c3aff79d10325257a001fcf92d991f24fc967cf', + 'type' => 'library', + 'install_path' => __DIR__ . '/../symfony/deprecation-contracts', + 'aliases' => array(), + 'dev_requirement' => false, + ), + ), +); diff --git a/vendor/composer/platform_check.php b/vendor/composer/platform_check.php new file mode 100644 index 00000000..4c3a5d68 --- /dev/null +++ b/vendor/composer/platform_check.php @@ -0,0 +1,26 @@ += 80100)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 8.1.0". You are running ' . PHP_VERSION . '.'; +} + +if ($issues) { + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); + } elseif (!headers_sent()) { + echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; + } + } + trigger_error( + 'Composer detected issues in your platform: ' . implode(' ', $issues), + E_USER_ERROR + ); +}