YaWK  24.1
Yet another WebKit
friend-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  AND confirmed = '1'
24  AND aborted NOT LIKE '1'"))
25 { // if users are friends...
26  $res = mysqli_fetch_row($sql);
27  if ($res[0] === true )
28  { // already friends
29  if ($sql = $db->query("DELETE FROM {friends}
30  WHERE confirmed = '1' AND friendA = '".$uid."' AND friendB = '".$hunted."'
31  OR confirmed = '1' AND friendA = '".$hunted."' AND friendB = '".$uid."'"))
32  { // un-followd with user
33  \YAWK\sys::setSyslog($db, 17, 0, "$userA un-friended $userB.", $uid, $hunted, 0, 0);
34  // \YAWK\sys::setNotification($db, 3, "$userA un-friended you.", $uid, $hunted, 0, 0);
35  \YAWK\sys::setNotification($db, 3, 0, "$userA un-friended you.", $uid, $hunted, 0, 0);
36  \YAWK\alert::draw("danger","Disconnected with $userB", "You are not friend with $userB anymore.","",4200);
37  }
38  }
39  else
40  { // user is not in db, follow now:
41  if ($sql = $db->query("INSERT INTO {friends} (friendA, friendB) VALUES ('$uid', '$hunted')"))
42  { // put data into logfile
43  \YAWK\sys::setSyslog($db, 17, 0,"$userA asked $userB for friendship", $uid, $hunted, 0, 0);
44  /*
45  \YAWK\sys::setNotification($db, 3, "<b>$userA</b> wants to be your friend<br>
46  <b><i class=\"fa fa-check-circle-o text-green\"> </i>&nbsp;&nbsp;
47  <i class=\"fa fa-times-circle-o text-red\"> </i></b>", $uid, $hunted, 0, 0);
48  */
49  \YAWK\sys::setNotification($db, 3, 0, $uid, $hunted, 0, 0, 0);
50 
51  // throw success alert
52  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);
53  }
54  else
55  { // follow not successful, throw alert
56  echo \YAWK\alert::draw("warning", "Error!", "A database error occured, your request could not be sent. Please try again.","",4200);
57  }
58  }
59 }
60 else
61 { // follow not successful
62  echo \YAWK\alert::draw("danger", "Error!", "Some kind of error happened to the database. Please try again.","",4200);
63 }
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
$userB
Definition: friend-user.php:16
$userA
Definition: friend-user.php:17
if(!isset($db)) $uid
Definition: friend-user.php:14
$hunted
Definition: friend-user.php:15
$sql
Definition: message-new.php:32