public function get_field_input($form, $value = '', $entry = null)
 {
     $form_id = $form['id'];
     $is_entry_detail = $this->is_entry_detail();
     $is_form_editor = $this->is_form_editor();
     $id = (int) $this->id;
     $product_name = !is_array($value) || empty($value[$this->id . '.1']) ? esc_attr($this->label) : esc_attr($value[$this->id . '.1']);
     $price = !is_array($value) || empty($value[$this->id . '.2']) ? $this->basePrice : esc_attr($value[$this->id . '.2']);
     $quantity = is_array($value) ? esc_attr($value[$this->id . '.3']) : '';
     if (rgblank($quantity)) {
         $quantity = 1;
     }
     if (empty($price)) {
         $price = 0;
     }
     $price = esc_attr($price);
     $has_quantity_field = sizeof(GFCommon::get_product_fields_by_type($form, array('quantity'), $this->id)) > 0;
     if ($has_quantity_field) {
         $this->disableQuantity = true;
     }
     $quantity_field = $has_quantity_field ? '' : "<input type='hidden' name='input_{$id}.3' value='" . esc_attr($quantity) . "' id='ginput_quantity_{$form_id}_{$this->id}' class='gform_hidden' />";
     $product_name_field = "<input type='hidden' name='input_{$id}.1' value='{$product_name}' class='gform_hidden' />";
     $disabled_text = $is_form_editor ? 'disabled="disabled"' : '';
     $field_type = $is_entry_detail || $is_form_editor ? 'text' : 'hidden';
     return $quantity_field . $product_name_field . "<input name='input_{$id}.2' id='ginput_base_price_{$form_id}_{$this->id}' type='{$field_type}' value='{$price}' class='gform_hidden ginput_amount' {$disabled_text}/>";
 }
 public function validate($value, $form)
 {
     // the POST value has already been converted from currency or decimal_comma to decimal_dot and then cleaned in get_field_value()
     $value = GFCommon::maybe_add_leading_zero($value);
     $raw_value = $_POST['input_' . $this->id];
     //Raw value will be tested against the is_numeric() function to make sure it is in the right format.
     $requires_valid_number = !rgblank($raw_value) && !$this->has_calculation();
     $is_valid_number = $this->validate_range($value) && GFCommon::is_numeric($raw_value, $this->numberFormat);
     if ($requires_valid_number && !$is_valid_number) {
         $this->failed_validation = true;
         $this->validation_message = empty($this->errorMessage) ? $this->get_range_message() : $this->errorMessage;
     } else {
         if ($this->type == 'quantity') {
             if (intval($value) != $value) {
                 $this->failed_validation = true;
                 $this->validation_message = empty($field['errorMessage']) ? __('Please enter a valid quantity. Quantity cannot contain decimals.', 'gravityforms') : $field['errorMessage'];
             } else {
                 if (!empty($value) && (!is_numeric($value) || intval($value) != floatval($value) || intval($value) < 0)) {
                     $this->failed_validation = true;
                     $this->validation_message = empty($field['errorMessage']) ? __('Please enter a valid quantity', 'gravityforms') : $field['errorMessage'];
                 }
             }
         }
     }
 }
function bb_click_array_field_input($input, $field, $value, $lead_id, $form_id)
{
    if ($field["type"] == "bb_click_array") {
        $field_id = IS_ADMIN || $form_id == 0 ? "input_{$id}" : "input_" . $form_id . "_{$id}";
        $input_name = $form_id . '_' . $field["id"];
        $css = isset($field['cssClass']) ? $field['cssClass'] : "";
        $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != "entry" ? "disabled='disabled'" : "";
        $amount = '';
        $clicked = '';
        if (is_array($value)) {
            $amount = esc_attr(rgget($field["id"] . ".1", $value));
            $clicked = rgget($field["id"] . ".5", $value);
        }
        $html = "<div id='{$field_id}' class='ginput_container bb-click-array-" . count($field['choices']) . " " . esc_attr($css) . "'>" . "\n";
        if (is_array($field["choices"])) {
            $choice_id = 0;
            $tabindex = GFCommon::get_tabindex();
            foreach ($field["choices"] as $choice) {
                $id = $field["id"] . '_' . $choice_id;
                $field_value = !empty($choice["value"]) || rgar($field, "enableChoiceValue") ? $choice["value"] : $choice["text"];
                if (rgblank($amount) && RG_CURRENT_VIEW != "entry") {
                    $active = rgar($choice, "isSelected") ? "checked='checked'" : "";
                } else {
                    $active = RGFormsModel::choice_value_match($field, $choice, $amount) ? "checked='checked'" : "";
                }
                if ($active) {
                    $amount = $field_value;
                }
                $field_class = $active ? 's-active' : 's-passive';
                if (rgar($field, 'field_bb_click_array_is_product')) {
                    require_once GFCommon::get_base_path() . '/currency.php';
                    $currency = new RGCurrency(GFCommon::get_currency());
                    $field_value = $currency->to_money($field_value);
                    $field_class .= ' s-currency';
                }
                $html .= sprintf('<div data-clickarray-value="%s" data-choice-id="%s" class="s-html-wrapper %s" id="%s">', esc_attr($field_value), $choice_id, $field_class, $id);
                $html .= sprintf('<div class="s-html-value">%s</div>', $field_value);
                $html .= sprintf("<label for='choice_%s' id='label_%s'>%s</label>", $id, $id, $choice["text"]);
                $html .= '</div>';
                $choice_id++;
            }
            $onblur = !IS_ADMIN ? 'if(jQuery(this).val().replace(" ", "") == "") { jQuery(this).val("' . $other_default_value . '"); }' : '';
            $onkeyup = empty($field["conditionalLogicFields"]) || IS_ADMIN ? '' : "onchange='gf_apply_rules(" . $field["formId"] . "," . GFCommon::json_encode($field["conditionalLogicFields"]) . ");' onkeyup='clearTimeout(__gf_timeout_handle); __gf_timeout_handle = setTimeout(\"gf_apply_rules(" . $field["formId"] . "," . GFCommon::json_encode($field["conditionalLogicFields"]) . ")\", 300);'";
            $value_exists = RGFormsModel::choices_value_match($field, $field["choices"], $value);
            $other_label = empty($field['field_bb_click_array_other_label']) ? 'My Best Gift' : $field['field_bb_click_array_other_label'];
            $other_class = rgar($field, 'enableOtherChoice') ? '' : 'hide';
            $html .= "<label for='input_{$field["formId"]}_{$field["id"]}_1' class='ginput_bb_click_array_other_label " . $other_class . "'>" . $other_label . "</label>";
            $other_class .= rgar($field, 'field_bb_click_array_is_product') ? ' ginput_amount gfield_price gfield_price_' . $field['formId'] . '_' . $field['id'] . '_1 gfield_product_' . $field['formId'] . '_' . $field['id'] . '_1' : '';
            $html .= "<input id='input_{$field["formId"]}_{$field["id"]}_1' name='input_{$field["id"]}_1' type='text' value='" . esc_attr($amount) . "' class='ginput_bb ginput_click_array_other " . $other_class . " " . $field['size'] . "' onblur='{$onblur}' {$tabindex} {$onkeyup} {$disabled_text}>";
            $html .= "<input id='input_{$field["formId"]}_{$field["id"]}_5' name='input_{$field["id"]}_5' type='hidden' value='" . esc_attr($clicked) . "' class='ginput_bb ginput_click_array_clicked'>";
        }
        $html .= "</div>";
        return $html;
    }
    return $input;
}
Example #4
0
 public static function notification_page()
 {
     $form_id = rgget('id');
     $notification_id = rgget("nid");
     if (!rgblank($notification_id)) {
         self::notification_edit_page($form_id, $notification_id);
     } else {
         self::notification_list_page($form_id);
     }
 }
 public function validate($value, $form)
 {
     if (!class_exists('RGCurrency')) {
         require_once GFCommon::get_base_path() . '/currency.php';
     }
     $price = GFCommon::to_number($value);
     if (!rgblank($value) && ($price === false || $price < 0)) {
         $this->failed_validation = true;
         $this->validation_message = empty($this->errorMessage) ? __('Please enter a valid amount.', 'gravityforms') : $this->errorMessage;
     }
 }
 public function validate($value, $form)
 {
     $quantity_id = $this->id . '.3';
     $quantity = rgget($quantity_id, $value);
     if ($this->isRequired && rgblank($quantity) && !$this->disableQuantity) {
         $this->failed_validation = true;
         $this->validation_message = empty($this->errorMessage) ? esc_html__('This field is required.', 'gravityforms') : $this->errorMessage;
     } elseif (!empty($quantity) && (!is_numeric($quantity) || intval($quantity) != floatval($quantity) || intval($quantity) < 0)) {
         $this->failed_validation = true;
         $this->validation_message = esc_html__('Please enter a valid quantity', 'gravityforms');
     }
 }
 public function validate($value, $form)
 {
     $email = is_array($value) ? rgar($value, 0) : $value;
     // Form objects created in 1.8 will supply a string as the value.
     if (!rgblank($value) && !GFCommon::is_valid_email($email)) {
         $this->failed_validation = true;
         $this->validation_message = empty($this->errorMessage) ? __('Please enter a valid email address.', 'gravityforms') : $this->errorMessage;
     } elseif ($this->emailConfirmEnabled && !empty($email)) {
         $confirm = is_array($value) ? rgar($value, 1) : rgpost('input_' . $this->id . '_2');
         if ($confirm != $email) {
             $this->failed_validation = true;
             $this->validation_message = __('Your emails do not match.', 'gravityforms');
         }
     }
 }
 /**
  * Make API request.
  * 
  * @access public
  * @param string $action
  * @param array $options (default: array())
  * @param string $method (default: 'GET')
  * @return void
  */
 public function make_request($action = null, $options = array(), $method = 'GET', $expected_code = 200, $return_key = null)
 {
     /* Build request options string. */
     $request_options = 'auth_token=' . $this->api_token;
     $request_options .= $method == 'GET' && !empty($options) ? '&' . http_build_query($options) : '';
     /* Build request URL. */
     $request_url = 'https://' . $this->account_url . '.batchbook.com/api/v1/' . $action . '.json?' . $request_options;
     /* Prepare request and execute. */
     $args = array('method' => $method, 'headers' => array('Content-Type' => 'application/json'));
     if ($method == 'POST' || $method == 'PUT') {
         $args['body'] = json_encode($options);
     }
     $response = wp_remote_request($request_url, $args);
     /* If WP_Error, die. Otherwise, return decoded JSON. */
     if (is_wp_error($response)) {
         die('Request failed. ' . $response->get_error_messages());
     } else {
         if (strpos($response['headers']['content-type'], 'application/json') === FALSE) {
             throw new Exception('Invalid account URL.');
         } else {
             $response_body = json_decode($response['body'], true);
             if (isset($response_body['error'])) {
                 throw new Exception($response_body['error']);
             }
             if (isset($response_body['code']) && $response_body['code'] !== $expected_code) {
                 throw new Exception($response_body['message']);
             }
             if (!rgblank($response_body)) {
                 return empty($return_key) || !empty($return_key) && !isset($response_body[$return_key]) ? $response_body : $response_body[$return_key];
             }
             /* If the body is empty, retrieve the ID from the location header. */
             $id = explode('/', $response['headers']['location']);
             return end($id);
         }
     }
 }
