public static function is_duplicate($form_id, $field, $value)
 {
     global $wpdb;
     $lead_detail_table_name = self::get_lead_details_table_name();
     $lead_table_name = self::get_lead_table_name();
     $lead_detail_long = self::get_lead_details_long_table_name();
     $is_long = !is_array($value) && strlen($value) > GFORMS_MAX_FIELD_LENGTH - 10;
     $sql_comparison = $is_long ? '( ld.value = %s OR ldl.value = %s )' : 'ld.value = %s';
     switch (GFFormsModel::get_input_type($field)) {
         case 'time':
             $value = sprintf("%02d:%02d %s", $value[0], $value[1], $value[2]);
             break;
         case 'date':
             $value = self::prepare_date($field->dateFormat, $value);
             break;
         case 'number':
             $value = GFCommon::clean_number($value, $field->numberFormat);
             break;
         case 'phone':
             $value = str_replace(array(')', '(', '-', ' '), '', $value);
             $sql_comparison = 'replace( replace( replace( replace( ld.value, ")", "" ), "(", "" ), "-", "" ), " ", "" ) = %s';
             break;
         case 'email':
             $value = is_array($value) ? rgar($value, 0) : $value;
             break;
     }
     $inner_sql_template = "SELECT %s as input, ld.lead_id\n                                FROM {$lead_detail_table_name} ld\n                                INNER JOIN {$lead_table_name} l ON l.id = ld.lead_id\n";
     if ($is_long) {
         $inner_sql_template .= "INNER JOIN {$lead_detail_long} ldl ON ldl.lead_detail_id = ld.id\n";
     }
     $inner_sql_template .= "WHERE l.form_id=%d AND ld.form_id=%d\n                                AND ld.field_number between %s AND %s\n                                AND status='active' AND {$sql_comparison}";
     $sql = "SELECT count(distinct input) as match_count FROM ( ";
     $input_count = 1;
     if (is_array($field->get_entry_inputs())) {
         $input_count = sizeof($field->inputs);
         foreach ($field->inputs as $input) {
             $union = empty($inner_sql) ? '' : ' UNION ALL ';
             $inner_sql .= $union . $wpdb->prepare($inner_sql_template, $input['id'], $form_id, $form_id, $input['id'] - 0.0001, $input['id'] + 0.0001, $value[$input['id']], $value[$input['id']]);
         }
     } else {
         $inner_sql = $wpdb->prepare($inner_sql_template, $field->id, $form_id, $form_id, doubleval($field->id) - 0.0001, doubleval($field->id) + 0.0001, $value, $value);
     }
     $sql .= $inner_sql . "\n                ) as count\n                GROUP BY lead_id\n                ORDER BY match_count DESC";
     $count = gf_apply_filters('gform_is_duplicate', $form_id, $wpdb->get_var($sql), $form_id, $field, $value);
     return $count != null && $count >= $input_count;
 }
 public static function is_duplicate($form_id, $field, $value)
 {
     global $wpdb;
     $lead_detail_table_name = self::get_lead_details_table_name();
     $lead_table_name = self::get_lead_table_name();
     switch (RGFormsModel::get_input_type($field)) {
         case "time":
             $value = sprintf("%d:%02d %s", $value[0], $value[1], $value[2]);
             break;
         case "date":
             $value = self::prepare_date(rgar($field, "dateFormat"), $value);
             break;
         case "number":
             $value = GFCommon::clean_number($value, rgar($field, 'numberFormat'));
             break;
     }
     $inner_sql_template = " SELECT %s as input, ld.lead_id\n                                FROM {$lead_detail_table_name} ld\n                                INNER JOIN {$lead_table_name} l ON l.id = ld.lead_id\n                                WHERE l.form_id=%d AND ld.form_id=%d\n                                AND ld.field_number between %s AND %s\n                                AND ld.value=%s";
     $sql = "SELECT count(distinct input) as match_count FROM ( ";
     $input_count = 1;
     if (is_array($field["inputs"])) {
         $input_count = sizeof($field["inputs"]);
         foreach ($field["inputs"] as $input) {
             $union = empty($inner_sql) ? "" : " UNION ALL ";
             $inner_sql .= $union . $wpdb->prepare($inner_sql_template, $input["id"], $form_id, $form_id, $input["id"] - 0.001, $input["id"] + 0.001, $value[$input["id"]]);
         }
     } else {
         $inner_sql = $wpdb->prepare($inner_sql_template, $field["id"], $form_id, $form_id, doubleval($field["id"]) - 0.001, doubleval($field["id"]) + 0.001, $value);
     }
     $sql .= $inner_sql . "\n                ) as count\n                GROUP BY lead_id\n                ORDER BY match_count DESC";
     $count = apply_filters("gform_is_duplicate_{$form_id}", apply_filters('gform_is_duplicate', $wpdb->get_var($sql), $form_id, $field, $value), $form_id, $field, $value);
     return $count != null && $count >= $input_count;
 }
 private static function validate_range($field, $value)
 {
     if (!GFCommon::is_numeric($value, rgar($field, "numberFormat"))) {
         return false;
     }
     $number = GFCommon::clean_number($value, rgar($field, "numberFormat"));
     if (is_numeric($field["rangeMin"]) && $number < $field["rangeMin"] || is_numeric($field["rangeMax"]) && $number > $field["rangeMax"]) {
         return false;
     } else {
         return true;
     }
 }
 public function sanitize_settings()
 {
     parent::sanitize_settings();
     $this->enableCalculation = (bool) $this->enableCalculation;
     if ($this->numberFormat == 'currency') {
         require_once GFCommon::get_base_path() . '/currency.php';
         $currency = new RGCurrency(GFCommon::get_currency());
         $this->rangeMin = $currency->to_number($this->rangeMin);
         $this->rangeMax = $currency->to_number($this->rangeMax);
     } elseif ($this->numberFormat == 'decimal_comma') {
         $this->rangeMin = GFCommon::clean_number($this->rangeMin, 'decimal_comma');
         $this->rangeMax = GFCommon::clean_number($this->rangeMax, 'decimal_comma');
     } elseif ($this->numberFormat == 'decimal_dot') {
         $this->rangeMin = GFCommon::clean_number($this->rangeMin, 'decimal_dot');
         $this->rangeMin = GFCommon::clean_number($this->rangeMin, 'decimal_dot');
     }
 }
 public function clean_number($value)
 {
     if ($this->numberFormat == 'currency') {
         return GFCommon::to_number($value);
     } else {
         return GFCommon::clean_number($value, $this->numberFormat);
     }
 }
 public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead)
 {
     $value = GFCommon::maybe_add_leading_zero($value);
     $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
     $value = $this->has_calculation() ? GFCommon::round_number(GFCommon::calculate($this, $form, $lead), $this->calculationRounding) : GFCommon::clean_number($value, $this->numberFormat);
     //return the value as a string when it is zero and a calc so that the "==" comparison done when checking if the field has changed isn't treated as false
     if ($this->has_calculation() && $value == 0) {
         $value = '0';
     }
     return $value;
 }
