commit a30eb74e3e566d25bab3a1cad8ab1a39db71b144 Author: Joshua Perry <45966243+jpez-development@users.noreply.github.com> Date: Sat Jan 21 23:12:42 2023 +0000 first commit diff --git a/CSY2028 Assignment 2.pdf b/CSY2028 Assignment 2.pdf new file mode 100644 index 0000000..2b7692b Binary files /dev/null and b/CSY2028 Assignment 2.pdf differ diff --git a/CSY2028/DatabaseTable.php b/CSY2028/DatabaseTable.php new file mode 100644 index 0000000..ed1f060 --- /dev/null +++ b/CSY2028/DatabaseTable.php @@ -0,0 +1,70 @@ +table = $table; + $this->pk = $pk; + $this->entityClass = $entityClass; + $this->entityConstructor = $entityConstructor; + } + + private function startDB() { //TODO: Maybe move + $server = 'mysql'; + $username = 'student'; + $password = 'student'; + $schema = 'job'; + return new \PDO('mysql:dbname='.$schema.';host='.$server, $username, $password); + } + + private function insert($record) { + $keys = \array_keys($record); + $columns = \implode(', ', $keys); + $values = \implode(', :', $keys); + startDB()->prepare('INSERT INTO '. $this->table . ' (' . $columns . ') VALUES (:' . $values . ')')->execute($record); + } + + private function update($record) { + $params = []; + foreach ($record as $key => $value) { + $params[] = $key . ' = :' .$key; + } + $record['primaryKey'] = $record[$this->pk]; + startDB()->prepare('UPDATE '. $this->table .' SET '. \implode(', ', $params) .' WHERE '. $this->pk .' = :primaryKey')->execute($record); + } + + public function find($column, $value) { + $values = [ + 'value' => $value + ]; + return startDB()->prepare('SELECT * FROM '. $this->table . ' WHERE '. $field . ' = :value')->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor)->execute($values)->fetchAll(); + } + + public function findAll() { + return startDB()->prepare('SELECT * FROM ' . $this->table)->execute()->fetchAll(); + } + + public function delete($column, $value) { + $values = [ + 'value' => $value + ]; + startDB()->prepare('DELETE FROM '. $this->$table .' WHERE '. $column .' = :value')->execute($values); + } + + public function save($record) { + if (\empty($record[$pk])) { + \unset($record[$pk]); + } + try { + insert($record); + } + catch (\Exception $e) { + update($record); + } + } +} +?> \ No newline at end of file diff --git a/CSY2028/EntryPoint.php b/CSY2028/EntryPoint.php new file mode 100644 index 0000000..b9d780f --- /dev/null +++ b/CSY2028/EntryPoint.php @@ -0,0 +1,34 @@ +routes = $routes; + } + + public function loadTemplate($fileName, $templateData) { + \extract($templateData); + \ob_start(); + require $fileName; + return \ob_get_clean(); + } + + public function run() { + $route = \ltrim(\explode('?', $_SERVER['REQUEST_URI'])[0], '/'); + if ($route == '') { + $route = $this->routes->getDefaultRoute(); + } + + list($controllerName, $functionName) = \explode('/', $route); + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $functionName = $functionName . 'Submit'; + } + + $page = $this->routes->getController($controllerName)->$functionName(); + $content = $this->loadTemplate('../templates/' . $page['template'], $page['vars']); + $title = $page['title']; + require '../templates/layout.html.php'; + } +} \ No newline at end of file diff --git a/CSY2028/Routes.php b/CSY2028/Routes.php new file mode 100644 index 0000000..defb9cf --- /dev/null +++ b/CSY2028/Routes.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/jobs/Routes.php b/jobs/Routes.php new file mode 100644 index 0000000..970efb4 --- /dev/null +++ b/jobs/Routes.php @@ -0,0 +1,33 @@ +jobTable = $jobTable; + } + + public function home() { + return ['template' => 'home.html.php', + 'title' => 'Jo\'s Jobs- Home', + 'vars' => [] + ]; + } +} +?> \ No newline at end of file diff --git a/pages/about.html b/pages/about.html new file mode 100644 index 0000000..1d16eb0 --- /dev/null +++ b/pages/about.html @@ -0,0 +1,55 @@ + + + + + Jo's Jobs - About + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+

Welcome to Jo's Jobs, we're a recruitment agency based in Northampton. We offer a range of different office jobs. Get in touch if you'd like to list a job with us.

+ +

Select the type of job you are looking for:

+ + + +
+ + + + + diff --git a/pages/admin/addcategory.php b/pages/admin/addcategory.php new file mode 100644 index 0000000..057585d --- /dev/null +++ b/pages/admin/addcategory.php @@ -0,0 +1,112 @@ + + + + + + Jo's Jobs - Add Category + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ + prepare('INSERT INTO category (name) VALUES (:name)'); + + $criteria = [ + 'name' => $_POST['name'] + ]; + + $stmt->execute($criteria); + echo 'Category added'; + } + else { + ?> + + +

Add Category

+ +
+ + + + + + +
+ + + +

Log in

+ +
+ + + + +
+ + + +
+
+ + + + diff --git a/pages/admin/addjob.php b/pages/admin/addjob.php new file mode 100644 index 0000000..be28ede --- /dev/null +++ b/pages/admin/addjob.php @@ -0,0 +1,149 @@ + + + + + + Jo's Jobs - Add Job + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ +prepare('INSERT INTO job (title, description, salary, location, closingDate, categoryId) + VALUES (:title, :description, :salary, :location, :closingDate, :categoryId)'); + + $criteria = [ + 'title' => $_POST['title'], + 'description' => $_POST['description'], + 'salary' => $_POST['salary'], + 'location' => $_POST['location'], + 'categoryId' => $_POST['categoryId'], + 'closingDate' => $_POST['closingDate'], + ]; + + $stmt->execute($criteria); + + echo 'Job Added'; + } + else { + + ?> + + +

Add Job

+ +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + +

Log in

+ +
+ + + + + +
+ + +
+
+ + + + + + + diff --git a/pages/admin/applicants.php b/pages/admin/applicants.php new file mode 100644 index 0000000..8f533c0 --- /dev/null +++ b/pages/admin/applicants.php @@ -0,0 +1,116 @@ + + + + + + Jo's Jobs - Applicants + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ + prepare('SELECT * FROM job WHERE id = :id'); + + $stmt->execute(['id' => $_GET['id']]); + + $job = $stmt->fetch(); + ?> + + +

Applicants for

+ + '; + echo ''; + echo ''; + echo 'Name'; + echo 'Email'; + echo 'Details'; + echo 'CV'; + echo ''; + + $stmt = $pdo->prepare('SELECT * FROM applicants WHERE jobId = :id'); + + $stmt->execute(['id' => $_GET['id']]); + + foreach ($stmt as $applicant) { + echo ''; + echo '' . $applicant['name'] . ''; + echo '' . $applicant['email'] . ''; + echo '' . $applicant['details'] . ''; + echo 'Download CV'; + echo ''; + } + + echo ''; + echo ''; + + } + + else { + ?> +

Log in

+ +
+ + + + +
+ + +
+
+ + + + + + diff --git a/pages/admin/categories.php b/pages/admin/categories.php new file mode 100644 index 0000000..7a2aa3a --- /dev/null +++ b/pages/admin/categories.php @@ -0,0 +1,111 @@ + + + + + + Jo's Jobs - Categories + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ + + + +

Categories

+ + Add new category + + '; + echo ''; + echo ''; + echo 'Name'; + echo ' '; + echo ' '; + echo ''; + + $categories = $pdo->query('SELECT * FROM category'); + + foreach ($categories as $category) { + echo ''; + echo '' . $category['name'] . ''; + echo 'Edit'; + echo '
+ + +
'; + echo ''; + } + + echo ''; + echo ''; + + } + + else { + ?> +

Log in

+ +
+ + + + +
+ + +
+
+ + + + + diff --git a/pages/admin/deletecategory.php b/pages/admin/deletecategory.php new file mode 100644 index 0000000..835413b --- /dev/null +++ b/pages/admin/deletecategory.php @@ -0,0 +1,14 @@ +prepare('DELETE FROM category WHERE id = :id'); + $stmt->execute(['id' => $_POST['id']]); + + + header('location: categories.php'); +} + + diff --git a/pages/admin/deletejob.php b/pages/admin/deletejob.php new file mode 100644 index 0000000..77dc9cd --- /dev/null +++ b/pages/admin/deletejob.php @@ -0,0 +1,14 @@ +prepare('DELETE FROM job WHERE id = :id'); + $stmt->execute(['id' => $_POST['id']]); + + + header('location: jobs.php'); +} + + diff --git a/pages/admin/editcategory.php b/pages/admin/editcategory.php new file mode 100644 index 0000000..c1f0ea2 --- /dev/null +++ b/pages/admin/editcategory.php @@ -0,0 +1,117 @@ + + + + + + Jo's Jobs - Edit Category + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ + prepare('UPDATE category SET name = :name WHERE id = :id '); + + $criteria = [ + 'name' => $_POST['name'], + 'id' => $_POST['id'] + ]; + + $stmt->execute($criteria); + echo 'Category Saved'; + } + else { + $currentCategory = $pdo->query('SELECT * FROM category WHERE id = ' . $_GET['id'])->fetch(); + ?> + + +

