/**
  * Perform actions normally performed after updating a lead
  *
  * @since 1.8
  *
  * @see GFEntryDetail::lead_detail_page()
  *
  * @return void
  */
 function after_update()
 {
     do_action('gform_after_update_entry', $this->form, $this->entry['id']);
     do_action("gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id']);
     // Re-define the entry now that we've updated it.
     $entry = RGFormsModel::get_lead($this->entry['id']);
     $entry = GFFormsModel::set_entry_meta($entry, $this->form);
     // We need to clear the cache because Gravity Forms caches the field values, which
     // we have just updated.
     foreach ($this->form['fields'] as $key => $field) {
         GFFormsModel::refresh_lead_field_value($entry['id'], $field->id);
     }
     $this->entry = $entry;
 }
 /**
  * Perform actions normally performed after updating a lead
  *
  * @since 1.8
  *
  * @see GFEntryDetail::lead_detail_page()
  *
  * @return void
  */
 function after_update()
 {
     //custom MF code
     /* update has occurred, reset the validation form as this has admin only fields set to false */
     unset($this->form_after_validation);
     do_action('gform_after_update_entry', $this->form, $this->entry['id']);
     do_action("gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id']);
     // Re-define the entry now that we've updated it.
     $entry = RGFormsModel::get_lead($this->entry['id']);
     $entry = GFFormsModel::set_entry_meta($entry, $this->form);
     // We need to clear the cache because Gravity Forms caches the field values, which
     // we have just updated.
     foreach ($this->form['fields'] as $key => $field) {
         GFFormsModel::refresh_lead_field_value($entry['id'], $field->id);
     }
     $this->entry = $entry;
 }
 public function save_entry($form, &$lead, $editable_fields)
 {
     global $wpdb;
     gravity_flow()->log_debug(__METHOD__ . '(): Saving entry.');
     $lead_detail_table = GFFormsModel::get_lead_details_table_name();
     $is_new_lead = $lead == null;
     // Bailing if null
     if ($is_new_lead) {
         return;
     }
     $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead['id']));
     $total_fields = array();
     /* @var $calculation_fields GF_Field[] */
     $calculation_fields = array();
     $recalculate_total = false;
     GFCommon::log_debug(__METHOD__ . '(): Saving entry fields.');
     foreach ($form['fields'] as &$field) {
         /* @var $field GF_Field */
         //Ignore fields that are marked as display only
         if ($field->displayOnly && $field->type != 'password') {
             continue;
         }
         //ignore pricing fields in the entry detail
         if (RG_CURRENT_VIEW == 'entry' && GFCommon::is_pricing_field($field->type)) {
             //continue;
         }
         //process total field after all fields have been saved
         if ($field->type == 'total') {
             $total_fields[] = $field;
             continue;
         }
         // process calculation fields after all fields have been saved (moved after the is hidden check)
         if ($field->has_calculation()) {
             $calculation_fields[] = $field;
             continue;
         }
         if (!in_array($field->id, $editable_fields)) {
             continue;
         }
         if (!$this->conditional_logic_editable_fields_enabled) {
             $field->conditionalLogic = null;
         }
         gravity_flow()->log_debug(__METHOD__ . "(): Saving field {$field->label}(#{$field->id} - {$field->type}).");
         if ($field->type == 'post_category') {
             $field = GFCommon::add_categories_as_choices($field, '');
         }
         $inputs = $field->get_entry_inputs();
         if (is_array($inputs)) {
             foreach ($inputs as $input) {
                 GFFormsModel::save_input($form, $field, $lead, $current_fields, $input['id']);
             }
         } else {
             GFFormsModel::save_input($form, $field, $lead, $current_fields, $field->id);
         }
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $calculation_field) {
             gravity_flow()->log_debug(__METHOD__ . "(): Saving calculated field {$calculation_field->label}(#{$calculation_field->id} - {$calculation_field->type}).");
             // Make sure that the value gets recalculated
             $calculation_field->conditionalLogic = null;
             $inputs = $calculation_field->get_entry_inputs();
             if (is_array($inputs)) {
                 if (!in_array($calculation_field->id, $editable_fields)) {
                     // Make sure calculated product names and quantities are saved as if they're submitted.
                     $value = array($calculation_field->id . '.1' => $lead[$calculation_field->id . '.1']);
                     $_POST['input_' . $calculation_field->id . '_1'] = $calculation_field->get_field_label(false, $value);
                     $quantity = trim($lead[$calculation_field->id . '.3']);
                     if ($calculation_field->disableQuantity && empty($quantity)) {
                         $_POST['input_' . $calculation_field->id . '_3'] = 1;
                     } else {
                         $_POST['input_' . $calculation_field->id . '_3'] = $quantity;
                     }
                 }
                 foreach ($inputs as $input) {
                     GFFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input['id']);
                     GFFormsModel::refresh_lead_field_value($lead['id'], $input['id']);
                 }
             } else {
                 GFFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field->id);
                 GFFormsModel::refresh_lead_field_value($lead['id'], $calculation_field->id);
             }
         }
     }
     GFFormsModel::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
     //saving total field as the last field of the form.
     if (!empty($total_fields)) {
         foreach ($total_fields as $total_field) {
             gravity_flow()->log_debug(__METHOD__ . '(): Saving total field.');
             GFFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field->id);
             GFFormsModel::refresh_lead_field_value($lead['id'], $total_field->id);
         }
     }
 }