Add feature to kill everybody who hasn't killed anybody

Change-Id: Idb1a1cf1edda51ab3a25bf32922a3ba66a74525f
diff --git a/admin/index.php b/admin/index.php
index f376dd3..85c2fd5 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -13,3 +13,9 @@
 	<input type="password" name="token" placeholder="Token">
 	<input type="submit" />
 </form>
+
+<h1>Mata qui no hagi matat a ningu</h1>
+<form action="killnotkillers.php" method="GET">
+	<input type="password" name="token" placeholder="Token">
+	<input type="submit" />
+</form>
diff --git a/admin/killnotkillers.php b/admin/killnotkillers.php
new file mode 100644
index 0000000..61a4dce
--- /dev/null
+++ b/admin/killnotkillers.php
@@ -0,0 +1,27 @@
+<?php
+	require '../credentials.php';
+	require '../php/utils.php';
+
+	$credentials = new Credentials();
+	if ($credentials->adminToken() != ($_GET["token"] ?? "")) {
+		exit();
+	}
+
+	$dbname = $credentials->usersdb();
+	$mortsname = $credentials->mortsdb();
+	
+	while (true) {
+		$query = "SELECT u.id, u.quimata, ud.id FROM $dbname u LEFT JOIN $mortsname m ON u.id = m.assassi INNER JOIN $dbname ud ON ud.quimata = u.id WHERE m.assassi IS NULL AND u.mort = 0 LIMIT 1";
+		$result = query($query);
+
+		header('Content-Type: text/plain');
+
+		if ($r = $result->fetch_row()) {
+			var_dump($r);
+			$sid = (int)$r[0];
+			$smata = (int)$r[1];
+			$sassassi = (int)$r[2];
+			query("UPDATE $dbname SET mort = 1, quimata = 0 WHERE id = $sid");
+			query("UPDATE $dbname SET quimata = $smata WHERE id = $sassassi");
+		} else break;
+	}