Skip to content

Commit 103511b

Browse files
committed
[Log search] fix error when no values set
1 parent 387ffac commit 103511b

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

web/includes/Log.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public static function add($type, $title, $message): void
5555
*/
5656
public static function getAll($start, $limit): mixed
5757
{
58-
$where = '';
58+
$where = null;
5959
$valueOther = null;
60-
$value = $_GET['advSearch'];
61-
$type = $_GET['advType'];
60+
$value = $_GET['advSearch'] ?? null;
61+
$type = $_GET['advType'] ?? null;
6262

6363
switch ($type) {
6464
case "admin":
@@ -82,15 +82,16 @@ public static function getAll($start, $limit): mixed
8282
break;
8383
}
8484

85-
$query = "SELECT ad.user, l.* FROM `:prefix_log` AS l
85+
$query = 'SELECT ad.user, l.* FROM `:prefix_log` AS l
8686
LEFT JOIN `:prefix_admins` AS ad ON l.aid = ad.aid
87-
WHERE $where
87+
'. ($where ? "WHERE $where" : '') .'
8888
ORDER BY l.created DESC
89-
LIMIT :start, :lim";
89+
LIMIT :start, :lim';
9090

91-
self::$dbs->query($query)
92-
->bind('value', $value);
91+
self::$dbs->query($query);
9392

93+
if ($value !== null)
94+
self::$dbs->bind('value', $value);
9495
if ($valueOther !== null)
9596
self::$dbs->bind('valueOther', $valueOther);
9697

@@ -105,17 +106,17 @@ public static function getAll($start, $limit): mixed
105106
*/
106107
public static function getCount($search): mixed
107108
{
108-
$value = $_GET['advSearch'];
109+
$value = $_GET['advSearch'] ?? null;
109110
$valueOther = null;
110-
$type = $_GET['advType'];
111-
$query = "SELECT COUNT(l.lid) AS count FROM `:prefix_log` AS l WHERE ";
111+
$type = $_GET['advType'] ?? null;
112+
$query = "SELECT COUNT(l.lid) AS count FROM `:prefix_log` AS l ";
112113
switch ($type) {
113114
case "admin":
114-
$query .= " l.aid = :value";
115+
$query .= "WHERE l.aid = :value";
115116
break;
116117
case "message":
117118
$value = "%$value%";
118-
$query .= " l.message LIKE :value OR l.title LIKE :value";
119+
$query .= "WHERE l.message LIKE :value OR l.title LIKE :value";
119120
break;
120121
case "date":
121122
$date = explode(",", $value);
@@ -124,16 +125,17 @@ public static function getCount($search): mixed
124125
$date[2] = (is_numeric($date[2])) ? $date[2] : date('Y');
125126
$value = mktime($date[3], $date[4], 0, (int)$date[1], (int)$date[0], (int)$date[2]);
126127
$valueOther = mktime($date[5], $date[6], 59, (int)$date[1], (int)$date[0], (int)$date[2]);
127-
$query .= " l.created > :value AND l.created :valueOther";
128+
$query .= "WHERE l.created > :value AND l.created :valueOther";
128129
break;
129130
case "type":
130-
$query .= " l.type = :value";
131+
$query .= "WHERE l.type = :value";
131132
break;
132133
}
133134

134-
self::$dbs->query($query)
135-
->bind('value', $value);
135+
self::$dbs->query($query);
136136

137+
if ($value !== null)
138+
self::$dbs->bind('value', $value);
137139
if ($valueOther !== null)
138140
self::$dbs->bind('valueOther', $valueOther);
139141

0 commit comments

Comments
 (0)