Example #9
0
 /**
  * Validates settings fields.
  * Validates that all fields are valid. Fields can be invalid when they are blank and marked as required or if it fails a custom validation check.
  * To specify a custom validation, use the 'validation_callback' field meta property and implement the validation function with the custom logic.
  * @param $fields - A list of all fields from the field meta configuration
  * @param $settings - A list of submitted settings values
  * @return bool - Returns true if all fields have passed validation, and false otherwise.
  */
 protected function validate_settings($fields, $settings)
 {
     foreach ($fields as $section) {
         foreach ($section['fields'] as $field) {
             $field_setting = rgar($settings, rgar($field, 'name'));
             if (is_callable(rgar($field, 'validation_callback'))) {
                 call_user_func(rgar($field, 'validation_callback'), $field, $field_setting);
             } else {
                 if (rgar($field, 'required')) {
                     if (rgblank($field_setting)) {
                         $this->set_field_error($field, rgar($field, 'error_message'));
                     }
                 }
             }
         }
     }
     $field_errors = $this->get_field_errors();
     $is_valid = empty($field_errors);
     return $is_valid;
 }
 /**
  * Get init script and all necessary data for conditional logic.
  *
  * @todo: Replace much of the field value retrieval with a get_original_value() method in GF_Field class.
  *
  * @param       $form
  * @param array $field_values
  *
  * @return string
  */
 private static function get_conditional_logic($form, $field_values = array())
 {
     $logics = '';
     $dependents = '';
     $fields_with_logic = array();
     $default_values = array();
     foreach ($form['fields'] as $field) {
         /* @var GF_Field $field */
         $field_deps = self::get_conditional_logic_fields($form, $field->id);
         $field_dependents[$field->id] = !empty($field_deps) ? $field_deps : array();
         //use section's logic if one exists
         $section = RGFormsModel::get_section($form, $field->id);
         $section_logic = !empty($section) ? $section->conditionalLogic : null;
         $field_logic = $field->type != 'page' ? $field->conditionalLogic : null;
         //page break conditional logic will be handled during the next button click
         $next_button_logic = !empty($field->nextButton) && !empty($field->nextButton['conditionalLogic']) ? $field->nextButton['conditionalLogic'] : null;
         if (!empty($field_logic) || !empty($next_button_logic)) {
             $field_section_logic = array('field' => $field_logic, 'nextButton' => $next_button_logic, 'section' => $section_logic);
             $logics .= $field->id . ': ' . GFCommon::json_encode($field_section_logic) . ',';
             $fields_with_logic[] = $field->id;
             $peers = $field->type == 'section' ? GFCommon::get_section_fields($form, $field->id) : array($field);
             $peer_ids = array();
             foreach ($peers as $peer) {
                 $peer_ids[] = $peer->id;
             }
             $dependents .= $field->id . ': ' . GFCommon::json_encode($peer_ids) . ',';
         }
         //-- Saving default values so that they can be restored when toggling conditional logic ---
         $field_val = '';
         $input_type = $field->get_input_type();
         $inputs = $field->get_entry_inputs();
         //get parameter value if pre-populate is enabled
         if ($field->allowsPrepopulate) {
             if ($input_type == 'checkbox') {
                 $field_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 if (!is_array($field_val)) {
                     $field_val = explode(',', $field_val);
                 }
             } elseif (is_array($inputs)) {
                 $field_val = array();
                 foreach ($inputs as $input) {
                     $field_val["input_{$input['id']}"] = RGFormsModel::get_parameter_value(rgar($input, 'name'), $field_values, $field);
                 }
             } elseif ($input_type == 'time') {
                 // maintained for backwards compatibility. The Time field now has an inputs array.
                 $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 if (!empty($parameter_val) && preg_match('/^(\\d*):(\\d*) ?(.*)$/', $parameter_val, $matches)) {
                     $field_val = array();
                     $field_val[] = esc_attr($matches[1]);
                     //hour
                     $field_val[] = esc_attr($matches[2]);
                     //minute
                     $field_val[] = rgar($matches, 3);
                     //am or pm
                 }
             } elseif ($input_type == 'list') {
                 $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 $field_val = is_array($parameter_val) ? $parameter_val : explode(',', str_replace('|', ',', $parameter_val));
                 if (is_array(rgar($field_val, 0))) {
                     $list_values = array();
                     foreach ($field_val as $row) {
                         $list_values = array_merge($list_values, array_values($row));
                     }
                     $field_val = $list_values;
                 }
             } else {
                 $field_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
             }
         }
         //use default value if pre-populated value is empty
         $field_val = $field->get_value_default_if_empty($field_val);
         if (is_array($field->choices) && $input_type != 'list') {
             //radio buttons start at 0 and checkboxes start at 1
             $choice_index = $input_type == 'radio' ? 0 : 1;
             $is_pricing_field = GFCommon::is_pricing_field($field->type);
             foreach ($field->choices as $choice) {
                 if ($input_type == 'checkbox' && $choice_index % 10 == 0) {
                     $choice_index++;
                 }
                 $is_prepopulated = is_array($field_val) ? in_array($choice['value'], $field_val) : $choice['value'] == $field_val;
                 $is_choice_selected = rgar($choice, 'isSelected') || $is_prepopulated;
                 if ($is_choice_selected && $input_type == 'select') {
                     $price = GFCommon::to_number(rgar($choice, 'price')) == false ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                     $val = $is_pricing_field && $field->type != 'quantity' ? $choice['value'] . '|' . $price : $choice['value'];
                     $default_values[$field->id] = $val;
                 } elseif ($is_choice_selected) {
                     if (!isset($default_values[$field->id])) {
                         $default_values[$field->id] = array();
                     }
                     $default_values[$field->id][] = "choice_{$form['id']}_{$field->id}_{$choice_index}";
                 }
                 $choice_index++;
             }
         } elseif (!rgblank($field_val)) {
             switch ($input_type) {
                 case 'date':
                     // for date fields; that are multi-input; and where the field value is a string
                     // (happens with prepop, default value will always be an array for multi-input date fields)
                     if (is_array($field->inputs) && (!is_array($field_val) || !isset($field_val['m']))) {
                         $format = empty($field->dateFormat) ? 'mdy' : esc_attr($field->dateFormat);
                         $date_info = GFcommon::parse_date($field_val, $format);
                         // converts date to array( 'm' => 1, 'd' => '13', 'y' => '1987' )
                         $field_val = $field->get_date_array_by_format(array($date_info['month'], $date_info['day'], $date_info['year']));
                     }
                     break;
                 case 'time':
                     if (is_array($field_val)) {
                         $ampm_key = key(array_slice($field_val, -1, 1, true));
                         $field_val[$ampm_key] = strtolower($field_val[$ampm_key]);
                     }
                     break;
                 case 'address':
                     $state_input_id = sprintf('%s.4', $field->id);
                     if (isset($field_val[$state_input_id]) && !$field_val[$state_input_id]) {
                         $field_val[$state_input_id] = $field->defaultState;
                     }
                     $country_input_id = sprintf('%s.6', $field->id);
                     if (isset($field_val[$country_input_id]) && !$field_val[$country_input_id]) {
                         $field_val[$country_input_id] = $field->defaultCountry;
                     }
                     break;
             }
             $default_values[$field->id] = $field_val;
         }
     }
     $button_conditional_script = '';
     //adding form button conditional logic if enabled
     if (isset($form['button']['conditionalLogic'])) {
         $logics .= '0: ' . GFCommon::json_encode(array('field' => $form['button']['conditionalLogic'], 'section' => null)) . ',';
         $dependents .= '0: ' . GFCommon::json_encode(array(0)) . ',';
         $fields_with_logic[] = 0;
         $button_conditional_script = "jQuery('#gform_{$form['id']}').submit(" . 'function(event, isButtonPress){' . '    var visibleButton = jQuery(".gform_next_button:visible, .gform_button:visible, .gform_image_button:visible");' . '    return visibleButton.length > 0 || isButtonPress == true;' . '}' . ');';
     }
     if (!empty($logics)) {
         $logics = substr($logics, 0, strlen($logics) - 1);
     }
     //removing last comma;
     if (!empty($dependents)) {
         $dependents = substr($dependents, 0, strlen($dependents) - 1);
     }
     //removing last comma;
     $animation = rgar($form, 'enableAnimation') ? '1' : '0';
     global $wp_locale;
     $number_format = $wp_locale->number_format['decimal_point'] == ',' ? 'decimal_comma' : 'decimal_dot';
     $str = "if(window['jQuery']){" . "if(!window['gf_form_conditional_logic'])" . "window['gf_form_conditional_logic'] = new Array();" . "window['gf_form_conditional_logic'][{$form['id']}] = { logic: { {$logics} }, dependents: { {$dependents} }, animation: {$animation}, defaults: " . json_encode($default_values) . ", fields: " . json_encode($field_dependents) . " }; " . "if(!window['gf_number_format'])" . "window['gf_number_format'] = '" . $number_format . "';" . 'jQuery(document).ready(function(){' . "gf_apply_rules({$form['id']}, " . json_encode($fields_with_logic) . ', true);' . "jQuery('#gform_wrapper_{$form['id']}').show();" . "jQuery(document).trigger('gform_post_conditional_logic', [{$form['id']}, null, true]);" . $button_conditional_script . '} );' . '} ';
     return $str;
 }
