PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.2.0
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Fallback / Report.php

Report.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.2.0, at includes/Core/Fallback/Report.php

109 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Fallback;
4
5 use BitCode\BitForm\Core\Database\FormModel;
6 use BitCode\BitForm\Core\Database\ReportsModel;
7 use BitCode\BitForm\Core\Util\IpTool;
8
9 class Report
10 {
11 public function report()
12 {
13 $reportMdl = new ReportsModel();
14 global $wpdb;
15 $tablename = $wpdb->prefix . 'bitforms_reports';
16
17 // $latestIds = $wpdb->get_results("SELECT MAX(`id`) as latest_id FROM $tablename GROUP BY `context`");
18 // Direct query: table name from $wpdb->prefix concatenation (no user input). $wpdb->prepare() cannot parameterize table names.
19 $wpdb->query(
20 $wpdb->prepare(
21 "SELECT MAX(`id`) as latest_id FROM `{$tablename}` GROUP BY `context`"
22 )
23 );
24 $latestIds = $wpdb->last_result;
25
26 $notDeletedIds = array_column($latestIds, 'latest_id');
27
28 if (!is_wp_error($latestIds) && count($notDeletedIds) > 0) {
29 $reportMdl->bulkDelete(['id' => $notDeletedIds], 'NOT IN');
30 }
31
32 $ipTool = new IpTool();
33 $user_details = $ipTool->getUserDetail();
34
35 $formModel = new FormModel();
36
37 $forms = $formModel->get(
38 ['id']
39 );
40
41 $details = [
42 'report_name' => __('All Entries', 'bit-form'),
43 'hiddenColumns' => [],
44 'pageSize' => 10,
45 'sortBy' => [],
46 'filters' => [],
47 'globalFilter' => '',
48 'order' => [],
49 ];
50
51 foreach ($forms as $form) {
52 $existReportId = $reportMdl->get(
53 [
54 'id',
55 ],
56 [
57 'context' => $form->id,
58 ]
59 );
60 if (is_wp_error($existReportId)) {
61 $defaultReport = [
62 'type' => 'table',
63 'category' => 'form',
64 'context' => $form->id,
65 'details' => wp_json_encode($details),
66 'isDefault' => (bool) 1,
67 'user_id' => $user_details['id'],
68 'user_ip' => $user_details['ip'],
69 'user_device' => $user_details['device'],
70 'created_at' => $user_details['time'],
71 'updated_at' => $user_details['time'],
72 ];
73
74 $reportMdl->insert($defaultReport);
75 }
76 }
77 }
78
79 public function addHiddenColumns()
80 {
81 $reportMdl = new ReportsModel();
82 $reports = $reportMdl->get(
83 [
84 'id',
85 'details',
86 ],
87 [
88 'category' => 'form',
89 'type' => 'table',
90 ]
91 );
92
93 foreach ($reports as $report) {
94 $reportDetails = json_decode($report->details);
95 if (is_object($reportDetails) && (!property_exists($reportDetails, 'hiddenColumns') || empty($reportDetails->hiddenColumns))) {
96 $reportDetails->hiddenColumns = ['__user_id', '__user_ip', '__referer', '__user_device', '__created_at', '__updated_at'];
97 $reportMdl->update(
98 [
99 'details' => wp_json_encode($reportDetails),
100 ],
101 [
102 'id' => $report->id,
103 ]
104 );
105 }
106 }
107 }
108 }
109