Edit Category

+ +
+ + + + + + + + +
+ + + +

Log in

+ +
+ + + + + +
+ + + +
+
+ + + + diff --git a/pages/admin/editjob.php b/pages/admin/editjob.php new file mode 100644 index 0000000..44decbc --- /dev/null +++ b/pages/admin/editjob.php @@ -0,0 +1,165 @@ + + + + + + Jo's Jobs - Edit Job + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ + prepare('UPDATE job + SET title = :title, + description = :description, + salary = :salary, + location = :location, + categoryId = :categoryId, + closingDate = :closingDate + WHERE id = :id + '); + + $criteria = [ + 'title' => $_POST['title'], + 'description' => $_POST['description'], + 'salary' => $_POST['salary'], + 'location' => $_POST['location'], + 'categoryId' => $_POST['categoryId'], + 'closingDate' => $_POST['closingDate'], + 'id' => $_POST['id'] + ]; + + $stmt->execute($criteria); + + + echo 'Job saved'; + } + else { + if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) { + + $stmt = $pdo->prepare('SELECT * FROM job WHERE id = :id'); + + $stmt->execute($_GET); + + $job = $stmt->fetch(); + ?> + +

Edit Job

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

Log in

+ +
+ + + + + +
+ + +
+
+ + + + diff --git a/pages/admin/index.php b/pages/admin/index.php new file mode 100644 index 0000000..c342d45 --- /dev/null +++ b/pages/admin/index.php @@ -0,0 +1,92 @@ + + + + + + Jo's Jobs - Admin Home + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ + + + + +
+ +
+ +
+

