PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.13
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.13
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Submission / SubmissionPrint.php

SubmissionPrint.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.13, at app/Services/Submission/SubmissionPrint.php

177 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\Submission;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\App\Models\Submission;
7 use FluentForm\App\Services\FormBuilder\ShortCodeParser;
8 use FluentForm\Framework\Helpers\ArrayHelper as Arr;
9
10
11 class SubmissionPrint
12 {
13 public function getContent($attr)
14 {
15 $submissionIds = Arr::get($attr, 'submission_ids', []);
16 $submissionIds = array_filter(array_map('intval', $submissionIds));
17 $orderBy = Helper::sanitizeOrderValue(Arr::get($attr, 'sort_by', 'DESC'));
18 $formId = intval(Arr::get($attr, 'form_id'));
19 $form = Helper::getForm($formId);
20 $submissions = Submission::where('form_id', $formId)
21 ->whereIn('id', $submissionIds)
22 ->orderBy('id', $orderBy)
23 ->get();
24
25 if (!$form || count($submissionIds) === 0 || count($submissions) !== count($submissionIds)) {
26 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output
27 throw new \Exception(__('Invalid Submissions', 'fluentform'));
28 }
29 $pdfBody = $this->getBody($submissions, $form);
30 $pdfCss = '<style>' . $this->getCss() . '</style>';
31 return fluentform_sanitize_html($pdfCss . $pdfBody);
32 }
33
34 protected function getBody($submissions, $form)
35 {
36 $pdfBody = '';
37 foreach ($submissions as $index => $submission) {
38 $formData = json_decode($submission->response, true);
39 $htmlBody = ShortCodeParser::parse('{all_data}', $submission, $formData, $form, false, true);
40 $htmlBody = '<h3>Submission - #' . $submission->id . '</h3>' . $htmlBody;
41 if ($index !== 0 && apply_filters('fluentform/bulk_entries_print_start_on_new_page', __return_true(),
42 $submission, $form)) {
43 $htmlBody = '<div class="ff-new-entry-page-break"></div>' . $htmlBody;
44 }
45 if (apply_filters('fluentform/entry_print_with_notes', __return_true(), $form, $submission)) {
46 $htmlBody = $this->addNotes($htmlBody, $submission, $form);
47 }
48 $pdfBody .= apply_filters('fluentform/entry_print_body', $htmlBody, $submission, $form, $formData);
49 }
50 return apply_filters('fluentform/entries_print_body', $pdfBody, $submissions, $form);
51 }
52
53 protected function addNotes($htmlBody, $submission, $form)
54 {
55 $notes = (new SubmissionService())->getNotes($submission->id, ['form_id' => $form->id]);
56 if ($notes && count($notes) > 0) {
57 $notesHtml = '<br\><h3>Submission Notes</h3><table class="ff_all_data" width="600" cellpadding="0" cellspacing="0"><tbody>';
58 foreach ($notes as $note) {
59 if (isset($note->created_by)) {
60 $label = '' . $note->created_by . ' - ' . $note->created_at;
61 } else {
62 $label = '' . $note->name . ' - ' . $note->created_at;
63 }
64 $notesHtml .= '<tr class="field-label"><th style="padding: 6px 12px; background-color: #f8f8f8; text-align: left;"><strong>' . esc_html($label) . '</strong></th></tr><tr class="field-value"><td style="padding: 6px 12px 12px 12px;">' . wp_kses_post($note->value) . '</td></tr>';
65 }
66 $htmlBody = $htmlBody . $notesHtml . '</tbody></table>';
67 }
68 return $htmlBody;
69 }
70
71
72 protected function getCss()
73 {
74 $mainColor = '#4F4F4F';
75 $fontSize = 14;
76 $secondaryColor = '#EAEAEA';
77 ob_start();
78 ?>
79 .ff_pdf_wrapper, p, li, td, th {
80 color:
81 <?php
82 echo esc_attr($mainColor);
83 ?>
84 ;
85 font-size:
86 <?php
87 echo esc_attr($fontSize);
88 ?>
89 px;
90 }
91
92 .ff_all_data, table {
93 empty-cells: show;
94 border-collapse: collapse;
95 border: 1px solid
96 <?php
97 echo esc_attr($secondaryColor);
98 ?>
99 ;
100 width: 100%;
101 color:
102 <?php
103 echo esc_attr($mainColor);
104 ?>
105 ;
106 }
107 hr {
108 color:
109 <?php
110 echo esc_attr($secondaryColor);
111 ?>
112 ;
113 background-color:
114 <?php
115 echo esc_attr($secondaryColor);
116 ?>
117 ;
118 }
119 .ff_all_data th {
120 border-bottom: 1px solid
121 <?php
122 echo esc_attr($secondaryColor);
123 ?>
124 ;
125 border-top: 1px solid
126 <?php
127 echo esc_attr($secondaryColor);
128 ?>
129 ;
130 padding-bottom: 10px !important;
131 }
132 .ff_all_data tr td {
133 padding-left: 30px !important;
134 padding-top: 15px !important;
135 padding-bottom: 15px !important;
136 }
137
138 .ff_all_data tr td, .ff_all_data tr th {
139 border: 1px solid
140 <?php
141 echo esc_attr($secondaryColor);
142 ?>
143 ;
144 text-align: left;
145 }
146
147 table, .ff_all_data {width: 100%; overflow:wrap;} img.alignright { float: right; margin: 0 0 1em 1em; }
148 img.alignleft { float: left; margin: 0 10px 10px 0; }
149 .center-image-wrapper {text-align:center;}
150 .center-image-wrapper img.aligncenter {display: initial; margin: 0; text-align: center;}
151 .alignright { float: right; }
152 .alignleft { float: left; }
153 .aligncenter { display: block; margin-left: auto; margin-right: auto; text-align: center; }
154
155 .invoice_title {
156 padding-bottom: 10px;
157 display: block;
158 }
159 .ffp_table thead th {
160 background-color: #e3e8ee;
161 color: #000;
162 text-align: left;
163 vertical-align: bottom;
164 }
165 table th {
166 padding: 5px 10px;
167 }
168 .ff_rtl table th, .ff_rtl table td {
169 text-align: right !important;
170 }
171 /* Add CSS for page breaks */
172 @media print { .ff-new-entry-page-break { page-break-before: always; } }
173 <?php
174 return apply_filters('fluentform/entries_print_css', ob_get_clean());
175 }
176 }
177