-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvoting.php
More file actions
70 lines (55 loc) · 1.87 KB
/
voting.php
File metadata and controls
70 lines (55 loc) · 1.87 KB
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
<?php
session_start();
$postId=$_GET['postid'];
$type=$_GET['type'];
$nums=$_GET['nums']*1;
$username=$_SESSION['username'];
$con=new MongoClient();
$db=$con->admin_panel;
$record=$db->all_posts->findOne(array("post_Id"=>$postId));
$postId=$record["post_Id"];
$author=$record["author"];
$title=$record["title"];
$time=$record["time"];
$post_Content=$record["post_Content"];
$upvotes=$record["upvotes"];
$downvotes=$record["downvote"];
$usercon=new MongoClient();
$dbuser=$usercon->$username;
if($type == "upvote")
{
$upvotes=$nums*1;
$votediff=($upvotes - $downvotes)*1;
$modified=array("post_Id" => $postId, "author" => $author, "title" => $title, "time" => $time, "post_Content" => $post_Content, "upvotes" => $upvotes, "downvote" => $downvotes);
$que=$db->all_posts->update(array("post_Id"=>$postId), $modified);
$modified2=array("post_Id" => $postId, "vote_diff" => $votediff);
$que=$db->votecount->update(array("post_Id" => $postId), $modified2);
$query= $dbuser->upvoted->findOne(array("post_Id" => $postId));
if(!$query)
{
$dbuser->upvoted->insert(array("post_Id" => $postId));
}
else
{
$dbuser->upvoted->remove(array("post_Id" => $postId));
}
}
else if ($type =="downvote")
{
$downvotes=$nums*1;
$votediff=($upvotes - $downvotes)*1;
$modified=array("post_Id" => $postId, "author" => $author, "title" => $title, "time" => $time, "post_Content" => $post_Content, "upvotes" => $upvotes, "downvote" => $downvotes);
$que=$db->all_posts->update(array("post_Id"=>$postId), $modified);
$modified2=array("post_Id" => $postId, "vote_diff" => $votediff);
$que=$db->votecount->update(array("post_Id" => $postId), $modified2);
$query= $dbuser->downvoted->findOne(array("post_Id" => $postId));
if(!$query)
{
$dbuser->downvoted->insert(array("post_Id" => $postId));
}
else
{
$dbuser->downvoted->remove(array("post_Id" => $postId));
}
}
?>