aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/BusinessAdmin.class.php478
-rw-r--r--classes/assignment.class.php534
-rw-r--r--classes/client.class.php310
-rw-r--r--classes/contact.class.php648
-rw-r--r--classes/correspondence.class.php460
-rw-r--r--classes/file.class.php216
-rw-r--r--classes/offer.class.php131
-rw-r--r--classes/response.class.php154
-rw-r--r--index.php2
9 files changed, 1466 insertions, 1467 deletions
diff --git a/classes/BusinessAdmin.class.php b/classes/BusinessAdmin.class.php
index 900034f..ce5525b 100644
--- a/classes/BusinessAdmin.class.php
+++ b/classes/BusinessAdmin.class.php
@@ -25,258 +25,258 @@
* Provides basic functions like adding elements to the database
*/
class BusinessAdmin {
- //------------------------------------------------------------------------------
- // Getters and setters
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Getters and setters
+ //------------------------------------------------------------------------------
- /**
- * Get all client ids
- *
- * @see BusinessAdmin::getClients() This funtion returns instances of the client class instead of just the ids
- *
- * @param PDO $pdo The PDO class for database connection
- *
- * @throws PDOException Is something went wrong with the database
- *
- * @return int[] The ids
- */
- public static function getClientIds($pdo) {
- $ids = array();
- $clients = $pdo->query("SELECT `id` FROM `".constants::db_prefix."client`")->fetchAll(PDO::FETCH_ASSOC);
- foreach ($clients as $client) {
- $ids[] = $client['id'];
- }
- return $ids;
- }
+ /**
+ * Get all client ids
+ *
+ * @see BusinessAdmin::getClients() This funtion returns instances of the client class instead of just the ids
+ *
+ * @param PDO $pdo The PDO class for database connection
+ *
+ * @throws PDOException Is something went wrong with the database
+ *
+ * @return int[] The ids
+ */
+ public static function getClientIds($pdo) {
+ $ids = array();
+ $clients = $pdo->query("SELECT `id` FROM `".constants::db_prefix."client`")->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($clients as $client) {
+ $ids[] = $client['id'];
+ }
+ return $ids;
+ }
- /**
- * Get all clients
- *
- * @see BusinessAdmin::getClientIds() This function returns just the ids of the clients, and not instances of the client class
- *
- * @param PDO $pdo The PDO class for database connection
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return client[] An array indexed by id of instances of the client class
- */
- public static function getClients($pdo) {
- $ids = self::getClientIds($pdo);
- $clients = array();
- foreach ($ids as $id) {
- $clients[$id] = new client($pdo, $id);
- }
- return $clients;
- }
+ /**
+ * Get all clients
+ *
+ * @see BusinessAdmin::getClientIds() This function returns just the ids of the clients, and not instances of the client class
+ *
+ * @param PDO $pdo The PDO class for database connection
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return client[] An array indexed by id of instances of the client class
+ */
+ public static function getClients($pdo) {
+ $ids = self::getClientIds($pdo);
+ $clients = array();
+ foreach ($ids as $id) {
+ $clients[$id] = new client($pdo, $id);
+ }
+ return $clients;
+ }
- /**
- * Get all contact ids
- *
- * @see BusinessAdmin::getContacts() This funtion returns instances of the contact class instead of just the ids
- *
- * @param PDO $pdo The PDO class for database connection
- *
- * @throws PDOException Is something went wrong with the database
- *
- * @return int[] The ids
- */
- public static function getContactIds($pdo) {
- $ids = array();
- $contacts = $pdo->query("SELECT `id` FROM `".constants::db_prefix."contact`")->fetchAll(PDO::FETCH_ASSOC);
- foreach ($contacts as $contact) {
- $ids[] = $contact['id'];
- }
- return $ids;
- }
+ /**
+ * Get all contact ids
+ *
+ * @see BusinessAdmin::getContacts() This funtion returns instances of the contact class instead of just the ids
+ *
+ * @param PDO $pdo The PDO class for database connection
+ *
+ * @throws PDOException Is something went wrong with the database
+ *
+ * @return int[] The ids
+ */
+ public static function getContactIds($pdo) {
+ $ids = array();
+ $contacts = $pdo->query("SELECT `id` FROM `".constants::db_prefix."contact`")->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($contacts as $contact) {
+ $ids[] = $contact['id'];
+ }
+ return $ids;
+ }
- /**
- * Get all contacts
- *
- * @see BusinessAdmin::getContactIds() This function returns just the ids of the contacts, and not instances of the contact class
- *
- * @param PDO $pdo The PDO class for database connection
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return contact[] An array indexed by id of instances of the contact class
- */
- public static function getContacts($pdo) {
- $ids = self::getContactIds($pdo);
- $contacts = array();
- foreach ($ids as $id) {
- $contacts[$id] = new contact($pdo, $id);
- }
- return $contacts;
- }
+ /**
+ * Get all contacts
+ *
+ * @see BusinessAdmin::getContactIds() This function returns just the ids of the contacts, and not instances of the contact class
+ *
+ * @param PDO $pdo The PDO class for database connection
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return contact[] An array indexed by id of instances of the contact class
+ */
+ public static function getContacts($pdo) {
+ $ids = self::getContactIds($pdo);
+ $contacts = array();
+ foreach ($ids as $id) {
+ $contacts[$id] = new contact($pdo, $id);
+ }
+ return $contacts;
+ }
- /**
- * Get all offer ids
- *
- * @see BusinessAdmin::getOffers() This funtion returns instances of the offer class instead of just the ids
- *
- * @param PDO $pdo The PDO class for database connection
- * @param string[] $where An array of WHERE clauses that will be AND-ed
- *
- * @throws PDOException Is something went wrong with the database
- *
- * @return int[] The ids
- */
- public static function getOfferIds($pdo, $where = array()) {
- $ids = array();
- $offers = $pdo->query("SELECT `id` FROM `".constants::db_prefix."offer`" . ((count($where) > 0) ? (" WHERE (" . implode(') AND (', $where) . ")") : ""))->fetchAll(PDO::FETCH_ASSOC);
- foreach ($offers as $offer) {
- $ids[] = $offer['id'];
- }
- return $ids;
- }
+ /**
+ * Get all offer ids
+ *
+ * @see BusinessAdmin::getOffers() This funtion returns instances of the offer class instead of just the ids
+ *
+ * @param PDO $pdo The PDO class for database connection
+ * @param string[] $where An array of WHERE clauses that will be AND-ed
+ *
+ * @throws PDOException Is something went wrong with the database
+ *
+ * @return int[] The ids
+ */
+ public static function getOfferIds($pdo, $where = array()) {
+ $ids = array();
+ $offers = $pdo->query("SELECT `id` FROM `".constants::db_prefix."offer`" . ((count($where) > 0) ? (" WHERE (" . implode(') AND (', $where) . ")") : ""))->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($offers as $offer) {
+ $ids[] = $offer['id'];
+ }
+ return $ids;
+ }
- /**
- * Get all offers
- *
- * @see BusinessAdmin::getOfferIds() This function returns just the ids of the offers, and not instances of the offer class
- *
- * @param PDO $pdo The PDO class for database connection
- * @param string[] $where An array of WHERE clauses that will be AND-ed
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return offer[] An array indexed by id of instances of the offer class
- */
- public static function getOffers($pdo, $where = array()) {
- $ids = self::getOfferIds($pdo, $where);
- $offers = array();
- foreach ($ids as $id) {
- $offers[$id] = new offer($pdo, $id);
- }
- return $offers;
- }
+ /**
+ * Get all offers
+ *
+ * @see BusinessAdmin::getOfferIds() This function returns just the ids of the offers, and not instances of the offer class
+ *
+ * @param PDO $pdo The PDO class for database connection
+ * @param string[] $where An array of WHERE clauses that will be AND-ed
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return offer[] An array indexed by id of instances of the offer class
+ */
+ public static function getOffers($pdo, $where = array()) {
+ $ids = self::getOfferIds($pdo, $where);
+ $offers = array();
+ foreach ($ids as $id) {
+ $offers[$id] = new offer($pdo, $id);
+ }
+ return $offers;
+ }
- /**
- * Get all assignment ids
- *
- * @see BusinessAdmin::getAssignments() This funtion returns instances of the assignment class instead of just the ids
- *
- * @param PDO $pdo The PDO class for database connection
- *
- * @throws PDOException Is something went wrong with the database
- *
- * @return int[] The ids
- */
- public static function getAssignmentIds($pdo) {
- $ids = array();
- $assignments = $pdo->query("SELECT `id` FROM `".constants::db_prefix."assignment`")->fetchAll(PDO::FETCH_ASSOC);
- foreach ($assignments as $assignment) {
- $ids[] = $assignment['id'];
- }
- return $ids;
- }
+ /**
+ * Get all assignment ids
+ *
+ * @see BusinessAdmin::getAssignments() This funtion returns instances of the assignment class instead of just the ids
+ *
+ * @param PDO $pdo The PDO class for database connection
+ *
+ * @throws PDOException Is something went wrong with the database
+ *
+ * @return int[] The ids
+ */
+ public static function getAssignmentIds($pdo) {
+ $ids = array();
+ $assignments = $pdo->query("SELECT `id` FROM `".constants::db_prefix."assignment`")->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($assignments as $assignment) {
+ $ids[] = $assignment['id'];
+ }
+ return $ids;
+ }
- /**
- * Get all assignments
- *
- * @see BusinessAdmin::getAssignmentIds() This function returns just the ids of the assignments, and not instances of the assignment class
- *
- * @param PDO $pdo The PDO class for database connection
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return assignment[] An array indexed by id of instances of the assignment class
- */
- public static function getAssignments($pdo) {
- $ids = self::getAssignmentIds($pdo);
- $assignments = array();
- foreach ($ids as $id) {
- $assignments[$id] = new assignment($pdo, $id);
- }
- return $assignments;
- }
+ /**
+ * Get all assignments
+ *
+ * @see BusinessAdmin::getAssignmentIds() This function returns just the ids of the assignments, and not instances of the assignment class
+ *
+ * @param PDO $pdo The PDO class for database connection
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return assignment[] An array indexed by id of instances of the assignment class
+ */
+ public static function getAssignments($pdo) {
+ $ids = self::getAssignmentIds($pdo);
+ $assignments = array();
+ foreach ($ids as $id) {
+ $assignments[$id] = new assignment($pdo, $id);
+ }
+ return $assignments;
+ }
- //------------------------------------------------------------------------------
- // Other functions
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Other functions
+ //------------------------------------------------------------------------------
- /**
- * Create a new client
- *
- * @param PDO $pdo The database connection
- * @param string $name The name for the new client
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return client|bool A new instance of the client object, or false on failure
- */
- public static function createClient($pdo, $name) {
- $stmt = $pdo->prepare("INSERT INTO `".constants::db_prefix."client` (`name`) VALUES (?)");
- $stmt->execute(array($name));
- if ($stmt->rowCount() == 1) {
- return new client($pdo, $pdo->lastInsertId());
- } else {
- return false;
- }
- }
+ /**
+ * Create a new client
+ *
+ * @param PDO $pdo The database connection
+ * @param string $name The name for the new client
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return client|bool A new instance of the client object, or false on failure
+ */
+ public static function createClient($pdo, $name) {
+ $stmt = $pdo->prepare("INSERT INTO `".constants::db_prefix."client` (`name`) VALUES (?)");
+ $stmt->execute(array($name));
+ if ($stmt->rowCount() == 1) {
+ return new client($pdo, $pdo->lastInsertId());
+ } else {
+ return false;
+ }
+ }
- /**
- * Create a new file
- *
- * @param PDO $pdo The database connection
- * @param string $filename The desired filename
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the file could not be created (due to permissions, file existed already, etc.), or the database record couldn't be added
- *
- * @return file A new instance of the file object
- */
- public static function createFile($pdo, $filename) {
- // Check for file existence
- if (file_exists(constants::files_folder . $filename)) {
- throw new Exception("$filename already exists.");
- }
+ /**
+ * Create a new file
+ *
+ * @param PDO $pdo The database connection
+ * @param string $filename The desired filename
+ *
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If the file could not be created (due to permissions, file existed already, etc.), or the database record couldn't be added
+ *
+ * @return file A new instance of the file object
+ */
+ public static function createFile($pdo, $filename) {
+ // Check for file existence
+ if (file_exists(constants::files_folder . $filename)) {
+ throw new Exception("$filename already exists.");
+ }
- // Try to create the file
- if (file_put_contents(constants::files_folder . $filename, '') === false) {
- throw new Exception("$filename could not be created. Check the permissions.");
- }
+ // Try to create the file
+ if (file_put_contents(constants::files_folder . $filename, '') === false) {
+ throw new Exception("$filename could not be created. Check the permissions.");
+ }
- $stmt = $pdo->prepare("INSERT INTO `".constants::db_prefix."file` (`filename`) VALUES (?)");
- $stmt->execute(array($filename));
- if ($stmt->rowCount() == 1) {
- return new file($pdo, $pdo->lastInsertId());
- } else {
- unlink(constants::files_folder . $filename);
- throw new Exception("$filename could not be added to the database");
- }
- }
+ $stmt = $pdo->prepare("INSERT INTO `".constants::db_prefix."file` (`filename`) VALUES (?)");
+ $stmt->execute(array($filename));
+ if ($stmt->rowCount() == 1) {
+ return new file($pdo, $pdo->lastInsertId());
+ } else {
+ unlink(constants::files_folder . $filename);
+ throw new Exception("$filename could not be added to the database");
+ }
+ }
- /**
- * Format a date nicely
- *
- * @todo implement $relatively = true
- *
- * @param int $timestamp The UNIX timestamp to format
- * @param bool $with_time If false, only the date is returned; if false, also the time
- * @param bool $full_date If true, a year will be outputted even if the date is in the current year
- * @param bool $relatively Whether or not to show the date relatively (e.g. '1 day ago') (NOT IMPLEMENTED YET)
- *
- * @return string The formatted date
- */
- public static function formatDate($timestamp, $with_time = true, $full_date = false, $relatively = false) {
- $output = '';
- if (date('Y', $timestamp) == 1970) {
- return 'never';
- }
- if (date('d/m/Y') == date('d/m/Y', $timestamp)) {
- return 'today';
- }
- if (date('Y') != date('Y', $timestamp) || $full_date) {
- $output .= date('Y-', $timestamp);
- }
- if (date('d/m/Y') != date('d/m/Y', $timestamp) || $full_date) {
- $output .= date('m-d', $timestamp);
- }
- if ($with_time) {
- $output .= date(' H:i', $timestamp);
- }
+ /**
+ * Format a date nicely
+ *
+ * @todo implement $relatively = true
+ *
+ * @param int $timestamp The UNIX timestamp to format
+ * @param bool $with_time If false, only the date is returned; if false, also the time
+ * @param bool $full_date If true, a year will be outputted even if the date is in the current year
+ * @param bool $relatively Whether or not to show the date relatively (e.g. '1 day ago') (NOT IMPLEMENTED YET)
+ *
+ * @return string The formatted date
+ */
+ public static function formatDate($timestamp, $with_time = true, $full_date = false, $relatively = false) {
+ $output = '';
+ if (date('Y', $timestamp) == 1970) {
+ return 'never';
+ }
+ if (date('d/m/Y') == date('d/m/Y', $timestamp)) {
+ return 'today';
+ }
+ if (date('Y') != date('Y', $timestamp) || $full_date) {
+ $output .= date('Y-', $timestamp);
+ }
+ if (date('d/m/Y') != date('d/m/Y', $timestamp) || $full_date) {
+ $output .= date('m-d', $timestamp);
+ }
+ if ($with_time) {
+ $output .= date(' H:i', $timestamp);
+ }
- return $output;
- }
+ return $output;
+ }
} \ No newline at end of file
diff --git a/classes/assignment.class.php b/classes/assignment.class.php
index e13bd6d..9b7de09 100644
--- a/classes/assignment.class.php
+++ b/classes/assignment.class.php
@@ -25,292 +25,292 @@
* An interface to the assignment table in the database
*/
class assignment {
- /**
- * @var pdo $pdo The PDO class for database communication
- * @var int $id The id of the assignment
- * @var int $offerId The id of the offer this assignment is linked to
- * @var string $title The title of the assignment
- * @var string $description The description of the assignment
- * @var int $hours The amount of hours of the assignment
- * @var float $price_per_hour The price per hour for this assignment, in your valuta
- * @var float $vat The percentage of VAT to calculate on this assignment
- */
- protected $pdo, $offerId, $id, $title, $description, $hours, $price_per_hour, $vat;
+ /**
+ * @var pdo $pdo The PDO class for database communication
+ * @var int $id The id of the assignment
+ * @var int $offerId The id of the offer this assignment is linked to
+ * @var string $title The title of the assignment
+ * @var string $description The description of the assignment
+ * @var int $hours The amount of hours of the assignment
+ * @var float $price_per_hour The price per hour for this assignment, in your valuta
+ * @var float $vat The percentage of VAT to calculate on this assignment
+ */
+ protected $pdo, $offerId, $id, $title, $description, $hours, $price_per_hour, $vat;
- const SUBTOTAL = 1;
- const VAT = 2;
- const TOTAL = 3;
+ const SUBTOTAL = 1;
+ const VAT = 2;
+ const TOTAL = 3;
- /**
- * Create a new instance
- *
- * @param PDO $pdo The PDO class, to access the database
- * @param int $id The id of the assignment to fetch
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the assignment could not be found
- */
- public function __construct($pdo, $id) {
- $this->pdo = $pdo;
+ /**
+ * Create a new instance
+ *
+ * @param PDO $pdo The PDO class, to access the database
+ * @param int $id The id of the assignment to fetch
+ *
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If the assignment could not be found
+ */
+ public function __construct($pdo, $id) {
+ $this->pdo = $pdo;
- $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."assignment` WHERE `id`=?");
- $stmt->execute(array($id));
- if ($stmt->rowCount() == 0) {
- throw new Exception("The assignment with id '$id' could not be found.");
- }
- $assignment = $stmt->fetch(PDO::FETCH_ASSOC);
+ $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."assignment` WHERE `id`=?");
+ $stmt->execute(array($id));
+ if ($stmt->rowCount() == 0) {
+ throw new Exception("The assignment with id '$id' could not be found.");
+ }
+ $assignment = $stmt->fetch(PDO::FETCH_ASSOC);
- $this->id = $assignment['id'];
- $this->offerId = $assignment['offerId'];
- $this->title = $assignment['title'];
- $this->description = $assignment['description'];
- $this->hours = $assignment['hours'];
- $this->price_per_hour = $assignment['price_per_hour'];
- $this->vat = $assignment['VAT_percentage'];
- }
+ $this->id = $assignment['id'];
+ $this->offerId = $assignment['offerId'];
+ $this->title = $assignment['title'];
+ $this->description = $assignment['description'];
+ $this->hours = $assignment['hours'];
+ $this->price_per_hour = $assignment['price_per_hour'];
+ $this->vat = $assignment['VAT_percentage'];
+ }
- //------------------------------------------------------------------------------
- // Getters and setters
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Getters and setters
+ //------------------------------------------------------------------------------
- /**
- * Get the ID of the assignment
- *
- * @return int The ID
- */
- public function getId() {
- return $this->id;
- }
+ /**
+ * Get the ID of the assignment
+ *
+ * @return int The ID
+ */
+ public function getId() {
+ return $this->id;
+ }
- /**
- * Get the ID of the offer that this assignment is linked to
- *
- * @return int The ID
- */
- public function getOfferId() {
- return $this->offerId;
- }
+ /**
+ * Get the ID of the offer that this assignment is linked to
+ *
+ * @return int The ID
+ */
+ public function getOfferId() {
+ return $this->offerId;
+ }
- /**
- * Get the offer that this assignment is linked to
- *
- * @return offer The offer
- */
- public function getOffer() {
- return new offer($this->pdo, $this->offerId);
- }
+ /**
+ * Get the offer that this assignment is linked to
+ *
+ * @return offer The offer
+ */
+ public function getOffer() {
+ return new offer($this->pdo, $this->offerId);
+ }
- /**
- * Get the title of the assignment
- *
- * @return string The title
- */
- public function getTitle() {
- return $this->title;
- }
+ /**
+ * Get the title of the assignment
+ *
+ * @return string The title
+ */
+ public function getTitle() {
+ return $this->title;
+ }
- /**
- * Set the title of the assignment
- *
- * @param string $title The new title for the assignment
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setTitle($title) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `title`=? WHERE `id`=?");
- $stmt->execute(array($title, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->title = $title;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the title of the assignment
+ *
+ * @param string $title The new title for the assignment
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setTitle($title) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `title`=? WHERE `id`=?");
+ $stmt->execute(array($title, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->title = $title;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the description of the assignment
- *
- * @param bool $parseMarkdown Whether or not to parse markdown
- *
- * @return string The description
- */
- public function getDescription($parseMarkdown = true) {
- if ($parseMarkdown) {
- $pd = new Parsedown;
- return $pd->text($this->description);
- } else {
- return $this->description;
- }
- }
+ /**
+ * Get the description of the assignment
+ *
+ * @param bool $parseMarkdown Whether or not to parse markdown
+ *
+ * @return string The description
+ */
+ public function getDescription($parseMarkdown = true) {
+ if ($parseMarkdown) {
+ $pd = new Parsedown;
+ return $pd->text($this->description);
+ } else {
+ return $this->description;
+ }
+ }
- /**
- * Set the description of the assignment
- *
- * @param string $description The new description for the assignment
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setDescription($description) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `description`=? WHERE `id`=?");
- $stmt->execute(array($description, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->description = $description;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the description of the assignment
+ *
+ * @param string $description The new description for the assignment
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setDescription($description) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `description`=? WHERE `id`=?");
+ $stmt->execute(array($description, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->description = $description;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the amount of hours of the assignment
- *
- * @return int The amount of hours
- */
- public function getHours() {
- return $this->hours;
- }
+ /**
+ * Get the amount of hours of the assignment
+ *
+ * @return int The amount of hours
+ */
+ public function getHours() {
+ return $this->hours;
+ }
- /**
- * Set the amount of hours of the assignment
- *
- * @param int $hours The new amount hours for the assignment
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setHours($hours) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `hours`=? WHERE `id`=?");
- $stmt->execute(array($hours, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->hours = $hours;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the amount of hours of the assignment
+ *
+ * @param int $hours The new amount hours for the assignment
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setHours($hours) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `hours`=? WHERE `id`=?");
+ $stmt->execute(array($hours, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->hours = $hours;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the price per hour of the assignment
- *
- * @return float The price per hour
- */
- public function getPricePerHour() {
- return $this->price_per_hour;
- }
+ /**
+ * Get the price per hour of the assignment
+ *
+ * @return float The price per hour
+ */
+ public function getPricePerHour() {
+ return $this->price_per_hour;
+ }
- /**
- * Set the price per hour of the assignment
- *
- * @param float $price_per_hour The new price per hour for the assignment
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setPricePerHour($price_per_hour) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `price_per_hour`=? WHERE `id`=?");
- $stmt->execute(array($price_per_hour, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->price_per_hour = $price_per_hour;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the price per hour of the assignment
+ *
+ * @param float $price_per_hour The new price per hour for the assignment
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setPricePerHour($price_per_hour) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `price_per_hour`=? WHERE `id`=?");
+ $stmt->execute(array($price_per_hour, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->price_per_hour = $price_per_hour;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the VAT percentage of the assignment
- *
- * @return float The VAT percentage
- */
- public function getVAT() {
- return $this->vat;
- }
+ /**
+ * Get the VAT percentage of the assignment
+ *
+ * @return float The VAT percentage
+ */
+ public function getVAT() {
+ return $this->vat;
+ }
- /**
- * Set the VAT percentage of the assignment
- *
- * @param float $vat The new VAT percentage for the assignment
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setVAT($vat) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `VAT_percentage`=? WHERE `id`=?");
- $stmt->execute(array($vat, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->vat = $vat;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the VAT percentage of the assignment
+ *
+ * @param float $vat The new VAT percentage for the assignment
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setVAT($vat) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."assignment` SET `VAT_percentage`=? WHERE `id`=?");
+ $stmt->execute(array($vat, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->vat = $vat;
+ return true;
+ } else {
+ return false;
+ }
+ }
- //------------------------------------------------------------------------------
- // Other functions
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Other functions
+ //------------------------------------------------------------------------------
- /**
- * Calculate useful numbers about the assignment
- *
- * Subtotal: price_per_hour \* hours
- *
- * VAT: subtotal \* VAT_percentage
- *
- * Total: subtotal + VAT
- *
- * @param int $what Any of assignment::SUBTOTAL, assignment::VAT, assignment::TOTAL
- * @param int $round How many decimals to round on
- * @param bool $format Whether to format the number nicely (for output) or not (for calculations)
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return float|bool The calculated value rounded on $round decimals, or false when the input is incorrect
- */
- public function calculate($what = self::TOTAL, $round = 2, $format = true) {
- $return = 0;
- switch ($what) {
- case self::SUBTOTAL:
- $return = $this->getPricePerHour() * $this->getHours();
- break;
- case self::VAT:
- $return = $this->calculate(self::SUBTOTAL, $round + 1, false) * $this->getVAT() / 100;
- break;
- case self::TOTAL:
- $return = $this->calculate(self::SUBTOTAL, $round + 1, false) + $this->calculate(self::VAT, $round + 1, false);
- break;
- default:
- return false;
- }
- if ($format) {
- return number_format($return, $round);
- } else {
- return round($return, $round);
- }
- }
+ /**
+ * Calculate useful numbers about the assignment
+ *
+ * Subtotal: price_per_hour \* hours
+ *
+ * VAT: subtotal \* VAT_percentage
+ *
+ * Total: subtotal + VAT
+ *
+ * @param int $what Any of assignment::SUBTOTAL, assignment::VAT, assignment::TOTAL
+ * @param int $round How many decimals to round on
+ * @param bool $format Whether to format the number nicely (for output) or not (for calculations)
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return float|bool The calculated value rounded on $round decimals, or false when the input is incorrect
+ */
+ public function calculate($what = self::TOTAL, $round = 2, $format = true) {
+ $return = 0;
+ switch ($what) {
+ case self::SUBTOTAL:
+ $return = $this->getPricePerHour() * $this->getHours();
+ break;
+ case self::VAT:
+ $return = $this->calculate(self::SUBTOTAL, $round + 1, false) * $this->getVAT() / 100;
+ break;
+ case self::TOTAL:
+ $return = $this->calculate(self::SUBTOTAL, $round + 1, false) + $this->calculate(self::VAT, $round + 1, false);
+ break;
+ default:
+ return false;
+ }
+ if ($format) {
+ return number_format($return, $round);
+ } else {
+ return round($return, $round);
+ }
+ }
- /**
- * Remove this assignment from the database
- *
- * If this doesn't succeed (i.e. false is returned), that means the assignment was removed manually or by another instance of this class
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on success, false on failure
- */
- public function delete() {
- $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."assignment` WHERE `id`=?");
- $stmt->execute(array($this->id));
- if ($stmt->rowCount() != 1) {
- return false;
- } else {
- return true;
- }
- }
+ /**
+ * Remove this assignment from the database
+ *
+ * If this doesn't succeed (i.e. false is returned), that means the assignment was removed manually or by another instance of this class
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on success, false on failure
+ */
+ public function delete() {
+ $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."assignment` WHERE `id`=?");
+ $stmt->execute(array($this->id));
+ if ($stmt->rowCount() != 1) {
+ return false;
+ } else {
+ return true;
+ }
+ }
} \ No newline at end of file
diff --git a/classes/client.class.php b/classes/client.class.php
index d39cfaf..1b45bae 100644
--- a/classes/client.class.php
+++ b/classes/client.class.php
@@ -25,171 +25,171 @@
* An interface to the client table in the database
*/
class client {
- /**
- * @var pdo $pdo The PDO class for database communication
- * @var int $id The id of the client
- * @var string $name The name of the client
- */
- protected $pdo, $id, $name;
+ /**
+ * @var pdo $pdo The PDO class for database communication
+ * @var int $id The id of the client
+ * @var string $name The name of the client
+ */
+ protected $pdo, $id, $name;
- /**
- * Create a new instance
- *
- * @param PDO $pdo The PDO class, to access the database
- * @param int $id The id of the client to fetch
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the client could not be found
- */
- public function __construct($pdo, $id) {
- $this->pdo = $pdo;
+ /**
+ * Create a new instance
+ *
+ * @param PDO $pdo The PDO class, to access the database
+ * @param int $id The id of the client to fetch
+ *
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If the client could not be found
+ */
+ public function __construct($pdo, $id) {
+ $this->pdo = $pdo;
- $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."client` WHERE `id`=?");
- $stmt->execute(array($id));
- if ($stmt->rowCount() == 0) {
- throw new Exception("The client with id '$id' could not be found.");
- }
- $client = $stmt->fetch(PDO::FETCH_ASSOC);
+ $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."client` WHERE `id`=?");
+ $stmt->execute(array($id));
+ if ($stmt->rowCount() == 0) {
+ throw new Exception("The client with id '$id' could not be found.");
+ }
+ $client = $stmt->fetch(PDO::FETCH_ASSOC);
- $this->id = $client['id'];
- $this->name = $client['name'];
- }
+ $this->id = $client['id'];
+ $this->name = $client['name'];
+ }
- //------------------------------------------------------------------------------
- // Getters and setters
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Getters and setters
+ //------------------------------------------------------------------------------
- /**
- * Get the ID of the client
- *
- * @return int The ID
- */
- public function getId() {
- return $this->id;
- }
+ /**
+ * Get the ID of the client
+ *
+ * @return int The ID
+ */
+ public function getId() {
+ return $this->id;
+ }
- /**
- * Get the name of the client
- *
- * @return string The name
- */
- public function getName() {
- return $this->name;
- }
+ /**
+ * Get the name of the client
+ *
+ * @return string The name
+ */
+ public function getName() {
+ return $this->name;
+ }
- /**
- * Set the name of the client
- *
- * @param string $name The new name for the client
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setName($name) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."client` SET `name`=? WHERE `id`=?");
- $stmt->execute(array($name, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->name = $name;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the name of the client
+ *
+ * @param string $name The new name for the client
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setName($name) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."client` SET `name`=? WHERE `id`=?");
+ $stmt->execute(array($name, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->name = $name;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get all contact ids for this client
- *
- * @see client::getContacts() This funtion returns instances of the contact class instead of just the ids
- *
- * @throws PDOException Is something went wrong with the database
- *
- * @return int[] The ids
- */
- public function getContactIds() {
- $ids = array();
- $contacts = $this->pdo->query("SELECT `id` FROM `".constants::db_prefix."contact` WHERE `clientId`={$this->id}")->fetchAll(PDO::FETCH_ASSOC);
- foreach ($contacts as $contact) {
- $ids[] = $contact['id'];
- }
- return $ids;
- }
+ /**
+ * Get all contact ids for this client
+ *
+ * @see client::getContacts() This funtion returns instances of the contact class instead of just the ids
+ *
+ * @throws PDOException Is something went wrong with the database
+ *
+ * @return int[] The ids
+ */
+ public function getContactIds() {
+ $ids = array();
+ $contacts = $this->pdo->query("SELECT `id` FROM `".constants::db_prefix."contact` WHERE `clientId`={$this->id}")->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($contacts as $contact) {
+ $ids[] = $contact['id'];
+ }
+ return $ids;
+ }
- /**
- * Get all contacts for this client
- *
- * @see client::getContactIds() This function returns just the ids of the contacts, and not instances of the contact class
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return contact[] An array indexed by id of instances of the contact class
- */
- public function getContacts() {
- $ids = $this->getContactIds();
- $contacts = array();
- foreach ($ids as $id) {
- $contacts[$id] = new contact($this->pdo, $id);
- }
- return $contacts;
- }
+ /**
+ * Get all contacts for this client
+ *
+ * @see client::getContactIds() This function returns just the ids of the contacts, and not instances of the contact class
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return contact[] An array indexed by id of instances of the contact class
+ */
+ public function getContacts() {
+ $ids = $this->getContactIds();
+ $contacts = array();
+ foreach ($ids as $id) {
+ $contacts[$id] = new contact($this->pdo, $id);
+ }
+ return $contacts;
+ }
- //------------------------------------------------------------------------------
- // Other functions
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Other functions
+ //------------------------------------------------------------------------------
- /**
- * Remove this client from the database
- *
- * If this doesn't succeed (i.e. false is returned), that means the client was removed manually or by another instance of this class
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on success, false on failure
- */
- public function delete() {
- $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."client` WHERE `id`=?");
- $stmt->execute(array($this->id));
- if ($stmt->rowCount() != 1) {
- return false;
- } else {
- return true;
- }
- }
+ /**
+ * Remove this client from the database
+ *
+ * If this doesn't succeed (i.e. false is returned), that means the client was removed manually or by another instance of this class
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on success, false on failure
+ */
+ public function delete() {
+ $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."client` WHERE `id`=?");
+ $stmt->execute(array($this->id));
+ if ($stmt->rowCount() != 1) {
+ return false;
+ } else {
+ return true;
+ }
+ }
- /**
- * Make a new contact for this client
- *
- * @param string $name The name for this contact
- * @param string $email The email for this contact
- * @param string $address The first address line of this contact (normally street and house number)
- * @param string $address_2 The second address line of this contact
- * @param string $postal_code The postal code for this contact
- * @param string $city The city for this contact
- * @param string $state The state for this contact
- * @param string $country The country for this contact
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If there was a problem with the input
- *
- * @return contact A new instance of the contact class containing the new contact
- */
- public function createContact($name, $email, $address, $address_2, $postal_code, $city, $country) {
- $stmt = $this->pdo->prepare("INSERT INTO `".constants::db_prefix."contact` (`clientId`,`name`,`email`,`address`,`address_2`,`postal_code`,`city`,`country`) VALUES (?,?,?,?,?,?,?,?)");
- $stmt->execute(array(
- $this->id,
- $name,
- $email,
- $address,
- $address_2,
- $postal_code,
- $city,
- $country
- ));
- if ($stmt->rowCount() == 1) {
- return new contact($this->pdo, $this->pdo->lastInsertId());
- } else {
- $error = $stmt->errorInfo();
- throw new Exception($error[2]);
- }
- }
+ /**
+ * Make a new contact for this client
+ *
+ * @param string $name The name for this contact
+ * @param string $email The email for this contact
+ * @param string $address The first address line of this contact (normally street and house number)
+ * @param string $address_2 The second address line of this contact
+ * @param string $postal_code The postal code for this contact
+ * @param string $city The city for this contact
+ * @param string $state The state for this contact
+ * @param string $country The country for this contact
+ *
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If there was a problem with the input
+ *
+ * @return contact A new instance of the contact class containing the new contact
+ */
+ public function createContact($name, $email, $address, $address_2, $postal_code, $city, $country) {
+ $stmt = $this->pdo->prepare("INSERT INTO `".constants::db_prefix."contact` (`clientId`,`name`,`email`,`address`,`address_2`,`postal_code`,`city`,`country`) VALUES (?,?,?,?,?,?,?,?)");
+ $stmt->execute(array(
+ $this->id,
+ $name,
+ $email,
+ $address,
+ $address_2,
+ $postal_code,
+ $city,
+ $country
+ ));
+ if ($stmt->rowCount() == 1) {
+ return new contact($this->pdo, $this->pdo->lastInsertId());
+ } else {
+ $error = $stmt->errorInfo();
+ throw new Exception($error[2]);
+ }
+ }
} \ No newline at end of file
diff --git a/classes/contact.class.php b/classes/contact.class.php
index 299e6df..f920f00 100644
--- a/classes/contact.class.php
+++ b/classes/contact.class.php
@@ -25,354 +25,354 @@
* An interface to the contact table in the database
*/
class contact {
- /**
- * @var PDO $pdo The PDO class for database communication
- * @var int $id The id of the contact
- * @var int $clientId The id of the client the contact is linked to
- * @var string $name The name of the contact
- * @var string $email The email address of the contact
- * @var string $address The first address line (normally street and house number) of the contact
- * @var string $address_2 The second address line (can be null)
- * @var string $postal_code The postal code of the contact
- * @var string $city The city of the contact
- * @var string $country The country of the contact
- * @var string $language The language of the contact
- */
- protected $pdo, $id, $clientId, $name, $email, $address, $postal_code, $city, $country, $language;
+ /**
+ * @var PDO $pdo The PDO class for database communication
+ * @var int $id The id of the contact
+ * @var int $clientId The id of the client the contact is linked to
+ * @var string $name The name of the contact
+ * @var string $email The email address of the contact
+ * @var string $address The first address line (normally street and house number) of the contact
+ * @var string $address_2 The second address line (can be null)
+ * @var string $postal_code The postal code of the contact
+ * @var string $city The city of the contact
+ * @var string $country The country of the contact
+ * @var string $language The language of the contact
+ */
+ protected $pdo, $id, $clientId, $name, $email, $address, $postal_code, $city, $country, $language;
- /**
- * Create a new instance
- *
- * @param PDO $pdo The PDO class, to access the database
- * @param int $id The id of the contact to fetch
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the contact could not be found
- */
- public function __construct($pdo, $id) {
- $this->pdo = $pdo;
+ /**
+ * Create a new instance
+ *
+ * @param PDO $pdo The PDO class, to access the database
+ * @param int $id The id of the contact to fetch
+ *
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If the contact could not be found
+ */
+ public function __construct($pdo, $id) {
+ $this->pdo = $pdo;
- $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."contact` WHERE `id`=?");
- $stmt->execute(array($id));
- if ($stmt->rowCount() == 0) {
- throw new Exception("The contact with id '$id' could not be found.");
- }
- $contact = $stmt->fetch(PDO::FETCH_ASSOC);
+ $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."contact` WHERE `id`=?");
+ $stmt->execute(array($id));
+ if ($stmt->rowCount() == 0) {
+ throw new Exception("The contact with id '$id' could not be found.");
+ }
+ $contact = $stmt->fetch(PDO::FETCH_ASSOC);
- $this->id = $contact['id'];
- $this->clientId = $contact['clientId'];
- $this->name = $contact['name'];
- $this->email = $contact['email'];
- $this->address = $contact['address'];
- $this->address_2 = $contact['address_2'];
- $this->postal_code = $contact['postal_code'];
- $this->city = $contact['city'];
- $this->country = $contact['country'];
- $this->language = $contact['language'];
- }
+ $this->id = $contact['id'];
+ $this->clientId = $contact['clientId'];
+ $this->name = $contact['name'];
+ $this->email = $contact['email'];
+ $this->address = $contact['address'];
+ $this->address_2 = $contact['address_2'];
+ $this->postal_code = $contact['postal_code'];
+ $this->city = $contact['city'];
+ $this->country = $contact['country'];
+ $this->language = $contact['language'];
+ }
- //------------------------------------------------------------------------------
- // Getters and setters
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Getters and setters
+ //------------------------------------------------------------------------------
- /**
- * Get the ID of the contact
- *
- * @return int The ID
- */
- public function getId() {
- return $this->id;
- }
+ /**
+ * Get the ID of the contact
+ *
+ * @return int The ID
+ */
+ public function getId() {
+ return $this->id;
+ }
- /**
- * Get the ID of the client that this contact is linked to
- *
- * @return int The ID
- */
- public function getClientId() {
- return $this->clientId;
- }
+ /**
+ * Get the ID of the client that this contact is linked to
+ *
+ * @return int The ID
+ */
+ public function getClientId() {
+ return $this->clientId;
+ }
- /**
- * Get the client that this contact is linked to
- *
- * @return client The client
- */
- public function getClient() {
- return new client($this->pdo, $this->clientId);
- }
+ /**
+ * Get the client that this contact is linked to
+ *
+ * @return client The client
+ */
+ public function getClient() {
+ return new client($this->pdo, $this->clientId);
+ }
- /**
- * Get the name of the contact
- *
- * @return string The name
- */
- public function getName() {
- return $this->name;
- }
+ /**
+ * Get the name of the contact
+ *
+ * @return string The name
+ */
+ public function getName() {
+ return $this->name;
+ }
- /**
- * Set the name of the contact
- *
- * @param string $name The new name for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setName($name) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `name`=? WHERE `id`=?");
- $stmt->execute(array($name, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->name = $name;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the name of the contact
+ *
+ * @param string $name The new name for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setName($name) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `name`=? WHERE `id`=?");
+ $stmt->execute(array($name, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->name = $name;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the email of the contact
- *
- * @return string The email
- */
- public function getEmail() {
- return $this->email;
- }
+ /**
+ * Get the email of the contact
+ *
+ * @return string The email
+ */
+ public function getEmail() {
+ return $this->email;
+ }
- /**
- * Set the email of the contact
- *
- * @param string $email The new email for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setEmail($email) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `email`=? WHERE `id`=?");
- $stmt->execute(array($email, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->email = $email;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the email of the contact
+ *
+ * @param string $email The new email for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setEmail($email) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `email`=? WHERE `id`=?");
+ $stmt->execute(array($email, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->email = $email;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the first address line of the contact
- *
- * @return string The address
- */
- public function getAddress() {
- return $this->address;
- }
+ /**
+ * Get the first address line of the contact
+ *
+ * @return string The address
+ */
+ public function getAddress() {
+ return $this->address;
+ }
- /**
- * Set the first address line of the contact
- *
- * @param string $address The new address for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setAddress($address) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `address`=? WHERE `id`=?");
- $stmt->execute(array($address, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->address = $address;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the first address line of the contact
+ *
+ * @param string $address The new address for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setAddress($address) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `address`=? WHERE `id`=?");
+ $stmt->execute(array($address, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->address = $address;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the second address line of the contact
- *
- * @return string The address
- */
- public function getAddress_2() {
- return $this->address_2;
- }
+ /**
+ * Get the second address line of the contact
+ *
+ * @return string The address
+ */
+ public function getAddress_2() {
+ return $this->address_2;
+ }
- /**
- * Set the second address line of the contact
- *
- * @param string $address_2 The new address for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setAddress_2($address_2) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `address_2`=? WHERE `id`=?");
- $stmt->execute(array($address_2, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->address_2 = $address_2;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the second address line of the contact
+ *
+ * @param string $address_2 The new address for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setAddress_2($address_2) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `address_2`=? WHERE `id`=?");
+ $stmt->execute(array($address_2, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->address_2 = $address_2;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the postal_code of the contact
- *
- * @return string The postal_code
- */
- public function getPostalCode() {
- return $this->postal_code;
- }
+ /**
+ * Get the postal_code of the contact
+ *
+ * @return string The postal_code
+ */
+ public function getPostalCode() {
+ return $this->postal_code;
+ }
- /**
- * Set the postal code of the contact
- *
- * @param $postal_code string The new postal code for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setPostalCode($postal_code) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `postal_code`=? WHERE `id`=?");
- $stmt->execute(array($postal_code, $this->id));
- if ($stmt->rowCount() == 1) {
- return true;
- $this->postal_code = $postal_code;
- } else {
- return false;
- }
- }
+ /**
+ * Set the postal code of the contact
+ *
+ * @param $postal_code string The new postal code for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setPostalCode($postal_code) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `postal_code`=? WHERE `id`=?");
+ $stmt->execute(array($postal_code, $this->id));
+ if ($stmt->rowCount() == 1) {
+ return true;
+ $this->postal_code = $postal_code;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the city of the contact
- *
- * @return string The city
- */
- public function getCity() {
- return $this->city;
- }
+ /**
+ * Get the city of the contact
+ *
+ * @return string The city
+ */
+ public function getCity() {
+ return $this->city;
+ }
- /**
- * Set the city of the contact
- *
- * @param string $city The new city for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setCity($city) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `city`=? WHERE `id`=?");
- $stmt->execute(array($city, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->city = $city;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the city of the contact
+ *
+ * @param string $city The new city for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setCity($city) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `city`=? WHERE `id`=?");
+ $stmt->execute(array($city, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->city = $city;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the country of the contact
- *
- * @return string The country
- */
- public function getCountry() {
- return $this->country;
- }
+ /**
+ * Get the country of the contact
+ *
+ * @return string The country
+ */
+ public function getCountry() {
+ return $this->country;
+ }
- /**
- * Set the country of the contact
- *
- * @param string $country The new country for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setCountry($country) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `country`=? WHERE `id`=?");
- $stmt->execute(array($country, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->country = $country;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the country of the contact
+ *
+ * @param string $country The new country for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setCountry($country) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `country`=? WHERE `id`=?");
+ $stmt->execute(array($country, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->country = $country;
+ return true;
+ } else {
+ return false;
+ }
+ }
- /**
- * Get the language of the contact
- *
- * @return string The language
- */
- public function getLanguage() {
- return $this->language;
- }
+ /**
+ * Get the language of the contact
+ *
+ * @return string The language
+ */
+ public function getLanguage() {
+ return $this->language;
+ }
- /**
- * Set the language of the contact
- *
- * @param string $language The new language for the contact
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setLanguage($language) {
- $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `language`=? WHERE `id`=?");
- $stmt->execute(array($language, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->language = $language;
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Set the language of the contact
+ *
+ * @param string $language The new language for the contact
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on succes, false on failure
+ */
+ public function setLanguage($language) {
+ $stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."contact` SET `language`=? WHERE `id`=?");
+ $stmt->execute(array($language, $this->id));
+ if ($stmt->rowCount() == 1) {
+ $this->language = $language;
+ return true;
+ } else {
+ return false;
+ }
+ }
- //------------------------------------------------------------------------------
- // Other functions
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Other functions
+ //------------------------------------------------------------------------------
- /**
- * Remove this contact from the database
- *
- * If this doesn't succeed (i.e. false is returned), that means the contact was removed manually or by another instance of this class
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on success, false on failure
- */
- public function delete() {
- $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."contact` WHERE `id`=?");
- $stmt->execute(array($this->id));
- if ($stmt->rowCount() != 1) {
- return false;
- } else {
- return true;
- }
- }
+ /**
+ * Remove this contact from the database
+ *
+ * If this doesn't succeed (i.e. false is returned), that means the contact was removed manually or by another instance of this class
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return bool True on success, false on failure
+ */
+ public function delete() {
+ $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."contact` WHERE `id`=?");
+ $stmt->execute(array($this->id));
+ if ($stmt->rowCount() != 1) {
+ return false;
+ } else {
+ return true;
+ }
+ }
- /**
- * Make a new offer for this contact
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If there was a problem with the input
- *
- * @return offer A new instance of the offer class containing the new offer
- */
- public function createOffer() {
- $stmt = $this->pdo->prepare("INSERT INTO `".constants::db_prefix."offer` (`contactId`) VALUES (?)");
- $stmt->execute(array($this->id));
- if ($stmt->rowCount() == 1) {
- return new offer($this->pdo, $this->pdo->lastInsertId());
- } else {
- $error = $stmt->errorInfo();
- throw new Exception($error[2]);
- }
- }
+ /**
+ * Make a new offer for this contact
+ *
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If there was a problem with the input
+ *
+ * @return offer A new instance of the offer class containing the new offer
+ */
+ public function createOffer() {
+ $stmt = $this->pdo->prepare("INSERT INTO `".constants::db_prefix."offer` (`contactId`) VALUES (?)");
+ $stmt->execute(array($this->id));
+ if ($stmt->rowCount() == 1) {
+ return new offer($this->pdo, $this->pdo->lastInsertId());
+ } else {
+ $error = $stmt->errorInfo();
+ throw new Exception($error[2]);
+ }
+ }
} \ No newline at end of file
diff --git a/classes/correspondence.class.php b/classes/correspondence.class.php
index efe4c8d..979f4ee 100644
--- a/classes/correspondence.class.php
+++ b/classes/correspondence.class.php
@@ -27,239 +27,239 @@ require_once('fpdf.php');
* An extension of FPDF to generate personalized correspondence PDFs
*/
class correspondence extends FPDF {
- var $contact, $language;
-
- /**
- * If you'd want, you could change these constants to encode an RGB colour for headings in your PDFs
- */
- const HEAD_RED = 0;
- const HEAD_GREEN = 0;
- const HEAD_BLUE = 0;
+ var $contact, $language;
+
+ /**
+ * If you'd want, you could change these constants to encode an RGB colour for headings in your PDFs
+ */
+ const HEAD_RED = 0;
+ const HEAD_GREEN = 0;
+ const HEAD_BLUE = 0;
- /**
- * Array holding the translations
- *
- * @see _() A function to translate
- */
- protected static $translations = array(
- 'adres' => array(
- 'en' => 'Address',
- 'nl' => 'Adres'),
- 'amount' => array(
- 'en' => 'Amount',
- 'nl' => 'Subtotaal'),
- 'amount-due' => array(
- 'en' => 'Total amount due',
- 'nl' => 'Te voldoen'),
- 'biccode' => array(
- 'en' => 'The BIC code of our bank is %%.',
- 'nl' => 'De BIC-code van de bank is %%.'),
- 'btwnr' => array(
- 'en' => 'VAT nr',
- 'nl' => 'BTW nr'),
- 'description' => array(
- 'en' => 'Description',
- 'nl' => 'Omschrijving'),
- 'due-date' => array(
- 'en' => 'Due date',
- 'nl' => 'Vervaldatum'),
- 'email' => array(
- 'en' => 'Email',
- 'nl' => 'Email'),
- 'iban' => array(
- 'en' => 'IBAN',
- 'nl' => 'IBAN'),
- 'invoice' => array(
- 'en' => 'Invoice',
- 'nl' => 'Factuur'),
- 'invoice-date' => array(
- 'en' => 'Invoice date',
- 'nl' => 'Factuurdatum'),
- 'invoice-nr' => array(
- 'en' => 'Invoice number',
- 'nl' => 'Factuurnummer'),
- 'price-excl' => array(
- 'en' => 'Price excl.',
- 'nl' => 'Prijs excl.'),
- 'price-incl' => array(
- 'en' => 'Price incl.',
- 'nl' => 'Prijs incl.'),
- 'request' => array(
- 'en' => 'You are kindly requested to transfer the total amount before the due date to the provided IBAN nr.',
- 'nl' => 'U wordt vriendelijk verzocht het te voldoen bedrag voor de vervaldatum van de factuur over te maken naar opgegeven IBAN-nummer.'),
- 'tel-nr' => array(
- 'en' => 'Tel.',
- 'nl' => 'Tel.'),
- 'total' => array(
- 'en' => 'Total',
- 'nl' => 'Totaal'),
- 'vat' => array(
- 'en' => 'VAT',
- 'nl' => 'BTW'),
- );
+ /**
+ * Array holding the translations
+ *
+ * @see _() A function to translate
+ */
+ protected static $translations = array(
+ 'adres' => array(
+ 'en' => 'Address',
+ 'nl' => 'Adres'),
+ 'amount' => array(
+ 'en' => 'Amount',
+ 'nl' => 'Subtotaal'),
+ 'amount-due' => array(
+ 'en' => 'Total amount due',
+ 'nl' => 'Te voldoen'),
+ 'biccode' => array(
+ 'en' => 'The BIC code of our bank is %%.',
+ 'nl' => 'De BIC-code van de bank is %%.'),
+ 'btwnr' => array(
+ 'en' => 'VAT nr',
+ 'nl' => 'BTW nr'),
+ 'description' => array(
+ 'en' => 'Description',
+ 'nl' => 'Omschrijving'),
+ 'due-date' => array(
+ 'en' => 'Due date',
+ 'nl' => 'Vervaldatum'),
+ 'email' => array(
+ 'en' => 'Email',
+ 'nl' => 'Email'),
+ 'iban' => array(
+ 'en' => 'IBAN',
+ 'nl' => 'IBAN'),
+ 'invoice' => array(
+ 'en' => 'Invoice',
+ 'nl' => 'Factuur'),
+ 'invoice-date' => array(
+ 'en' => 'Invoice date',
+ 'nl' => 'Factuurdatum'),
+ 'invoice-nr' => array(
+ 'en' => 'Invoice number',
+ 'nl' => 'Factuurnummer'),
+ 'price-excl' => array(
+ 'en' => 'Price excl.',
+ 'nl' => 'Prijs excl.'),
+ 'price-incl' => array(
+ 'en' => 'Price incl.',
+ 'nl' => 'Prijs incl.'),
+ 'request' => array(
+ 'en' => 'You are kindly requested to transfer the total amount before the due date to the provided IBAN nr.',
+ 'nl' => 'U wordt vriendelijk verzocht het te voldoen bedrag voor de vervaldatum van de factuur over te maken naar opgegeven IBAN-nummer.'),
+ 'tel-nr' => array(
+ 'en' => 'Tel.',
+ 'nl' => 'Tel.'),
+ 'total' => array(
+ 'en' => 'Total',
+ 'nl' => 'Totaal'),
+ 'vat' => array(
+ 'en' => 'VAT',
+ 'nl' => 'BTW'),
+ );
- /**
- * Translate a string
- *
- * @see $translations The array holding the translations
- *
- * @param string $key The string to translate
- * @param string $lang The language to translate to (two-letter code)
- *
- * @return string The translated string
- */
- public function _($key) {
- if (!array_key_exists($key, self::$translations))
- return $key;
- return self::$translations[$key][$this->language];
- }
-
- /**
- * Create a new PDF
- *
- * @param string $orientation See the FPDF class specs
- * @param string $unit See the FPDF class specs
- * @param string $size See the FPDF class specs
- */
- function __construct($orientation='P',$unit='mm',$size='A4') {
- $this->FPDF($orientation,$unit,$size);
-
- $this->SetMargins(30,20,20);
- $this->SetAuthor(constants::invoice_name);
- $this->SetCreator('BusinessAdmin Correspondence Generator');
- $this->SetDisplayMode('fullpage','continuous');
- }
+ /**
+ * Translate a string
+ *
+ * @see $translations The array holding the translations
+ *
+ * @param string $key The string to translate
+ * @param string $lang The language to translate to (two-letter code)
+ *
+ * @return string The translated string
+ */
+ public function _($key) {
+ if (!array_key_exists($key, self::$translations))
+ return $key;
+ return self::$translations[$key][$this->language];
+ }
+
+ /**
+ * Create a new PDF
+ *
+ * @param string $orientation See the FPDF class specs
+ * @param string $unit See the FPDF class specs
+ * @param string $size See the FPDF class specs
+ */
+ function __construct($orientation='P',$unit='mm',$size='A4') {
+ $this->FPDF($orientation,$unit,$size);
+
+ $this->SetMargins(30,20,20);
+ $this->SetAuthor(constants::invoice_name);
+ $this->SetCreator('BusinessAdmin Correspondence Generator');
+ $this->SetDisplayMode('fullpage','continuous');
+ }
- /**
- * Set the language of the correspondence (used to translate stuff)
- *
- * @param string $lang The language, two letter code ('en', 'nl', ...)
- */
- function SetLangauge($lang) {
- $supported = array('nl', 'en');
- if (!in_array($lang, $supported)) {
- throw new Exception("Language not supported");
- } else {
- $this->language = $lang;
- }
- }
-
- /**
- * Set the contact to whom this correspondence will be sent (used for the address)
- *
- * @param contact $contact The contact
- */
- function SetContact($contact) {
- $this->contact = $contact;
+ /**
+ * Set the language of the correspondence (used to translate stuff)
+ *
+ * @param string $lang The language, two letter code ('en', 'nl', ...)
+ */
+ function SetLangauge($lang) {
+ $supported = array('nl', 'en');
+ if (!in_array($lang, $supported)) {
+ throw new Exception("Language not supported");
+ } else {
+ $this->language = $lang;
+ }
+ }
+
+ /**
+ * Set the contact to whom this correspondence will be sent (used for the address)
+ *
+ * @param contact $contact The contact
+ */
+ function SetContact($contact) {
+ $this->contact = $contact;
- $this->language = $contact->getLanguage();
- }
+ $this->language = $contact->getLanguage();
+ }
- /**
- * Makes a header with your details and the address of the contact
- */
- function CorrespondenceHeader() {
- if (file_exists(constants::files_folder . 'logo-correspondence.png')) {
- $this->Image(constants::files_folder . 'logo-correspondence.png',30,20,50);
- }
-
- $this->SetFont('Helvetica','',7);
- $this->Cell(110,20);
- $this->Cell(12,1,' ','T');
- $this->Cell(2,1);
- $this->Cell(35,1,' ','T');
- $this->Ln();
-
- $this->Cell(110,3.5);
- $this->SetFont('','B');
- $this->Cell(12,3.5,$this->_('adres'),'',0,'R');
- $this->Cell(2,3.5);
- $this->SetFont('','');
- $this->Cell(35,3.5, constants::invoice_name);
- $this->Ln();
-
- $this->Cell(124,3.5);
- $this->Cell(35,3.5, constants::invoice_address_1);
- $this->Ln();
- $this->Cell(124,3.5);
- $this->Cell(35,3.5, constants::invoice_address_2);
- $this->Ln();
- $this->Cell(124,3.5);
- $this->Cell(35,3.5, constants::invoice_address_3);
- $this->Ln();
- $this->Cell(160,1.5);
- $this->Ln();
- $this->Cell(110,3.5);
- $this->SetFont('','B');
- $this->Cell(12,3.5,$this->_('btwnr'),'',0,'R');
- $this->Cell(2,3.5);
- $this->SetFont('','');
- $this->Cell(35,3.5, constants::invoice_tax_nr);
- $this->Ln();
- $this->Cell(160,1.5);
- $this->Ln();
- $this->Cell(110,3.5);
- $this->SetFont('','B');
- $this->Cell(12,3.5, $this->_('iban'),'',0,'R');
- $this->Cell(2,3.5);
- $this->SetFont('','');
- $this->Cell(35,3.5, constants::invoice_iban);
- $this->Ln();
- $this->Cell(160,1.5);
- $this->Ln();
- $this->Cell(110,3.5);
- $this->SetFont('','B');
- $this->Cell(12,3.5, $this->_('tel-nr'),'',0,'R');
- $this->Cell(2,3.5);
- $this->SetFont('','',7);
- $this->Cell(35,3.5, constants::invoice_tel_nr);
- $this->Ln();
- $this->Cell(110,3.5);
- $this->SetFont('','B');
- $this->Cell(12,3.5, $this->_('email'),'',0,'R');
- $this->Cell(2,3.5);
- $this->SetFont('','');
- $this->Cell(35,3.5, constants::invoice_email);
- $this->Ln();
- $this->Cell(110,1);
- $this->Cell(12,1,' ','B');
- $this->Cell(2,1);
- $this->Cell(35,1,' ','B');
- $this->Ln();
- $this->Cell(160,15);
- $this->Ln();
-
- $this->SetFont('','',11);
- $this->SetXY(30,56.5);
- $this->Cell(90,5.5,utf8_decode($this->contact->getName()));
- $this->Ln();
- $this->SetXY(30,61.5);
- $this->Cell(90,5.5,utf8_decode($this->contact->getAddress()));
- $this->Ln();
- $this->SetXY(30,66.5);
- $this->Cell(90,5.5,utf8_decode($this->contact->getPostalCode().' '.$this->contact->getCity()));
- $this->Ln();
- $this->SetXY(30,71.5);
- $this->Cell(90,5.5,utf8_decode($this->contact->getCountry()));
- $this->Ln();
- }
-
- /**
- * Put PDF information
- */
- function _putinfo()
- {
- $this->_out('/Producer '.$this->_textstring('BusinessAdmin Correspondence Generator'));
- if(!empty($this->title))
- $this->_out('/Title '.$this->_textstring($this->title));
- if(!empty($this->subject))
- $this->_out('/Subject '.$this->_textstring($this->subject));
- if(!empty($this->author))
- $this->_out('/Author '.$this->_textstring($this->author));
- if(!empty($this->keywords))
- $this->_out('/Keywords '.$this->_textstring($this->keywords));
- if(!empty($this->creator))
- $this->_out('/Creator '.$this->_textstring($this->creator));
- $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis')));
- }
+ /**
+ * Makes a header with your details and the address of the contact
+ */
+ function CorrespondenceHeader() {
+ if (file_exists(constants::files_folder . 'logo-correspondence.png')) {
+ $this->Image(constants::files_folder . 'logo-correspondence.png',30,20,50);
+ }
+
+ $this->SetFont('Helvetica','',7);
+ $this->Cell(110,20);
+ $this->Cell(12,1,' ','T');
+ $this->Cell(2,1);
+ $this->Cell(35,1,' ','T');
+ $this->Ln();
+
+ $this->Cell(110,3.5);
+ $this->SetFont('','B');
+ $this->Cell(12,3.5,$this->_('adres'),'',0,'R');
+ $this->Cell(2,3.5);
+ $this->SetFont('','');
+ $this->Cell(35,3.5, constants::invoice_name);
+ $this->Ln();
+
+ $this->Cell(124,3.5);
+ $this->Cell(35,3.5, constants::invoice_address_1);
+ $this->Ln();
+ $this->Cell(124,3.5);
+ $this->Cell(35,3.5, constants::invoice_address_2);
+ $this->Ln();
+ $this->Cell(124,3.5);
+ $this->Cell(35,3.5, constants::invoice_address_3);
+ $this->Ln();
+ $this->Cell(160,1.5);
+ $this->Ln();
+ $this->Cell(110,3.5);
+ $this->SetFont('','B');
+ $this->Cell(12,3.5,$this->_('btwnr'),'',0,'R');
+ $this->Cell(2,3.5);
+ $this->SetFont('','');
+ $this->Cell(35,3.5, constants::invoice_tax_nr);
+ $this->Ln();
+ $this->Cell(160,1.5);
+ $this->Ln();
+ $this->Cell(110,3.5);
+ $this->SetFont('','B');
+ $this->Cell(12,3.5, $this->_('iban'),'',0,'R');
+ $this->Cell(2,3.5);
+ $this->SetFont('','');
+ $this->Cell(35,3.5, constants::invoice_iban);
+ $this->Ln();
+ $this->Cell(160,1.5);
+ $this->Ln();
+ $this->Cell(110,3.5);
+ $this->SetFont('','B');
+ $this->Cell(12,3.5, $this->_('tel-nr'),'',0,'R');
+ $this->Cell(2,3.5);
+ $this->SetFont('','',7);
+ $this->Cell(35,3.5, constants::invoice_tel_nr);
+ $this->Ln();
+ $this->Cell(110,3.5);
+ $this->SetFont('','B');
+ $this->Cell(12,3.5, $this->_('email'),'',0,'R');
+ $this->Cell(2,3.5);
+ $this->SetFont('','');
+ $this->Cell(35,3.5, constants::invoice_email);
+ $this->Ln();
+ $this->Cell(110,1);
+ $this->Cell(12,1,' ','B');
+ $this->Cell(2,1);
+ $this->Cell(35,1,' ','B');
+ $this->Ln();
+ $this->Cell(160,15);
+ $this->Ln();
+
+ $this->SetFont('','',11);
+ $this->SetXY(30,56.5);
+ $this->Cell(90,5.5,utf8_decode($this->contact->getName()));
+ $this->Ln();
+ $this->SetXY(30,61.5);
+ $this->Cell(90,5.5,utf8_decode($this->contact->getAddress()));
+ $this->Ln();
+ $this->SetXY(30,66.5);
+ $this->Cell(90,5.5,utf8_decode($this->contact->getPostalCode().' '.$this->contact->getCity()));
+ $this->Ln();
+ $this->SetXY(30,71.5);
+ $this->Cell(90,5.5,utf8_decode($this->contact->getCountry()));
+ $this->Ln();
+ }
+
+ /**
+ * Put PDF information
+ */
+ function _putinfo()
+ {
+ $this->_out('/Producer '.$this->_textstring('BusinessAdmin Correspondence Generator'));
+ if(!empty($this->title))
+ $this->_out('/Title '.$this->_textstring($this->title));
+ if(!empty($this->subject))
+ $this->_out('/Subject '.$this->_textstring($this->subject));
+ if(!empty($this->author))
+ $this->_out('/Author '.$this->_textstring($this->author));
+ if(!empty($this->keywords))
+ $this->_out('/Keywords '.$this->_textstring($this->keywords));
+ if(!empty($this->creator))
+ $this->_out('/Creator '.$this->_textstring($this->creator));
+ $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis')));
+ }
} \ No newline at end of file
diff --git a/classes/file.class.php b/classes/file.class.php
index ee1ccce..f6019ec 100644
--- a/classes/file.class.php
+++ b/classes/file.class.php
@@ -25,124 +25,124 @@
* An interface to the file table in the database
*/
class file {
- /**
- * @var PDO $pdo The PDO class for database communication
- * @var int $id The id of the file
- * @var string $filename The relative path to the file
- */
- protected $pdo, $id, $filename;
+ /**
+ * @var PDO $pdo The PDO class for database communication
+ * @var int $id The id of the file
+ * @var string $filename The relative path to the file
+ */
+ protected $pdo, $id, $filename;
- /**
- * Create a new instance
- *
- * @param PDO $pdo The PDO class, to access the database
- * @param int $id The id of the file to fetch
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the file could not be found
- */
- public function __construct($pdo, $id) {
- $this->pdo = $pdo;
+ /**
+ * Create a new instance
+ *
+ * @param PDO $pdo The PDO class, to access the database
+ * @param int $id The id of the file to fetch
+ *
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If the file could not be found
+ */
+ public function __construct($pdo, $id) {
+ $this->pdo = $pdo;
- $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."file` WHERE `id`=?");
- $stmt->execute(array($id));
- if ($stmt->rowCount() == 0) {
- throw new Exception("The file with id '$id' could not be found.");
- }
- $file = $stmt->fetch(PDO::FETCH_ASSOC);
+ $stmt = $this->pdo->prepare("SELECT * FROM `".constants::db_prefix."file` WHERE `id`=?");
+ $stmt->execute(array($id));
+ if ($stmt->rowCount() == 0) {
+ throw new Exception("The file with id '$id' could not be found.");
+ }
+ $file = $stmt->fetch(PDO::FETCH_ASSOC);
- $this->id = $file['id'];
- $this->filename = $file['filename'];
- }
+ $this->id = $file['id'];
+ $this->filename = $file['filename'];
+ }
- //------------------------------------------------------------------------------
- // Getters and setters
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Getters and setters
+ //------------------------------------------------------------------------------
- /**
- * Get the ID of the file
- *
- * @return int The ID
- */
- public function getId() {
- return $this->id;
- }
+ /**
+ * Get the ID of the file
+ *
+ * @return int The ID
+ */
+ public function getId() {
+ return $this->id;
+ }
- /**
- * Get the relative filename of the file
- *
- * @see file::getFilenamePath To get the full internal path to the file
- * @see file::getFilenameURI To get the full external path to the file
- *
- * @return string The filename
- */
- public function getFilename() {
- return $this->filename;
- }
+ /**
+ * Get the relative filename of the file
+ *
+ * @see file::getFilenamePath To get the full internal path to the file
+ * @see file::getFilenameURI To get the full external path to the file
+ *
+ * @return string The filename
+ */
+ public function getFilename() {
+ return $this->filename;
+ }
- /**
- * Get the full internal path to the file
- *
- * @see file::getFilename To get the relative filename
- * @see file::getFilenameURI To get the full external path to the file
- *
- * @return string The path
- */
- public function getFilenamePath() {
- return constants::files_folder . $this->filename;
- }
+ /**
+ * Get the full internal path to the file
+ *
+ * @see file::getFilename To get the relative filename
+ * @see file::getFilenameURI To get the full external path to the file
+ *
+ * @return string The path
+ */
+ public function getFilenamePath() {
+ return constants::files_folder . $this->filename;
+ }
- /**
- * Get the full external path to the file
- *
- * @see file::getFilename To get the relative filename
- * @see file::getFilenamePath To get the full internal path to the file
- *
- * @return string The URI
- */
- public function getFilenameURI() {
- return constants::files_folder_external . $this->filename;
- }
+ /**
+ * Get the full external path to the file
+ *
+ * @see file::getFilename To get the relative filename
+ * @see file::getFilenamePath To get the full internal path to the file
+ *
+ * @return string The URI
+ */
+ public function getFilenameURI() {
+ return constants::files_folder_external . $this->filename;
+ }
- //------------------------------------------------------------------------------
- // Other functions
- //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ // Other functions
+ //------------------------------------------------------------------------------
- /**
- * Move this file to the trash and delete all records for it
- *
- * Physically, this moves the file to a trash folder
- * Then, the file will be removed from the file table in the database
- * Any appendices linking to this file with fileId will have fileId NULL
- * Any offers linking to this file with invoice_fileId will have invoice_fileId NULL
- *
- * @throws PDOException If there's something wrong with the database
- *
- * @return bool True on success, false on failure
- */
- public function delete() {
- // Try to move the file to trash
- $newname = pathinfo($this->filename, PATHINFO_FILENAME) . '--' . date('Y-m-d.H.i.s.') . pathinfo($this->filename, PATHINFO_EXTENSION);
- $newdir = pathinfo($this->getFilenamePath(), PATHINFO_DIRNAME) . '/' . constants::files_folder_trash . '/';
- if (!file_exists($newdir)) {
- if (!mkdir($newdir)) {
- return false;
- }
- }
- if (!(@rename($this->getFilenamePath(), $newdir . $newname))) {
- return false;
- }
+ /**
+ * Move this file to the trash and delete all records for it
+ *
+ * Physically, this moves the file to a trash folder
+ * Then, the file will be removed from the file table in the database
+ * Any appendices linking to this file with fileId will have fileId NULL
+ * Any offers linking to this file with invoice_fileId will have invoice_fileId NULL
+ *
+ * @throws PDOException If there's something wrong with the database
+ *
+ * @return bool True on success, false on failure
+ */
+ public function delete() {
+ // Try to move the file to trash
+ $newname = pathinfo($this->filename, PATHINFO_FILENAME) . '--' . date('Y-m-d.H.i.s.') . pathinfo($this->filename, PATHINFO_EXTENSION);
+ $newdir = pathinfo($this->getFilenamePath(), PATHINFO_DIRNAME) . '/' . constants::files_folder_trash . '/';
+ if (!file_exists($newdir)) {
+ if (!mkdir($newdir)) {
+ return false;
+ }
+ }
+ if (!(@rename($this->getFilenamePath(), $newdir . $newname))) {
+ return false;
+ }
- // Remove offers linked by invoice_fileId
- $this->pdo->query("UPDATE `".constants::db_prefix."offer` SET `invoice_fileId`=NULL WHERE `invoice_fileId`={$this->id}");
+ // Remove offers linked by invoice_fileId
+ $this->pdo->query("UPDATE `".constants::db_prefix."offer` SET `invoice_fileId`=NULL WHERE `invoice_fileId`={$this->id}");
- // Remove the record of the file
- $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."file` WHERE `id`=?");
- $stmt->execute(array($this->id));
- if ($stmt->rowCount() == 1) {
- return true;
- } else {
- return false;
- }
- }
+ // Remove the record of the file
+ $stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."file` WHERE `id`=?");
+ $stmt->execute(array($this->id));
+ if ($stmt->rowCount() == 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
} \ No newline at end of file
diff --git a/classes/offer.class.php b/classes/offer.class.php
index 1a465f4..9e0a956 100644
--- a/classes/offer.class.php
+++ b/classes/offer.class.php
@@ -26,15 +26,15 @@
*/
class offer {
/**
- * @var pdo $pdo The PDO class for database communication
- * @var int $id The id of the offer
- * @var int $contactId The id of the contact this offer is linked to
- * @var int $start_date A UNIX timestamp of the start date
- * @var int $end_date A UNIX timestamp of the end date
- * @var int $invoice_date A UNIX timestamp of the invoice date
- * @var bool $accepted Whether the offer is accepted or not
- * @var null|int $invoice_fileId If an invoice has been generated, an the id of the file
- * @var null|int $payment_received A UNIX timestamp of the date the payment has been received
+ * @var pdo $pdo The PDO class for database communication
+ * @var int $id The id of the offer
+ * @var int $contactId The id of the contact this offer is linked to
+ * @var int $start_date A UNIX timestamp of the start date
+ * @var int $end_date A UNIX timestamp of the end date
+ * @var int $invoice_date A UNIX timestamp of the invoice date
+ * @var bool $accepted Whether the offer is accepted or not
+ * @var null|int $invoice_fileId If an invoice has been generated, an the id of the file
+ * @var null|int $payment_received A UNIX timestamp of the date the payment has been received
*/
protected $pdo, $id, $contactId, $start_date, $end_date, $invoice_date, $accepted, $invoice_fileId, $payment_received;
@@ -45,11 +45,11 @@ class offer {
/**
* Create a new instance
*
- * @param PDO $pdo The PDO class, to access the database
- * @param int $id The id of the offer to fetch
+ * @param PDO $pdo The PDO class, to access the database
+ * @param int $id The id of the offer to fetch
*
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the offer could not be found
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If the offer could not be found
*/
public function __construct($pdo, $id) {
$this->pdo = $pdo;
@@ -78,7 +78,7 @@ class offer {
/**
* Get the ID of the offer
*
- * @return int The ID
+ * @return int The ID
*/
public function getId() {
return $this->id;
@@ -87,9 +87,9 @@ class offer {
/**
* Get the ID of the contact that this offer is linked to
*
- * @see offer::getContact() This function returns the contact as an instance of the object class
+ * @see offer::getContact() This function returns the contact as an instance of the object class
*
- * @return int The ID
+ * @return int The ID
*/
public function getContactId() {
return $this->contactId;
@@ -98,9 +98,9 @@ class offer {
/**
* Get the contact that this offer is linked to
*
- * @see offer::getContactId() This function returns just the id
+ * @see offer::getContactId() This function returns just the id
*
- * @return contact The contact
+ * @return contact The contact
*/
public function getContact() {
return new contact($this->pdo, $this->contactId);
@@ -109,11 +109,11 @@ class offer {
/**
* Get all assignment ids for this offer
*
- * @see offer::getAssignments() This funtion returns instances of the assignment class instead of just the ids
+ * @see offer::getAssignments() This funtion returns instances of the assignment class instead of just the ids
*
* @throws PDOException Is something went wrong with the database
*
- * @return int[] The ids
+ * @return int[] The ids
*/
public function getAssignmentIds() {
$ids = array();
@@ -127,11 +127,11 @@ class offer {
/**
* Get all assignments for this offer
*
- * @see offer::getAssignmentIds() This function returns just the ids of the assignments, and not instances of the assignment class
+ * @see offer::getAssignmentIds() This function returns just the ids of the assignments, and not instances of the assignment class
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return assignment[] An array indexed by id of instances of the assignment class
+ * @return assignment[] An array indexed by id of instances of the assignment class
*/
public function getAssignments() {
$ids = $this->getAssignmentIds();
@@ -145,7 +145,7 @@ class offer {
/**
* Get the start date of the assignment
*
- * @return int The start date as a UNIX timestamp
+ * @return int The start date as a UNIX timestamp
*/
public function getStartDate() {
return $this->start_date;
@@ -154,11 +154,11 @@ class offer {
/**
* Set the start date of the assignment
*
- * @param int $start_date The new start date for the assignment as a UNIX timestamp
+ * @param int $start_date The new start date for the assignment as a UNIX timestamp
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return bool True on succes, false on failure
+ * @return bool True on succes, false on failure
*/
public function setStartDate($start_date) {
$stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."offer` SET `start_date`=? WHERE `id`=?");
@@ -174,7 +174,7 @@ class offer {
/**
* Get the end date of the assignment
*
- * @return int The end date as a UNIX timestamp
+ * @return int The end date as a UNIX timestamp
*/
public function getEndDate() {
return $this->end_date;
@@ -183,11 +183,11 @@ class offer {
/**
* Set the end date of the assignment
*
- * @param int $end_date The new end date for the assignment as a UNIX timestamp
+ * @param int $end_date The new end date for the assignment as a UNIX timestamp
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return bool True on succes, false on failure
+ * @return bool True on succes, false on failure
*/
public function setEndDate($end_date) {
$stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."offer` SET `end_date`=? WHERE `id`=?");
@@ -203,7 +203,7 @@ class offer {
/**
* Get the invoice date of the assignment
*
- * @return int The invoice date as a UNIX timestamp
+ * @return int The invoice date as a UNIX timestamp
*/
public function getInvoiceDate() {
return $this->invoice_date;
@@ -212,11 +212,11 @@ class offer {
/**
* Set the invoice date of the assignment
*
- * @param int $invoice_date The new invoice date for the assignment as a UNIX timestamp
+ * @param int $invoice_date The new invoice date for the assignment as a UNIX timestamp
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return bool True on succes, false on failure
+ * @return bool True on succes, false on failure
*/
public function setInvoiceDate($invoice_date) {
$stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."offer` SET `invoice_date`=? WHERE `id`=?");
@@ -232,7 +232,7 @@ class offer {
/**
* Get the date the payment was received
*
- * @return int|null The date as a UNIX timestamp, or null if it wasn't received yet
+ * @return int|null The date as a UNIX timestamp, or null if it wasn't received yet
*/
public function getPaymentReceived() {
return $this->payment_received;
@@ -241,11 +241,11 @@ class offer {
/**
* Set the payment received date of the assignment
*
- * @param int $payment_received The new date the payment has been received as a UNIX timestamp
+ * @param int $payment_received The new date the payment has been received as a UNIX timestamp
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return bool True on succes, false on failure
+ * @return bool True on succes, false on failure
*/
public function setPaymentReceived($payment_received) {
$stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."offer` SET `payment_received`=? WHERE `id`=?");
@@ -261,7 +261,7 @@ class offer {
/**
* Check if the offer is accepted or not
*
- * @return bool True if the offer is accepted, false if not
+ * @return bool True if the offer is accepted, false if not
*/
public function isAccepted() {
return $this->accepted;
@@ -270,9 +270,9 @@ class offer {
/**
* Toggle the `accepted' status of the offer
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return bool True on success, false on failure
+ * @return bool True on success, false on failure
*/
public function toggleAccepted() {
$stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."offer` SET `accepted`=? WHERE `id`=?");
@@ -289,9 +289,9 @@ class offer {
/**
* Get the ID of the file that the invoice of this offer is linked to
*
- * @see offer::getInvoiceFile() This function returns the file as an instance of the file class
+ * @see offer::getInvoiceFile() This function returns the file as an instance of the file class
*
- * @return int The ID
+ * @return int The ID
*/
public function getInvoiceFileId() {
return $this->invoice_fileId;
@@ -300,9 +300,9 @@ class offer {
/**
* Get the file that the invoice this offer is linked to
*
- * @see offer::getInvoiceId() This function returns just the id
+ * @see offer::getInvoiceId() This function returns just the id
*
- * @return file|null The file, or null if it doesn't exist
+ * @return file|null The file, or null if it doesn't exist
*/
public function getInvoiceFile() {
if ($this->invoice_fileId != null) {
@@ -315,11 +315,11 @@ class offer {
/**
* Set the invoice file id of the assignment
*
- * @param int $invoice_fileId The new invoice file id for the assignment
+ * @param int $invoice_fileId The new invoice file id for the assignment
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return bool True on succes, false on failure
+ * @return bool True on succes, false on failure
*/
public function setInvoiceFileId($invoice_fileId) {
$stmt = $this->pdo->prepare("UPDATE `".constants::db_prefix."offer` SET `invoice_fileId`=? WHERE `id`=?");
@@ -345,13 +345,13 @@ class offer {
*
* Total: the sum of subtotal and total
*
- * @param int $what Any of offer::SUBTOTAL, offer::VAT and offer::TOTAL
- * @param int $round How many decimals to round the result on
- * @param bool $format Whether to format the number nicely (for output) or not (for calculations)
+ * @param int $what Any of offer::SUBTOTAL, offer::VAT and offer::TOTAL
+ * @param int $round How many decimals to round the result on
+ * @param bool $format Whether to format the number nicely (for output) or not (for calculations)
*
- * @throws PDOException If something went wrong with the database
+ * @throws PDOException If something went wrong with the database
*
- * @return float|bool The calculated value rounded to $round decimals, or false on incorrect input
+ * @return float|bool The calculated value rounded to $round decimals, or false on incorrect input
*/
public function calculate($what = self::TOTAL, $round = 2, $format = true) {
$return = 0;
@@ -388,7 +388,7 @@ class offer {
*
* @throws PDOException If something went wrong with the database
*
- * @return bool True on success, false on failure
+ * @return bool True on success, false on failure
*/
public function delete() {
$stmt = $this->pdo->prepare("DELETE FROM `".constants::db_prefix."offer` WHERE `id`=?");
@@ -404,15 +404,15 @@ class offer {
* Make a new assignment linked to this order
*
* @param string $title The title for this assignment
- * @param string $description The description for this assignment
- * @param int $hours The amount of hours to work on this assignment
- * @param float $price_per_hour The price per hour on this assignment
- * @param float $vat The VAT percentage (so, 21 for 21%, not 0.21!)
+ * @param string $description The description for this assignment
+ * @param int $hours The amount of hours to work on this assignment
+ * @param float $price_per_hour The price per hour on this assignment
+ * @param float $vat The VAT percentage (so, 21 for 21%, not 0.21!)
*
* @throws PDOException If something went wrong with the database
- * @throws Exception If there was a problem with the input
+ * @throws Exception If there was a problem with the input
*
- * @return assignment A new instance of the assignment class containing the new assignment
+ * @return assignment A new instance of the assignment class containing the new assignment
*/
public function createAssignment($title, $description, $hours, $price_per_hour, $vat) {
$stmt = $this->pdo->prepare("INSERT INTO `".constants::db_prefix."assignment` (`offerId`,`title`,`description`,`hours`,`price_per_hour`,`VAT_percentage`) VALUES (?,?,?,?,?,?)");
@@ -435,13 +435,10 @@ class offer {
/**
* Generate a PDF invoice
*
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the file could not be written or an other error occured
- *
- * @return file An instance of the file class with information on the invoice file generated
+ * @throws PDOException If something went wrong with the database
+ * @throws Exception If the file could not be written or an other error occured
*
- * @todo This function was directly copied from the old admin.vivisoft.nl class invoice. It should be checked and improved.
- * @todo This function should use self::calculate()
+ * @return file An instance of the file class with information on the invoice file generated
*/
public function generateInvoice() {
// Check if we already have a file
diff --git a/classes/response.class.php b/classes/response.class.php
index 887c700..babf5ed 100644
--- a/classes/response.class.php
+++ b/classes/response.class.php
@@ -25,88 +25,88 @@
* Provides a standard to base all responses to be called with AJAX on
*/
class response {
- /** The variable to keep the response in until output */
- private $response;
- /** The variable to keep the HTTP response code in until output */
- private $http_response_code;
+ /** The variable to keep the response in until output */
+ private $response;
+ /** The variable to keep the HTTP response code in until output */
+ private $http_response_code;
- /**
- * Create a new instance
- */
- public function __construct() {
- $this->response = array();
- $this->http_response_code = 200;
- }
+ /**
+ * Create a new instance
+ */
+ public function __construct() {
+ $this->response = array();
+ $this->http_response_code = 200;
+ }
- /**
- * Set a variable of the response
- *
- * @param string $name The name of the variable to set
- * @param string $value The (new) value for the variable
- */
- public function __set($name, $value) {
- $this->response[$name] = $value;
- }
+ /**
+ * Set a variable of the response
+ *
+ * @param string $name The name of the variable to set
+ * @param string $value The (new) value for the variable
+ */
+ public function __set($name, $value) {
+ $this->response[$name] = $value;
+ }
- /**
- * Get a variable of the response
- *
- * @param string $name The name of the variable to get
- *
- * @return mixed The value of the variable
- */
- public function __get($name) {
- return $this->response[$name];
- }
+ /**
+ * Get a variable of the response
+ *
+ * @param string $name The name of the variable to get
+ *
+ * @return mixed The value of the variable
+ */
+ public function __get($name) {
+ return $this->response[$name];
+ }
- /**
- * Check if a variable of the response is set
- *
- * @param string $name The name of the variable to check
- *
- * @return bool True if the variable exists, false otherwise
- */
- public function __isset($name) {
- return isset($this->response[$name]);
- }
+ /**
+ * Check if a variable of the response is set
+ *
+ * @param string $name The name of the variable to check
+ *
+ * @return bool True if the variable exists, false otherwise
+ */
+ public function __isset($name) {
+ return isset($this->response[$name]);
+ }
- /**
- * Unset a variable of the response
- *
- * @param string $name The variable to unset
- */
- public function __unset($name) {
- unset($this->response[$name]);
- }
+ /**
+ * Unset a variable of the response
+ *
+ * @param string $name The variable to unset
+ */
+ public function __unset($name) {
+ unset($this->response[$name]);
+ }
- /**
- * Get or set the HTTP response code
- *
- * If a parameter is provided, it is used as the new HTTP response code, and a bool is returned for success or failure. Otherwise, the current one is returned.
- *
- * @param int $code The new code
- *
- * @return int|bool True on successful change, false on unsuccesful change, int when the current code is returned
- */
- public function http_response_code($code = null) {
- if ($code === null) {
- return $this->http_response_code;
- } else {
- if (http_response_code($code)) {
- $this->http_response_code = $code;
- return true;
- } else {
- return false;
- }
- }
- }
+ /**
+ * Get or set the HTTP response code
+ *
+ * If a parameter is provided, it is used as the new HTTP response code, and a bool is returned for success or failure. Otherwise, the current one is returned.
+ *
+ * @param int $code The new code
+ *
+ * @return int|bool True on successful change, false on unsuccesful change, int when the current code is returned
+ */
+ public function http_response_code($code = null) {
+ if ($code === null) {
+ return $this->http_response_code;
+ } else {
+ if (http_response_code($code)) {
+ $this->http_response_code = $code;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
- /**
- * Output the response in json
- *
- * @return string The response in json format
- */
- public function getJson() {
- return json_encode($this->response);
- }
+ /**
+ * Output the response in json
+ *
+ * @return string The response in json format
+ */
+ public function getJson() {
+ return json_encode($this->response);
+ }
} \ No newline at end of file
diff --git a/index.php b/index.php
index 238b72e..a27f054 100644
--- a/index.php
+++ b/index.php
@@ -51,6 +51,7 @@ $pages = array(
'/assignments/edit' => './include/assignments-edit.php',
'/about' => './include/about.php'
);
+
$_page = null;
foreach ($pages as $uri => $path) {
if ($_request == $uri && file_exists($path)) {
@@ -59,6 +60,7 @@ foreach ($pages as $uri => $path) {
break;
}
}
+
if ($_page === null) {
$_page = '/404';
http_response_code(404);