This commit is contained in:
adri 2018-12-30 17:41:15 +01:00
commit cf68cb8d93
5 changed files with 200 additions and 0 deletions

8
config.php Normal file
View File

@ -0,0 +1,8 @@
<?php
return array(
'host' => 'localhost',
'username' => 'adri',
'pw' => '',
'dbName' => 'projetphp',
);
?>

63
index.php Executable file
View File

@ -0,0 +1,63 @@
<?php
try {
$config = include('config.php');
$bdd = new PDO('mysql:host='.$config['host'].';dbname='.$config['dbName'].';charset=utf8', $config['username'], $config['pw']);
} catch (Exception $e) {
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM projetphp');
?>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!-- somme features-->
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js" integrity="sha256-KsRuvuRtUVvobe66OFtOQfjP8WA2SzYsmm4VPfMnxms=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--My features-->
<link rel="stylesheet" href="style.css?<?php echo date('l jS \of F Y h:i:s A'); ?>">
<script src="script.js?<?php echo date('l jS \of F Y h:i:s A'); ?>"></script>
</head>
<body>
<table id="allRecord">
<thead>
<tr>
<th>login</th>
<th>Date de nésance</th>
<th>email</th>
<th>PW</th>
<th>slvl</th>
<th><i class="fas fa-cogs"></i></th>
</tr>
</thead>
<tbody>
<?php
while($data = $reponse->fetch())
{
?>
<tr class="record">
<td class="login">
<?= htmlspecialchars($data["login"]) ?></td>
<td class="datene">
<?= htmlspecialchars($data["date_naissance"]) ?></td>
<td class="email">
<?= htmlspecialchars($data["e_mail"]) ?></td>
<td class="pw">
<?= htmlspecialchars($data["mot_de_passe"]) ?></td>
<td class="sl">
<?= htmlspecialchars($data["security_level"]) ?></td>
<td><i class="fas fa-edit click editUser"></i><i class="fas fa-trash-alt click delUser"></i></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>

40
post.php Normal file
View File

@ -0,0 +1,40 @@
<?php
$ret["return"] = false;
$ret["pw"] = null;
try {
$config = include('config.php');
$bdd = new PDO('mysql:host='.$config['host'].';dbname='.$config['dbName'].';charset=utf8', $config['username'], $config['pw']);
} catch (Exception $e) {
die('Erreur : '.$e->getMessage());
}
//UPDATE `projetphp` SET `security_level` = '6' WHERE `projetphp`.`login` = 'aaazzze';
if(isset($_POST["updatePW"], $_POST["datene"], $_POST["email"], $_POST["pw"], $_POST["sl"], $_POST["login"]))
if($_POST["updatePW"] == "true")
{
$req = $bdd->prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `mot_de_passe` = :pw, `security_level` = :sl WHERE `projetphp`.`login` = :login');
$req->execute(array(
'datene' => $_POST["datene"],
'email' => $_POST["email"],
'pw' => md5($_POST["pw"]),
'sl' => $_POST["sl"],
'login' => $_POST["login"],
));
$ret["return"] = true;
$ret["pw"] = md5($_POST["pw"]);
}
else
{
$req = $bdd->prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `security_level` = :sl WHERE `projetphp`.`login` = :login');
$req->execute(array(
'datene' => $_POST["datene"],
'email' => $_POST["email"],
'sl' => $_POST["sl"],
'login' => $_POST["login"],
));
$ret["return"] = true;
$ret["pw"] = $_POST["pw"];
}
else;
echo json_encode((object)$ret);
?>

85
script.js Normal file
View File

@ -0,0 +1,85 @@
$(function() {
$("#allRecord").on("click", ".editUser", function() {
$(this).toggleClass('fa-edit fa-check');
$(this).toggleClass('editUser confirmEditUser');
for(i=0; i<$("td", $(this).parent().parent()).length-1;i++)
{
j= $($("td", $(this).parent().parent())[i]);
j.html('<input '+(j.attr('class')=="pw"?'type="password" \
data-oldpw="'+ltrim(j.html())+'"':'type="text"')+'\
value="'+(j.attr('class')=="pw"?'':ltrim(j.html()))+'" />');
}
});
$("#allRecord").on("click", ".confirmEditUser", function() {
function callBackVerif(data){
var dataToSend = new Object();
dataToSend["updatePW"] = (data===true?false:true);
if($(".pw input", tr).val() === data || data === true)
{
for(i=0; i<tds.length-1;i++)
{
j= $(tds[i]);
className = j.attr('class');
if(className == "pw")
value = $('input', j).data("oldpw");
else
value = $('input', j).val();
dataToSend[className] = value;
}
$.post("post.php", dataToSend, function(data){
try {
if(data.return == true)
{
for(i=0; i<tds.length-1;i++)
{
j= $(tds[i]);
className = j.attr('class');
if(className == "pw")
value = data.pw;
else
value = $('input', j).val();
dataToSend[className] = value;
j.html(value);
}
swal("all done");
$(that).toggleClass('fa-check fa-edit');
$(that).toggleClass('confirmEditUser editUser');
}
else
swal(data);
} catch (e) {
swal( "Oops" , "Something went wrong!<br>"+e , "error" );
}
console.log(data.return)
}, "json");
}
else {
swal( "Oops" , "Password don't match !" , "error" );
}
}
tds = $("td", $(this).parent().parent());
tr = $(this).parent().parent();
that = this;
if ($(".pw input", tr).val() === "") {
swal("no pw update");
callBackVerif(true);
}
else {
swal({
closeOnClickOutside: false,
closeOnEsc: false,
content: {
element: "input",
attributes: {
placeholder: "Confirmer le mot de passe",
type: "password",
},
},
}).then(callBackVerif);
}
});
});
function ltrim(str) {
if(str == null) return str;
return str.replace(/^\s+/g, '');
}

4
style.css Normal file
View File

@ -0,0 +1,4 @@
.click:hover
{
cursor: pointer;
}