You are now logged in

+
+ +

Log in

+ +
+ + + + + +
+ + + +
+ + + + + diff --git a/pages/admin/jobs.php b/pages/admin/jobs.php new file mode 100644 index 0000000..e1b0f3f --- /dev/null +++ b/pages/admin/jobs.php @@ -0,0 +1,122 @@ + + + + + + Jo's Jobs - Job list + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ + + + +

Jobs

+ + Add new job + + '; + echo ''; + echo ''; + echo 'Title'; + echo 'Salary'; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ''; + + $stmt = $pdo->query('SELECT * FROM job'); + + foreach ($stmt as $job) { + $applicants = $pdo->prepare('SELECT count(*) as count FROM applicants WHERE jobId = :jobId'); + + $applicants->execute(['jobId' => $job['id']]); + + $applicantCount = $applicants->fetch(); + + echo ''; + echo '' . $job['title'] . ''; + echo '' . $job['salary'] . ''; + echo 'Edit'; + echo 'View applicants (' . $applicantCount['count'] . ')'; + echo '
+ + +
'; + echo ''; + } + + echo ''; + echo ''; + + } + + else { + ?> +

Log in

+ +
+ + + + +
+ + +
+
+ + + + + + diff --git a/pages/apply.php b/pages/apply.php new file mode 100644 index 0000000..055e8ac --- /dev/null +++ b/pages/apply.php @@ -0,0 +1,145 @@ + + + + + + Jo's Jobs - Apply + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ + $_POST['name'], + 'email' => $_POST['email'], + 'details' => $_POST['details'], + 'jobId' => $_POST['jobId'], + 'cv' => $fileName + ]; + + $stmt = $pdo->prepare('INSERT INTO applicants (name, email, details, jobId, cv) + VALUES (:name, :email, :details, :jobId, :cv)'); + + $stmt->execute($criteria); + + echo 'Your application is complete. We will contact you after the closing date.'; + + + } + else { + echo 'There was an error uploading your CV'; + } + + + + } + else { + + $stmt = $pdo->prepare('SELECT * FROM job WHERE id = :id'); + + $stmt->execute($_GET); + + $job = $stmt->fetch(); + ?> + +

