public static function get_credit_card_init_script($form) { $script = ""; foreach ($form["fields"] as $field) { if ($field['type'] != 'creditcard') { continue; } $field_id = "input_{$form["id"]}_{$field["id"]}"; $field_script = "jQuery(document).ready(function(){ { gformMatchCard(\"{$field_id}_1\"); } } );"; if (rgar($field, "forceSSL") && !GFCommon::is_ssl() && !GFCommon::is_preview()) { $field_script = "document.location.href='" . esc_js(RGFormsModel::get_current_page_url(true)) . "';"; } $script .= $field_script; } $card_rules = self::get_credit_card_rules(); $script = "if(!window['gf_cc_rules']){window['gf_cc_rules'] = new Array(); } window['gf_cc_rules'] = " . GFCommon::json_encode($card_rules) . "; {$script}"; return $script; }
public static function is_preview() { $url_info = parse_url(RGFormsModel::get_current_page_url()); $file_name = basename($url_info["path"]); return $file_name == "preview.php" || rgget("gf_page", $_GET) == "preview"; }
public function get_form_inline_script_on_page_render($form) { $field_id = "input_{$form['id']}_{$this->id}"; if ($this->forceSSL && !GFCommon::is_ssl() && !GFCommon::is_preview()) { $script = "document.location.href='" . esc_js(RGFormsModel::get_current_page_url(true)) . "';"; } else { $script = "jQuery(document).ready(function(){ { gformMatchCard(\"{$field_id}_1\"); } } );"; } $card_rules = $this->get_credit_card_rules(); $script = "if(!window['gf_cc_rules']){window['gf_cc_rules'] = new Array(); } window['gf_cc_rules'] = " . GFCommon::json_encode($card_rules) . "; {$script}"; return $script; }
public static function replace_variables_prepopulate($text, $url_encode = false) { //embed url $text = str_replace("{embed_url}", $url_encode ? urlencode(RGFormsModel::get_current_page_url()) : RGFormsModel::get_current_page_url(), $text); $local_timestamp = self::get_local_timestamp(time()); //date (mm/dd/yyyy) $local_date_mdy = date_i18n("m/d/Y", $local_timestamp, true); $text = str_replace("{date_mdy}", $url_encode ? urlencode($local_date_mdy) : $local_date_mdy, $text); //date (dd/mm/yyyy) $local_date_dmy = date_i18n("d/m/Y", $local_timestamp, true); $text = str_replace("{date_dmy}", $url_encode ? urlencode($local_date_dmy) : $local_date_dmy, $text); //ip $text = str_replace("{ip}", $url_encode ? urlencode($_SERVER['REMOTE_ADDR']) : $_SERVER['REMOTE_ADDR'], $text); global $post; $post_array = self::object_to_array($post); preg_match_all("/\\{embed_post:(.*?)\\}/", $text, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $full_tag = $match[0]; $property = $match[1]; $text = str_replace($full_tag, $url_encode ? urlencode($post_array[$property]) : $post_array[$property], $text); } //embed post custom fields preg_match_all("/\\{custom_field:(.*?)\\}/", $text, $matches, PREG_SET_ORDER); foreach ($matches as $match) { //embed post info $post_array = self::get_embed_post(); $full_tag = $match[0]; $custom_field_name = $match[1]; $custom_field_value = !empty($post_array["ID"]) ? get_post_meta($post_array["ID"], $custom_field_name, true) : ""; $text = str_replace($full_tag, $url_encode ? urlencode($custom_field_value) : $custom_field_value, $text); } //user agent $text = str_replace("{user_agent}", $url_encode ? urlencode(RGForms::get("HTTP_USER_AGENT", $_SERVER)) : RGForms::get("HTTP_USER_AGENT", $_SERVER), $text); //referrer $text = str_replace("{referer}", $url_encode ? urlencode(RGForms::get("HTTP_REFERER", $_SERVER)) : RGForms::get("HTTP_REFERER", $_SERVER), $text); //logged in user info global $userdata; $user_array = self::object_to_array($userdata); preg_match_all("/\\{user:(.*?)\\}/", $text, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $full_tag = $match[0]; $property = $match[1]; $text = str_replace($full_tag, $url_encode ? urlencode($user_array[$property]) : $user_array[$property], $text); } return $text; }
/** * * @global type $wpdb */ function entries_import() { $wform = $_REQUEST['form']; $gform = $_REQUEST['gform']; $entry_index = $_REQUEST['entry_index']; $this->init(); $field_map = maybe_unserialize(get_site_option('rt_wufoo_' . $wform . '_field_map')); $f = new RGFormsModel(); $c = new GFCommon(); $gform_meta = RGFormsModel::get_form_meta($gform); try { $entries = $this->wufoo->getEntries($wform, 'forms', 'pageStart=' . $entry_index . '&pageSize=' . RT_WUFOO_IMPORT_PAGE_SIZE); } catch (Exception $rt_importer_e) { $this->error($rt_importer_e); } $this->op = array(); foreach ($entries as $index => $entry) { $lead_exists_id = $this->is_imported($entry->EntryId); print_r($lead_exists_id); if (!$lead_exists_id) { foreach ($field_map as $g_id => $w_id) { if (isset($w_id) && $w_id != '') { $this->op[$g_id] = ''; $field_meta = RGFormsModel::get_field($gform_meta, $g_id); if ($field_meta['type'] == 'fileupload') { $this->op[$g_id] = $this->import_file_upload($entry, $w_id); } else { $this->import_regular_field($wform, $entry, $g_id, $w_id, $field_meta); } } } $currency = $c->get_currency(); $ip = $f->get_ip(); $page = $f->get_current_page_url(); $lead_table = $f->get_lead_table_name(); $lead_id = $this->insert_lead($entry, $lead_table, $ip, $currency, $page, $wform, $gform); } if ($lead_id) { foreach ($this->op as $inputid => $value) { $this->insert_fields($lead_id, $gform, $inputid, $value); } //Insert comments as notes for the corresponding user map $comments = $this->get_comments_by_entry($wform, $entry->EntryId); if (isset($comments) && !empty($comments)) { foreach ($comments as $comment) { $this->move_comments_for_entry($comment, $f->get_lead_notes_table_name(), $lead_id, $wform); } } } else { $lead_id = $lead_exists_id; } gform_update_meta($lead_id, 'rt_wufoo_entry_id', $entry->EntryId); } //update_site_option('rt_wufoo_' . $wform . '_entry_complete_count','0'); echo count($entries) + $entry_index; die; }
public static function is_preview() { $url_info = parse_url(RGFormsModel::get_current_page_url()); $file_name = basename($url_info['path']); return $file_name == 'preview.php' || rgget('gf_page', $_GET) == 'preview'; }
/** * Duplicates the contents of a specified entry id into the specified form * Adapted from forms_model.php, RGFormsModel::save_lead($Form, $lead) and * gravity -forms-addons.php for the gravity forms addon plugin * @param array $form Form object. * @param array $lead Lead object * @return void */ function duplicate_entry_data($form_change, $current_entry_id) { global $wpdb; $lead_table = GFFormsModel::get_lead_table_name(); $lead_detail_table = GFFormsModel::get_lead_details_table_name(); $lead_meta_table = GFFormsModel::get_lead_meta_table_name(); //pull existing entries information $current_lead = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$lead_table} WHERE id=%d", $current_entry_id)); $current_fields = $wpdb->get_results($wpdb->prepare("SELECT wp_rg_lead_detail.field_number, wp_rg_lead_detail.value, wp_rg_lead_detail_long.value as long_detail FROM {$lead_detail_table} left outer join wp_rg_lead_detail_long on wp_rg_lead_detail_long.lead_detail_id = wp_rg_lead_detail.id WHERE lead_id=%d", $current_entry_id)); // new lead $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL'; $user_agent = GFCommon::truncate_url($_SERVER["HTTP_USER_AGENT"], 250); $currency = GFCommon::get_currency(); $source_url = GFCommon::truncate_url(RGFormsModel::get_current_page_url(), 200); $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form_change, RGFormsModel::get_ip(), $source_url, $user_agent, $currency)); $lead_id = $wpdb->insert_id; echo 'Entry ' . $lead_id . ' created in Form ' . $form_change; //add a note to the new entry $results = mf_add_note($lead_id, 'Copied Entry ID:' . $current_entry_id . ' into form ' . $form_change . '. New Entry ID =' . $lead_id); foreach ($current_fields as $row) { $fieldValue = $row->field_number != 303 ? $row->value : 'Proposed'; $wpdb->query($wpdb->prepare("INSERT INTO {$lead_detail_table}(lead_id, form_id, field_number, value) VALUES(%d, %s, %s, %s)", $lead_id, $form_change, $row->field_number, $fieldValue)); //if detail long is set, add row for new record if ($row->long_detail != 'NULL') { $lead_detail_id = $wpdb->insert_id; $wpdb->query($wpdb->prepare("INSERT INTO wp_rg_lead_detail_long(lead_detail_id, value) VALUES(%d, %s)", $lead_detail_id, $row->long_detail)); } } }
public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false) { //reading form metadata $form = RGFormsModel::get_form_meta($form_id, true); $form = RGFormsModel::add_default_properties($form); //disable ajax if form has a reCAPTCHA field (not supported). if ($ajax && self::has_recaptcha_field($form)) { $ajax = false; } $is_postback = false; $is_valid = true; $confirmation_message = ""; $page_number = 1; //If form was submitted, read variables set during form submission procedure $submission_info = isset(self::$submission[$form_id]) ? self::$submission[$form_id] : false; if ($submission_info) { $is_postback = true; $is_valid = $submission_info["is_valid"] || rgget("is_confirmation", $submission_info); $form = $submission_info["form"]; $lead = $submission_info["lead"]; $confirmation_message = rgget("confirmation_message", $submission_info); if ($is_valid && !RGForms::get("is_confirmation", $submission_info)) { if ($submission_info["page_number"] == 0) { //post submission hook do_action("gform_post_submission", $lead, $form); do_action("gform_post_submission_{$form["id"]}", $lead, $form); } else { //change page hook do_action("gform_post_paging", $form, $submission_info["source_page_number"], $submission_info["page_number"]); do_action("gform_post_paging_{$form["id"]}", $form, $submission_info["source_page_number"], $submission_info["page_number"]); } } } else { if (!current_user_can("administrator")) { RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']); } } if ($form["enableHoneypot"]) { $form["fields"][] = self::get_honeypot_field($form); } //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end $form = apply_filters("gform_pre_render_{$form_id}", apply_filters("gform_pre_render", $form)); if ($form == null) { return "<p>" . __("Oops! We could not locate your form.", "gravityforms") . "</p>"; } $has_pages = self::has_pages($form); //calling tab index filter GFCommon::$tab_index = apply_filters("gform_tabindex_{$form_id}", apply_filters("gform_tabindex", 1, $form), $form); //Don't display inactive forms if (!$force_display && !$is_postback) { $form_info = RGFormsModel::get_form($form_id); if (!$form_info->is_active) { return ""; } //If form has a schedule, make sure it is within the configured start and end dates if ($form["scheduleForm"]) { $local_time_start = sprintf("%s %02d:%02d %s", $form["scheduleStart"], $form["scheduleStartHour"], $form["scheduleStartMinute"], $form["scheduleStartAmpm"]); $local_time_end = sprintf("%s %02d:%02d %s", $form["scheduleEnd"], $form["scheduleEndHour"], $form["scheduleEndMinute"], $form["scheduleEndAmpm"]); $timestamp_start = strtotime($local_time_start . ' +0000'); $timestamp_end = strtotime($local_time_end . ' +0000'); $now = current_time("timestamp"); if (!empty($form["scheduleStart"]) && $now < $timestamp_start || !empty($form["scheduleEnd"]) && $now > $timestamp_end) { return empty($form["scheduleMessage"]) ? "<p>" . __("Sorry. This form is no longer available.", "gravityforms") . "</p>" : "<p>" . do_shortcode($form["scheduleMessage"]) . "</p>"; } } //If form has a limit of entries, check current entry count if ($form["limitEntries"]) { $entry_count = RGFormsModel::get_lead_count($form_id, ""); if ($entry_count >= $form["limitEntriesCount"]) { return empty($form["limitEntriesMessage"]) ? "<p>" . __("Sorry. This form is no longer accepting new submissions.", "gravityforms") . "</p>" : "<p>" . do_shortcode($form["limitEntriesMessage"]) . "</p>"; } } } $form_string = ""; //When called via a template, this will enqueue the proper scripts //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event self::enqueue_form_scripts($form, $ajax); if (empty($confirmation_message)) { //Hidding entire form if conditional logic is on to prevent "hidden" fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied. $style = self::has_conditional_logic($form) ? "style='display:none'" : ""; $form_string .= "\n <div class='gform_wrapper' id='gform_wrapper_{$form_id}' " . $style . ">"; $action = RGFormsModel::get_current_page_url(); $default_anchor = $has_pages ? 1 : 0; if (apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor))) { $form_string .= "<a name='gf_{$form_id}' class='gform_anchor' ></a>"; $action .= "#gf_{$form_id}"; } $target = $ajax ? "target='gform_ajax_frame_{$form_id}'" : ""; $form_string .= apply_filters("gform_form_tag_{$form_id}", apply_filters("gform_form_tag", "<form method='post' enctype='multipart/form-data' {$target} id='gform_{$form_id}' class='" . $form["cssClass"] . "' action='{$action}'>", $form), $form); if ($display_title || $display_description) { $form_string .= "\n <div class='gform_heading'>"; if ($display_title) { $form_string .= "\n <h3 class='gform_title'>" . $form['title'] . "</h3>"; } if ($display_description) { $form_string .= "\n <span class='gform_description'>" . $form['description'] . "</span>"; } $form_string .= "\n </div>"; } if ($has_pages && !IS_ADMIN) { $page_count = self::get_max_page_number($form); $current_page = self::get_current_page($form_id); if ($form["pagination"]["type"] == "percentage") { $percent = floor($current_page / $page_count * 100) . "%"; $page_name = isset($form["pagination"]["pages"][$current_page - 1]) ? " - " . $form["pagination"]["pages"][$current_page - 1] : ""; $style = $form["pagination"]["style"]; $color = $style == "custom" ? " color:{$form["pagination"]["color"]};" : ""; $bgcolor = $style == "custom" ? " background-color:{$form["pagination"]["backgroundColor"]};" : ""; $form_string .= "\n <div id='gf_progressbar_wrapper_{$form_id}' class='gf_progressbar_wrapper'>\n <h3 class='gf_progressbar_title'>" . __("Step", "gravityforms") . " {$current_page} " . __("of", "gravityforms") . " {$page_count}{$page_name}</h3>\n <div class='gf_progressbar'>\n <div class='gf_progressbar_percentage percentbar_{$style}' style='width:{$percent};{$color}{$bgcolor}'><span>{$percent}</span></div>\n </div>\n </div>"; } else { if ($form["pagination"]["type"] == "steps") { $form_string .= "\n <div id='gf_page_steps_{$form_id}' class='gf_page_steps'>"; for ($i = 0, $count = sizeof($form["pagination"]["pages"]); $i < $count; $i++) { $step_number = $i + 1; $active_class = $step_number == $current_page ? " gf_step_active" : ""; $form_string .= "\n <div id='gf_step_{$form_id}_{$step_number}' class='gf_step{$active_class}'><span class='gf_step_number'>{$step_number}</span> {$form["pagination"]["pages"][$i]}</div>"; } $form_string .= "\n </div>"; } } } if ($is_postback && !$is_valid) { $validation_message = "<div class='validation_error'>" . __("There was a problem with your submission.", "gravityforms") . " " . __("Errors have been highlighted below.", "gravityforms") . "</div>"; $form_string .= apply_filters("gform_validation_message_{$form["id"]}", apply_filters("gform_validation_message", $validation_message, $form), $form); } $form_string .= "\n <div class='gform_body'>"; //add first page if this form has any page fields if ($has_pages) { $style = self::is_page_active($form_id, 1) ? "" : "style='display:none;'"; $class = !empty($form["firstPageCssClass"]) ? " {$form["firstPageCssClass"]}" : ""; $form_string .= "<div id='gform_page_{$form_id}_1' class='gform_page{$class}' {$style}>\n <div class='gform_page_fields'>"; } $form_string .= "\n <ul id='gform_fields_{$form_id}' class='gform_fields " . $form['labelPlacement'] . "'>"; if (is_array($form['fields'])) { foreach ($form['fields'] as $field) { $field["conditionalLogicFields"] = self::get_conditional_logic_fields($form, $field["id"]); $form_string .= self::get_field($field, RGFormsModel::get_field_value($field, $field_values), false, $form, $field_values); } } $form_string .= "\n </ul>"; if ($has_pages) { $previous_button = self::get_form_button($form["id"], "gform_previous_button_{$form["id"]}", $form["lastPageButton"], __("Previous", "gravityforms"), "button gform_previous_button", __("Previous Page", "gravityforms"), self::get_current_page($form_id) - 1); $form_string .= "</div>" . self::gform_footer($form, "gform_page_footer " . $form['labelPlacement'], $ajax, $field_values, $previous_button, $display_title, $display_description, $is_postback) . "\n </div>"; //closes gform_page } $form_string .= "</div>"; //closes gform_body //suppress form footer for multi-page forms (footer will be included on the last page if (!$has_pages) { $form_string .= self::gform_footer($form, "gform_footer " . $form['labelPlacement'], $ajax, $field_values, "", $display_title, $display_description, $is_postback); } $form_string .= "\n </form>\n </div>"; //adding conditional logic script if conditional logic is configured for this form if (self::has_conditional_logic($form)) { $form_string .= self::get_conditional_logic($form); } //adding currency config if there are any product fields in the form if (self::has_price_field($form)) { if (!class_exists("RGCurrency")) { require_once "currency.php"; } $form_string .= "<script type='text/javascript'>if(window[\"gformInitPriceFields\"]) jQuery(document).ready(function(){gformInitPriceFields();}); window['gf_currency_config'] = " . GFCommon::json_encode(RGCurrency::get_currency(GFCommon::get_currency())) . ";</script>"; } if (self::has_password_strength($form)) { $form_string .= "<script type='text/javascript'>if(!window['gf_text']){window['gf_text'] = new Array();} window['gf_text']['password_blank'] = '" . __("Strength indicator", "gravityforms") . "'; window['gf_text']['password_mismatch'] = '" . __("Mismatch", "gravityforms") . "';window['gf_text']['password_bad'] = '" . __("Bad", "gravityforms") . "'; window['gf_text']['password_short'] = '" . __("Short", "gravityforms") . "'; window['gf_text']['password_good'] = '" . __("Good", "gravityforms") . "'; window['gf_text']['password_strong'] = '" . __("Strong", "gravityforms") . "';</script>"; } if ($ajax && $is_postback) { $form_string = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body>" . $form_string . "</body></html>"; } if ($ajax && !$is_postback) { $spinner_url = apply_filters("gform_ajax_spinner_url_{$form_id}", apply_filters("gform_ajax_spinner_url", GFCommon::get_base_url() . "/images/spinner.gif", $form), $form); $form_string .= "\n <iframe style='display:none;width:0px; height:0px;' src='about:blank' name='gform_ajax_frame_{$form_id}' id='gform_ajax_frame_{$form_id}'></iframe>\n <script type='text/javascript'>" . "function gformInitSpinner(){" . "jQuery('#gform_{$form_id}').submit(function(){" . "jQuery('#gform_submit_button_{$form_id}').attr('disabled', 'disabled').after('<' + 'img id=\"gform_ajax_spinner_{$form_id}\" class=\"gform_ajax_spinner\" src=\"{$spinner_url}\" alt=\"\" />');" . "jQuery('#gform_wrapper_{$form_id} .gform_previous_button').attr('disabled', 'disabled'); " . "jQuery('#gform_wrapper_{$form_id} .gform_next_button').attr('disabled', 'disabled').after('<' + 'img id=\"gform_ajax_spinner_{$form_id}\" class=\"gform_ajax_spinner\" src=\"{$spinner_url}\" alt=\"\" />');" . "});" . "}" . "jQuery(document).ready(function(\$){" . "gformInitSpinner();" . "jQuery('#gform_ajax_frame_{$form_id}').load( function(){" . "var form_content = jQuery(this).contents().find('#gform_wrapper_{$form_id}');" . "var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message');" . "jQuery('#gform_submit_button_{$form_id}').removeAttr('disabled');" . "if(form_content.length > 0){" . "jQuery('#gform_wrapper_{$form_id}').html(form_content.html());" . "jQuery(document).scrollTop(jQuery('#gform_wrapper_{$form_id}').offset().top);" . "if(window['gformInitDatepicker']) {gformInitDatepicker();}" . "if(window['gformInitPriceFields']) {gformInitPriceFields();}" . "var current_page = jQuery('#gform_source_page_number_{$form_id}').val();" . "gformInitSpinner();" . "jQuery(document).trigger('gform_page_loaded', [{$form_id}, current_page]);" . "}" . "else if(confirmation_content.length > 0){" . "setTimeout(function(){" . "jQuery('#gform_wrapper_{$form_id}').replaceWith('<' + 'div id=\\'gforms_confirmation_message\\'' + '>' + confirmation_content.html() + '<' + '/div' + '>');" . "jQuery(document).scrollTop(jQuery('#gforms_confirmation_message').offset().top);" . "jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}]);" . "}, 50);" . "}" . "else{" . "jQuery('#gform_{$form_id}').append(jQuery(this).contents().find('*').html());" . "if(window['gformRedirect']) gformRedirect();" . "}" . "});" . "});" . "</script>"; } return $form_string; } else { if ($ajax) { $confirmation_message = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body>" . $confirmation_message . "</body></html>"; } return $confirmation_message; } }
/** * Adapted from forms_model.php, RGFormsModel::save_lead($Form, $lead) * @param array $form Form object. * @param array $lead Lead object * @return void */ public static function save_lead($form, &$lead) { global $wpdb; if (IS_ADMIN && !GFCommon::current_user_can_any("gravityforms_edit_entries")) { die(__("You don't have adequate permission to edit entries.", "gravityforms")); } $lead_detail_table = RGFormsModel::get_lead_details_table_name(); //Inserting lead if null if ($lead == null) { global $current_user; $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL'; $lead_table = RGFormsModel::get_lead_table_name(); $user_agent = RGFormsModel::truncate($_SERVER["HTTP_USER_AGENT"], 250); $currency = GFCommon::get_currency(); $source_url = RGFormsModel::truncate(RGFormsModel::get_current_page_url(), 200); $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form["id"], RGFormsModel::get_ip(), $source_url, $user_agent, $currency)); //reading newly created lead id $lead_id = $wpdb->insert_id; $lead = array("id" => $lead_id); } $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead["id"])); $original_post_id = rgget("post_id", $lead); $total_fields = array(); $calculation_fields = array(); $recalculate_total = false; foreach ($form["fields"] as $field) { //Ignore fields that are marked as display only if (rgget("displayOnly", $field) && $field["type"] != "password") { continue; } //ignore pricing fields in the entry detail if (RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field($field["type"])) { continue; } //process total field after all fields have been saved if ($field["type"] == "total") { $total_fields[] = $field; continue; } //only save fields that are not hidden (except on entry screen) if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array(), $lead)) { // process calculation fields after all fields have been saved (moved after the is hidden check) if (GFCommon::has_field_calculation($field)) { $calculation_fields[] = $field; continue; } if ($field['type'] == 'post_category') { $field = GFCommon::add_categories_as_choices($field, ''); } if (isset($field["inputs"]) && is_array($field["inputs"])) { foreach ($field["inputs"] as $input) { RGFormsModel::save_input($form, $field, $lead, $current_fields, $input["id"]); } } else { RGFormsModel::save_input($form, $field, $lead, $current_fields, $field["id"]); } } //Refresh lead to support conditionals (not optimal but...) $lead = RGFormsModel::get_lead($lead['id']); } if (!empty($calculation_fields)) { foreach ($calculation_fields as $calculation_field) { if (isset($calculation_field["inputs"]) && is_array($calculation_field["inputs"])) { foreach ($calculation_field["inputs"] as $input) { RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input["id"]); RGFormsModel::refresh_lead_field_value($lead["id"], $input["id"]); } } else { RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field["id"]); RGFormsModel::refresh_lead_field_value($lead["id"], $calculation_field["id"]); } } RGFormsModel::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id'])); } //saving total field as the last field of the form. if (!empty($total_fields)) { foreach ($total_fields as $total_field) { GFCommon::log_debug("Saving total field."); RGFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field["id"]); } } }
public static function start_express_checkout($confirmation, $form, $entry, $ajax) { $config = self::get_config($form); if (!$config) { return $confirmation; } $product_billing_data = self::get_product_billing_data($form, $entry, $config); $amount = $product_billing_data["amount"]; $products = $product_billing_data["products"]; $billing = $product_billing_data["billing"]; //TODO: add to settings $allow_note = "0"; //rgar($gateway_settings, "allownote") ? "1": "0"; //1- send to paypal and get response $fields = "METHOD=SetExpressCheckout&"; if ($config["meta"]["type"] != "product") { $fields .= "L_BILLINGTYPE0=RecurringPayments&" . "PAYMENTREQUEST_0_AMT={$amount}&" . "L_BILLINGAGREEMENTDESCRIPTION0=" . urlencode(self::get_recurring_description($config, $product_billing_data)) . "&"; } else { $fields .= "PAYMENTREQUEST_0_AMT={$amount}&" . "PAYMENTREQUEST_0_CURRENCYCODE=" . GFCommon::get_currency() . "&" . "REQCONFIRMSHIPPING=0&" . "ALLOWNOTE={$allow_note}&" . "NOSHIPPING=1&"; for ($i = 0; $i < $product_billing_data["line_items"]; $i++) { $fields .= "L_PAYMENTREQUEST_0_NAME{$i}=" . urlencode($billing["L_NAME{$i}"]) . "&" . "L_PAYMENTREQUEST_0_AMT{$i}=" . $billing["L_AMT{$i}"] . "&" . "L_PAYMENTREQUEST_0_QTY{$i}=" . $billing["L_QTY{$i}"] . "&"; } } $cancel_url = rgempty("cancel_url", $config) ? RGFormsModel::get_current_page_url() : rgar($config, "cancel_url"); $fields .= "CANCELURL=" . urlencode($cancel_url) . "&" . "RETURNURL=" . urlencode(RGFormsModel::get_current_page_url()) . "&" . "PAGESTYLE=" . urlencode(rgar($config, "page_style")) . "&" . "LOCALECODE=" . urlencode(rgar($config, "locale")) . "&" . "EMAIL=" . urlencode(rgar($data, "user_email")); $response = array(); $success = self::send_request($config, $fields, $response, $form, $entry); if (!$success) { //GCCommon::log_error("paypalpro", "Error on SetExpressCheckout call \n\nFields:\n {$fields} \n\nResponse:\n " . print_r($response, true)); return __("There was an error while contacting PayPal. Your payment could not be processed. Please try again later", "gravityformspaypalpro"); } else { //Getting Url (Production or Sandbox) $url = rgar($config, "mode") == "production" ? self::$production_express_checkout_url : self::$sandbox_express_checkout_url; $url .= "?cmd=_express-checkout&token={$response["TOKEN"]}"; gform_update_meta($entry["id"], "paypalpro_express_checkout_token", $response["TOKEN"]); //Redirecting to paypal return array("redirect" => $url); } }