-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodify_presets.php
More file actions
864 lines (819 loc) · 41.5 KB
/
modify_presets.php
File metadata and controls
864 lines (819 loc) · 41.5 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
<?php
/**
* oneforall - modify_presets.php
* Preset Manager — list, load, save, import, export
* @version 1.2.0 @license GNU GPL @platform WBCE 1.6.5+
*/
require('../../config.php');
$inc_path = dirname(__FILE__);
require_once($inc_path.'/info.php');
require_once(WB_PATH.'/framework/class.admin.php');
$admin = new admin('Modules', 'module_view', false, false);
if(LANGUAGE_LOADED) {
require_once($inc_path.'/languages/EN.php');
if(file_exists($inc_path.'/languages/'.LANGUAGE.'.php')) {
require_once($inc_path.'/languages/'.LANGUAGE.'.php');
}
}
$L = $MOD_ONEFORALL[$mod_name];
$page_id = (int)($_POST['page_id'] ?? $_GET['page_id'] ?? 0);
$section_id = (int)($_POST['section_id'] ?? $_GET['section_id'] ?? 0);
if(!$page_id || !$section_id) {
$admin->print_header();
$admin->print_error('Missing page_id or section_id.', ADMIN_URL.'/pages/index.php');
}
if(!$admin->isAdmin()) {
$admin->print_header();
$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS'],
ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
}
$presets_dir = $inc_path.'/presets';
$presets_dir_url = WB_URL.'/modules/'.$mod_name.'/modify_presets.php';
$return_url = $presets_dir_url.'?page_id='.$page_id.'§ion_id='.$section_id;
$action = $_POST['action'] ?? $_GET['action'] ?? '';
// ── Export preset as JSON — BEFORE print_header() ─────────────────────────
if($action === 'export' && !empty($_POST['preset_file'])) {
$file = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_POST['preset_file']);
$path = $presets_dir.'/'.$file.'.json';
if(!file_exists($path)) { header('Location: '.$return_url.'&msg=not_found'); exit; }
$data = json_decode(file_get_contents($path), true);
if(!$data) { header('Location: '.$return_url.'&msg=invalid'); exit; }
$filename = date('Y-m-d').'_'.$mod_name.'_preset_'.$file;
while(ob_get_level()) ob_end_clean();
header('Content-Type: application/json; charset=utf-8');
header('Content-Disposition: attachment; filename='.$filename.'.json');
header('Cache-Control: no-cache, no-store, must-revalidate');
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
// ── Export current config as JSON — BEFORE print_header() ─────────────────
// ── Globaler Export (fields section_id=0 + general_settings) ─────────────
if($action === 'export_global') {
$fields_global = $database->get_array(
"SELECT `field_id`,`position`,`type`,`extra`,`name`,`label`,`template`
FROM `{TP}mod_{$mod_name}_fields` WHERE `section_id` = 0 ORDER BY `position`"
);
$general = $database->get_array(
"SELECT `name`,`value` FROM `{TP}mod_{$mod_name}_general_settings` ORDER BY `id`"
);
$output = [
'export_module' => [
'default_mod_name' => 'oneforall',
'mod_name' => $mod_name,
'module_version' => $module_version,
'export_type' => 'global',
'comment' => 'Global export: fields (section_id=0) + general_settings',
],
'export_fields' => ['name' => 'fields', 'data' => $fields_global],
'export_general_settings' => ['name' => 'general_settings', 'data' => $general],
];
$filename = date('Y-m-d').'_'.$mod_name.'_global_export';
while(ob_get_level()) ob_end_clean();
header('Content-Type: application/json; charset=utf-8');
header('Content-Disposition: attachment; filename='.$filename.'.json');
header('Cache-Control: no-cache, no-store, must-revalidate');
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
if($action === 'export_current') {
$preset_name = trim($_POST['preset_name'] ?? 'My Preset');
$preset_desc = trim($_POST['preset_description'] ?? '');
$fields = $database->get_array(
"SELECT `field_id`,`position`,`type`,`extra`,`name`,`label`,`template`
FROM `{TP}mod_{$mod_name}_fields`
WHERE `section_id` = '$section_id' OR `section_id` = 0
ORDER BY `position`"
);
$ps = $database->get_array(
"SELECT `section_id`,`page_id`,`header`,`item_loop`,`footer`,
`item_header`,`item_footer`,`items_per_page`,`resize`,
`lightbox2`,`img_section`
FROM `{TP}mod_{$mod_name}_page_settings` WHERE `section_id` = '$section_id'"
);
$output = [
'export_module' => [
'default_mod_name' => 'oneforall',
'mod_name' => $mod_name,
'module_version' => $module_version,
'preset_name' => $preset_name,
'preset_description' => $preset_desc,
'preset_icon' => 'cog',
'comment' => 'Exported from WBCE OFA Preset Manager',
],
'export_fields' => ['name' => 'fields', 'data' => $fields],
'export_page_settings' => ['name' => 'page_settings', 'data' => $ps],
];
$filename = date('Y-m-d').'_'.$mod_name.'_preset';
while(ob_get_level()) ob_end_clean();
header('Content-Type: application/json; charset=utf-8');
header('Content-Disposition: attachment; filename='.$filename.'.json');
header('Cache-Control: no-cache, no-store, must-revalidate');
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
// ── All other actions need print_header() ─────────────────────────────────
$admin->print_header();
$msg_success = '';
$msg_error = '';
$url_msg = $_GET['msg'] ?? '';
if($url_msg === 'not_found') $msg_error = $L['TXT_PRESET_MSG_NOT_FOUND'];
if($url_msg === 'invalid') $msg_error = $L['TXT_PRESET_MSG_INVALID'];
if($url_msg === 'default_set') $msg_success = $L['TXT_PRESET_MSG_DEFAULT'];
// ── Set default preset ─────────────────────────────────────────────────────
if($action === 'set_default' && !empty($_POST['preset_file'])) {
$file = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_POST['preset_file']);
if(file_exists($presets_dir.'/'.$file.'.json')) {
if(file_put_contents($presets_dir.'/default.txt', $file) !== false) {
header('Location: '.$return_url.'&msg=default_set&preset='.urlencode($file));
exit;
} else {
$msg_error = 'Could not write default.txt — check file permissions.';
}
} else {
$msg_error = $L['TXT_PRESET_MSG_NOT_FOUND'];
}
}
// ── Load preset: Step 1 — Diff anzeigen ──────────────────────────────────
if($action === 'load_confirm' && !empty($_POST['preset_file'])) {
$file = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_POST['preset_file']);
$path = $presets_dir.'/'.$file.'.json';
$import = file_exists($path) ? json_decode(file_get_contents($path), true) : null;
if(!$import) {
$msg_error = $L['TXT_PRESET_MSG_NOT_FOUND'];
} else {
$cur_fields = $database->get_array(
"SELECT * FROM `{TP}mod_{$mod_name}_fields`
WHERE `section_id` = '$section_id' OR `section_id` = 0 ORDER BY position"
);
$cur_by_name = [];
foreach($cur_fields as $f) $cur_by_name[$f['name']] = $f;
$preset_fields = $import['export_fields']['data'] ?? [];
$preset_names = array_column($preset_fields, 'name');
$diff_keep = $diff_add = $diff_remove = [];
foreach($preset_fields as $pf) {
if(isset($cur_by_name[$pf['name']])) $diff_keep[] = $pf;
else $diff_add[] = $pf;
}
foreach($cur_by_name as $name => $cf) {
if(!in_array($name, $preset_names)) $diff_remove[] = $cf;
}
$_SESSION['ofa_load_confirm'] = [
'file' => $file,
'import' => $import,
];
$show_diff = true;
$diff_preset = $import['export_module']['preset_name'] ?? $file;
$diff_is_legacy = ($import['export_module']['export_type'] ?? '') === 'legacy'
|| empty($import['export_module']['export_type']);
}
}
// ── Load preset: Step 2 — Ausführen nach Bestätigung ─────────────────────
if($action === 'load' && !empty($_POST['preset_file']) && !empty($_SESSION['ofa_load_confirm'])) {
$confirmed = $_SESSION['ofa_load_confirm'];
$file = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_POST['preset_file']);
if($confirmed['file'] === $file) {
$import = $confirmed['import'];
// Alte item_fields dieser Section löschen — field_ids werden durch neue ersetzt
$database->query(
"DELETE FROM `{TP}mod_{$mod_name}_item_fields`
WHERE `item_id` IN (
SELECT `item_id` FROM `{TP}mod_{$mod_name}_items` WHERE `section_id` = '$section_id'
)"
);
// Globale Felder (section_id=0) existieren noch → für jede andere Section
// die noch keine eigenen Felder hat, section-spezifische Kopien anlegen
$global_count = $database->get_one(
"SELECT COUNT(*) FROM `{TP}mod_{$mod_name}_fields` WHERE `section_id` = 0"
);
if($global_count) {
// Alle Sections die dieses Modul nutzen und noch keine eigenen Felder haben
$other_sections = $database->get_array(
"SELECT DISTINCT s.section_id FROM `{TP}sections` s
WHERE s.module = '$mod_name' AND s.section_id != '$section_id'
AND NOT EXISTS (
SELECT 1 FROM `{TP}mod_{$mod_name}_fields` f
WHERE f.section_id = s.section_id
)"
);
foreach($other_sections as $os) {
$database->query(
"INSERT INTO `{TP}mod_{$mod_name}_fields`
(`section_id`,`position`,`type`,`extra`,`name`,`label`,`template`)
SELECT '".$os['section_id']."', `position`,`type`,`extra`,`name`,`label`,`template`
FROM `{TP}mod_{$mod_name}_fields` WHERE `section_id` = 0"
);
}
// Globale Felder jetzt löschen — alle Sections haben eigene Kopien
$database->query("DELETE FROM `{TP}mod_{$mod_name}_fields` WHERE `section_id` = 0");
}
// Jetzt alle section-spezifischen Felder dieser Section löschen
$database->query(
"DELETE FROM `{TP}mod_{$mod_name}_fields` WHERE `section_id` = '$section_id'"
);
foreach($import['export_fields']['data'] ?? [] as $row) {
$type = $row['type'] ?? 'text';
$extra = $row['extra'] ?? '';
// media-Felder: Standardverzeichnis vorbelegen wenn leer
if($type === 'media' && empty(trim($extra))) {
$extra = '/'.$mod_name.'/images/';
}
$type = $database->escapeString($type);
$extra = $database->escapeString($extra);
$name = $database->escapeString($row['name'] ?? '');
$label = $database->escapeString($row['label'] ?? '');
$template = $database->escapeString($row['template'] ?? '');
$position = (int)($row['position'] ?? 1);
$database->query(
"INSERT INTO `{TP}mod_{$mod_name}_fields`
(`section_id`,`position`,`type`,`extra`,`name`,`label`,`template`)
VALUES ('$section_id','$position','$type','$extra','$name','$label','$template')"
);
$new_field_id = $database->getLastInsertId();
$database->query(
"INSERT IGNORE INTO `{TP}mod_{$mod_name}_item_fields` (`item_id`, `field_id`)
SELECT `item_id`, '$new_field_id' FROM `{TP}mod_{$mod_name}_items` WHERE `section_id` = '$section_id'"
);
}
if(!empty($import['export_page_settings']['data'])) {
$database->query(
"DELETE FROM `{TP}mod_{$mod_name}_page_settings` WHERE `section_id` = '$section_id'"
);
// Preset speichert als [{name:X, value:Y}] Array — in Key/Value umwandeln
$ps_data = $import['export_page_settings']['data'];
$row = [];
// Prüfen ob name/value Format oder direktes Format
if(isset($ps_data[0]['name']) && isset($ps_data[0]['value'])) {
foreach($ps_data as $ps_item) {
$row[$ps_item['name']] = $ps_item['value'];
}
} else {
$row = $ps_data[0] ?? [];
}
$header = $database->escapeString($row['header'] ?? '');
$item_loop = $database->escapeString($row['item_loop'] ?? '');
$footer = $database->escapeString($row['footer'] ?? '');
$item_header = $database->escapeString($row['item_header'] ?? '');
$item_footer = $database->escapeString($row['item_footer'] ?? '');
$ipp = (int)($row['items_per_page'] ?? 0);
$resize = (int)($row['resize'] ?? 100);
$lightbox2 = $database->escapeString($row['lightbox2'] ?? 'detail');
$img_section = $database->escapeString($row['img_section'] ?? '0');
$database->query(
"INSERT INTO `{TP}mod_{$mod_name}_page_settings`
(`section_id`,`page_id`,`header`,`item_loop`,`footer`,
`item_header`,`item_footer`,`items_per_page`,`resize`,
`lightbox2`,`img_section`)
VALUES ('$section_id','$page_id','$header','$item_loop','$footer',
'$item_header','$item_footer','$ipp','$resize',
'$lightbox2','$img_section')"
);
}
unset($_SESSION['ofa_load_confirm']);
// Sync-Checkbox deaktivieren — Preset-Templates sollen nicht überschrieben werden
$_SESSION[$mod_name]['sync_type_template'] = '';
$preset_name = htmlspecialchars($import['export_module']['preset_name'] ?? $file);
$ps_url = WB_URL.'/modules/'.$mod_name.'/modify_page_settings.php'
.'?page_id='.$page_id.'§ion_id='.$section_id
.'&preset_loaded='.urlencode($preset_name);
header('Location: '.$ps_url);
exit;
}
}
// ── Delete custom preset ───────────────────────────────────────────────────
if($action === 'delete' && !empty($_POST['preset_file'])) {
$file = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_POST['preset_file']);
$starters = ['grid', 'list', 'slider', 'timeline',
'team', 'menu', 'events', 'downloads', 'faq', 'jobs',
'flipcatalog', 'datatable', 'timetable'];
if(in_array($file, $starters)) {
$msg_error = 'Starter presets cannot be deleted.';
} else {
$path = $presets_dir.'/'.$file.'.json';
if(file_exists($path)) { unlink($path); $msg_success = $L['TXT_PRESET_MSG_DELETED']; }
else { $msg_error = $L['TXT_PRESET_MSG_NOT_FOUND']; }
}
}
// ── Import Step 1: upload + validate ──────────────────────────────────────
$show_import_form = false;
if($action === 'import_file' && !empty($_FILES['preset_json']['tmp_name'])) {
$raw = file_get_contents($_FILES['preset_json']['tmp_name']);
$import = json_decode($raw, true);
// Altes Format erkennen: export_module vorhanden aber kein export_type und kein preset_name
// (Export aus OFA <= 1.1.x hatte export_module mit comment/mod_name aber kein preset_name)
$is_old_format = !empty($import)
&& !empty($import['export_module'])
&& empty($import['export_module']['export_type'])
&& empty($import['export_module']['preset_name']);
if(!$import) {
$msg_error = $L['TXT_PRESET_MSG_INVALID'];
} elseif(empty($import['export_module']) || $is_old_format) {
// ── Altes Ex/Import Format erkennen ──────────────────────────────
if(!empty($import['export_fields']) || !empty($import['export_page_settings'])) {
$msg_warning = 'Altes Export-Format erkannt (OFA < 1.2.x). Felder und Layout-Einstellungen werden als Preset gespeichert und können dann gezielt auf eine Seite angewendet werden. Andere OFA-Abschnitte werden nicht beeinflusst.';
// Konvertieren in neues Format
$import['export_module'] = [
'default_mod_name' => 'oneforall',
'mod_name' => $mod_name,
'module_version' => $module_version ?? '1.x',
'preset_name' => 'Importiert (altes Format)',
'preset_description' => 'Automatisch konvertiert aus altem OFA Ex/Import Format',
'export_type' => 'legacy',
'comment' => 'Converted from legacy OFA export format',
];
// general_settings direkt importieren wenn vorhanden
if(!empty($import['export_general_settings']['data'])) {
foreach($import['export_general_settings']['data'] as $setting) {
$name = $database->escapeString($setting['name']);
$value = $database->escapeString($setting['value']);
$database->query(
"UPDATE `{TP}mod_{$mod_name}_general_settings` SET `value` = '$value' WHERE `name` = '$name'"
);
}
$msg_warning .= ' Allgemeine Einstellungen wurden übernommen.';
unset($import['export_general_settings']);
}
$_SESSION['ofa_preset_import'] = [
'export_module' => $import['export_module'],
'export_fields' => $import['export_fields'] ?? [],
'export_page_settings' => $import['export_page_settings'] ?? [],
'is_legacy' => true,
];
$_SESSION['ofa_preset_import_name'] = 'Importiert (altes Format)';
$_SESSION['ofa_preset_import_desc'] = 'Konvertiert aus altem OFA Ex/Import Format';
$show_import_form = true;
} else {
$msg_error = $L['TXT_PRESET_MSG_INVALID'];
}
} elseif(!empty($import['export_module']['export_type']) && $import['export_module']['export_type'] === 'global') {
// ── Globaler Import (fields section_id=0 + general_settings) ─────
$msg_info = '';
// Fields global importieren
if(!empty($import['export_fields']['data'])) {
$database->query("DELETE FROM `{TP}mod_{$mod_name}_fields` WHERE `section_id` = 0");
foreach($import['export_fields']['data'] as $row) {
$database->query(
"INSERT INTO `{TP}mod_{$mod_name}_fields`
(`section_id`,`position`,`type`,`extra`,`name`,`label`,`template`)
VALUES (0,?,?,?,?,?,?)",
[
(int)($row['position'] ?? 1),
$row['type'] ?? 'text',
$row['extra'] ?? '',
$row['name'] ?? '',
$row['label'] ?? '',
$row['template'] ?? '',
]
);
}
$msg_info .= count($import['export_fields']['data']).' Felder global importiert. ';
}
// General settings importieren
if(!empty($import['export_general_settings']['data'])) {
foreach($import['export_general_settings']['data'] as $setting) {
$database->query(
"UPDATE `{TP}mod_{$mod_name}_general_settings` SET `value` = ? WHERE `name` = ?",
[$setting['value'], $setting['name']]
);
}
$msg_info .= 'Allgemeine Einstellungen übernommen.';
}
$msg_success = $msg_info ?: $L['TXT_PRESET_MSG_IMPORTED'];
} else {
// ── Normales Preset-Format ────────────────────────────────────────
$_SESSION['ofa_preset_import'] = [
'export_module' => $import['export_module'],
'export_fields' => $import['export_fields'] ?? [],
'export_page_settings' => $import['export_page_settings'] ?? [],
];
$_SESSION['ofa_preset_import_name'] = $import['export_module']['preset_name'] ?? 'My Preset';
$_SESSION['ofa_preset_import_desc'] = $import['export_module']['preset_description'] ?? '';
$show_import_form = true;
}
}
// ── Import Step 2: save with name + description ────────────────────────────
if($action === 'import_save' && !empty($_SESSION['ofa_preset_import'])) {
$import = $_SESSION['ofa_preset_import'];
$pname_raw = trim($_POST['import_name'] ?? 'custom');
$pdesc = trim($_POST['import_desc'] ?? '');
$pname_file = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $pname_raw);
$import['export_module']['preset_name'] = $pname_raw;
$import['export_module']['preset_description'] = $pdesc;
file_put_contents(
$presets_dir.'/'.$pname_file.'.json',
json_encode($import, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
);
unset($_SESSION['ofa_preset_import'], $_SESSION['ofa_preset_import_name'], $_SESSION['ofa_preset_import_desc']);
$msg_success = $L['TXT_PRESET_MSG_IMPORTED'];
}
// ── Restore default ────────────────────────────────────────────────────────
if($action === 'restore_default') {
$display_name = $_SESSION['DISPLAY_NAME'] ?? 'Administrator';
$_header =
'<h1>Hello '.$display_name.'</h1>
<p>This is your module '.$mod_name.' speaking:</p>
<p>Before taking off there have to been made some modifications.</p>
<h2>Adding custom fields</h2>
<ol>
<li>Login to your WBCE installation.</li>
<li>Add a new page with page type "'.$mod_name.'".</li>
<li>Go to the "Fields Settings" and add the customized fields you intend to collect the data.</li>
<li>Select the field type and modify the field templates to fit your needs.</li>
<li>Note that every field must have a unique field name. Allowed characters are a-z, A-Z, 0-9, . (dot), _ (underscore) and - (hyphen).</li>
<li>Consider the displayed placeholders. You will need them later when adding the item templates.</li>
</ol>
<h2>Adding item templates</h2>
<p>Create your own item templates using the generated and general placeholders:</p>
<ol>
<li>Go to the "Page Settings" and use the mentioned placeholders in your templates to view the items just the way you want.</li>
<li>Replace this text by them HTML code of your template.</li>
<li>[PLACEHOLDERS] are uppercase and enclosed by square brackets.</li>
<li>For a list of more general placeholders to accomplish your template click the "Help"-button on top of the "Page Settings" page.</li>
<li>Add an item or two, enter some data and have fun!</li>
</ol>';
$_item_loop =
'<div class="mod_'.$mod_name.'_item_loop_f">
[THUMB]
<h3 class="mod_'.$mod_name.'_main_title_f"><a href="[LINK]">[TITLE]</a></h3>
<!-- ADD YOUR PLACEHOLDERS LIKE THIS: -->
[FIELD_1]
[FIELD_2]
</div>';
$_footer =
'<table class="mod_'.$mod_name.'_pagination_f" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
<tr>
<td width="35%" align="left">[PREVIOUS_PAGE_LINK]</td>
<td width="30%" align="center">[TXT_ITEM] [OF] </td>
<td width="35%" align="right">[NEXT_PAGE_LINK]</td>
</tr>
</table>';
$_item_footer =
'<div class="mod_'.$mod_name.'_item_f">
[THUMBS]
<h2 class="mod_'.$mod_name.'_item_title_f">[TITLE]</h2>
<!-- ADD YOUR PLACEHOLDERS LIKE THIS: -->
[FIELD_1]
[FIELD_2]
</div>
<div class="mod_'.$mod_name.'_prev_next_links_f">
[PREVIOUS] | <a href="[BACK]">[TXT_BACK]</a> | [NEXT]
</div>';
// Section-spezifische Felder löschen (section_id=0 = global, bleibt)
$database->query(
"DELETE FROM `{TP}mod_{$mod_name}_fields` WHERE `section_id` = ?",
[$section_id]
);
$database->query(
"DELETE FROM `{TP}mod_{$mod_name}_page_settings` WHERE `section_id` = ?",
[$section_id]
);
$database->query(
"INSERT INTO `{TP}mod_{$mod_name}_page_settings`
(`section_id`,`page_id`,`header`,`item_loop`,`footer`,
`item_header`,`item_footer`,`items_per_page`,`resize`,`lightbox2`,`img_section`)
VALUES (?,?,?,?,?,?,?,?,?,?,?)",
[$section_id,$page_id,$_header,$_item_loop,$_footer,$_header,$_item_footer,0,100,'detail','0']
);
$msg_success = $L['TXT_PRESET_MSG_RESTORED'];
}
// ── Load all presets ───────────────────────────────────────────────────────
$starters = ['grid', 'list', 'slider', 'timeline',
'team', 'menu', 'events', 'downloads', 'faq', 'jobs',
'flipcatalog', 'datatable', 'timetable'];
$default_preset = '';
$default_file = $presets_dir.'/default.txt';
if(file_exists($default_file)) { $default_preset = trim(file_get_contents($default_file)); }
$presets_starter = [];
$presets_custom = [];
foreach(glob($presets_dir.'/*.json') as $file) {
$key = basename($file, '.json');
$data = json_decode(file_get_contents($file), true);
if(!$data) continue;
$preset = [
'file' => $key,
'name' => $data['export_module']['preset_name'] ?? $key,
'description'=> $data['export_module']['preset_description'] ?? '',
'icon' => $data['export_module']['preset_icon'] ?? 'cog',
'is_default' => ($key === $default_preset),
'fields' => count($data['export_fields']['data'] ?? []),
];
if(in_array($key, $starters)) {
$presets_starter[$key] = $preset;
} else {
$presets_custom[$key] = $preset;
}
}
$icon_map = [
'th-large'=>'th-large','list'=>'list','film'=>'film','clock-o'=>'clock-o',
'cog'=>'cog','users'=>'users','cutlery'=>'cutlery','calendar'=>'calendar',
'download'=>'download','question-circle'=>'question-circle','briefcase'=>'briefcase',
'book'=>'book','table'=>'table',
];
// ── HTML Output ────────────────────────────────────────────────────────────
?>
<!-- CSS in backend.css -->
<div class="ofa-pm">
<h2><i class="fa fa-sliders"></i> <?php echo $L['TXT_PRESET_MANAGER']; ?>
<a href="#" onclick="window.open('<?php echo WB_URL; ?>/modules/<?php echo $mod_name; ?>/presets_help.php?page_id=<?php echo $page_id; ?>§ion_id=<?php echo $section_id; ?>','ofa_presets_help','width=860,height=700,scrollbars=yes,resizable=yes'); return false;"
style="margin-left:auto;background:#fff;color:#1a6ca8;padding:.25em .75em;border-radius:3px;font-size:.75em;font-weight:700;text-decoration:none;display:inline-flex;align-items:center;gap:.35em;">
<i class="fa fa-question-circle"></i> Hilfe
</a>
</h2>
<?php if($msg_success): ?>
<div class="ofa-pm-msg ofa-pm-msg-ok"><i class="fa fa-check-circle"></i> <?php echo $msg_success; ?></div>
<?php endif; ?>
<?php if(!empty($msg_warning)): ?>
<div class="ofa-pm-msg ofa-pm-msg-warn" style="background:#fff8e1;border-color:#f0c040;color:#7a6000;"><i class="fa fa-exclamation-triangle"></i> <?php echo $msg_warning; ?></div>
<?php endif; ?>
<?php if($msg_error): ?>
<div class="ofa-pm-msg ofa-pm-msg-err"><i class="fa fa-exclamation-triangle"></i> <?php echo $msg_error; ?></div>
<?php endif; ?>
<!-- Import Step 2 Form -->
<?php if(!empty($show_import_form) && !empty($_SESSION['ofa_preset_import'])): ?>
<div class="ofa-pm-import-form">
<h3><i class="fa fa-upload"></i> <?php echo $L['TXT_PRESET_IMPORT_NAME']; ?></h3>
<form method="post">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
<input type="hidden" name="action" value="import_save">
<div class="ofa-pm-import-grid">
<label><?php echo $L['TXT_PRESET_NAME']; ?>:</label>
<input type="text" name="import_name"
value="<?php echo htmlspecialchars($_SESSION['ofa_preset_import_name'] ?? ''); ?>" required>
<label><?php echo $L['TXT_PRESET_DESC']; ?>:</label>
<input type="text" name="import_desc"
value="<?php echo htmlspecialchars($_SESSION['ofa_preset_import_desc'] ?? ''); ?>">
<span></span>
<div style="display:flex;gap:.5em;margin-top:.4em">
<button type="submit" class="ofa-pm-btn ofa-pm-btn-load">
<i class="fa fa-save"></i> <?php echo $TEXT['SAVE']; ?>
</button>
<a href="<?php echo $return_url; ?>" class="ofa-pm-btn ofa-pm-btn-json">
<?php echo $TEXT['CANCEL']; ?>
</a>
</div>
</div>
</form>
</div>
<?php endif; ?>
<!-- Top Action Panels: Save + Global Export + Import -->
<div class="ofa-pm-panels">
<!-- Save current as preset -->
<div class="ofa-pm-panel">
<h3><i class="fa fa-download"></i> <?php echo $L['TXT_PRESET_SAVE_CURRENT']; ?></h3>
<form method="post">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
<input type="hidden" name="action" value="export_current">
<div class="ofa-pm-form-row">
<label><?php echo $L['TXT_PRESET_NAME']; ?>:</label>
<input type="text" name="preset_name" value="My Preset" required>
</div>
<div class="ofa-pm-form-row">
<label><?php echo $L['TXT_PRESET_DESC']; ?>:</label>
<input type="text" name="preset_description" value="">
</div>
<button type="submit" class="ofa-pm-btn ofa-pm-btn-load" style="margin-top:.35em">
<i class="fa fa-download"></i> Download JSON
</button>
<div class="ofa-pm-hint"><?php echo $L['TXT_PRESET_FIELDS_ONLY']; ?></div>
</form>
</div>
<!-- Globaler Export -->
<div class="ofa-pm-panel">
<h3><i class="fa fa-globe"></i> Globaler Export</h3>
<form method="post">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
<input type="hidden" name="action" value="export_global">
<p style="font-size:.85em;color:#555;margin:.25em 0 .75em;">
Exportiert globale Felder (section_id=0) und allgemeine Einstellungen.<br>
Geeignet als Website-Backup oder für die Migration auf eine andere Installation.
</p>
<button type="submit" class="ofa-pm-btn ofa-pm-btn-json">
<i class="fa fa-download"></i> Global Export JSON
</button>
</form>
</div>
<!-- Import preset -->
<div class="ofa-pm-panel">
<h3><i class="fa fa-upload"></i> <?php echo $L['TXT_PRESET_IMPORT']; ?></h3>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
<input type="hidden" name="action" value="import_file">
<div class="ofa-pm-form-row">
<input type="file" name="preset_json" accept=".json" style="flex:1">
</div>
<button type="submit" class="ofa-pm-btn ofa-pm-btn-load" style="margin-top:.35em">
<i class="fa fa-upload"></i> <?php echo $L['TXT_PRESET_IMPORT']; ?>
</button>
<div class="ofa-pm-hint"><?php echo $L['TXT_PRESET_IMPORT_HINT']; ?></div>
</form>
</div>
</div>
<?php if(!empty($show_diff) && isset($diff_keep, $diff_add, $diff_remove)): ?>
<div style="background:#fff8e1;border:1px solid #f0c040;border-radius:6px;padding:1em 1.25em;margin-bottom:1.25rem;">
<h3 style="margin:0 0 .75em;color:#c7a800;font-size:1em;">
<i class="fa fa-exchange"></i>
Preset "<?php echo htmlspecialchars($diff_preset); ?>" — Feldvergleich
</h3>
<?php if(!empty($diff_is_legacy)): ?>
<div style="background:#fff3cd;border:1px solid #f0ad4e;border-radius:4px;padding:.75em 1em;margin-bottom:1em;font-size:.88em;">
<p style="margin:0 0 .5em;font-weight:700;color:#856404;">
<i class="fa fa-info-circle"></i> Hinweis: Altes Export-Format (OFA < 1.2.x)
</p>
<p style="margin:0 0 .4em;color:#5a4000;">
Dieses Preset wurde mit einer älteren OFA-Version exportiert. Die Felder werden mit
<strong>neuen IDs</strong> angelegt — die Platzhalter in den Layout-Templates
(z. B. <code>[FELD_1]</code>, <code>[FIELD_1]</code>) stimmen danach
<strong>nicht mehr</strong> mit den neuen IDs überein.
</p>
<p style="margin:0;color:#5a4000;">
<i class="fa fa-wrench"></i> <strong>Nach dem Import bitte prüfen:</strong>
Seiteneinstellungen → Layout → Platzhalter der Felder anpassen
(neue Platzhalter werden in den Feldeinstellungen angezeigt).
</p>
</div>
<?php endif; ?>
<table style="width:100%;border-collapse:collapse;font-size:.88em;margin-bottom:.75em;">
<thead>
<tr style="border-bottom:2px solid #e0c060;">
<th style="text-align:left;padding:.3em .5em;">Feld</th>
<th style="text-align:left;padding:.3em .5em;">Typ</th>
<th style="text-align:left;padding:.3em .5em;">Aktion</th>
</tr>
</thead>
<tbody>
<?php foreach($diff_keep as $f): ?>
<tr style="background:#f0fff4;">
<td style="padding:.3em .5em;font-weight:600;"><?php echo htmlspecialchars($f['name']); ?></td>
<td style="padding:.3em .5em;color:#666;"><?php echo htmlspecialchars($f['type']); ?></td>
<td style="padding:.3em .5em;color:#1a7a42;"><i class="fa fa-check"></i> bleibt / wird aktualisiert</td>
</tr>
<?php endforeach; ?>
<?php foreach($diff_add as $f): ?>
<tr style="background:#e8f4fd;">
<td style="padding:.3em .5em;font-weight:600;"><?php echo htmlspecialchars($f['name']); ?></td>
<td style="padding:.3em .5em;color:#666;"><?php echo htmlspecialchars($f['type']); ?></td>
<td style="padding:.3em .5em;color:#1a5a9a;"><i class="fa fa-plus"></i> wird hinzugefügt</td>
</tr>
<?php endforeach; ?>
<?php foreach($diff_remove as $f): ?>
<tr style="background:#fdf0ee;">
<td style="padding:.3em .5em;font-weight:600;"><?php echo htmlspecialchars($f['name']); ?></td>
<td style="padding:.3em .5em;color:#666;"><?php echo htmlspecialchars($f['type']); ?></td>
<td style="padding:.3em .5em;color:#c0392b;"><i class="fa fa-trash"></i> wird gelöscht (inkl. Daten)</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if(!empty($diff_remove)): ?>
<p style="color:#c0392b;font-size:.85em;margin:.25em 0 .75em;">
<i class="fa fa-exclamation-triangle"></i>
<strong>Achtung:</strong> Die rot markierten Felder und alle darin gespeicherten Daten werden unwiderruflich gelöscht.
</p>
<?php endif; ?>
<div style="display:flex;gap:.5em;align-items:center;">
<form method="post">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
<input type="hidden" name="action" value="load">
<input type="hidden" name="preset_file" value="<?php echo htmlspecialchars($_SESSION['ofa_load_confirm']['file'] ?? ''); ?>">
<button type="submit" class="ofa-pm-btn ofa-pm-btn-load">
<i class="fa fa-check"></i> Preset übernehmen
</button>
</form>
<a href="<?php echo $return_url; ?>" class="ofa-pm-btn ofa-pm-btn-json">
<i class="fa fa-times"></i> Abbrechen
</a>
</div>
</div>
<?php endif; ?>
<?php
function renderPresetRow($p, $section_id, $page_id, $icon_map, $L, $is_starter) {
$icon = htmlspecialchars($icon_map[$p['icon']] ?? 'cog');
$badge = $is_starter
? '<span class="ofa-pm-badge ofa-pm-badge-starter">'.$L['TXT_PRESET_STARTER'].'</span>'
: '<span class="ofa-pm-badge ofa-pm-badge-custom">'.$L['TXT_PRESET_CUSTOM'].'</span>';
if($p['is_default']) {
$badge .= ' <span class="ofa-pm-badge ofa-pm-badge-default">★ '.$L['TXT_PRESET_DEFAULT'].'</span>';
}
echo '<tr>';
echo '<td class="ofa-pm-icon"><i class="fa fa-'.$icon.'"></i></td>';
echo '<td class="ofa-pm-info">';
echo '<div class="ofa-pm-preset-name">'.htmlspecialchars($p['name']).'</div>';
if($p['description']) echo '<div class="ofa-pm-preset-desc">'.htmlspecialchars($p['description']).'</div>';
echo '<div class="ofa-pm-meta">';
echo '<span class="ofa-pm-fields-count">'.$p['fields'].' Felder</span> ';
echo $badge;
echo '</div>';
echo '<div class="ofa-pm-actions">';
// Laden
echo '<form method="post">';
echo '<input type="hidden" name="section_id" value="'.$section_id.'">';
echo '<input type="hidden" name="page_id" value="'.$page_id.'">';
echo '<input type="hidden" name="action" value="load_confirm">';
echo '<input type="hidden" name="preset_file" value="'.htmlspecialchars($p['file']).'">';
echo '<button type="submit" class="ofa-pm-btn ofa-pm-btn-load"><i class="fa fa-download"></i> '.$L['TXT_PRESET_LOAD'].'</button>';
echo '</form>';
// JSON Export
echo '<form method="post">';
echo '<input type="hidden" name="section_id" value="'.$section_id.'">';
echo '<input type="hidden" name="page_id" value="'.$page_id.'">';
echo '<input type="hidden" name="action" value="export">';
echo '<input type="hidden" name="preset_file" value="'.htmlspecialchars($p['file']).'">';
echo '<button type="submit" class="ofa-pm-btn ofa-pm-btn-json"><i class="fa fa-file-code-o"></i> '.$L['TXT_PRESET_JSON'].'</button>';
echo '</form>';
// Set Default
if(!$p['is_default']) {
echo '<form method="post">';
echo '<input type="hidden" name="section_id" value="'.$section_id.'">';
echo '<input type="hidden" name="page_id" value="'.$page_id.'">';
echo '<input type="hidden" name="action" value="set_default">';
echo '<input type="hidden" name="preset_file" value="'.htmlspecialchars($p['file']).'">';
echo '<button type="submit" class="ofa-pm-btn ofa-pm-btn-star" title="'.htmlspecialchars($L['TXT_PRESET_SET_DEFAULT']).'">★</button>';
echo '</form>';
}
// Delete (only custom)
if(!$is_starter) {
echo '<form method="post" onsubmit="return confirm(\''.addslashes($L['TXT_PRESET_CONFIRM_DELETE']).'\')">';
echo '<input type="hidden" name="section_id" value="'.$section_id.'">';
echo '<input type="hidden" name="page_id" value="'.$page_id.'">';
echo '<input type="hidden" name="action" value="delete">';
echo '<input type="hidden" name="preset_file" value="'.htmlspecialchars($p['file']).'">';
echo '<button type="submit" class="ofa-pm-btn ofa-pm-btn-del">✕</button>';
echo '</form>';
}
echo '</div>';
echo '</td>';
echo '</tr>';
}
?>
<!-- Starter Presets -->
<?php if(!empty($presets_starter)): ?>
<div class="ofa-pm-section">
<div class="ofa-pm-section-header">
<i class="fa fa-star-o"></i>
<?php echo $L['TXT_PRESET_SECTION_STARTER']; ?>
<span class="ofa-pm-section-count"><?php echo count($presets_starter); ?></span>
</div>
<table class="ofa-pm-table">
<colgroup>
<col class="col-icon">
<col class="col-name">
</colgroup>
<thead>
<tr>
<th><?php echo $L["TXT_PRESET_NAME"]; ?></th><th></th>
</tr>
</thead>
<tbody>
<?php foreach($presets_starter as $p): renderPresetRow($p, $section_id, $page_id, $icon_map, $L, true); endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<!-- Custom Presets -->
<?php if(!empty($presets_custom)): ?>
<div class="ofa-pm-section">
<div class="ofa-pm-section-header custom">
<i class="fa fa-folder-o"></i>
<?php echo $L['TXT_PRESET_SECTION_CUSTOM']; ?>
<span class="ofa-pm-section-count"><?php echo count($presets_custom); ?></span>
</div>
<table class="ofa-pm-table">
<colgroup>
<col class="col-icon">
<col class="col-name">
</colgroup>
<thead>
<tr>
<th><?php echo $L["TXT_PRESET_NAME"]; ?></th><th></th>
</tr>
</thead>
<tbody>
<?php foreach($presets_custom as $p): renderPresetRow($p, $section_id, $page_id, $icon_map, $L, false); endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php if(empty($presets_starter) && empty($presets_custom)): ?>
<p style="color:#999;padding:1em 0"><?php echo $L['TXT_PRESET_NONE']; ?></p>
<?php endif; ?>
<!-- Bottom Bar -->
<div class="ofa-pm-bottombar">
<form method="post" onsubmit="return confirm('<?php echo addslashes($L['TXT_PRESET_CONFIRM_RESTORE']); ?>')">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
<input type="hidden" name="action" value="restore_default">
<button type="submit" class="ofa-pm-btn ofa-pm-btn-restore">
<i class="fa fa-refresh"></i> <?php echo $L['TXT_PRESET_RESTORE']; ?>
</button>
</form>
<button onclick="window.location='<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>'"
class="ofa-pm-btn ofa-pm-btn-back">
<i class="fa fa-arrow-left"></i> <?php echo $L['TXT_PRESET_BACK']; ?>
</button>
</div>
</div><!-- .ofa-pm -->
<?php $admin->print_footer(); ?>