From c50a323c25a0787ba2051b19721983776a229615 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Thu, 5 Feb 2015 00:40:47 +0100
Subject: Initial commit
---
install/index.php | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
create mode 100644 install/index.php
(limited to 'install/index.php')
diff --git a/install/index.php b/install/index.php
new file mode 100644
index 0000000..85a6c4d
--- /dev/null
+++ b/install/index.php
@@ -0,0 +1,109 @@
+.
+ */
+
+require('../conf.php');
+
+if (isset($_GET['create_tables'])) {
+ try {
+ $_pdo->query("CREATE TABLE IF NOT EXISTS `".constants::db_prefix."assignment` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `offerId` smallint(5) unsigned NOT NULL,
+ `title` tinytext NOT NULL,
+ `description` text NOT NULL,
+ `hours` smallint(5) unsigned NOT NULL,
+ `price_per_hour` float NOT NULL,
+ `VAT_percentage` float NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `offerId - title` (`offerId`,`title`(255)),
+ KEY `offerId` (`offerId`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+
+ $_pdo->query("CREATE TABLE IF NOT EXISTS `".constants::db_prefix."client` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `name` tinytext NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`(255))
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+
+ $_pdo->query("CREATE TABLE IF NOT EXISTS `".constants::db_prefix."contact` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `clientId` smallint(5) unsigned NOT NULL,
+ `name` tinytext NOT NULL,
+ `email` varchar(680) NOT NULL,
+ `address` tinytext NOT NULL,
+ `address_2` tinytext,
+ `postal_code` varchar(7) NOT NULL,
+ `city` tinytext NOT NULL,
+ `country` tinytext NOT NULL,
+ `language` varchar(3) NOT NULL DEFAULT 'en',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `clientId-name` (`clientId`,`name`(255)),
+ KEY `clientId` (`clientId`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+
+ $_pdo->query("CREATE TABLE IF NOT EXISTS `".constants::db_prefix."file` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `filename` varchar(100) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `filename` (`filename`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+
+ $_pdo->query("CREATE TABLE IF NOT EXISTS `".constants::db_prefix."offer` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `contactId` smallint(5) unsigned NOT NULL,
+ `start_date` date NOT NULL,
+ `end_date` date NOT NULL,
+ `invoice_date` date NOT NULL,
+ `accepted` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `invoice_fileId` smallint(5) unsigned DEFAULT NULL,
+ `payment_received` date DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `invoice_fileId` (`invoice_fileId`),
+ KEY `contactId` (`contactId`),
+ KEY `contactId_2` (`contactId`),
+ KEY `invoice_fileId_2` (`invoice_fileId`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."assignment`
+ ADD CONSTRAINT `assignment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `offer` (`id`)");
+
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."contact`
+ ADD CONSTRAINT `contact_ibfk_1` FOREIGN KEY (`clientId`) REFERENCES `client` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION");
+
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."offer`
+ ADD CONSTRAINT `offer_ibfk_1` FOREIGN KEY (`invoice_fileId`) REFERENCES `file` (`id`),
+ ADD CONSTRAINT `offer_ibfk_2` FOREIGN KEY (`contactId`) REFERENCES `contact` (`id`)");
+
+ echo "Succeeded creating the database tables.";
+
+ } catch (PDOException $e) {
+
+ echo "Creating the database tables failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString();
+
+ }
+}
+?>
+
+