updatedb.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. date_default_timezone_set('America/Los_Angeles');
  3. $data = false;
  4. ini_set("display_errors", 1);
  5. ini_set("error_reporting", E_ALL | E_STRICT);
  6. require_once("user.php");
  7. $USER = new User("registration_callback");
  8. function checkDatabase($type, $table, $check) {
  9. if ($type == "PRAGMA") :
  10. $query = 'PRAGMA table_info(' . $table . ')';
  11. elseif ($type == "SELECT") :
  12. $query = 'SELECT name FROM sqlite_master WHERE type="table" AND name="' . $table . '"';
  13. endif;
  14. $dbfile = DATABASE_LOCATION.'users.db';
  15. $file_db = new PDO("sqlite:" . $dbfile);
  16. $file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  17. $runQuery = $file_db->query($query);
  18. $buildArray = array();
  19. foreach($runQuery as $row) :
  20. array_push($buildArray, $row['name']);
  21. endforeach;
  22. $file_db = null;
  23. if (in_array($check, $buildArray)) :
  24. $found = '<div class="panel panel-success"><div class="panel-heading"><h3 class="panel-title">'. $check . '</h3></div><div style="color: gray" class="panel-body">' . $check . ' was found in ' . $table . ' and is Good 2 Go!</div></div>';
  25. elseif (!in_array($check, $buildArray)) :
  26. $found = '<div class="panel panel-danger"><div class="panel-heading"><h3 class="panel-title">'. $check . '</h3></div><div style="color: gray" class="panel-body">' . $check . ' was not found in ' . $table . ' and is being added now!</div></div>';
  27. if ($type == "PRAGMA") :
  28. $file_db = new PDO("sqlite:" . $dbfile);
  29. $file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  30. $count = $file_db->exec("ALTER TABLE `$table` ADD COLUMN `$check` TEXT");
  31. $file_db = null;
  32. endif;
  33. endif;
  34. echo $found;
  35. }
  36. ?>
  37. <html lang="en" class="no-js">
  38. <head>
  39. <meta charset="UTF-8">
  40. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  41. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  42. <meta name="msapplication-tap-highlight" content="no" />
  43. <title>Database Upgrade</title>
  44. <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  45. <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  46. <link rel="stylesheet" href="bower_components/mdi/css/materialdesignicons.min.css">
  47. <link rel="stylesheet" href="bower_components/metisMenu/dist/metisMenu.min.css">
  48. <link rel="stylesheet" href="bower_components/Waves/dist/waves.min.css">
  49. <link rel="stylesheet" href="bower_components/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css">
  50. <link rel="stylesheet" href="js/selects/cs-select.css">
  51. <link rel="stylesheet" href="js/selects/cs-skin-elastic.css">
  52. <link rel="stylesheet" href="css/style.css">
  53. </head>
  54. <body class="gray-bg" style="padding: 0;">
  55. <div id="main-wrapper" class="main-wrapper">
  56. <!--Content-->
  57. <div id="content" style="margin:0 20px; overflow:hidden">
  58. <h1><center>Database Upgrade</center></h1>
  59. <h5 id="countdown"></h5>
  60. <?php
  61. checkDatabase('SELECT', 'options', 'options');
  62. checkDatabase('SELECT', 'tabs', 'tabs');
  63. checkDatabase('PRAGMA', 'options', 'loading');
  64. checkDatabase('PRAGMA', 'options', 'hovertext');
  65. ?>
  66. </div>
  67. </div>
  68. <script>
  69. (function countdown(remaining) {
  70. if(remaining === 0)
  71. window.top.location = window.top.location.href.split('#')[0];
  72. document.getElementById('countdown').innerHTML = "<center>Page will refresh in <strong>" + remaining + "</strong> seconds [You may close this at anytime]</center>";
  73. setTimeout(function(){ countdown(remaining - 1); }, 1000);
  74. })(10);
  75. </script>
  76. </body>
  77. </html>