-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders_list.php
More file actions
34 lines (30 loc) · 1.04 KB
/
Copy pathorders_list.php
File metadata and controls
34 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require_once 'includes/auth.php';
require_login();
require_once 'includes/db.php';
$orderBy = in_array($_GET['orderBy'] ?? '', [
'beleg','pos','artikel','bezeichnung_artikel','menge','liefermenge','versendet','verpackt','in_produktion','offen','liefertermin','verwendung'
]) ? $_GET['orderBy'] : 'id';
$orderDir = ($_GET['orderDir'] ?? 'ASC') === 'DESC' ? 'DESC' : 'ASC';
$where = [];
$params = [];
if (!empty($_GET['search'])) {
$where[] = "(artikel LIKE ? OR bezeichnung_artikel LIKE ?)";
$params[] = '%'.$_GET['search'].'%';
$params[] = '%'.$_GET['search'].'%';
}
if (!empty($_GET['from'])) {
$where[] = "liefertermin >= ?";
$params[] = $_GET['from'];
}
if (!empty($_GET['to'])) {
$where[] = "liefertermin <= ?";
$params[] = $_GET['to'];
}
$where_sql = $where ? 'WHERE '.implode(' AND ', $where) : '';
$sql = "SELECT * FROM orders $where_sql ORDER BY $orderBy $orderDir";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-Type: application/json');
echo json_encode($orders);