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);
46 'extra_attrs' =>
'data-dbx="grid-search"',
50 dbx()->debug(
"grid_cols=($cols)");
52 $content=$oTPL->get_tpl(
'modul|report-lkw',$data);
56 private function get_fd_fields(): array {
58 $file = function_exists(
'dbx_lng_resolve_file')
60 :
$dir . $this->fd .
'.fd.php';
73 private function get_fd_cols(): string {
76 foreach ($this->get_fd_fields() as
$field) {
77 if (!empty(
$field[
'name']) && is_string(
$field[
'name'])) {
82 return implode(
',', $cols);
85 private function get_fd_grid_cols(): string {
88 foreach ($this->get_fd_fields() as
$field) {
89 if (empty(
$field[
'name'])) {
93 $name = (string)
$field[
'name'];
94 if (str_starts_with($name,
'_')) {
98 $type =
$field[
'type'] ??
'text';
99 $gridType = method_exists($this->
oDB,
'map_dd_type_to_grid_type')
100 ? $this->
oDB->map_dd_type_to_grid_type((
string) $type)
103 $label = trim((
string)(
$field[
'label'] ??
''));
104 $label = str_replace(array(
':',
'[',
']'),
'-', $label);
110 if (!empty(
$field[
'group']) && is_string(
$field[
'group'])) {
111 $group =
'@' . trim(
$field[
'group']);
114 $protect = isset(
$field[
'protect']) ? (string)
$field[
'protect'] :
'0';
116 if ($protect ===
'2') {
118 } elseif ($protect ===
'1') {
122 $cols[] = $name .
'[' . $label .
']:' . $gridType . $suffix . $group;
125 return implode(
',', $cols);
129 private function sort_lkw(){
134 $server_time = (new \DateTime())->format(
'Y-m-d H:i:s.v');
136 $rwhere =
'TRACTOR > " "';
137 $flds = $this->get_fd_cols();
146 if(!preg_match(
'/^[a-zA-Z0-9_]+$/',
$field)){
150 $dir = strtolower(
$dir) ===
'desc' ?
'DESC' :
'ASC';
153 $dir = (
$dir ===
'ASC') ?
'DESC' :
'ASC';
154 $rsort =
"TIPO {$dir}";
156 $rsort =
"TIPO DESC, {$field} {$dir}";
161 $rows = $oDB->select(
172 if(!is_array(
$rows)){
177 dbx()->debug(
"count=($count) resort=($rsort)");
179 dbx()->json_response(array(
182 'rows' => array_values(
$rows),
183 'server_time' => $server_time,
189 private function read_lkw(){
194 $server_time = (new \DateTime())->format(
'Y-m-d H:i:s.v');
196 $rwhere =
'TRACTOR > " "';
197 $flds = $this->get_fd_cols();
201 $rsort =
'TIPO DESC, d2_carga_region ASC, TRACTOR ASC';
204 $rows = $oDB->select(
215 if(!is_array(
$rows)){
221 dbx()->json_response(array(
224 'rows' => array_values(
$rows),
225 'server_time' => $server_time,
231 private function save_lkw(){
234 if (isset(
$_POST[
'rows'])) {
237 $this->json(
false,
"Keine rows übergeben");
240 foreach ($post as $no => $record) {
241 dbx()->debug(
"record=",$record);
242 if(!empty($record[
'id'])){
244 $id = intval($record[
'id']);
245 $ok = $this->
oDB->update($this->dd,$record,$id);
246 if (
$ok) $new_rec=$this->
oDB->select1(
$dd,$id);
247 dbx()->debug(
"WRITE-LKW ok=($ok)= id=($id) New rec=",$new_rec);
273 private function delete_lkw(){
275 $id = intval(
$_POST[
'id'] ?? 0);
278 $this->json(
false,
"Keine ID übergeben");
281 $ok = $this->
oDB->delete($this->dd,$id);
288 private function json(
bool $success,
string $msg=
""){
289 header(
'Content-Type: application/json; charset=utf-8');
293 ],JSON_UNESCAPED_UNICODE);
301 $run =
dbx()->get_modul_var(
'dbx_run2',
'create_tab',
'parameter');
302 dbx()->debug(
"myLKW_list run work=($run)");
307 return $this->create_tab();
327 return "Unbekannte Aktion ($run)";
dbx_lng_resolve_file(string $dir, string $name, string $ext, string $lng='', bool $fallback=true)
Datei mit Sprachsuffix aufloesen: name_lng.ext mit Fallback name.ext.