BARRAUX Arthur
3 years ago
7 changed files with 87 additions and 12 deletions
@ -0,0 +1,45 @@ |
|||
<?php |
|||
include '../session_restraintes.php'; |
|||
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', ''); |
|||
$reponse = $bdd->query("SELECT * FROM logins"); |
|||
$arr = []; |
|||
while ($line = $reponse->fetch()) { |
|||
$arr[$line[0]] = $line[1]; |
|||
} |
|||
$reponse->closeCursor(); |
|||
?> |
|||
|
|||
<html> |
|||
<head> |
|||
<?php include 'include/menu.php'; ?> |
|||
<script type="text/javascript" src="js/admin.js" defer></script> |
|||
</head> |
|||
<body> |
|||
<?php include 'include/nav.php'; ?> |
|||
<table> |
|||
<thead> |
|||
<tr> |
|||
<th colspan="3">Mot de passe</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
<tr class='table-title'> |
|||
<td>Login</td> |
|||
<td>Password</td> |
|||
</tr> |
|||
<tr> |
|||
<?php |
|||
foreach ($arr as $key => $value) { |
|||
echo '<tr> |
|||
<td class=',$key,' style="font-weight: bold;">', $key,'</td> |
|||
<td class=',$key,'>', $value,'</td> |
|||
<td class=',$key,'><input class="edit" type="button" value="edit" onclick="Edit(\'',$key,'\')"></td> |
|||
</tr>'; |
|||
} |
|||
?> |
|||
</tr> |
|||
|
|||
</tbody> |
|||
</table> |
|||
</body> |
|||
</html> |
@ -0,0 +1,8 @@ |
|||
<?php |
|||
$decode = json_decode($_POST['value'], TRUE); |
|||
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', ''); |
|||
$update = $bdd->query('UPDATE `logins` SET `pwd` = "' .$decode['pwd'] .'" WHERE `login` = "' .$decode['login'] .'"'); |
|||
|
|||
$traitement = $bdd->query("SELECT * FROM `logins` WHERE `login`= '" .$decode['login'] ."'"); |
|||
print_r(json_encode($traitement->fetch())); |
|||
?> |
@ -0,0 +1,26 @@ |
|||
function Edit(clas) { |
|||
let obj = document.getElementsByClassName(clas); |
|||
let data = new FormData(); |
|||
if (obj[2].querySelector('input').value == 'edit') { |
|||
obj[1].innerHTML = '<input type="text" style="width: 80%;" value="' + obj[1].textContent + '">'; |
|||
obj[2].querySelector('input').value = 'ok'; |
|||
} |
|||
else { |
|||
let value = {}; |
|||
value.login = obj[0].textContent; |
|||
value.pwd = obj[1].querySelector('input').value; |
|||
console.log(value); |
|||
let xhr = new XMLHttpRequest(); |
|||
data.append('value', JSON.stringify(value)); |
|||
xhr.onreadystatechange = function() { |
|||
if (this.readyState == 4 && this.status == 200) { |
|||
console.log(this.response); |
|||
obj[1].innerHTML = this.response[1]; |
|||
obj[2].querySelector('input').value = 'edit'; |
|||
} |
|||
}; |
|||
xhr.open('POST', 'cible/admin.php', true); |
|||
xhr.responseType = 'json'; |
|||
xhr.send(data); |
|||
} |
|||
} |
Loading…
Reference in new issue