aboutsummaryrefslogtreecommitdiff
path: root/install
diff options
context:
space:
mode:
authorCamil Staps2016-07-20 10:54:07 +0200
committerCamil Staps2016-07-20 10:54:07 +0200
commit0b60b0ccc66cbcc26619ac762b8881f52fa85bf7 (patch)
treeb3575a335585250b300f4eafa2e0f250d8c41a2a /install
parentNo minimum string length for assignment descriptions (diff)
Discounts
Diffstat (limited to 'install')
-rw-r--r--install/index.php19
-rw-r--r--install/upgrade.php49
2 files changed, 49 insertions, 19 deletions
diff --git a/install/index.php b/install/index.php
index 8a3d0b0..6c57769 100644
--- a/install/index.php
+++ b/install/index.php
@@ -57,6 +57,16 @@ if (isset($_GET['create_tables'])) {
KEY `clientId` (`clientId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+ $_pdo->query("CREATE TABLE IF NOT EXISTS `".constants::db_prefix."discount` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `offerId` smallint(5) unsigned NOT NULL,
+ `title` tinytext NOT NULL,
+ `description` text NOT NULL,
+ `value` float unsigned NOT NULL,
+ `VAT_percentage` float NOT NULL,
+ PRIMARY KEY (`id`)
+ ) 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,
@@ -81,10 +91,13 @@ if (isset($_GET['create_tables'])) {
) ENGINE=InnoDB DEFAULT CHARSET=latin1");
$_pdo->query("ALTER TABLE `".constants::db_prefix."assignment`
- ADD CONSTRAINT `assignment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".constants::db_prefix."offer` (`id`)");
+ ADD CONSTRAINT `assignment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".constants::db_prefix."offer` (`id`)");
$_pdo->query("ALTER TABLE `".constants::db_prefix."contact`
- ADD CONSTRAINT `contact_ibfk_1` FOREIGN KEY (`clientId`) REFERENCES `".constants::db_prefix."client` (`id`)");
+ ADD CONSTRAINT `contact_ibfk_1` FOREIGN KEY (`clientId`) REFERENCES `".constants::db_prefix."client` (`id`)");
+
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."discount`
+ ADD CONSTRAINT `discount_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".constants::db_prefix."offer` (`id`);");
$_pdo->query("ALTER TABLE `".constants::db_prefix."offer`
ADD CONSTRAINT `offer_ibfk_1` FOREIGN KEY (`invoice_fileId`) REFERENCES `".constants::db_prefix."file` (`id`),
@@ -118,4 +131,4 @@ if (isset($_GET['create_folders'])) {
<li><a href="?create_folders">Create folders</a></li>
</ol>
-<p>When you're done, it would be the neatest to remove the /install folder (even though this whole control panel should not be accessible for the public).</p> \ No newline at end of file
+<p>When you're done, it would be the neatest to remove the /install folder (even though this whole control panel should not be accessible for the public).</p>
diff --git a/install/upgrade.php b/install/upgrade.php
index 55b4316..04cc03a 100644
--- a/install/upgrade.php
+++ b/install/upgrade.php
@@ -38,23 +38,40 @@ function lower_version($that, $new) {
if (isset($_GET['upgrade'])) {
- if (lower_version($_GET['upgrade'], '0.1')) {
- try {
- $_pdo->query("ALTER TABLE `".constants::db_prefix."assignment` CHANGE `hours` `hours` FLOAT UNSIGNED NOT NULL");
- } catch (PDOException $e) {
- echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
- }
- }
-
- if (lower_version($_GET['upgrade'], '0.2.2')) {
- try {
- $_pdo->query("ALTER TABLE `".constants::db_prefix."assignment` DROP FOREIGN KEY `assignment_ibfk_1`");
- $_pdo->query("ALTER TABLE `".constants::db_prefix."assignment` ADD CONSTRAINT `assignment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".constants::db_prefix."offer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE");
- } catch (PDOException $e) {
- echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
- }
+ if (lower_version($_GET['upgrade'], '0.1')) {
+ try {
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."assignment` CHANGE `hours` `hours` FLOAT UNSIGNED NOT NULL");
+ } catch (PDOException $e) {
+ echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
+ }
+ }
- }
+ if (lower_version($_GET['upgrade'], '0.2.2')) {
+ try {
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."assignment` DROP FOREIGN KEY `assignment_ibfk_1`");
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."assignment` ADD CONSTRAINT `assignment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".constants::db_prefix."offer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE");
+ } catch (PDOException $e) {
+ echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
+ }
+ }
+
+ if (lower_version($_GET['upgrade'], '0.3')) {
+ try {
+ $_pdo->query("CREATE TABLE IF NOT EXISTS `".constants::db_prefix."discount` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `offerId` smallint(5) unsigned NOT NULL,
+ `title` tinytext NOT NULL,
+ `description` text NOT NULL,
+ `value` float unsigned NOT NULL,
+ `VAT_percentage` float NOT NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
+ $_pdo->query("ALTER TABLE `".constants::db_prefix."discount`
+ ADD CONSTRAINT `discount_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".constants::db_prefix."offer` (`id`);");
+ } catch (PDOException $e) {
+ echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
+ }
+ }
echo "<br/>All done.";
}