Merge branch 'master' into marijn-settings
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
function selectGroupById($groupID) {
|
||||
return $GLOBALS["db"]->query("
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`group_page`.`name`,
|
||||
`group_page`.`picture`,
|
||||
@@ -11,12 +11,16 @@ function selectGroupById($groupID) {
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`group_page`.`groupID` = $groupID
|
||||
`group_page`.`groupID` = :groupID
|
||||
");
|
||||
|
||||
$q->bindParam(':groupID', $groupID);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function select20GroupsFromN($n) {
|
||||
return $GLOBALS["db"]->query("
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`group_page`.`groupID`,
|
||||
`group_page`.`name`,
|
||||
@@ -29,12 +33,16 @@ function select20GroupsFromN($n) {
|
||||
ORDER BY
|
||||
`group_page`.`name` ASC
|
||||
LIMIT
|
||||
$n, 20
|
||||
:n, 20
|
||||
");
|
||||
|
||||
$q->bindParam(':n', $n);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function select20GroupsByStatusFromN($n, $status) {
|
||||
return $GLOBALS["db"]->query("
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`group_page`.`groupID`,
|
||||
`group_page`.`name`,
|
||||
@@ -45,12 +53,17 @@ function select20GroupsByStatusFromN($n, $status) {
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`group_page`.`status` = $status
|
||||
`group_page`.`status` = :status
|
||||
ORDER BY
|
||||
`group_page`.`name` ASC
|
||||
LIMIT
|
||||
$n, 20
|
||||
:n, 20
|
||||
");
|
||||
|
||||
$q->bindParam(':status', $status);
|
||||
$q->bindParam(':n', $n);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function search20GroupsFromNByStatus($n, $keyword, $status) {
|
||||
@@ -80,6 +93,55 @@ function search20GroupsFromNByStatus($n, $keyword, $status) {
|
||||
return $q;
|
||||
}
|
||||
|
||||
function searchSomeGroupsByStatus($n, $m, $keyword, $status) {
|
||||
$q = $GLOBALS['db']->prepare("
|
||||
SELECT
|
||||
`groupID`,
|
||||
`name`,
|
||||
`status`,
|
||||
`description`
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`name` LIKE :keyword AND
|
||||
FIND_IN_SET (`status`, :statuses)
|
||||
ORDER BY
|
||||
`name`
|
||||
LIMIT
|
||||
:n, :m
|
||||
");
|
||||
|
||||
$keyword = "%$keyword%";
|
||||
$q->bindParam(':keyword', $keyword);
|
||||
$q->bindParam(':n', $n, PDO::PARAM_INT);
|
||||
$q->bindParam(':m', $m, PDO::PARAM_INT);
|
||||
$statuses = implode(',', $status);
|
||||
$q->bindParam(':statuses', $statuses);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function countSomeGroupsByStatus($keyword, $status) {
|
||||
$q = $GLOBALS['db']->prepare("
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
`name` LIKE :keyword AND
|
||||
FIND_IN_SET (`status`, :statuses)
|
||||
ORDER BY
|
||||
`name`
|
||||
");
|
||||
|
||||
$keyword = "%$keyword%";
|
||||
$q->bindParam(':keyword', $keyword);
|
||||
$statuses = implode(',', $status);
|
||||
$q->bindParam(':statuses', $statuses);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function changeGroupStatusByID($id, $status) {
|
||||
$q = $GLOBALS["db"]->query("
|
||||
UPDATE
|
||||
@@ -92,3 +154,23 @@ function changeGroupStatusByID($id, $status) {
|
||||
|
||||
return $q;
|
||||
}
|
||||
|
||||
function changeMultipleGroupStatusByID($ids, $status) {
|
||||
$q = $GLOBALS['db']->prepare("
|
||||
UPDATE
|
||||
`group_page`
|
||||
SET
|
||||
`status` = :status
|
||||
WHERE
|
||||
FIND_IN_SET (`groupID`, :ids)
|
||||
");
|
||||
|
||||
$ids = implode(',', $ids);
|
||||
$q->bindParam(':ids', $ids);
|
||||
$q->bindParam(':status', $status);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
39
website/queries/nicetime.php
Normal file
39
website/queries/nicetime.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
function nicetime($date) {
|
||||
if(empty($date)) {
|
||||
return "No date provided";
|
||||
}
|
||||
|
||||
$single_periods = array("seconde", "minuut", "uur", "dag", "week", "maand", "jaar", "decennium");
|
||||
$multiple_periods = array("seconden", "minuten", "uur", "dagen", "weken", "maanden", "jaar", "decennia");
|
||||
$lengths = array("60", "60", "24", "7", "4.35", "12", "10", "0");
|
||||
|
||||
$now = time();
|
||||
$unix_date = strtotime($date);
|
||||
|
||||
if(empty($unix_date)) {
|
||||
return "Bad date";
|
||||
}
|
||||
|
||||
if($now > $unix_date) {
|
||||
$difference = $now - $unix_date;
|
||||
$tense = "geleden";
|
||||
} else {
|
||||
$difference = $unix_date - $now;
|
||||
$tense = "vanaf nu";
|
||||
}
|
||||
|
||||
for($i = 0; $difference >= $lengths[$i] && $i < count($lengths) - 1; $i++) {
|
||||
$difference /= $lengths[$i];
|
||||
}
|
||||
|
||||
$difference = round($difference);
|
||||
|
||||
if($difference != 1) {
|
||||
$period = $multiple_periods[$i];
|
||||
} else {
|
||||
$period = $single_periods[$i];
|
||||
}
|
||||
|
||||
return "$difference $period $tense";
|
||||
}
|
||||
@@ -88,7 +88,7 @@ function selectAllUserPosts($userID) {
|
||||
}
|
||||
|
||||
function select20UsersFromN($n) {
|
||||
return $GLOBALS["db"]->query("
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`userID`,
|
||||
`username`,
|
||||
@@ -100,8 +100,12 @@ function select20UsersFromN($n) {
|
||||
`role`,
|
||||
`username`
|
||||
LIMIT
|
||||
$n, 20
|
||||
:n, 20
|
||||
");
|
||||
|
||||
$q->bindParam(':n', $n);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function search20UsersFromN($n, $keyword) {
|
||||
@@ -156,19 +160,90 @@ function search20UsersFromNByStatus($n, $keyword, $status) {
|
||||
return $q;
|
||||
}
|
||||
|
||||
function changeUserStatusByID($id, $status) {
|
||||
$q = $GLOBALS["db"]->query("
|
||||
UPDATE
|
||||
function searchSomeUsersByStatus($n, $m, $keyword, $status) {
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`userID`,
|
||||
`username`,
|
||||
`role`,
|
||||
`bancomment`
|
||||
FROM
|
||||
`user`
|
||||
SET
|
||||
`role` = $status
|
||||
WHERE
|
||||
`userID` = $id
|
||||
`username` LIKE :keyword AND
|
||||
FIND_IN_SET (`role`, :statuses)
|
||||
ORDER BY
|
||||
`role`,
|
||||
`username`
|
||||
LIMIT
|
||||
:n, :m
|
||||
");
|
||||
|
||||
$keyword = "%$keyword%";
|
||||
$q->bindParam(':keyword', $keyword);
|
||||
$q->bindParam(':n', $n, PDO::PARAM_INT);
|
||||
$q->bindParam(':m', $m, PDO::PARAM_INT);
|
||||
$statuses = implode(',', $status);
|
||||
$q->bindParam(':statuses', $statuses);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function countSomeUsersByStatus($keyword, $status) {
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`username` LIKE :keyword AND
|
||||
FIND_IN_SET (`role`, :statuses)
|
||||
ORDER BY
|
||||
`role`,
|
||||
`username`
|
||||
");
|
||||
|
||||
$keyword = "%$keyword%";
|
||||
$q->bindParam(':keyword', $keyword);
|
||||
$statuses = implode(',', $status);
|
||||
$q->bindParam(':statuses', $statuses);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
|
||||
function changeUserStatusByID($id, $status) {
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`role` = :status
|
||||
WHERE
|
||||
`userID` = :id
|
||||
");
|
||||
|
||||
$q->bindParam(':status', $status);
|
||||
$q->bindParam(':id', $id);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function changeMultipleUserStatusByID($ids, $status) {
|
||||
$q = $GLOBALS["db"]->prepare("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`role` = :status
|
||||
WHERE
|
||||
FIND_IN_SET (`userID`, :ids)
|
||||
");
|
||||
|
||||
$ids = implode(',', $ids);
|
||||
$q->bindParam(':ids', $ids);
|
||||
$q->bindParam(':status', $status);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function selectRandomNotFriendUser($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
|
||||
Reference in New Issue
Block a user