index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. require "settings.php";
  3. $pdo = null;
  4. try {
  5. $pdo = new PDO("sqlite:" . "${db_path}/slork.sqlite");
  6. } catch (PDOException $e) {
  7. // handle the exception here
  8. }
  9. require "functions.php";
  10. /**
  11. * BUSINESS LOGIC
  12. *
  13. * $screen = 0; // start
  14. * 1) First we validate or create a maintainer.
  15. * Adding a maintainer is a detour but results
  16. * in the start page with the new maintainer added
  17. * to be selected.
  18. * $_REQUEST['action'] == 'i'; // New maintainer
  19. * $_REQUEST['action'] == 'm'; // Maintainer selected
  20. * 1a) Cannot validate new maintainer; back to
  21. * $screen = 0;
  22. * 2) The maintainer will be presented a page with
  23. * players. He can edit or remove a player.
  24. * $screen = 3; $_REQUEST['action'] == 'm'; // edit player
  25. * $screen = 4; $_REQUEST['action'] == 'x'; // remove player
  26. * 3) The edit page allows the maintainer to add
  27. * or remove features from the player.
  28. */
  29. // global
  30. $screen = 0;
  31. $maintainer = array(0, '?');
  32. $action = '';
  33. if ( isset( $_REQUEST['action'] ) ) {
  34. $action = $_REQUEST['action'];
  35. }
  36. if ( $action == 'i' ) {
  37. // Try adding new maintainer ...
  38. $maintainer = add_maintainer( $_REQUEST['api'] );
  39. // ... then return to start screen
  40. $screen = 0;
  41. }
  42. if ( $action == 'm' ) {
  43. // There is a maintainer
  44. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  45. $screen = 2;
  46. }
  47. if ( $action == 'p' ) {
  48. // New player
  49. $maintainer = add_player( $_REQUEST['maintainer'], $_REQUEST['player'] );
  50. if ( $maintainer[0] < 100 ) {
  51. print( "<pre>" );
  52. print("ERROR ${maintainer[0]}: ${maintainer[1]}" );
  53. print("</pre>" );
  54. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  55. }
  56. $screen = 2;
  57. }
  58. if ( $action == 'e' ) {
  59. // Request for edit screen
  60. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  61. $screen = 3;
  62. }
  63. if ( $action == 's' ) {
  64. // Getting the Edit array back from the maintainer
  65. // Store preferences and return to Edit screen
  66. $maintainer = get_maintainer( $_REQUEST['maintainer'] );
  67. $player = $_REQUEST['player'];
  68. $properties = $_REQUEST['properties'];
  69. store_player_properties( $player, $maintainer, $properties );
  70. $screen = 3;
  71. }
  72. if ( $action == 'x' ) {
  73. // Request to remove player
  74. $maintainer = delete_player( $_REQUEST['player'] );
  75. if ( $maintainer[0] == 0 ) {
  76. $screen = 0;
  77. } else {
  78. $screen = 2;
  79. }
  80. }
  81. assert( '$screen >= 0', "By now \$screen should be set to a value >= 0." );
  82. ?>
  83. <!doctype html>
  84. <html lang="en">
  85. <head>
  86. <!-- Required meta tags -->
  87. <meta charset="utf-8">
  88. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  89. <!-- Bootstrap CSS -->
  90. <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  91. <!-- Latest compiled and minified CSS -->
  92. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">
  93. <title>Slork</title>
  94. </head>
  95. <body>
  96. <div class="container">
  97. <div class="row">
  98. <div class="col-md">
  99. One of three columns
  100. </div>
  101. <div class="col-md">
  102. <?php
  103. require "snippets.php";
  104. if ( $maintainer[0] > 0 && $maintainer[0] < 100 ) {
  105. // Error in creating maintainer
  106. print( "<pre>" );
  107. print( "ERROR $maintainer[0]: $maintainer[1]" );
  108. print( "</pre>" );
  109. // Try again
  110. $screen = 0;
  111. }
  112. // Choose or add a maintainer; default screen
  113. print( $snippets[$screen] );
  114. ?>
  115. </div>
  116. <div class="col-md">
  117. <pre>
  118. <?php
  119. print_r( $_REQUEST );
  120. ?>
  121. </pre>
  122. </div>
  123. </div>
  124. </div>
  125. <!-- Optional JavaScript -->
  126. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  127. <script src="//code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  128. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  129. <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  130. <!-- Latest compiled and minified JavaScript -->
  131. <script src="//cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>
  132. </body>
  133. </html>