forked from HSJared/Social-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addfriend.php
75 lines (68 loc) · 2.33 KB
/
addfriend.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
<?php
//Include MySQL config info
include("config.php");
//Kick out users who are not logged in
include("authen.php");
//Library of Friend Functions
include("friendingfunctions.php");
//Check to see if user requested exists
$userid = intval($_GET['id']);
$loginquery="SELECT * FROM login WHERE userid='$userid'";
$loginresult=mysql_query($loginquery);
if (!mysql_num_rows($loginresult))
{
header("location: 404.php"); //If not redirect
}
$myuserid = $_SESSION['userid'];
//Get the current relation status
$f = friendStatus($userid,$myuserid);
//Based on this relation status, do what is appriopate.
switch ($f)
{
/****relations table:
0 = userid1 requested by userid2
1 = Nothing, held in reserve for follow feature later on
2 = friends with eachother
3 = userid1 blocked by userid2
*****/
case 0:
{ //This completes a friend request
$requestquery="insert into relations(userid1, userid2, relation) values('$userid','$myuserid','0')";
$result=mysql_query($requestquery,$conc) or die("Unable to send friend request");
header("location: profile.php?id=$userid"); //Redirect back to user's profile
}
break;
case 3:
{ //Since the other user has requested the logged in user, we can just convert this request into a friend request.
$addquery="Update relations SET relation=2 WHERE userid1='$myuserid' and userid2='$userid';";
$result=mysql_query($addquery,$conc) or die("Unable to send friend request");
header("location: profile.php?id=$userid"); //Redirect back to user's profile
}
case 2:
{
include("head.php");
include("navtop.php");
echo "<h2 align=\"center\" class=\"err\">You have already requested this user! You may only send one request!<br />";
echo "<button onclick=\"goHome()\">Click here to go back to the homepage</button>";
include ('footer.php');
}
break;
case 1:
{
include("head.php");
include("navtop.php");
echo "<h2 align=\"center\" class=\"err\">You are already friends with this user!<br />";
echo "<button onclick=\"goHome()\">Click here to go back to the homepage</button>";
include ('footer.php');
}
break;
case -1:
{
include("head.php");
include("navtop.php");
echo "<h2 align=\"center\" class=\"err\">You can not add yourself as a friend!<br />";
echo "<button onclick=\"goHome()\">Click here to go back to the homepage</button>";
include ('footer.php');
}
break;
}