Example #11
0
 public static function all_leads_page()
 {
     $view = rgget('view');
     $lead_id = rgget('lid');
     if ($view == 'entry' && (rgget('lid') || !rgblank(rgget('pos')))) {
         require_once GFCommon::get_base_path() . '/entry_detail.php';
         GFEntryDetail::lead_detail_page();
     } else {
         if ($view == 'entries' || empty($view)) {
             require_once GFCommon::get_base_path() . '/entry_list.php';
             GFEntryList::all_leads_page();
         } else {
             $form_id = rgget('id');
             do_action('gform_entries_view', $view, $form_id, $lead_id);
         }
     }
 }
Example #12
0
 public static function entry_detail_pagination_link($pos, $label = '', $class = '', $icon = '')
 {
     $href = !rgblank($pos) ? 'href="' . add_query_arg(array('pos' => $pos), remove_query_arg(array('pos', 'lid'))) . '"' : '';
     $class .= ' gf_entry_pagination_link';
     $class .= $pos !== false ? ' gf_entry_pagination_link_active' : ' gf_entry_pagination_link_inactive';
     return '<a ' . $href . ' class="' . $class . '" title="' . $label . '"><i class="fa-lg ' . $icon . '"></i></a></li>';
 }
 public static function update_lead_field_value($form, $lead, $field, $lead_detail_id, $input_id, $value)
 {
     global $wpdb;
     $lead_id = $lead['id'];
     $form_id = $form['id'];
     $lead_detail_table = self::get_lead_details_table_name();
     $lead_detail_long_table = self::get_lead_details_long_table_name();
     if (!rgblank($value)) {
         $value = apply_filters('gform_save_field_value', $value, $lead, $field, $form, $input_id);
         $truncated_value = GFCommon::safe_substr($value, 0, GFORMS_MAX_FIELD_LENGTH);
         if ($lead_detail_id > 0) {
             $result = $wpdb->update($lead_detail_table, array('value' => $truncated_value), array('id' => $lead_detail_id), array('%s'), array('%d'));
             if (false === $result) {
                 return false;
             }
             //insert, update or delete long value
             $sql = $wpdb->prepare("SELECT count(0) FROM {$lead_detail_long_table} WHERE lead_detail_id=%d", $lead_detail_id);
             $has_long_field = intval($wpdb->get_var($sql)) > 0;
             //delete long field if value has been shortened
             if ($has_long_field && GFCommon::safe_strlen($value) <= GFORMS_MAX_FIELD_LENGTH) {
                 $sql = $wpdb->prepare("DELETE FROM {$lead_detail_long_table} WHERE lead_detail_id=%d", $lead_detail_id);
                 $result = $wpdb->query($sql);
                 if (false === $result) {
                     return false;
                 }
             } else {
                 if ($has_long_field) {
                     $result = $wpdb->update($lead_detail_long_table, array('value' => $value), array('lead_detail_id' => $lead_detail_id), array('%s'), array('%d'));
                     if (false === $result) {
                         return false;
                     }
                 } else {
                     if (GFCommon::safe_strlen($value) > GFORMS_MAX_FIELD_LENGTH) {
                         $result = $wpdb->insert($lead_detail_long_table, array('lead_detail_id' => $lead_detail_id, 'value' => $value), array('%d', '%s'));
                         if (false === $result) {
                             return false;
                         }
                     }
                 }
             }
         } else {
             $result = $wpdb->insert($lead_detail_table, array('lead_id' => $lead_id, 'form_id' => $form_id, 'field_number' => $input_id, 'value' => $truncated_value), array('%d', '%d', '%F', '%s'));
             if (false === $result) {
                 return false;
             }
             if (GFCommon::safe_strlen($value) > GFORMS_MAX_FIELD_LENGTH) {
                 //read newly created lead detal id
                 $lead_detail_id = $wpdb->insert_id;
                 //insert long value
                 $result = $wpdb->insert($lead_detail_long_table, array('lead_detail_id' => $lead_detail_id, 'value' => $value), array('%d', '%s'));
                 if (false === $result) {
                     return false;
                 }
             }
         }
     } else {
         //Deleting long field if there is one
         $sql = $wpdb->prepare("DELETE {$lead_detail_long_table} FROM {$lead_detail_long_table}\n\t\t\t\tJOIN (\n\t\t\t\t\tSELECT ld.id FROM {$lead_detail_table} ld\n\t\t\t\t\tWHERE lead_id=%d AND field_number BETWEEN %s AND %s\n\t\t\t\t) tmp\n\t\t\t\tON tmp.id = {$lead_detail_long_table}.lead_detail_id", $lead_id, doubleval($input_id) - 0.0001, doubleval($input_id) + 0.0001);
         $result = $wpdb->query($sql);
         if ($result === false) {
             return false;
         }
         //Deleting details for this field
         $sql = $wpdb->prepare("DELETE FROM {$lead_detail_table} WHERE lead_id=%d AND field_number BETWEEN %s AND %s ", $lead_id, doubleval($input_id) - 0.0001, doubleval($input_id) + 0.0001);
         $result = $wpdb->query($sql);
         if (false === $result) {
             return false;
         }
     }
     return true;
 }
 /**
  * Initialized Zoho CRM API if credentials are valid.
  * 
  * @access public
  * @return bool
  */
 public function initialize_api()
 {
     if (!is_null($this->api)) {
         return true;
     }
     /* Include the API library. */
     if (!class_exists('Zoho_CRM')) {
         require_once 'includes/class-zohocrm.php';
     }
     /* Get the plugin settings */
     $settings = $this->get_plugin_settings();
     /* If the auth token, return null. */
     if (rgblank($settings['authToken'])) {
         return null;
     }
     $this->log_debug(__METHOD__ . "(): Validating API credentials.");
     $zohocrm = new Zoho_CRM($settings['authToken']);
     try {
         /* Run API test. */
         $zohocrm->get_users();
         /* Log that test passed. */
         $this->log_debug(__METHOD__ . '(): API credentials are valid.');
         /* Assign Zoho CRM object to the class. */
         $this->api = $zohocrm;
         return true;
     } catch (Exception $e) {
         /* Log that test failed. */
         $this->log_error(__METHOD__ . '(): API credentials are invalid; ' . $e->getMessage());
         return false;
     }
 }
