YaWK  24.1
Yet another WebKit
unfriend-user.php
Go to the documentation of this file.
1 <?php
2 include '../../system/classes/db.php';
3 include '../../system/classes/sys.php';
4 include '../../system/classes/user.php';
5 include '../../system/classes/alert.php';
6 include '../../system/classes/settings.php';
7 
8 /* set database object */
9 if (!isset($db))
10 { // create new db object
11  $db = new \YAWK\db();
12 }
13 
14 $uid = $_POST['uid'];
15 $hunted = $_POST['hunted'];
16 $userB = $_POST['user'];
17 $userA = \YAWK\user::getUserNameFromID($db, $uid);
18 
19 // check if uid follows hunted already
20 if ($sql = $db->query("SELECT id FROM {friends}
21  WHERE friendA = '".$uid."' AND friendB = '".$hunted."'
22  OR friendA = '".$hunted."' AND friendB = '".$uid."'"))
23 { // if users are friends...
24  $res = mysqli_fetch_row($sql);
25  if ($res[0] === true )
26  { // already friends
27  if ($sql = $db->query("DELETE FROM {friends}
28  WHERE confirmed = '1' AND friendA = '".$uid."' AND friendB = '".$hunted."'
29  OR confirmed = '1' AND friendA = '".$hunted."' AND friendB = '".$uid."'"))
30  { // un-followd with user
31  \YAWK\sys::setSyslog($db, 17, 0, "$userA un-friended $userB.", $uid, $hunted, 0, 0);
32  \YAWK\sys::setNotification($db, 3, 0, "$userA un-friended you.", $uid, $hunted, 0, 0);
33  \YAWK\alert::draw("danger","Disconnected with $userB", "You are not friend with $userB anymore.","",4200);
34  }
35  }
36  else
37  { // user is not in db, follow now:
38  if ($sql = $db->query("INSERT INTO {friends} (friendA, friendB) VALUES ('$uid', '$hunted')"))
39  { // put data into logfile
40  \YAWK\sys::setSyslog($db, 17, 0, "$userA asked $userB for friendship", $uid, $hunted, 0, 0);
41  \YAWK\sys::setNotification($db, 3, 0, "$userA want to be your friend<br>
42  <b><i class=\"fa fa-check-circle-o text-green\"> </i>&nbsp;&nbsp;
43  <i class=\"fa fa-times-circle-o text-red\"> </i></b>", $uid, $hunted, 0, 0);
44  // throw success alert
45  echo \YAWK\alert::draw("success", "You sent a friend request to $userB.", "Now you can take a cup of tea and... wait until $userB responds.","",4200);
46  }
47  else
48  { // follow not successful, throw alert
49  echo \YAWK\alert::draw("warning", "Error!", "A database error occured, your request could not be sent. Please try again.","",4200);
50  }
51  }
52 }
53 else
54 { // follow not successful
55  echo \YAWK\alert::draw("danger", "Error!", "Some kind of error happened to the database. Please try again.","",4200);
56 }
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
$sql
Definition: message-new.php:32
$userB
$userA
if(!isset($db)) $uid
$hunted