Fixed bug with JQuery .load()
diff --git a/admin/createtable.php b/admin/createtable.php
index 027788c..4abafb0 100644
--- a/admin/createtable.php
+++ b/admin/createtable.php
@@ -15,5 +15,16 @@
`password` varchar(100) NOT NULL DEFAULT ''
)";
+ /*
+ CREATE TABLE `morts` (
+ `id` int(11) NOT NULL,
+ `quimatava` int(11) NOT NULL,
+ `assassi` int(11) NOT NULL,
+ `curs` tinyint(1) NOT NULL,
+ `grau` tinyint(1) NOT NULL,
+ `data` date NOT NULL DEFAULT current_timestamp()
+ )
+ */
+
if (query($create)) header("Location: ./index.php?dbname=".$dbname);
?>
diff --git a/ajax/victiminfo.php b/ajax/victiminfo.php
index 41b1b67..e2c7ce6 100644
--- a/ajax/victiminfo.php
+++ b/ajax/victiminfo.php
@@ -1,11 +1,13 @@
<?php
require '../credentials.php';
require '../php/utils.php';
+
$user = get_users($_GET['userid']);
+ if ($user->mort) die();
$victim = get_users($user->quimata);
?>
-<table class="victima">
+<table id="victim_info">
<tr>
<td><img id="victim_img" src="https://picsum.photos/id/<?=$victim->id?>/200/200" /></td>
<td>
diff --git a/js/animations.js b/js/animations.js
index 4af9929..5ceebf9 100644
--- a/js/animations.js
+++ b/js/animations.js
@@ -1,6 +1,6 @@
function change_victim(user) {
$(".victima").fadeOut(400, function() {
- $(".victima").load('./ajax/victiminfo.php?userid=' + user.id + " .victima");
+ $(".victima").load('./ajax/victiminfo.php?userid=' + user.id + " #victim_info");
$(".victima").fadeIn(400);
});
}
diff --git a/js/utils.js b/js/utils.js
index e35b5cb..47ab686 100644
--- a/js/utils.js
+++ b/js/utils.js
@@ -35,7 +35,7 @@
if (info.requested) {
// Check for requests
if(info.requested) dead = confirm("El teu assassí ha dit que t'ha matat, és veritat?");
-
+
// Confirm/deny request
if (dead) send_request(user, "CONF DEAD"); // confirm death
else send_request(user, "DENY REQ"); // deny kill/death
@@ -56,11 +56,11 @@
// Check if user is dead
if (!user.mort) user.mort = check_requests(info, user);
- else window.location.href= "./dead.php";
// Check if there has been a change of victim
if (info.quimata != user.quimata) {
- change_victim(info);
+ if (!user.mort) change_victim(info);
+ else window.location.href = "./dead.php";
user.quimata = info.quimata;
}
diff --git a/main.php b/main.php
index 6a77599..6228fbf 100644
--- a/main.php
+++ b/main.php
@@ -70,22 +70,24 @@
<p>La teva víctima és:</p>
- <table class="victima">
- <tr>
- <td><img id="victim_img" src="https://picsum.photos/id/<?=$victim->id?>/200/200" /></td>
- <td>
- <div id="victim_name"><?=$victim->nomcomplet?></div>
- <div id="victim_curs_i_grau">
- <span id="victim_curs"><?=$victim->curs?></span>
- -
- <span id="victim_grau"><?=$victim->grau?></span>
- </div>
- <div id="butons" class="options">
- <button id="win" onclick="js: send_request(user, 'REQ KILL');">L'he matat</button>
- </div>
- </td>
- </tr>
- </table>
+ <div class="victima">
+ <table>
+ <tr>
+ <td><img id="victim_img" src="https://picsum.photos/id/<?=$victim->id?>/200/200" /></td>
+ <td>
+ <div id="victim_name"><?=$victim->nomcomplet?></div>
+ <div id="victim_curs_i_grau">
+ <span id="victim_curs"><?=$victim->curs?></span>
+ -
+ <span id="victim_grau"><?=$victim->grau?></span>
+ </div>
+ <div id="butons" class="options">
+ <button id="win" onclick="js: send_request(user, 'REQ KILL');">L'he matat</button>
+ </div>
+ </td>
+ </tr>
+ </table>
+ </div>
<div style="clear: both;"></div>
</div>
diff --git a/php/request.php b/php/request.php
index 12f0f7d..8def47f 100644
--- a/php/request.php
+++ b/php/request.php
@@ -10,12 +10,13 @@
if ($_POST['msg'] == "REQ DEAD") $queries = ["UPDATE users SET requested=2 WHERE quimata=".(int)$_POST['user_id']]; // request dead
if ($_POST['msg'] == "DENY REQ") $queries = ["UPDATE users SET requested=0 WHERE id=".(int)$_POST['user_id']]; // deny request
if ($_POST['msg'] == "CONF DEAD") {
- $queries = ["UPDATE users SET requested=0, quimata=".(int)$_POST['user_quimata']." WHERE quimata=".(int)$_POST['user_id'], // assign new victim to killer
- "UPDATE users SET quimata=0, mort=1 WHERE id=".(int)$_POST['user_id']]; // confirm victim dead/killed
+ $queries = ["INSERT INTO morts (id, quimatava, assassi, curs, grau) (SELECT id, quimata, (SELECT id FROM users WHERE quimata=".(int)$_POST['user_id']."), curs, grau FROM users WHERE id=".(int)$_POST['user_id'].")", // add to 'morts'
+ "UPDATE users SET requested=0, quimata=".(int)$_POST['user_quimata']." WHERE quimata=".(int)$_POST['user_id'], // assign new victim to killer
+ "UPDATE users SET quimata=0, mort=1 WHERE id=".(int)$_POST['user_id']]; // confirm victim dead/killed
}
// Fetch the information of the user
foreach ($queries as $query) {
if ($query != "" and $result = query($query)) echo $query;
- else die("Query failed: " . $result);
+ else die("Query failed: " . $query);
}
?>