Beispiel #7
0
 private static function get_product_array($form, $lead, $has_product_fields, $form_array)
 {
     $currency_type = method_exists('GFCommon', 'is_currency_decimal_dot') ? GFCommon::is_currency_decimal_dot() : PDF_Common::is_currency_decimal_dot();
     $currency_format = $currency_type ? 'decimal_dot' : 'decimal_comma';
     if ($has_product_fields) {
         $products = GFCommon::get_product_fields($form, $lead, true);
         /* check that there are actual product fields */
         if (sizeof($products['products']) > 0) {
             /*
              * Set up our variables
              */
             $total = 0;
             $subtotal = 0;
             foreach ($products['products'] as $id => $product) {
                 $price = GFCommon::to_number($product['price']);
                 /* add all options to total price */
                 if (is_array(rgar($product, 'options'))) {
                     foreach ($product['options'] as $option) {
                         $price += GFCommon::to_number($option['price']);
                     }
                 }
                 /* calculate subtotal */
                 $subtotal = floatval($product['quantity']) * $price;
                 $total += $subtotal;
                 /*
                  * Check if we should include options
                  */
                 $options = isset($product['options']) ? $product['options'] : array();
                 /*
                  * Add formated price for each product option 
                  */
                 foreach ($options as &$o) {
                     if (is_numeric($o['price'])) {
                         $o['price_formatted'] = GFCommon::format_number($o['price'], 'currency');
                     }
                 }
                 /*
                  * Store product in $form_array array
                  */
                 $form_array['products'][$id] = array('name' => esc_html($product['name']), 'price' => esc_html($product['price']), 'price_unformatted' => GFCommon::clean_number($product['price'], $currency_format), 'options' => $options, 'quantity' => $product['quantity'], 'subtotal' => $subtotal, 'subtotal_formatted' => GFCommon::format_number($subtotal, 'currency'));
             }
             /* Increment total */
             $total += floatval($products['shipping']['price']);
             $subtotal = $total - floatval($products['shipping']['price']);
             /* add totals to form data */
             $form_array['products_totals'] = array('subtotal' => $subtotal, 'shipping' => $products['shipping']['price'], 'total' => $total, 'shipping_formatted' => GFCommon::format_number($products['shipping']['price'], 'currency'), 'subtotal_formatted' => GFCommon::format_number($subtotal, 'currency'), 'total_formatted' => GFCommon::format_number($total, 'currency'));
         }
     }
     return $form_array;
 }
