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