Filter on search page

It also works with jquery now
This commit is contained in:
Lars van Hijfte
2017-01-26 13:53:59 +01:00
parent 7b7f0b2c64
commit 33a640329b
14 changed files with 248 additions and 133 deletions

View 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);
}

View 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);
}

View File

@@ -4,12 +4,6 @@ session_start();
include_once ("../../queries/friendship.php"); include_once ("../../queries/friendship.php");
if (isset($_POST["limit"])) {
$limit = $_POST["limit"];
} else {
$limit = 5;
}
if (isset($_POST["action"])) { if (isset($_POST["action"])) {
$action = $_POST["action"]; $action = $_POST["action"];
} else { } else {
@@ -26,11 +20,6 @@ $friends = json_decode($_POST["friends"]);
foreach($friends as $i => $friend) { foreach($friends as $i => $friend) {
$friendshipStatus = getFriendshipStatus($friend->userID); $friendshipStatus = getFriendshipStatus($friend->userID);
if ($limit != 0 && $i >= $limit)
$extra = "extra-friend-item";
else
$extra = "";
?> ?>
<li class='friend-item <?= $extra ?>'> <li class='friend-item <?= $extra ?>'>
<form action='<?= $action ?>' method='<?= $actionType ?>'> <form action='<?= $action ?>' method='<?= $actionType ?>'>
@@ -60,15 +49,13 @@ foreach($friends as $i => $friend) {
</form> </form>
<?php <?php
if ($friendshipStatus > 1) { if ($friendshipStatus > 1) {
if ($friendshipStatus == 2) {
$denyName = "Annuleer";
} else {
$denyName = "Weiger";
}
?> ?>
<div class='notification-options'> <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 <?php
if ($friendshipStatus == 3) { if ($friendshipStatus == 3) {
?> ?>
@@ -76,11 +63,19 @@ foreach($friends as $i => $friend) {
onclick="editFriendship('<?= $friend->userID ?>', 'accept')" onclick="editFriendship('<?= $friend->userID ?>', 'accept')"
class='accept-notification' class='accept-notification'
value='1'> value='1'>
<i class='fa fa-check'></i> <i class='fa fa-check'></i>Accepteer
</button> </button>
<?php <?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> </div>
<?php <?php
} }
@@ -89,13 +84,6 @@ foreach($friends as $i => $friend) {
<?php <?php
} }
if (sizeof($friends) > $limit) {
?>
<li class='more-item'>
Meer vrienden...
</li>
<?php
}
?> ?>

View File

@@ -22,17 +22,3 @@ foreach($groups as $i => $group) {
</li> </li>
<?php <?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>

View File

@@ -252,16 +252,20 @@ div[data-title]:hover:after {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
} }
.friend {
}
.friend-item, .group-item { .friend-item, .group-item {
cursor: pointer; cursor: pointer;
transition-duration: 250ms; 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 { .friend-item:hover, .group-item:hover {
background: #FBC02D; background: #FBC02D;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);

View File

@@ -34,15 +34,6 @@
cursor: pointer; cursor: pointer;
} }
.menu button {
background: none;
color: inherit;
width: 100%;
height: 100%;
padding: 0;
text-align: left;
}
#notification-center { #notification-center {
left: auto; left: auto;
width: 236px; width: 236px;
@@ -67,7 +58,6 @@
.notification-options { .notification-options {
width: 100%; width: 100%;
text-align: center;
display: none; display: none;
} }
@@ -88,3 +78,12 @@
.friend-item:hover .notification-options { .friend-item:hover .notification-options {
display: inline-block; display: inline-block;
} }
.menu button {
background: none;
color: inherit;
width: 100%;
height: 100%;
padding: 0;
text-align: left;
}

View File

@@ -94,7 +94,7 @@ function selectAllFriendRequests() {
`friendship`.`user2ID` = `user`.`userID` OR `friendship`.`user2ID` = `user`.`userID` OR
`friendship`.`user2ID` = :userID AND `friendship`.`user2ID` = :userID AND
`friendship`.`user1ID` = `user`.`userID`) AND `friendship`.`user1ID` = `user`.`userID`) AND
`user`.`role` != 5 AND `user`.`role` != 'banned' AND
`friendship`.`status` = 'requested' `friendship`.`status` = 'requested'
"); ");
@@ -218,3 +218,46 @@ function setLastVisited($friend) {
return $stmt; 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());
}

View File

@@ -27,3 +27,30 @@ function selectLimitedGroupsFromUser($userID, $limit) {
return json_encode($stmt->fetchAll()); 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());
}

View File

@@ -192,7 +192,7 @@ function searchSomeGroups($n, $m, $search) {
$stmt->bindParam(':n', $n, PDO::PARAM_INT); $stmt->bindParam(':n', $n, PDO::PARAM_INT);
$stmt->bindParam(':m', $m, PDO::PARAM_INT); $stmt->bindParam(':m', $m, PDO::PARAM_INT);
$stmt->execute(); $stmt->execute();
return $stmt; return json_encode($stmt->fetchAll());
} }
function countSomeGroups($search) { function countSomeGroups($search) {

View File

@@ -83,7 +83,7 @@ function selectAllUnreadChat() {
`user`.`userID`, `user`.`userID`,
IFNULL( IFNULL(
`profilepicture`, `profilepicture`,
'../img/notbad.jpg' '../img/avatar-standard.png'
) AS profilepicture, ) AS profilepicture,
LEFT(`private_message`.`content`, 15) as `content` LEFT(`private_message`.`content`, 15) as `content`
FROM FROM

View File

@@ -316,17 +316,16 @@ function selectRandomNotFriendUser($userID) {
return $stmt->fetch(); return $stmt->fetch();
} }
function searchSomeUsers($n, $m, $search) function searchSomeUsers($n, $m, $search) {
{
$stmt = $GLOBALS["db"]->prepare(" $stmt = $GLOBALS["db"]->prepare("
SELECT SELECT
`userID`,
`username`, `username`,
IFNULL( IFNULL(
`profilepicture`, `profilepicture`,
'../img/notbad.jpg' '../img/avatar-standard.png'
) AS profilepicture, ) AS profilepicture,
`fname`, LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`
`lname`
FROM FROM
`user` `user`
WHERE WHERE
@@ -345,8 +344,10 @@ function searchSomeUsers($n, $m, $search)
$stmt->bindParam(':keyword', $search); $stmt->bindParam(':keyword', $search);
$stmt->bindParam(':n', $n, PDO::PARAM_INT); $stmt->bindParam(':n', $n, PDO::PARAM_INT);
$stmt->bindParam(':m', $m, PDO::PARAM_INT); $stmt->bindParam(':m', $m, PDO::PARAM_INT);
$stmt->execute(); $stmt->execute();
return $stmt;
return json_encode($stmt->fetchAll());
} }
function countSomeUsers($search) { function countSomeUsers($search) {

View File

@@ -12,7 +12,6 @@ $userinfo = getHeaderInfo();
<input name="search" <input name="search"
type="text" type="text"
placeholder="Zoek naar wat je wil" placeholder="Zoek naar wat je wil"
required
/> />
<button type="submit"> <button type="submit">
<i class="fa fa-search"></i> <i class="fa fa-search"></i>

View File

@@ -1,25 +1,33 @@
<nav class="menu"> <nav class="menu">
<section id="friends-menu-section"> <section id="friends-menu-section">
<h4> <h4>
Vrienden Top vrienden
</h4> </h4>
<ul id="menu-friends-list" class="nav-list"> <ul id="menu-friends-list" class="nav-list">
</ul> </ul>
<h4><form action="search.php">
<input type="hidden"
value="friends"
name="filter" />
<button value=""
name="search">
Alle vrienden...
</button>
</form></h4>
</section> </section>
<section id="groups-menu-section"> <section id="groups-menu-section">
<h4> <h4>
Groepen Top groepen
</h4> </h4>
<ul id="menu-groups-list" class="nav-list"> <ul id="menu-groups-list" class="nav-list">
</ul> </ul>
</section> </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> </nav>

View File

@@ -5,11 +5,11 @@ $user_perpage = $group_perpage = 20;
$user_currentpage = $group_currentpage = 1; $user_currentpage = $group_currentpage = 1;
if (isset($_GET['user-pageselect'])) { if (isset($_GET['user-pageselect'])) {
$user_currentpage = $_GET['user-pageselect']; $user_currentpage = test_input($_GET['user-pageselect']);
} }
if (isset($_GET['group-pageselect'])) { if (isset($_GET['group-pageselect'])) {
$group_currentpage = $_GET['group-pageselect']; $group_currentpage = test_input($_GET['group-pageselect']);
} }
if (isset($_GET['search'])) { if (isset($_GET['search'])) {
@@ -17,7 +17,7 @@ if (isset($_GET['search'])) {
} }
if (isset($_GET['filter'])) { if (isset($_GET['filter'])) {
$filter = $_GET['filter']; $filter = test_input($_GET['filter']);
} }
$user_n = ($user_currentpage - 1) * $user_perpage; $user_n = ($user_currentpage - 1) * $user_perpage;
@@ -45,18 +45,12 @@ $group_count = countSomeGroups($search)->fetchColumn();
Filter: Filter:
</label> </label>
<select name="filter"> <select name="filter">
<option value="personal"
<?php if ($filter == "personal") echo "selected";?>>
Persoonlijk</option>
<option value="all" <option value="all"
<?php if ($filter == "all") echo "selected";?>> <?php if ($filter == "all") echo "selected";?>>
Alles</option> 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> </select>
<input onclick="document.getElementById('user-pageselect').value = 1; <input onclick="document.getElementById('user-pageselect').value = 1;
document.getElementById('group-pageselect').value = 1" document.getElementById('group-pageselect').value = 1"
@@ -84,31 +78,25 @@ $group_count = countSomeGroups($search)->fetchColumn();
?> ?>
</select> </select>
<ul class='nav-list'> <ul id='search-users-list' class='nav-list'>
<?php <script>
$q = searchSomeUsers($user_n, $user_perpage, $search); $(document).ready(function(){
$.post(
while ($user = $q->fetch(PDO::FETCH_ASSOC)) { "API/searchUsers.php",
$username = $user['username']; {
$profilepic = $user['profilepicture']; n: "<?= $user_n ?>",
$fname = $user['fname']; m: "<?= $user_perpage ?>",
$lname = $user['lname']; search: "<?= $search ?>",
filter: "<?= $filter ?>"
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>
");
} }
?> ).done(function(data) {
if (!showFriends(data, "#search-users-list", 0, "profile.php", "GET")) {
$("#search-friends-output").append("Niemand gevonden");
}
});
});
</script>
</ul> </ul>
</div> </div>
@@ -131,27 +119,44 @@ $group_count = countSomeGroups($search)->fetchColumn();
?> ?>
</select> </select>
<ul class="nav-list"> <ul id="search-groups-list" class="nav-list">
<script>
<?php $(document).ready(function(){
$q = searchSomeGroups($group_n, $user_perpage, $search); $.post(
"API/searchGroups.php",
while ($group = $q->fetch(PDO::FETCH_ASSOC)) { {
$groupname = $group['name']; n: "<?= $group_n ?>",
$grouppic = $group['picture']; m: "<?= $group_perpage ?>",
search: "<?= $search ?>",
echo(" filter: "<?= $filter ?>"
<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>
");
} }
).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> </ul>
</div> </div>