Example #15
0
    public static function payment_details_box($lead, $form)
    {
        ?>
		<!-- PAYMENT BOX -->
		<div id="submitdiv" class="stuffbox">
			<h3 class="hndle" style="cursor:default;">
                <span><?php 
        echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Details', 'gravityforms') : esc_html__('Payment Details', 'gravityforms');
        ?>
</span>
			</h3>

			<div class="inside">
				<div id="submitcomment" class="submitbox">
					<div id="minor-publishing" style="padding:10px;">
						<?php 
        $payment_status = apply_filters('gform_payment_status', $lead['payment_status'], $form, $lead);
        if (!empty($payment_status)) {
            ?>
							<div id="gf_payment_status" class="gf_payment_detail">
								<?php 
            esc_html_e('Status', 'gravityforms');
            ?>
:
								<span id="gform_payment_status"><?php 
            echo $payment_status;
            // May contain HTML
            ?>
</span>
							</div>

							<?php 
            $payment_date = apply_filters('gform_payment_date', GFCommon::format_date($lead['payment_date'], false, 'Y/m/d', $lead['transaction_type'] != 2), $form, $lead);
            if (!empty($payment_date)) {
                ?>
								<div id="gf_payment_date" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Start Date', 'gravityforms') : esc_html__('Date', 'gravityforms');
                ?>
:
									<span id='gform_payment_date'><?php 
                echo $payment_date;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            $transaction_id = apply_filters('gform_payment_transaction_id', $lead['transaction_id'], $form, $lead);
            if (!empty($transaction_id)) {
                ?>
								<div id="gf_payment_transaction_id" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Id', 'gravityforms') : esc_html__('Transaction Id', 'gravityforms');
                ?>
:
									<span id='gform_payment_transaction_id'><?php 
                echo $transaction_id;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            $payment_amount = apply_filters('gform_payment_amount', GFCommon::to_money($lead['payment_amount'], $lead['currency']), $form, $lead);
            if (!rgblank($payment_amount)) {
                ?>
								<div id="gf_payment_amount" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Recurring Amount', 'gravityforms') : esc_html__('Amount', 'gravityforms');
                ?>
:
									<span id='gform_payment_amount'><?php 
                echo $payment_amount;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
        }
        do_action('gform_payment_details', $form['id'], $lead);
        ?>
					</div>
				</div>
			</div>
		</div>
	<?php 
    }
Example #16
0
 public static function confirmations_page()
 {
     $form_id = rgget('id');
     $confirmation_id = rgget('cid');
     if (!rgblank($confirmation_id)) {
         self::confirmations_edit_page($form_id, $confirmation_id);
     } else {
         self::confirmations_list_page($form_id);
     }
 }
 /**
  * Initializes HipChat API if credentials are valid.
  * 
  * @access public
  * @return bool
  */
 public function initialize_api()
 {
     if (!is_null($this->api)) {
         return true;
     }
     /* Load the API library. */
     if (!class_exists('HipChat')) {
         require_once 'includes/class-hipchat.php';
     }
     /* Get the OAuth token. */
     $oauth_token = $this->get_plugin_setting('oauth_token');
     /* If the OAuth token, do not run a validation check. */
     if (rgblank($oauth_token)) {
         return null;
     }
     $this->log_debug(__METHOD__ . '(): Validating API Info.');
     /* Setup a new HipChat object with the API credentials. */
     /**
      * Enable or disable Verification of Hipchat SSL
      *
      * @param bool True or False to verify SSL
      */
     $verify_ssl = apply_filters('gform_hipchat_verify_ssl', true);
     $hipchat = new HipChat($oauth_token, $verify_ssl);
     /* Run an authentication test. */
     if ($hipchat->auth_test()) {
         $this->api = $hipchat;
         $this->log_debug(__METHOD__ . '(): API credentials are valid.');
         return true;
     } else {
         $this->log_error(__METHOD__ . '(): API credentials are invalid.');
         return false;
     }
 }
Example #18
0
 public static function is_section_empty($section_field, $form, $lead)
 {
     $fields = self::get_section_fields($form, $section_field["id"]);
     if (!is_array($fields)) {
         return true;
     }
     foreach ($fields as $field) {
         $val = RGFormsModel::get_lead_field_value($lead, $field);
         $val = GFCommon::get_lead_field_display($field, $val, rgar($lead, 'currency'));
         if (!self::is_product_field($field["type"]) && !rgblank($val)) {
             return false;
         }
     }
     return true;
 }
 public function signature_input($input, $field, $value, $lead_id, $form_id)
 {
     if ($field['type'] != 'signature') {
         return $input;
     }
     $unique_id = IS_ADMIN || $form_id == 0 ? "input_{$field['id']}" : 'input_' . $form_id . "_{$field['id']}";
     $supports_canvas = true;
     require_once 'super_signature/Browser.php';
     $browser = new Browser();
     if ($browser->getBrowser() == Browser::BROWSER_IE) {
         $supports_canvas = $browser->getVersion() >= 9;
     }
     $bgcolor = rgempty('backgroundColor', $field) ? '#FFFFFF' : rgar($field, 'backgroundColor');
     $bordercolor = rgempty('borderColor', $field) ? '#DDDDDD' : rgar($field, 'borderColor');
     $pencolor = rgempty('penColor', $field) ? '#000000' : rgar($field, 'penColor');
     $boxwidth = rgblank(rgget('boxWidth', $field)) ? '300' : rgar($field, 'boxWidth');
     $borderstyle = rgempty('borderStyle', $field) ? 'Dashed' : rgar($field, 'borderStyle');
     $borderwidth = rgblank(rgget('borderWidth', $field)) ? '2' : rgar($field, 'borderWidth');
     $pensize = rgblank(rgget('penSize', $field)) ? '2' : rgar($field, 'penSize');
     if (RG_CURRENT_VIEW != 'entry' && is_admin()) {
         //box width is hardcoded in the admin
         $input = '<style>' . ".top_label .gf_signature_container {width: 460px;} " . ".left_label .gf_signature_container, .right_label .gf_signature_container {width: 300px;} " . "</style>" . "<div style='display:-moz-inline-stack; display: inline-block; zoom: 1; *display: inline;'><div class='gf_signature_container' style='height:180px; border: {$borderwidth}px {$borderstyle} {$bordercolor}; background-color:{$bgcolor};'></div></div>";
         // if frontend OR entry detail
     } else {
         $input = '';
         if (RG_CURRENT_VIEW == 'entry') {
             //include super signature script when viewing the entry in the admin
             $input = "<script src='" . $this->get_base_url() . '/super_signature/ss.js?ver=' . $this->_version . "' type='text/javascript'></script>";
         }
         $signature_filename = !empty($value) ? $value : rgpost("{$unique_id}_signature_filename");
         if (!empty($signature_filename)) {
             $input .= "<div id='{$unique_id}_signature_image'>" . "<img src='" . $this->get_signature_url($signature_filename) . "' width='{$boxwidth}px'/>" . "   <div>";
             if (RG_CURRENT_VIEW == 'entry' && $value) {
                 //include the links to download/delete image
                 $input .= "       <a href='" . $this->get_signature_url($signature_filename) . "' target='_blank' alt='" . __('Download file', 'gravityformssignature') . "' title='" . __('Download file', 'gravityformssignature') . "'><img src='" . GFCommon::get_base_url() . '/images/download.png' . "' /></a>" . "       <a href='javascript:void(0);' alt='" . __('Delete file', 'gravityformssignature') . "' title='" . __('Delete file', 'gravityformssignature') . "' onclick='deleteSignature(" . $lead_id . ', ' . $field['id'] . ");' ><img src='" . GFCommon::get_base_url() . '/images/delete.png' . "' style='margin-left:8px;'/></a>";
             } else {
                 $input .= "       <a href='#' onclick='jQuery(\"#{$unique_id}_signature_filename\").val(\"\"); jQuery(\"#{$unique_id}_signature_image\").hide(); jQuery(\"#{$unique_id}_Container\").show(); jQuery(\"#{$unique_id}_resetbutton\").show(); return false;'>" . __('sign again', 'gravityformssignature') . '</a>';
             }
             $input .= '   </div>' . "</div>" . "<input type='hidden' value='{$signature_filename}' name='{$unique_id}_signature_filename' id='{$unique_id}_signature_filename'/>" . "<style type='text/css'>#{$unique_id}_resetbutton {display:none}</style>";
         }
         $display = !empty($signature_filename) ? 'display:none;' : '';
         $form = RGFormsModel::get_form_meta($form_id);
         $container_style = $form['labelPlacement'] == 'top_label' ? '' : "style='display:-moz-inline-stack; display: inline-block; zoom: 1; *display: inline;'";
         $input .= "<div {$container_style}>\n\t\t\t\t\t<div id='{$unique_id}_Container' style='height:180px; width: {$boxwidth}px; {$display}' >\n\t\t\t\t\t\t<input type='hidden' class='gform_hidden' name='{$unique_id}_valid' id='{$unique_id}_valid' />";
         if ($supports_canvas) {
             $input .= "<canvas id='{$unique_id}' width='{$boxwidth}' height='180'></canvas>";
         } else {
             $input .= "<div id='{$unique_id}' style='width:{$boxwidth}px; height:180px; border:{$borderstyle} {$borderwidth}px {$bordercolor}; background-color:{$bgcolor};'></div>";
         }
         $input .= "\n\t\t\t\t\t</div>\n\t\t\t\t  </div>\n\t\t\t\t  <script type='text/javascript'>" . "if(typeof SuperSignature != 'undefined'){" . "var obj{$unique_id} = new SuperSignature({IeModalFix: false, SignObject:'{$unique_id}',BackColor: '{$bgcolor}', PenSize: '{$pensize}', PenColor: '{$pencolor}',SignWidth: '{$boxwidth}',SignHeight: '180' ,BorderStyle:'{$borderstyle}',BorderWidth: '{$borderwidth}px',BorderColor: '{$bordercolor}', RequiredPoints: '15',ClearImage:'" . $this->get_base_url() . "/super_signature/refresh.png', PenCursor:'" . $this->get_base_url() . "/super_signature/pen.cur', Visible: 'true', ErrorMessage: '', StartMessage: '', SuccessMessage: ''});" . "obj{$unique_id}.Init();" . "jQuery('#gform_{$form_id}').submit(function(){" . "       jQuery('#{$unique_id}_valid').val(obj{$unique_id}.IsValid() || jQuery('#{$unique_id}_signature_filename').val() ? '1' : '');" . "});" . "}" . "</script>";
     }
     return $input;
 }
Example #20
0
 public static function all_leads_page()
 {
     //displaying lead detail page if lead id is in the query string
     if (rgget('lid') || !rgblank(rgget('pos'))) {
         require_once GFCommon::get_base_path() . "/entry_detail.php";
         GFEntryDetail::lead_detail_page();
     } else {
         require_once GFCommon::get_base_path() . "/entry_list.php";
         GFEntryList::all_leads_page();
     }
 }
Example #21
0
 public static function is_section_empty($section_field, $form, $lead)
 {
     $cache_key = "GFCommon::is_section_empty_" . $form["id"] . "_" . $section_field["id"];
     $value = GFCache::get($cache_key);
     if ($value !== false) {
         return $value == true;
     }
     $fields = self::get_section_fields($form, $section_field["id"]);
     if (!is_array($fields)) {
         GFCache::set($cache_key, 1);
         return true;
     }
     foreach ($fields as $field) {
         $val = RGFormsModel::get_lead_field_value($lead, $field);
         $val = GFCommon::get_lead_field_display($field, $val, rgar($lead, 'currency'));
         if (!self::is_product_field($field["type"]) && !rgblank($val)) {
             GFCache::set($cache_key, 0);
             return false;
         }
     }
     GFCache::set($cache_key, 1);
     return true;
 }
Example #22
0
    public static function payment_details_box($lead, $form)
    {
        ?>
		<!-- PAYMENT BOX -->
		<div id="submitdiv" class="stuffbox">
			<h3 class="hndle" style="cursor:default;">
                <span><?php 
        echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Details', 'gravityforms') : esc_html__('Payment Details', 'gravityforms');
        ?>
</span>
			</h3>

			<div class="inside">
				<div id="submitcomment" class="submitbox">
					<div id="minor-publishing" style="padding:10px;">
						<?php 
        $payment_status = apply_filters('gform_payment_status', $lead['payment_status'], $form, $lead);
        if (!empty($payment_status)) {
            ?>
							<div id="gf_payment_status" class="gf_payment_detail">
								<?php 
            esc_html_e('Status', 'gravityforms');
            ?>
:
								<span id="gform_payment_status"><?php 
            echo $payment_status;
            // May contain HTML
            ?>
</span>
							</div>

							<?php 
            /**
             * Allows for modification on the form payment date format
             *
             * @param array $form The Form object to filter through
             * @param array $lead The Lead object to filter through
             */
            $payment_date = apply_filters('gform_payment_date', GFCommon::format_date($lead['payment_date'], false, 'Y/m/d', $lead['transaction_type'] != 2), $form, $lead);
            if (!empty($payment_date)) {
                ?>
								<div id="gf_payment_date" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Start Date', 'gravityforms') : esc_html__('Date', 'gravityforms');
                ?>
:
									<span id='gform_payment_date'><?php 
                echo $payment_date;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            /**
             * Allows filtering through a payment transaction ID
             *
             * @param int $lead['transaction_id'] The transaction ID that can be modified
             * @param array $form The Form object to be filtered when modifying the transaction ID
             * @param array $lead The Lead object to be filtered when modifying the transaction ID
             */
            $transaction_id = apply_filters('gform_payment_transaction_id', $lead['transaction_id'], $form, $lead);
            if (!empty($transaction_id)) {
                ?>
								<div id="gf_payment_transaction_id" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Id', 'gravityforms') : esc_html__('Transaction Id', 'gravityforms');
                ?>
:
									<span id='gform_payment_transaction_id'><?php 
                echo $transaction_id;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            /**
             * Filter through the way the Payment Amount is rendered
             *
             * @param string $lead['payment_amount'] The payment amount taken from the lead object
             * @param string $lead['currency'] The payment currency taken from the lead object
             * @param array $form The Form onject to filter through
             * @param array $lead The lead object to filter through
             */
            $payment_amount = apply_filters('gform_payment_amount', GFCommon::to_money($lead['payment_amount'], $lead['currency']), $form, $lead);
            if (!rgblank($payment_amount)) {
                ?>
								<div id="gf_payment_amount" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Recurring Amount', 'gravityforms') : esc_html__('Amount', 'gravityforms');
                ?>
:
									<span id='gform_payment_amount'><?php 
                echo $payment_amount;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
        }
        /**
         * Fires after the Form Payment Details (The type of payment, the cost, the ID, etc)
         *
         * @param int $form['id'] The current Form ID
         * @param array $lead The current Lead object
         */
        do_action('gform_payment_details', $form['id'], $lead);
        ?>
					</div>
				</div>
			</div>
		</div>
	<?php 
    }
 protected function validate_field_map_settings($field, $settings)
 {
     $field_map = rgar($field, 'field_map');
     if (empty($field_map)) {
         return;
     }
     foreach ($field_map as $child_field) {
         if (!$this->setting_dependency_met(rgar($child_field, 'dependency'))) {
             continue;
         }
         $child_field['name'] = $this->get_mapped_field_name($field, $child_field['name']);
         $setting_value = rgar($settings, $child_field['name']);
         if (rgar($child_field, 'required') && rgblank($setting_value)) {
             $this->set_field_error($child_field);
         } else {
             if (rgar($child_field, 'validation_callback') && is_callable(rgar($child_field, 'validation_callback'))) {
                 call_user_func(rgar($child_field, 'validation_callback'), $child_field, $field);
             }
         }
     }
 }
Example #24
0
 public static function prepopulate_form($form, $config)
 {
     global $bp;
     $mapped_fields = array();
     $meta = rgar($config, 'meta');
     $user = wp_get_current_user();
     foreach (array('username', 'lastname', 'firstname', 'email') as $meta_key) {
         $field_id = rgar($meta, $meta_key);
         if ($field_id) {
             $mapped_fields[(string) $field_id] = $user->get(self::convert_to_wp_meta_key($meta_key));
         }
     }
     $custom_meta = rgars($config, 'meta/user_meta') ? rgars($config, 'meta/user_meta') : array();
     foreach ($custom_meta as $meta_item) {
         if (rgar($meta_item, 'meta_value')) {
             $field_id = rgar($meta_item, 'meta_value');
             $mapped_fields[(string) $field_id] = $user->get(rgar($meta_item, 'meta_name'));
         }
     }
     if (function_exists("xprofile_get_field_data")) {
         $buddypress_meta = rgars($config, 'meta/buddypress_meta') ? rgars($config, 'meta/buddypress_meta') : array();
         foreach ($buddypress_meta as $meta_item) {
             if (rgar($meta_item, 'meta_value')) {
                 $field_id = rgar($meta_item, 'meta_value');
                 $value = xprofile_get_field_data(rgar($meta_item, 'meta_name'), $user->ID);
                 $mapped_fields[(string) $field_id] = is_array($value) ? array_map('html_entity_decode', $value) : html_entity_decode($value);
             }
         }
     }
     $mapped_fields = apply_filters('gform_user_registration_user_data_pre_populate', $mapped_fields, $form, $config);
     // get all fields for cheap check inside field loop
     $mapped_field_ids = array_map('intval', array_keys($mapped_fields));
     foreach ($form['fields'] as &$field) {
         if (!in_array($field['id'], $mapped_field_ids)) {
             continue;
         }
         $value = false;
         switch (RGFormsModel::get_input_type($field)) {
             case 'fileupload':
                 $value = rgar($mapped_fields, $field['id']);
                 $path_info = pathinfo($value);
                 // check if file has been "deleted" via form UI
                 $upload_files = json_decode(rgpost('gform_uploaded_files'), ARRAY_A);
                 $input_name = "input_{$field['id']}";
                 if (is_array($upload_files) && array_key_exists($input_name, $upload_files) && !$upload_files[$input_name]) {
                     continue;
                 }
                 // if $uploaded_files array is not set for this form at all, init as array
                 if (!isset(RGFormsModel::$uploaded_files[$form['id']])) {
                     RGFormsModel::$uploaded_files[$form['id']] = array();
                 }
                 // check if this field's key has been set in the $uploaded_files array, if not add this file (otherwise, a new image may have been uploaded so don't overwrite)
                 if (!isset(RGFormsModel::$uploaded_files[$form['id']]["input_{$field['id']}"])) {
                     RGFormsModel::$uploaded_files[$form['id']]["input_{$field['id']}"] = $path_info['basename'];
                 }
                 break;
             case 'checkbox':
                 $value = rgar($mapped_fields, $field['id']);
                 $cb_values = array();
                 if (is_array($value)) {
                     $cb_values = $value;
                 } else {
                     $inputs = $field['inputs'];
                     foreach ($inputs as &$input) {
                         $cb_values[] = rgar($mapped_fields, (string) $input['id']);
                     }
                     $field['inputs'] = $inputs;
                 }
                 $value = implode(',', $cb_values);
                 break;
             case 'list':
                 $value = maybe_unserialize(rgar($mapped_fields, $field['id']));
                 $list_values = array();
                 if (is_array($value)) {
                     foreach ($value as $vals) {
                         if (!is_array($vals)) {
                             $vals = array($vals);
                         }
                         $list_values = array_merge($list_values, array_values($vals));
                     }
                     $value = $list_values;
                 }
                 break;
             case 'date':
                 $value = GFCommon::date_display(rgar($mapped_fields, $field['id']), $field['dateFormat'], false);
                 break;
             default:
                 // handle complex fields
                 $inputs = $field instanceof GF_Field ? $field->get_entry_inputs() : rgar($field, 'inputs');
                 if (is_array($inputs)) {
                     foreach ($inputs as &$input) {
                         $filter_name = self::prepopulate_input($input['id'], rgar($mapped_fields, (string) $input['id']));
                         $field['allowsPrepopulate'] = true;
                         $input['name'] = $filter_name;
                     }
                     $field['inputs'] = $inputs;
                 } else {
                     $value = is_array(rgar($mapped_fields, $field['id'])) ? implode(',', rgar($mapped_fields, $field['id'])) : rgar($mapped_fields, $field['id']);
                 }
         }
         if (rgblank($value)) {
             continue;
         }
         $value = self::maybe_get_category_id($field, $value);
         $filter_name = self::prepopulate_input($field['id'], $value);
         $field['allowsPrepopulate'] = true;
         $field['inputName'] = $filter_name;
     }
     return $form;
 }
Example #25
0
 public static function validate(&$form, $field_values, $page_number = 0, &$failed_validation_page = 0)
 {
     $form = apply_filters('gform_pre_validation', $form);
     // validate form schedule
     if (self::validate_form_schedule($form)) {
         return false;
     }
     // validate entry limit
     if (self::validate_entry_limit($form)) {
         return false;
     }
     foreach ($form["fields"] as &$field) {
         //If a page number is specified, only validates fields that are on current page
         $field_in_other_page = $page_number > 0 && $field["pageNumber"] != $page_number;
         //validate fields with "no duplicate" functionality when they are present on pages before the current page.
         $validate_duplicate_feature = $field["noDuplicates"] && $page_number > 0 && $field["pageNumber"] <= $page_number;
         if ($field_in_other_page && !$validate_duplicate_feature) {
             continue;
         }
         //ignore validation if field is hidden or admin only
         if (RGFormsModel::is_field_hidden($form, $field, $field_values) || $field["adminOnly"]) {
             continue;
         }
         $value = RGFormsModel::get_field_value($field);
         //display error message if field is marked as required and the submitted value is empty
         if ($field["isRequired"] && self::is_empty($field, $form["id"])) {
             $field["failed_validation"] = true;
             $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
         } else {
             if ($field["noDuplicates"] && RGFormsModel::is_duplicate($form["id"], $field, $value)) {
                 $field["failed_validation"] = true;
                 //set page number so the failed field displays if on multi-page form
                 $failed_validation_page = $field["pageNumber"];
                 $input_type = RGFormsModel::get_input_type($field);
                 switch ($input_type) {
                     case "date":
                         $default_message = __("This date has already been taken. Please select a new date.", "gravityforms");
                         break;
                     default:
                         $default_message = is_array($value) ? __("This field requires an unique entry and the values you entered have been already been used.", "gravityforms") : sprintf(__("This field requires an unique entry and '%s' has already been used", "gravityforms"), $value);
                         break;
                 }
                 $field["validation_message"] = apply_filters("gform_duplicate_message_{$form["id"]}", apply_filters("gform_duplicate_message", $default_message, $form), $form);
             } else {
                 if (self::failed_state_validation($form["id"], $field, $value)) {
                     $field["failed_validation"] = true;
                     $field["validation_message"] = in_array($field["inputType"], array("singleproduct", "singleshipping", "hiddenproduct")) ? __("Please enter a valid value.", "gravityforms") : __("Invalid selection. Please select one of the available choices.", "gravityforms");
                 } else {
                     switch (RGFormsModel::get_input_type($field)) {
                         case "password":
                             $password = $_POST["input_" . $field["id"]];
                             $confirm = $_POST["input_" . $field["id"] . "_2"];
                             if ($password != $confirm) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = __("Your passwords do not match.", "gravityforms");
                             } else {
                                 if (rgar($field, "passwordStrengthEnabled") && !rgempty("minPasswordStrength", $field) && !empty($password)) {
                                     $strength = $_POST["input_" . $field["id"] . "_strength"];
                                     $levels = array("short" => 1, "bad" => 2, "good" => 3, "strong" => 4);
                                     if ($levels[$strength] < $levels[$field["minPasswordStrength"]]) {
                                         $field["failed_validation"] = true;
                                         $field["validation_message"] = empty($field["errorMessage"]) ? __("Your password does not meet the required strength. <br/>Hint: To make it stronger, use upper and lower case letters, numbers and symbols like ! \" ? \$ % ^ & ).", "gravityforms") : $field["errorMessage"];
                                     }
                                 }
                             }
                             break;
                         case "name":
                             if ($field["isRequired"] && $field["nameFormat"] != "simple") {
                                 $first = $_POST["input_" . $field["id"] . "_3"];
                                 $last = $_POST["input_" . $field["id"] . "_6"];
                                 if (empty($first) || empty($last)) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter the first and last name.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "address":
                             if ($field["isRequired"]) {
                                 $street = $_POST["input_" . $field["id"] . "_1"];
                                 $city = $_POST["input_" . $field["id"] . "_3"];
                                 $state = $_POST["input_" . $field["id"] . "_4"];
                                 $zip = $_POST["input_" . $field["id"] . "_5"];
                                 $country = $_POST["input_" . $field["id"] . "_6"];
                                 if (empty($street) || empty($city) || empty($zip) || empty($state) && !$field["hideState"] || empty($country) && !$field["hideCountry"]) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a complete address.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "creditcard":
                             $card_number = rgpost("input_" . $field["id"] . "_1");
                             $expiration_date = rgpost("input_" . $field["id"] . "_2");
                             $security_code = rgpost("input_" . $field["id"] . "_3");
                             if (rgar($field, "isRequired") && (empty($card_number) || empty($security_code) || empty($expiration_date[0]) || empty($expiration_date[1]))) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter your credit card information.", "gravityforms") : $field["errorMessage"];
                             } else {
                                 if (!empty($card_number)) {
                                     $card_type = GFCommon::get_card_type($card_number);
                                     $security_code = rgpost("input_" . $field["id"] . "_3");
                                     if (empty($security_code)) {
                                         $field["failed_validation"] = true;
                                         $field["validation_message"] = __("Please enter your card's security code.", "gravityforms");
                                     } else {
                                         if (!$card_type) {
                                             $field["failed_validation"] = true;
                                             $field["validation_message"] = __("Invalid credit card number.", "gravityforms");
                                         } else {
                                             if (!GFCommon::is_card_supported($field, $card_type["slug"])) {
                                                 $field["failed_validation"] = true;
                                                 $field["validation_message"] = $card_type["name"] . " " . __("is not supported. Please enter one of the supported credit cards.", "gravityforms");
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         case "email":
                             if (!rgblank($value) && !GFCommon::is_valid_email($value)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid email address.", "gravityforms") : $field["errorMessage"];
                             } else {
                                 if (rgget("emailConfirmEnabled", $field) && !empty($value)) {
                                     $confirm = rgpost("input_" . $field["id"] . "_2");
                                     if ($confirm != $value) {
                                         $field["failed_validation"] = true;
                                         $field["validation_message"] = __("Your emails do not match.", "gravityforms");
                                     }
                                 }
                             }
                             break;
                         case "donation":
                         case "price":
                             if (!class_exists("RGCurrency")) {
                                 require_once "currency.php";
                             }
                             $donation = GFCommon::to_number($value);
                             if (!rgblank($value) && ($donation === false || $donation < 0)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid amount.", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                         case "number":
                             if (!rgblank($value) && !self::validate_range($field, $value) && !GFCommon::has_field_calculation($field)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? GFCommon::get_range_message($field) : $field["errorMessage"];
                             } else {
                                 if ($field["type"] == "quantity" && intval($value) != $value) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid quantity. Quantity cannot contain decimals.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "phone":
                             $regex = '/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/';
                             if ($field["phoneFormat"] == "standard" && !empty($value) && !preg_match($regex, $value)) {
                                 $field["failed_validation"] = true;
                                 if (!empty($field["errorMessage"])) {
                                     $field["validation_message"] = $field["errorMessage"];
                                 }
                             }
                             break;
                         case "date":
                             if (is_array($value) && rgempty(0, $value) && rgempty(1, $value) && rgempty(2, $value)) {
                                 $value = null;
                             }
                             if (!empty($value)) {
                                 $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"];
                                 $date = GFCommon::parse_date($value, $format);
                                 if (empty($date) || !self::checkdate($date["month"], $date["day"], $date["year"])) {
                                     $field["failed_validation"] = true;
                                     $format_name = "";
                                     switch ($format) {
                                         case "mdy":
                                             $format_name = "mm/dd/yyyy";
                                             break;
                                         case "dmy":
                                             $format_name = "dd/mm/yyyy";
                                             break;
                                         case "dmy_dash":
                                             $format_name = "dd-mm-yyyy";
                                             break;
                                         case "dmy_dot":
                                             $format_name = "dd.mm.yyyy";
                                             break;
                                         case "ymd_slash":
                                             $format_name = "yyyy/mm/dd";
                                             break;
                                         case "ymd_dash":
                                             $format_name = "yyyy-mm-dd";
                                             break;
                                         case "ymd_dot":
                                             $format_name = "yyyy.mm.dd";
                                             break;
                                     }
                                     $message = $field["dateType"] == "datepicker" ? sprintf(__("Please enter a valid date in the format (%s).", "gravityforms"), $format_name) : __("Please enter a valid date.", "gravityforms");
                                     $field["validation_message"] = empty($field["errorMessage"]) ? $message : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "time":
                             //create variable values if time came in one field
                             if (!is_array($value) && !empty($value)) {
                                 preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
                                 $value = array();
                                 $value[0] = $matches[1];
                                 $value[1] = $matches[2];
                             }
                             $hour = $value[0];
                             $minute = $value[1];
                             if (empty($hour) && empty($minute)) {
                                 break;
                             }
                             $is_valid_format = is_numeric($hour) && is_numeric($minute);
                             $min_hour = rgar($field, "timeFormat") == "24" ? 0 : 1;
                             $max_hour = rgar($field, "timeFormat") == "24" ? 23 : 12;
                             if (!$is_valid_format || $hour < $min_hour || $hour > $max_hour || $minute < 0 || $minute >= 60) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid time.", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                         case "website":
                             if (empty($value) || $value == "http://") {
                                 $value = "";
                                 if ($field["isRequired"]) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             if (!empty($value) && !GFCommon::is_valid_url($value)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid Website URL (i.e. http://www.gravityforms.com).", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                         case "captcha":
                             switch ($field["captchaType"]) {
                                 case "simple_captcha":
                                     if (class_exists("ReallySimpleCaptcha")) {
                                         $prefix = $_POST["input_captcha_prefix_{$field["id"]}"];
                                         $captcha_obj = GFCommon::get_simple_captcha();
                                         if (!$captcha_obj->check($prefix, str_replace(" ", "", $value))) {
                                             $field["failed_validation"] = true;
                                             $field["validation_message"] = empty($field["errorMessage"]) ? __("The CAPTCHA wasn't entered correctly. Go back and try it again.", "gravityforms") : $field["errorMessage"];
                                         }
                                         //removes old files in captcha folder (older than 1 hour);
                                         $captcha_obj->cleanup();
                                     }
                                     break;
                                 case "math":
                                     $prefixes = explode(",", $_POST["input_captcha_prefix_{$field["id"]}"]);
                                     $captcha_obj = GFCommon::get_simple_captcha();
                                     //finding first number
                                     $first = 0;
                                     for ($first = 0; $first < 10; $first++) {
                                         if ($captcha_obj->check($prefixes[0], $first)) {
                                             break;
                                         }
                                     }
                                     //finding second number
                                     $second = 0;
                                     for ($second = 0; $second < 10; $second++) {
                                         if ($captcha_obj->check($prefixes[2], $second)) {
                                             break;
                                         }
                                     }
                                     //if it is a +, perform the sum
                                     if ($captcha_obj->check($prefixes[1], "+")) {
                                         $result = $first + $second;
                                     } else {
                                         $result = $first - $second;
                                     }
                                     if (intval($result) != intval($value)) {
                                         $field["failed_validation"] = true;
                                         $field["validation_message"] = empty($field["errorMessage"]) ? __("The CAPTCHA wasn't entered correctly. Go back and try it again.", "gravityforms") : $field["errorMessage"];
                                     }
                                     //removes old files in captcha folder (older than 1 hour);
                                     $captcha_obj->cleanup();
                                     break;
                                 default:
                                     if (!function_exists("recaptcha_get_html")) {
                                         require_once GFCommon::get_base_path() . '/recaptchalib.php';
                                     }
                                     $privatekey = get_option("rg_gforms_captcha_private_key");
                                     $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
                                     if (!$resp->is_valid) {
                                         $field["failed_validation"] = true;
                                         $field["validation_message"] = empty($field["errorMessage"]) ? __("The reCAPTCHA wasn't entered correctly. Go back and try it again.", "gravityforms") : $field["errorMessage"];
                                     }
                             }
                             break;
                         case "fileupload":
                         case "post_image":
                             $info = pathinfo($_FILES["input_" . $field["id"]]["name"]);
                             $allowedExtensions = self::clean_extensions(explode(",", strtolower($field["allowedExtensions"])));
                             $extension = strtolower(rgget("extension", $info));
                             if (empty($field["allowedExtensions"]) && in_array($extension, array("php", "asp", "exe", "com", "htaccess"))) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("The uploaded file type is not allowed.", "gravityforms") : $field["errorMessage"];
                             } else {
                                 if (!empty($field["allowedExtensions"]) && !empty($info["basename"]) && !in_array($extension, $allowedExtensions)) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? sprintf(__("The uploaded file type is not allowed. Must be one of the following: %s", "gravityforms"), strtolower($field["allowedExtensions"])) : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "calculation":
                         case "singleproduct":
                         case "hiddenproduct":
                             $quantity_id = $field["id"] . ".3";
                             $quantity = rgget($quantity_id, $value);
                             if ($field["isRequired"] && rgblank($quantity) && !rgar($field, "disableQuantity")) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = rgempty("errorMessage", $field) ? __("This field is required.", "gravityforms") : rgar($field, "errorMessage");
                             } else {
                                 if (!empty($quantity) && (!is_numeric($quantity) || intval($quantity) != floatval($quantity))) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = __("Please enter a valid quantity", "gravityforms");
                                 }
                             }
                             break;
                         case "radio":
                             if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
                                 $value = rgpost("input_{$field['id']}_other");
                             }
                             if ($field["isRequired"] && rgar($field, 'enableOtherChoice') && $value == GFCommon::get_other_choice_value()) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
                             }
                             break;
                     }
                 }
             }
         }
         $custom_validation_result = apply_filters("gform_field_validation", array("is_valid" => rgar($field, "failed_validation") ? false : true, "message" => rgar($field, "validation_message")), $value, $form, $field);
         $custom_validation_result = apply_filters("gform_field_validation_{$form["id"]}", $custom_validation_result, $value, $form, $field);
         $custom_validation_result = apply_filters("gform_field_validation_{$form["id"]}_{$field["id"]}", $custom_validation_result, $value, $form, $field);
         $field["failed_validation"] = rgar($custom_validation_result, "is_valid") ? false : true;
         $field["validation_message"] = rgar($custom_validation_result, "message");
     }
     $is_valid = true;
     foreach ($form["fields"] as $f) {
         if (rgar($f, "failed_validation")) {
             $is_valid = false;
             break;
         }
     }
     $validation_result = apply_filters("gform_validation_{$form["id"]}", apply_filters("gform_validation", array("is_valid" => $is_valid, "form" => $form)));
     $is_valid = $validation_result["is_valid"];
     $form = $validation_result["form"];
     return $is_valid;
 }
Example #26
0
    /**
     * @param $lead
     * @param $form
     * @return mixed
     */
    public static function payment_details_box($lead, $form)
    {
        ?>
        <!-- PAYMENT BOX -->
        <div id="submitdiv" class="stuffbox">
            <h3>
                <span
                    class="hndle"><?php 
        echo $lead["transaction_type"] == 2 ? __("Subscription Details", "gravityforms") : __("Payment Details", "gravityforms");
        ?>
</span>
            </h3>

            <div class="inside">
                <div id="submitcomment" class="submitbox">
                    <div id="minor-publishing" style="padding:10px;">
                        <br/>
                        <?php 
        if (!empty($lead["payment_status"])) {
            echo __("Status", "gravityforms");
            ?>
: <span
                                id="gform_payment_status"><?php 
            echo apply_filters("gform_payment_status", $lead["payment_status"], $form, $lead);
            ?>
</span>
                            <br/><br/>
                            <?php 
            if (!empty($lead["payment_date"])) {
                echo $lead["transaction_type"] == 2 ? __("Start Date", "gravityforms") : __("Date", "gravityforms");
                ?>
: <?php 
                echo GFCommon::format_date($lead["payment_date"], false, "Y/m/d", $lead["transaction_type"] != 2);
                ?>
                                <br/><br/>
                            <?php 
            }
            if (!empty($lead["transaction_id"])) {
                echo $lead["transaction_type"] == 2 ? __("Subscription Id", "gravityforms") : __("Transaction Id", "gravityforms");
                ?>
: <?php 
                echo $lead["transaction_id"];
                ?>
                                <br/><br/>
                            <?php 
            }
            if (!rgblank($lead["payment_amount"])) {
                echo $lead["transaction_type"] == 2 ? __("Recurring Amount", "gravityforms") : __("Amount", "gravityforms");
                ?>
: <?php 
                echo GFCommon::to_money($lead["payment_amount"], $lead["currency"]);
                ?>
                                <br/><br/>
                            <?php 
            }
        }
        do_action("gform_payment_details", $form["id"], $lead);
        ?>
                    </div>
                </div>
            </div>
        </div>
        <?php 
    }
Example #27
0
 public static function create_post($form, &$lead)
 {
     $has_post_field = false;
     foreach ($form["fields"] as $field) {
         $is_hidden = self::is_field_hidden($form, $field, array(), $lead);
         if (!$is_hidden && in_array($field["type"], array("post_category", "post_title", "post_content", "post_excerpt", "post_tags", "post_custom_field", "post_image"))) {
             $has_post_field = true;
             break;
         }
     }
     //if this form does not have any post fields, don't create a post
     if (!$has_post_field) {
         return $lead;
     }
     //processing post fields
     $post_data = self::get_post_fields($form, $lead);
     //allowing users to change post fields before post gets created
     $post_data = apply_filters("gform_post_data_{$form["id"]}", apply_filters("gform_post_data", $post_data, $form, $lead), $form, $lead);
     //adding default title if none of the required post fields are in the form (will make sure wp_insert_post() inserts the post)
     if (empty($post_data["post_title"]) && empty($post_data["post_content"]) && empty($post_data["post_excerpt"])) {
         $post_data["post_title"] = self::get_default_post_title();
     }
     //inserting post
     if (GFCommon::is_bp_active()) {
         //disable buddy press action so save_post is not called because the post data is not yet complete at this point
         remove_action("save_post", "bp_blogs_record_post");
     }
     $post_id = wp_insert_post($post_data);
     //adding form id and entry id hidden custom fields
     add_post_meta($post_id, "_gform-form-id", $form["id"]);
     add_post_meta($post_id, "_gform-entry-id", $lead["id"]);
     //creating post images
     $post_images = array();
     foreach ($post_data["images"] as $image) {
         $image_meta = array("post_excerpt" => $image["caption"], "post_content" => $image["description"]);
         //adding title only if it is not empty. It will default to the file name if it is not in the array
         if (!empty($image["title"])) {
             $image_meta["post_title"] = $image["title"];
         }
         if (!empty($image["url"])) {
             $media_id = self::media_handle_upload($image["url"], $post_id, $image_meta);
             if ($media_id) {
                 //save media id for post body/title template variable replacement (below)
                 $post_images[$image["field_id"]] = $media_id;
                 $lead[$image["field_id"]] .= "|:|{$media_id}";
                 // set featured image
                 $field = RGFormsModel::get_field($form, $image["field_id"]);
                 if (rgar($field, 'postFeaturedImage')) {
                     set_post_thumbnail($post_id, $media_id);
                 }
             }
         }
     }
     //adding custom fields
     foreach ($post_data["post_custom_fields"] as $meta_name => $meta_value) {
         if (!is_array($meta_value)) {
             $meta_value = array($meta_value);
         }
         $meta_index = 0;
         foreach ($meta_value as $value) {
             $custom_field = self::get_custom_field($form, $meta_name, $meta_index);
             //replacing template variables if template is enabled
             if ($custom_field && rgget("customFieldTemplateEnabled", $custom_field)) {
                 //replacing post image variables
                 $value = GFCommon::replace_variables_post_image($custom_field["customFieldTemplate"], $post_images, $lead);
                 //replacing all other variables
                 $value = GFCommon::replace_variables($value, $form, $lead, false, false, false);
                 // replace conditional shortcodes
                 $value = do_shortcode($value);
             }
             switch (RGFormsModel::get_input_type($custom_field)) {
                 case "list":
                     $value = maybe_unserialize($value);
                     if (is_array($value)) {
                         foreach ($value as $item) {
                             if (is_array($item)) {
                                 $item = implode("|", $item);
                             }
                             if (!rgblank($item)) {
                                 add_post_meta($post_id, $meta_name, $item);
                             }
                         }
                     }
                     break;
                 case "multiselect":
                 case "checkbox":
                     $value = explode(",", $value);
                     if (is_array($value)) {
                         foreach ($value as $item) {
                             if (!rgblank($item)) {
                                 add_post_meta($post_id, $meta_name, $item);
                             }
                         }
                     }
                     break;
                 case "date":
                     $value = GFCommon::date_display($value, rgar($custom_field, "dateFormat"));
                     if (!rgblank($value)) {
                         add_post_meta($post_id, $meta_name, $value);
                     }
                     break;
                 default:
                     if (!rgblank($value)) {
                         add_post_meta($post_id, $meta_name, $value);
                     }
                     break;
             }
             $meta_index++;
         }
     }
     $has_content_field = sizeof(GFCommon::get_fields_by_type($form, array("post_content"))) > 0;
     $has_title_field = sizeof(GFCommon::get_fields_by_type($form, array("post_title"))) > 0;
     //if a post field was configured with a content or title template, process template
     if (rgar($form, "postContentTemplateEnabled") && $has_content_field || rgar($form, "postTitleTemplateEnabled") && $has_title_field) {
         $post = get_post($post_id);
         if ($form["postContentTemplateEnabled"] && $has_content_field) {
             //replacing post image variables
             $post_content = GFCommon::replace_variables_post_image($form["postContentTemplate"], $post_images, $lead);
             //replacing all other variables
             $post_content = GFCommon::replace_variables($post_content, $form, $lead, false, false, false);
             //updating post content
             $post->post_content = $post_content;
         }
         if ($form["postTitleTemplateEnabled"] && $has_title_field) {
             //replacing post image variables
             $post_title = GFCommon::replace_variables_post_image($form["postTitleTemplate"], $post_images, $lead);
             //replacing all other variables
             $post_title = GFCommon::replace_variables($post_title, $form, $lead, false, false, false);
             // replace conditional shortcodes
             $post_title = do_shortcode($post_title);
             //updating post
             $post->post_title = $post_title;
             $post->post_name = $post_title;
         }
         if (GFCommon::is_bp_active()) {
             //re-enable buddy press action for save_post since the post data is complete at this point
             add_action('save_post', 'bp_blogs_record_post', 10, 2);
         }
         wp_update_post($post);
     }
     //adding post format
     if (current_theme_supports('post-formats') && rgar($form, 'postFormat')) {
         $formats = get_theme_support('post-formats');
         $post_format = rgar($form, 'postFormat');
         if (is_array($formats)) {
             $formats = $formats[0];
             if (in_array($post_format, $formats)) {
                 set_post_format($post_id, $post_format);
             } else {
                 if ('0' == $post_format) {
                     set_post_format($post_id, false);
                 }
             }
         }
     }
     //update post_id field if a post was created
     $lead["post_id"] = $post_id;
     self::update_lead($lead);
     return $post_id;
 }
 private static function remove_blank_custom_fields($merge_vars)
 {
     $i = 0;
     $count = count($merge_vars);
     for ($i = 0; $i < $count; $i++) {
         if (rgblank($merge_vars[$i]['value'])) {
             unset($merge_vars[$i]);
         }
     }
     //resort the array because items could have been removed, this will give an error from CRM if the keys are not in numeric sequence
     sort($merge_vars);
     return $merge_vars;
 }
Example #29
0
 public static function all_leads_page()
 {
     if (self::maybe_display_installation_wizard()) {
         return;
     }
     $view = rgget('view');
     $lead_id = rgget('lid');
     if ($view == 'entry' && (rgget('lid') || !rgblank(rgget('pos')))) {
         require_once GFCommon::get_base_path() . '/entry_detail.php';
         GFEntryDetail::lead_detail_page();
     } else {
         if ($view == 'entries' || empty($view)) {
             require_once GFCommon::get_base_path() . '/entry_list.php';
             GFEntryList::all_leads_page();
         } else {
             $form_id = rgget('id');
             /**
              * Fires when viewing entries of a certain form
              *
              */
             do_action('gform_entries_view', $view, $form_id, $lead_id);
         }
     }
 }
 /**
  * Returns the field ID of the first field of the desired type.
  * 
  * @access public
  * @param string $field_type
  * @param int $subfield_id (default: null)
  * @param int $form_id (default: null)
  * @return string
  */
 public function get_first_field_by_type($field_type, $subfield_id = null, $form_id = null, $return_first_only = true)
 {
     /* Get the current form ID. */
     if (rgblank($form_id)) {
         $form_id = rgget('id');
     }
     /* Get the form. */
     $form = GFAPI::get_form($form_id);
     /* Get the request field type for the form. */
     $fields = GFAPI::get_fields_by_type($form, array($field_type));
     if (count($fields) == 0 || count($fields) > 1 && $return_first_only) {
         return null;
     } else {
         if (rgblank($subfield_id)) {
             return $fields[0]->id;
         } else {
             return $fields[0]->id . '.' . $subfield_id;
         }
     }
 }