-
Notifications
You must be signed in to change notification settings - Fork 0
/
diary.php
196 lines (163 loc) · 5.37 KB
/
diary.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
if (isset($_POST["del"])) {
require "pdo.php";
$sno = $_POST["sno"];
$sql = "delete from blogs.blogs where sno= $sno";
$stmt = $pdo->prepare($sql);
$stmt->execute();
echo $sno;
exit();
}
if(isset($_POST["edit"]))
{
require "pdo.php";
$sno = $_POST["sno"];
$title=$_POST["title"];
$content=$_POST["content"];
$sql = "Update blogs.blogs set title= :title, content =:content where sno= :sno";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
":title"=>$title,
":content"=>$content,
":sno"=>$sno
));
// echo $sno;
header("Location:diary.php");
return;
}
include "header.php";
session_start();
?>
<link rel="stylesheet" href="style/diary.css">
</link>
<?php if (isset($_SESSION["account"])) {
require "pdo.php";
$user = $_SESSION["account"];
$sql = "select * from blogs.blogs where user= :user ORDER BY SNO desc";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(":user" => $user));
echo '<div class="main">
<div class=" sub">';
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
?><div class="card" id="card<?= $row['sno']; ?>">
<div class="button">
<?php
$arr1 = array(
"sno" => $row["sno"],
"title" => ($row['title'])
);
$var =json_encode($arr1,JSON_HEX_APOS);
?>
<input type="button" value="Delete" onclick='func(<?php echo $var; ?>)' />
<?php
$arr = array(
"sno" => $row["sno"],
"title" => ($row['title']),
"content" => $row['content']
);
$var2 = json_encode($arr,JSON_HEX_APOS);
?>
<input type="button" value="Edit" onclick=' edit(<?= $var2 ?> )' />
</div>
<H3><?= htmlentities($row["title"]);
?></H3>
<div><?= htmlentities($row["content"]);
?></div>
</div>
<?php
} ?>
</div>
</div>
<div class="overlay hidden" id="overlay">
<div id="cancel"><button onclick=' canc()'><img src=" assets/cancel.jpg"></button>
</div>
<form action="diary.php" method="post" style="display:inline-grid;position:fixed; top:40%; left:30%">
<label>Title</label>
<input type="hidden" name="sno" id="sno" value="">
<input type=" text" name="title" id="title" value="">
<label>Content</label>
<textarea name="content" cols="30" rows="10" id="content">
</textarea>
<input type="submit" name="edit" value="Edit">
<button onclick=' canc()'>Cancel
</form>
</div>
<a href=" insert.php" class="insert"><img src=" assets/plus.gif" /></a>
?>
<div class="profile">
<h1 style="
color: white;
">HELLO, <?=htmlentities($_SESSION['account']);?></h1>
Gender
<br>
<input type="radio" name="gender" id="" value="Female" onclick="change('female','male','cute' )">Female
<input type="radio" name="gender" id="" value="Male" onclick="change('male','female','cute' )">Male
<input type="radio" name="gender" id="" value="notsay" onclick="change('cute','male','female' )" checked>Rather not
say
<div id="female" class="hidden"><img src="assets/female.png" />
</div>
<div id="male" class="hidden"><img src="assets/male.png" /> </div>
<div id="cute" class=""><img src="assets/cute.png" width="80%" /> </div>
</div>
<?php
?><?php
} else {
header("Location:login.php");
exit();
}
?><?php include "footer.php";
?><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function change(a, b, c) {
console.log(a, b, c);
document.getElementById(a).classList.remove("hidden");
document.getElementById(b).classList.add("hidden");
document.getElementById(c).classList.add("hidden");
}
function func(arr) {
let sno = JSON.parse(JSON.stringify(arr["sno"]));
let title = JSON.parse(JSON.stringify(arr["title"]));
console.log(sno);
let ans = confirm("Are you sure you want to delete the blog: " + title);
console.log(ans);
let del = true;
if (ans == true) {
$.ajax({
url: ' diary.php',
type: 'post',
data: {
del: del,
sno: sno
},
success: function(response) {
{
document.getElementById(`card${sno}`).style.display = "none"; //
// console.log(document.getElementById(`card${sno}`).classList);
console.log(response);
}
}
});
}
}
function edit(arr) {
let cont = document.getElementById("content");
console.log(arr);
document.getElementById("overlay")
.classList.remove('hidden');
var a = arr["title"];
a = JSON.parse(JSON.stringify(a));
var search = "\\";
// a = a.replaceAll(search, "");
document.getElementById("title").value = a;
var b = arr["content"];
b = JSON.parse(JSON.stringify(b));
// b = b.replaceAll(search, "");
cont.textContent = b;
document.getElementById("sno").value = arr["sno"];
}
function canc() {
document.getElementById("content").textContent = "";
document.getElementById("overlay").classList.add("hidden");
}
</script><?php include "footer.php";
?>