index.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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; back to
  20. * $screen = 0;
  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 == 'p' ) {
  47. // New player
  48. $maintainer = add_player( $_REQUEST['maintainer'], $_REQUEST['player'] );
  49. if ( $maintainer[0] < 100 ) {
  50. print( "<pre>" );
  51. print("ERROR ${maintainer[0]}: ${maintainer[1]}" );
  52. print("</pre>" );
  53. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  54. }
  55. $screen = 2;
  56. }
  57. if ( $action == 'e' ) {
  58. // Request for edit screen
  59. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  60. $screen = 3;
  61. }
  62. if ( $action == 's' ) {
  63. // Getting the Edit array back from the maintainer
  64. // Store preferences and return to Edit screen
  65. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  66. $player = $_REQUEST['player'];
  67. $properties = $_REQUEST['properties'];
  68. store_player_properties( $player, $maintainer, $properties );
  69. $screen = 3;
  70. }
  71. if ( $action == 'x' ) {
  72. // Request to remove player
  73. $maintainer = delete_player( $_REQUEST['player'] );
  74. if ( $maintainer[0] == 0 ) {
  75. $screen = 0;
  76. } else {
  77. $screen = 2;
  78. }
  79. }
  80. assert( '$screen >= 0', "By now \$screen should be set to a value >= 0." );
  81. ?>
  82. <!doctype html>
  83. <html lang="en">
  84. <head>
  85. <!-- Required meta tags -->
  86. <meta charset="utf-8">
  87. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  88. <!-- Bootstrap CSS -->
  89. <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  90. <!-- Latest compiled and minified CSS -->
  91. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">
  92. <title>Slork</title>
  93. </head>
  94. <body>
  95. <div class="container">
  96. <div class="row">
  97. <div class="col-md">
  98. One of three columns
  99. </div>
  100. <div class="col-md">
  101. <?php
  102. require "snippets.php";
  103. if ( $maintainer[0] > 0 && $maintainer[0] < 100 ) {
  104. // Error in creating maintainer
  105. print( "<pre>" );
  106. print( "ERROR $maintainer[0]: $maintainer[1]" );
  107. print( "</pre>" );
  108. // Try again
  109. $screen = 0;
  110. }
  111. // Choose or add a maintainer; default screen
  112. print( $snippets[$screen] );
  113. ?>
  114. </div>
  115. <div class="col-md">
  116. <pre>
  117. <?php
  118. print_r( $_REQUEST );
  119. ?>
  120. </pre>
  121. </div>
  122. </div>
  123. </div>
  124. <!-- Optional JavaScript -->
  125. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  126. <script src="//code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  127. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  128. <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  129. <!-- Latest compiled and minified JavaScript -->
  130. <script src="//cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>
  131. </body>
  132. </html>