|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
trait table_request |
|
4
|
|
|
{ |
|
5
|
|
|
private static function requestFilter() |
|
6
|
|
|
{ |
|
7
|
|
|
$filter = filter_input(INPUT_GET, 'filter') ?: false; |
|
8
|
|
|
if ($filter) { |
|
9
|
|
|
$by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
|
10
|
|
|
if ($by === false || is_null($by)) { |
|
11
|
|
|
$by = self::requestFilterByAll(); |
|
12
|
|
|
} else { |
|
13
|
|
|
$by = self::$cols[$by][1]; |
|
14
|
|
|
} |
|
15
|
|
|
$by = 'CONCAT(" ",' . $by . ', " ")'; |
|
16
|
|
|
if (self::config('FILTER_CASE_SENSITIVE') !== true) { |
|
17
|
|
|
$by .= ' COLLATE ' . self::config('DB_COLLATION_CI'); |
|
18
|
|
|
} |
|
19
|
|
|
$filter = $by . ' LIKE ' . '"%' . $filter . '%"'; |
|
20
|
|
|
} |
|
21
|
|
|
return $filter; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
private static function requestFilterByAll() |
|
25
|
|
|
{ |
|
26
|
|
|
$by = []; |
|
27
|
|
|
foreach (self::$cols as $v) { |
|
28
|
|
|
if (isset($v[2]['sort']) && $v[2]['sort'] === false) { |
|
29
|
|
|
continue; |
|
30
|
|
|
} |
|
31
|
|
|
$by[] = 'IFNULL(' . $v[1] . ', "")'; |
|
32
|
|
|
} |
|
33
|
|
|
return 'CONCAT(' . implode(',', $by) . ')'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private static function requestOrderCol() |
|
37
|
|
|
{ |
|
38
|
|
|
if (($col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT))) { |
|
39
|
|
|
return isset(self::$cols[$col][2]['sort']) ? |
|
40
|
|
|
self::$cols[$col][2]['sort'] : |
|
41
|
|
|
self::$cols[$col][1]; |
|
42
|
|
|
} |
|
43
|
|
|
return self::$t['order']['col']; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private static function requestOrderDir() |
|
47
|
|
|
{ |
|
48
|
|
|
$reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
|
49
|
|
|
return in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
|
50
|
|
|
filter_input(INPUT_GET, 'ord') : |
|
51
|
|
|
($reset ?: self::$t['order']['dir']); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private static function requestExport() |
|
55
|
|
|
{ |
|
56
|
|
|
$exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
|
57
|
|
|
return in_array($exp, self::config('SAVES')) ? $exp : false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private static function requestPage() |
|
61
|
|
|
{ |
|
62
|
|
|
return filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
|
63
|
|
|
(int) filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
|
64
|
|
|
self::$t['page']; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|