150 lines
3.4 KiB
PHP
150 lines
3.4 KiB
PHP
<?php
|
|
include "db.php";
|
|
session_start();
|
|
$username = $_SESSION["user"];
|
|
$id = $_SESSION["id"];
|
|
|
|
if(isset($_POST['submit'])) {
|
|
session_destroy();
|
|
header("Location:kirjaudu.php");
|
|
}
|
|
|
|
$stmt = $mysqli ->prepare("SELECT usersname FROM users WHERE idusers = ? AND usersname = ? ");
|
|
$stmt -> bind_param("ss",$id,$username);
|
|
$stmt -> execute();
|
|
$result = $stmt->get_result();
|
|
$stmt->store_result();
|
|
|
|
|
|
|
|
if ($row = $result->fetch_assoc()) {
|
|
// Verify the submitted password against the securely hashed password in DB
|
|
$checkuser=$row["usersname"];
|
|
}
|
|
else
|
|
{echo("warning");}
|
|
|
|
$customer=htmlspecialchars($_GET["kuvat"]);
|
|
|
|
if($customer === $checkuser){
|
|
$stmt = $mysqli ->prepare("SELECT imagesurls,imagesname FROM images WHERE imagesusers = ? ");
|
|
$stmt -> bind_param("s",$customer);
|
|
$stmt -> execute();
|
|
$result = $stmt->get_result();
|
|
$images = array();
|
|
while($row = mysqli_fetch_assoc($result)){
|
|
$images[] = $row;
|
|
}
|
|
|
|
}else{echo("warning");
|
|
exit;}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="stylesheet" type="text/css" href="styles/style.css">
|
|
<link rel="icon" type="image/x-icon" href="styles/Modify_logo_valkoinen.png">
|
|
<title>Document</title>
|
|
</head>
|
|
<header>
|
|
<div class="headerDiv kuvatHeaderDiv">
|
|
<form action="" method="post">
|
|
<input type="submit" name="submit" value="Kirjaudu ulos">
|
|
</form>
|
|
|
|
</div>
|
|
</header>
|
|
<body >
|
|
|
|
<?php foreach($images as $picture): ?>
|
|
<div class="imagesDiv" onclick='add("<?php echo($picture["imagesname"]) ?>", this)'>
|
|
<img style=""src="<?php echo($picture["imagesurls"]); ?>" alt="" >
|
|
<p><?php echo($picture["imagesname"]);?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<input type="submit" value="Tilaa" onclick="send()" >
|
|
|
|
</body>
|
|
</html>
|
|
<script>
|
|
let arr = [];
|
|
|
|
|
|
function add(name, elem){
|
|
|
|
|
|
|
|
|
|
|
|
if(elem.classList.contains("active")){
|
|
console.log("--|--");
|
|
for(i = 0 ; i < elem.classList.length; i ++){
|
|
console.log(elem.classList[i]);
|
|
if(elem.classList[i] == "active"){
|
|
elem.classList.remove("active");
|
|
}
|
|
}
|
|
}else{
|
|
|
|
elem.classList.add("active");
|
|
}
|
|
|
|
if (arr.includes(name)) {
|
|
arr = arr.filter(item => item !== name);
|
|
} else {
|
|
arr.push(name);
|
|
}
|
|
|
|
console.log(arr);
|
|
|
|
}
|
|
|
|
function send(){
|
|
var dataToSend = "variableName=" + arr;
|
|
|
|
// Prepare the data to send
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
// Create a new XMLHttpRequest object
|
|
xhr.open("POST", "order.php", true);
|
|
|
|
// Specify the request method, PHP script URL, and asynchronous
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
// Set the content type
|
|
xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
|
|
// Check if the request is complete
|
|
if (xhr.status === 200) {
|
|
|
|
// Check if the request was successful
|
|
console.log(xhr.responseText);
|
|
|
|
|
|
// Output the response from the PHP script
|
|
} else {
|
|
console.error("Error:", xhr.status);
|
|
// Log an error if the request was unsuccessful
|
|
}
|
|
|
|
}
|
|
arr = [];
|
|
let removeClass = document.getElementsByClassName("active");
|
|
for(i=0; i<removeClass.length; i++){
|
|
removeClass[i].classList.remove("active");
|
|
}
|
|
|
|
}
|
|
;
|
|
xhr.send(dataToSend);
|
|
}
|
|
</script>
|