public function upgrade($previous_version)
 {
     if (version_compare($previous_version, '1.0.5') == -1) {
         $forms = GFAPI::get_forms(true);
         foreach ($forms as $form) {
             $entries = GFAPI::get_entries($form['id']);
             $fields = GFAPI::get_fields_by_type($form, 'repeater');
             foreach ($entries as $entry) {
                 foreach ($fields as $field) {
                     if (array_key_exists($field['id'], $entry)) {
                         $dataArray = GFFormsModel::unserialize($entry[$field['id']]);
                         $dataUpdated = false;
                         if (!is_array($dataArray)) {
                             continue;
                         }
                         foreach ($dataArray as $repeaterChildId => $repeaterChild) {
                             foreach ($repeaterChild as $repeatedFieldId => $repeatedField) {
                                 if (!is_array($repeatedField)) {
                                     if ($repeatedField !== '[gfRepeater-section]') {
                                         $dataUpdated = true;
                                         $dataArray[$repeaterChildId][$repeatedFieldId] = array($repeatedField);
                                     }
                                 } elseif (reset($repeatedField) == '[gfRepeater-section]') {
                                     $dataUpdated = true;
                                     $dataArray[$repeaterChildId][$repeatedFieldId] = reset($repeatedField);
                                 }
                             }
                         }
                         if ($dataUpdated) {
                             GFAPI::update_entry_field($entry['id'], $field['id'], maybe_serialize($dataArray));
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
 private static function fix_leading_and_trailing_spaces()
 {
     global $wpdb;
     $meta_table_name = GFFormsModel::get_meta_table_name();
     $lead_details_table = GFFormsModel::get_lead_details_table_name();
     $lead_details_long_table = GFFormsModel::get_lead_details_long_table_name();
     $result = $wpdb->query("UPDATE {$lead_details_table} SET value = TRIM(value)");
     $result = $wpdb->query("UPDATE {$lead_details_long_table} SET value = TRIM(value)");
     $results = $wpdb->get_results("SELECT form_id, display_meta, confirmations, notifications FROM {$meta_table_name}", ARRAY_A);
     foreach ($results as &$result) {
         $form_id = $result['form_id'];
         $form = GFFormsModel::unserialize($result['display_meta']);
         $form_updated = false;
         $form = GFFormsModel::trim_form_meta_values($form, $form_updated);
         if ($form_updated) {
             GFFormsModel::update_form_meta($form_id, $form);
         }
         $confirmations = GFFormsModel::unserialize($result['confirmations']);
         $confirmations_updated = false;
         $confirmations = GFFormsModel::trim_conditional_logic_values($confirmations, $form, $confirmations_updated);
         if ($confirmations_updated) {
             GFFormsModel::update_form_meta($form_id, $confirmations, 'confirmations');
         }
         $notifications = GFFormsModel::unserialize($result['notifications']);
         $notifications_updated = false;
         $notifications = GFFormsModel::trim_conditional_logic_values($notifications, $form, $notifications_updated);
         if ($notifications_updated) {
             GFFormsModel::update_form_meta($form_id, $notifications, 'notifications');
         }
     }
     return $results;
 }
 private static function fix_leading_and_trailing_spaces()
 {
     global $wpdb;
     $meta_table_name = GFFormsModel::get_meta_table_name();
     $lead_details_table = GFFormsModel::get_lead_details_table_name();
     $lead_details_long_table = GFFormsModel::get_lead_details_long_table_name();
     //fast but doesn't allow for the gform_trim_input_value filter
     //$result = $wpdb->query("UPDATE $lead_details_table SET value = TRIM(value)");
     //$result = $wpdb->query("UPDATE $lead_details_long_table SET value = TRIM(value)");
     $results = $wpdb->get_results("SELECT form_id, display_meta FROM {$meta_table_name}", ARRAY_A);
     foreach ($results as &$result) {
         $form_id = $result["form_id"];
         $form = GFFormsModel::unserialize($result["display_meta"]);
         $form_updated = false;
         if (isset($form["fields"]) && is_array($form["fields"])) {
             $fields_to_update = array();
             foreach ($form["fields"] as &$field) {
                 $trim_value = apply_filters("gform_trim_input_value", true, $form_id, $field);
                 if (!$trim_value) {
                     continue;
                 }
                 if (isset($field["label"]) && $field["label"] != trim($field["label"])) {
                     $field["label"] = trim($field["label"]);
                     $form_updated = true;
                 }
                 if (isset($field["choices"]) && is_array($field["choices"])) {
                     foreach ($field["choices"] as &$choice) {
                         if (isset($choice["text"]) && $choice["text"] != trim($choice["text"])) {
                             $choice["text"] = trim($choice["text"]);
                             $form_updated = true;
                         }
                         if (isset($choice["value"]) && $choice["value"] != trim($choice["value"])) {
                             $choice["value"] = trim($choice["value"]);
                             $form_updated = true;
                         }
                     }
                 }
                 if (isset($field["inputs"]) && is_array($field["inputs"])) {
                     foreach ($field["inputs"] as &$input) {
                         if (isset($input["label"]) && $input["label"] != trim($input["label"])) {
                             $input["label"] = trim($input["label"]);
                             $form_updated = true;
                         }
                     }
                 }
                 $field_id = (int) $field["id"];
                 $field_number_min = $field_id - 0.001;
                 $field_number_max = $field_id + 0.999;
                 $fields_to_update[] = sprintf("field_number BETWEEN %s AND %s", $field_number_min, $field_number_max);
             }
             if (!empty($fields_to_update)) {
                 $fields_to_update_str = join(" OR ", $fields_to_update);
                 //slow - may cause timeouts on sites with high volume of entries
                 $result = $wpdb->query("UPDATE {$lead_details_table} SET value = TRIM(value) WHERE form_id = {$form_id} AND ({$fields_to_update_str})");
                 $result = $wpdb->query("UPDATE {$lead_details_long_table} SET value = TRIM(value) WHERE lead_detail_id IN (SELECT id FROM {$lead_details_table} WHERE form_id = {$form_id} AND ({$fields_to_update_str}))");
             }
         }
         if ($form_updated) {
             GFFormsModel::update_form_meta($form_id, $form);
         }
     }
     return $results;
 }
 public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
 {
     if (empty($value)) {
         return '';
     } else {
         $dataArray = GFFormsModel::unserialize($value);
         $arrayCount = count($dataArray);
         $output = "\n";
         $count = 0;
         $repeatCount = 0;
         $display_empty_fields = rgget('gf_display_empty_fields', $_COOKIE);
         $form_id = $this->formId;
         $get_form = GFFormsModel::get_form_meta_by_id($form_id);
         $form = $get_form[0];
         foreach ($dataArray as $key => $value) {
             $repeatCount++;
             $tableContents = '';
             if (empty($value)) {
                 continue;
             }
             if (!empty($value) && !is_array($value)) {
                 $save_value = $value;
                 unset($value);
                 $value[0] = $save_value;
             } elseif (version_compare(phpversion(), '5.3') !== -1) {
                 uksort($value, function ($a, $b) use($form) {
                     $a_index = GF_Field_Repeater::get_field_index($form, 'id', $a);
                     $b_index = GF_Field_Repeater::get_field_index($form, 'id', $b);
                     if ($a_index > $b_index) {
                         return 1;
                     }
                     return 0;
                 });
             }
             foreach ($value as $childKey => $childValue) {
                 $count++;
                 $childValueOutput = '';
                 if (empty($display_empty_fields) && count($childValue) == 0) {
                     continue;
                 }
                 if (is_numeric($childKey)) {
                     $field_index = GF_Field_Repeater::get_field_index($form, 'id', $childKey);
                     if ($field_index === false) {
                         continue;
                     }
                     $entry_title = $form['fields'][$field_index]['label'];
                 } else {
                     $entry_title = $childKey;
                 }
                 $entry_title = str_replace('[gfRepeater-count]', $repeatCount, $entry_title);
                 if ($format == 'html') {
                     if ($childValue == '[gfRepeater-section]') {
                         if ($media == 'email') {
                             $tableStyling = ' style="font-size:14px;font-weight:bold;background-color:#eee;border-bottom:1px solid #dfdfdf;padding:7px 7px"';
                         } else {
                             $tableStyling = ' class="entry-view-section-break"';
                         }
                     } else {
                         if ($media == 'email') {
                             $tableStyling = ' style="background-color:#EAF2FA;font-family:sans-serif;font-size:12px;font-weight:bold"';
                         } else {
                             $tableStyling = ' class="entry-view-field-name"';
                         }
                     }
                     $tableContents .= "<tr>\n<td colspan=\"2\"" . $tableStyling . ">" . $entry_title . "</td>\n</tr>\n";
                 } else {
                     $tableContents .= $entry_title . ": ";
                 }
                 if (is_array($childValue)) {
                     if (count($childValue) == 1) {
                         $childValueOutput = apply_filters('gform_entry_field_value', reset($childValue), $form['fields'][$field_index], array(), $form);
                     } elseif (count($childValue) > 1) {
                         if ($format == 'html') {
                             if ($media == 'email') {
                                 $childValueOutput = "<ul style=\"list-style:none;margin:0;padding:0;\">\n";
                             } else {
                                 $childValueOutput = "<ul>\n";
                             }
                         }
                         foreach ($childValue as $childValueData) {
                             $childValueData = apply_filters('gform_entry_field_value', reset($childValue), $form['fields'][$field_index], array(), $form);
                             if ($format == 'html') {
                                 $childValueOutput .= "<li>" . $childValueData . "</li>";
                             } else {
                                 $childValueOutput .= $childValueData . "\n";
                             }
                         }
                         if ($format == 'html') {
                             $childValueOutput .= "</ul>\n";
                         }
                     }
                     if ($media == 'email') {
                         $tableStyling = '';
                     } else {
                         $tableStyling = ' class=\\"entry-view-field-value\\"';
                     }
                     if ($format == 'html') {
                         $tableContents .= "<tr>\n<td colspan=\"2\"" . $tableStyling . ">" . $childValueOutput . "</td>\n</tr>\n";
                     } else {
                         $tableContents .= $childValueOutput . "\n";
                     }
                 }
             }
             if (!empty($tableContents)) {
                 if ($format == 'html') {
                     if ($media == 'email') {
                         $tableStyling = ' width="100%" border="0" cellpadding="5" bgcolor="#FFFFFF"';
                     } else {
                         $tableStyling = ' class="widefat fixed entry-detail-view"';
                     }
                     $output .= "<table cellspacing=\"0\"" . $tableStyling . ">\n";
                     $output .= $tableContents;
                     $output .= "</table>\n";
                 } else {
                     $output .= $tableContents . "\n";
                 }
             }
         }
     }
     if ($count !== 0) {
         if ($format == 'text') {
             $output = rtrim($output);
         }
         if (GF_REPEATER_DEBUG && $format == 'html') {
             $output = '<pre style="height:100px;overflow:auto;resize:vertical;">' . print_r($dataArray, true) . '</pre>' . $output;
         }
         return $output;
     } else {
         return '';
     }
 }