summaryrefslogtreecommitdiffstats
path: root/index.php
blob: ea198375465c5508270e4dc308f611d88e7c5553 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <link rel="icon" type="image/svg+xml" href="favicon.svg" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Markup Language of Saddness</title>
  <link rel="stylesheet" href="src/style.css" />
</head>

<?php
require_once "src/data.php";
[$data, $count] = get_data();
function is_pos(): bool
{
  return $_GET["m"] === "pos" || $_GET["m"] === "" || !$_GET["m"];
}
?>

<body>
  <header>
    <button type="button"><a href="?m=pos">Positions</a></button>
    <button type="button"><a href="?m=pre">Preview</a></button>
  </header>
  <table>
    <thead>
      <tr>
        <th></th>
        <th></th>
        <th>Game name</th>
        <th>Thumbnail</th>
        <th>Author</th>
        <th>Magazine</th>
        <th></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <?php if (is_pos()) { ?>
        <?php foreach ($data as $d) { ?>
          <tr>
            <form action="api/change-order.php" method="post">
              <td>
                <?php if ($d["order"] !== $count) { ?>
                  <input type="hidden" name="old-order" value="<?= $d["order"] ?>">
                  <input type="hidden" name="new-order" value="<?= intval($d["order"]) + 1 ?>">
                  <input type="submit" value="pos -" />
                <?php } ?>
              </td>
            </form>
            <form action="api/remove.php" method="post">
              <td><input type="submit" onclick="edit(event)" value="E" data-id="<?= $d['id'] ?>"></td>
              <td data-id="<?= $d['id'] ?>"><?= htmlspecialchars($d["name"]) ?></td>
              <td data-id="<?= $d['id'] ?>"><?= htmlspecialchars($d["thumbnail"]) ?></td>
              <td data-id="<?= $d['id'] ?>"><?= htmlspecialchars($d["author"]) ?></td>
              <td data-id="<?= $d['id'] ?>"><?= $d["magazine"] ?></td>
              <td><input type="submit" value="Remove" data-id="<?= $d['id'] ?>"></td>
              <input type="hidden" name="id" value="<?= $d['id'] ?>" data-id="<?= $d['id'] ?>" />
            </form>
            <form action="api/change-order.php" method="post">
              <td>
                <?php if ($d["order"] !== "1") { ?>
                  <input type="hidden" name="old-order" value="<?= $d["order"] ?>">
                  <input type="hidden" name="new-order" value="<?= intval($d["order"]) - 1 ?>">
                  <input type="submit" value="pos +" />
                <?php } ?>
              </td>
            </form>
          </tr>
        <?php } ?>
      <?php } ?>
      <?php if ($_GET["m"] === "pre") { ?>
        <?php foreach ($data as $d) { ?>
          <tr>
            <form action="api/remove.php" method="post">
              <td></td>
              <td data-id="<?= $d['id'] ?>"><?= htmlspecialchars($d["name"]) ?></td>
              <td data-id="<?= $d['id'] ?>"><img src="/imgs/<?= htmlspecialchars($d["thumbnail"]) ?>" width="200" /></td>
              <td data-id="<?= $d['id'] ?>"><?= htmlspecialchars($d["author"]) ?></td>
              <td data-id="<?= $d['id'] ?>"><?= $d["magazine"] ?></td>
              <td></td>
            </form>
          </tr>
        <?php } ?>
      <?php } ?>
      <?php if (is_pos()) { ?>
        <tr>
          <form action="api/add.php" method="post">
            <td></td>
            <td></td>
            <td><input type="text" name="name"></td>
            <td><input type="text" name="thumbnail"></td>
            <td><input type="text" name="author"></td>
            <td><input type="text" name="magazine"></td>
            <td><input type="submit" value="Add"></td>
          </form>
        </tr>
      <?php } ?>
    </tbody>
  </table>
  <a href="/api/export.php">Export to xlsx</a>
  <script src="/src/main.js"></script>
</body>

</html>