index.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $action = '';
  31. if ( isset( $_REQUEST['action'] ) ) {
  32. $action = $_REQUEST['action'];
  33. }
  34. if ( $action == 'i' ) {
  35. // Try adding new maintainer ...
  36. $maintainer = add_maintainer( $_REQUEST['api'] );
  37. // ... then return to start screen
  38. $screen = 0;
  39. }
  40. if ( $action == 'm' ) {
  41. // There is a maintainer
  42. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  43. $screen = 2;
  44. }
  45. if ( $action == 'e' ) {
  46. // Request for edit screen
  47. $screen = 3;
  48. }
  49. if ( $action == 'x' ) {
  50. // Request to remove player
  51. $screen = 4;
  52. }
  53. assert( '$screen >= 0', "By now \$screen should be set to a value >= 0." );
  54. ?>
  55. <!doctype html>
  56. <html lang="en">
  57. <head>
  58. <!-- Required meta tags -->
  59. <meta charset="utf-8">
  60. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  61. <!-- Bootstrap CSS -->
  62. <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  63. <title>Hello, world!</title>
  64. </head>
  65. <body>
  66. <div class="container">
  67. <div class="row">
  68. <div class="col-md">
  69. One of three columns
  70. </div>
  71. <div class="col-md">
  72. <?php
  73. require "snippets.php";
  74. if ( $maintainer[0] > 0 && $maintainer[0] < 100 ) {
  75. // Error in creating maintainer
  76. print( "<pre>" );
  77. print( "ERROR $maintainer[0]: $maintainer[1]" );
  78. print( "</pre>" );
  79. // Try again
  80. $screen = 0;
  81. }
  82. // Choose or add a maintainer; default screen
  83. print( $snippets[$screen] );
  84. ?>
  85. </div>
  86. <div class="col-md">
  87. <pre>
  88. <?php
  89. print_r( $_REQUEST );
  90. ?>
  91. </pre>
  92. </div>
  93. </div>
  94. </div>
  95. <!-- Optional JavaScript -->
  96. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  97. <script src="//code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  98. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  99. <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  100. </body>