/** * Acquirrer field input * * @param string $field_content * @param string $field * @param string $value * @param string $lead_id * @param string $form_id */ public static function acquirer_field_input($field_content, $field, $value, $lead_id, $form_id) { $type = RGFormsModel::get_input_type($field); if (Pronamic_WP_Pay_Extensions_GravityForms_IssuerDropDown::TYPE === $type) { $id = $field['id']; $field_id = IS_ADMIN || 0 === $form_id ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $class_suffix = RG_CURRENT_VIEW === 'entry' ? '_admin' : ''; $size = rgar($field, 'size'); $class = $size . $class_suffix; $css_class = trim(esc_attr($class) . ' gfield_ideal_acquirer_select'); $tab_index = GFCommon::get_tabindex(); $disabled_text = IS_ADMIN && 'entry' !== RG_CURRENT_VIEW ? "disabled='disabled'" : ''; $html = ''; $feed = get_pronamic_gf_pay_conditioned_feed_by_form_id($form_id, true); /** * Developing warning: * Don't use single quotes in the HTML you output, it is buggy in combination with SACK */ if (IS_ADMIN) { if (null === $feed) { $html .= sprintf("<a class='ideal-edit-link' href='%s' target='_blank'>%s</a>", add_query_arg('post_type', 'pronamic_pay_gf', admin_url('post-new.php')), __('Create iDEAL feed', 'pronamic_ideal')); } else { $html .= sprintf("<a class='ideal-edit-link' href='%s' target='_blank'>%s</a>", get_edit_post_link($feed->id), __('Edit iDEAL feed', 'pronamic_ideal')); } } $html_input = ''; $html_error = ''; if (null !== $feed) { $gateway = Pronamic_WP_Pay_Plugin::get_gateway($feed->config_id); if ($gateway) { $issuer_field = $gateway->get_issuer_field(); $error = $gateway->get_error(); if (is_wp_error($error)) { $html_error .= Pronamic_WP_Pay_Plugin::get_default_error_message(); $html_error .= '<br /><em>' . $error->get_error_message() . '</em>'; } elseif ($issuer_field) { $choices = $issuer_field['choices']; $options = Pronamic_WP_HTML_Helper::select_options_grouped($choices, $value); // Double quotes are not working, se we replace them with an single quote $options = str_replace('"', '\'', $options); $html_input = ''; $html_input .= sprintf("<select name='input_%d' id='%s' class='%s' %s %s>", $id, $field_id, $css_class, $tab_index, $disabled_text); $html_input .= sprintf('%s', $options); $html_input .= sprintf('</select>'); } } } if ($html_error) { $html .= sprintf("<div class='gfield_description validation_message'>"); $html .= sprintf('%s', $html_error); $html .= sprintf('</div>'); } else { $html .= sprintf("<div class='ginput_container ginput_ideal'>"); $html .= sprintf('%s', $html_input); $html .= sprintf('</div>'); } $field_content = $html; } return $field_content; }
function output_data($pdf, $lead = array(), $form = array(), $fieldData = array()) { $pdf->AddPage(); $dataArray = array(array('Project ID #', 3), array('Project Name', 28), array('Name of person responsible for fire safety at your exhibit', 5), array('Their Email', 15), array('Their phone', 16), array('Description', 19), array('Describe your safety concerns', 12), array('Describe how you plan to keep your exhibit safe', 20), array('Who will be assisting at your exhibit to keep it safe', 11), array('Placement Requirements', 7), array('Do you have Insurance', 9), array('Additional Comments', 13), array('Are you 18 years or older?', 23), array('Signed', 25), array('I am the Parent and/or Legal Guardian of', 26), array('Date', 27)); $pdf->SetFillColor(190, 210, 247); $lineheight = 6; foreach ($dataArray as $data) { $fieldID = $data[1]; if (isset($fieldData[$fieldID])) { $field = $fieldData[$fieldID]; $value = RGFormsModel::get_lead_field_value($lead, $field); if (RGFormsModel::get_input_type($field) != 'email') { $display_value = GFCommon::get_lead_field_display($field, $value); $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $lead, $form); } else { $display_value = $value; } } else { $display_value = ''; } $pdf->MultiCell(0, $lineheight, $data[0] . ': '); $pdf->MultiCell(0, $lineheight, $display_value, 0, 'L', true); $pdf->Ln(); } }
function output_data($pdf, $lead = array(), $form = array(), $fieldData = array()) { $pdf->AddPage(); $dataArray = array(array('Project ID #', 3, 'text'), array('Project Name', 38, 'text'), array('Name of person responsible for fire safety at your exhibit', 21, 'text'), array('Their Email', 23, 'text'), array('Their Phone', 24, 'text'), array('Description', 37, 'textarea'), array('Describe your fire safety concerns', 19, 'textarea'), array('Describe how you plan to keep your exhibit safe', 27, 'textarea'), array('Who will be assisting at your exhibit to keep it safe', 20, 'text'), array('Placement Requirements', 7, 'textarea'), array('What is burning', 10, 'text'), array('What is the fuel source', 11, 'text'), array('how much is fuel is burning and in what time period', 12, 'textarea'), array('how much fuel will you have at the event, including tank sizes', 13, 'textarea'), array('where and how is the fuel stored', 14, 'text'), array('Does the valve have an electronic propane sniffer', 15, 'text'), array('Other suppression devices', 16, 'textarea'), array('Do you have insurance?', 18, 'text'), array('Additional comments', 28, 'textarea'), array('Are you 18 years or older?', 30, 'text'), array('Signed', 32, 'text'), array('I am the Parent and/or Legal Guardian of', 33, 'text'), array('Date', 34, 'text')); $pdf->SetFillColor(190, 210, 247); $lineheight = 6; foreach ($dataArray as $data) { $fieldID = $data[1]; if (isset($fieldData[$fieldID])) { $field = $fieldData[$fieldID]; $value = RGFormsModel::get_lead_field_value($lead, $field); if (RGFormsModel::get_input_type($field) != 'email') { $display_value = GFCommon::get_lead_field_display($field, $value); $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $lead, $form); } else { $display_value = $value; } } else { $display_value = ''; } $pdf->MultiCell(0, $lineheight, $data[0] . ': '); $pdf->MultiCell(0, $lineheight, $display_value, 0, 'L', true); $pdf->Ln(); } }
public static function create_post($form, &$lead) { GFCommon::log_debug('GFFormsModel::create_post(): Starting.'); $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) { GFCommon::log_debug("GFFormsModel::create_post(): Stopping. The form doesn't have any post fields."); return $lead; } //processing post fields GFCommon::log_debug('GFFormsModel::create_post(): Getting post fields.'); $post_data = self::get_post_fields($form, $lead); //allowing users to change post fields before post gets created $post_data = gf_apply_filters('gform_post_data', $form['id'], $post_data, $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(); } // remove original post status and save it for later $post_status = $post_data['post_status']; // replace original post status with 'draft' so other plugins know this post is not fully populated yet $post_data['post_status'] = 'draft'; // inserting post GFCommon::log_debug('GFFormsModel::create_post(): Inserting post via wp_insert_post().'); $post_id = wp_insert_post($post_data); GFCommon::log_debug("GFFormsModel::create_post(): Result from wp_insert_post(): {$post_id}."); //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 GFCommon::log_debug('GFFormsModel::create_post(): 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'])) { GFCommon::log_debug('GFFormsModel::create_post(): Adding image: ' . $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 ($field->postFeaturedImage) { set_post_thumbnail($post_id, $media_id); } } } } //adding custom fields GFCommon::log_debug('GFFormsModel::create_post(): 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) { GFCommon::log_debug('GFFormsModel::create_post(): Getting custom field: ' . $meta_name); $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 GFCommon::log_debug('GFFormsModel::create_post(): 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 and replace HTML symbol in $item with real comma add_post_meta($post_id, $meta_name, str_replace(',', ',', $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(self::get_fields_by_type($form, array('post_content'))) > 0; $has_title_field = sizeof(self::get_fields_by_type($form, array('post_title'))) > 0; $post = false; //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) { GFCommon::log_debug('GFFormsModel::create_post(): Processing template.'); $post = get_post($post_id); if (rgar($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 (rgar($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; } } // update post status back to original status (if not draft) if ($post_status != 'draft') { $post = is_object($post) ? $post : get_post($post_id); $post->post_status = $post_status; } // if post has been modified since creation, save updates if (is_object($post)) { GFCommon::log_debug('GFFormsModel::create_post(): Updating post.'); 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; GFCommon::log_debug('GFFormsModel::create_post(): Updating entry with post id.'); self::update_lead_property($lead['id'], 'post_id', $post_id); do_action('gform_after_create_post', $post_id); return $post_id; }
private static function has_currency_format_number_field($form) { if (is_array($form['fields'])) { foreach ($form['fields'] as $field) { $input_type = RGFormsModel::get_input_type($field); if ($input_type == 'number' && $field->numberFormat == 'currency') { return true; } } } return false; }
public static function get_field_map_choices($form_id) { $form = RGFormsModel::get_form_meta($form_id); $fields = array(); // Adding default fields $fields[] = array("value" => "", "label" => ""); $fields[] = array("value" => "date_created", "label" => __("Entry Date", "gravityforms")); $fields[] = array("value" => "ip", "label" => __("User IP", "gravityforms")); $fields[] = array("value" => "source_url", "label" => __("Source Url", "gravityforms")); $fields[] = array("value" => "form_title", "label" => __("Form Title", "gravityforms")); // Populate entry meta $entry_meta = GFFormsModel::get_entry_meta($form["id"]); foreach ($entry_meta as $meta_key => $meta) { $fields[] = array('value' => $meta_key, 'label' => rgars($entry_meta, "{$meta_key}/label")); } // Populate form fields if (is_array($form["fields"])) { foreach ($form["fields"] as $field) { if (is_array(rgar($field, "inputs"))) { //If this is an address field, add full name to the list if (RGFormsModel::get_input_type($field) == "address") { $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . " (" . __("Full", "gravityforms") . ")"); } //If this is a name field, add full name to the list if (RGFormsModel::get_input_type($field) == "name") { $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . " (" . __("Full", "gravityforms") . ")"); } //If this is a checkbox field, add to the list if (RGFormsModel::get_input_type($field) == "checkbox") { $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . " (" . __("Selected", "gravityforms") . ")"); } foreach ($field['inputs'] as $input) { if (RGFormsModel::get_input_type($field) == 'creditcard') { //only include the credit card type (field_id.4) and number (field_id.1) if ($input['id'] == $field['id'] . '.1' || $input['id'] == $field['id'] . '.4') { $fields[] = array('value' => $input["id"], 'label' => GFCommon::get_label($field, $input['id'])); } } else { $fields[] = array('value' => $input["id"], 'label' => GFCommon::get_label($field, $input["id"])); } } } else { if (!rgar($field, "displayOnly")) { $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field)); } } } } return $fields; }
public static function start_export($form) { $form_id = $form['id']; $fields = $_POST['export_field']; $start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00'); $end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59'); $search_criteria['status'] = 'active'; $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form); if (!empty($start_date)) { $search_criteria['start_date'] = $start_date; } if (!empty($end_date)) { $search_criteria['end_date'] = $end_date; } $sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info'); GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}"); GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}"); $form = self::add_default_export_fields($form); $entry_count = GFAPI::count_entries($form_id, $search_criteria); $page_size = 100; $offset = 0; //Adding BOM marker for UTF-8 $lines = chr(239) . chr(187) . chr(191); // set the separater $separator = apply_filters('gform_export_separator_' . $form_id, apply_filters('gform_export_separator', ',', $form_id), $form_id); $field_rows = self::get_field_row_count($form, $fields, $entry_count); //writing header $headers = array(); foreach ($fields as $field_id) { $field = RGFormsModel::get_field($form, $field_id); $value = str_replace('"', '""', GFCommon::get_label($field, $field_id)); GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}"); $headers[$field_id] = $str = preg_replace('/[^a-z\\d ]/i', '', $value); $subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0; if ($subrow_count == 0) { $lines .= '"' . $value . '"' . $separator; } else { for ($i = 1; $i <= $subrow_count; $i++) { $lines .= '"' . $value . ' ' . $i . '"' . $separator; } } GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}"); } $lines = substr($lines, 0, strlen($lines) - 1) . "\n"; //paging through results for memory issues while ($entry_count > 0) { $paging = array('offset' => $offset, 'page_size' => $page_size); $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging); $leads = apply_filters("gform_leads_before_export_{$form_id}", apply_filters('gform_leads_before_export', $leads, $form, $paging), $form, $paging); foreach ($leads as $lead) { foreach ($fields as $field_id) { switch ($field_id) { case 'date_created': $lead_gmt_time = mysql2date('G', $lead['date_created']); $lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time); $value = date_i18n('Y-m-d H:i:s', $lead_local_time, true); break; default: $long_text = ''; if (strlen(rgar($lead, $field_id)) >= GFORMS_MAX_FIELD_LENGTH - 10) { $long_text = RGFormsModel::get_field_value_long($lead, $field_id, $form); } $value = !empty($long_text) ? $long_text : rgar($lead, $field_id); $field = RGFormsModel::get_field($form, $field_id); $input_type = RGFormsModel::get_input_type($field); if ($input_type == 'checkbox') { //pass in label value that has not had quotes escaped so the is_checkbox_checked function compares the unchanged label value with the lead value $header_label_not_escaped = GFCommon::get_label($field, $field_id); $value = GFFormsModel::is_checkbox_checked($field_id, $header_label_not_escaped, $lead, $form); if ($value === false) { $value = ''; } } else { if ($input_type == 'fileupload' && $field->multipleFiles) { $value = !empty($value) ? implode(' , ', json_decode($value, true)) : ''; } } $value = preg_replace('/[^a-z\\d ]/i', '', $value); $value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead); GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}"); break; } if (isset($field_rows[$field_id])) { $list = empty($value) ? array() : unserialize($value); foreach ($list as $row) { $row_values = array_values($row); $row_str = implode('|', $row_values); $lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator; } //filling missing subrow columns (if any) $missing_count = intval($field_rows[$field_id]) - count($list); for ($i = 0; $i < $missing_count; $i++) { $lines .= '""' . $separator; } } else { $value = maybe_unserialize($value); if (is_array($value)) { $value = implode('|', $value); } $lines .= '"' . str_replace('"', '""', $value) . '"' . $separator; } } $lines = substr($lines, 0, strlen($lines) - 1); GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}"); $lines .= "\n"; } $offset += $page_size; $entry_count -= $page_size; if (!seems_utf8($lines)) { $lines = utf8_encode($lines); } if (function_exists('mb_convert_encoding')) { // Convert the contents to UTF-16LE which has wider support than UTF-8. // This fixes an issue with special characters in Excel for Mac. $lines = mb_convert_encoding($lines, 'UTF-16LE', 'UTF-8'); } echo $lines; $lines = ''; } }
public static function lead_detail_grid($form, $lead, $allow_display_empty_fields = false) { $form_id = $form["id"]; $display_empty_fields = false; if ($allow_display_empty_fields) { $display_empty_fields = rgget("gf_display_empty_fields", $_COOKIE); } ?> <table cellspacing="0" class="widefat fixed entry-detail-view"> <thead> <tr> <th id="details"> <?php echo $form["title"]; ?> : <?php _e("Entry # ", "gravityforms"); ?> <?php echo $lead["id"]; ?> </th> <th style="width:140px; font-size:10px; text-align: right;"> <?php if ($allow_display_empty_fields) { ?> <input type="checkbox" id="gentry_display_empty_fields" <?php echo $display_empty_fields ? "checked='checked'" : ""; ?> onclick="ToggleShowEmptyFields();"/> <label for="gentry_display_empty_fields"><?php _e("show empty fields", "gravityforms"); ?> </label> <?php } ?> </th> </tr> </thead> <tbody> <?php $count = 0; $field_count = sizeof($form["fields"]); $has_product_fields = false; foreach ($form["fields"] as $field) { switch (RGFormsModel::get_input_type($field)) { case "section": if (!GFCommon::is_section_empty($field, $form, $lead) || $display_empty_fields) { $count++; $is_last = $count >= $field_count ? true : false; ?> <tr> <td colspan="2" class="entry-view-section-break<?php echo $is_last ? " lastrow" : ""; ?> "><?php echo esc_html(GFCommon::get_label($field)); ?> </td> </tr> <?php } break; case "captcha": case "html": case "password": case "page": //ignore captcha, html, password, page field break; default: //ignore product fields as they will be grouped together at the end of the grid if (GFCommon::is_product_field($field["type"])) { $has_product_fields = true; continue; } $value = RGFormsModel::get_lead_field_value($lead, $field); $display_value = GFCommon::get_lead_field_display($field, $value, $lead["currency"]); $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $lead, $form); if ($display_empty_fields || !empty($display_value) || $display_value === "0") { $count++; $is_last = $count >= $field_count && !$has_product_fields ? true : false; $last_row = $is_last ? " lastrow" : ""; $display_value = empty($display_value) && $display_value !== "0" ? " " : $display_value; $content = ' <tr> <td colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</td> </tr> <tr> <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td> </tr>'; $content = apply_filters("gform_field_content", $content, $field, $value, $lead["id"], $form["id"]); echo $content; } break; } } $products = array(); if ($has_product_fields) { $products = GFCommon::get_product_fields($form, $lead); if (!empty($products["products"])) { ?> <tr> <td colspan="2" class="entry-view-field-name"><?php echo apply_filters("gform_order_label_{$form["id"]}", apply_filters("gform_order_label", __("Order", "gravityforms"), $form["id"]), $form["id"]); ?> </td> </tr> <tr> <td colspan="2" class="entry-view-field-value lastrow"> <table class="entry-products" cellspacing="0" width="97%"> <colgroup> <col class="entry-products-col1"> <col class="entry-products-col2"> <col class="entry-products-col3"> <col class="entry-products-col4"> </colgroup> <thead> <th scope="col"><?php echo apply_filters("gform_product_{$form_id}", apply_filters("gform_product", __("Product", "gravityforms"), $form_id), $form_id); ?> </th> <th scope="col" class="textcenter"><?php echo apply_filters("gform_product_qty_{$form_id}", apply_filters("gform_product_qty", __("Qty", "gravityforms"), $form_id), $form_id); ?> </th> <th scope="col"><?php echo apply_filters("gform_product_unitprice_{$form_id}", apply_filters("gform_product_unitprice", __("Unit Price", "gravityforms"), $form_id), $form_id); ?> </th> <th scope="col"><?php echo apply_filters("gform_product_price_{$form_id}", apply_filters("gform_product_price", __("Price", "gravityforms"), $form_id), $form_id); ?> </th> </thead> <tbody> <?php $total = 0; foreach ($products["products"] as $product) { ?> <tr> <td> <div class="product_name"><?php echo $product["name"]; ?> </div> <ul class="product_options"> <?php $price = GFCommon::to_number($product["price"]); if (is_array(rgar($product, "options"))) { $count = sizeof($product["options"]); $index = 1; foreach ($product["options"] as $option) { $price += GFCommon::to_number($option["price"]); $class = $index == $count ? " class='lastitem'" : ""; $index++; ?> <li<?php echo $class; ?> ><?php echo $option["option_label"]; ?> </li> <?php } } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; ?> </ul> </td> <td class="textcenter"><?php echo $product["quantity"]; ?> </td> <td><?php echo GFCommon::to_money($price, $lead["currency"]); ?> </td> <td><?php echo GFCommon::to_money($subtotal, $lead["currency"]); ?> </td> </tr> <?php } $total += floatval($products["shipping"]["price"]); ?> </tbody> <tfoot> <?php if (!empty($products["shipping"]["name"])) { ?> <tr> <td colspan="2" rowspan="2" class="emptycell"> </td> <td class="textright shipping"><?php echo $products["shipping"]["name"]; ?> </td> <td class="shipping_amount"><?php echo GFCommon::to_money($products["shipping"]["price"], $lead["currency"]); ?> </td> </tr> <?php } ?> <tr> <?php if (empty($products["shipping"]["name"])) { ?> <td colspan="2" class="emptycell"> </td> <?php } ?> <td class="textright grandtotal"><?php _e("Total", "gravityforms"); ?> </td> <td class="grandtotal_amount"><?php echo GFCommon::to_money($total, $lead["currency"]); ?> </td> </tr> </tfoot> </table> </td> </tr> <?php } } ?> </tbody> </table> <?php }
/** * Returns the GF Form field type for a certain field(id) of a form * @param object $form Gravity Forms form * @param mixed $field_id Field ID or Field array * @return string field type */ public static function get_field_type($form = null, $field_id = '') { if (!empty($field_id) && !is_array($field_id)) { $field = self::get_field($form, $field_id); } else { $field = $field_id; } return class_exists('RGFormsModel') ? RGFormsModel::get_input_type($field) : ''; }
public static function get_lead_field_display($field, $value, $currency = "", $use_text = false) { switch (RGFormsModel::get_input_type($field)) { case "name": if (is_array($value)) { $prefix = trim($value[$field["id"] . ".2"]); $first = trim($value[$field["id"] . ".3"]); $last = trim($value[$field["id"] . ".6"]); $suffix = trim($value[$field["id"] . ".8"]); $name = $prefix; $name .= !empty($name) && !empty($first) ? " {$first}" : $first; $name .= !empty($name) && !empty($last) ? " {$last}" : $last; $name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix; return $name; } else { return $value; } break; case "address": if (is_array($value)) { $street_value = trim($value[$field["id"] . ".1"]); $street2_value = trim($value[$field["id"] . ".2"]); $city_value = trim($value[$field["id"] . ".3"]); $state_value = trim($value[$field["id"] . ".4"]); $zip_value = trim($value[$field["id"] . ".5"]); $country_value = trim($value[$field["id"] . ".6"]); $address_display_format = apply_filters("gform_address_display_format", "street,city,state,zip,country"); if ($address_display_format == "zip_before_city") { /* Sample: 3333 Some Street suite 16 2344 City, State Country */ $addr_ary = array(); $addr_ary[] = $street_value; if (!empty($street2_value)) { $addr_ary[] = $street2_value; } $zip_line = trim($zip_value . " " . $city_value); $zip_line .= !empty($zip_line) && !empty($state_value) ? ", {$state_value}" : $state_value; $zip_line = trim($zip_line); if (!empty($zip_line)) { $addr_ary[] = $zip_line; } if (!empty($country_value)) { $addr_ary[] = $country_value; } $address = implode("<br />", $addr_ary); } else { $address = $street_value; $address .= !empty($address) && !empty($street2_value) ? "<br />{$street2_value}" : $street2_value; $address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? "<br />{$city_value}" : $city_value; $address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value; $address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value; $address .= !empty($address) && !empty($country_value) ? "<br />{$country_value}" : $country_value; } //adding map link if (!empty($address)) { $address_qs = str_replace("<br />", " ", $address); //replacing <br/> with spaces $address_qs = urlencode($address_qs); $address .= "<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>"; } return $address; } else { return ""; } break; case "email": return GFCommon::is_valid_email($value) ? "<a href='mailto:{$value}'>{$value}</a>" : $value; break; case "website": return GFCommon::is_valid_url($value) ? "<a href='{$value}' target='_blank'>{$value}</a>" : $value; break; case "checkbox": if (is_array($value)) { foreach ($value as $key => $item) { if (!empty($item)) { $items .= "<li>" . GFCommon::selection_display($item, $field, $currency, $use_text) . "</li>"; } } return empty($items) ? "" : "<ul class='bulleted'>{$items}</ul>"; } else { return $value; } break; case "post_image": list($url, $title, $caption, $description) = explode("|:|", $value); if (!empty($url)) { $url = str_replace(" ", "%20", $url); $value = "<a href='{$url}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$url}' width='100' /></a>"; $value .= !empty($title) ? "<div>Title: {$title}</div>" : ""; $value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : ""; $value .= !empty($description) ? "<div>Description: {$description}</div>" : ""; } return $value; case "fileupload": $file_path = $value; if (!empty($file_path)) { $info = pathinfo($file_path); $file_path = esc_attr(str_replace(" ", "%20", $file_path)); $value = "<a href='{$file_path}' target='_blank' title='" . __("Click to view", "gravityforms") . "'>" . $info["basename"] . "</a>"; } return $value; break; case "date": return GFCommon::date_display($value, $field["dateFormat"]); break; case "radio": case "select": return GFCommon::selection_display($value, $field, $currency, $use_text); break; case "singleproduct": if (is_array($value)) { $product_name = trim($value[$field["id"] . ".1"]); $price = trim($value[$field["id"] . ".2"]); $quantity = trim($value[$field["id"] . ".3"]); $product = $product_name . ", " . __("Qty: ", "gravityforms") . $quantity . ", " . __("Price: ", "gravityforms") . $price; return $product; } else { return ""; } break; case "singleshipping": case "donation": case "total": case "price": return GFCommon::to_money($value, $currency); default: return nl2br($value); break; } }
public static function export_feed($entry, $form, $feed, $api) { $email_field_id = $feed["meta"]["field_map"]["email_address"]; $email = $entry[$email_field_id]; $merge_vars = array(''); foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) { $field = RGFormsModel::get_field($form, $field_id); $field_type = RGFormsModel::get_input_type($field); if ($field_id == intval($field_id) && $field_type == "address") { //handling full address $merge_vars[$var_tag] = self::get_address($entry, $field_id); } elseif ($field_type == 'date') { $merge_vars[$var_tag] = apply_filters('gravityforms_constant_contact_change_date_format', $entry[$field_id]); } else { $merge_vars[$var_tag] = $entry[$field_id]; } } $retval = $api->listSubscribe($feed["meta"]["contact_list_id"], $merge_vars, "html"); if (!is_wp_error($retval) && !empty($retval)) { self::add_note($entry["id"], __('Successfully added/updated in Constant Contact.', 'gravity-forms-constant-contact')); } else { $error = ''; if (is_wp_error($retval)) { $error = ': ' . $retval->get_error_message(); } self::add_note($entry["id"], __('Errors when adding/updating in Constant Contact', 'gravity-forms-constant-contact') . $error); } }
public function export_feed($entry, $form, $feed) { //$email = $entry[ $feed['meta']['listFields_email'] ]; //$name = ''; if (!empty($feed['meta']['listFields_first_name'])) { $name = $this->get_name($entry, $feed['meta']['listFields_first_name']); } $merge_vars = array(); $field_maps = $this->get_field_map_fields($feed, 'listFields'); foreach ($field_maps as $var_key => $field_id) { $field = RGFormsModel::get_field($form, $field_id); if (GFCommon::is_product_field($field['type']) && rgar($field, 'enablePrice')) { $ary = explode('|', $entry[$field_id]); $product_name = count($ary) > 0 ? $ary[0] : ''; $merge_vars[] = array('name' => $var_key, 'value' => $product_name); } else { if (RGFormsModel::get_input_type($field) == 'checkbox') { foreach ($field['inputs'] as $input) { $index = (string) $input['id']; $merge_vars[] = array('name' => $var_key, 'value' => apply_filters('gform_crm_field_value', rgar($entry, $index), $form['id'], $field_id, $entry)); } } else { $merge_vars[] = array('name' => $var_key, 'value' => apply_filters('gform_crm_field_value', rgar($entry, $field_id), $form['id'], $field_id, $entry)); } } } $override_custom_fields = apply_filters('gform_crm_override_blank_custom_fields', false, $entry, $form, $feed); if (!$override_custom_fields) { $merge_vars = $this->remove_blank_custom_fields($merge_vars); } $settings = $this->get_plugin_settings(); if (isset($settings['gf_fd_accountname'])) { $accountname = $settings['gf_fd_accountname']; } else { $accountname = ""; } if (isset($settings['gf_fd_apipassword'])) { $apipassword = $settings['gf_fd_apipassword']; } else { $apipassword = ""; } $id = $this->facturadirecta_createlead($accountname, $apipassword, $merge_vars); //Sends email if it does not create a lead //if ($id == false) // $this->send_emailerrorlead($crm_type); $this->debugcrm($id); }
public static function export_feed($entry, $form, $feed, $api) { $double_optin = $feed["meta"]["double_optin"] ? true : false; $send_welcome = $feed["meta"]["welcome_email"] ? true : false; $email_field_id = $feed["meta"]["field_map"]["EMAIL"]; $email = rgar($entry, $email_field_id); $merge_vars = array(''); foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) { $field = RGFormsModel::get_field($form, $field_id); if ($field_id == intval($field_id) && RGFormsModel::get_input_type($field) == "address") { //handling full address $merge_vars[$var_tag] = self::get_address($entry, $field_id); } else { if ($var_tag != "EMAIL") { //ignoring email field as it will be handled separatelly $merge_vars[$var_tag] = rgar($entry, $field_id); } } } $groupings = $feed["meta"]["groups"]; if (is_array($groupings)) { $keys = array_keys($groupings); $i = 0; foreach ($feed["meta"]["groups"] as $grouping_name => $groups) { $group_list = ""; $grouping_label = ""; foreach ($groups as $group_name => $group) { $group_label = $group["group_label"]; $grouping_label = $group["grouping_label"]; if (self::assign_group_allowed($form, $feed, $grouping_name, $group_name)) { $group_list .= $group_label . ","; } } if (!empty($group_list)) { $merge_vars["GROUPINGS"][$i]["name"] = $grouping_label; $merge_vars["GROUPINGS"][$i]["groups"] = substr($group_list, 0, -1); } $i++; } } self::log("Checking to see if {$email} is already on the list", "debug"); $member_info = $api->listMemberInfo($feed["meta"]["contact_list_id"], $email); if ($member_info["errors"] > 0) { self::log("{$email} is not on the list; adding to list", "debug"); self::log("Calling - listSubscribe, Parameters - List ID: " . $feed["meta"]["contact_list_id"] . ", Email: {$email}, " . " Merge_Vars: " . print_r($merge_vars, true) . ", Email Type: html, Double Opt In: {$double_optin}, Update Existing: false, Replace Interests: true, Send Welcome: {$send_welcome}", "debug"); $retval = $api->listSubscribe($feed["meta"]["contact_list_id"], $email, $merge_vars, "html", $double_optin, false, true, $send_welcome); } else { //see if subscription is pending, unsubscribed, or cleaned for email; do not update because an error will be thrown by mailchimp $status_check = $member_info["data"]; if ($status_check[0]["status"] != "subscribed") { self::log("{$email} is already on the list but the status is currently " . $status_check[0]["status"] . "; not updating info", "debug"); $retval = true; } else { self::log("{$email} is already on the list; updating info", "debug"); self::log("Calling - listUpdateMember, Parameters - List ID: " . $feed["meta"]["contact_list_id"] . ", Email: {$email}, " . " Merge_Vars: " . print_r($merge_vars, true) . ", Email Type: html, Replace Interests: true", "debug"); $retval = $api->listUpdateMember($feed["meta"]["contact_list_id"], $email, $merge_vars, "html", true); } } //listSubscribe and listUpdateMember return true/false if ($retval) { self::log("Transaction successful", "debug"); } else { self::log("Transaction failed. Error " . $api->errorCode . " - " . $api->errorMessage, "error"); } }
public static function export_feed($entry, $form, $feed, $api) { $double_optin = $feed["meta"]["double_optin"] ? true : false; $send_welcome = $feed["meta"]["welcome_email"] ? true : false; $email_field_id = $feed["meta"]["field_map"]["EMAIL"]; $email = rgar($entry, $email_field_id); $merge_vars = array(''); foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) { switch (strtolower($field_id)) { case "date_created": $merge_vars[$var_tag] = rgar($entry, "date_created"); break; case "form_title": $merge_vars[$var_tag] = rgar($form, "title"); break; case "ip": $merge_vars[$var_tag] = rgar($entry, "ip"); break; case "source_url": $merge_vars[$var_tag] = rgar($entry, "source_url"); break; default: $field = RGFormsModel::get_field($form, $field_id); if ($field_id == intval($field_id) && RGFormsModel::get_input_type($field) == "address") { //handling full address $merge_vars[$var_tag] = self::get_address($entry, $field_id); } else { if ($field_id == intval($field_id) && RGFormsModel::get_input_type($field) == "name") { //handling full name $merge_vars[$var_tag] = self::get_name($entry, $field_id); } else { if ($field_id == intval($field_id) && RGFormsModel::get_input_type($field) == "phone" && $field["phoneFormat"] == "standard") { //reformat phone to go to mailchimp when standard format (US/CAN), needs to be in the format NPA-NXX-LINE 404-555-1212 when US/CAN $phone = rgar($entry, $field_id); if (preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $phone, $matches)) { $phone = sprintf("%s-%s-%s", $matches[1], $matches[2], $matches[3]); } $merge_vars[$var_tag] = $phone; } else { if ($var_tag != "EMAIL") { //ignoring email field as it will be handled separatelly $merge_vars[$var_tag] = apply_filters("gform_mailchimp_field_value", rgar($entry, $field_id), $form["id"], $field_id, $entry); } } } } break; } } $groupings = $feed["meta"]["groups"]; if (is_array($groupings)) { $keys = array_keys($groupings); $i = 0; foreach ($feed["meta"]["groups"] as $grouping_name => $groups) { $group_list = ""; $grouping_label = ""; foreach ($groups as $group_name => $group) { //replace commas in the group name because commas to mailchimp indicate multiple groups $group_label = str_replace(",", "\\,", $group["group_label"]); $grouping_label = $group["grouping_label"]; if (self::assign_group_allowed($form, $feed, $grouping_name, $group_name, $entry)) { $group_list .= $group_label . ","; } } $merge_vars["GROUPINGS"][$i]["name"] = $grouping_label; $merge_vars["GROUPINGS"][$i]["groups"] = empty($group_list) ? "" : substr($group_list, 0, -1); $i++; } } self::log_debug("Checking to see if {$email} is already on the list"); $member_info = $api->listMemberInfo($feed["meta"]["contact_list_id"], $email); if (absint($member_info["errors"]) > 0 || rgar($member_info["data"][0], "status") != "subscribed") { $allow_resubscription = apply_filters('gform_mailchimp_allow_resubscription', apply_filters("gform_mailchimp_allow_resubscription_{$form['id']}", true, $form, $entry, $feed), $form, $entry, $feed); if (rgar($member_info["data"][0], "status") == "unsubscribed" && !$allow_resubscription) { self::log_debug("User is unsubscribed and resubscription is not allowed."); return true; } //adding member to list, statuses of rgar($member_info["data"][0], "status") != "subscribed", pending, cleaned need to be "re-subscribed" to send out confirmation email self::log_debug("{$email} is either not on the list or on the list but the status is not subscribed - status: " . rgar($member_info["data"][0], "status") . "; adding to list"); self::log_debug("Calling - listSubscribe, Parameters - List ID: " . $feed["meta"]["contact_list_id"] . ", Email: {$email}, " . " Merge_Vars: " . print_r($merge_vars, true) . ", Email Type: html, Double Opt In: {$double_optin}, Update Existing: false, Replace Interests: true, Send Welcome: {$send_welcome}"); $retval = $api->listSubscribe($feed["meta"]["contact_list_id"], $email, $merge_vars, "html", $double_optin, false, true, $send_welcome); } else { //updating member self::log_debug("{$email} is already on the list; updating info"); //retrieve existing groups for subscribers; add existing groups to selected groups from form so that existing groups are maintained for that subscriber $current_groups = $member_info["data"][0]["merges"]["GROUPINGS"]; $keep_existing_groups = apply_filters("gform_mailchimp_keep_existing_groups_{$form["id"]}", apply_filters("gform_mailchimp_keep_existing_groups", true, $form, $entry, $feed), $form, $entry, $feed); if (is_array($current_groups) && $keep_existing_groups) { self::log_debug("Appending existing groups."); $merge_vars = self::append_groups($merge_vars, $current_groups); } self::log_debug("Calling - listUpdateMember, Parameters - List ID: " . $feed["meta"]["contact_list_id"] . ", Email: {$email}, " . " Merge_Vars: " . print_r($merge_vars, true) . ", Email Type: html, Replace Interests: true"); $retval = $api->listUpdateMember($feed["meta"]["contact_list_id"], $email, $merge_vars, "html", true); } //listSubscribe and listUpdateMember return true/false if ($retval) { self::log_debug("Transaction successful"); } else { self::log_error("Transaction failed. Error " . $api->errorCode . " - " . $api->errorMessage); } }
public static function select_columns_page() { $form_id = $_GET["id"]; if (empty($form_id)) { echo esc_html__("Oops! We could not locate your form. Please try again.", "gravity-forms-addons"); exit; } //reading form metadata $form = RGFormsModel::get_form_meta($form_id); ?> <html> <head> <?php wp_print_styles(array("wp-admin", "colors-fresh")); wp_print_scripts(array("jquery", "sack", "jquery-ui-sortable")); ?> <style type="text/css"> body { font-family:"Lucida Grande",Verdana,Arial,sans-serif; } #wrapper { padding: 10px;} #sortable_available, #sortable_selected { list-style-type: none; margin: 0; padding: 2px; min-height:250px; border:1px solid #eaeaea; -moz-border-radius:4px; -webkit-border-radius:4px; -khtml-border-radius:4px; border-radius:4px; background-color:#FFF; } #sortable_available li, #sortable_selected li { margin: 0 2px 2px 2px; padding:2px; width: 96%; border:1px solid white; cursor:pointer; font-size: 13px;} .field_hover { border: 1px dashed #2175A9!important;} .placeholder{background-color: #FFF0A5; height:20px;} .gcolumn_wrapper { overflow:auto; height:80%; } .gcolumn_container_left, .gcolumn_container_right {width:46%;} .gcolumn_container_left {float:left;} .gcolumn_container_right {float:right;} .gform_select_column_heading{font-weight:bold; padding-bottom:7px; font-size:13px;} .column-arrow-mid { float:left; width:7%; min-width: 27px; height:100%; background: url(<?php echo plugins_url('images/arrow-rightleft.jpg', __FILE__); ?> ) repeat-y top center; /*background-attachment: fixed;*/ margin-top:26px; } .panel-instructions { border-bottom: 1px solid #dfdfdf; color: #555; font-size:12px; margin-bottom:6px; } .panel-instructions p { padding: 0 0 5px 0; margin: 0; } .clear { clear: both; display: block;} div.panel-buttons {margin-top:8px} div.panel-buttons {*margin-top:0px} /* ie specific */ code { font-size: 12px;} </style> <script type="text/javascript"> function equalHeights(makeTheseEqual) { var currentTallest = 0; var $makeTheseEqual = jQuery(makeTheseEqual); $makeTheseEqual.each(function(i){ if (jQuery(this).height() > currentTallest) { currentTallest = jQuery(this).height(); } }); // for ie6, set height since min-height isn't supported if (jQuery.browser.msie && jQuery.browser.version === 6.0) { $makeTheseEqual.css({'height': currentTallest}); } $makeTheseEqual.css({'min-height': currentTallest}); } jQuery(document).ready(function($) { $("#sortable_available, #sortable_selected").sortable({connectWith: '.sortable_connected', placeholder: 'placeholder'}); equalHeights('.gcolumn_wrapper ul, .column-arrow-mid'); $(".sortable_connected li").hover( function(){ $(this).addClass("field_hover"); }, function(){ $(this).removeClass("field_hover"); } ); }); var columns = new Array(); function SelectColumns(){ columns = []; jQuery("#sortable_selected li").each(function(){ columns.push(this.id); }); ChangeColumns(columns); } function ChangeColumns(columns){ var json_columns = JSON.stringify(columns); UpdateColumns(jQuery("body").data('formid'), json_columns); } function UpdateColumns(form_id, columns) { var mysack = new sack("<?php echo admin_url("admin-ajax.php"); ?> " ); mysack.execute = 1; mysack.method = 'POST'; mysack.setVar( "action", "change_directory_columns" ); mysack.setVar( "gforms_directory_columns", "<?php echo wp_create_nonce("gforms_directory_columns"); ?> " ); mysack.setVar( "form_id", form_id); mysack.setVar( "directory_columns", columns); mysack.onCompletion = function() { self.parent.tb_remove(); }; mysack.onError = function() { alert('<?php echo esc_js(__("Ajax error while setting lead property", "gravity-forms-addons")); ?> ' )}; mysack.runAJAX(); return true; } </script> </head> <body data-formid="<?php echo $form_id; ?> "> <div id="wrapper"> <?php $columns = GFDirectory::get_grid_columns($form_id); $field_ids = array_keys($columns); #$form = RGFormsModel::get_form_meta($form_id); array_push($form["fields"], array("id" => "id", "label" => esc_html__("Entry Id", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "date_created", "label" => esc_html__("Entry Date", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "ip", "label" => esc_html__("User IP", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "source_url", "label" => esc_html__("Source Url", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "payment_status", "label" => esc_html__("Payment Status", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "transaction_id", "label" => esc_html__("Transaction Id", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "payment_amount", "label" => esc_html__("Payment Amount", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "payment_date", "label" => esc_html__("Payment Date", "gravity-forms-addons"))); array_push($form["fields"], array("id" => "created_by", "label" => esc_html__("User", "gravity-forms-addons"))); $form = self::get_selectable_entry_meta($form); ?> <div class="panel-instructions"> <p><?php esc_html_e("Drag & drop to order and select which columns are displayed in the Gravity Forms Directory.", "gravity-forms-addons"); ?> </p> <p><?php echo sprintf(esc_html__("Embed the Directory on a post or a page using %s ", "gravity-forms-addons"), '<code>[directory form="' . $_GET['id'] . '"]</code>'); ?> </p> </div> <div class="clear"></div> <div class="gcolumn_wrapper"> <div class="gcolumn_container_left"> <div class="gform_select_column_heading"><?php esc_html_e("Visible Columns", "gravity-forms-addons"); ?> </div> <ul id="sortable_selected" class="sortable_connected"> <?php foreach ($columns as $field_id => $field_info) { ?> <li id="<?php echo $field_id; ?> "><?php echo esc_html($field_info["label"]); ?> </li> <?php } ?> </ul> </div> <div class="column-arrow-mid"></div> <div class="gcolumn_container_right" id="available_column"> <div class="gform_select_column_heading"> <?php esc_html_e("Hidden Columns", "gravity-forms-addons"); ?> </div> <ul id="sortable_available" class="sortable_connected"> <?php $approvedcolumn = GFDirectory::get_approved_column($form); foreach ($form["fields"] as $field) { if (in_array(RGFormsModel::get_input_type($field), array("checkbox", 'address', 'radio', 'name')) && !in_array($field["id"], $field_ids) && floatval($field['id']) !== floor(floatval($approvedcolumn))) { ?> <li id="<?php echo $field["id"]; ?> "><?php echo esc_html(rgar($field, "label")); ?> </li> <?php } if (is_array(rgar($field, "inputs"))) { foreach ($field["inputs"] as $input) { if (!in_array($input["id"], $field_ids) && !($field["type"] == "creditcard" && in_array($input["id"], array(floatval("{$field["id"]}.2"), floatval("{$field["id"]}.3"))))) { ?> <li id="<?php echo $input["id"]; ?> "><?php echo esc_html(GFDirectory::get_label($field, $input["id"])); ?> <span class="description">(<?php echo esc_html(rgar($field, "label")); ?> )</span></li> <?php } } } else { if (!rgar($field, "displayOnly") && !in_array($field["id"], $field_ids)) { ?> <li id="<?php echo $field["id"]; ?> "><?php echo esc_html($field["label"]); ?> </li> <?php } } } ?> </ul> </div> </div> <div class="panel-buttons"> <input type="button" value="<?php esc_attr_e("Save", "gravity-forms-addons"); ?> " class="button-primary" onclick="SelectColumns();"/> <input type="button" value="<?php esc_html_e("Cancel", "gravity-forms-addons"); ?> " class="button" onclick="self.parent.tb_remove();"/> </div> </div> </body> </html> <?php }
public static function preview_image_value($input_name, $field, $form, $lead) { $field_id = $field['id']; $file_info = RGFormsModel::get_temp_filename($form['id'], $input_name); $source = RGFormsModel::get_upload_url($form['id']) . "/tmp/" . $file_info["temp_filename"]; if (!$file_info) { return ''; } switch (RGFormsModel::get_input_type($field)) { case "post_image": list(, $image_title, $image_caption, $image_description) = explode("|:|", $lead[$field['id']]); $value = !empty($source) ? $source . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : ""; break; case "fileupload": $value = $source; break; } return $value; }
public static function get_form_fields($form_id) { $form = RGFormsModel::get_form_meta($form_id); $fields = array(); //Adding default fields array_push($form["fields"], array("id" => "date_created", "label" => __("Entry Date", "gravityformscampaignmonitor"))); array_push($form["fields"], array("id" => "ip", "label" => __("User IP", "gravityformscampaignmonitor"))); array_push($form["fields"], array("id" => "source_url", "label" => __("Source Url", "gravityformscampaignmonitor"))); if (is_array($form["fields"])) { foreach ($form["fields"] as $field) { if (is_array(rgar($field, "inputs"))) { //If this is a name field, add full name to the list if (RGFormsModel::get_input_type($field) == "name") { $fields[] = array($field["id"], GFCommon::get_label($field) . " (" . __("Full", "gravityformscampaignmonitor") . ")"); } foreach ($field["inputs"] as $input) { $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"])); } } else { if (!rgar($field, "displayOnly")) { $fields[] = array($field["id"], GFCommon::get_label($field)); } } } } return $fields; }
/** * Make validation work for Edit Entry * * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post * fields. This goes through all the fields and if they're an invalid post field, we * set them as valid. If there are still issues, we'll return false. * * @param [type] $validation_results [description] * @return [type] [description] */ function custom_validation($validation_results) { do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results); do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html(print_r($_POST, true))); $gv_valid = true; foreach ($validation_results['form']['fields'] as $key => &$field) { $value = RGFormsModel::get_field_value($field); $field_type = RGFormsModel::get_input_type($field); // Validate always switch ($field_type) { case 'fileupload': // in case nothing is uploaded but there are already files saved if (!empty($field->failed_validation) && !empty($field->isRequired) && !empty($value)) { $field->failed_validation = false; unset($field->validation_message); } // validate if multi file upload reached max number of files [maxFiles] => 2 if (rgar($field, 'maxFiles') && rgar($field, 'multipleFiles')) { $input_name = 'input_' . $field->id; //uploaded $file_names = isset(GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name]) ? GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name] : array(); //existent $entry = $this->get_entry(); $value = NULL; if (isset($entry[$field->id])) { $value = json_decode($entry[$field->id], true); } // count uploaded files and existent entry files $count_files = count($file_names) + count($value); if ($count_files > $field->maxFiles) { $field->validation_message = __('Maximum number of files reached', 'gravityview'); $field->failed_validation = 1; $gv_valid = false; // in case of error make sure the newest upload files are removed from the upload input GFFormsModel::$uploaded_files[$validation_results['form']['id']] = null; } } break; } // This field has failed validation. if (!empty($field->failed_validation)) { do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array('field' => $field, 'value' => $value)); switch ($field_type) { // Captchas don't need to be re-entered. case 'captcha': // Post Image fields aren't editable, so we un-fail them. // Post Image fields aren't editable, so we un-fail them. case 'post_image': $field->failed_validation = false; unset($field->validation_message); break; } // You can't continue inside a switch, so we do it after. if (empty($field->failed_validation)) { continue; } // checks if the No Duplicates option is not validating entry against itself, since // we're editing a stored entry, it would also assume it's a duplicate. if (!empty($field->noDuplicates)) { $entry = $this->get_entry(); // If the value of the entry is the same as the stored value // Then we can assume it's not a duplicate, it's the same. if (!empty($entry) && $value == $entry[$field->id]) { //if value submitted was not changed, then don't validate $field->failed_validation = false; unset($field->validation_message); do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry); continue; } } // if here then probably we are facing the validation 'At least one field must be filled out' if (GFFormDisplay::is_empty($field, $this->form_id) && empty($field->isRequired)) { unset($field->validation_message); $field->validation_message = false; continue; } $gv_valid = false; } } $validation_results['is_valid'] = $gv_valid; do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results); // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) $this->form_after_validation = $validation_results['form']; return $validation_results; }
public static function handle_existing_images_submission($form) { global $_gf_uploaded_files; // get UR config // get all fileupload fields mapped in the UR config // foreach loop through and see if the image has been: // - resubmitted populate the existing image data into the $_gf_uploaded_files // - deleted do nothing // - new image submitted do nothing if (empty($_gf_uploaded_files)) { $_gf_uploaded_files = array(); } $config = GFUserData::get_update_feed($form['id']); if (!$config) { return; } $meta = rgars($config, 'meta/user_meta'); if (function_exists('xprofile_get_field_data')) { $bp_meta = rgars($config, 'meta/buddypress_meta'); if (is_array($bp_meta)) { $bp_meta = array_map(create_function('$a', '$a["is_bp"] = true; return $a;'), $bp_meta); $meta = array_merge($meta, $bp_meta); } } foreach ($meta as $meta_item) { $field = RGFormsModel::get_field($form, $meta_item['meta_value']); $input_name = "input_{$field['id']}"; if (RGFormsModel::get_input_type($field) != 'fileupload') { continue; } if (self::is_prepopulated_file_upload($form['id'], $input_name)) { if (rgar($meta_item, 'is_bp')) { $_gf_uploaded_files[$input_name] = xprofile_get_field_data($meta_item['meta_name'], get_current_user_id()); } else { $_gf_uploaded_files[$input_name] = get_user_meta(get_current_user_id(), $meta_item['meta_name'], true); } } } }
public function submission_values_pre_save($submitted_values, $form) { foreach ($form['fields'] as $field) { if (RGFormsModel::get_input_type($field) == 'signature') { //get field name so the value can be pulled from the post data $input_name = 'input_' . $form['id'] . '_' . str_replace('.', '_', $field['id']); //when adding a new signature the data field will be populated if (!rgempty("{$input_name}_data")) { //new image added, save $filename = $this->save_signature($input_name . '_data'); } else { //existing image edited $filename = rgpost($input_name . '_signature_filename'); } $submitted_values[strval($field['id'])] = $filename; } } return $submitted_values; }
private function cleanup(&$forms) { unset($forms["version"]); //adding checkboxes "inputs" property based on "choices". (they were removed from the export //to provide a cleaner xml format foreach ($forms as &$form) { if (!is_array($form["fields"])) { continue; } foreach ($form["fields"] as &$field) { $input_type = RGFormsModel::get_input_type($field); if (in_array($input_type, array("checkbox", "radio", "select"))) { //creating inputs array for checkboxes if ($input_type == "checkbox" && !isset($field["inputs"])) { $field["inputs"] = array(); } for ($i = 1, $count = sizeof($field["choices"]); $i <= $count; $i++) { if (!RGForms::get("enableChoiceValue", $field)) { $field["choices"][$i - 1]["value"] = $field["choices"][$i - 1]["text"]; } if ($input_type == "checkbox") { $field["inputs"][] = array("id" => $field["id"] . "." . $i, "label" => $field["choices"][$i - 1]["text"]); } } } } } }
public static function is_valid_for_calcuation($field) { $supported_input_types = array('text', 'select', 'number', 'checkbox', 'radio', 'hidden', 'singleproduct', 'price', 'hiddenproduct', 'calculation', 'singleshipping'); $unsupported_field_types = array('category'); $input_type = RGFormsModel::get_input_type($field); return in_array($input_type, $supported_input_types) && !in_array($input_type, $unsupported_field_types); }
private static function get_routing_fields($form, $selected_field_id) { $str = ""; foreach ($form["fields"] as $field) { $input_type = RGFormsModel::get_input_type($field); $field_label = RGFormsModel::get_label($field); if (in_array($input_type, self::$supported_fields)) { $selected = $field["id"] == $selected_field_id ? "selected='selected'" : ""; $str .= "<option value='" . $field["id"] . "' " . $selected . ">" . $field_label . "</option>"; } } return $str; }
/** * Given an entry and a form field id, calculate the entry value for that field. * * @access public * @param array $entry * @param integer $field * @return null|string */ public static function field_value($entry, $field_settings, $format = 'html') { if (empty($entry['form_id']) || empty($field_settings['id'])) { return NULL; } $gravityview_view = GravityView_View::getInstance(); if (class_exists('GFCache')) { /** * Gravity Forms' GFCache function was thrashing the database, causing double the amount of time for the field_value() method to run. * * The reason is that the cache was checking against a field value stored in a transient every time `GFFormsModel::get_lead_field_value()` is called. * * What we're doing here is telling the GFCache that it's already checked the transient and the value is false, forcing it to just use the non-cached data, which is actually faster. * * @hack * @since 1.3 * @param string $cache_key Field Value transient key used by Gravity Forms * @param mixed false Setting the value of the cache to false so that it's not used by Gravity Forms' GFFormsModel::get_lead_field_value() method * @param boolean false Tell Gravity Forms not to store this as a transient * @param int 0 Time to store the value. 0 is maximum amount of time possible. */ GFCache::set("GFFormsModel::get_lead_field_value_" . $entry["id"] . "_" . $field_settings["id"], false, false, 0); } $field_id = $field_settings['id']; $form = $gravityview_view->getForm(); $field = gravityview_get_field($form, $field_id); $field_type = RGFormsModel::get_input_type($field); if ($field_type) { $field_type = $field['type']; $value = RGFormsModel::get_lead_field_value($entry, $field); } else { // For non-integer field types (`id`, `date_created`, etc.) $field_type = $field_id; $field['type'] = $field_id; $value = isset($entry[$field_type]) ? $entry[$field_type] : NULL; } // Prevent any PHP warnings that may be generated ob_start(); $display_value = GFCommon::get_lead_field_display($field, $value, $entry["currency"], false, $format); if ($errors = ob_get_clean()) { do_action('gravityview_log_error', 'GravityView_API[field_value] Errors when calling GFCommon::get_lead_field_display()', $errors); } $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $entry, $form); // prevent the use of merge_tags for non-admin fields if (!empty($field['adminOnly'])) { $display_value = self::replace_variables($display_value, $form, $entry); } // Check whether the field exists in /includes/fields/{$field_type}.php // This can be overridden by user template files. $field_exists = $gravityview_view->locate_template("fields/{$field_type}.php"); // Set the field data to be available in the templates $gravityview_view->setCurrentField(array('form' => $form, 'field_id' => $field_id, 'field' => $field, 'field_settings' => $field_settings, 'value' => $value, 'display_value' => $display_value, 'format' => $format, 'entry' => $entry, 'field_type' => $field_type)); if ($field_exists) { do_action('gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_exists)); ob_start(); load_template($field_exists, false); $output = ob_get_clean(); } else { // Backup; the field template doesn't exist. $output = $display_value; } $field_settings = $gravityview_view->getCurrentField('field_settings'); /** * Link to the single entry by wrapping the output in an anchor tag * * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example. * */ if (!empty($field_settings['show_as_link'])) { $output = self::entry_link_html($entry, $output, array(), $field_settings); } /** * @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number` * @since 1.6 * @param string $output HTML value output * @param array $entry The GF entry array * @param array $field_settings Settings for the particular GV field */ $output = apply_filters('gravityview_field_entry_value_' . $field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField()); /** * @filter `gravityview_field_entry_value` Modify the field value output for all field types * @param string $output HTML value output * @param array $entry The GF entry array * @param array $field_settings Settings for the particular GV field * @param array $field_data {@since 1.6} */ $output = apply_filters('gravityview_field_entry_value', $output, $entry, $field_settings, $gravityview_view->getCurrentField()); return $output; }
private static function cleanup(&$forms) { unset($forms['version']); //adding checkboxes 'inputs' property based on 'choices'. (they were removed from the export //to provide a cleaner xml format foreach ($forms as &$form) { if (!is_array($form['fields'])) { continue; } $form = GFFormsModel::convert_field_objects($form); foreach ($form['fields'] as &$field) { $input_type = RGFormsModel::get_input_type($field); if (in_array($input_type, array('checkbox', 'radio', 'select', 'multiselect'))) { //creating inputs array for checkboxes if ($input_type == 'checkbox' && !isset($field->inputs)) { $field->inputs = array(); } $adjust_by = 0; for ($i = 1, $count = sizeof($field->choices); $i <= $count; $i++) { if (!$field->enableChoiceValue) { $field->choices[$i - 1]['value'] = $field->choices[$i - 1]['text']; } if ($input_type == 'checkbox') { if (($i + $adjust_by) % 10 == 0) { $adjust_by++; } $id = $i + $adjust_by; $field->inputs[] = array('id' => $field->id . '.' . $id, 'label' => $field->choices[$i - 1]['text']); } } } } } }
private static function get_routing_fields($form, $selected_field_id) { $str = ''; foreach ($form['fields'] as $field) { $input_type = RGFormsModel::get_input_type($field); $field_label = RGFormsModel::get_label($field); if (in_array($input_type, self::get_routing_field_types())) { $selected = $field->id == $selected_field_id ? "selected='selected'" : ''; $str .= "<option value='" . $field->id . "' " . $selected . '>' . $field_label . '</option>'; } } return $str; }
public static function get_field_content($field, $value = "", $force_frontend_label = false, $form_id = 0) { $id = $field["id"]; $size = rgar($field, "size"); $validation_message = rgget("failed_validation", $field) && !empty($field["validation_message"]) ? sprintf("<div class='gfield_description validation_message'>%s</div>", $field["validation_message"]) : ""; $duplicate_disabled = array('captcha', 'post_title', 'post_content', 'post_excerpt', 'total', 'shipping', 'creditcard'); $duplicate_field_link = !in_array($field['type'], $duplicate_disabled) ? "<a class='field_duplicate_icon' id='gfield_duplicate_{$id}' title='" . __("click to duplicate this field", "gravityforms") . "' href='#' onclick='StartDuplicateField(this); return false;'>" . __("Duplicate", "gravityforms") . "</a>" : ""; $duplicate_field_link = apply_filters("gform_duplicate_field_link", $duplicate_field_link); $delete_field_link = "<a class='field_delete_icon' id='gfield_delete_{$id}' title='" . __("click to delete this field", "gravityforms") . "' href='#' onclick='StartDeleteField(this); return false;'>" . __("Delete", "gravityforms") . "</a>"; $delete_field_link = apply_filters("gform_delete_field_link", $delete_field_link); $field_type_title = GFCommon::get_field_type_title($field["type"]); $admin_buttons = IS_ADMIN ? "<div class='gfield_admin_icons'><div class='gfield_admin_header_title'>{$field_type_title} : " . __("Field ID", "gravityforms") . " {$field["id"]}</div>" . $delete_field_link . $duplicate_field_link . "<a class='field_edit_icon edit_icon_collapsed' title='" . __("click to edit this field", "gravityforms") . "'>" . __("Edit", "gravityforms") . "</a></div>" : ""; $field_label = $force_frontend_label ? $field["label"] : GFCommon::get_label($field); if (rgar($field, "inputType") == "singleproduct" && !rgempty($field["id"] . ".1", $value)) { $field_label = rgar($value, $field["id"] . ".1"); } $field_id = IS_ADMIN || $form_id == 0 ? "input_{$id}" : "input_" . $form_id . "_{$id}"; $required_div = IS_ADMIN || rgar($field, "isRequired") ? sprintf("<span class='gfield_required'>%s</span>", $field["isRequired"] ? "*" : "") : ""; $target_input_id = ""; $is_description_above = rgar($field, "descriptionPlacement") == "above"; switch (RGFormsModel::get_input_type($field)) { case "section": $description = self::get_description(rgget("description", $field), "gsection_description"); $field_content = sprintf("%s<h2 class='gsection_title'>%s</h2>%s", $admin_buttons, esc_html($field_label), $description); break; case "page": //only executed on the form editor in the admin $page_label = __("Page Break", "gravityforms"); $src = GFCommon::get_base_url() . "/images/gf_pagebreak_inline.png"; $field_content = "{$admin_buttons} <label class='gfield_label'> </label><img src='{$src}' alt='{$page_label}' title='{$page_label}' />"; break; case "adminonly_hidden": case "hidden": case "html": $field_content = !IS_ADMIN ? "{FIELD}" : ($field_content = sprintf("%s<label class='gfield_label' for='%s'>%s</label>{FIELD}", $admin_buttons, $field_id, esc_html($field_label))); break; case "checkbox": case "radio": $description = self::get_description(rgget("description", $field), "gfield_description"); if ($is_description_above) { $field_content = sprintf("%s<label class='gfield_label'>%s%s</label>%s{FIELD}%s", $admin_buttons, esc_html($field_label), $required_div, $description, $validation_message); } else { $field_content = sprintf("%s<label class='gfield_label'>%s%s</label>{FIELD}%s%s", $admin_buttons, esc_html($field_label), $required_div, $description, $validation_message); } break; case "name": switch (rgar($field, "nameFormat")) { case "simple": $target_input_id = $field_id; break; case "extended": $target_input_id = $field_id . "_2"; break; default: $target_input_id = $field_id . "_3"; } case "address": if (empty($target_input_id)) { $target_input_id = $field_id . "_1"; } default: if (empty($target_input_id)) { $target_input_id = $field_id; } $description = self::get_description(rgget("description", $field), "gfield_description"); if ($is_description_above) { $field_content = sprintf("%s<label class='gfield_label' for='%s'>%s%s</label>%s{FIELD}%s", $admin_buttons, $target_input_id, esc_html($field_label), $required_div, $description, $validation_message); } else { $field_content = sprintf("%s<label class='gfield_label' for='%s'>%s%s</label>{FIELD}%s%s", $admin_buttons, $target_input_id, esc_html($field_label), $required_div, $description, $validation_message); } break; } if (RGFormsModel::get_input_type($field) == "creditcard" && !GFCommon::is_ssl() && !IS_ADMIN) { $field_content = "<div class='gfield_creditcard_warning_message'>" . __("This page is unsecured. Do not enter a real credit card number. Use this field only for testing purposes. ", "gravityforms") . "</div>" . $field_content; } $value = self::default_if_empty($field, $value); $field_content = str_replace("{FIELD}", GFCommon::get_field_input($field, $value, 0, $form_id), $field_content); $field_content = apply_filters("gform_field_content", $field_content, $field, $value, 0, $form_id); return $field_content; }
function should_field_be_validated($form, $field) { if ($field['pageNumber'] != GFFormDisplay::get_source_page($form['id'])) { return false; } // if no limits provided for this field if (!$this->get_field_limits($field['id'])) { return false; } // or if this field is not a checkbox if (RGFormsModel::get_input_type($field) != 'checkbox') { return false; } // or if this field is hidden if (RGFormsModel::is_field_hidden($form, $field, array())) { return false; } return true; }
public static function lead_detail_grid($form, $lead, $allow_display_empty_fields = false) { $form_id = absint($form['id']); $display_empty_fields = false; if ($allow_display_empty_fields) { $display_empty_fields = rgget('gf_display_empty_fields', $_COOKIE); } $display_empty_fields = apply_filters('gform_entry_detail_grid_display_empty_fields', $display_empty_fields, $form, $lead); ?> <table cellspacing="0" class="widefat fixed entry-detail-view"> <thead> <tr> <th id="details"> <?php $title = sprintf('%s : %s %s', esc_html($form['title']), esc_html__('Entry # ', 'gravityforms'), absint($lead['id'])); echo apply_filters('gravityflow_title_entry_detail', $title, $form, $lead); ?> </th> <th style="width:140px; font-size:10px; text-align: right;"> <?php if ($allow_display_empty_fields) { ?> <input type="checkbox" id="gentry_display_empty_fields" <?php echo $display_empty_fields ? "checked='checked'" : ''; ?> onclick="ToggleShowEmptyFields();" /> <label for="gentry_display_empty_fields"><?php esc_html_e('show empty fields', 'gravityforms'); ?> </label> <?php } ?> </th> </tr> </thead> <tbody> <?php $count = 0; $field_count = sizeof($form['fields']); $has_product_fields = false; foreach ($form['fields'] as $field) { switch (RGFormsModel::get_input_type($field)) { case 'section': if (!GFCommon::is_section_empty($field, $form, $lead) || $display_empty_fields) { $count++; $is_last = $count >= $field_count ? true : false; ?> <tr> <td colspan="2" class="entry-view-section-break<?php echo $is_last ? ' lastrow' : ''; ?> "><?php echo esc_html(GFCommon::get_label($field)); ?> </td> </tr> <?php } break; case 'captcha': case 'html': case 'password': case 'page': //ignore captcha, html, password, page field break; default: //ignore product fields as they will be grouped together at the end of the grid if (GFCommon::is_product_field($field->type)) { $has_product_fields = true; continue; } $value = RGFormsModel::get_lead_field_value($lead, $field); $display_value = GFCommon::get_lead_field_display($field, $value, $lead['currency']); $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $lead, $form); if ($display_empty_fields || !empty($display_value) || $display_value === '0') { $count++; $is_last = $count >= $field_count && !$has_product_fields ? true : false; $last_row = $is_last ? ' lastrow' : ''; $display_value = empty($display_value) && $display_value !== '0' ? ' ' : $display_value; $content = ' <tr> <td colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</td> </tr> <tr> <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td> </tr>'; $content = apply_filters('gform_field_content', $content, $field, $value, $lead['id'], $form['id']); echo $content; } break; } } $products = array(); if ($has_product_fields) { $products = GFCommon::get_product_fields($form, $lead); if (!empty($products['products'])) { ?> <tr> <td colspan="2" class="entry-view-field-name"><?php echo esc_html(apply_filters("gform_order_label_{$form_id}", apply_filters('gform_order_label', __('Order', 'gravityforms'), $form_id), $form_id)); ?> </td> </tr> <tr> <td colspan="2" class="entry-view-field-value lastrow"> <table class="entry-products" cellspacing="0" width="97%"> <colgroup> <col class="entry-products-col1" /> <col class="entry-products-col2" /> <col class="entry-products-col3" /> <col class="entry-products-col4" /> </colgroup> <thead> <th scope="col"><?php echo apply_filters("gform_product_{$form_id}", apply_filters('gform_product', __('Product', 'gravityforms'), $form_id), $form_id); ?> </th> <th scope="col" class="textcenter"><?php echo esc_html(apply_filters("gform_product_qty_{$form_id}", apply_filters('gform_product_qty', __('Qty', 'gravityforms'), $form_id), $form_id)); ?> </th> <th scope="col"><?php echo esc_html(apply_filters("gform_product_unitprice_{$form_id}", apply_filters('gform_product_unitprice', __('Unit Price', 'gravityforms'), $form_id), $form_id)); ?> </th> <th scope="col"><?php echo esc_html(apply_filters("gform_product_price_{$form_id}", apply_filters('gform_product_price', __('Price', 'gravityforms'), $form_id), $form_id)); ?> </th> </thead> <tbody> <?php $total = 0; foreach ($products['products'] as $product) { ?> <tr> <td> <div class="product_name"><?php echo esc_html($product['name']); ?> </div> <ul class="product_options"> <?php $price = GFCommon::to_number($product['price']); if (is_array(rgar($product, 'options'))) { $count = sizeof($product['options']); $index = 1; foreach ($product['options'] as $option) { $price += GFCommon::to_number($option['price']); $class = $index == $count ? " class='lastitem'" : ''; $index++; ?> <li<?php echo $class; ?> ><?php echo $option['option_label']; ?> </li> <?php } } $subtotal = floatval($product['quantity']) * $price; $total += $subtotal; ?> </ul> </td> <td class="textcenter"><?php echo esc_html($product['quantity']); ?> </td> <td><?php echo GFCommon::to_money($price, $lead['currency']); ?> </td> <td><?php echo GFCommon::to_money($subtotal, $lead['currency']); ?> </td> </tr> <?php } $total += floatval($products['shipping']['price']); ?> </tbody> <tfoot> <?php if (!empty($products['shipping']['name'])) { ?> <tr> <td colspan="2" rowspan="2" class="emptycell"> </td> <td class="textright shipping"><?php echo esc_html($products['shipping']['name']); ?> </td> <td class="shipping_amount"><?php echo GFCommon::to_money($products['shipping']['price'], $lead['currency']); ?> </td> </tr> <?php } ?> <tr> <?php if (empty($products['shipping']['name'])) { ?> <td colspan="2" class="emptycell"> </td> <?php } ?> <td class="textright grandtotal"><?php esc_html_e('Total', 'gravityforms'); ?> </td> <td class="grandtotal_amount"><?php echo GFCommon::to_money($total, $lead['currency']); ?> </td> </tr> </tfoot> </table> </td> </tr> <?php } } ?> </tbody> </table> <?php }
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; }