index.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. $pdo = null;
  3. try {
  4. $pdo = new PDO("sqlite:" . './slork.sqlite');
  5. } catch (PDOException $e) {
  6. // handle the exception here
  7. }
  8. require "functions.php";
  9. /**
  10. * BUSINESS LOGIC
  11. *
  12. * $screen = 0; // start
  13. * 1) First we validate or create a maintainer.
  14. * Adding a maintainer is a detour but results
  15. * in the same situation as selecting one.
  16. * 1b) Cannot validate maintainer
  17. * $screen = 1;
  18. * 1a) Can validate maintainer
  19. * $screen = 2; $_REQUEST['m']; // maintainer exists
  20. * 2) The maintainer will be presented a page with
  21. * players. He can edit or remove a player.
  22. * $screen = 3; $_REQUEST['e']; // edit player
  23. * $screen = 4; $_REQUEST['x']; // remove player
  24. * 3) The edit page allows the maintainer to add
  25. * or remove features from the player.
  26. */
  27. // global
  28. $screen = 0;
  29. $maintainer = array(0, '?');
  30. if ( isset( $_REQUEST['i'] ) && $_REQUEST['i'] != '' ) {
  31. // Try adding new maintainer ...
  32. $maintainer = add_maintainer( $_REQUEST['i'] );
  33. // ... then return to start screen
  34. $screen = 0;
  35. }
  36. if ( isset( $_REQUEST['m'] ) && $_REQUEST['m'] != '' ) {
  37. // There is a maintainer
  38. $maintainer = get_maintainer( $_REQUEST['m'] );
  39. $screen = 2;
  40. if (isset($_REQUEST['e'])) {
  41. // Request for edit screen
  42. $screen = 3;
  43. }
  44. if (isset($_REQUEST['x'])) {
  45. // Request to remove player
  46. $screen = 4;
  47. }
  48. }
  49. assert( '$screen >= 0', "By now \$screen should be set to a value >= 0." );
  50. ?>
  51. <!doctype html>
  52. <html lang="en">
  53. <head>
  54. <!-- Required meta tags -->
  55. <meta charset="utf-8">
  56. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  57. <!-- Bootstrap CSS -->
  58. <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  59. <title>Hello, world!</title>
  60. </head>
  61. <body>
  62. <div class="container">
  63. <div class="row">
  64. <div class="col-md">
  65. One of three columns
  66. </div>
  67. <div class="col-md">
  68. <?php
  69. require "snippets.php";
  70. if ( $maintainer[0] > 0 && $maintainer[0] < 100 ) {
  71. // Error in creating maintainer
  72. print( "<pre>" );
  73. print( "ERROR $maintainer[0]: $maintainer[1]" );
  74. print( "</pre>" );
  75. // Try again
  76. $screen = 0;
  77. }
  78. // Choose or add a maintainer; default screen
  79. print( $snippets[$screen] );
  80. ?>
  81. </div>
  82. <div class="col-md">
  83. <pre>
  84. <?php
  85. print_r( $_REQUEST );
  86. ?>
  87. </pre>
  88. </div>
  89. </div>
  90. </div>
  91. <!-- Optional JavaScript -->
  92. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  93. <script src="//code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  94. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  95. <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  96. </body>