public static function verifyTable($database)
 {
     UserManager::verifyTable($database);
     if (!$database->query("CREATE TABLE IF NOT EXISTS `user_notifications` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`blid` INT NOT NULL,\n\t\t\t`date` timestamp NOT NULL,\n\t\t\t`text` text NOT NULL,\n\t\t\t`params` text NOT NULL,\n\t\t\t`seen` TINYINT NOT NULL DEFAULT 0,\n\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Error creating table: " . $database->error());
     }
 }
 public static function verifyTable($database)
 {
     require_once realpath(dirname(__FILE__) . '/UserManager.php');
     require_once realpath(dirname(__FILE__) . '/AddonManager.php');
     UserManager::verifyTable($database);
     AddonManager::verifyTable($database);
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_ratings` (\n\t\t\t`id` INT AUTO_INCREMENT,\n\t\t\t`blid` INT NOT NULL,\n\t\t\t`aid` INT NOT NULL,\n\t\t\t`rating` TINYINT NOT NULL,\n\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Unable to create table addon_ratings: " . $database->error());
     }
 }
 public static function loadBasicDummyData()
 {
     TestManager::clearDatabase();
     $database = new DatabaseManager();
     UserManager::verifyTable($database);
     AddonManager::verifyTable($database);
     BoardManager::verifyTable($database);
     TagManager::verifyTable($database);
     GroupManager::verifyTable($database);
     DependencyManager::verifyTable($database);
     CommentManager::verifyTable($database);
     RatingManager::verifyTable($database);
     BuildManager::verifyTable($database);
     StatManager::verifyTable($database);
     ScreenshotManager::verifyTable($database);
     if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('General Content', 'general_content_bg', 'Bricks, Events, Sounds, Prints, Environments, and much more!')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Minigames', 'minigames_bg', 'Weapons, Vehicles, Gamemodes, and all your gaming needs!')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Client Mods', 'client_mods_bg', 'Mods that run on your client.')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Bargain Bin', 'bargain_bin_bg', 'A home for \\'special\\' content.')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `users` (username, blid, password, email, salt, verified) VALUES ('testuser', '4833', '1d8436e97ef95a7a6151f47b909167c77cfe1985ee5500efa8d46cfe825abc59', '*****@*****.**', '273eb4', '1')")) {
         throw new Exception("Database error: " . $database->error());
     }
     //the default json types likely need to be reworked
     if (!$database->query("INSERT INTO `addon_addons` (board, blid, name, filename, description, approved, versionInfo, authorInfo, reviewInfo) VALUES ('1', '4833', 'crapy adon', 'sciprt_hax.zip', 'bad addone pls delete', '1', '{}', '[]', '[]')")) {
         throw new Exception("Database error: " . $database->error());
     }
     StatManager::addStatsToAddon(1);
     if (!$database->query("INSERT INTO `addon_tags` (name, base_color, icon) VALUES ('dum tag', 'ff6600', 'brokenimage')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `addon_tagmap` (aid, tid) VALUES ('1', '1')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `group_groups` (leader, name, description, color, icon) VALUES ('4833', 'legion of dumies', 'a group for people who just want to be in a group', '00ff00', 'brokenimage')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `group_usermap` (gid, blid, administrator) VALUES ('1', '4833', '1')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `addon_comments` (blid, aid, comment) VALUES ('4833', '1', 'glorious addon comrade')")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("INSERT INTO `addon_ratings` (blid, aid, rating) VALUES ('4833', '1', '1')")) {
         throw new Exception("Database error: " . $database->error());
     }
 }
 public static function verifyTable($database)
 {
     UserManager::verifyTable($database);
     AddonManager::verifyTable($database);
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_stats` (\n\t\t\t`aid` INT NOT NULL,\n\t\t\t`rating` FLOAT,\n\n\t\t\t`totalDownloads` INT NOT NULL DEFAULT 0,\n\n\t\t\t`iterationDownloads` INT NOT NULL DEFAULT 0,\n\n\t\t\t`webDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t`ingameDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t`updateDownloads` INT NOT NULL DEFAULT 0,\n\n\t\t\tKEY (`totalDownloads`),\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE)")) {
         throw new Exception("Failed to create addon stats table: " . $database->error());
     }
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_stats_hist` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t`aid` INT NOT NULL DEFAULT 0,\n\n\t\t\t`webDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t`ingameDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t`updateDownloads` INT NOT NULL DEFAULT 0,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Failed to create addon stat history table: " . $database->error());
     }
 }
 public static function verifyTable($database)
 {
     UserManager::verifyTable($database);
     if (!$database->query("CREATE TABLE IF NOT EXISTS `group_groups` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`leader` INT NOT NULL,\n\t\t\t`name` varchar(16) NOT NULL,\n\t\t\t`description` TEXT,\n\t\t\t`color` varchar(6) NOT NULL,\n\t\t\t`icon` text NOT NULL,\n\t\t\tFOREIGN KEY (`leader`)\n\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Error creating group table: " . $database->error());
     }
     //this table might not need a primary key
     if (!$database->query("CREATE TABLE IF NOT EXISTS `group_usermap` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`gid` INT NOT NULL,\n\t\t\t`blid` INT NOT NULL,\n\t\t\t`administrator` TINYINT NOT NULL DEFAULT 0,\n\t\t\tFOREIGN KEY (`gid`)\n\t\t\t\tREFERENCES group_groups(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Error creating group usermap table: " . $database->error());
     }
 }
 public static function verifyTable($database)
 {
     /*TO DO:
     			- screenshots
     			- tags
     			- approval info should probably be in a different table,
     			or actually maybe not I dunno
     			- do we really need stable vs testing vs dev?
     			- bargain/danger should probably be boards
     			- figure out how data is split between addon and file
     			- I don't know much about how the file system works, but
     			having 'name', 'file', 'filename', and a separate 'addon_files'
     			table doesn't seem ideal.
     			- Maybe we should just keep track of total downloads instead
     			of 3 different columns
     			- I think users should just credit people in their descriptions
     			instead of having a dedicated authorInfo json object
     		*/
     if ($database->debug()) {
         require_once realpath(dirname(__FILE__) . '/UserManager.php');
         require_once realpath(dirname(__FILE__) . '/BoardManager.php');
         UserManager::verifyTable($database);
         BoardManager::verifyTable($database);
         //why is the blid foreign key constraint removed?
         //If you want to be able to set blid to null, you should reconsider.
         //blid is used to determine which account has control over the addon.
         //There is no need to set it to null.  Just default it to some admin.
         if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_addons` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`board` INT,\n\t\t\t\t`blid` INT NOT NULL,\n\t\t\t\t`name` VARCHAR(30) NOT NULL,\n\t\t\t\t`filename` TEXT NOT NULL,\n\t\t\t\t`description` TEXT NOT NULL,\n\t\t\t\t`versionInfo` TEXT NOT NULL,\n\t\t\t\t`authorInfo` TEXT NOT NULL,\n\t\t\t\t`reviewInfo` TEXT NOT NULL,\n\t\t\t\t`repositoryInfo` TEXT NOT NULL,\n\t\t\t\t`deleted` TINYINT NOT NULL DEFAULT 0,\n\t\t\t\t`approved` TINYINT NOT NULL DEFAULT 0,\n\t\t\t\t`uploadDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\tFOREIGN KEY (`board`)\n\t\t\t\t\tREFERENCES addon_boards(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,,\n\t\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Failed to create table addon_addons: " . $database->error());
         }
     }
 }
 public static function verifyTable($database)
 {
     /*TO DO:
     			- screenshots
     			- approval info should probably be in a different table,
     			or actually maybe not I dunno
     			- do we really need stable vs testing vs dev?
     			- bargain/danger should probably be boards
     			- figure out how data is split between addon and file
     			- I don't know much about how the file system works, but
     			having 'name', 'file', 'filename', and a separate 'addon_files'
     			table doesn't seem ideal.
     			- Maybe we should just keep track of total downloads instead
     			of 3 different columns
     			- I think users should just credit people in their descriptions
     			instead of having a dedicated authorInfo json object
     		*/
     require_once realpath(dirname(__FILE__) . '/UserManager.php');
     require_once realpath(dirname(__FILE__) . '/BoardManager.php');
     UserManager::verifyTable($database);
     BoardManager::verifyTable($database);
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_addons` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`board` INT,\n\t\t\t`blid` INT NOT NULL,\n\t\t\t`name` VARCHAR(30) NOT NULL,\n\t\t\t`filename` TEXT NOT NULL,\n\t\t\t`description` TEXT NOT NULL,\n\t\t\t`version` TEXT NOT NULL,\n\t\t\t`authorInfo` TEXT NOT NULL,\n\t\t\t`reviewInfo` TEXT NOT NULL,\n\t\t\t`repositoryInfo` TEXT NULL DEFAULT NULL,\n\t\t\t`deleted` TINYINT NOT NULL DEFAULT 0,\n\t\t\t`approved` TINYINT NOT NULL DEFAULT 0,\n\t\t\t`betaVersion` TEXT DEFAULT NULL,\n\t\t\t`rating` int(11) NOT NULL DEFAULT 0,\n\t\t\t`uploadDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t`type` TEXT NOT NULL,\n\t\t\tFOREIGN KEY (`board`)\n\t\t\t\tREFERENCES addon_boards(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Failed to create table addon_addons: " . $database->error());
     }
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_updates` (\n\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `aid` int(11) NOT NULL,\n\t\t  `version` text NOT NULL,\n\t\t  `tempfile` text NOT NULL,\n\t\t  `changelog` text NOT NULL,\n\t\t  `submitted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t  `upstream` bit(1) NOT NULL DEFAULT b'0',\n\t\t  `restart` bit(1) NOT NULL DEFAULT b'0',\n\t\t  `approved` bit(1) DEFAULT NULL,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t  PRIMARY KEY (`id`),\n\t\t  UNIQUE KEY `id` (`id`))")) {
         throw new Exception("Failed to create table addon_updates: " . $database->error());
     }
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_ratings` (\n\t\t  `aid` int(11) NOT NULL,\n\t\t\t`blid` int(11) NOT NULL,\n\t\t\t`rating` int(11) NOT NULL,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE)")) {
         throw new Exception("Failed to create table addon_updates: " . $database->error());
     }
 }
 public static function verifyTable($database)
 {
     if ($database->debug()) {
         UserManager::verifyTable($database);
         AddonManager::verifyTable($database);
         TagManager::verifyTable($database);
         BuildManager::verifyTable($database);
         GroupManager::verifyTable($database);
         if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_stats` (\n\t\t\t\t`aid` INT NOT NULL,\n\t\t\t\t`rating` FLOAT,\n\t\t\t\t`totalDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`iterationDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`webDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`ingameDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`updateDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\tKEY (`totalDownloads`),\n\t\t\t\tKEY (`iterationDownloads`),\n\t\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE)")) {
             throw new Exception("Failed to create addon stats table: " . $database->error());
         }
         if (!$database->query("CREATE TABLE IF NOT EXISTS `build_stats` (\n\t\t\t\t`bid` INT NOT NULL,\n\t\t\t\t`rating` FLOAT,\n\t\t\t\t`totalDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`iterationDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\tKEY (`totalDownloads`),\n\t\t\t\tKEY (`iterationDownloads`),\n\t\t\t\tFOREIGN KEY (`bid`)\n\t\t\t\t\tREFERENCES build_builds(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE)")) {
             throw new Exception("Failed to create build stats table: " . $database->error());
         }
         if (!$database->query("CREATE TABLE IF NOT EXISTS `tag_stats` (\n\t\t\t\t`tid` INT NOT NULL,\n\t\t\t\t`totalDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`iterationDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\tKEY (`totalDownloads`),\n\t\t\t\tKEY (`iterationDownloads`),\n\t\t\t\tFOREIGN KEY (`tid`)\n\t\t\t\t\tREFERENCES addon_tags(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE)")) {
             throw new Exception("Failed to create tag stats table: " . $database->error());
         }
         //includes a lot of foreign keys, not sure if it is a good idea to include them all
         if (!$database->query("CREATE TABLE IF NOT EXISTS `statistics` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\t`users` INT NOT NULL DEFAULT 0,\n\t\t\t\t`addons` INT NOT NULL DEFAULT 0,\n\t\t\t\t`downloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`groups` INT NOT NULL DEFAULT 0,\n\t\t\t\t`comments` INT NOT NULL DEFAULT 0,\n\t\t\t\t`builds` INT NOT NULL DEFAULT 0,\n\t\t\t\t`tags` INT NOT NULL DEFAULT 0,\n\t\t\t\t`addon0` INT NOT NULL,\n\t\t\t\t`addon1` INT NOT NULL,\n\t\t\t\t`addon2` INT NOT NULL,\n\t\t\t\t`addon3` INT NOT NULL,\n\t\t\t\t`addon4` INT NOT NULL,\n\t\t\t\t`addon5` INT NOT NULL,\n\t\t\t\t`addon6` INT NOT NULL,\n\t\t\t\t`addon7` INT NOT NULL,\n\t\t\t\t`addon8` INT NOT NULL,\n\t\t\t\t`addon9` INT NOT NULL,\n\t\t\t\t`addonDownloads0` INT NOT NULL,\n\t\t\t\t`addonDownloads1` INT NOT NULL,\n\t\t\t\t`addonDownloads2` INT NOT NULL,\n\t\t\t\t`addonDownloads3` INT NOT NULL,\n\t\t\t\t`addonDownloads4` INT NOT NULL,\n\t\t\t\t`addonDownloads5` INT NOT NULL,\n\t\t\t\t`addonDownloads6` INT NOT NULL,\n\t\t\t\t`addonDownloads7` INT NOT NULL,\n\t\t\t\t`addonDownloads8` INT NOT NULL,\n\t\t\t\t`addonDownloads9` INT NOT NULL,\n\t\t\t\t`tag0` INT NOT NULL,\n\t\t\t\t`tag1` INT NOT NULL,\n\t\t\t\t`tag2` INT NOT NULL,\n\t\t\t\t`tag3` INT NOT NULL,\n\t\t\t\t`tag4` INT NOT NULL,\n\t\t\t\t`tagDownloads0` INT NOT NULL,\n\t\t\t\t`tagDownloads1` INT NOT NULL,\n\t\t\t\t`tagDownloads2` INT NOT NULL,\n\t\t\t\t`tagDownloads3` INT NOT NULL,\n\t\t\t\t`tagDownloads4` INT NOT NULL,\n\t\t\t\t`build0` INT NOT NULL,\n\t\t\t\t`build1` INT NOT NULL,\n\t\t\t\t`build2` INT NOT NULL,\n\t\t\t\t`buildDownloads0` INT NOT NULL,\n\t\t\t\t`buildDownloads1` INT NOT NULL,\n\t\t\t\t`buildDownloads2` INT NOT NULL,\n\t\t\t\tKEY (`date`),\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Failed to create stat history table: " . $database->error());
         }
     }
 }
 public static function verifyTable($database)
 {
     if ($database->debug()) {
         require_once realpath(dirname(__FILE__) . '/UserManager.php');
         require_once realpath(dirname(__FILE__) . '/AddonManager.php');
         UserManager::verifyTable($database);
         //we need users table to exist before we can create this one
         AddonManager::verifyTable($database);
         if (!$database->query("CREATE TABLE IF NOT EXISTS `build_builds` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`blid` INT NOT NULL,\n\t\t\t\t`name` VARCHAR(60) NOT NULL,\n\t\t\t\t`filename` VARCHAR(60) NOT NULL,\n\t\t\t\t`bricks` INT NOT NULL DEFAULT 0,\n\t\t\t\t`description` TEXT NOT NULL,\n\t\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tKEY (`name`),\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Error creating builds table: " . $database->error());
         }
         //to do: probably should move this to another class, maybe make dependencyManager more general
         if (!$database->query("CREATE TABLE IF NOT EXISTS `build_dependency` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`bid` INT NOT NULL,\n\t\t\t\t`aid` INT NOT NULL,\n\t\t\t\tFOREIGN KEY (`bid`)\n\t\t\t\t\tREFERENCES build_builds(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("unable to create build dependency table: " . $database->error());
         }
     }
 }
 public static function verifyTable($database)
 {
     if ($database->debug()) {
         require_once realpath(dirname(__FILE__) . '/UserManager.php');
         require_once realpath(dirname(__FILE__) . '/AddonManager.php');
         require_once realpath(dirname(__FILE__) . '/BuildManager.php');
         UserManager::verifyTable($database);
         //we need users table to exist before we can create this one
         AddonManager::verifyTable($database);
         BuildManager::verifyTable($database);
         //we need to be able to build a url out of this data too
         //	UNIQUE KEY (`filename`),
         if (!$database->query("CREATE TABLE IF NOT EXISTS `screenshots` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`blid` INT NOT NULL,\n\t\t\t\t`name` VARCHAR(60),\n\t\t\t\t`filename` VARCHAR(60),\n\t\t\t\t`description` TEXT,\n\t\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tKEY (`name`),\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Error creating screenshots table: " . $database->error());
         }
         if (!$database->query("CREATE TABLE IF NOT EXISTS `build_screenshotmap` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`sid` INT NOT NULL,\n\t\t\t\t`bid` INT NOT NULL,\n\t\t\t\t`primary` TINYINT NOT NULL DEFAULT 0,\n\t\t\t\tFOREIGN KEY (`sid`)\n\t\t\t\t\tREFERENCES screenshots(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tFOREIGN KEY (`bid`)\n\t\t\t\t\tREFERENCES build_builds(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Error creating build_screenshotmap table: " . $database->error());
         }
         if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_screenshotmap` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`sid` INT NOT NULL,\n\t\t\t\t`aid` INT NOT NULL,\n\t\t\t\tFOREIGN KEY (`sid`)\n\t\t\t\t\tREFERENCES screenshots(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Error creating addon_screenshotmap table: " . $database->error());
         }
     }
 }
Beispiel #11
0
 private static function buildLoginDetailsFromQuery($database, $query)
 {
     UserManager::verifyTable($database);
     $resource = $database->query($query);
     if (!$resource) {
         throw new Exception("Database error: " . $database->error());
     }
     if ($resource->num_rows === 0) {
         $loginDetails = false;
     } else {
         $resultObj = $resource->fetch_object();
         $loginDetails = ["hash" => $resultObj->password, "salt" => $resultObj->salt, "blid" => $resultObj->blid, "username" => $resultObj->username, "email" => $resultObj->email, "verified" => $resultObj->verified];
     }
     $resource->close();
     return $loginDetails;
 }
 public static function verifyTable($database)
 {
     require_once realpath(dirname(__FILE__) . '/UserManager.php');
     require_once realpath(dirname(__FILE__) . '/AddonManager.php');
     UserManager::verifyTable($database);
     AddonManager::verifyTable($database);
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_comments` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`blid` INT NOT NULL,\n\t\t\t`aid` INT NOT NULL,\n\t\t\t`comment` TEXT NOT NULL,\n\t\t\t`timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n\t\t\t`lastedit` TIMESTAMP NULL,\n\t\t\tKEY (`timestamp`),\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Unable to create table addon_comments: " . $database->error());
     }
 }
    public static function sendPasswordResetEmail($user)
    {
        $resetToken = substr(base64_encode(sha1(mt_rand())), 0, 16);
        $db = new DatabaseManager();
        UserManager::verifyTable($db);
        $db->query("UPDATE `users` SET `reset`='" . $db->sanitize($resetToken . " " . time()) . "' WHERE `blid`='" . $db->sanitize($user->getBlid()) . "'");
        $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
			"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html>
			  <head>
			    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			    <title>Blockland Glass Password Reset</title>
			    <meta name="description" content="" />
			    <meta name="keywords" content="" />
			    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1" />
			    <style type="text/css">
			    h1 {
			      margin-top: 0;
			    }

			    td {
			      width: 600px;
			      padding: 20px;
			      font-family: Verdana;
			      border-radius: 15px;
			      border: 1px solid #aaa;
			      background-color: #ccc;
			    }

			    td[class=footer] {
			      background-color: #333;
			      color: #fff;
			      font-weight: bold;
			      padding:10px;
			    }

			    table {
			      width: 600px;
			      margin: 15px auto;
			    }
			    </style>
			  </head>
			  <body>
			    <table class="content">
			      <tr>
			        <td>
			          <h1>Blockland Glass</h1>
			          You seem to have forgotten your password! Please click <a href="http://blocklandglass.com/user/resetPassword.php?token=' . urlencode($resetToken) . '&id=' . $user->getBLID() . '">here to reset your password</a>.<br /><br />
								If you were not the one who requested a password reset, you may disregard this message.
			        </td>
			      </tr>
			      <tr>
			        <td class="footer" style="background-color:#333;color:#fff;font-weight: bold;padding:10px;font-size:0.6em; text-align:center;border: 1px solid black;">Email sent ' . date('H:i:s M-d-y') . '</td>
			      </tr>
			    </table>
			  </body>
			</html>';
        UserManager::email($user, "Password Reset", $body);
    }