-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaction.php
79 lines (64 loc) · 2.52 KB
/
action.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
<?php
include'core/init.php';
protect_page();
session_start();
$action= $_GET['action'];
$user=$_GET['user'];//jiska username dala hai
$type=$_GET['type'];//jo type hai
$id=$_GET['id'];//post ka hai
$votes=$_GET['votes'];//no. of votes
$ovotes=$_GET['ovotes'];//no. of votes
$user2=$session_user_id;//jo loggedin hai
$user_data =user_data($user,'first_name','last_name','email','username','profile','enrollment_id','gender','age','type');
if($type=='post'){
if($action=='upvote'){
if(user_post_upvote_exists($user2,$id) === 1){
$con->query("DELETE FROM upvote_post WHERE `who_id`='$user2' AND `post_id`='$id' ");
$votes--;
$queryy="UPDATE `post` SET `post_upvotes`='$votes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryy);
}
else if(user_post_downvote_exists($user2,$id) === 1){
$con->query("DELETE FROM downvote_post WHERE `who_id`='$user2' AND `post_id`='$id' ");
$con->query("INSERT INTO upvote_post VALUES('','$user2','$id' )");
$votes++;
$ovotes--;
$queryy="UPDATE `post` SET `post_upvotes`='$votes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryy);
$queryz="UPDATE `post` SET `post_downvotes`='$ovotes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryz);
}
else{
$con->query("INSERT INTO upvote_post VALUES('','$user2','$id' )");
$votes++;
$queryy="UPDATE `post` SET `post_upvotes`='$votes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryy);
}
}
else if($action=='downvote'){
if(user_post_downvote_exists($user2,$id) === 1){
$con->query("DELETE FROM downvote_post WHERE `who_id`='$user2' AND `post_id`='$id' ");
$votes--;
$queryy="UPDATE `post` SET `post_downvotes`='$votes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryy);
}
else if(user_post_upvote_exists($user2,$id) === 1){
$con->query("DELETE FROM upvote_post WHERE `who_id`='$user2' AND `post_id`='$id' ");
$con->query("INSERT INTO downvote_post VALUES('','$user2','$id' )");
$votes++;
$queryy="UPDATE `post` SET `post_downvotes`='$votes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryy);
$ovotes--;
$queryz="UPDATE `post` SET `post_upvotes`='$ovotes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryz);
}
else{
$con->query("INSERT INTO downvote_post VALUES('','$user2','$id' )");
$votes++;
$queryy="UPDATE `post` SET `post_downvotes`='$votes' WHERE `post_id`='$id' ";
mysqli_query($con,$queryy);
}
}
}
header('location: profile.php?username='.$user_data['username']);
?>