Andreu | 78e5bb0 | 2019-09-22 13:38:04 +0200 | [diff] [blame] | 1 | <?php |
| 2 | require './credentials.php'; |
| 3 | require './php/utils.php'; |
Andreu | 0d0f9fd | 2019-09-23 03:56:08 +0200 | [diff] [blame] | 4 | |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 5 | $credentials = new Credentials(); |
| 6 | $usersdb = $credentials->usersdb; |
| 7 | $mortsdb = $credentials->mortsdb; |
| 8 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 9 | date_default_timezone_set("Europe/Berlin"); |
| 10 | |
| 11 | $user = $_COOKIE['user']; // (int)$_POST['user']; |
| 12 | $password = $_COOKIE['password']; // isset($_POST['password']) ? md5($_POST['password']) : ''; |
Andreu | 4b2fbd9 | 2019-09-22 22:30:25 +0200 | [diff] [blame] | 13 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 14 | if (!isset($_COOKIE['user']) or $_COOKIE['user'] == '') { |
| 15 | die("<script>window.location.href = './'</script>"); |
| 16 | } else if (isset($_COOKIE['password'])) { |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 17 | $query_password = "SELECT password FROM $usersdb WHERE id=$user"; |
Andreu | a0fc827 | 2019-09-23 00:35:25 +0200 | [diff] [blame] | 18 | if (query($query_password)->fetch_row()[0] != $password) { |
Andreu | 78e5bb0 | 2019-09-22 13:38:04 +0200 | [diff] [blame] | 19 | // Unset variables |
| 20 | setcookie('user', '', -1, "/"); |
| 21 | setcookie('password', '', -1, "/"); |
| 22 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 23 | die("<script>window.location.href = './?passwordchanged=1'</script>"); |
Andreu | 78e5bb0 | 2019-09-22 13:38:04 +0200 | [diff] [blame] | 24 | } |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 25 | } |
| 26 | ?> |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 27 | <html> |
| 28 | <head> |
| 29 | <meta charset="UTF-8"> |
Andreu | 0d0f9fd | 2019-09-23 03:56:08 +0200 | [diff] [blame] | 30 | <title>PastanagAPP</title> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 31 | |
| 32 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
Andreu | 0d0f9fd | 2019-09-23 03:56:08 +0200 | [diff] [blame] | 33 | <link rel="manifest" href="https://api.myjson.com/bins/u6r41"> |
| 34 | |
| 35 | <!-- Apple web app --> |
| 36 | <link rel="apple-touch-icon" href="./bin/images/icons/icon-72x72.png"> |
| 37 | <meta name="apple-mobile-web-app-title" content="PastanagAPP"> |
| 38 | <meta name="apple-mobile-web-app-capable" content="yes"> |
| 39 | <meta name="apple-mobile-web-app-status-bar-style" content="green"> |
| 40 | |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 41 | |
Andreu | 4b2fbd9 | 2019-09-22 22:30:25 +0200 | [diff] [blame] | 42 | <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" /> |
| 43 | |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 44 | <link rel="stylesheet" href="./css/basic.css" /> |
| 45 | <link rel="stylesheet" href="./css/main.css" /> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 46 | |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 47 | <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> |
Andreu | ed8e1f9 | 2019-09-18 22:26:04 +0200 | [diff] [blame] | 48 | <script src="https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js"></script> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 49 | |
Andreu | 10cb304 | 2019-09-18 19:55:36 +0200 | [diff] [blame] | 50 | <script src="./js/utils.js"></script> |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 51 | <script src="./js/animations.js"></script> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 52 | |
| 53 | <?php |
Andreu | a0fc827 | 2019-09-23 00:35:25 +0200 | [diff] [blame] | 54 | $user = get_users($user); |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 55 | $victim = get_users($user->quimata); |
Andreu | 0530b30 | 2019-09-24 04:18:20 +0200 | [diff] [blame] | 56 | if ($user->mort) die("<script>window.location.href = './dead.php'</script>"); |
Andreu | 779c3b7 | 2019-09-24 03:14:35 +0200 | [diff] [blame] | 57 | |
| 58 | $bits = dec2bits($user->bits); |
| 59 | $bit_counter = 0; |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 60 | ?> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 61 | |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 62 | <script> |
Andreu | ed49167 | 2019-09-20 13:09:18 +0200 | [diff] [blame] | 63 | let user = { |
Andreu | 9950105 | 2019-09-22 20:09:08 +0200 | [diff] [blame] | 64 | 'id': <?=(int)$user->id?>, |
| 65 | 'quimata': <?=(int)$user->quimata?>, |
| 66 | 'requested': <?=(int)$user->requested?>, |
| 67 | 'mort': <?=(int)$user->mort?>, |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 68 | |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 69 | 'nom': "<?=$user->nomcomplet?>", |
Andreu | 9950105 | 2019-09-22 20:09:08 +0200 | [diff] [blame] | 70 | 'curs': <?=(int)$user->curs?>, |
| 71 | 'grau': <?=(int)$user->grau?> |
Andreu | ed49167 | 2019-09-20 13:09:18 +0200 | [diff] [blame] | 72 | }; |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 73 | </script> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 74 | |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 75 | </head> |
| 76 | <body> |
| 77 | <div id="outter-container"> |
| 78 | <div id="inner-container"> |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 79 | <a href="./" class="goback">Canvi d'usuari</a><br /> |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 80 | <h2>Hola <name id="user_name"><?=$user->nom()?></name>,</h2> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 81 | |
Andreu | 4b2fbd9 | 2019-09-22 22:30:25 +0200 | [diff] [blame] | 82 | <div class="formulari_contrasenya"> |
Andreu | a0fc827 | 2019-09-23 00:35:25 +0200 | [diff] [blame] | 83 | <p>Sembla que no tens clau d'accés, la gent podrà entrar al teu compte...</p> |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 84 | <form action="./php/change_password.php" method="POST"> |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 85 | <input type="hidden" value="<?=$user->id?>" name="userid"> |
Andreu | 543e70c | 2019-09-22 14:08:49 +0200 | [diff] [blame] | 86 | <input type="password" placeholder="Nova clau d'accés..." name="password" /><br /> |
| 87 | <input type="password" placeholder="Repeteix la clau d'accés" name="confirmation"/><br /> |
Andreu | 4b2fbd9 | 2019-09-22 22:30:25 +0200 | [diff] [blame] | 88 | <input type="submit" value="Posar clau d'accés"> |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 89 | </form> |
| 90 | </div> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 91 | |
| 92 | <p>La teva víctima és:</p> |
| 93 | |
Andreu | 04f79ef | 2019-09-22 18:52:19 +0200 | [diff] [blame] | 94 | <div class="victima"> |
| 95 | <table> |
| 96 | <tr> |
Andreu | 779c3b7 | 2019-09-24 03:14:35 +0200 | [diff] [blame] | 97 | <td class="table_img"> |
| 98 | <div id="victim_img"> |
Andreu Huguet | f133417 | 2020-09-15 17:29:22 +0200 | [diff] [blame] | 99 | <div class="grid-container"> |
| 100 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 101 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 102 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 103 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 104 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 105 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 106 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 107 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 108 | <div class="grid-item <?=(int)$bits[$bit_counter++] ? 'black' : ''?>"></div> |
| 109 | </div> |
Andreu | 779c3b7 | 2019-09-24 03:14:35 +0200 | [diff] [blame] | 110 | </div> |
| 111 | </td> |
Andreu | 0d0f9fd | 2019-09-23 03:56:08 +0200 | [diff] [blame] | 112 | <td class="table_text"> |
Andreu | 04f79ef | 2019-09-22 18:52:19 +0200 | [diff] [blame] | 113 | <div id="victim_name"><?=$victim->nomcomplet?></div> |
| 114 | <div id="victim_curs_i_grau"> |
Andreu | 4b2fbd9 | 2019-09-22 22:30:25 +0200 | [diff] [blame] | 115 | <span id="victim_curs"><?=$victim->nomcurs()?></span> |
Andreu | 04f79ef | 2019-09-22 18:52:19 +0200 | [diff] [blame] | 116 | - |
Andreu | 4b2fbd9 | 2019-09-22 22:30:25 +0200 | [diff] [blame] | 117 | <span id="victim_grau"><?=$victim->nomgrau()?></span> |
Andreu | 04f79ef | 2019-09-22 18:52:19 +0200 | [diff] [blame] | 118 | </div> |
| 119 | <div id="butons" class="options"> |
| 120 | <button id="win" onclick="js: send_request(user, 'REQ KILL');">L'he matat</button> |
| 121 | </div> |
| 122 | </td> |
| 123 | </tr> |
| 124 | </table> |
| 125 | </div> |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 126 | |
Andreu Huguet | 6a633f2 | 2020-09-15 18:07:15 +0200 | [diff] [blame] | 127 | <div id="message-board"> |
Andreu Huguet | 73fd1bc | 2020-09-15 19:21:05 +0200 | [diff] [blame] | 128 | <h1>L'atacat</h1> |
| 129 | <div id="messages-sent"> |
| 130 | <?php |
| 131 | // Create connection |
| 132 | $credentials = new Credentials(); |
| 133 | $conn = new mysqli($credentials->servername, $credentials->username, $credentials->password, $credentials->dbname); |
| 134 | if ($conn->connect_error) die("Connection failed: " . $conn->connect_error); |
| 135 | $conn->set_charset("utf8"); |
| 136 | |
| 137 | // Execute query and save result |
| 138 | $query_msgs = "SELECT * FROM `missatges` WHERE (`sender_id` = ".$user->id." AND `receiver_id` = ".$user->quimata . |
| 139 | ") OR (`sender_id` = ".$user->quimata." AND `receiver_id` = ".$user->id . ")"; |
| 140 | $result = $conn->query($query_msgs); |
| 141 | |
| 142 | while($res = $result->fetch_row()) { |
Andreu Huguet | c273a86 | 2020-09-15 19:41:39 +0200 | [diff] [blame] | 143 | if ($res[1] == $user->id) { |
Andreu Huguet | b9e26c8 | 2020-09-15 19:48:27 +0200 | [diff] [blame^] | 144 | echo "<div class='from-me'><div class='msg-content'>$res[4]</div><div class='meta-data'><span class='timestamp'>$res[3]</span><span class='seen'>".($res[5] == 0 ? 'New' : '')."</span></div></div>"; |
Andreu Huguet | c273a86 | 2020-09-15 19:41:39 +0200 | [diff] [blame] | 145 | } else { |
Andreu Huguet | b9e26c8 | 2020-09-15 19:48:27 +0200 | [diff] [blame^] | 146 | echo "<div class='to-me'><div class='msg-content'>$res[4]</div><div class='meta-data'><span class='timestamp'>$res[3]</span><span class='seen'>".($res[5] == 0 ? 'New' : '')."</span></div></div>"; |
Andreu Huguet | c273a86 | 2020-09-15 19:41:39 +0200 | [diff] [blame] | 147 | } |
Andreu Huguet | 73fd1bc | 2020-09-15 19:21:05 +0200 | [diff] [blame] | 148 | } |
| 149 | ?> |
| 150 | </div> |
Andreu Huguet | dd3ae82 | 2020-09-15 18:27:51 +0200 | [diff] [blame] | 151 | <form action="./php/send_thread.php" method="POST"> |
Andreu Huguet | 92c6e0d | 2020-09-15 18:15:40 +0200 | [diff] [blame] | 152 | <input type="text" name="msg-content" placeholder="Que es cagui de por" /> |
| 153 | <input type="hidden" name="killer-id" value="<?=(int)$user->id?>"> |
| 154 | <input type="hidden" name="victim-id" value="<?=(int)$user->quimata?>"> |
Andreu Huguet | 6a633f2 | 2020-09-15 18:07:15 +0200 | [diff] [blame] | 155 | <input type="submit" value="Enviar amenaça" /> |
| 156 | </form> |
Andreu Huguet | 73fd1bc | 2020-09-15 19:21:05 +0200 | [diff] [blame] | 157 | <h1>L'atacant</h1> |
| 158 | <div id="messages-sent"> |
| 159 | <?php |
| 160 | $query_quielmata = "SELECT id FROM pastanaga WHERE quimata = " . $user->id; |
| 161 | $quielmata = $conn->query($query_quielmata)->fetch_row()[0]; |
| 162 | |
| 163 | // Execute query and save result |
| 164 | $query_msgs = "SELECT * FROM `missatges` WHERE (`sender_id` = ".$user->id." AND `receiver_id` = ".$quielmata . |
| 165 | ") OR (`sender_id` = ".$quielmata." AND `receiver_id` = ".$user->id . ")"; |
| 166 | $result = $conn->query($query_msgs); |
| 167 | |
| 168 | while($res = $result->fetch_row()) { |
Andreu Huguet | c273a86 | 2020-09-15 19:41:39 +0200 | [diff] [blame] | 169 | if ($res[1] == $user->id) { |
Andreu Huguet | b9e26c8 | 2020-09-15 19:48:27 +0200 | [diff] [blame^] | 170 | echo "<div class='from-me'><div class='msg-content'>$res[4]</div><div class='meta-data'><span class='timestamp'>$res[3]</span><span class='seen'>".($res[5] == 0 ? 'New' : '')."</span></div></div>"; |
Andreu Huguet | c273a86 | 2020-09-15 19:41:39 +0200 | [diff] [blame] | 171 | } else { |
Andreu Huguet | b9e26c8 | 2020-09-15 19:48:27 +0200 | [diff] [blame^] | 172 | echo "<div class='to-me'><div class='msg-content'>$res[4]</div><div class='meta-data'><span class='timestamp'>$res[3]</span><span class='seen'>".($res[5] == 0 ? 'New' : '')."</span></div></div>"; |
Andreu Huguet | c273a86 | 2020-09-15 19:41:39 +0200 | [diff] [blame] | 173 | } |
Andreu Huguet | 73fd1bc | 2020-09-15 19:21:05 +0200 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
| 177 | // Close the connection |
| 178 | $conn->close(); |
| 179 | ?> |
| 180 | </div> |
| 181 | <form action="./php/send_thread.php" method="POST"> |
| 182 | <input type="text" name="msg-content" placeholder="Demostra que no tens por" /> |
| 183 | <input type="hidden" name="killer-id" value="<?=(int)$user->id?>"> |
| 184 | <input type="hidden" name="victim-id" value="<?=(int)$quielmata?>"> |
| 185 | <input type="submit" value="Respon amenaça" /> |
| 186 | </form> |
Andreu Huguet | 6a633f2 | 2020-09-15 18:07:15 +0200 | [diff] [blame] | 187 | </div> |
| 188 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 189 | <div> |
| 190 | <p>Podeu posar aquesta pàgina com a icona apretant el botó de "Add to Home Screen" del vostre navegador.</p> |
| 191 | <a href="./ranking.php">Anar al rànquing</a> |
| 192 | </div> |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 193 | </div> |
| 194 | </div> |
avm99963 | db383ed | 2019-09-22 02:14:42 +0200 | [diff] [blame] | 195 | |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 196 | <script> |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 197 | $(document).ready(function() { |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 198 | // Set interval of checking |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 199 | let checking = setInterval(function() { update_info(user); }, 1500); |
Andreu | 96f1bcd | 2019-09-22 00:33:09 +0200 | [diff] [blame] | 200 | // Set to hidden or not the password prompt |
Andreu | 543e70c | 2019-09-22 14:08:49 +0200 | [diff] [blame] | 201 | if (<?=$user->md5password=="" ? 1 : 0?>) { |
| 202 | $.notify("No tens clau d'accés", "info"); |
| 203 | $(".formulari_contrasenya").show(); |
| 204 | } |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 205 | // Notify of messages |
| 206 | if (getUrlParameter("wrongconfirmation")) read_message("Les contrasenyes no coincideixen", "error"); |
| 207 | if (getUrlParameter("errordb")) read_message("Hi ha hagut un problema a la base de dades, torna-ho a intentar", "error"); |
| 208 | if (getUrlParameter("successpassword")) read_message("La teva clau d'accés s'ha guardat", "success"); |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 209 | }); |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 210 | </script> |
| 211 | </body> |
| 212 | </html> |