Fix per les cookies que no funcionen
diff --git a/admin/createtable.php b/admin/createtable.php
index 4abafb0..ca5f2d6 100644
--- a/admin/createtable.php
+++ b/admin/createtable.php
@@ -26,5 +26,5 @@
)
*/
- if (query($create)) header("Location: ./index.php?dbname=".$dbname);
+ if (query($create)) die("<script>window.location.href = './index.php?dbname=".$dbname."'<script>");
?>
diff --git a/admin/insert.php b/admin/insert.php
index 4301bdd..e357105 100644
--- a/admin/insert.php
+++ b/admin/insert.php
@@ -20,5 +20,5 @@
if (!query($template)) die("An error ocurred.");
}
- header("Location: ./index.php");
+ die("<script>window.location.href = './index.php'</script>");
?>
diff --git a/ajax/getusers.php b/ajax/getusers.php
index 7d9f52e..181ca56 100644
--- a/ajax/getusers.php
+++ b/ajax/getusers.php
@@ -3,12 +3,15 @@
require '../php/utils.php';
$users = get_users(0, false);
+ $users_alive = [];
+
foreach ($users as &$user) {
if ($user["mort"]) continue;
- $user["nopassword"] = $user["md5password"] == "" ? "nopassword" : "";
+ $user["nopassword"] = ($user["md5password"] == "" ? "nopassword" : "");
unset($user["md5password"]);
+ array_push($users_alive, $user);
}
- echo json_encode($users);
+ echo json_encode($users_alive);
?>
diff --git a/ajax/victiminfo.php b/ajax/victiminfo.php
index e2c7ce6..44a3c88 100644
--- a/ajax/victiminfo.php
+++ b/ajax/victiminfo.php
@@ -12,7 +12,11 @@
<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="victim_curs_i_grau">
+ <span id="victim_curs"><?=$victim->nomcurs()?></span>
+ -
+ <span id="victim_grau"><?=$victim->nomgrau()?></span>
+ </div>
<div id="butons" class="options">
<button id="win" onclick="js: send_request(user, 'REQ KILL');">L'he matat</button>
</div>
diff --git a/css/basic.css b/css/basic.css
index 5c6382f..38f4d7f 100644
--- a/css/basic.css
+++ b/css/basic.css
@@ -1,11 +1,14 @@
body {
font-size: 24px;
- font-family: Helvetica;
background-image: url('https://images.unsplash.com/photo-1428196457394-f0c4aec5f574?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80');
background-size: cover;
}
+* {
+ font-family: Georgia, serif;
+}
+
#outter-container {
margin: 32px auto;
max-width: 800px;
diff --git a/css/login.css b/css/login.css
index 2ad3b75..c18a282 100644
--- a/css/login.css
+++ b/css/login.css
@@ -1,7 +1,5 @@
-select {
+#password {
font-size: 18px;
- height: 2em;
- width: 80%;
}
input[type="submit"] {
diff --git a/css/main.css b/css/main.css
index e668a86..a07653c 100644
--- a/css/main.css
+++ b/css/main.css
@@ -54,3 +54,11 @@
margin-bottom: 8px;
}
}
+
+.formulari_contrasenya {
+ padding: 5px 20px;
+ font-size: 18px;
+ background-color: rgba(255, 255, 255, 0.8);
+ border-bottom: solid grey 1px;
+ display: none;
+}
diff --git a/index.php b/index.php
index faf3c3e..2e2a106 100644
--- a/index.php
+++ b/index.php
@@ -5,6 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
+
<link rel="stylesheet" href="./css/basic.css" />
<link rel="stylesheet" href="./css/login.css" />
@@ -44,7 +46,7 @@
</div>
<input disabled required placeholder="Clau d'accés..." id="password" type="password" name="password"/>
- <input type="submit" value="Entrar" />
+ <input type="submit" value="Entrar" id="submit" />
</form>
</div>
</div>
@@ -57,11 +59,7 @@
userid = <?=isset($_COOKIE['user']) ? (int)$_COOKIE['user'] : -1 ?>;
username = get_user_name(users, userid);
-
- if (userid > 0) {
- redir = confirm("Has entrat com a usuari " + username + " anteriorment, vols tornar-ho a fer?");
- if (redir) window.location.href = 'main.php';
- }
+ if (userid > 0) $("#search-input").prop("placeholder", username);
});
$(document).ready(function() {
diff --git a/js/autocomplete.js b/js/autocomplete.js
index 28b9abf..3b27deb 100644
--- a/js/autocomplete.js
+++ b/js/autocomplete.js
@@ -1,3 +1,16 @@
+function nomcurs(curs) {
+ if (curs == 1) return "1er";
+ if (curs == 2) return "2on";
+ if (curs == 3) return "3er";
+ if (curs == 4) return "4rt";
+}
+
+function nomgrau(grau) {
+ if (grau == 0) return "MAT";
+ if (grau == 1) return "EST";
+ if (grau == 2) return "MAMME";
+}
+
function autocomplete(inp, obj, act) {
/*the autocomplete function takes two arguments,
the text field element and an objay of possible autocompleted values:*/
@@ -30,7 +43,7 @@
b.innerHTML += nomNode.substr(parts[0].length, val.length);
b.innerHTML += "<span style='font-weight: bold; position:relative; z-index:120;'>" + nomNode.substr(parts[0].length + val.length) + "</span>";
- b.innerHTML += " <span class='autocomplete-year'>(" + obj[node].curs + "-" + obj[node].grau + ")</span>";
+ b.innerHTML += " <span class='autocomplete-year'>(" + nomcurs(obj[node].curs) + " - " + nomgrau(obj[node].grau) + ")</span>";
/*include node id to keep track of which is it*/
b.dataset.id = node;
diff --git a/main.php b/main.php
index 7e0231b..1157677 100644
--- a/main.php
+++ b/main.php
@@ -2,9 +2,11 @@
require './credentials.php';
require './php/utils.php';
+ $_COOKIE['user'] = $_GET['user'];
+ $_COOKIE['password'] = $_GET['password'];
+
if (!isset($_COOKIE['user'])) {
- header("Location: ./index.php");
- die();
+ die("<script>window.location.href = './index.php'</script>");
} else if (isset($_COOKIE['password'])) {
$query_password = "SELECT password FROM users WHERE id=" . (int)$_COOKIE['user'];
if (query($query_password)->fetch_row()[0] != $_COOKIE['password']) {
@@ -12,8 +14,7 @@
setcookie('user', '', -1, "/");
setcookie('password', '', -1, "/");
- header("Location: ./index.php?passwordchanged=1");
- die();
+ die("<script>window.location.href = './index.php?passwordchanged=1'</script>");
}
}
?>
@@ -24,6 +25,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
+
<link rel="stylesheet" href="./css/basic.css" />
<link rel="stylesheet" href="./css/main.css" />
@@ -36,7 +39,7 @@
<?php
$user = get_users($_COOKIE['user']);
$victim = get_users($user->quimata);
- if ($user->mort) header("Location: ./dead.php");
+ if ($user->mort) die("<script>window.location.href = './dead.php'</script>");
?>
<script>
@@ -58,13 +61,13 @@
<div id="inner-container">
<h2>Hola <name id="user_name"><?=$user->nom()?></name>,</h2>
- <div class="formulari_contrasenya" style="display: none;">
+ <div class="formulari_contrasenya">
<p>Sembla que no tens clau d'accés, la gent podrà entrar a la teva compta...</p>
<form action="./php/change_password.php" method="POST">
<input type="hidden" value="<?=(int)$_COOKIE['user']?>" name="userid">
<input type="password" placeholder="Nova clau d'accés..." name="password" /><br />
<input type="password" placeholder="Repeteix la clau d'accés" name="confirmation"/><br />
- <input type="submit">
+ <input type="submit" value="Posar clau d'accés">
</form>
</div>
@@ -77,9 +80,9 @@
<td>
<div id="victim_name"><?=$victim->nomcomplet?></div>
<div id="victim_curs_i_grau">
- <span id="victim_curs"><?=(int)$victim->curs?></span>
+ <span id="victim_curs"><?=$victim->nomcurs()?></span>
-
- <span id="victim_grau"><?=(int)$victim->grau?></span>
+ <span id="victim_grau"><?=$victim->nomgrau()?></span>
</div>
<div id="butons" class="options">
<button id="win" onclick="js: send_request(user, 'REQ KILL');">L'he matat</button>
diff --git a/php/change_password.php b/php/change_password.php
index 6f13127..1585a41 100644
--- a/php/change_password.php
+++ b/php/change_password.php
@@ -4,17 +4,16 @@
// Check if confirmation is the same
if ($_POST['password'] != $_POST['confirmation']) {
- header("Location: ../main.php?wrongconfirmation=1");
- die();
+ die("<script>window.location.href = '../main.php?wrongconfirmation=1'</script>");
} else {
// Execute query to change password
$update_password = "UPDATE users SET password=\"".md5($_POST['password'])."\" WHERE id=".$_POST['userid'];
- if(!$result = query($update_password)) header("Location: ../main.php?errordb=1");
+ if(!$result = query($update_password)) die("<script>window.location.href = '../main.php?errordb=1'</script>");
// Save 'password' to cookies
setcookie('password', md5($_POST['password']), time() + (86400 * 10), "/");
// Go back to main page
- header("Location: ../main.php?successpassword=1");
+ die("<script>window.location.href = '../main.php?successpassword=1'</script>");
}
?>
diff --git a/php/login.php b/php/login.php
index 9fcdc39..fb8f923 100644
--- a/php/login.php
+++ b/php/login.php
@@ -7,8 +7,7 @@
if (isset($_POST['user'])) $user = $_POST['user'];
else if (isset($_COOKIE['user'])) $user = $_COOKIE['user'];
else {
- header("Location: ../index.php");
- die();
+ die("<script>window.location.href = '../index.php'</script>");
}
// Check if password is correct
@@ -26,8 +25,7 @@
setcookie('user', '', -1, "/");
setcookie('password', '', -1, "/");
- header("Location: ../index.php?wrongpassword=1");
- die();
+ die("<script>window.location.href = '../index.php?wrongpassword=1'</script>");
}
// Save variables as cookies
@@ -35,6 +33,8 @@
if ($real_password != "") setcookie('password', md5($password), time() + (86400 * 10), "/");
else setcookie('password', '', -1, "/");
+ echo "<script>window.location.href = '../main.php?user=$user&password=$password'; </script>";
+
// Success, proceed to main page
- header("Location: ../main.php");
+ // die("<script>window.location.href = '../main.php?user='.$user.'&password='.$password</script>");
?>
diff --git a/php/utils.php b/php/utils.php
index 6ac2e7e..edd53fa 100644
--- a/php/utils.php
+++ b/php/utils.php
@@ -10,6 +10,19 @@
$noms = explode(" ", $this->nomcomplet);
return $noms[0];
}
+
+ public function nomcurs() {
+ if ($this->curs == 1) return "1er";
+ if ($this->curs == 2) return "2on";
+ if ($this->curs == 3) return "3er";
+ if ($this->curs == 4) return "4rt";
+ }
+
+ public function nomgrau() {
+ if ($this->grau == 0) return "MAT";
+ if ($this->grau == 1) return "EST";
+ if ($this->grau == 2) return "MAMME";
+ }
}
function query($query) {
@@ -41,23 +54,23 @@
while ($row = $result->fetch_row()) {
if ($getAsObjects) {
$user = new User();
- $user->id = $row[0];
+ $user->id = (int)$row[0];
$user->nomcomplet = $row[1];
- $user->curs = $row[2];
- $user->grau = $row[3];
- $user->quimata = $row[4];
- $user->requested = $row[5];
- $user->mort = $row[6];
+ $user->curs = (int)$row[2];
+ $user->grau = (int)$row[3];
+ $user->quimata = (int)$row[4];
+ $user->requested = (int)$row[5];
+ $user->mort = (int)$row[6];
$user->md5password = $row[7];
} else {
$user = [];
- $user["id"] = $row[0];
+ $user["id"] = (int)$row[0];
$user["nomcomplet"] = $row[1];
- $user["curs"] = $row[2];
- $user["grau"] = $row[3];
- $user["quimata"] = $row[4];
- $user["requested"] = $row[5];
- $user["mort"] = $row[6];
+ $user["curs"] = (int)$row[2];
+ $user["grau"] = (int)$row[3];
+ $user["quimata"] = (int)$row[4];
+ $user["requested"] = (int)$row[5];
+ $user["mort"] = (int)$row[6];
$user["md5password"] = $row[7];
}