-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-friends.php
60 lines (33 loc) · 1.2 KB
/
check-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
<?php
/**
* I Have Plans --Check-friend controller
* @author Steven Dufresne <[email protected]>
* @link http://github.com/StevenDufresne/web-app
* @copyright 2012 Steven Dufresne
* @license BSD-3-Clause <https://github.com/stevendufresne/web-app/BSD-3-CLAUSE-LICENSE.txt>
*/
require_once 'includes/db.inc.php';
require_once 'includes/users.inc.php';
require_once 'includes/requests.inc.php';
require_once 'includes/functions.inc.php';
$requestType = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING);
if($requestType == "all-users") {
$json_users = get_users_by_name( $db );
$userObjectArray = array();
foreach( $json_users as $users ) {
$userObject = ucFirst($users['username'].' : '.$users['email']);
$userObjectArray[] = $userObject;
}
echo (json_encode( $userObjectArray ));
}
if($requestType == "friends") {
$friend_ids = get_friend_ids($db, $_SESSION['user-id']);
foreach($friend_ids as $friends) {
if($friends[0] !== $_SESSION['user-id']){
$current_friend = intval($friends['friend_id']);
$friend_info = get_username ($db, $current_friend);
$json_users[] = $friend_info['username'];
}
}
echo (json_encode( $json_users));
}