Filter on search page
It also works with jquery now
This commit is contained in:
28
website/public/API/searchGroups.php
Normal file
28
website/public/API/searchGroups.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
|
||||
session_start();
|
||||
|
||||
require_once ("../../queries/connect.php");
|
||||
require_once ("../../queries/checkInput.php");
|
||||
require_once ("../../queries/group_member.php");
|
||||
require_once ("../../queries/group_page.php");
|
||||
|
||||
$n = 0;
|
||||
if (isset($_POST["n"])) {
|
||||
$n = (int) test_input($_POST["n"]);
|
||||
}
|
||||
$m = 20;
|
||||
if (isset($_POST["m"])) {
|
||||
$m = (int) test_input($_POST["m"]);
|
||||
}
|
||||
$search = "";
|
||||
if (isset($_POST["search"])) {
|
||||
$search = test_input($_POST["search"]);
|
||||
}
|
||||
|
||||
if (isset($_POST["filter"]) && $_POST["filter"] == "personal") {
|
||||
echo searchSomeOwnGroups($n, $m, $search);
|
||||
} else {
|
||||
echo searchSomeGroups($n, $m, $search);
|
||||
}
|
||||
27
website/public/API/searchUsers.php
Normal file
27
website/public/API/searchUsers.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once ("../../queries/connect.php");
|
||||
require_once ("../../queries/checkInput.php");
|
||||
require_once ("../../queries/friendship.php");
|
||||
require_once ("../../queries/user.php");
|
||||
|
||||
$n = 0;
|
||||
if (isset($_POST["n"])) {
|
||||
$n = (int) test_input($_POST["n"]);
|
||||
}
|
||||
$m = 20;
|
||||
if (isset($_POST["m"])) {
|
||||
$m = (int) test_input($_POST["m"]);
|
||||
}
|
||||
$search = "";
|
||||
if (isset($_POST["search"])) {
|
||||
$search = test_input($_POST["search"]);
|
||||
}
|
||||
|
||||
if (isset($_POST["filter"]) && $_POST["filter"] == "personal") {
|
||||
echo searchSomeFriends($n, $m, $search);
|
||||
} else {
|
||||
echo searchSomeUsers($n, $m, $search);
|
||||
}
|
||||
@@ -4,12 +4,6 @@ session_start();
|
||||
|
||||
include_once ("../../queries/friendship.php");
|
||||
|
||||
if (isset($_POST["limit"])) {
|
||||
$limit = $_POST["limit"];
|
||||
} else {
|
||||
$limit = 5;
|
||||
}
|
||||
|
||||
if (isset($_POST["action"])) {
|
||||
$action = $_POST["action"];
|
||||
} else {
|
||||
@@ -26,11 +20,6 @@ $friends = json_decode($_POST["friends"]);
|
||||
|
||||
foreach($friends as $i => $friend) {
|
||||
$friendshipStatus = getFriendshipStatus($friend->userID);
|
||||
|
||||
if ($limit != 0 && $i >= $limit)
|
||||
$extra = "extra-friend-item";
|
||||
else
|
||||
$extra = "";
|
||||
?>
|
||||
<li class='friend-item <?= $extra ?>'>
|
||||
<form action='<?= $action ?>' method='<?= $actionType ?>'>
|
||||
@@ -60,15 +49,13 @@ foreach($friends as $i => $friend) {
|
||||
</form>
|
||||
<?php
|
||||
if ($friendshipStatus > 1) {
|
||||
if ($friendshipStatus == 2) {
|
||||
$denyName = "Annuleer";
|
||||
} else {
|
||||
$denyName = "Weiger";
|
||||
}
|
||||
?>
|
||||
<div class='notification-options'>
|
||||
<input type='hidden' name='userID' value='' />
|
||||
<button name='delete'
|
||||
onclick="editFriendship('<?= $friend->userID ?>', 'delete')"
|
||||
class='deny-notification'
|
||||
value='1'>
|
||||
<i class='fa fa-times'></i>
|
||||
</button>
|
||||
<?php
|
||||
if ($friendshipStatus == 3) {
|
||||
?>
|
||||
@@ -76,11 +63,19 @@ foreach($friends as $i => $friend) {
|
||||
onclick="editFriendship('<?= $friend->userID ?>', 'accept')"
|
||||
class='accept-notification'
|
||||
value='1'>
|
||||
<i class='fa fa-check'></i>
|
||||
<i class='fa fa-check'></i>Accepteer
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
<input type='hidden' name='userID' value='' />
|
||||
<button name='delete'
|
||||
onclick="editFriendship('<?= $friend->userID ?>', 'delete')"
|
||||
class='deny-notification'
|
||||
value='1'>
|
||||
<i class='fa fa-times'></i> <?= $denyName ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -89,13 +84,6 @@ foreach($friends as $i => $friend) {
|
||||
<?php
|
||||
}
|
||||
|
||||
if (sizeof($friends) > $limit) {
|
||||
?>
|
||||
<li class='more-item'>
|
||||
Meer vrienden...
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -22,17 +22,3 @@ foreach($groups as $i => $group) {
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<li>
|
||||
<form action="search.php" method="get">
|
||||
<input type="hidden"
|
||||
name="search"
|
||||
value="" />
|
||||
<input type="hidden"
|
||||
name="filter"
|
||||
value="groups" />
|
||||
<button type="submit">
|
||||
Alle groepen...
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
|
||||
@@ -252,16 +252,20 @@ div[data-title]:hover:after {
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.friend {
|
||||
|
||||
}
|
||||
|
||||
|
||||
.friend-item, .group-item {
|
||||
cursor: pointer;
|
||||
transition-duration: 250ms;
|
||||
}
|
||||
|
||||
.friend-item button, .group-item button {
|
||||
background: none;
|
||||
color: inherit;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.friend-item:hover, .group-item:hover {
|
||||
background: #FBC02D;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
|
||||
@@ -34,15 +34,6 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.menu button {
|
||||
background: none;
|
||||
color: inherit;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#notification-center {
|
||||
left: auto;
|
||||
width: 236px;
|
||||
@@ -67,7 +58,6 @@
|
||||
|
||||
.notification-options {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -88,3 +78,12 @@
|
||||
.friend-item:hover .notification-options {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.menu button {
|
||||
background: none;
|
||||
color: inherit;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ function selectAllFriendRequests() {
|
||||
`friendship`.`user2ID` = `user`.`userID` OR
|
||||
`friendship`.`user2ID` = :userID AND
|
||||
`friendship`.`user1ID` = `user`.`userID`) AND
|
||||
`user`.`role` != 5 AND
|
||||
`user`.`role` != 'banned' AND
|
||||
`friendship`.`status` = 'requested'
|
||||
");
|
||||
|
||||
@@ -218,3 +218,46 @@ function setLastVisited($friend) {
|
||||
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
function searchSomeFriends($n, $m, $search) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`userID`,
|
||||
`username`,
|
||||
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/avatar-standard.png'
|
||||
) AS profilepicture,
|
||||
`onlinestatus`,
|
||||
`role`
|
||||
FROM
|
||||
`user`
|
||||
INNER JOIN
|
||||
`friendship`
|
||||
WHERE
|
||||
((`friendship`.`user1ID` = :userID AND
|
||||
`friendship`.`user2ID` = `user`.`userID` OR
|
||||
`friendship`.`user2ID` = :userID AND
|
||||
`friendship`.`user1ID` = `user`.`userID`) AND
|
||||
`user`.`role` != 'banned' AND
|
||||
`friendship`.`status` = 'confirmed') AND
|
||||
(`username` LIKE :keyword OR
|
||||
`fname` LIKE :keyword OR
|
||||
`lname` LIKE :keyword)
|
||||
ORDER BY
|
||||
`fname`,
|
||||
`lname`,
|
||||
`username`
|
||||
LIMIT
|
||||
:n, :m
|
||||
");
|
||||
|
||||
$search = "%$search%";
|
||||
$stmt->bindParam(':keyword', $search);
|
||||
$stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
$stmt->bindParam(':n', $n, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':m', $m, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
@@ -27,3 +27,30 @@ function selectLimitedGroupsFromUser($userID, $limit) {
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
|
||||
function searchSomeOwnGroups($n, $m, $search) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`group_page`.`name`,
|
||||
`group_page`.`picture`
|
||||
FROM
|
||||
`group_page`
|
||||
INNER JOIN
|
||||
`group_member`
|
||||
WHERE
|
||||
`group_member`.`userID` = :userID AND
|
||||
`group_member`.`groupID` = `group_page`.`groupID` AND
|
||||
`group_page`.`status` != 'hidden' AND
|
||||
`name` LIKE :keyword
|
||||
LIMIT
|
||||
:n, :m
|
||||
");
|
||||
|
||||
$search = "%$search%";
|
||||
$stmt->bindParam(':keyword', $search);
|
||||
$stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
$stmt->bindParam(':n', $n, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':m', $m, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ function searchSomeGroups($n, $m, $search) {
|
||||
$stmt->bindParam(':n', $n, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':m', $m, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
return $stmt;
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
|
||||
function countSomeGroups($search) {
|
||||
|
||||
@@ -83,7 +83,7 @@ function selectAllUnreadChat() {
|
||||
`user`.`userID`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/notbad.jpg'
|
||||
'../img/avatar-standard.png'
|
||||
) AS profilepicture,
|
||||
LEFT(`private_message`.`content`, 15) as `content`
|
||||
FROM
|
||||
|
||||
@@ -316,17 +316,16 @@ function selectRandomNotFriendUser($userID) {
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
function searchSomeUsers($n, $m, $search)
|
||||
{
|
||||
function searchSomeUsers($n, $m, $search) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`userID`,
|
||||
`username`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/notbad.jpg'
|
||||
'../img/avatar-standard.png'
|
||||
) AS profilepicture,
|
||||
`fname`,
|
||||
`lname`
|
||||
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
@@ -345,8 +344,10 @@ function searchSomeUsers($n, $m, $search)
|
||||
$stmt->bindParam(':keyword', $search);
|
||||
$stmt->bindParam(':n', $n, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':m', $m, PDO::PARAM_INT);
|
||||
|
||||
$stmt->execute();
|
||||
return $stmt;
|
||||
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
|
||||
function countSomeUsers($search) {
|
||||
|
||||
@@ -12,7 +12,6 @@ $userinfo = getHeaderInfo();
|
||||
<input name="search"
|
||||
type="text"
|
||||
placeholder="Zoek naar wat je wil"
|
||||
required
|
||||
/>
|
||||
<button type="submit">
|
||||
<i class="fa fa-search"></i>
|
||||
|
||||
@@ -1,25 +1,33 @@
|
||||
<nav class="menu">
|
||||
<section id="friends-menu-section">
|
||||
<h4>
|
||||
Vrienden
|
||||
Top vrienden
|
||||
</h4>
|
||||
<ul id="menu-friends-list" class="nav-list">
|
||||
</ul>
|
||||
<h4><form action="search.php">
|
||||
<input type="hidden"
|
||||
value="friends"
|
||||
name="filter" />
|
||||
<button value=""
|
||||
name="search">
|
||||
Alle vrienden...
|
||||
</button>
|
||||
</form></h4>
|
||||
</section>
|
||||
<section id="groups-menu-section">
|
||||
<h4>
|
||||
Groepen
|
||||
Top groepen
|
||||
</h4>
|
||||
<ul id="menu-groups-list" class="nav-list">
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<ul class="nav-list">
|
||||
<li>
|
||||
<form action="search.php" method="get">
|
||||
<input type="hidden"
|
||||
name="search"
|
||||
value="" />
|
||||
<input type="hidden"
|
||||
name="filter"
|
||||
value="personal" />
|
||||
<button type="submit">
|
||||
Klik voor al je groepen en vrienden...
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</nav>
|
||||
@@ -5,11 +5,11 @@ $user_perpage = $group_perpage = 20;
|
||||
$user_currentpage = $group_currentpage = 1;
|
||||
|
||||
if (isset($_GET['user-pageselect'])) {
|
||||
$user_currentpage = $_GET['user-pageselect'];
|
||||
$user_currentpage = test_input($_GET['user-pageselect']);
|
||||
}
|
||||
|
||||
if (isset($_GET['group-pageselect'])) {
|
||||
$group_currentpage = $_GET['group-pageselect'];
|
||||
$group_currentpage = test_input($_GET['group-pageselect']);
|
||||
}
|
||||
|
||||
if (isset($_GET['search'])) {
|
||||
@@ -17,7 +17,7 @@ if (isset($_GET['search'])) {
|
||||
}
|
||||
|
||||
if (isset($_GET['filter'])) {
|
||||
$filter = $_GET['filter'];
|
||||
$filter = test_input($_GET['filter']);
|
||||
}
|
||||
|
||||
$user_n = ($user_currentpage - 1) * $user_perpage;
|
||||
@@ -45,18 +45,12 @@ $group_count = countSomeGroups($search)->fetchColumn();
|
||||
Filter:
|
||||
</label>
|
||||
<select name="filter">
|
||||
<option value="personal"
|
||||
<?php if ($filter == "personal") echo "selected";?>>
|
||||
Persoonlijk</option>
|
||||
<option value="all"
|
||||
<?php if ($filter == "all") echo "selected";?>>
|
||||
Alles</option>
|
||||
<option value="users"
|
||||
<?php if ($filter == "users") echo "selected";?>>
|
||||
Gebruikers</option>
|
||||
<option value="groups"
|
||||
<?php if ($filter == "groups") echo "selected";?>>
|
||||
Groepen</option>
|
||||
<option value="friends"
|
||||
<?php if ($filter == "friends") echo "selected";?>>
|
||||
Vrienden</option>
|
||||
</select>
|
||||
<input onclick="document.getElementById('user-pageselect').value = 1;
|
||||
document.getElementById('group-pageselect').value = 1"
|
||||
@@ -84,31 +78,25 @@ $group_count = countSomeGroups($search)->fetchColumn();
|
||||
?>
|
||||
</select>
|
||||
|
||||
<ul class='nav-list'>
|
||||
<ul id='search-users-list' class='nav-list'>
|
||||
|
||||
<?php
|
||||
$q = searchSomeUsers($user_n, $user_perpage, $search);
|
||||
|
||||
while ($user = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||
$username = $user['username'];
|
||||
$profilepic = $user['profilepicture'];
|
||||
$fname = $user['fname'];
|
||||
$lname = $user['lname'];
|
||||
|
||||
echo("
|
||||
<a href='https://myhyvesbookplus.nl/profile?username=$username'>
|
||||
<li class='search-item'>
|
||||
<div class='friend'>
|
||||
<img class='profile-picture'
|
||||
src='$profilepic'>
|
||||
$fname $lname ($username)
|
||||
</div>
|
||||
</li>
|
||||
</a>
|
||||
");
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$.post(
|
||||
"API/searchUsers.php",
|
||||
{
|
||||
n: "<?= $user_n ?>",
|
||||
m: "<?= $user_perpage ?>",
|
||||
search: "<?= $search ?>",
|
||||
filter: "<?= $filter ?>"
|
||||
}
|
||||
?>
|
||||
|
||||
).done(function(data) {
|
||||
if (!showFriends(data, "#search-users-list", 0, "profile.php", "GET")) {
|
||||
$("#search-friends-output").append("Niemand gevonden");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -131,27 +119,44 @@ $group_count = countSomeGroups($search)->fetchColumn();
|
||||
?>
|
||||
</select>
|
||||
|
||||
<ul class="nav-list">
|
||||
|
||||
<?php
|
||||
$q = searchSomeGroups($group_n, $user_perpage, $search);
|
||||
|
||||
while ($group = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||
$groupname = $group['name'];
|
||||
$grouppic = $group['picture'];
|
||||
|
||||
echo("
|
||||
<a href='https://myhyvesbookplus.nl/group?groupName=$groupname'>
|
||||
<li class='search-item'>
|
||||
<div class='group'>
|
||||
<img class='group-picture'
|
||||
src='$grouppic'>
|
||||
$groupname
|
||||
</div>
|
||||
</li>
|
||||
</a>
|
||||
");
|
||||
<ul id="search-groups-list" class="nav-list">
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$.post(
|
||||
"API/searchGroups.php",
|
||||
{
|
||||
n: "<?= $group_n ?>",
|
||||
m: "<?= $group_perpage ?>",
|
||||
search: "<?= $search ?>",
|
||||
filter: "<?= $filter ?>"
|
||||
}
|
||||
).done(function(data) {
|
||||
console.log(data);
|
||||
if (!showGroups(data, "#search-groups-list")) {
|
||||
$("#search-groups-list").append("Geen groepen gevonden");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
// $q = searchSomeGroups($group_n, $user_perpage, $search);
|
||||
//
|
||||
// while ($group = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||
// $groupname = $group['name'];
|
||||
// $grouppic = $group['picture'];
|
||||
//
|
||||
// echo("
|
||||
// <a href='https://myhyvesbookplus.nl/group?groupName=$groupname'>
|
||||
// <li class='search-item'>
|
||||
// <div class='group'>
|
||||
// <img class='group-picture'
|
||||
// src='$grouppic'>
|
||||
// $groupname
|
||||
// </div>
|
||||
// </li>
|
||||
// </a>
|
||||
// ");
|
||||
// }
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user