From c56907d9d35255829b5e85c7f79e578269df55b8 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 31 Mar 2021 19:21:00 +0300 Subject: Added initial script and config file for apache --- src/index.php | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/index.php (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..d87d760 --- /dev/null +++ b/src/index.php @@ -0,0 +1 @@ +

Hello

-- cgit v1.3.1-26-gb76a From 067e78d5d64adbf52c911f0f65cdaa7f8156e903 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 31 Mar 2021 20:41:37 +0300 Subject: Added database initialisation to DB model; added a script for watching file changes --- src/index.php | 7 ++++++- src/models/DB.php | 31 +++++++++++++++++++++++++++++++ watch-move-to-www.sh | 14 ++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/models/DB.php create mode 100755 watch-move-to-www.sh (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index d87d760..86562ab 100644 --- a/src/index.php +++ b/src/index.php @@ -1 +1,6 @@ -

Hello

+

Hello World!

+ diff --git a/src/models/DB.php b/src/models/DB.php new file mode 100644 index 0000000..f6db512 --- /dev/null +++ b/src/models/DB.php @@ -0,0 +1,31 @@ +connection = mysqli_connect(self::$servername, self::$username, self::$password); + + if (!$this->connection) { + die(mysqli_connect_error()); + } + + // Make sure the actual db exists + $createDBQuery = "CREATE DATABASE IF NOT EXISTS " . self::$dbname . ";"; + + if (!mysqli_query($this->connection, $createDBQuery)) { + die(mysqli_error($this->connection)); + } + + // Make the actual connection to the database + mysqli_select_db($this->connection, self::$dbname); + } + + function __destruct() { + mysqli_close($this->connection); + } +} diff --git a/watch-move-to-www.sh b/watch-move-to-www.sh new file mode 100755 index 0000000..a67bc44 --- /dev/null +++ b/watch-move-to-www.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +DEFAULT_DIR="/var/www/devrix-job-board/" + +if [ ! -d "$DEFAULT_DIR" ]; then + -u www-data mkdir $DEFAULT_DIR +fi + +inotifywait -m ./src/ -r -e attrib -e create -e move -e delete | + while read dir action file; do + echo "[`date +"%Y-%m-%d %T"`] Updated folder" + cp -R ./src/. $DEFAULT_DIR + chown -R www-data:www-data $DEFAULT_DIR* + done -- cgit v1.3.1-26-gb76a From 3298938d8f3bc7d6dafd8e67311e4ff0afc8d288 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 31 Mar 2021 22:01:00 +0300 Subject: Implemented DBModel for storing an instance of DB --- src/index.php | 4 ++-- src/models/DBModel.php | 12 ++++++++++++ src/models/JobOffer.php | 13 +++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 src/models/DBModel.php (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 86562ab..285f6e7 100644 --- a/src/index.php +++ b/src/index.php @@ -1,6 +1,6 @@

Hello World!

diff --git a/src/models/DBModel.php b/src/models/DBModel.php new file mode 100644 index 0000000..65bb725 --- /dev/null +++ b/src/models/DBModel.php @@ -0,0 +1,12 @@ +db = $db; + function __construct(string $title, string $description, string $company, float $salary) { + $this->title = $title; + $this->description = $description; + $this->company = $company; + $this->salary = $salary; } } -- cgit v1.3.1-26-gb76a From 588c444417c1aa68eccfe9cb96b6d10ebd4a0a84 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:15:17 +0300 Subject: Implemented a getall values from db method in JobOffer and show results in index --- src/index.php | 3 +++ src/models/JobOffer.php | 7 +++++++ 2 files changed, 10 insertions(+) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 285f6e7..6f290d6 100644 --- a/src/index.php +++ b/src/index.php @@ -3,4 +3,7 @@ include_once("models/JobOffer.php"); $jb = new JobOffer("a", "", "", 0); + foreach(JobOffer::getAll() as $key => $obj) { + echo $obj->salary . "
"; + } ?> diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 5cd6de4..736d644 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -18,4 +18,11 @@ class JobOffer extends DBModel { self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } + + /** + * @return JobOffer[] + */ + static function getAll() { + return self::$DB->getAllValues(self::TABLE_NAME); + } } -- cgit v1.3.1-26-gb76a From 7d845c9e752c92eabf5005f2bd310cf360991c1a Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:25:09 +0300 Subject: Added the id property in DBModel --- src/index.php | 2 +- src/models/DBModel.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 6f290d6..5fefff4 100644 --- a/src/index.php +++ b/src/index.php @@ -4,6 +4,6 @@ $jb = new JobOffer("a", "", "", 0); foreach(JobOffer::getAll() as $key => $obj) { - echo $obj->salary . "
"; + echo $obj->id . "
"; } ?> diff --git a/src/models/DBModel.php b/src/models/DBModel.php index 6980446..859ea97 100644 --- a/src/models/DBModel.php +++ b/src/models/DBModel.php @@ -2,6 +2,12 @@ include_once("DB.php"); abstract class DBModel { + /** + * Used ONLY for gotten values form the database. Mustn't be assigned to, since it's AUTO_INCREMENT. + * The id column is set by default in the DB class. + */ + public int $id; + protected static DB $DB; public static function __constructStatic() { -- cgit v1.3.1-26-gb76a From e9ba7fbcff47f0e4a03d74b857e9864d67a8b163 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:37:42 +0300 Subject: Implemented value insertion into DB --- src/index.php | 5 +++-- src/models/DB.php | 18 ++++++++++++++++++ src/models/JobOffer.php | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 5fefff4..ecebcd9 100644 --- a/src/index.php +++ b/src/index.php @@ -2,8 +2,9 @@ $obj) { - echo $obj->id . "
"; + echo "{$obj->id} {$obj->title}
"; } ?> diff --git a/src/models/DB.php b/src/models/DB.php index 77e08a5..299b05a 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -43,4 +43,22 @@ class DB { return $sth->fetchAll(PDO::FETCH_OBJ); } + + function insertValue(string $tableName, ...$values) { + $query = "INSERT INTO {$tableName} VALUES(NULL, "; + + foreach($values as $value) { + if (gettype($value) == "string") { + $query .= "'{$value}', "; + } + else { + $query .= "{$value}, "; + } + } + $query = rtrim($query, ", "); + + $query .= ");"; + + $this->connection->exec($query); + } } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 736d644..7603211 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -25,4 +25,8 @@ class JobOffer extends DBModel { static function getAll() { return self::$DB->getAllValues(self::TABLE_NAME); } + + static function insertInDB(JobOffer $jb) { + self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); + } } -- cgit v1.3.1-26-gb76a From f9e2090a1028712ecc6e1b0c71390c821689b414 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:43:48 +0300 Subject: Implemented getById from DB and changed some method names --- src/index.php | 8 ++++++-- src/models/DB.php | 7 +++++++ src/models/JobOffer.php | 11 +++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index ecebcd9..55bba39 100644 --- a/src/index.php +++ b/src/index.php @@ -3,8 +3,12 @@ include_once("models/JobOffer.php"); $jb = new JobOffer("Test", "A test", "TheTest", 11); - JobOffer::insertInDB($jb); - foreach(JobOffer::getAll() as $key => $obj) { + // JobOffer::insertInDB($jb); + foreach(JobOffer::getAllFromDB() as $key => $obj) { echo "{$obj->id} {$obj->title}
"; } + echo "
"; + + $gottenjb = JobOffer::getFromDBById(1); + echo $gottenjb->title; ?> diff --git a/src/models/DB.php b/src/models/DB.php index 299b05a..b973e4b 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -37,6 +37,13 @@ class DB { $this->connection->exec($query); } + function getById(string $tableName, int $id) { + $sth = $this->connection->prepare("SELECT * FROM `{$tableName}` WHERE id = {$id}"); + $sth->execute(); + + return $sth->fetch(PDO::FETCH_OBJ); + } + function getAllValues(string $tableName) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}`"); $sth->execute(); diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 7603211..3bb1791 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -19,14 +19,21 @@ class JobOffer extends DBModel { self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } + /** + * @return JobOffer + */ + static function getFromDBById(int $id) { + return self::$DB->getById(self::TABLE_NAME, $id); + } + /** * @return JobOffer[] */ - static function getAll() { + static function getAllFromDB() { return self::$DB->getAllValues(self::TABLE_NAME); } - static function insertInDB(JobOffer $jb) { + static function insertIntoDB(JobOffer $jb) { self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); } } -- cgit v1.3.1-26-gb76a From 30ee8530a646d3dcf32d563bbf42475035449bb5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 10:13:17 +0300 Subject: Implemented update from DB and updated some comments and phpdocumentator tags --- src/index.php | 6 ++++++ src/models/DB.php | 40 ++++++++++++++++++++++++++++++---------- src/models/JobOffer.php | 21 +++++++++++++++++++-- 3 files changed, 55 insertions(+), 12 deletions(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 55bba39..6478815 100644 --- a/src/index.php +++ b/src/index.php @@ -11,4 +11,10 @@ $gottenjb = JobOffer::getFromDBById(1); echo $gottenjb->title; + + $gottenjb->title = "Something even newer"; + echo $gottenjb->title; + JobOffer::updateFromDB($gottenjb); + $secgot = JobOffer::getFromDBById(1); + echo $secgot->title; ?> diff --git a/src/models/DB.php b/src/models/DB.php index b973e4b..4c75d17 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -24,6 +24,8 @@ class DB { $this->connection->exec("USE " . self::$dbname); } + /* Create */ + function createTable(string $tableName, array $columns) { $query = "CREATE TABLE IF NOT EXISTS {$tableName}( id INT NOT NULL AUTO_INCREMENT,"; @@ -37,6 +39,26 @@ class DB { $this->connection->exec($query); } + function insertValue(string $tableName, ...$values) { + $query = "INSERT INTO {$tableName} VALUES(NULL, "; + + foreach($values as $value) { + if (gettype($value) == "string") { + $query .= "'{$value}', "; + } + else { + $query .= "{$value}, "; + } + } + $query = rtrim($query, ", "); + + $query .= ");"; + + $this->connection->exec($query); + } + + /* Read */ + function getById(string $tableName, int $id) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}` WHERE id = {$id}"); $sth->execute(); @@ -51,20 +73,18 @@ class DB { return $sth->fetchAll(PDO::FETCH_OBJ); } - function insertValue(string $tableName, ...$values) { - $query = "INSERT INTO {$tableName} VALUES(NULL, "; + /* Update */ - foreach($values as $value) { - if (gettype($value) == "string") { - $query .= "'{$value}', "; - } - else { - $query .= "{$value}, "; - } + function updateById(string $tableName, int $id, ...$values) { + $query = "UPDATE {$tableName} SET "; + + for ($i = 0; $i < sizeof($values); $i += 2) { + $query .= "{$values[$i]} = " . (gettype($values[$i+1]) == "string" ? "'{$values[$i+1]}'" : $values[$i+1]) . ", "; } $query = rtrim($query, ", "); - $query .= ");"; + $query .= " WHERE id = {$id};"; + echo $query; $this->connection->exec($query); } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 3bb1791..2627207 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -19,6 +19,17 @@ class JobOffer extends DBModel { self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } + /* Create */ + + /** + * @param JobOffer $jb + */ + static function insertIntoDB($jb) { + self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); + } + + /* Read */ + /** * @return JobOffer */ @@ -33,7 +44,13 @@ class JobOffer extends DBModel { return self::$DB->getAllValues(self::TABLE_NAME); } - static function insertIntoDB(JobOffer $jb) { - self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); + /* Update */ + + /** + * @param JobOffer $jb + */ + static function updateFromDB($jb) { + echo "here"; + self::$DB->updateById(self::TABLE_NAME, $jb->id, "title", $jb->title, "description", $jb->description, "company", $jb->company, "salary", $jb->salary); } } -- cgit v1.3.1-26-gb76a From 852e91a3da52a478c942bf7a664df8d8798b0641 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 10:26:26 +0300 Subject: Implemented delete from DB and added error handling to queries --- src/index.php | 2 ++ src/models/DB.php | 42 ++++++++++++++++++++++++++++++++++++------ src/models/JobOffer.php | 7 ++++++- 3 files changed, 44 insertions(+), 7 deletions(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 6478815..7120cd3 100644 --- a/src/index.php +++ b/src/index.php @@ -17,4 +17,6 @@ JobOffer::updateFromDB($gottenjb); $secgot = JobOffer::getFromDBById(1); echo $secgot->title; + + JobOffer::deleteFromDB(3); ?> diff --git a/src/models/DB.php b/src/models/DB.php index 4c75d17..b287273 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -12,8 +12,13 @@ class DB { private PDO $connection; function __construct() { - $this->connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); - $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + try { + $this->connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); + $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } // Make sure the actual db exists $createDBQuery = "CREATE DATABASE IF NOT EXISTS " . self::$dbname . ";"; @@ -36,7 +41,12 @@ class DB { $query .= "PRIMARY KEY (id));"; - $this->connection->exec($query); + try { + $this->connection->exec($query); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } } function insertValue(string $tableName, ...$values) { @@ -54,7 +64,12 @@ class DB { $query .= ");"; - $this->connection->exec($query); + try { + $this->connection->exec($query); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } } /* Read */ @@ -84,8 +99,23 @@ class DB { $query = rtrim($query, ", "); $query .= " WHERE id = {$id};"; - echo $query; - $this->connection->exec($query); + try { + $this->connection->exec($query); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } + } + + /* Delete */ + + function deleteById(string $tableName, int $id) { + try { + $this->connection->exec("DELETE FROM {$tableName} WHERE id = {$id}"); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } } } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 2627207..5d89048 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -50,7 +50,12 @@ class JobOffer extends DBModel { * @param JobOffer $jb */ static function updateFromDB($jb) { - echo "here"; self::$DB->updateById(self::TABLE_NAME, $jb->id, "title", $jb->title, "description", $jb->description, "company", $jb->company, "salary", $jb->salary); } + + /* Delete */ + + static function deleteFromDB(int $id) { + self::$DB->deleteById(self::TABLE_NAME, $id); + } } -- cgit v1.3.1-26-gb76a From 83bb68e766bf12c5c48350bd6d9f8237e301882c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 11:22:04 +0300 Subject: Added and improved existing phpdocumentator documentation --- src/index.php | 11 ----------- src/models/DB.php | 39 ++++++++++++++++++++++++++++++++++++++- src/models/DBModel.php | 5 ++++- src/models/JobOffer.php | 15 +++++++++++++++ 4 files changed, 57 insertions(+), 13 deletions(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 7120cd3..fb5e85e 100644 --- a/src/index.php +++ b/src/index.php @@ -8,15 +8,4 @@ echo "{$obj->id} {$obj->title}
"; } echo "
"; - - $gottenjb = JobOffer::getFromDBById(1); - echo $gottenjb->title; - - $gottenjb->title = "Something even newer"; - echo $gottenjb->title; - JobOffer::updateFromDB($gottenjb); - $secgot = JobOffer::getFromDBById(1); - echo $secgot->title; - - JobOffer::deleteFromDB(3); ?> diff --git a/src/models/DB.php b/src/models/DB.php index b287273..dc69cfe 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -1,4 +1,7 @@ connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -25,12 +29,21 @@ class DB { $this->connection->exec($createDBQuery); - // Make the actual connection to the database + // Connect to the actual database $this->connection->exec("USE " . self::$dbname); } /* Create */ + /** + * Creates a table, with the given name and given column information. + * **WARNING**: The method also creates an auto-incremented int id column, **DO NOT** specify it! + * + * @param string[] $columns + * Represents the column information. Each value must be like: "column_name data_type", where the data_type should be taken + * from the constant values of DB class. + * Example value: array("first_name " . DB::STRING_TYPE, "age " . DB::INTEGER_TYPE, "income " . DB::FLOAT_TYPE) + */ function createTable(string $tableName, array $columns) { $query = "CREATE TABLE IF NOT EXISTS {$tableName}( id INT NOT NULL AUTO_INCREMENT,"; @@ -49,6 +62,14 @@ class DB { } } + /** + * Inserts a value in a given table. + * + * @param string[] $values + * Represents the data that should be inserted. The values should be ordered the same way the table columns are ordered. + * Example: "John", 20, 2000.3 + * **WARNING**: DO NOT insert the id value + */ function insertValue(string $tableName, ...$values) { $query = "INSERT INTO {$tableName} VALUES(NULL, "; @@ -74,6 +95,9 @@ class DB { /* Read */ + /** + * Returns the next value that has the given id. + */ function getById(string $tableName, int $id) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}` WHERE id = {$id}"); $sth->execute(); @@ -81,6 +105,9 @@ class DB { return $sth->fetch(PDO::FETCH_OBJ); } + /** + * Returns all values inside a table. + */ function getAllValues(string $tableName) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}`"); $sth->execute(); @@ -90,6 +117,13 @@ class DB { /* Update */ + /** + * Updates the value with the given id inside the specified table. + * + * @param string[] $values + * Represents the data that should be updated. There should always be an even amount of data, where you alternate the column name and column value. + * Example: "first_name", "John", "age", 20, "income", 2000.3 + */ function updateById(string $tableName, int $id, ...$values) { $query = "UPDATE {$tableName} SET "; @@ -110,6 +144,9 @@ class DB { /* Delete */ + /** + * Deletes the value with the given id inside the given table. + */ function deleteById(string $tableName, int $id) { try { $this->connection->exec("DELETE FROM {$tableName} WHERE id = {$id}"); diff --git a/src/models/DBModel.php b/src/models/DBModel.php index 859ea97..4e10c18 100644 --- a/src/models/DBModel.php +++ b/src/models/DBModel.php @@ -1,9 +1,12 @@ deleteById(self::TABLE_NAME, $id); } -- cgit v1.3.1-26-gb76a From 3a702b69f154a457c99fb00f4df38032d6b55400 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 12:48:53 +0300 Subject: Added a bottom and top part of a page that should be inserted in all views --- src/document-bot.php | 2 ++ src/document-top.php | 5 +++++ src/index.php | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 src/document-bot.php create mode 100644 src/document-top.php (limited to 'src/index.php') diff --git a/src/document-bot.php b/src/document-bot.php new file mode 100644 index 0000000..7fb2bd6 --- /dev/null +++ b/src/document-bot.php @@ -0,0 +1,2 @@ + + diff --git a/src/document-top.php b/src/document-top.php new file mode 100644 index 0000000..c6f9116 --- /dev/null +++ b/src/document-top.php @@ -0,0 +1,5 @@ + + + DevriX Job Board + + diff --git a/src/index.php b/src/index.php index fb5e85e..7313cbb 100644 --- a/src/index.php +++ b/src/index.php @@ -1,3 +1,5 @@ + +

Hello World!

"; ?> + + -- cgit v1.3.1-26-gb76a From 0aa067b783ec3ba374380b82612eb876634c78f8 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 13:27:08 +0300 Subject: Made index.php a router and added the basis of landing view and controller --- src/controllers/LandingController.php | 9 +++++++++ src/index.php | 28 +++++++++++++++++++--------- src/models/DB.php | 1 - src/views/landing.php | 7 +++++++ 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/controllers/LandingController.php create mode 100644 src/views/landing.php (limited to 'src/index.php') diff --git a/src/controllers/LandingController.php b/src/controllers/LandingController.php new file mode 100644 index 0000000..80e0b5b --- /dev/null +++ b/src/controllers/LandingController.php @@ -0,0 +1,9 @@ + -

Hello World!

$obj) { - echo "{$obj->id} {$obj->title}
"; - } - echo "
"; +include_once("controllers/LandingController.php"); + +/* The landing page practically acts as our page router + * Thanks https://www.taniarascia.com/the-simplest-php-router/ + */ + +$landingController = new LandingController(); + +$request = $_SERVER['REQUEST_URI']; + +switch ($request) { + case "": + case "/": + $landingController->invoke(); + break; + default: + http_response_code(404); + break; +} ?> diff --git a/src/models/DB.php b/src/models/DB.php index 9fd705c..8174831 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -71,7 +71,6 @@ class DB { $query = rtrim($query, ", "); $query .= ");"; - echo $query; try { $this->connection->exec($query); diff --git a/src/views/landing.php b/src/views/landing.php new file mode 100644 index 0000000..06e32a5 --- /dev/null +++ b/src/views/landing.php @@ -0,0 +1,7 @@ +

Landing page!

+ +id} {$job->title}
"; + } +?> -- cgit v1.3.1-26-gb76a From 380b0c6c7842d7016e2abbd15e61b835f62ca43b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 13:55:39 +0300 Subject: Implemented base controller --- src/controllers/BaseController.php | 27 +++++++++++++++++++++++++++ src/controllers/LandingController.php | 14 ++++++++++++-- src/index.php | 4 +--- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/controllers/BaseController.php (limited to 'src/index.php') diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php new file mode 100644 index 0000000..fd4bedd --- /dev/null +++ b/src/controllers/BaseController.php @@ -0,0 +1,27 @@ +invoke(); + LandingController::invoke(); break; default: http_response_code(404); -- cgit v1.3.1-26-gb76a From c026d4bb267d725d5cec82f102bb90a248334d2f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 14:49:27 +0300 Subject: Moved shell scripts and apache config to their own folder; Updated bash scripts to have checks for root and apps --- configs/devrix-job-board.conf | 15 +++++++++++++++ devrix-job-board.conf | 15 --------------- move-to-www.sh | 10 ---------- src/index.php | 3 ++- tools/move-to-www.sh | 16 ++++++++++++++++ tools/watch-move-to-www.sh | 24 ++++++++++++++++++++++++ watch-move-to-www.sh | 14 -------------- 7 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 configs/devrix-job-board.conf delete mode 100644 devrix-job-board.conf delete mode 100755 move-to-www.sh create mode 100755 tools/move-to-www.sh create mode 100755 tools/watch-move-to-www.sh delete mode 100755 watch-move-to-www.sh (limited to 'src/index.php') diff --git a/configs/devrix-job-board.conf b/configs/devrix-job-board.conf new file mode 100644 index 0000000..49356f2 --- /dev/null +++ b/configs/devrix-job-board.conf @@ -0,0 +1,15 @@ + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/devrix-job-board + ServerName djb.local + ServerAlias djb.local + + + RewriteEngine On + RewriteBase / + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.+)$ index.php [QSA,L] + + + diff --git a/devrix-job-board.conf b/devrix-job-board.conf deleted file mode 100644 index 49356f2..0000000 --- a/devrix-job-board.conf +++ /dev/null @@ -1,15 +0,0 @@ - - ServerAdmin webmaster@localhost - DocumentRoot /var/www/devrix-job-board - ServerName djb.local - ServerAlias djb.local - - - RewriteEngine On - RewriteBase / - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.+)$ index.php [QSA,L] - - - diff --git a/move-to-www.sh b/move-to-www.sh deleted file mode 100755 index c427606..0000000 --- a/move-to-www.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DEFAULT_DIR="/var/www/devrix-job-board/" - -if [ ! -d "$DEFAULT_DIR" ]; then - sudo -u www-data mkdir $DEFAULT_DIR -fi - -sudo cp -R ./src/. $DEFAULT_DIR -sudo chown -R www-data:www-data $DEFAULT_DIR* diff --git a/src/index.php b/src/index.php index 70da9a1..8dcef32 100644 --- a/src/index.php +++ b/src/index.php @@ -3,7 +3,8 @@ /dev/null; then + echo "You'll need to install inotify-tools!" +fi + +if [ "$EUID" -ne 0 ]; then + echo "Please run as root!" + exit +fi + +DEFAULT_DIR="/var/www/devrix-job-board/" + +if [ ! -d "$DEFAULT_DIR" ]; then + mkdir $DEFAULT_DIR + chown www-data:www-data $DEFAULT_DIR +fi + +inotifywait -m ../src/ -r -e attrib -e create -e move -e delete | + while read dir action file; do + echo "[`date +"%Y-%m-%d %T"`] Updated folder" + cp -R ../src/. $DEFAULT_DIR + chown -R www-data:www-data $DEFAULT_DIR* + done diff --git a/watch-move-to-www.sh b/watch-move-to-www.sh deleted file mode 100755 index a67bc44..0000000 --- a/watch-move-to-www.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -DEFAULT_DIR="/var/www/devrix-job-board/" - -if [ ! -d "$DEFAULT_DIR" ]; then - -u www-data mkdir $DEFAULT_DIR -fi - -inotifywait -m ./src/ -r -e attrib -e create -e move -e delete | - while read dir action file; do - echo "[`date +"%Y-%m-%d %T"`] Updated folder" - cp -R ./src/. $DEFAULT_DIR - chown -R www-data:www-data $DEFAULT_DIR* - done -- cgit v1.3.1-26-gb76a From f6b24f9842fbbc6add0bdf3732e5b9df5b6a4b5a Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 09:05:30 +0300 Subject: Added create (job) offer and view that have demo functionality (basic post request and echo values) --- src/controllers/CreateOfferController.php | 16 ++++++++++++++++ src/index.php | 5 +++++ src/views/create-offer.php | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/controllers/CreateOfferController.php create mode 100644 src/views/create-offer.php (limited to 'src/index.php') diff --git a/src/controllers/CreateOfferController.php b/src/controllers/CreateOfferController.php new file mode 100644 index 0000000..d510978 --- /dev/null +++ b/src/controllers/CreateOfferController.php @@ -0,0 +1,16 @@ +Works

+ +
+ + +
+ + +
+ + +
+ + +
+ +
-- cgit v1.3.1-26-gb76a From 68808a388a61c7a778494739fe0150651a09ea66 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 09:58:18 +0300 Subject: Implemented a simple login page for (admin) dashboard and skeleton of dashboard controller and view --- src/controllers/DashboardController.php | 8 ++++++++ src/controllers/DashboardLoginController.php | 24 ++++++++++++++++++++++++ src/index.php | 5 +++++ src/views/dashboard-login.php | 12 ++++++++++++ src/views/dashboard.php | 1 + 5 files changed, 50 insertions(+) create mode 100644 src/controllers/DashboardController.php create mode 100644 src/controllers/DashboardLoginController.php create mode 100644 src/views/dashboard-login.php create mode 100644 src/views/dashboard.php (limited to 'src/index.php') diff --git a/src/controllers/DashboardController.php b/src/controllers/DashboardController.php new file mode 100644 index 0000000..84beb14 --- /dev/null +++ b/src/controllers/DashboardController.php @@ -0,0 +1,8 @@ + + + +
+ + +
+ + + diff --git a/src/views/dashboard.php b/src/views/dashboard.php new file mode 100644 index 0000000..86c393a --- /dev/null +++ b/src/views/dashboard.php @@ -0,0 +1 @@ +

Dashboard works!

-- cgit v1.3.1-26-gb76a