2023-01-25 15:38:19 +00:00
|
|
|
<?php
|
|
|
|
|
namespace jobs\controllers;
|
|
|
|
|
class Portal {
|
|
|
|
|
private $catsTable;
|
|
|
|
|
private $jobsTable;
|
|
|
|
|
private $appsTable;
|
|
|
|
|
private $vars;
|
|
|
|
|
|
2023-01-25 17:44:11 +00:00
|
|
|
public function __construct(\jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $appsTable) {
|
2023-01-25 15:38:19 +00:00
|
|
|
$this->catsTable = $catsTable;
|
|
|
|
|
$this->jobsTable = $jobsTable;
|
|
|
|
|
$this->appsTable = $appsTable;
|
|
|
|
|
$this->vars['cats'] = $this->catsTable->findAll();
|
|
|
|
|
$this->vars['table'] = 'job_table.html.php';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function home() {
|
|
|
|
|
$this->vars['table'] = 'job_table.html.php';
|
2023-01-25 16:16:14 +00:00
|
|
|
if (isset($_GET['filter'])) {
|
|
|
|
|
if ($_SESSION['userType'] == 'client') {
|
2023-02-04 22:19:29 +00:00
|
|
|
$this->vars['jobs'] = $this->jobsTable->find(['clientId', 'categoryId'], ['value0' => $_SESSION['loggedin'],'value1' => $_GET['filter']]);
|
2023-01-25 16:16:14 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-02-04 22:19:29 +00:00
|
|
|
$this->vars['jobs'] = $this->jobsTable->find(["categoryId"], ['value0' => $_GET['filter']]);
|
2023-01-25 16:16:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-25 15:38:19 +00:00
|
|
|
else {
|
2023-01-25 16:16:14 +00:00
|
|
|
if ($_SESSION['userType'] == 'client') {
|
2023-02-04 22:19:29 +00:00
|
|
|
$this->vars['jobs'] = $this->jobsTable->find(['clientId'], ['value0' => $_SESSION['loggedin']]);
|
2023-01-25 16:16:14 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this->vars['jobs'] = $this->jobsTable->findAll();
|
|
|
|
|
}
|
2023-01-25 15:38:19 +00:00
|
|
|
}
|
|
|
|
|
return ['template' => 'portal.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Jobs',
|
|
|
|
|
'vars' => $this->vars];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function homeSubmit() {
|
2023-02-05 14:09:02 +00:00
|
|
|
if ($_POST['submit'] == "List") {
|
|
|
|
|
$this->vars['job'] = $this->jobsTable->find(['id'], ['value0' => $_POST['job_id']])[0];
|
|
|
|
|
return ['template' => 'job_edit.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Update Job',
|
|
|
|
|
'vars' => $this->vars];
|
2023-01-25 15:38:19 +00:00
|
|
|
}
|
2023-02-05 13:50:57 +00:00
|
|
|
else {
|
2023-02-05 13:13:12 +00:00
|
|
|
if (isset($_POST['job_id'])) {
|
2023-02-05 13:50:57 +00:00
|
|
|
$record = [
|
|
|
|
|
'id' => $_POST['job_id'],
|
|
|
|
|
'archived' => 'y'
|
|
|
|
|
];
|
|
|
|
|
$this->jobsTable->save($record);
|
2023-02-05 13:13:12 +00:00
|
|
|
return $this->home();
|
|
|
|
|
}
|
|
|
|
|
if (isset($_POST['cat_id'])) {
|
|
|
|
|
$this->catsTable->delete("id", $_POST['cat_id']);
|
|
|
|
|
return $this->categories();
|
|
|
|
|
}
|
2023-01-25 15:38:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-05 14:09:02 +00:00
|
|
|
public function secondHomeSubmit() {
|
|
|
|
|
if(isset($_POST['archived'])) {
|
|
|
|
|
$record = [
|
|
|
|
|
'id' => $_POST['jobId'],
|
|
|
|
|
'closingDate' => $_POST['closingDate'],
|
|
|
|
|
'archived' => $_POST['archived']
|
|
|
|
|
];
|
|
|
|
|
$this->jobsTable->save($record);
|
|
|
|
|
}
|
|
|
|
|
$this->vars['response'] = 'Update successful';
|
|
|
|
|
return ['template' => 'response.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Success',
|
|
|
|
|
'vars' => $this->vars
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 15:38:19 +00:00
|
|
|
public function categories() {
|
|
|
|
|
if ($_SESSION['userType'] == 'admin') {
|
|
|
|
|
$this->vars['table'] = 'category_table.html.php';
|
|
|
|
|
$this->vars['cats'] = $this->catsTable->findAll();
|
|
|
|
|
return ['template' => 'portal.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Categories',
|
|
|
|
|
'vars' => $this->vars];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function applicants() {
|
2023-02-05 12:11:41 +00:00
|
|
|
$job = $this->jobsTable->find(['id'], ['value0' => $_GET['job_id']])[0];
|
2023-01-25 15:38:19 +00:00
|
|
|
$this->vars['table'] = 'applicant_table.html.php';
|
2023-02-05 12:11:41 +00:00
|
|
|
$this->vars['apps'] = $job->getApps();
|
|
|
|
|
$this->vars['job'] = $job->title;
|
2023-01-25 15:38:19 +00:00
|
|
|
return ['template' => 'portal.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Applicants',
|
|
|
|
|
'vars' => $this->vars];
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 17:14:23 +00:00
|
|
|
public function edit() { //TODO: finish this function
|
2023-01-25 15:38:19 +00:00
|
|
|
if (isset($_GET['job_id'])) {
|
2023-02-05 14:09:02 +00:00
|
|
|
$this->vars['job'] = $this->jobsTable->find(["id"], ['value0' => $_GET['job_id']]);
|
2023-01-25 15:38:19 +00:00
|
|
|
}
|
|
|
|
|
if (isset($_GET['cat_id'])) {
|
2023-02-04 22:19:29 +00:00
|
|
|
$this->vars['cat'] = $this->catsTable->find(["id"], ['value0' => $_GET['cat_id']]);
|
2023-01-25 15:38:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-25 17:14:23 +00:00
|
|
|
|
2023-02-04 21:34:17 +00:00
|
|
|
public function addJob() {
|
2023-02-05 12:55:06 +00:00
|
|
|
return ['template' => 'job_add.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Add Job',
|
|
|
|
|
'vars' => $this->vars
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addJobSubmit() {
|
|
|
|
|
if (count($this->jobsTable->find(['title', 'clientId'], ['value0' => $_POST['title'], 'value1' => $_POST['client_id']])) == 0 && $this->catsTable->find(['name'], ['value0' => $_POST['categoryName']]) != 0) {
|
|
|
|
|
$record = [
|
|
|
|
|
'title' => $_POST['title'],
|
|
|
|
|
'description' => $_POST['description'],
|
|
|
|
|
'salary' => $_POST['salary'],
|
|
|
|
|
'closingDate' => $_POST['closingDate'],
|
|
|
|
|
'categoryId' => $this->catsTable->find(['name'], ['value0' => $_POST['categoryName']])[0]->id,
|
|
|
|
|
'location' => $_POST['location'],
|
|
|
|
|
'clientId' => $_POST['client_id']
|
|
|
|
|
];
|
|
|
|
|
$this->jobsTable->save($record);
|
|
|
|
|
$this->vars['response'] = 'Job made successfully';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this->vars['response'] = 'Some data was incorrect';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ['template' => 'response.html.php',
|
2023-02-05 12:30:28 +00:00
|
|
|
'title' => 'Jo\'s Jobs- Add Job',
|
|
|
|
|
'vars' => $this->vars
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addCategory() {
|
|
|
|
|
if ($_SESSION['userType'] == 'admin') {
|
|
|
|
|
return ['template' => 'category_add.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Add Category',
|
|
|
|
|
'vars' => $this->vars
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addCategorySubmit() {
|
|
|
|
|
if ($_SESSION['userType'] == 'admin') {
|
|
|
|
|
|
|
|
|
|
if (count($this->catsTable->find(['name'], ['value0' => $_POST['name']])) > 0) {
|
|
|
|
|
$this->vars['response'] = 'This category already exists';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$record = [
|
|
|
|
|
'name' => $_POST['name']
|
|
|
|
|
];
|
|
|
|
|
$this->catsTable->save($record);
|
|
|
|
|
$this->vars['response'] = 'Category Created';
|
|
|
|
|
}
|
|
|
|
|
return ['template' => 'response.html.php',
|
|
|
|
|
'title' => 'Jo\'s Jobs- Add Category',
|
|
|
|
|
'vars' => $this->vars
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-02-04 21:34:17 +00:00
|
|
|
}
|
2023-01-25 17:14:23 +00:00
|
|
|
}
|
|
|
|
|
?>
|