generated from EnseirbTelecom/ProgrammationWeb2020Template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_friends.php
124 lines (104 loc) · 4.76 KB
/
add_friends.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
<?php
// $ttl = 3600; // Une heure, en secondes
// session_set_cookie_params($ttl);
// ini_set('session.gc_maxlifetime', $ttl);
session_start();
include("functions.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="../it103/carnet_amis.css">
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</head>
<body>
<title> Statut de l'ajout d'ami </title>
<?php
$link = mysqli_connect('localhost', 'admin', 'it103','Dubnation');
if (!$link) {
echo "Probleme de connexion";
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully ';
$pseudo_1 = $_SESSION["pseudo"];
//echo $pseudo_1;
$Requete = mysqli_query($link,"SELECT userid FROM user WHERE pseudo = \"$pseudo_1\";");
$result = mysqli_fetch_all($Requete, MYSQLI_ASSOC);
//echo $result[0]["userid"];
$_SESSION["userid"] = $result[0]["userid"];
//echo $_SESSION["userid"];
$user_con = $result[0]["userid"];
//echo $_SESSION["userid"];
///////////////
// Toutes les relations d'amis en lien avec le user connecté
$Requete_1 = mysqli_query($link,"SELECT * FROM Reach_my_friend WHERE id_username_1 = \"$user_con\" OR id_username_2 = \"$user_con\";");
$result_1 = mysqli_fetch_all($Requete_1, MYSQLI_ASSOC);
//var_dump($result_1);
$Requete_5 = mysqli_query($link, "SELECT pseudo FROM user");
$result_5 = mysqli_fetch_all($Requete_5, MYSQLI_ASSOC);
$user_global[] = $_SESSION["pseudo"];
/////////////
if ($_SESSION["pseudo"]){
$user_check[]=$_SESSION["pseudo"];
//var_dump($user_check);
}
$condition=0;
if (isset($_POST["friends_name"])){
if (empty($_POST["friends_name"])){
echo "Veuillez rentrer le pseudo de l'ami que vous voulez ajouter";
}
// if ($_POST["friends_name"]=$_SESSION["pseudo"]){
// echo "Vous ne pouvez pas vous ajouter";
// }
for ($i=0; $i<sizeof($result_1) ; $i++) {
if ($result_1[$i]["id_username_1"] == $_SESSION["userid"]) {
$friend = $result_1[$i]["id_username_2"];
$Requete_2 = mysqli_query($link,"SELECT first_name, last_name, pseudo FROM user WHERE userid = \"$friend\";");
$result_2 = mysqli_fetch_all($Requete_2, MYSQLI_ASSOC);
$user_check[]=$result_2[0]["pseudo"];
}
if ($result_1[$i]["id_username_2"] == $_SESSION["userid"]) {
$friend_bis = $result_1[$i]["id_username_1"];
$Requete_3 = mysqli_query($link,"SELECT userid, first_name, last_name, pseudo FROM user WHERE userid = \"$friend_bis\";");
$result_3 = mysqli_fetch_all($Requete_3, MYSQLI_ASSOC);
//var_dump($result_3);
$user_check[]=$result_3[0]["pseudo"];
}
}
for ($i=1; $i <sizeof($result_5) ; $i++) {
$user_global[]=$result_5[$i]["pseudo"];
}
//var_dump($user_global);
if (!in_array($_POST["friends_name"],$user_global)){
echo "Cet utilisateur n'existe pas sur Debster";
exit();
}
//var_dump($user_check);
if (in_array($_POST["friends_name"],$user_check)) {
echo "C'est déjà votre ami !";
}
else {
$condition+=1;
$friend_added=$_POST["friends_name"];
$Requete_finale = mysqli_query($link,"SELECT userid FROM user WHERE pseudo = \"$friend_added\";");
$result_final = mysqli_fetch_all($Requete_finale, MYSQLI_ASSOC);
//echo $result_final[0]["userid"];
if ($condition == 1 ){
addfriendship($_SESSION["userid"],$result_final[0]["userid"],$link);
echo "Ajout réussi";
}
}
}
?>
<form method="link" action="carnet_amis.php"> <input type="submit" value="Retour au carnet d'amis" id="submit"> </form>
<form method="link" action="myprofile.php"> <input type="submit" value="Retour à l'accueil" id="submit"> </form>
</body>
</html>