8 private string $dd =
'lkw';
9 private string $fd =
'lkw-grid';
13 $this->oDB =
dbx()->get_system_obj(
'dbxDB');
17 private function dbx_shift_window(
int $block): string {
22 $base = new \DateTime($baseStr);
32 private function create_tab() {
33 $oTPL =
dbx()->get_system_obj(
'dbxTPL');
35 $data[
'dat0'] = $this->dbx_shift_window(0);
36 $data[
'dat1'] = $this->dbx_shift_window(1);
37 $data[
'dat2'] = $this->dbx_shift_window(2);
38 $data[
'dat3'] = $this->dbx_shift_window(3);
39 $data[
'dat4'] = $this->dbx_shift_window(4);
40 $data[
'dat5'] = $this->dbx_shift_window(5);
42 $cols = $this->get_fd_grid_cols();
43 $data[
'cols'] = $oTPL->replaces($cols, $data);
44 $data[
'dbx_search'] =
dbx()->search_html(
dbx()->search_defaults(array(
46 'extra_attrs' =>
'data-dbx="grid-search"',
49 dbx()->debug(
"grid_cols=($cols)");
51 $content=$oTPL->get_tpl(
'modul|report-lkw',$data);
55 private function get_fd_fields(): array {
57 $file = function_exists(
'dbx_lng_resolve_file')
58 ? dbx_lng_resolve_file(
$dir, $this->fd,
'fd.php',
'',
true)
59 :
$dir . $this->fd .
'.fd.php';
61 if (!$file || !is_file($file)) {
72 private function get_fd_cols(): string {
75 foreach ($this->get_fd_fields() as
$field) {
76 if (!empty(
$field[
'name']) && is_string(
$field[
'name'])) {
81 return implode(
',', $cols);
84 private function get_fd_grid_cols(): string {
87 foreach ($this->get_fd_fields() as
$field) {
88 if (empty(
$field[
'name'])) {
92 $name = (string)
$field[
'name'];
93 if (str_starts_with($name,
'_')) {
97 $type =
$field[
'type'] ??
'text';
98 $gridType = method_exists($this->oDB,
'map_dd_type_to_grid_type')
99 ? $this->oDB->map_dd_type_to_grid_type((
string) $type)
102 $label = trim((
string)(
$field[
'label'] ??
''));
103 $label = str_replace(array(
':',
'[',
']'),
'-', $label);
109 if (!empty(
$field[
'group']) && is_string(
$field[
'group'])) {
110 $group =
'@' . trim(
$field[
'group']);
113 $protect = isset(
$field[
'protect']) ? (string)
$field[
'protect'] :
'0';
115 if ($protect ===
'2') {
117 } elseif ($protect ===
'1') {
121 $cols[] = $name .
'[' . $label .
']:' . $gridType . $suffix . $group;
124 return implode(
',', $cols);
128 private function sort_lkw(){
133 $server_time = (new \DateTime())->format(
'Y-m-d H:i:s.v');
135 $rwhere =
'TRACTOR > " "';
136 $flds = $this->get_fd_cols();
141 $field = $_GET[
'field'] ??
'';
142 $dir = $_GET[
'dir'] ??
'asc';
145 if(!preg_match(
'/^[a-zA-Z0-9_]+$/',
$field)){
149 $dir = strtolower(
$dir) ===
'desc' ?
'DESC' :
'ASC';
152 $dir = (
$dir ===
'ASC') ?
'DESC' :
'ASC';
153 $rsort =
"TIPO {$dir}";
155 $rsort =
"TIPO DESC, {$field} {$dir}";
160 $rows = $oDB->select(
171 if(!is_array($rows)){
176 dbx()->debug(
"count=($count) resort=($rsort)");
178 dbx()->json_response(array(
181 'rows' => array_values($rows),
182 'server_time' => $server_time,
188 private function read_lkw(){
193 $server_time = (new \DateTime())->format(
'Y-m-d H:i:s.v');
195 $rwhere =
'TRACTOR > " "';
196 $flds = $this->get_fd_cols();
200 $rsort =
'TIPO DESC, d2_carga_region ASC, TRACTOR ASC';
203 $rows = $oDB->select(
214 if(!is_array($rows)){
220 dbx()->json_response(array(
223 'rows' => array_values($rows),
224 'server_time' => $server_time,
230 private function save_lkw(){
233 if (isset($_POST[
'rows'])) {
234 $post = $_POST[
'rows'];
236 $this->json(
false,
"Keine rows übergeben");
239 foreach ($post as $no => $record) {
240 dbx()->debug(
"record=",$record);
241 if(!empty($record[
'id'])){
243 $id = intval($record[
'id']);
244 $ok = $this->oDB->update($this->dd,$record,$id);
245 if ($ok) $new_rec=$this->oDB->select1($dd,$id);
246 dbx()->debug(
"WRITE-LKW ok=($ok)= id=($id) New rec=",$new_rec);
272 private function delete_lkw(){
274 $id = intval($_POST[
'id'] ?? 0);
277 $this->json(
false,
"Keine ID übergeben");
280 $ok = $this->oDB->delete($this->dd,$id);
287 private function json(
bool $success,
string $msg=
""){
288 header(
'Content-Type: application/json; charset=utf-8');
292 ],JSON_UNESCAPED_UNICODE);
300 $run =
dbx()->get_modul_var(
'dbx_run2',
'create_tab',
'parameter');
301 dbx()->debug(
"myLKW_list run work=($run)");
306 return $this->create_tab();
326 return "Unbekannte Aktion ($run)";