Apply for

+ +
+ + + + + + + + + + + + + + + + +
+ + + + + +
+
+ + + + + + + diff --git a/pages/hr.php b/pages/hr.php new file mode 100644 index 0000000..89412aa --- /dev/null +++ b/pages/hr.php @@ -0,0 +1,93 @@ + + + + + Jo's Jobs - Human Resources + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ +

Human Resources Jobs

+ + + +
+
+ + + + + + diff --git a/pages/it.php b/pages/it.php new file mode 100644 index 0000000..e047753 --- /dev/null +++ b/pages/it.php @@ -0,0 +1,93 @@ + + + + + Jo's Jobs - IT Jobs + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ +

IT Jobs

+ + + +
+
+ + + + + + diff --git a/pages/sales.php b/pages/sales.php new file mode 100644 index 0000000..29fe78e --- /dev/null +++ b/pages/sales.php @@ -0,0 +1,93 @@ + + + + + Jo's Jobs - Sales + + +
+
+ +

Jo's Jobs

+ +
+
+ + +
+ +
+ +
+ +
+ +

Sales Jobs

+ + + +
+
+ + + + + + diff --git a/public/images/banners/1.jpg b/public/images/banners/1.jpg new file mode 100644 index 0000000..03430d7 Binary files /dev/null and b/public/images/banners/1.jpg differ diff --git a/public/images/banners/2.jpg b/public/images/banners/2.jpg new file mode 100644 index 0000000..9926068 Binary files /dev/null and b/public/images/banners/2.jpg differ diff --git a/public/images/banners/3.jpg b/public/images/banners/3.jpg new file mode 100644 index 0000000..8460725 Binary files /dev/null and b/public/images/banners/3.jpg differ diff --git a/public/images/randombanner.php b/public/images/randombanner.php new file mode 100644 index 0000000..ed02e6f --- /dev/null +++ b/public/images/randombanner.php @@ -0,0 +1,26 @@ +isDot()) { + continue; + } + + if (!strpos($file->getFileName(), '.jpg')) { + continue; + } + + $files[] = $file->getFileName(); +} + +header('content-type: image/jpg'); + +$contents = file_get_contents('./banners/' . $files[rand(0,count($files)-1)]); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header('content-length: ' . strlen($contents)); + +echo $contents; diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..1603ce2 --- /dev/null +++ b/public/index.php @@ -0,0 +1,6 @@ +run(); +?> diff --git a/public/styles.css b/public/styles.css new file mode 100644 index 0000000..66e62b5 --- /dev/null +++ b/public/styles.css @@ -0,0 +1,122 @@ +/* import fonts */ +@import url('https://stockfont.org/?3e1218d9a01517d5734a1be9e67be4af797abff1230ab272235ec8ed759251d6'); +* {margin: 0; padding: 0;} + +html {font-family: 'Oxygen-Regular', verdana, sans-serif; } + +body {background-color: #eaeaea;} +header {background-color: #4b72ad + +; color: white; + +height: 200px; + +} + +header img {width: 500px; float: left; background-color: white; border-radius: 20px; margin-top: 20px;} +header aside {float: right; margin-top: 15px;} +header section {width: 1000px; display: block; margin:auto;} +header h1 {float: left; margin-left: 20px;} +nav {width: 100%; background-color: #264f87; overflow: auto;} +body > img {width: 100%; display: block;} +nav ul {width: 1000px; margin: auto; display: block; list-style-type: none;} +nav ul li {width: 25%; float: left; overflow: auto; text-align: center;} +nav li {color: white; padding-top: 10px; display: block;} +nav a {color: white; text-decoration: none} +nav ul ul { + max-height: 0; + position: absolute; + overflow: hidden; + background-color: #264f87; + transition: max-height 0.5s; + margin-left: 4em; + width: 20vw; +} +main ul { + margin-left: 3em; +} + +nav ul ul li { float: none; text-align: left; margin-left: 3em; width: auto;} + + li:hover ul { max-height: 400px; } + + +main a { + color: #333; +} + +nav {font-family: 'Oxygen-Regular';} +header section { display: block; font-family: 'Oxygen-Regular', cursive;} + +header h1 {font-weight: normal;} + + +h1 { font-size:4em; color: white; text-align: center; padding-top: 20px; text-shadow: 2px 2px 2px #000;} + +main {min-height: 50vh; background-color: #fff; width: 70vw; display: block; margin: auto; box-shadow: 0px 0px 10px #888; color:#444;} +footer {min-height: 5vh; color: white;} + +main h2 {font-size:2em;} +.home {padding: 5vw; width: 60vw;} + +p, li, h2 {margin-bottom: 1em;} +ol {margin-left: 30px;} + +pre {margin-top: 20px;} +code {background-color: #ccc;} +pre code {display: block;} + +footer {background-color: #4b72ad; padding: 10px; color: white;} + +form select, form label, form input, form textarea {float: left; width: 200px; padding: 10px; margin-top: 20px;} +form label {clear: left;} +textarea {height: 100px;} +form input[type="text"], form input[type="password"], textarea {color: #999; font-family: verdana, sans-serif} +input[type="submit"] {clear: both; margin-left: 220px; width: 220px;} + + +.left ul {list-style-type: none } +section a {color: #444;} + +form select {width: 220px;} +table {width: 100%; margin-top: 20px;} +td {padding: 5px; border-bottom: 1px solid #333;} + +.jobs {list-style-type: none} +.jobs strong {width: 150px; float: left; clear: left;} +.jobs p {width: 500px; float: left;} + +.jobs li {padding-top: 20px; padding-bottom: 20px; border-bottom: 2px solid #aaa; overflow: auto} +.jobs a {float: right; clear: both;} + +img.shop {width: 800px;} + +.stock, .sidebar {display: table;} +.stock > ul, .sidebar .left { width: 10vw; list-style-type: none; display: table-cell; padding: 10px; background-color: #555; margin: 0;} + +.stock .products, .sidebar .right {display: table-cell; padding: 20px;} + +.stock > ul a, .sidebar .left a {color: white; text-decoration: none;} + +table td input[type="submit"] {margin: 0; float: right; width: auto; padding: auto;} + +.listing ul {margin-top: 40px; list-style-type: none;} +.listing li {border-top: 2px solid #888; padding: 20px; overflow: auto;} + +.listing li .noimage, .listing li img {width: 20%; margin-right: 4%; min-height: 50px; float: left;} +.listing .info {float: left; width: 75%;} + +.current {background-color: #ddd; color: #333; display: block; } +.current a {color: #333 !important;} +.stock > ul .current a {color: #333;} +.categories li {margin: 0; padding: 0.5em; font-size: 2em;} + +.products > img {max-height: 300px;} + +a:hover {color: #ccc !important;} + +.right {padding: 20px;} + +main h1 {color: #666;} + +main img {display: block;} \ No newline at end of file diff --git a/templates/home.html.php b/templates/home.html.php new file mode 100644 index 0000000..af8d1b7 --- /dev/null +++ b/templates/home.html.php @@ -0,0 +1,7 @@ +

Welcome to Jo's Jobs, we're a recruitment agency based in Northampton. We offer a range of different office jobs. Get in touch if you'd like to list a job with us.

+

Select the type of job you are looking for:

+ \ No newline at end of file diff --git a/templates/layout.html.php b/templates/layout.html.php new file mode 100644 index 0000000..c52c243 --- /dev/null +++ b/templates/layout.html.php @@ -0,0 +1,40 @@ + + + + + <?=$title;?> + + +
+
+ +

Jo's Jobs

+
+
+ + +
+ +
+ + + diff --git a/todo b/todo new file mode 100644 index 0000000..12fbbea --- /dev/null +++ b/todo @@ -0,0 +1,26 @@ +Assignment 2: + - Copyright updates to current year @done + - Add FAQs page + - Placeholder text ('FAQs coming soon') + - Menu link + - Admin can update categories but are not visable on site + - Add cats to Jobs page + - Add cats to nav bar + - Job list in admin area lists all jobs + - Add cat name as new column in table + - Add filter to be able to filter by cat + - Allow customers to filter by location + - Add admin user control to admin panel + - Client user accounts + - restricted admin panel + - add and remove jobs + - see who has applied for jobs + - Client can only see their jobs + - Homepage has 10 jobs that are about to reach closing date + - Contact form on contact page + - forms store data in db + - stored enquiries can be accessed from admin panel + - can mark enquieries as Completed once admin has responded + - Keep list of all previous enquieries and which admin dealt with it + - Create entity classes for database entities (topic 18) + - page 37-38 for implementation