From 5709215241fc99eada2efcc770bfb33e7ee72e53 Mon Sep 17 00:00:00 2001 From: lshprung Date: Sat, 16 Apr 2022 21:44:52 -0700 Subject: Added automatic table creation to setup.php --- setup.php | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/setup.php b/setup.php index 0108510..7ed1928 100644 --- a/setup.php +++ b/setup.php @@ -24,20 +24,68 @@ if($check == "y"){ $input["socket"] = readline("Enter socket [leave blank for default]: "); fwrite_wrapper($handle, ""); echo "\nSuccessfully wrote \"$config_path\"\n"; } +$check = readline("Automatically create tables? [Y/n] "); + +if($check != "n"){ + print "\n"; + + print "Testing connection using credentials..."; + include "backend/config.php"; + print "\tSuccess!\n"; + + GLOBAL $database; + $tables = [ + "Classes" => "CREATE TABLE IF NOT EXISTS Classes ( + ID int(11) NOT NULL AUTO_INCREMENT, + Name varchar(255) DEFAULT NULL, + Code varchar(255) NOT NULL, + Location tinyint(1) DEFAULT NULL, + Link varchar(255) DEFAULT NULL, + Hidden tinyint(1) DEFAULT '0', + PRIMARY KEY (ID))", + "Assignments" => "CREATE TABLE IF NOT EXISTS Assignments ( + ID int(11) NOT NULL AUTO_INCREMENT, + Class_ID int(11) NOT NULL, + Due_date date DEFAULT NULL, + Alt_due_date varchar(255) DEFAULT NULL, + Description varchar(1024) NOT NULL, + Color varchar(255) DEFAULT NULL, + Highlight varchar(255) DEFAULT NULL, + Done tinyint(1) DEFAULT NULL, + Link varchar(255) DEFAULT NULL, + Hidden tinyint(1) DEFAULT '0', + PRIMARY KEY (ID))" + ]; + + foreach(array_keys($tables) as $key){ + print "Creating table \"$key\"..."; + $q = $tables[$key]; + if(mysqli_query($db, $q)) print "\tSuccess!\n"; + else die("$q\nInsertion Failed: " . mysqli_error($db) . "\n"); + } +} + function fwrite_wrapper($file, $string){ GLOBAL $config_path; -- cgit