index.php 3.6 KB

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