modals.php
См. документацию.
1 <?php
2 
3 /**
4  * @file
5  * @brief выборка моделей типа "модальное окно"
6  */
7 
8 isset($user) or require $_SERVER['DOCUMENT_ROOT'] . '/page/404.php';
9 
10 header("Content-type: application/json");
11 
12 $table_name = basename($request);
13 
14 $response['recordsFiltered'] = $response['recordsTotal'];
15 
16 $columns = ['id', 'request', 'file', 'groups', 'owner_group', 'note', 'act'];
17 
18 $order_column = isset($_GET['order'][0]['column']) && isset($columns[$_GET['order'][0]['column']]) ? $columns[$_GET['order'][0]['column']] : $columns[0];
19 $order_dir = isset($_GET['order'][0]['dir']) && $_GET['order'][0]['dir'] == 'asc' ? 'ASC' : 'DESC';
20 $start = abs(intval($_GET['start']));
21 $length = intval($_GET['length']);
22 
23 $query = "SELECT " . implode(', ', $columns) . " FROM `$table_name` ORDER BY `$order_column` $order_dir";
24 
25 $sth = $dbh->prepare($query);
26 $sth->execute();
27 $arr = $sth->fetchAll(PDO::FETCH_NUM);
28 
30 
32 
33 if (!empty($_GET['search']['value'])) {
34  $searchable_columns = [];
35  $arr_filtered = [];
36  foreach ($_GET['columns'] as $key => $item) {
37  if ($item['searchable']) {
38  $searchable_columns[] = $key;
39  }
40  }
41 
42  if ($searchable_columns) {
43  foreach ($arr as $key => $item) {
44  $arr_search = array_intersect_key($item, $searchable_columns);
45  foreach ($arr_search as $word) {
46  if (mb_stripos(strip_tags($word), $_GET['search']['value']) !== false) {
47  $arr_filtered[] = $arr[$key];
48  continue 2;
49  }
50  }
51  }
52  }
53 }
54 
55 $response = [];
56 $response['recordsTotal'] = count($arr);
57 $response['recordsFiltered'] = $response['recordsTotal'];
58 $length = $length == -1 ? $response['recordsTotal'] : $length;
59 $response['recordsFiltered'] = count($arr_filtered);
60 $response['data'] = array_slice($arr_filtered, $start, $length);
61 $response['draw'] = abs(intval($_GET['draw']));
62 
63 exit(json_encode($response, JSON_UNESCAPED_UNICODE));
static formatter($arr, $columns, $table)
Definition: Selects.php:68
$user
Definition: from-user.php:38
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' $_SERVER['HTTP_HOST']
Definition: from-user.php:36
if(($dbh=Connect::getInstance(true) ->dbh) && $dbh->query("SHOW TABLES") ->fetchAll() && $dbh->query("SELECT COUNT(*) FROM `users`") ->fetchColumn()) if(!empty($_POST)) exit
Definition: install.php:198
$columns
Definition: modals.php:16
$order_column
Definition: modals.php:18
$start
Definition: modals.php:20
$arr_filtered
Definition: modals.php:31
$arr
Definition: modals.php:27
$table_name
Definition: modals.php:12
$order_dir
Definition: modals.php:19
$response['recordsFiltered']
Definition: modals.php:14
$length
Definition: modals.php:21
$query
Definition: modals.php:23
$sth
Definition: modals.php:25
catch(\Throwable $th) $request
Definition: session.php:28
$dbh
Definition: session.php:19