PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.2
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.2
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / class-form-entry.php

class-form-entry.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.3.2, at includes/class-form-entry.php

462 lines 15.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Single Form Entry Class
5 *
6 * @since 1.1.0
7 */
8 class WeForms_Form_Entry {
9
10 /**
11 * The form object
12 *
13 * @var \WeForms_Form
14 */
15 private $form;
16
17 /**
18 * Entry id
19 *
20 * @var integer
21 */
22 public $id = 0;
23
24 /**
25 * The form id
26 *
27 * @var integer
28 */
29 public $form_id = 0;
30
31 /**
32 * The user id
33 *
34 * @var integer
35 */
36 public $user_id = 0;
37
38 /**
39 * IP Address
40 *
41 * @var string
42 */
43 public $ip_address = '127.0.0.1';
44
45 /**
46 * The device of the user
47 *
48 * @var string
49 */
50 public $device = '';
51
52 /**
53 * Referer URL
54 *
55 * @var string
56 */
57 public $referer = '';
58
59 /**
60 * Entry creation date
61 *
62 * @var string
63 */
64 public $created = '0000-00-00 00:00:00';
65
66 /**
67 * Form fields
68 *
69 * @var array
70 */
71 public $fields = array();
72
73 /**
74 * Form fields raw data
75 *
76 * @var array
77 */
78 public $raw_fields = array();
79
80 /**
81 * The constructor
82 *
83 * @param integer $entry_id
84 * @param \WeForms_Form $form
85 */
86 function __construct( $entry_id, $form ) {
87 $this->id = $entry_id;
88 $this->form = $form;
89
90 $this->populate_entry_data();
91 }
92
93 /**
94 *
95 * Populate the class with data
96 *
97 * @TODO: Abstract this
98 *
99 * @return void
100 */
101 public function populate_entry_data() {
102 global $wpdb;
103
104 // return if we populated the already, ensures single db call
105 if ( $this->form_id ) {
106 return;
107 }
108
109 $grid_css_added = false;
110 $grid_css = '<style>.wpufTable {display: table; width: 100%; } .wpufTableRow {display: table-row; } .wpufTableRow:nth-child(even) {background-color: #f5f5f5; } .wpufTableHeading {background-color: #eee; display: table-header-group; font-weight: bold; } .wpufTableCell, .wpufTableHead {border: none; display: table-cell; padding: 3px 10px; } .wpufTableFoot {background-color: #eee; display: table-footer-group; font-weight: bold; } .wpufTableBody {display: table-row-group; }</style>';
111
112 $values = array();
113
114 $query = "SELECT * FROM {$wpdb->weforms_entries} as entry
115 LEFT JOIN {$wpdb->weforms_entrymeta} AS meta ON entry.id = meta.weforms_entry_id
116 WHERE entry.id = {$this->id}";
117
118 $results = $wpdb->get_results( $query );
119
120 if ( $results ) {
121 $first_row = reset( $results );
122
123 $this->form_id = (int) $first_row->form_id;
124 $this->user_id = (int) $first_row->user_id;
125 $this->ip_address = long2ip( $first_row->user_ip );
126 $this->device = $first_row->user_device;
127 $this->referer = $first_row->referer;
128 $this->created = $first_row->created_at;
129
130 $this->fields = $this->form->get_field_values();
131 $this->raw_fields = $this->fields;
132
133 foreach ( $results as $result ) {
134
135 if ( array_key_exists( $result->meta_key, $this->fields ) ) {
136
137 $field = $this->fields[ $result->meta_key ];
138 $value = $result->meta_value;
139
140 $this->raw_fields[ $result->meta_key ]['value'] = $value;
141
142 if ( $field['type'] == 'textarea_field' ) {
143
144 $value = weforms_format_text( $value );
145
146 } elseif ( $field['type'] == 'name_field' ) {
147
148 $value = implode( ' ', explode( WeForms::$field_separator, $value ) );
149
150 } elseif ( in_array( $field['type'], array( 'dropdown_field', 'radio_field' ) ) ) {
151
152 if ( isset( $field['options'] ) && $field['options'] ) {
153
154 if ( isset( $field['options'][ $value ] ) ) {
155 $value = $field['options'][ $value ];
156 }
157 }
158 } elseif ( in_array( $field['type'], array( 'multiple_select', 'checkbox_field' ) ) ) {
159 $value = explode( WeForms::$field_separator, $value );
160 $temp_value = $value;
161
162 if ( is_array( $value ) && $value ) {
163
164 $new_array = array();
165
166 foreach ( $value as $option_key ) {
167 if ( is_array( $field['options'] ) && array_key_exists( $option_key, $field['options'] ) ) {
168 $new_array[] = $field['options'][ $option_key ];
169 } else {
170 $new_array[] = $option_key;
171 }
172 }
173
174 $value = $new_array;
175 }
176 } elseif ( in_array( $field['type'], array( 'image_upload', 'file_upload' ) ) ) {
177
178 $file_field = '';
179 $value = maybe_unserialize( $value );
180
181 if ( is_array( $value ) && $value ) {
182
183 foreach ( $value as $attachment_id ) {
184
185 if ( $field['type'] == 'image_upload' ) {
186 $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
187 } else {
188 $thumb = get_post_field( 'post_title', $attachment_id );
189 }
190
191 $full_size = wp_get_attachment_url( $attachment_id );
192
193 $file_field .= sprintf( '<a href="%s" target="_blank">%s</a> ', $full_size, $thumb );
194 }
195 }
196
197 $value = $file_field;
198
199 } elseif ( $field['type'] == 'google_map' ) {
200 list( $lat, $long ) = explode( ',', $value );
201
202 $value = array(
203 'lat' => $lat,
204 'long' => $long
205 );
206
207 } elseif ( $field['type'] == 'multiple_product' ) {
208
209 $field_value = unserialize( $value );
210
211 $serialized_value = array();
212
213 if ( is_array( $field_value ) ) {
214
215 foreach ( $field_value as $key => $sfv ) {
216
217 if ( is_array( $sfv ) ) {
218
219 $v = array();
220
221 foreach ( $sfv as $key => $sv ) {
222
223 $sv = str_replace( array( '_', '-' ), ' ', $key ) . ': ' . $sv;
224 $sv = ucwords( $sv );
225 $v[] = $sv;
226 }
227
228 $serialized_value[] = implode( '<br> ', $v );
229
230 }
231 }
232
233 $value = implode( '<br> <br> ', $serialized_value );
234 }
235 } elseif ( $field['type'] == 'checkbox_grid' ) {
236
237 $entry_value = unserialize( $value );
238
239 if ( $entry_value ) {
240
241 $return = '';
242 $check = '';
243
244 if ( ! $grid_css_added ) {
245 $return = $grid_css;
246 $grid_css_added = true;
247 }
248
249 $new_val = array();
250
251 foreach ( $entry_value as $key => $option_value ) {
252 $new_val[ $key ] = $option_value;
253 }
254
255 if ( $field['grid_rows'] && count( $field['grid_rows'] ) > 0 && $field['grid_columns'] && count( $field['grid_columns'] ) > 0 ) {
256
257 $return .= '<div class="wpufTable">
258 <div class="wpufTableHeading">
259 <div class="wpufTableRow">
260 <div class="wpufTableHead">&nbsp;</div>';
261
262 foreach ( $field['grid_columns'] as $column ) {
263 $return .= '<div class="wpufTableHead">' . $column . '</div>';
264 }
265
266 $return .= '</div>
267 </div>
268 <div class="wpufTableBody">';
269
270 foreach ( $field['grid_rows'] as $row_key => $row_value ) {
271
272 $return .= '<div class="wpufTableRow">
273 <div class="wpufTableHead">' . $row_value . '</div>';
274
275 foreach ( $field['grid_columns'] as $column_key => $column_value ) {
276 if ( isset( $new_val[ $row_key ] ) ) {
277 $check = ( in_array( $column_value, $new_val[ $row_key ] ) ) ? 'checked ' : '';
278 }
279
280 $return .= '<div class="wpufTableCell">
281 <label class="wpuf-radio-inline">
282 <input
283 name="' . $field['name'] . '[' . $row_key . '][]"
284 class="wpuf_' . $field['name'] . '_' . $this->form_id . '"
285 type="checkbox"
286 value="' . esc_attr( $column_value ) . '"'
287 . $check . 'disabled
288 />
289 </label>
290 </div>';
291
292 }
293
294 $return .= '</div>';
295
296 }
297
298 $return .= '</div>
299 </div>';
300
301 }
302
303 $value = $return;
304 }
305 } elseif ( $field['type'] == 'multiple_choice_grid' ) {
306
307 $entry_value = unserialize( $value );
308
309 if ( $entry_value ) {
310
311 $return = '';
312 $check = '';
313
314 if ( ! $grid_css_added ) {
315 $return = $grid_css;
316 $grid_css_added = true;
317 }
318
319 $new_val = array();
320
321 foreach ( $entry_value as $key => $option_value ) {
322 $new_val[ $key ] = $option_value;
323 }
324
325 if ( $field['grid_rows'] && count( $field['grid_rows'] ) > 0 && $field['grid_columns'] && count( $field['grid_columns'] ) > 0 ) {
326
327 $return .= '<div class="wpufTable">
328 <div class="wpufTableHeading">
329 <div class="wpufTableRow">
330 <div class="wpufTableHead">&nbsp;</div>';
331
332 foreach ( $field['grid_columns'] as $column ) {
333 $return .= '<div class="wpufTableHead">' . $column . '</div>';
334 }
335
336 $return .= '</div>
337 </div>
338 <div class="wpufTableBody">';
339
340 foreach ( $field['grid_rows'] as $row_key => $row_value ) {
341
342 $return .= '<div class="wpufTableRow">
343 <div class="wpufTableHead">' . $row_value . '</div>';
344
345 foreach ( $field['grid_columns'] as $column_key => $column_value ) {
346 if ( isset( $new_val[ $row_key ] ) ) {
347 $check = ( $new_val[ $row_key ] == $column_value ) ? 'checked ' : '';
348 }
349
350 $return .= '<div class="wpufTableCell">
351 <label class="wpuf-radio-inline">
352 <input
353 name="' . $field['name'] . '[' . $row_key . ']"
354 class="wpuf_' . $field['name'] . '_' . $this->form_id . '"
355 type="radio"
356 value="' . esc_attr( $column_value ) . '"'
357 . $check . 'disabled
358 />
359 </label>
360 </div>';
361
362 }
363
364 $return .= '</div>';
365
366 }
367
368 $return .= '</div>
369 </div>';
370
371 }
372
373 $value = $return;
374 }
375 } elseif ( $field['type'] == 'address_field' || is_serialized( $value ) ) {
376
377 $field_value = unserialize( $value );
378
379 $serialized_value = array();
380
381 if ( is_array( $field_value ) ) {
382
383 foreach ( $field_value as $key => $sfv ) {
384
385 $sfv = str_replace( array( '_', '-' ), ' ', $key ) . ': ' . $sfv;
386 $sfv = ucwords( $sfv );
387 $serialized_value[] = $sfv;
388 }
389
390 $value = implode( '<br> ', $serialized_value );
391 }
392 } elseif ( $field['type'] == 'signature_field' ) {
393 $url = content_url() . $value;
394 $value = $url;
395
396 if ( $_REQUEST['action'] != 'weforms_pdf_download' ) {
397 $value = sprintf( '<img src="%s">', $url );
398 $value .= sprintf( '<a style="margin-left: -200px" href="%s">Download</a>', $url );
399 }
400
401 }
402
403 $this->fields[ $result->meta_key ]['value'] = apply_filters( 'weforms_entry_meta_field', $value, $field );
404 }
405 }
406 }
407 }
408
409
410 /**
411 * Get entry fields
412 *
413 * @return array
414 */
415 public function get_fields() {
416 return $this->fields;
417 }
418
419 /**
420 * Get entry fields
421 *
422 * @return array
423 */
424 public function get_raw_fields() {
425 return $this->raw_fields;
426 }
427
428 /**
429 * Get entry metadata
430 *
431 * @return array
432 */
433 public function get_metadata() {
434 return array(
435 'id' => $this->id,
436 'form_id' => $this->form_id,
437 'form_title' => $this->form->get_name(),
438 'user' => $this->user_id ? get_user_by( 'id', $this->user_id )->display_name : false,
439 'ip_address' => $this->ip_address,
440 'device' => $this->device,
441 'referer' => $this->referer,
442 'created' => date_i18n( 'F j, Y g:i a', strtotime( $this->created ) )
443 );
444 }
445
446 /**
447 * Get entry metadata
448 *
449 * @return array
450 */
451 public function get_payment_data() {
452 global $wpdb;
453
454 if ( ! class_exists( 'WeForms_Payment' ) ) {
455 return;
456 }
457
458 return $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}weforms_payments WHERE entry_id = {$this->id} " );
459 }
460
461 }
462