| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- require "settings.php";
- $pdo = null;
- try {
- $pdo = new PDO("sqlite:" . "${db_path}/slork.sqlite");
- } catch (PDOException $e) {
- // handle the exception here
- }
- require "functions.php";
- /**
- * BUSINESS LOGIC
- *
- * $screen = 0; // start
- * 1) First we validate or create a maintainer.
- * Adding a maintainer is a detour but results
- * in the start page with the new maintainer added
- * to be selected.
- * $_REQUEST['action'] == 'i'; // New maintainer
- * $_REQUEST['action'] == 'm'; // Maintainer selected
- * 1a) Cannot validate new maintainer; back to
- * $screen = 0;
- * 2) The maintainer will be presented a page with
- * players. He can edit or remove a player.
- * $screen = 3; $_REQUEST['action'] == 'm'; // edit player
- * $screen = 4; $_REQUEST['action'] == 'x'; // remove player
- * 3) The edit page allows the maintainer to add
- * or remove features from the player.
- */
- // global
- $screen = 0;
- $maintainer = array(0, '?');
- $action = '';
- if ( isset( $_REQUEST['action'] ) ) {
- $action = $_REQUEST['action'];
- }
- if ( $action == 'i' ) {
- // Try adding new maintainer ...
- $maintainer = add_maintainer( $_REQUEST['api'] );
- // ... then return to start screen
- $screen = 0;
- }
- if ( $action == 'm' ) {
- // There is a maintainer
- $maintainer = get_maintainer( $_REQUEST['maintainer'] );
- $screen = 2;
- }
- if ( $action == 'p' ) {
- // New player
- $maintainer = add_player( $_REQUEST['maintainer'], $_REQUEST['player'] );
- if ( $maintainer[0] < 100 ) {
- print( "<pre>" );
- print("ERROR ${maintainer[0]}: ${maintainer[1]}" );
- print("</pre>" );
- $maintainer = get_maintainer( $_REQUEST['maintainer'] );
- }
- $screen = 2;
- }
- if ( $action == 'e' ) {
- // Request for edit screen
- $maintainer = get_maintainer( $_REQUEST['maintainer'] );
- $screen = 3;
- }
- if ( $action == 's' ) {
- // Getting the Edit array back from the maintainer
- // Store preferences and return to Edit screen
- $maintainer = get_maintainer( $_REQUEST['maintainer'] );
- $player = $_REQUEST['player'];
- $properties = $_REQUEST['properties'];
- if ( in_array( 'ALL', $properties ) ) {
- $query = <<<QUERY
- SELECT DISTINCT property FROM properties;
- QUERY;
- $stmt = $pdo->prepare( $query );
- $stmt->execute();
- $rows = $stmt->fetchAll();
- $properties = [];
- foreach( $rows as $row ) {
- $properties[] = $row['property'];
- }
- }
- if ( in_array( 'NONE', $properties ) ) {
- $properties = [];
- $properties[] = "name";
- }
- print( "<pre>" );
- print_r( $properties );
- print( "</pre>" );
- store_player_properties( $player, $maintainer, $properties );
- $screen = 3;
- }
- if ( $action == 'r' ) {
- // If remove then ask verification first
- $screen = 4;
- }
- if ( $action == 'x' ) {
- // Request to remove player
- $maintainer = delete_player( $_REQUEST['player'] );
- if ( $maintainer[0] == 0 ) {
- $screen = 0;
- } else {
- $screen = 2;
- }
- }
- assert( '$screen >= 0', "By now \$screen should be set to a value >= 0." );
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <!-- Required meta tags -->
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
- <!-- Latest compiled and minified CSS -->
- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">
- <title>Slork</title>
- </head>
- <body>
- <div class="container">
- <div class="row">
- <div class="col-md">
-
- </div>
- <div class="col-md">
- <?php
- require "snippets.php";
- if ( $maintainer[0] > 0 && $maintainer[0] < 100 ) {
- // Error in creating maintainer
- print( "<pre>" );
- print( "ERROR $maintainer[0]: $maintainer[1]" );
- print( "</pre>" );
- // Try again
- $screen = 0;
- }
- // Choose or add a maintainer; default screen
- print( $snippets[$screen] );
- ?>
- </div>
- <div class="col-md">
- <pre>
- <?php
- print( "\$screen: ${screen}" );
- print_r( $_REQUEST );
- ?>
- </pre>
- </div>
- </div>
- </div>
- <!-- Optional JavaScript -->
- <!-- jQuery first, then Popper.js, then Bootstrap JS -->
- <script src="//code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
- <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
- <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
- <!-- Latest compiled and minified JavaScript -->
- <script src="//cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>
- </body>
- </html>
|