-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathview_more.php
171 lines (133 loc) · 5.32 KB
/
view_more.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
<?php
include_once("checkUserLoginStatus.php");
// if(!$user_ok) {
// header("location: $siteAddress/loginpage.php");
// exit();
// }
?>
<?php
if(isset($_POST["elem"])){
// if(isset($_SESSION["userName"])){
// $userName = $_SESSION["userName"];
// }else {
// echo "6578";
// }
$userName = "$log_username";
$elem = $_POST['elem'];
// -------------------------------------------
$sql = "SELECT id FROM like_dislike WHERE imageId='$elem' AND userName='$userName' LIMIT 1";
$query = mysqli_query($connect_db, $sql);
$l_check = mysqli_num_rows($query);
if ($l_check > 0){
$sql = "DELETE FROM `like_dislike` WHERE imageId='$elem' AND userName='$userName' ";
$query = mysqli_query($connect_db, $sql);
$uid = mysqli_insert_id($connect_db);
// echo "You Have Already Liked This Image.";
// echo trim(ob_get_clean());
exit();
}
$sql = "INSERT INTO `like_dislike` (`imageId`,`userName`,`date_time`) VALUES ('$elem','$userName',now())";
$query = mysqli_query($connect_db, $sql);
$uid = mysqli_insert_id($connect_db);
echo "like_success";
echo trim(ob_get_clean());
exit();
}
// <-------------to store downloaded images entry in databse------------>
if(isset($_POST["downloadImage"])){
// if(isset($_SESSION["userName"])){
// $userName = $_SESSION["userName"];
// }else {
// echo "6578";
// }
$userName = "$log_username";
$elem = $_POST['downloadImage'];
// -------------------------------------------
//$sql = "SELECT id FROM like_dislike WHERE imageId='$elem' AND userName='$userName' LIMIT 1";
// $query = mysqli_query($connect_db, $sql);
// $l_check = mysqli_num_rows($query);
// if ($l_check > 0){
// $sql = "DELETE FROM `like_dislike` WHERE imageId='$elem' AND userName='$userName' ";
// $query = mysqli_query($connect_db, $sql);
// $uid = mysqli_insert_id($connect_db);
// // echo "You Have Already Liked This Image.";
// // echo trim(ob_get_clean());
// exit();
$sql = "INSERT INTO `download` (`imageId`,`userName`,`date_time`) VALUES ('$elem','$userName',now())";
$query = mysqli_query($connect_db, $sql);
$uid = mysqli_insert_id($connect_db);
echo "download_success";
echo trim(ob_get_clean());
exit();
}
$select_path="select * from images";
$var=mysqli_query($connect_db,$select_path);
$imageArray = "";
while($row=mysqli_fetch_array($var))
{
$image_name=$row["name"];
$image_path=$row["image"];
$image_id = $row["id"];
$imageArray .= "<img src=".$image_path." height=100><span onclick=\"like_event('$image_id')\" id=\"$image_id\" ><i class=\"material-icons\" >favorite_border</i></span> <a onclick=\"download_event('$image_id')\" id=\"$image_id\" id=\"download\" href=\"$image_path\" download=\"$image_path\">Download</a>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Images</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<a href="main_page.php"><button>home</button></a><br><br>
<!-- <a href="http://localhost/SellMyClick/fetch_image.php?&filter=uploaded" style="padding-right:10px" >recently uploaded images </a>
<a href="http://localhost/SellMyClick/fetch_image.php?&filter=liked" style="padding-right:10px">most liked images </a>
<a href="http://localhost/SellMyClick/fetch_image.php?&filter=topuploaded">Top uploaded images </a><br><br> -->
<div>
<?php echo $imageArray; ?>
</div>
<!-- script -->
<?php include_once("script.php"); ?>
<script>
function like_event(elem)
{
// _("likebtn").style.display = "none";
// status.innerHTML = 'please wait ...';
var ajax = ajaxObj("POST", "view_more.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText != "like_success"){
alert(ajax.responseText);
// status.style.display = "block";
// _("likebtn").style.display = "block";
} else {
_(elem).innerHTML = "<i class=\"material-icons\" style.color=\"#ff0000\" >favorite</i>";
}
}
}
ajax.send("elem="+elem);
}
// <=------------download_event-->
function download_event(elem)
{
// _("likebtn").style.display = "none";
// status.innerHTML = 'please wait ...';
var ajax = ajaxObj("POST", "view_more.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText != "download _success"){
alert(ajax.responseText);
// status.style.display = "block";
// _("likebtn").style.display = "block";
} else {
// _(elem).innerHTML = "<i class=\"material-icons\" style.color=\"#000000\" >favorite</i>";
}
}
}
ajax.send("downloadImage="+elem);
}
</script>
</body>
</html>