Beispiel #8
0
 private static function prepare_value($form_id, $field, $value, $input_name)
 {
     $input_type = self::get_input_type($field);
     switch ($input_type) {
         case "post_category":
             $cat = get_category($value);
             $value = $cat->name;
             break;
         case "phone":
             if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) {
                 $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]);
             }
             break;
         case "time":
             if (!is_array($value) && !empty($value)) {
                 preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
                 $value = array();
                 $value[0] = $matches[1];
                 $value[1] = $matches[2];
                 $value[2] = $matches[3];
             }
             $hour = empty($value[0]) ? "0" : strip_tags($value[0]);
             $minute = empty($value[1]) ? "0" : strip_tags($value[1]);
             $ampm = strip_tags($value[2]);
             if (!(empty($hour) && empty($minute))) {
                 $value = sprintf("%02d:%02d %s", $hour, $minute, $ampm);
             } else {
                 $value = "";
             }
             break;
         case "date":
             $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"];
             $date_info = GFCommon::parse_date($value, $format);
             if (!empty($date_info)) {
                 $value = sprintf("%d-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]);
             } else {
                 $value = "";
             }
             break;
         case "post_image":
             $url = self::get_fileupload_value($form_id, $input_name);
             $image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : "";
             $image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : "";
             $image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : "";
             $value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : "";
             break;
         case "fileupload":
             $value = self::get_fileupload_value($form_id, $input_name);
             break;
         case "number":
             $value = GFCommon::clean_number($value);
             break;
         default:
             $value = stripslashes($value);
             //allow HTML for certain field types
             if (!in_array($field["type"], array("post_custom_field", "post_title", "post_content", "post_excerpt", "post_tags")) && !in_array($input_type, array("checkbox", "radio"))) {
                 $value = strip_tags($value);
             }
             //do not save price fields with blank price
             if ($field["enablePrice"]) {
                 list($label, $price) = explode("|", $value);
                 $is_empty = strlen(trim($price)) <= 0;
                 if ($is_empty) {
                     $value = "";
                 }
             }
             break;
     }
     return $value;
 }
 private static function prepare_value($form, $field, $value, $input_name, $lead_id)
 {
     $form_id = $form["id"];
     $input_type = self::get_input_type($field);
     switch ($input_type) {
         case "total":
             $lead = RGFormsModel::get_lead($lead_id);
             $value = GFCommon::get_order_total($form, $lead);
             break;
         case "post_category":
             $cat = get_category($value);
             $value = !empty($cat) ? $cat->name . ":" . $value : "";
             break;
         case "phone":
             if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) {
                 $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]);
             }
             break;
         case "time":
             if (!is_array($value) && !empty($value)) {
                 preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
                 $value = array();
                 $value[0] = $matches[1];
                 $value[1] = $matches[2];
                 $value[2] = rgar($matches, 3);
             }
             $hour = empty($value[0]) ? "0" : strip_tags($value[0]);
             $minute = empty($value[1]) ? "0" : strip_tags($value[1]);
             $ampm = strip_tags(rgar($value, 2));
             if (!empty($ampm)) {
                 $ampm = " {$ampm}";
             }
             if (!(empty($hour) && empty($minute))) {
                 $value = sprintf("%02d:%02d%s", $hour, $minute, $ampm);
             } else {
                 $value = "";
             }
             break;
         case "date":
             $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"];
             $date_info = GFCommon::parse_date($value, $format);
             if (!empty($date_info)) {
                 $value = sprintf("%d-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]);
             } else {
                 $value = "";
             }
             break;
         case "post_image":
             $url = self::get_fileupload_value($form_id, $input_name);
             $image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : "";
             $image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : "";
             $image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : "";
             $value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : "";
             break;
         case "fileupload":
             $value = self::get_fileupload_value($form_id, $input_name);
             break;
         case "number":
             $value = GFCommon::clean_number($value, rgar($field, "numberFormat"));
             break;
         case "website":
             if ($value == "http://") {
                 $value = "";
             }
             break;
         case "list":
             if (GFCommon::is_empty_array($value)) {
                 $value = "";
             } else {
                 $value = self::create_list_array($field, $value);
                 $value = serialize($value);
             }
             break;
         case "radio":
             if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
                 $value = rgpost("input_{$field['id']}_other");
             }
             break;
         case "multiselect":
             $value = empty($value) ? "" : implode(",", $value);
             break;
         case "creditcard":
             //saving last 4 digits of credit card
             list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);
             if ($input_id == "1") {
                 $value = str_replace(" ", "", $value);
                 $card_number_length = strlen($value);
                 $value = substr($value, -4, 4);
                 $value = str_pad($value, $card_number_length, "X", STR_PAD_LEFT);
             } else {
                 if ($input_id == "4") {
                     $card_number = rgpost("input_{$field_id_token}_1");
                     $card_type = GFCommon::get_card_type($card_number);
                     $value = $card_type ? $card_type["name"] : "";
                 } else {
                     $value = "";
                 }
             }
             break;
         default:
             //allow HTML for certain field types
             $allow_html = in_array($field["type"], array("post_custom_field", "post_title", "post_content", "post_excerpt", "post_tags")) || in_array($input_type, array("checkbox", "radio")) ? true : false;
             $allowable_tags = apply_filters("gform_allowable_tags_{$form_id}", apply_filters("gform_allowable_tags", $allow_html, $field, $form_id), $field, $form_id);
             if ($allowable_tags !== true) {
                 $value = strip_tags($value, $allowable_tags);
             }
             break;
     }
     //do not save price fields with blank price
     if (rgar($field, "enablePrice")) {
         $ary = explode("|", $value);
         $label = count($ary) > 0 ? $ary[0] : "";
         $price = count($ary) > 1 ? $ary[1] : "";
         $is_empty = strlen(trim($price)) <= 0;
         if ($is_empty) {
             $value = "";
         }
     }
     return $value;
 }
