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;
}
 public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead)
 {
     // ignore submitted value and recalculate price in backend
     list($prefix, $field_id, $input_id) = rgexplode('_', $input_name, 3);
     if ($input_id == 2) {
         require_once GFCommon::get_base_path() . '/currency.php';
         $currency = new RGCurrency(GFCommon::get_currency());
         $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
         $value = $currency->to_money(GFCommon::calculate($this, $form, $lead));
     }
     return $value;
 }
示例#3
0
 /**
  * Prepare the value before saving it to the lead.
  *
  * @param mixed $form
  * @param mixed $field
  * @param mixed $value
  * @param mixed $input_name
  * @param mixed $lead_id the current lead ID, used for fields that are processed after other fields have been saved (ie Total, Calculations)
  * @param mixed $lead passed by the RGFormsModel::create_lead() method, lead ID is not available for leads created by this function
  */
 public static function prepare_value($form, $field, $value, $input_name, $lead_id, $lead = array())
 {
     $form_id = $form["id"];
     $input_type = self::get_input_type($field);
     switch ($input_type) {
         case "total":
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::get_order_total($form, $lead);
             break;
         case "calculation":
             // ignore submitted value and recalculate price in backend
             list(, , $input_id) = rgexplode("_", $input_name, 3);
             if ($input_id == 2) {
                 require_once GFCommon::get_base_path() . '/currency.php';
                 $currency = new RGCurrency(GFCommon::get_currency());
                 $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
                 $value = $currency->to_money(GFCommon::calculate($field, $form, $lead));
             }
             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":
             $value = self::prepare_date($field["dateFormat"], $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":
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::has_field_calculation($field) ? GFCommon::round_number(GFCommon::calculate($field, $form, $lead), rgar($field, "calculationRounding")) : GFCommon::clean_number($value, rgar($field, "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 (GFCommon::has_field_calculation($field) && $value == 0) {
                 $value = "0";
             }
             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;
     }
     // special format for Post Category fields
     if ($field['type'] == 'post_category') {
         $full_values = array();
         if (!is_array($value)) {
             $value = explode(',', $value);
         }
         foreach ($value as $cat_id) {
             $cat = get_term($cat_id, 'category');
             $full_values[] = !is_wp_error($cat) && is_object($cat) ? $cat->name . ":" . $cat_id : "";
         }
         $value = implode(',', $full_values);
     }
     //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;
 }
示例#4
0
 public static function to_money($number, $currency_code = "")
 {
     if (!class_exists("RGCurrency")) {
         require_once "currency.php";
     }
     if (empty($currency_code)) {
         $currency_code = self::get_currency();
     }
     $currency = new RGCurrency($currency_code);
     return $currency->to_money($number);
 }
示例#5
0
 /**
  * Prepare the value before saving it to the lead.
  *
  * @param mixed $form
  * @param mixed $field
  * @param mixed $value
  * @param mixed $input_name
  * @param mixed $lead_id the current lead ID, used for fields that are processed after other fields have been saved (ie Total, Calculations)
  * @param mixed $lead passed by the RGFormsModel::create_lead() method, lead ID is not available for leads created by this function
  */
 public static function prepare_value($form, $field, $value, $input_name, $lead_id, $lead = array())
 {
     $form_id = $form["id"];
     $input_type = self::get_input_type($field);
     switch ($input_type) {
         case "total":
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::get_order_total($form, $lead);
             break;
         case "calculation":
             // ignore submitted value and recalculate price in backend
             list(, , $input_id) = rgexplode("_", $input_name, 3);
             if ($input_id == 2) {
                 require_once GFCommon::get_base_path() . '/currency.php';
                 $currency = new RGCurrency(GFCommon::get_currency());
                 $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
                 $value = $currency->to_money(GFCommon::calculate($field, $form, $lead));
             }
             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":
             $value = self::prepare_date(rgar($field, 'dateFormat'), $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":
             if (rgar($field, "multipleFiles")) {
                 global $_gf_uploaded_files;
                 if (isset($_gf_uploaded_files[$input_name])) {
                     $value = $_gf_uploaded_files[$input_name];
                 } else {
                     if (isset(GFFormsModel::$uploaded_files[$form_id][$input_name])) {
                         $uploaded_temp_files = GFFormsModel::$uploaded_files[$form_id][$input_name];
                         $uploaded_files = array();
                         foreach ($uploaded_temp_files as $i => $file_info) {
                             $temp_filepath = self::get_upload_path($form_id) . '/tmp/' . $file_info['temp_filename'];
                             if ($file_info && file_exists($temp_filepath)) {
                                 $uploaded_files[$i] = self::move_temp_file($form_id, $file_info);
                             }
                         }
                         if (!empty($value)) {
                             // merge with existing files (admin edit entry)
                             $value = json_decode($value, true);
                             $value = array_merge($value, $uploaded_files);
                             $value = json_encode($value);
                         } else {
                             $value = json_encode($uploaded_files);
                         }
                     } else {
                         $value = '';
                     }
                     $_gf_uploaded_files[$input_name] = $value;
                 }
             } else {
                 $value = self::get_fileupload_value($form_id, $input_name);
             }
             break;
         case "number":
             $value = GFCommon::maybe_add_leading_zero($value);
             $is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
             $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
             $value = GFCommon::has_field_calculation($field) ? GFCommon::round_number(GFCommon::calculate($field, $form, $lead), rgar($field, "calculationRounding")) : GFCommon::clean_number($value, rgar($field, "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 (GFCommon::has_field_calculation($field) && $value == 0) {
                 $value = "0";
             }
             break;
         case "website":
             if ($value == "http://") {
                 $value = "";
             }
             break;
         case "list":
             if (rgar($field, "adminOnly") && rgar($field, "allowsPrepopulate")) {
                 $value = json_decode($value);
             }
             if (GFCommon::is_empty_array($value)) {
                 $value = "";
             } else {
                 foreach ($value as &$val) {
                     $val = self::sanitize_entry_value($field, $val, $input_type, $form_id);
                 }
                 $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");
             }
             $value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
             break;
         case "multiselect":
             $value = empty($value) ? "" : is_array($value) ? implode(",", $value) : $value;
             $value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
             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') {
                     $value = rgpost("input_{$field_id_token}_4");
                     if (!$value) {
                         $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;
         case 'password':
             $encrypt_password = apply_filters('gform_encrypt_password', false, $field, $form);
             if ($encrypt_password) {
                 $value = GFCommon::encrypt($value);
                 self::set_encrypted_fields($lead_id, $field['id']);
             }
             break;
         default:
             // only filter HTML on non-array based values
             if (!is_array($value)) {
                 $value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
             }
             break;
     }
     // special format for Post Category fields
     if ($field['type'] == 'post_category') {
         $full_values = array();
         if (!is_array($value)) {
             $value = explode(',', $value);
         }
         foreach ($value as $cat_id) {
             $cat = get_term($cat_id, 'category');
             $full_values[] = !is_wp_error($cat) && is_object($cat) ? $cat->name . ":" . $cat_id : "";
         }
         $value = implode(',', $full_values);
     }
     //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;
 }