Compare commits

..

10 Commits

Author SHA1 Message Date
Joshua Perry 5cbd031279 comments 2023-02-05 23:35:31 +00:00
Joshua Perry dd6c8d1cab finished 2023-02-05 23:04:45 +00:00
Joshua Perry 1f487fe45e added enquiry admin portal 2023-02-05 16:13:36 +00:00
Joshua Perry e9f4b7de97 contact page added 2023-02-05 15:56:21 +00:00
Joshua Perry 86bb50cc47 user creation portal 2023-02-05 15:36:11 +00:00
Joshua Perry 2e21773018 edit category fixed 2023-02-05 15:05:54 +00:00
Joshua Perry 27d8600ea8 better addjob 2023-02-05 14:58:16 +00:00
Joshua Perry 7e29e9c8b4 can relist archived listings 2023-02-05 14:09:02 +00:00
Joshua Perry d8173208da archive instead of delete 2023-02-05 13:50:57 +00:00
Joshua Perry dfc971f9c0 partial implementation of archive of jobs 2023-02-05 13:13:12 +00:00
28 changed files with 485 additions and 135 deletions

View File

@ -20,14 +20,14 @@ class DatabaseTable {
$this->pdo = new \PDO('mysql:dbname='.$this->schema.';host='.$this->server, $this->username, $this->password); $this->pdo = new \PDO('mysql:dbname='.$this->schema.';host='.$this->server, $this->username, $this->password);
} }
private function insert($record) { private function insert($record) { //Insert record into table
$keys = \array_keys($record); $keys = \array_keys($record);
$columns = \implode(', ', $keys); $columns = \implode(', ', $keys);
$values = \implode(', :', $keys); $values = \implode(', :', $keys);
$this->pdo->prepare('INSERT INTO '. $this->table . ' (' . $columns . ') VALUES (:' . $values . ')')->execute($record); $this->pdo->prepare('INSERT INTO '. $this->table . ' (' . $columns . ') VALUES (:' . $values . ')')->execute($record);
} }
private function update($record) { private function update($record) { //Update record in table
$params = []; $params = [];
foreach ($record as $key => $value) { foreach ($record as $key => $value) {
$params[] = $key . ' = :' .$key; $params[] = $key . ' = :' .$key;
@ -36,7 +36,7 @@ class DatabaseTable {
$this->pdo->prepare('UPDATE '. $this->table .' SET '. \implode(', ', $params) .' WHERE '. $this->pk .' = :primaryKey')->execute($record); $this->pdo->prepare('UPDATE '. $this->table .' SET '. \implode(', ', $params) .' WHERE '. $this->pk .' = :primaryKey')->execute($record);
} }
public function find($columns, $values, $comparators = ['=', '='], $order = "ASC", $orderColumn = "id") { public function find($columns, $values, $comparators = ['=', '='], $order = "ASC", $orderColumn = "id") { //Find rows in table
$string = 'SELECT * FROM '.$this->table.' WHERE '; $string = 'SELECT * FROM '.$this->table.' WHERE ';
for ($i = 0; $i < count($values); $i++) { for ($i = 0; $i < count($values); $i++) {
if ($i > 0) { if ($i > 0) {
@ -51,21 +51,21 @@ class DatabaseTable {
return $stmt->fetchAll(); return $stmt->fetchAll();
} }
public function findAll() { public function findAll() { //Find all rows in table
$stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table); $stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table);
$stmt->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor); $stmt->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor);
$stmt->execute(); $stmt->execute();
return $stmt->fetchAll(); return $stmt->fetchAll();
} }
public function delete($column, $value) { public function delete($column, $value) { //Delete row from table
$values = [ $values = [
'value' => $value 'value' => $value
]; ];
$this->pdo->prepare('DELETE FROM '. $this->table .' WHERE '. $column .' = :value')->execute($values); $this->pdo->prepare('DELETE FROM '. $this->table .' WHERE '. $column .' = :value')->execute($values);
} }
public function save($record) { public function save($record) { //Save record to table
if (empty($record[$this->pk])) { if (empty($record[$this->pk])) {
unset($record[$this->pk]); unset($record[$this->pk]);
} }

View File

@ -7,14 +7,14 @@ class EntryPoint {
$this->routes = $routes; $this->routes = $routes;
} }
public function loadTemplate($fileName, $templateData) { public function loadTemplate($fileName, $templateData) { //Load HTML template
\extract($templateData); \extract($templateData);
\ob_start(); \ob_start();
require $fileName; require $fileName;
return \ob_get_clean(); return \ob_get_clean();
} }
public function run() { public function run() { //run response
$route = \ltrim(\explode('?', $_SERVER['REQUEST_URI'])[0], '/'); $route = \ltrim(\explode('?', $_SERVER['REQUEST_URI'])[0], '/');

View File

@ -11,7 +11,7 @@ class Routes {
$this->loginControllers = []; $this->loginControllers = [];
} }
public function getController($controllerName, $functionName) { public function getController($controllerName, $functionName) { //get controller
$this->checkLogin($controllerName); $this->checkLogin($controllerName);
@ -29,11 +29,11 @@ class Routes {
} }
public function getDefaultRoute() { public function getDefaultRoute() { //Default request route
return 'controller/home'; return 'controller/home';
} }
public function checkLogin($name) { public function checkLogin($name) { //Check if controller requires user to be logged in
$requiresLogin = $this->loginControllers[$name] ?? false; $requiresLogin = $this->loginControllers[$name] ?? false;
if ($requiresLogin && !isset($_SESSION['loggedin'])) { if ($requiresLogin && !isset($_SESSION['loggedin'])) {
@ -42,7 +42,7 @@ class Routes {
} }
} }
//404 Page
public function notFound() { public function notFound() {
return ['template' => 'response.html.php', return ['template' => 'response.html.php',
'title' => '404 Not Found', 'title' => '404 Not Found',

View File

@ -1,6 +1,6 @@
<?php <?php
namespace jobs\Entity; namespace jobs\Entity;
class Applicant { class Applicant { //Represents Applicant Entity from applicants table
public $id; public $id;
public $name; public $name;
public $email; public $email;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace jobs\Entity; namespace jobs\Entity;
class Category { class Category { //Represents category Entity from categories table
public $id; public $id;
public $name; public $name;
} }

27
jobs/Entity/Enquiry.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace jobs\Entity;
class Enquiry { //Represents enquiry Entity from enquiries table
public $id;
public $name;
public $email;
public $telephone;
public $enquiry;
public $completed;
public $admin_id;
private $usersTable;
public function __construct(\jobs\JobDatabaseTable $usersTable) {
$this->usersTable = $usersTable;
}
public function getAdmin() { //Get the admin that completed the enquiry
if ($this->completed == 'y') {
return $this->usersTable->find(['id'], ['value0' => $this->admin_id])[0];
}
else {
return 'N/A';
}
}
}
?>

View File

@ -1,6 +1,6 @@
<?php <?php
namespace jobs\Entity; namespace jobs\Entity;
class Job { class Job { //Represents Job Entity from jobs table
public $id; public $id;
public $title; public $title;
public $description; public $description;
@ -9,6 +9,7 @@ class Job {
public $location; public $location;
public $categoryId; public $categoryId;
public $clientId; public $clientId;
public $archived;
private $catsTable; private $catsTable;
private $appsTable; private $appsTable;
@ -17,11 +18,11 @@ class Job {
$this->appsTable = $appsTable; $this->appsTable = $appsTable;
} }
public function getCat() { public function getCat() { //Get category job is in
return $this->catsTable->find(['id'], ['value0' => $this->categoryId])[0]; return $this->catsTable->find(['id'], ['value0' => $this->categoryId])[0];
} }
public function getApps() { public function getApps() { //Get applicants for job
return $this->appsTable->find(['jobId'], ['value0' => $this->id]); return $this->appsTable->find(['jobId'], ['value0' => $this->id]);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace jobs\Entity; namespace jobs\Entity;
class User { class User { //Represents User Entity from userss table
public $id; public $id;
public $username; public $username;
public $password; public $password;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace jobs; namespace jobs;
class JobDatabaseTable extends \CSY2028\DatabaseTable { class JobDatabaseTable extends \CSY2028\DatabaseTable { //Represents A table from the schema for this site
protected $server = 'mysql'; protected $server = 'mysql';
protected $username = 'student'; protected $username = 'student';
protected $password = 'student'; protected $password = 'student';

View File

@ -1,14 +1,14 @@
<?php <?php
namespace jobs; namespace jobs;
class Routes extends \CSY2028\Routes { class Routes extends \CSY2028\Routes { //Represents the routes for this site
public function __construct() { public function __construct() {
$this->setDbTables(); $this->setDbTables();
$this->controllers = [ $this->controllers = [
"jobs" => new \jobs\controllers\Jobs($this->databaseTables["jobs"], $this->databaseTables["categories"], $this->databaseTables["applicants"]), "jobs" => new \jobs\controllers\Jobs($this->databaseTables["jobs"], $this->databaseTables["categories"], $this->databaseTables["applicants"], $this->databaseTables['enquiries']),
"portal" => new \jobs\controllers\Portal($this->databaseTables["categories"], $this->databaseTables["jobs"], $this->databaseTables["applicants"]), "portal" => new \jobs\controllers\Portal($this->databaseTables["categories"], $this->databaseTables["jobs"], $this->databaseTables["applicants"], $this->databaseTables['users'], $this->databaseTables['enquiries']),
"user" => new \jobs\controllers\User($this->databaseTables["users"], $this->databaseTables["categories"]) "user" => new \jobs\controllers\User($this->databaseTables["users"], $this->databaseTables["categories"])
]; ];
$this->loginControllers = [ $this->loginControllers = [
@ -26,6 +26,7 @@ class Routes extends \CSY2028\Routes {
$this->databaseTables["applicants"] = new \jobs\JobDatabaseTable('applicants', 'id', '\jobs\Entity\Applicant'); $this->databaseTables["applicants"] = new \jobs\JobDatabaseTable('applicants', 'id', '\jobs\Entity\Applicant');
$this->databaseTables["jobs"] = new \jobs\JobDatabaseTable('job', 'id', '\jobs\Entity\Job', [$this->databaseTables["categories"], $this->databaseTables['applicants']]); $this->databaseTables["jobs"] = new \jobs\JobDatabaseTable('job', 'id', '\jobs\Entity\Job', [$this->databaseTables["categories"], $this->databaseTables['applicants']]);
$this->databaseTables["users"] = new \jobs\JobDatabaseTable('users', 'id', '\jobs\Entity\User'); $this->databaseTables["users"] = new \jobs\JobDatabaseTable('users', 'id', '\jobs\Entity\User');
$this->databaseTables["enquiries"] = new \jobs\JobDatabaseTable('enquiries', 'id', '\jobs\Entity\Enquiry', [$this->databaseTables['users']]);
} }
} }
?> ?>

View File

@ -4,40 +4,43 @@ class Jobs {
private $jobsTable; private $jobsTable;
private $catsTable; private $catsTable;
private $appsTable; private $appsTable;
private $enquiryTable;
private $vars = []; private $vars = [];
public function __construct(\jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $appsTable) { public function __construct(\jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $appsTable, \jobs\JobDatabaseTable $enquiryTable) {
$this->jobsTable = $jobsTable; $this->jobsTable = $jobsTable;
$this->catsTable = $catsTable; $this->catsTable = $catsTable;
$this->appsTable = $appsTable; $this->appsTable = $appsTable;
$this->enquiryTable = $enquiryTable;
$this->vars['cats'] = $this->catsTable->findAll(); $this->vars['cats'] = $this->catsTable->findAll();
} }
//Homepage
public function home() { public function home() { //Route: jobs.v.je/jobs/home
$this->vars['jobs'] = $this->jobsTable->find(["closingDate"], ['value0' => date('y-m-d')], ['>'], "DESC", "closingDate"); $this->vars['jobs'] = $this->jobsTable->find(["closingDate", 'archived'], ['value0' => date('y-m-d'), 'value1' => 'n'], ['>', '='], "DESC", "closingDate");
return ['template' => 'home.html.php', return ['template' => 'home.html.php',
'title' => 'Jo\'s Jobs- Home', 'title' => 'Jo\'s Jobs- Home',
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }
//Category pages
public function category() { public function category() { //Route: jobs.v.je/jobs/category
$cat = $this->catsTable->find(['name'], ['value0' => $_GET['page']]); $cat = $this->catsTable->find(['name'], ['value0' => $_GET['page']]);
if ($cat == null) { if ($cat == null) {
return $this->notFound(); return $this->notFound();
} }
else { else {
if (isset($_GET['filter'])) { if (isset($_GET['filter'])) { //location filter for jobs
$columns = ['categoryId', "location", 'closingDate']; $columns = ['categoryId', "location", 'closingDate', 'archived'];
$values = ['value0' => $cat[0]->id, $values = ['value0' => $cat[0]->id,
'value1' => $_GET['filter'], 'value1' => $_GET['filter'],
'value2' => date('y-m-d') 'value2' => date('y-m-d'),
'value3' => 'n'
]; ];
$comparators = ["=","=",">"]; $comparators = ["=","=",">",'='];
$this->vars['jobs'] = $this->jobsTable->find($columns, $values, $comparators); $this->vars['jobs'] = $this->jobsTable->find($columns, $values, $comparators);
} }
else { else {
$this->vars['jobs'] = $this->jobsTable->find(['categoryId', 'closingDate'], ["value0" => $cat[0]->id, "value1" => date("y-m-d")], ["=", ">"]); $this->vars['jobs'] = $this->jobsTable->find(['categoryId', 'closingDate', 'archived'], ["value0" => $cat[0]->id, "value1" => date("y-m-d"), 'value2' => 'n'], ["=", ">", '=']);
} }
$this->vars['heading'] = $cat[0]->name; $this->vars['heading'] = $cat[0]->name;
@ -47,32 +50,52 @@ class Jobs {
]; ];
} }
} }
//About page
public function about() { public function about() { //Route: jobs.v.je/jobs/about
return ['template' => 'about.html.php', return ['template' => 'about.html.php',
'title' => 'Jo\'s Jobs- About us', 'title' => 'Jo\'s Jobs- About us',
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }
//Contact page
public function contact() { //Route: jobs.v.je/jobs/contact
public function notFound() { return ['template' => 'contact.html.php',
'title' => 'Jo\'s Jobs- Contact',
'vars' => $this->vars
];
}
//Contact page POST
public function contactSubmit() { //Route: jobs.v.je/jobs/contact
$record = [
'name' => $_POST['name'],
'email' => $_POST['email'],
'telephone' => $_POST['number'],
'enquiry' => $_POST['enquiry']
];
$this->enquiryTable->save($record);
$this->vars['response'] = 'Enquiry Sent';
return ['template' => 'response.html.php',
'title' => 'Jo\'s Jobs- Enquiry Sent',
'vars' => $this->vars];
}
//404 page
public function notFound() { //Route: jobs.v.je/jobs/notFound
$this->vars['response'] = 'The page you have requested has not been found'; $this->vars['response'] = 'The page you have requested has not been found';
return ['template' => 'response.html.php', return ['template' => 'response.html.php',
'title' => 'Jo\'s Jobs- 404 Not Found', 'title' => 'Jo\'s Jobs- 404 Not Found',
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }
//Job Application page
public function apply() { public function apply() { //Route: jobs.v.je/jobs/apply
$this->vars['job'] = $this->jobsTable->find(['id'], ["value0" => $_GET['id']])[0]; $this->vars['job'] = $this->jobsTable->find(['id'], ["value0" => $_GET['id']])[0];
return ['template' => 'apply.html.php', return ['template' => 'apply.html.php',
'title' => 'Jo\'s Jobs- Apply', 'title' => 'Jo\'s Jobs- Apply',
'vars' => $this->vars]; 'vars' => $this->vars];
} }
//Job Application page POST
public function applySubmit() { public function applySubmit() { //Route: jobs.v.je/jobs/apply
if ($_FILES['cv']['error'] == 0) { if ($_FILES['cv']['error'] == 0) {
$parts = explode('.', $_FILES['cv']['name']); $parts = explode('.', $_FILES['cv']['name']);
$extension = end($parts); $extension = end($parts);
@ -102,8 +125,8 @@ class Jobs {
'vars' => $this->vars]; 'vars' => $this->vars];
} }
//FAQ Page
public function faq() { public function faq() { //Route: jobs.v.je/jobs/faq
return ['template' => 'construction.html.php', return ['template' => 'construction.html.php',
'title' => 'Jo\'s Jobs- FAQ', 'title' => 'Jo\'s Jobs- FAQ',
'vars' => $this->vars]; 'vars' => $this->vars];

View File

@ -4,17 +4,21 @@ class Portal {
private $catsTable; private $catsTable;
private $jobsTable; private $jobsTable;
private $appsTable; private $appsTable;
private $usersTable;
private $enquiryTable;
private $vars; private $vars;
public function __construct(\jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $appsTable) { public function __construct(\jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $appsTable, \jobs\JobDatabaseTable $usersTable, \jobs\JobDatabaseTable $enquiryTable) {
$this->catsTable = $catsTable; $this->catsTable = $catsTable;
$this->jobsTable = $jobsTable; $this->jobsTable = $jobsTable;
$this->appsTable = $appsTable; $this->appsTable = $appsTable;
$this->usersTable = $usersTable;
$this->enquiryTable = $enquiryTable;
$this->vars['cats'] = $this->catsTable->findAll(); $this->vars['cats'] = $this->catsTable->findAll();
$this->vars['table'] = 'job_table.html.php'; $this->vars['table'] = 'job_table.html.php';
} }
//Portal homepage
public function home() { public function home() { //Route: jobs.v.je/portal/
$this->vars['table'] = 'job_table.html.php'; $this->vars['table'] = 'job_table.html.php';
if (isset($_GET['filter'])) { if (isset($_GET['filter'])) {
if ($_SESSION['userType'] == 'client') { if ($_SESSION['userType'] == 'client') {
@ -36,19 +40,47 @@ class Portal {
'title' => 'Jo\'s Jobs- Jobs', 'title' => 'Jo\'s Jobs- Jobs',
'vars' => $this->vars]; 'vars' => $this->vars];
} }
//Portal homepage POST
public function homeSubmit() { public function homeSubmit() { //Route: jobs.v.je/portal/
if (isset($_POST['job_id'])) { if ($_POST['submit'] == "List") { //Relist archived job
$this->jobsTable->delete("id", $_POST['job_id']); $this->vars['job'] = $this->jobsTable->find(['id'], ['value0' => $_POST['job_id']])[0];
$this->vars['archive'] = true;
$this->vars['update'] = true;
return ['template' => 'job_add.html.php',
'title' => 'Jo\'s Jobs- Update Job',
'vars' => $this->vars];
}
else {
if (isset($_POST['job_id'])) { //archive job
$record = [
'id' => $_POST['job_id'],
'archived' => 'y'
];
$this->jobsTable->save($record);
return $this->home(); return $this->home();
} }
if (isset($_POST['cat_id'])) { if (isset($_POST['cat_id'])) { //delete category
$this->catsTable->delete("id", $_POST['cat_id']); $this->catsTable->delete("id", $_POST['cat_id']);
$jobs = $this->jobsTable->find(['categoryId'], ['value0' => $_POST['cat_id']]);
foreach ($jobs as $job) {
$this->jobsTable->delete("id", $job->id);
}
return $this->categories(); return $this->categories();
} }
if (isset($_POST['user_id'])) { //delete user
if($_POST['user_type'] == 'client') {
$this->usersTable->delete('id', $_POST['user_id']);
$jobs = $this->jobsTable->find(['clientId'], ['value0' => $_POST['user_id']]);
foreach ($jobs as $job) {
$this->jobsTable->delete('id', $job->id);
} }
return $this->users();
public function categories() { }
}
}
}
//Categories Portal page
public function categories() { //Route: jobs.v.je/portal/categories
if ($_SESSION['userType'] == 'admin') { if ($_SESSION['userType'] == 'admin') {
$this->vars['table'] = 'category_table.html.php'; $this->vars['table'] = 'category_table.html.php';
$this->vars['cats'] = $this->catsTable->findAll(); $this->vars['cats'] = $this->catsTable->findAll();
@ -57,8 +89,8 @@ class Portal {
'vars' => $this->vars]; 'vars' => $this->vars];
} }
} }
//Applicants Portal page
public function applicants() { public function applicants() { //Route: jobs.v.je/portal/applicants
$job = $this->jobsTable->find(['id'], ['value0' => $_GET['job_id']])[0]; $job = $this->jobsTable->find(['id'], ['value0' => $_GET['job_id']])[0];
$this->vars['table'] = 'applicant_table.html.php'; $this->vars['table'] = 'applicant_table.html.php';
$this->vars['apps'] = $job->getApps(); $this->vars['apps'] = $job->getApps();
@ -67,25 +99,98 @@ class Portal {
'title' => 'Jo\'s Jobs- Applicants', 'title' => 'Jo\'s Jobs- Applicants',
'vars' => $this->vars]; 'vars' => $this->vars];
} }
//Users Portal page
public function edit() { //TODO: finish this function public function users() { //Route: jobs.v.je/portal/users
if (isset($_GET['job_id'])) { if ($_SESSION['userType'] == 'admin') {
$this->vars['job'] = $this->jobsTable->find(["id"], ['value0' => $_GET['jod_id']]); $this->vars['table'] = 'user_table.html.php';
} $this->vars['users'] = $this->usersTable->findAll();
if (isset($_GET['cat_id'])) { return ['template' => 'portal.html.php',
$this->vars['cat'] = $this->catsTable->find(["id"], ['value0' => $_GET['cat_id']]); 'title' => 'Jo\'s Jobs- Users',
}
}
public function addJob() {
return ['template' => 'job_add.html.php',
'title' => 'Jo\'s Jobs- Add Job',
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }
}
public function addJobSubmit() { //Enquiries Portal page
if (count($this->jobsTable->find(['title', 'clientId'], ['value0' => $_POST['title'], 'value1' => $_POST['client_id']])) == 0 && $this->catsTable->find(['name'], ['value0' => $_POST['categoryName']]) != 0) { public function enquiries() { //Route: jobs.v.je/portal/enquiries
if ($_SESSION['userType'] == 'admin') {
$this->vars['table'] = 'enquiry_table.html.php';
$this->vars['enqs'] = $this->enquiryTable->findAll();
return ['template' => 'portal.html.php',
'title' => 'Jo\'s Jobs- Enquiries',
'vars' => $this->vars
];
}
}
//Enquiries Portal page POST
public function enquiriesSubmit() { //Route: jobs.v.je/portal/enquiries
$record = [
'id' => $_POST['enq_id'],
'completed' => 'y',
'admin_id' => $_SESSION['loggedin']
];
$this->enquiryTable->save($record);
$this->enquiries();
}
//Edit User Portal page
public function addUser() { //Route: jobs.v.je/portal/addUser
if ($_SESSION['userType'] == 'admin') {
if (isset($_GET['user_id'])) { //Update user
$this->vars['user'] = $this->usersTable->find(['id'], ['value0' => $_GET['user_id']])[0];
$this->vars['update'] = true;
}
else { //Create user
$this->vars['update'] = false;
}
return ['template' => 'user_add.html.php',
'title' => 'Jo\'s Jobs- Edit user',
'vars' => $this->vars
];
}
}
//Edit User Portal page POST
public function addUserSubmit() {
if ($_SESSION['userType'] == 'admin') {
if($_POST['password'] != "") {
$record = [
'username' => $_POST['username'],
'password' => password_hash($_POST['password'], PASSWORD_DEFAULT),
'userType' => $_POST['type']
];
if ($_POST['submit'] == 'Update') {
$record['id'] = $_POST['user_id'];
$this->vars['response'] = 'User Updated Successfully';
}
else {
$this->vars['response'] = 'User Created Successfully';
}
$this->usersTable->save($record);
return [
'template' => 'response.html.php',
'title' => 'Jo\'s Jobs- Edit user',
'vars' => $this->vars
];
}
}
}
//Edit Job Portal page
public function addJob() { //Route: jobs.v.je/portal/addJob
if (isset($_GET['job_id'])) { //Update Job
$this->vars['job'] = $this->jobsTable->find(["id"], ['value0' => $_GET['job_id']])[0];
$this->vars['archive'] = false;
$this->vars['update'] = true;
}
else { //Create Job
$this->vars['archive'] = false;
$this->vars['update'] = false;
}
return ['template' => 'job_add.html.php',
'title' => 'Jo\'s Jobs- Edit Job',
'vars' => $this->vars
];
}
//Edit Job page POST
public function addJobSubmit() { //Route: jobs.v.je/portal/addJob
if ($this->catsTable->find(['name'], ['value0' => $_POST['categoryName']]) != 0) {
$record = [ $record = [
'title' => $_POST['title'], 'title' => $_POST['title'],
'description' => $_POST['description'], 'description' => $_POST['description'],
@ -93,33 +198,49 @@ class Portal {
'closingDate' => $_POST['closingDate'], 'closingDate' => $_POST['closingDate'],
'categoryId' => $this->catsTable->find(['name'], ['value0' => $_POST['categoryName']])[0]->id, 'categoryId' => $this->catsTable->find(['name'], ['value0' => $_POST['categoryName']])[0]->id,
'location' => $_POST['location'], 'location' => $_POST['location'],
'clientId' => $_POST['client_id'] 'clientId' => $_POST['client_id'],
'archived' => $_POST['archived']
]; ];
if ($_POST['submit'] == 'Create' && count($this->jobsTable->find(['title', 'clientId'], ['value0' => $_POST['title'], 'value1' => $_POST['client_id']])) == 0) {
$this->jobsTable->save($record); $this->jobsTable->save($record);
$this->vars['response'] = 'Job made successfully'; $this->vars['response'] = 'Job made successfully';
} }
else if ($_POST['submit'] == 'Update') {
$record['id'] = $_POST['jobId'];
$this->jobsTable->save($record);
$this->vars['response'] = 'Job updated successfully';
}
}
else { else {
$this->vars['response'] = 'Some data was incorrect'; $this->vars['response'] = 'Some data was incorrect';
} }
return ['template' => 'response.html.php', return ['template' => 'response.html.php',
'title' => 'Jo\'s Jobs- Add Job', 'title' => 'Jo\'s Jobs- Edit Job',
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }
//Edit Category page
public function addCategory() { public function addCategory() { //Route: jobs.v.je/portal/addCategory
if ($_SESSION['userType'] == 'admin') { if ($_SESSION['userType'] == 'admin') {
if (isset($_GET['cat_id'])) {
$this->vars['cat'] = $this->catsTable->find(["id"], ['value0' => $_GET['cat_id']])[0];
$this->vars['update'] = true;
}
else {
$this->vars['update'] = false;
}
return ['template' => 'category_add.html.php', return ['template' => 'category_add.html.php',
'title' => 'Jo\'s Jobs- Add Category', 'title' => 'Jo\'s Jobs- Edit Category',
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }
} }
//Edit Category page POST
public function addCategorySubmit() { public function addCategorySubmit() { //Route: jobs.v.je/portal/addCategory
if ($_SESSION['userType'] == 'admin') { if ($_SESSION['userType'] == 'admin') {
if ($_POST['submit'] == 'Create') {
if (count($this->catsTable->find(['name'], ['value0' => $_POST['name']])) > 0) { if (count($this->catsTable->find(['name'], ['value0' => $_POST['name']])) > 0) {
$this->vars['response'] = 'This category already exists'; $this->vars['response'] = 'This category already exists';
} }
@ -130,8 +251,17 @@ class Portal {
$this->catsTable->save($record); $this->catsTable->save($record);
$this->vars['response'] = 'Category Created'; $this->vars['response'] = 'Category Created';
} }
}
else {
$record = [
'id' => $_POST['id'],
'name' => $_POST['name']
];
$this->catsTable->save($record);
$this->vars['response'] = 'Category Updated';
}
return ['template' => 'response.html.php', return ['template' => 'response.html.php',
'title' => 'Jo\'s Jobs- Add Category', 'title' => 'Jo\'s Jobs- Edit Category',
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }

View File

@ -11,14 +11,14 @@ class User {
$this->vars['cats'] = $this->catsTable->findAll(); $this->vars['cats'] = $this->catsTable->findAll();
$this->vars['response'] = ''; $this->vars['response'] = '';
} }
//Login page
public function login() { public function login() { //Route: jobs.v.je/user/login
return ['template' => 'login.html.php', return ['template' => 'login.html.php',
'title' => 'Jo\'s Jobs- Login', 'title' => 'Jo\'s Jobs- Login',
'vars' => $this->vars]; 'vars' => $this->vars];
} }
//Login page POST
public function loginSubmit() { public function loginSubmit() { //Route: jobs.v.je/user/login
if ($_POST['username'] != '' && $_POST['password'] != '') { if ($_POST['username'] != '' && $_POST['password'] != '') {
$user = $this->usersTable->find(["username"], ['value0' => $_POST['username']]); $user = $this->usersTable->find(["username"], ['value0' => $_POST['username']]);
if (password_verify($_POST['password'], $user[0]->password)) { if (password_verify($_POST['password'], $user[0]->password)) {
@ -49,8 +49,8 @@ class User {
'vars' => $this->vars 'vars' => $this->vars
]; ];
} }
//Logout page
public function logout() { public function logout() { //Route: jobs.v.je/user/logout
unset($_SESSION['loggedin']); unset($_SESSION['loggedin']);
unset($_SESSION['userType']); unset($_SESSION['userType']);
$this->vars['response'] = 'Logged Out Successfully'; $this->vars['response'] = 'Logged Out Successfully';

8
phpunit.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<phpunit>
<testsuites>
<testsuite name="tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -1,7 +1,7 @@
<?php <?php
session_start(); session_start(); //make sure session is started
require '../autoload.php'; require '../autoload.php'; //include autoload
$routes = new \jobs\Routes(); $routes = new \jobs\Routes(); //get routes
$entryPoint = new \CSY2028\EntryPoint($routes); $entryPoint = new \CSY2028\EntryPoint($routes); //get entrypoint
$entryPoint->run(); $entryPoint->run(); //start entrypoint
?> ?>

View File

@ -1,7 +1,15 @@
<main class="home"> <main class="home">
<form method="post" action="/portal/addCategory"> <form method="post" action="/portal/addCategory">
<label>Enter Category Name</label> <label>Enter Category Name</label>
<?php if($update) { ?>
<input type="text" name="name" value="<?=$cat->name?>"/>
<input type="hidden" name="id" value="<?=$cat->id?>"/>
<input type="submit" name="submit" value="Update"/>
<?php }
else { ?>
<input type="text" name="name"/> <input type="text" name="name"/>
<input type="submit" name="submit" value="Create"/> <input type="submit" name="submit" value="Create"/>
<?php } ?>
</form> </form>
</main> </main>

View File

@ -10,10 +10,10 @@
<?php foreach ($cats as $cat) { ?> <?php foreach ($cats as $cat) { ?>
<tr> <tr>
<td><?=$cat->name?></td> <td><?=$cat->name?></td>
<td><a style="float: right" href="/portal/edit?cat_id=<?=$cat->id?>">Edit</a></td> <td><a style="float: right" href="/portal/addCategory?cat_id=<?=$cat->id?>">Edit</a></td>
<td><form method="post" action="/portal/"> <td><form method="post" action="/portal/">
<input type="hidden" name="cat_id" value="<?=$cat->id?>" /> <input type="hidden" name="cat_id" value="<?=$cat->id?>" />
<input type="submit" name="submit" value="Archive" /> <input type="submit" name="submit" value="Delete" />
</form></td> </form></td>
</tr> </tr>
<?php } ?> <?php } ?>

View File

@ -0,0 +1,14 @@
<main class="home">
<h2>Contact Us</h2>
<form method="post" action="/jobs/contact">
<label>Name</label>
<input type="text" name="name" />
<label>Email</label>
<input type="email" name="email" />
<label>Telephone Number</label>
<input type="text" name="number" />
<label>Enquiry</label>
<input type="text" name="enquiry" />
<input type="submit" name="submit" value="Send" />
</form>
</main>

View File

@ -0,0 +1,42 @@
<h2>Enquiries</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Telephone</th>
<th>Enquiry</th>
<th>Completed</th>
<th>Handled by</th>
<th style="width: 5%">&nbsp;</th>
<th style="width: 5%">&nbsp;</th>
</tr>
<?php foreach ($enqs as $enq) { ?>
<tr>
<td><?=$enq->name?></td>
<td><?=$enq->email?></td>
<td><?=$enq->telephone?></td>
<td><?=$enq->enquiry?></td>
<td><?=$enq->completed?></td>
<td>
<?php
if ($enq->getAdmin() == 'N/A') {
echo 'N/A';
}
else {
echo $enq->getAdmin()->username;
}
?>
</td>
<?php if($enq->completed == 'n') { ?>
<td>
<form method="post" action="/portal/enquiries">
<input type="hidden" name="enq_id" value="<?=$enq->id?>" />
<input type="submit" name="submit" value="Complete" />
</form>
</td>
<?php } ?>
</tr>
<?php } ?>
</thead>
</table>

View File

@ -1,5 +1,28 @@
<main class="home"> <main class="home">
<form method="post" action="/portal/addJob"> <form method="post" action="/portal/addJob">
<?php if ($update) {?>
<input type="hidden" name="archived" value="<?=$job->archived?>"/>
<label>Enter Job Title</label>
<input type="text" name="title" value="<?=$job->title?>"/>
<label>Enter Job Description</label>
<input type="text" name="description" value="<?=$job->description?>"/>
<label>Enter Salary</label>
<input type="text" name="salary" value="<?=$job->salary?>"/>
<label>Enter Closing Date</label>
<input type="date" name="closingDate" value="<?=$job->closingDate?>"/>
<label>Enter Category Name</label>
<input type="text" name="categoryName" value="<?=$job->getCat()->name?>"/>
<label>Enter Location</label>
<input type="text" name="location" value="<?=$job->location?>"/>
<input type="hidden" name="client_id" value="<?=$job->clientId?>" />
<input type="hidden" name="jobId" value="<?=$job->id?>"/>
<input type="submit" name="submit" value="Update"/>
<?php }
else if ($archive) { ?>
<input type="hidden" name="archived" value="n"/>
<?php }
else { ?>
<input type="hidden" name="archived" value="n"/>
<label>Enter Job Title</label> <label>Enter Job Title</label>
<input type="text" name="title"/> <input type="text" name="title"/>
<label>Enter Job Description</label> <label>Enter Job Description</label>
@ -14,5 +37,6 @@
<input type="text" name="location"/> <input type="text" name="location"/>
<input type="hidden" name="client_id" value="<?=$_SESSION['loggedin']?>" /> <input type="hidden" name="client_id" value="<?=$_SESSION['loggedin']?>" />
<input type="submit" name="submit" value="Create"/> <input type="submit" name="submit" value="Create"/>
<?php } ?>
</form> </form>
</main> </main>

View File

@ -15,6 +15,7 @@
<th>Title</th> <th>Title</th>
<th style="width: 15%">Salary</th> <th style="width: 15%">Salary</th>
<th>Category</th> <th>Category</th>
<th>Archived</th>
<th style="width: 5%">&nbsp;</th> <th style="width: 5%">&nbsp;</th>
<th style="width: 15%">&nbsp;</th> <th style="width: 15%">&nbsp;</th>
<th style="width: 5%">&nbsp;</th> <th style="width: 5%">&nbsp;</th>
@ -25,12 +26,27 @@
<td><?=$job->title?></td> <td><?=$job->title?></td>
<td><?=$job->salary?></td> <td><?=$job->salary?></td>
<td><?=$job->getCat()->name?></td> <td><?=$job->getCat()->name?></td>
<td><a style="float: right" href="portal/edit?job_id=<?=$job->id?>">Edit</a></td> <td>
<?php if ($job->archived == 'n') {
echo 'no';
}
if ($job->archived == 'y') {
echo 'yes';
} ?>
</td>
<td><a style="float: right" href="portal/addJob?job_id=<?=$job->id?>">Edit</a></td>
<td><a style="float: right" href="portal/applicants?job_id=<?=$job->id?>">View applicants (<?=count($job->getApps())?>)</a></td> <td><a style="float: right" href="portal/applicants?job_id=<?=$job->id?>">View applicants (<?=count($job->getApps())?>)</a></td>
<td><form method="post" action="portal/"> <td>
<form method="post" action="portal">
<input type="hidden" name="job_id" value="<?=$job->id?>" /> <input type="hidden" name="job_id" value="<?=$job->id?>" />
<?php if ($job->archived == 'n') { ?>
<input type="submit" name="submit" value="Archive" /> <input type="submit" name="submit" value="Archive" />
</form></td> <?php }
else if ($job->archived == 'y') { ?>
<input type="submit" name="submit" value="List" />
<?php } ?>
</form>
</td>
</tr> </tr>
<?php } ?> <?php } ?>
</thead> </thead>

View File

@ -24,6 +24,7 @@
</li> </li>
<li><a href="/jobs/faq">FAQ</a></li> <li><a href="/jobs/faq">FAQ</a></li>
<li><a href="/jobs/about">About Us</a></li> <li><a href="/jobs/about">About Us</a></li>
<li><a href="/jobs/contact">Contact</a></li>
</ul> </ul>
</nav> </nav>
<img src="../images/randombanner.php"/> <img src="../images/randombanner.php"/>

View File

@ -8,12 +8,12 @@
<?php if (isset($_SESSION['loggedin'])) { <?php if (isset($_SESSION['loggedin'])) {
if ($_SESSION['userType'] == 'admin') {?> if ($_SESSION['userType'] == 'admin') {?>
<li><a href="/portal">Admin Portal</a></li> <li><a href="/portal">Admin Portal</a></li>
<?php } <?php }
else if ($_SESSION['userType'] == 'client') {?> else if ($_SESSION['userType'] == 'client') {?>
<li><a href="/portal">Client Portal</a></li> <li><a href="/portal">Client Portal</a></li>
<?php } ?> <?php } ?>
<li><a href="/user/logout">Logout</a></li> <li><a href="/user/logout">Logout</a></li>
<?php } <?php }
else {?> else {?>
<li><a href="/user/login">Login</a></li> <li><a href="/user/login">Login</a></li>
<?php } ?> <?php } ?>

View File

@ -4,6 +4,8 @@
<li><a href="/portal">Jobs</a></li> <li><a href="/portal">Jobs</a></li>
<?php if ($_SESSION['userType'] == 'admin') { ?> <?php if ($_SESSION['userType'] == 'admin') { ?>
<li><a href="/portal/categories">Categories</a></li> <li><a href="/portal/categories">Categories</a></li>
<li><a href="/portal/enquiries">Enquiries</a></li>
<li><a href="/portal/users">Users</a></li>
<?php } ?> <?php } ?>
</ul> </ul>
</section> </section>

View File

@ -0,0 +1,23 @@
<main class="home">
<form method="post" action="/portal/addUser">
<?php if ($update) {?>
<label>Enter Username</label>
<input type="username" name="username" value="<?=$user->username?>"/>
<label>Enter Password</label>
<input type="password" name="password" value=""/>
<label>Enter User Type</label>
<input type="text" name="type" value="<?=$user->userType?>"/>
<input type="hidden" name="user_id" value="<?=$user->id?>" />
<input type="submit" name="submit" value="Update"/>
<?php }
else { ?>
<label>Enter Username</label>
<input type="username" name="username" />
<label>Enter Password</label>
<input type="password" name="password" />
<label>Enter User Type</label>
<input type="text" name="type" />
<input type="submit" name="submit" value="Create"/>
<?php } ?>
</form>
</main>

View File

@ -0,0 +1,23 @@
<h2>Users</h2>
<a class="new" href="/portal/addUser">Add new user</a>
<table>
<thead>
<tr>
<th>Username</th>
<th>User Type</th>
<th style="width: 5%">&nbsp;</th>
<th style="width: 5%">&nbsp;</th>
</tr>
<?php foreach ($users as $user) { ?>
<tr>
<td><?=$user->username?></td>
<td><a style="float: right" href="/portal/addUser?user_id=<?=$user->id?>">Edit</a></td>
<td><form method="post" action="/portal/">
<input type="hidden" name="user_id" value="<?=$user->id?>" />
<input type="hidden" name="user_type" value="<?=$user->userType?>" />
<input type="submit" name="submit" value="Delete" />
</form></td>
</tr>
<?php } ?>
</thead>
</table>

6
tests/testTest.php Normal file
View File

@ -0,0 +1,6 @@
<?php
class DatabaseTableTest extends \PHPUnit\Framework\TestCase {
public function testFindColumnsValues() {
}
}
?>

21
todo
View File

@ -12,20 +12,21 @@ Assignment 2:
- Allow customers to filter by location @done - Allow customers to filter by location @done
- Move new framework into project @done - Move new framework into project @done
- Fix Adding categories @done - Fix Adding categories @done
- Archive jobs instead of delete - Archive jobs instead of delete @done
- Add admin user control to admin portal - Relist archived jobs with new closing date @done
- User accounts made in admin portal - Add admin user control to admin portal @done
- Client user accounts - User accounts made in admin portal @done
- Client user accounts @done
- restricted admin panel @done - restricted admin panel @done
- add and archive jobs - add and archive jobs @done
- see who has applied for jobs @done - see who has applied for jobs @done
- Client can only see their jobs @done - Client can only see their jobs @done
- Homepage has 10 jobs that are about to reach closing date @done - Homepage has 10 jobs that are about to reach closing date @done
- Contact form on contact page - Contact form on contact page @done
- forms store data in db - forms store data in db @done
- stored enquiries can be accessed from admin panel - stored enquiries can be accessed from admin panel @done
- can mark enquieries as Completed once admin has responded - can mark enquieries as Completed once admin has responded @done
- Keep list of all previous enquieries and which admin dealt with it - Keep list of all previous enquieries and which admin dealt with it @done
- Create entity classes for database entities (topic 18) @done - Create entity classes for database entities (topic 18) @done
- page 37-38 for implementation @done - page 37-38 for implementation @done
- Restrict categories by jobs available past current date @done - Restrict categories by jobs available past current date @done