Beispiel #10
0
 private static function prepare_value($form_id, $field, $value, $input_name)
 {
     switch (self::get_input_type($field)) {
         case "post_category":
             $cat = get_category($value);
             $value = $cat->name;
             break;
         case "post_title":
         case "post_content":
         case "post_excerpt":
         case "post_tags":
         case "post_custom_fields":
         case "post_image":
             $value = stripslashes($value);
             break;
         case "phone":
             if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) {
                 $value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]);
             }
             break;
         case "time":
             if (!is_array($value) && !empty($value)) {
                 preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
                 $value = array();
                 $value[0] = $matches[1];
                 $value[1] = $matches[2];
                 $value[2] = $matches[3];
             }
             $hour = empty($value[0]) ? "0" : strip_tags($value[0]);
             $minute = empty($value[1]) ? "0" : strip_tags($value[1]);
             $ampm = strip_tags($value[2]);
             if (!(empty($hour) && empty($minute))) {
                 $value = sprintf("%02d:%02d %s", $hour, $minute, $ampm);
             } else {
                 $value = "";
             }
             break;
         case "date":
             $format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"];
             $date_info = GFCommon::parse_date($value, $format);
             if (!empty($date_info)) {
                 $value = sprintf("%d-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]);
             } else {
                 $value = "";
             }
             break;
         case "fileupload":
             $value = self::upload_file($form_id, $_FILES[$input_name]);
             break;
         case "number":
             $value = GFCommon::clean_number($value);
             break;
         default:
             $value = strip_tags(stripslashes($value));
             break;
     }
     return $value;
 }