Procházet zdrojové kódy

Fixed 'remove player'

Foppe Hemminga před 5 roky
rodič
revize
5540cae84b
3 změnil soubory, kde provedl 12 přidání a 9 odebrání
  1. 7 4
      functions.php
  2. 2 2
      index.php
  3. 3 3
      snippets.php

+ 7 - 4
functions.php

@@ -65,17 +65,20 @@ function delete_player( $player ) {
 	} catch (PDOException $e) {
 		// handle the exception here
 	}
-	$maintainer = $_REQUEST['m'];
+	$maintainer_id = $_REQUEST['maintainer'];
 
 	$query = "DELETE FROM player WHERE player = ? AND maintainer = ?;";
 	$stmt = $pdo->prepare( $query );
-	$stmt->execute( [$player, $maintainer] );
-	$maintainer = get_maintainer( $maintainer );
-	if ( $player == $maintainer ) {
+	$stmt->execute( [$player, $maintainer_id] );
+	$maintainer = get_maintainer( $maintainer_id );
+	if ( $player == $maintainer_id ) {
 		// Poof
 		$query = "DELETE FROM maintainer WHERE maintainer = ?";
 		$stmt = $pdo->prepare( $query );
 		$stmt->execute( [$maintainer] );
+		unset( $_REQUEST['action'] );
+		unset( $_REQUEST['maintainer'] );
+		unset( $_REQUEST['player'] );
 		$maintainer = [0, '?'];
 	}
 	return $maintainer;

+ 2 - 2
index.php

@@ -19,8 +19,8 @@ require "functions.php";
  * to be selected.
  * $_REQUEST['action'] == 'i';  // New maintainer
  * $_REQUEST['action'] == 'm';  // Maintainer selected
- * 1a) Cannot validate new maintainer
- * $screen = 1; @TODO
+ * 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

+ 3 - 3
snippets.php

@@ -56,7 +56,10 @@ HTML;
 			<button type="submit" class="btn btn-primary">Submit</button>
 		</form>
 HTML;
+}
 
+if ( $screen == 2 ) {
+	// Let maintainer select (or delete) a player
 	$query = <<<SQL
 		SELECT player, value FROM player 
 		WHERE maintainer = ?
@@ -73,10 +76,7 @@ SQL;
 	foreach ($rows as $row) {
 		$players_id[] = array($row['player'], $row['value'] . " [" . $row['player'] . "]");
 	}
-}
 
-if ( $screen == 2 ) {
-	// Let maintainer select (or delete) a player
 	$snippets[2] = <<<HTML
 		<form id="player">
 			<div class="form-group">