comments
This commit is contained in:
parent
dd6c8d1cab
commit
5cbd031279
|
|
@ -20,14 +20,14 @@ class DatabaseTable {
|
|||
$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);
|
||||
$columns = \implode(', ', $keys);
|
||||
$values = \implode(', :', $keys);
|
||||
$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 = [];
|
||||
foreach ($record as $key => $value) {
|
||||
$params[] = $key . ' = :' .$key;
|
||||
|
|
@ -36,7 +36,7 @@ class DatabaseTable {
|
|||
$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 ';
|
||||
for ($i = 0; $i < count($values); $i++) {
|
||||
if ($i > 0) {
|
||||
|
|
@ -51,21 +51,21 @@ class DatabaseTable {
|
|||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function findAll() {
|
||||
public function findAll() { //Find all rows in table
|
||||
$stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table);
|
||||
$stmt->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor);
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function delete($column, $value) {
|
||||
public function delete($column, $value) { //Delete row from table
|
||||
$values = [
|
||||
'value' => $value
|
||||
];
|
||||
$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])) {
|
||||
unset($record[$this->pk]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ class EntryPoint {
|
|||
$this->routes = $routes;
|
||||
}
|
||||
|
||||
public function loadTemplate($fileName, $templateData) {
|
||||
public function loadTemplate($fileName, $templateData) { //Load HTML template
|
||||
\extract($templateData);
|
||||
\ob_start();
|
||||
require $fileName;
|
||||
return \ob_get_clean();
|
||||
}
|
||||
|
||||
public function run() {
|
||||
public function run() { //run response
|
||||
$route = \ltrim(\explode('?', $_SERVER['REQUEST_URI'])[0], '/');
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Routes {
|
|||
$this->loginControllers = [];
|
||||
}
|
||||
|
||||
public function getController($controllerName, $functionName) {
|
||||
public function getController($controllerName, $functionName) { //get controller
|
||||
|
||||
$this->checkLogin($controllerName);
|
||||
|
||||
|
|
@ -29,11 +29,11 @@ class Routes {
|
|||
|
||||
}
|
||||
|
||||
public function getDefaultRoute() {
|
||||
public function getDefaultRoute() { //Default request route
|
||||
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;
|
||||
|
||||
if ($requiresLogin && !isset($_SESSION['loggedin'])) {
|
||||
|
|
@ -42,7 +42,7 @@ class Routes {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
//404 Page
|
||||
public function notFound() {
|
||||
return ['template' => 'response.html.php',
|
||||
'title' => '404 Not Found',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace jobs\Entity;
|
||||
class Applicant {
|
||||
class Applicant { //Represents Applicant Entity from applicants table
|
||||
public $id;
|
||||
public $name;
|
||||
public $email;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace jobs\Entity;
|
||||
class Category {
|
||||
class Category { //Represents category Entity from categories table
|
||||
public $id;
|
||||
public $name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace jobs\Entity;
|
||||
class Enquiry {
|
||||
class Enquiry { //Represents enquiry Entity from enquiries table
|
||||
public $id;
|
||||
public $name;
|
||||
public $email;
|
||||
|
|
@ -14,7 +14,7 @@ class Enquiry {
|
|||
$this->usersTable = $usersTable;
|
||||
}
|
||||
|
||||
public function getAdmin() {
|
||||
public function getAdmin() { //Get the admin that completed the enquiry
|
||||
if ($this->completed == 'y') {
|
||||
return $this->usersTable->find(['id'], ['value0' => $this->admin_id])[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace jobs\Entity;
|
||||
class Job {
|
||||
class Job { //Represents Job Entity from jobs table
|
||||
public $id;
|
||||
public $title;
|
||||
public $description;
|
||||
|
|
@ -18,11 +18,11 @@ class Job {
|
|||
$this->appsTable = $appsTable;
|
||||
}
|
||||
|
||||
public function getCat() {
|
||||
public function getCat() { //Get category job is in
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace jobs\Entity;
|
||||
class User {
|
||||
class User { //Represents User Entity from userss table
|
||||
public $id;
|
||||
public $username;
|
||||
public $password;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
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 $username = 'student';
|
||||
protected $password = 'student';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace jobs;
|
||||
class Routes extends \CSY2028\Routes {
|
||||
class Routes extends \CSY2028\Routes { //Represents the routes for this site
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,22 +14,22 @@ class Jobs {
|
|||
$this->enquiryTable = $enquiryTable;
|
||||
$this->vars['cats'] = $this->catsTable->findAll();
|
||||
}
|
||||
|
||||
public function home() {
|
||||
//Homepage
|
||||
public function home() { //Route: jobs.v.je/jobs/home
|
||||
$this->vars['jobs'] = $this->jobsTable->find(["closingDate", 'archived'], ['value0' => date('y-m-d'), 'value1' => 'n'], ['>', '='], "DESC", "closingDate");
|
||||
return ['template' => 'home.html.php',
|
||||
'title' => 'Jo\'s Jobs- Home',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function category() {
|
||||
//Category pages
|
||||
public function category() { //Route: jobs.v.je/jobs/category
|
||||
$cat = $this->catsTable->find(['name'], ['value0' => $_GET['page']]);
|
||||
if ($cat == null) {
|
||||
return $this->notFound();
|
||||
}
|
||||
else {
|
||||
if (isset($_GET['filter'])) {
|
||||
if (isset($_GET['filter'])) { //location filter for jobs
|
||||
$columns = ['categoryId', "location", 'closingDate', 'archived'];
|
||||
$values = ['value0' => $cat[0]->id,
|
||||
'value1' => $_GET['filter'],
|
||||
|
|
@ -50,22 +50,22 @@ class Jobs {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function about() {
|
||||
//About page
|
||||
public function about() { //Route: jobs.v.je/jobs/about
|
||||
return ['template' => 'about.html.php',
|
||||
'title' => 'Jo\'s Jobs- About us',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function contact() {
|
||||
//Contact page
|
||||
public function contact() { //Route: jobs.v.je/jobs/contact
|
||||
return ['template' => 'contact.html.php',
|
||||
'title' => 'Jo\'s Jobs- Contact',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function contactSubmit() {
|
||||
//Contact page POST
|
||||
public function contactSubmit() { //Route: jobs.v.je/jobs/contact
|
||||
$record = [
|
||||
'name' => $_POST['name'],
|
||||
'email' => $_POST['email'],
|
||||
|
|
@ -78,24 +78,24 @@ class Jobs {
|
|||
'title' => 'Jo\'s Jobs- Enquiry Sent',
|
||||
'vars' => $this->vars];
|
||||
}
|
||||
|
||||
public function notFound() {
|
||||
//404 page
|
||||
public function notFound() { //Route: jobs.v.je/jobs/notFound
|
||||
$this->vars['response'] = 'The page you have requested has not been found';
|
||||
return ['template' => 'response.html.php',
|
||||
'title' => 'Jo\'s Jobs- 404 Not Found',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function apply() {
|
||||
//Job Application page
|
||||
public function apply() { //Route: jobs.v.je/jobs/apply
|
||||
$this->vars['job'] = $this->jobsTable->find(['id'], ["value0" => $_GET['id']])[0];
|
||||
return ['template' => 'apply.html.php',
|
||||
'title' => 'Jo\'s Jobs- Apply',
|
||||
'vars' => $this->vars];
|
||||
|
||||
}
|
||||
|
||||
public function applySubmit() {
|
||||
//Job Application page POST
|
||||
public function applySubmit() { //Route: jobs.v.je/jobs/apply
|
||||
if ($_FILES['cv']['error'] == 0) {
|
||||
$parts = explode('.', $_FILES['cv']['name']);
|
||||
$extension = end($parts);
|
||||
|
|
@ -125,8 +125,8 @@ class Jobs {
|
|||
'vars' => $this->vars];
|
||||
|
||||
}
|
||||
|
||||
public function faq() {
|
||||
//FAQ Page
|
||||
public function faq() { //Route: jobs.v.je/jobs/faq
|
||||
return ['template' => 'construction.html.php',
|
||||
'title' => 'Jo\'s Jobs- FAQ',
|
||||
'vars' => $this->vars];
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ class Portal {
|
|||
$this->vars['cats'] = $this->catsTable->findAll();
|
||||
$this->vars['table'] = 'job_table.html.php';
|
||||
}
|
||||
|
||||
public function home() {
|
||||
//Portal homepage
|
||||
public function home() { //Route: jobs.v.je/portal/
|
||||
$this->vars['table'] = 'job_table.html.php';
|
||||
if (isset($_GET['filter'])) {
|
||||
if ($_SESSION['userType'] == 'client') {
|
||||
|
|
@ -40,9 +40,9 @@ class Portal {
|
|||
'title' => 'Jo\'s Jobs- Jobs',
|
||||
'vars' => $this->vars];
|
||||
}
|
||||
|
||||
public function homeSubmit() {
|
||||
if ($_POST['submit'] == "List") {
|
||||
//Portal homepage POST
|
||||
public function homeSubmit() { //Route: jobs.v.je/portal/
|
||||
if ($_POST['submit'] == "List") { //Relist archived job
|
||||
$this->vars['job'] = $this->jobsTable->find(['id'], ['value0' => $_POST['job_id']])[0];
|
||||
$this->vars['archive'] = true;
|
||||
$this->vars['update'] = true;
|
||||
|
|
@ -51,7 +51,7 @@ class Portal {
|
|||
'vars' => $this->vars];
|
||||
}
|
||||
else {
|
||||
if (isset($_POST['job_id'])) {
|
||||
if (isset($_POST['job_id'])) { //archive job
|
||||
$record = [
|
||||
'id' => $_POST['job_id'],
|
||||
'archived' => 'y'
|
||||
|
|
@ -59,7 +59,7 @@ class Portal {
|
|||
$this->jobsTable->save($record);
|
||||
return $this->home();
|
||||
}
|
||||
if (isset($_POST['cat_id'])) {
|
||||
if (isset($_POST['cat_id'])) { //delete category
|
||||
$this->catsTable->delete("id", $_POST['cat_id']);
|
||||
$jobs = $this->jobsTable->find(['categoryId'], ['value0' => $_POST['cat_id']]);
|
||||
foreach ($jobs as $job) {
|
||||
|
|
@ -67,7 +67,7 @@ class Portal {
|
|||
}
|
||||
return $this->categories();
|
||||
}
|
||||
if (isset($_POST['user_id'])) {
|
||||
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']]);
|
||||
|
|
@ -79,8 +79,8 @@ class Portal {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function categories() {
|
||||
//Categories Portal page
|
||||
public function categories() { //Route: jobs.v.je/portal/categories
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
$this->vars['table'] = 'category_table.html.php';
|
||||
$this->vars['cats'] = $this->catsTable->findAll();
|
||||
|
|
@ -89,8 +89,8 @@ class Portal {
|
|||
'vars' => $this->vars];
|
||||
}
|
||||
}
|
||||
|
||||
public function applicants() {
|
||||
//Applicants Portal page
|
||||
public function applicants() { //Route: jobs.v.je/portal/applicants
|
||||
$job = $this->jobsTable->find(['id'], ['value0' => $_GET['job_id']])[0];
|
||||
$this->vars['table'] = 'applicant_table.html.php';
|
||||
$this->vars['apps'] = $job->getApps();
|
||||
|
|
@ -99,8 +99,8 @@ class Portal {
|
|||
'title' => 'Jo\'s Jobs- Applicants',
|
||||
'vars' => $this->vars];
|
||||
}
|
||||
|
||||
public function users() {
|
||||
//Users Portal page
|
||||
public function users() { //Route: jobs.v.je/portal/users
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
$this->vars['table'] = 'user_table.html.php';
|
||||
$this->vars['users'] = $this->usersTable->findAll();
|
||||
|
|
@ -110,8 +110,8 @@ class Portal {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function enquiries() {
|
||||
//Enquiries Portal page
|
||||
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();
|
||||
|
|
@ -121,8 +121,8 @@ class Portal {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function enquiriesSubmit() {
|
||||
//Enquiries Portal page POST
|
||||
public function enquiriesSubmit() { //Route: jobs.v.je/portal/enquiries
|
||||
$record = [
|
||||
'id' => $_POST['enq_id'],
|
||||
'completed' => 'y',
|
||||
|
|
@ -131,14 +131,14 @@ class Portal {
|
|||
$this->enquiryTable->save($record);
|
||||
$this->enquiries();
|
||||
}
|
||||
|
||||
public function addUser() {
|
||||
//Edit User Portal page
|
||||
public function addUser() { //Route: jobs.v.je/portal/addUser
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
if (isset($_GET['user_id'])) {
|
||||
if (isset($_GET['user_id'])) { //Update user
|
||||
$this->vars['user'] = $this->usersTable->find(['id'], ['value0' => $_GET['user_id']])[0];
|
||||
$this->vars['update'] = true;
|
||||
}
|
||||
else {
|
||||
else { //Create user
|
||||
$this->vars['update'] = false;
|
||||
}
|
||||
return ['template' => 'user_add.html.php',
|
||||
|
|
@ -147,7 +147,7 @@ class Portal {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
//Edit User Portal page POST
|
||||
public function addUserSubmit() {
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
if($_POST['password'] != "") {
|
||||
|
|
@ -172,14 +172,14 @@ class Portal {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function addJob() {
|
||||
if (isset($_GET['job_id'])) {
|
||||
//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 {
|
||||
else { //Create Job
|
||||
$this->vars['archive'] = false;
|
||||
$this->vars['update'] = false;
|
||||
}
|
||||
|
|
@ -188,8 +188,8 @@ class Portal {
|
|||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function addJobSubmit() {
|
||||
//Edit Job page POST
|
||||
public function addJobSubmit() { //Route: jobs.v.je/portal/addJob
|
||||
if ($this->catsTable->find(['name'], ['value0' => $_POST['categoryName']]) != 0) {
|
||||
$record = [
|
||||
'title' => $_POST['title'],
|
||||
|
|
@ -221,8 +221,8 @@ class Portal {
|
|||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function addCategory() {
|
||||
//Edit Category page
|
||||
public function addCategory() { //Route: jobs.v.je/portal/addCategory
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
if (isset($_GET['cat_id'])) {
|
||||
$this->vars['cat'] = $this->catsTable->find(["id"], ['value0' => $_GET['cat_id']])[0];
|
||||
|
|
@ -237,8 +237,8 @@ class Portal {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function addCategorySubmit() {
|
||||
//Edit Category page POST
|
||||
public function addCategorySubmit() { //Route: jobs.v.je/portal/addCategory
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
if ($_POST['submit'] == 'Create') {
|
||||
if (count($this->catsTable->find(['name'], ['value0' => $_POST['name']])) > 0) {
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ class User {
|
|||
$this->vars['cats'] = $this->catsTable->findAll();
|
||||
$this->vars['response'] = '';
|
||||
}
|
||||
|
||||
public function login() {
|
||||
//Login page
|
||||
public function login() { //Route: jobs.v.je/user/login
|
||||
return ['template' => 'login.html.php',
|
||||
'title' => 'Jo\'s Jobs- Login',
|
||||
'vars' => $this->vars];
|
||||
}
|
||||
|
||||
public function loginSubmit() {
|
||||
//Login page POST
|
||||
public function loginSubmit() { //Route: jobs.v.je/user/login
|
||||
if ($_POST['username'] != '' && $_POST['password'] != '') {
|
||||
$user = $this->usersTable->find(["username"], ['value0' => $_POST['username']]);
|
||||
if (password_verify($_POST['password'], $user[0]->password)) {
|
||||
|
|
@ -49,8 +49,8 @@ class User {
|
|||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
//Logout page
|
||||
public function logout() { //Route: jobs.v.je/user/logout
|
||||
unset($_SESSION['loggedin']);
|
||||
unset($_SESSION['userType']);
|
||||
$this->vars['response'] = 'Logged Out Successfully';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
session_start();
|
||||
require '../autoload.php';
|
||||
$routes = new \jobs\Routes();
|
||||
$entryPoint = new \CSY2028\EntryPoint($routes);
|
||||
$entryPoint->run();
|
||||
session_start(); //make sure session is started
|
||||
require '../autoload.php'; //include autoload
|
||||
$routes = new \jobs\Routes(); //get routes
|
||||
$entryPoint = new \CSY2028\EntryPoint($routes); //get entrypoint
|
||||
$entryPoint->run(); //start entrypoint
|
||||
?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue