summaryrefslogtreecommitdiffstats
path: root/api/remove.php
blob: 0ef23e54ef1fa8484a159f53beedeae7b677f2b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

if (empty($_POST["id"])) {
  http_response_code(400);
  exit(0);
}
$path = "%PWD%src/db.xml";
require_once "%PWD%src/data.php";

$id = $_POST["id"];
$doc = get_doc();
$xpath = new DOMXpath($doc);
$game = $xpath->query('//game[@id="' . $id . '"]')->item(0);
$game->parentNode->removeChild($game);

$count = $doc->getElementsByTagName("count")->item(0);
$icount = intval($count->nodeValue) - 1;
$count->nodeValue = $icount;


[$data, $_] = get_data();
$i = 1;
foreach($data as $d) {
    if($d["id"] === $id) continue;
    $g = $xpath->query('//game[@id="' . $d["id"] . '"]')->item(0);
    var_dump('//game[@id="' . $d["id"] . '"]');
    $g->setAttribute("order", $i);
    $i++;	
}

$doc->save($path);
header("Location: " . $_SERVER["HTTP_REFERER"]);