/**
  * Add pending referral
  *
  * @access public
  * @uses GFFormsModel::get_lead()
  * @uses GFCommon::get_product_fields()
  * @uses GFCommon::to_number()
  *
  * @param array $entry
  * @param array $form
  */
 public function add_pending_referral($entry, $form)
 {
     if (!$this->was_referred() || !rgar($form, 'affwp_allow_referrals')) {
         return;
     }
     // Do some craziness to determine the price (this should be easy but is not)
     $desc = isset($form['title']) ? $form['title'] : '';
     $entry = GFFormsModel::get_lead($entry['id']);
     $products = GFCommon::get_product_fields($form, $entry);
     $total = 0;
     foreach ($products['products'] as $key => $product) {
         $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']);
             }
         }
         $subtotal = floatval($product['quantity']) * $price;
         $total += $subtotal;
     }
     // replace description if there are products
     if (!empty($products['products'])) {
         $product_names = wp_list_pluck($products['products'], 'name');
         $desc = implode(', ', $product_names);
     }
     $total += floatval($products['shipping']['price']);
     $referral_total = $this->calculate_referral_amount($total, $entry['id']);
     $this->insert_pending_referral($referral_total, $entry['id'], $desc);
     if (empty($total)) {
         $this->mark_referral_complete($entry, array());
     }
 }
 /**
  * Add pending referral
  *
  * @access public
  * @uses GFFormsModel::get_lead()
  * @uses GFCommon::get_product_fields()
  * @uses GFCommon::to_number()
  *
  * @param array $entry
  * @param array $form
  */
 public function add_pending_referral($entry, $form)
 {
     if ($this->was_referred()) {
         // Do some craziness to determine the price (this should be easy but is not)
         $desc = '';
         $entry = GFFormsModel::get_lead($entry['id']);
         $products = GFCommon::get_product_fields($form, $entry);
         $total = 0;
         foreach ($products['products'] as $key => $product) {
             $desc .= $product['name'];
             if ($key + 1 < count($products)) {
                 $description .= ', ';
             }
             $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']);
                 }
             }
             $subtotal = floatval($product['quantity']) * $price;
             $total += $subtotal;
         }
         $total += floatval($products['shipping']['price']);
         $referral_total = $this->calculate_referral_amount($total, $entry['id']);
         $this->insert_pending_referral($referral_total, $entry['id'], $desc);
     }
 }
 public function validate($value, $form)
 {
     if (!class_exists('RGCurrency')) {
         require_once GFCommon::get_base_path() . '/currency.php';
     }
     $price = GFCommon::to_number($value);
     if (!rgblank($value) && ($price === false || $price < 0)) {
         $this->failed_validation = true;
         $this->validation_message = empty($this->errorMessage) ? __('Please enter a valid amount.', 'gravityforms') : $this->errorMessage;
     }
 }
 /**
  * Product amount filter - this will deduct any field named 'Tax' (case-insensitive) from the $amount.
  * 
  * @param float $amount
  * @param array $products
  * @param array $entry
  * @return float
  */
 public static function affiliates_gravity_forms_products_amount($amount, $products, $entry)
 {
     if (isset($products['products']) && is_array($products['products'])) {
         foreach ($products['products'] as $id => $values) {
             if (isset($values['name']) && isset($values['price']) && in_array(strtolower($values['name']), array_map('strtolower', self::$tax_fields))) {
                 if (class_exists('GFCommon') && method_exists('GFCommon', 'to_number')) {
                     $tax = GFCommon::to_number($values['price']);
                     $amount -= floatval($tax);
                 }
             }
         }
     }
     return $amount;
 }
 public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format)
 {
     $format_numeric = $modifier == 'price';
     $value = $format_numeric ? GFCommon::to_number($value) : GFCommon::to_money($value);
     return GFCommon::format_variable_value($value, $url_encode, $esc_html, $format);
 }
 public function sanitize_settings()
 {
     parent::sanitize_settings();
     $price_number = GFCommon::to_number($this->basePrice);
     $this->basePrice = GFCommon::to_money($price_number);
 }
 private static function get_conditional_logic($form, $field_values = array())
 {
     $logics = "";
     $dependents = "";
     $fields_with_logic = array();
     $default_values = array();
     foreach ($form["fields"] as $field) {
         //use section's logic if one exists
         $section = RGFormsModel::get_section($form, $field["id"]);
         $section_logic = !empty($section) ? rgar($section, "conditionalLogic") : null;
         $field_logic = $field["type"] != "page" ? RGForms::get("conditionalLogic", $field) : null;
         //page break conditional logic will be handled during the next button click
         $next_button_logic = isset($field["nextButton"]) && isset($field["nextButton"]["conditionalLogic"]) ? $field["nextButton"]["conditionalLogic"] : null;
         if (!empty($field_logic) || !empty($next_button_logic)) {
             $field_section_logic = array("field" => $field_logic, "nextButton" => $next_button_logic, "section" => $section_logic);
             $logics .= $field["id"] . ": " . GFCommon::json_encode($field_section_logic) . ",";
             $fields_with_logic[] = $field["id"];
             $peers = $field["type"] == "section" ? GFCommon::get_section_fields($form, $field["id"]) : array($field);
             $peer_ids = array();
             foreach ($peers as $peer) {
                 $peer_ids[] = $peer["id"];
             }
             $dependents .= $field["id"] . ": " . GFCommon::json_encode($peer_ids) . ",";
         }
         //-- Saving default values so that they can be restored when toggling conditional logic ---
         $field_val = "";
         $input_type = RGFormsModel::get_input_type($field);
         //get parameter value if pre-populate is enabled
         if (rgar($field, "allowsPrepopulate")) {
             if (is_array(rgar($field, "inputs"))) {
                 $field_val = array();
                 foreach ($field["inputs"] as $input) {
                     $field_val["input_{$input["id"]}"] = RGFormsModel::get_parameter_value(rgar($input, "name"), $field, $field_values);
                 }
             } else {
                 if ($input_type == "time") {
                     $parameter_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field, $field_values);
                     if (!empty($parameter_val) && preg_match('/^(\\d*):(\\d*) ?(.*)$/', $parameter_val, $matches)) {
                         $field_val = array();
                         $field_val[] = esc_attr($matches[1]);
                         //hour
                         $field_val[] = esc_attr($matches[2]);
                         //minute
                         $field_val[] = rgar($matches, 3);
                         //am or pm
                     }
                 } else {
                     if ($input_type == "list") {
                         $parameter_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field, $field_values);
                         $field_val = explode(",", str_replace("|", ",", $parameter_val));
                     } else {
                         $field_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field, $field_values);
                     }
                 }
             }
         }
         //use default value if pre-populated value is empty
         $field_val = self::default_if_empty($field, $field_val);
         if (is_array(rgar($field, "choices")) && $input_type != "list") {
             //radio buttons start at 0 and checkboxes start at 1
             $choice_index = $input_type == "radio" ? 0 : 1;
             foreach ($field["choices"] as $choice) {
                 if (rgar($choice, "isSelected") && $input_type == "select") {
                     $val = isset($choice["price"]) ? $choice["value"] . "|" . GFCommon::to_number($choice["price"]) : $choice["value"];
                     $default_values[$field["id"]] = $val;
                 } else {
                     if (rgar($choice, "isSelected")) {
                         if (!isset($default_values[$field["id"]])) {
                             $default_values[$field["id"]] = array();
                         }
                         $default_values[$field["id"]][] = "choice_{$field["id"]}_{$choice_index}";
                     }
                 }
                 $choice_index++;
             }
         } else {
             if (!empty($field_val)) {
                 $default_values[$field["id"]] = $field_val;
             }
         }
     }
     $button_conditional_script = "";
     //adding form button conditional logic if enabled
     if (isset($form["button"]["conditionalLogic"])) {
         $logics .= "0: " . GFCommon::json_encode(array("field" => $form["button"]["conditionalLogic"], "section" => null)) . ",";
         $dependents .= "0: " . GFCommon::json_encode(array(0)) . ",";
         $fields_with_logic[] = 0;
         $button_conditional_script = "jQuery('#gform_{$form['id']}').submit(" . "function(event, isButtonPress){" . "    var visibleButton = jQuery('.gform_next_button:visible, .gform_button:visible, .gform_image_button:visible');" . "    return visibleButton.length > 0 || isButtonPress == true;" . "}" . ");";
     }
     if (!empty($logics)) {
         $logics = substr($logics, 0, strlen($logics) - 1);
     }
     //removing last comma;
     if (!empty($dependents)) {
         $dependents = substr($dependents, 0, strlen($dependents) - 1);
     }
     //removing last comma;
     $animation = rgar($form, "enableAnimation") ? "1" : "0";
     global $wp_locale;
     $number_format = $wp_locale->number_format['decimal_point'] == "," ? "decimal_comma" : "decimal_dot";
     $str = "if(window['jQuery']){" . "if(!window['gf_form_conditional_logic'])" . "window['gf_form_conditional_logic'] = new Array();" . "window['gf_form_conditional_logic'][{$form['id']}] = {'logic' : {" . $logics . " }, 'dependents' : {" . $dependents . " }, 'animation' : " . $animation . " , 'defaults' : " . json_encode($default_values) . " }; " . "if(!window['gf_number_format'])" . "window['gf_number_format'] = '" . $number_format . "';" . "jQuery(document).ready(function(){" . "gf_apply_rules({$form['id']}, " . json_encode($fields_with_logic) . ", true);" . "jQuery('#gform_wrapper_{$form['id']}').show();" . "jQuery(document).trigger('gform_post_conditional_logic', [{$form['id']}, null, true]);" . $button_conditional_script . "} );" . "} ";
     return $str;
 }
Beispiel #8
0
 /**
  * Sanitize the field choices property.
  *
  * @param array|null $choices The field choices property.
  *
  * @return array|null
  */
 public function sanitize_settings_choices($choices = null)
 {
     if (is_null($choices)) {
         $choices =& $this->choices;
     }
     if (!is_array($choices)) {
         return $choices;
     }
     $allowed_tags = wp_kses_allowed_html('post');
     foreach ($choices as &$choice) {
         if (isset($choice['isSelected'])) {
             $choice['isSelected'] = (bool) $choice['isSelected'];
         }
         if (isset($choice['price']) && !empty($choice['price'])) {
             $price_number = GFCommon::to_number($choice['price']);
             $choice['price'] = GFCommon::to_money($price_number);
         }
         if (isset($choice['text'])) {
             $choice['text'] = wp_kses($choice['text'], $allowed_tags);
         }
         if (isset($choice['value'])) {
             $choice['value'] = wp_kses($choice['value'], $allowed_tags);
         }
     }
     return $choices;
 }
 public static function get_paypal_payment_amount($form, $entry, $paypal_config)
 {
     //TODO: need to support old "paypal_config" format as well as new format when delayed payment suported feed addons are released
     $products = GFCommon::get_product_fields($form, $entry, true);
     $recurring_field = rgar($paypal_config['meta'], 'recurring_amount_field');
     $total = 0;
     foreach ($products['products'] as $id => $product) {
         if ($paypal_config['meta']['type'] != 'subscription' || $recurring_field == $id || $recurring_field == 'all') {
             $price = GFCommon::to_number($product['price']);
             if (is_array(rgar($product, 'options'))) {
                 foreach ($product['options'] as $option) {
                     $price += GFCommon::to_number($option['price']);
                 }
             }
             $total += $price * $product['quantity'];
         }
     }
     if ($recurring_field == 'all' && !empty($products['shipping']['price'])) {
         $total += floatval($products['shipping']['price']);
     }
     return $total;
 }
 /**
  * Push the Google Analytics Event!
  * 
  * @since 1.4.0
  * @param array $event Gravity Forms event object
  * @param array $form Gravity Forms form object
  */
 private function push_event($entry, $form, $ga_event_data)
 {
     // Init tracking object
     $this->tracking = new \Racecore\GATracking\GATracking(apply_filters('gform_ua_id', $this->ua_id, $form), true);
     $event = new \Racecore\GATracking\Tracking\Event();
     // Set some defaults
     $event->setDocumentLocation($ga_event_data['document_location']);
     $event->setDocumentTitle($ga_event_data['document_title']);
     // Set our event object variables
     $event->setEventCategory(apply_filters('gform_event_category', $ga_event_data['gaEventCategory'], $form));
     $event->setEventAction(apply_filters('gform_event_action', $ga_event_data['gaEventAction'], $form));
     $event->setEventLabel(apply_filters('gform_event_label', $ga_event_data['gaEventLabel'], $form));
     if ($event_value = apply_filters('gform_event_value', $ga_event_data['gaEventValue'], $form)) {
         // Event value must be a valid float!
         $event_value = GFCommon::to_number($event_value);
         $event->setEventValue($event_value);
     }
     // Pppp Push it!
     $this->tracking->addTracking($event);
     try {
         $this->tracking->send();
     } catch (Exception $e) {
         error_log($e->getMessage() . ' in ' . get_class($e));
     }
 }
Beispiel #11
0
 /**
  * Sanitize the field choices property.
  *
  * @param array|null $choices The field choices property.
  *
  * @return array|null
  */
 public function sanitize_settings_choices($choices = null)
 {
     if (is_null($choices)) {
         $choices =& $this->choices;
     }
     if (!is_array($choices)) {
         return $choices;
     }
     foreach ($choices as &$choice) {
         if (isset($choice['isSelected'])) {
             $choice['isSelected'] = (bool) $choice['isSelected'];
         }
         if (isset($choice['price']) && !empty($choice['price'])) {
             $price_number = GFCommon::to_number($choice['price']);
             $choice['price'] = GFCommon::to_money($price_number);
         }
         if (isset($choice['text'])) {
             $choice['text'] = $this->maybe_wp_kses($choice['text']);
         }
         if (isset($choice['value'])) {
             // Strip scripts but don't encode
             $allowed_protocols = wp_allowed_protocols();
             $choice['value'] = wp_kses_no_null($choice['value'], array('slash_zero' => 'keep'));
             $choice['value'] = wp_kses_hook($choice['value'], 'post', $allowed_protocols);
             $choice['value'] = wp_kses_split($choice['value'], 'post', $allowed_protocols);
         }
     }
     return $choices;
 }
Beispiel #12
0
 public static function get_payment_amount($form, $entry, $paypal_config)
 {
     $products = GFCommon::get_product_fields($form, $entry, true);
     $recurring_field = rgar($paypal_config["meta"], "recurring_amount_field");
     $total = 0;
     foreach ($products["products"] as $id => $product) {
         if ($paypal_config["meta"]["type"] != "subscription" || $recurring_field == $id || $recurring_field == "all") {
             $price = GFCommon::to_number($product["price"]);
             if (is_array(rgar($product, "options"))) {
                 foreach ($product["options"] as $option) {
                     $price += GFCommon::to_number($option["price"]);
                 }
             }
             $total += $price * $product['quantity'];
         }
     }
     if ($recurring_field == "all" && !empty($products["shipping"]["price"])) {
         $total += floatval($products["shipping"]["price"]);
     }
     return $total;
 }
 public function clean_number($value)
 {
     if ($this->numberFormat == 'currency') {
         return GFCommon::to_number($value);
     } else {
         return GFCommon::clean_number($value, $this->numberFormat);
     }
 }
 public static function get_calculation_value($field_id, $form, $lead)
 {
     $filters = array('price', 'value', '');
     $value = false;
     foreach ($filters as $filter) {
         if (is_numeric($value)) {
             //value found, exit loop
             break;
         }
         $value = GFCommon::to_number(GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead));
     }
     if (!$value || !is_numeric($value)) {
         GFCommon::log_debug("GFCommon::get_calculation_value(): No value or non-numeric value available for field #{$field_id}. Returning zero instead.");
         $value = 0;
     }
     return $value;
 }
 public static function get_select_choices($field, $value = '', $support_placeholders = true)
 {
     $choices = '';
     if (RG_CURRENT_VIEW == 'entry' && empty($value) && empty($field->placeholder)) {
         $choices .= "<option value=''></option>";
     }
     if (is_array($field->choices)) {
         if ($support_placeholders && !empty($field->placeholder)) {
             $selected = empty($value) ? "selected='selected'" : '';
             $choices .= sprintf("<option value='' %s class='gf_placeholder'>%s</option>", $selected, esc_html($field->placeholder));
         }
         foreach ($field->choices as $choice) {
             //needed for users upgrading from 1.0
             $field_value = !empty($choice['value']) || $field->enableChoiceValue || $field->type == 'post_category' ? $choice['value'] : $choice['text'];
             if ($field->enablePrice) {
                 $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                 $field_value .= '|' . $price;
             }
             if (!isset($_GET['gf_token']) && empty($_POST) && rgblank($value) && RG_CURRENT_VIEW != 'entry') {
                 $selected = rgar($choice, 'isSelected') ? "selected='selected'" : '';
             } else {
                 if (is_array($value)) {
                     $is_match = false;
                     foreach ($value as $item) {
                         if (RGFormsModel::choice_value_match($field, $choice, $item)) {
                             $is_match = true;
                             break;
                         }
                     }
                     $selected = $is_match ? "selected='selected'" : '';
                 } else {
                     $selected = RGFormsModel::choice_value_match($field, $choice, $value) ? "selected='selected'" : '';
                 }
             }
             $choice_markup = sprintf("<option value='%s' %s>%s</option>", esc_attr($field_value), $selected, esc_html($choice['text']));
             $choices .= gf_apply_filters(array('gform_field_choice_markup_pre_render', $field->formId, $field->id), $choice_markup, $choice, $field, $value);
         }
     }
     return $choices;
 }
Beispiel #16
0
 public static function get_calculation_value($field_id, $form, $lead)
 {
     $filters = array('price', 'value', '');
     do {
         $filter = isset($filter) ? next($filters) : reset($filters);
         $value = GFCommon::to_number(GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead));
     } while (!is_numeric($value) && $filter !== false);
     if (!$value || !is_numeric($value)) {
         $value = 0;
     }
     return $value;
 }
 /**
  * extract the shipping amount from a shipping field
  * @return float
  */
 private static function getShipping($form, $field)
 {
     $shipping = 0;
     $id = $field['id'];
     if (!GFFormsModel::is_field_hidden($form, $field, array())) {
         $value = rgpost("input_{$id}");
         if (!empty($value) && $field["inputType"] != 'singleshipping') {
             // drop-down list / radio buttons
             list($name, $value) = rgexplode('|', $value, 2);
         }
         $shipping = GFCommon::to_number($value);
     }
     return $shipping;
 }
 public static function failed_state_validation($form_id, $field, $value)
 {
     global $_gf_state;
     //if field can be populated dynamically, disable state validation
     if (rgar($field, "allowsPrepopulate")) {
         return false;
     } else {
         if (!GFCommon::is_product_field($field["type"] && $field["type"] != "donation")) {
             return false;
         } else {
             if (!in_array($field["inputType"], array("singleshipping", "singleproduct", "hiddenproduct", "checkbox", "radio", "select"))) {
                 return false;
             }
         }
     }
     if (!isset($_gf_state)) {
         $state = unserialize(base64_decode($_POST["state_{$form_id}"]));
         if (!$state || sizeof($state) != 2) {
             return true;
         }
         //making sure state wasn't tampered with by validating checksum
         $checksum = wp_hash(crc32($state[0]));
         if ($checksum != $state[1]) {
             return true;
         }
         $_gf_state = unserialize($state[0]);
     }
     if (!is_array($value)) {
         $value = array($field["id"] => $value);
     }
     foreach ($value as $key => $input_value) {
         $state = isset($_gf_state[$key]) ? $_gf_state[$key] : false;
         //converting price to a number for single product fields and single shipping fields
         if (in_array($field["inputType"], array("singleproduct", "hiddenproduct")) && $key == $field["id"] . ".2" || $field["inputType"] == "singleshipping") {
             $input_value = GFCommon::to_number($input_value);
         }
         $hash = wp_hash($input_value);
         if (strlen($input_value) > 0 && $state !== false && (is_array($state) && !in_array($hash, $state) || !is_array($state) && $hash != $state)) {
             return true;
         }
     }
     return false;
 }
 protected function get_order_data($feed, $form, $entry)
 {
     $products = GFCommon::get_product_fields($form, $entry);
     $payment_field = $feed['meta']['transactionType'] == 'product' ? rgars($feed, 'meta/paymentAmount') : rgars($feed, 'meta/recurringAmount');
     $setup_fee_field = rgar($feed['meta'], 'setupFee_enabled') ? $feed['meta']['setupFee_product'] : false;
     $trial_field = rgar($feed['meta'], 'trial_enabled') ? rgars($feed, 'meta/trial_product') : false;
     $amount = 0;
     $line_items = array();
     $discounts = array();
     $fee_amount = 0;
     $trial_amount = 0;
     foreach ($products['products'] as $field_id => $product) {
         $quantity = $product['quantity'] ? $product['quantity'] : 1;
         $product_price = GFCommon::to_number($product['price'], $entry['currency']);
         $options = array();
         if (is_array(rgar($product, 'options'))) {
             foreach ($product['options'] as $option) {
                 $options[] = $option['option_name'];
                 $product_price += $option['price'];
             }
         }
         $is_trial_or_setup_fee = false;
         if (!empty($trial_field) && $trial_field == $field_id) {
             $trial_amount = $product_price * $quantity;
             $is_trial_or_setup_fee = true;
         } elseif (!empty($setup_fee_field) && $setup_fee_field == $field_id) {
             $fee_amount = $product_price * $quantity;
             $is_trial_or_setup_fee = true;
         }
         //Do not add to line items if the payment field selected in the feed is not the current field.
         if (is_numeric($payment_field) && $payment_field != $field_id) {
             continue;
         }
         //Do not add to line items if the payment field is set to "Form Total" and the current field was used for trial or setup fee.
         if ($is_trial_or_setup_fee && !is_numeric($payment_field)) {
             continue;
         }
         $amount += $product_price * $quantity;
         $description = '';
         if (!empty($options)) {
             $description = esc_html__('options: ', 'gravityforms') . ' ' . implode(', ', $options);
         }
         if ($product_price >= 0) {
             $line_items[] = array('id' => $field_id, 'name' => $product['name'], 'description' => $description, 'quantity' => $quantity, 'unit_price' => GFCommon::to_number($product_price, $entry['currency']), 'options' => rgar($product, 'options'));
         } else {
             $discounts[] = array('id' => $field_id, 'name' => $product['name'], 'description' => $description, 'quantity' => $quantity, 'unit_price' => GFCommon::to_number($product_price, $entry['currency']), 'options' => rgar($product, 'options'));
         }
     }
     if ($trial_field == 'enter_amount') {
         $trial_amount = rgar($feed['meta'], 'trial_amount') ? GFCommon::to_number(rgar($feed['meta'], 'trial_amount'), $entry['currency']) : 0;
     }
     if (!empty($products['shipping']['name']) && !is_numeric($payment_field)) {
         $line_items[] = array('id' => $products['shipping']['id'], 'name' => $products['shipping']['name'], 'description' => '', 'quantity' => 1, 'unit_price' => GFCommon::to_number($products['shipping']['price'], $entry['currency']), 'is_shipping' => 1);
         $amount += $products['shipping']['price'];
     }
     return array('payment_amount' => $amount, 'setup_fee' => $fee_amount, 'trial' => $trial_amount, 'line_items' => $line_items, 'discounts' => $discounts);
 }
Beispiel #20
0
 public static function get_select_choices($field, $value = "")
 {
     $choices = "";
     if (RG_CURRENT_VIEW == "entry" && empty($value)) {
         $choices .= "<option value=''></option>";
     }
     if (is_array($field["choices"])) {
         foreach ($field["choices"] as $choice) {
             //needed for users upgrading from 1.0
             $field_value = !empty($choice["value"]) || $field["enableChoiceValue"] ? $choice["value"] : $choice["text"];
             if ($field["enablePrice"]) {
                 $field_value .= "|" . GFCommon::to_number($choice["price"]);
             }
             if (empty($value) && RG_CURRENT_VIEW != "entry") {
                 $selected = $choice["isSelected"] ? "selected='selected'" : "";
             } else {
                 $selected = RGFormsModel::choice_value_match($field, $choice, $value) ? "selected='selected'" : "";
             }
             $choices .= sprintf("<option value='%s' %s>%s</option>", esc_attr($field_value), $selected, esc_html($choice["text"]));
         }
     }
     return $choices;
 }
Beispiel #21
0
    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();"/>&nbsp;&nbsp;<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" ? "&nbsp;" : $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">&nbsp;</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"]);
                    ?>
&nbsp;</td>
                                            </tr>
                                        <?php 
                }
                ?>
                                        <tr>
                                            <?php 
                if (empty($products["shipping"]["name"])) {
                    ?>
                                                <td colspan="2" class="emptycell">&nbsp;</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 
    }
 public function get_checkbox_choices($value, $disabled_text, $form_id = 0)
 {
     $choices = '';
     $is_entry_detail = $this->is_entry_detail();
     $is_form_editor = $this->is_form_editor();
     if (is_array($this->choices)) {
         $choice_number = 1;
         $count = 1;
         foreach ($this->choices as $choice) {
             if ($choice_number % 10 == 0) {
                 //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10
                 $choice_number++;
             }
             $input_id = $this->id . '.' . $choice_number;
             if ($is_entry_detail || $is_form_editor || $form_id == 0) {
                 $id = $this->id . '_' . $choice_number++;
             } else {
                 $id = $form_id . '_' . $this->id . '_' . $choice_number++;
             }
             if (!isset($_GET['gf_token']) && empty($_POST) && rgar($choice, 'isSelected')) {
                 $checked = "checked='checked'";
             } elseif (is_array($value) && RGFormsModel::choice_value_match($this, $choice, rgget($input_id, $value))) {
                 $checked = "checked='checked'";
             } elseif (!is_array($value) && RGFormsModel::choice_value_match($this, $choice, $value)) {
                 $checked = "checked='checked'";
             } else {
                 $checked = '';
             }
             $logic_event = $this->get_conditional_logic_event('click');
             $tabindex = $this->get_tabindex();
             $choice_value = $choice['value'];
             if ($this->enablePrice) {
                 $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                 $choice_value .= '|' . $price;
             }
             $choice_value = esc_attr($choice_value);
             $choice_markup = "<li class='gchoice_{$id}'>\n\t\t\t\t\t\t\t\t<input name='input_{$input_id}' type='checkbox' {$logic_event} value='{$choice_value}' {$checked} id='choice_{$id}' {$tabindex} {$disabled_text} />\n\t\t\t\t\t\t\t\t<label for='choice_{$id}' id='label_{$id}'>{$choice['text']}</label>\n\t\t\t\t\t\t\t</li>";
             $choices .= gf_apply_filters(array('gform_field_choice_markup_pre_render', $this->formId, $this->id), $choice_markup, $choice, $this, $value);
             $is_entry_detail = $this->is_entry_detail();
             $is_form_editor = $this->is_form_editor();
             $is_admin = $is_entry_detail || $is_form_editor;
             if ($is_admin && RG_CURRENT_VIEW != 'entry' && $count >= 5) {
                 break;
             }
             $count++;
         }
         $total = sizeof($this->choices);
         if ($count < $total) {
             $choices .= "<li class='gchoice_total'>" . sprintf(esc_html__('%d of %d items shown. Edit field to view all', 'gravityforms'), $count, $total) . '</li>';
         }
     }
     return gf_apply_filters(array('gform_field_choices', $this->formId, $this->id), $choices, $this);
 }
Beispiel #23
0
 private static function get_subscription_query_string($config, $form, $entry)
 {
     //getting all product fields
     $products = GFCommon::get_product_fields($form, $entry, true);
     $item_name = "";
     $name_without_options = "";
     $amount = 0;
     foreach ($products["products"] as $id => $product) {
         if ($id == $config["meta"]["recurring_amount_field"] || $config["meta"]["recurring_amount_field"] == "all") {
             $options = "";
             $price = GFCommon::to_number($product["price"]);
             if (isset($product["options"]) && is_array($product["options"]) && !empty($product["options"])) {
                 $options = " (";
                 foreach ($product["options"] as $option) {
                     $options .= $option["option_name"] . ", ";
                     $price += GFCommon::to_number($option["price"]);
                 }
                 $options = substr($options, 0, strlen($options) - 2) . ")";
             }
             $quantity = GFCommon::to_number($product["quantity"]);
             $quantity_label = $quantity > 1 ? $quantity . " " : "";
             $item_name .= $quantity_label . $product["name"] . $options . ", ";
             $name_without_options .= $product["name"] . ", ";
             $amount += $price * $quantity;
         }
     }
     //adding shipping if feed was configured with "Form Total"
     if ($config["meta"]["recurring_amount_field"] == "all" && !empty($products["shipping"]["price"])) {
         $amount += floatval($products["shipping"]["price"]);
     }
     if (!empty($item_name)) {
         $item_name = substr($item_name, 0, strlen($item_name) - 2);
     }
     //if name is larger than max, remove options from it.
     if (strlen($item_name) > 127) {
         $item_name = substr($name_without_options, 0, strlen($name_without_options) - 2);
         //truncating name to maximum allowed size
         if (strlen($item_name) > 127) {
             $item_name = substr($item_name, 0, 124) . "...";
         }
     }
     $item_name = urlencode($item_name);
     $trial = "";
     if ($config["meta"]["trial_period_enabled"]) {
         $trial_amount = GFCommon::to_number($config["meta"]["trial_amount"]);
         if (empty($trial_amount)) {
             $trial_amount = 0;
         }
         $trial = "&a1={$trial_amount}&p1={$config["meta"]["trial_period_number"]}&t1={$config["meta"]["trial_period_type"]}";
     }
     $recurring_times = !empty($config["meta"]["recurring_times"]) ? "&srt={$config["meta"]["recurring_times"]}" : "";
     $recurring_retry = $config["meta"]["recurring_retry"] ? "1" : "0";
     $query_string = "&cmd=_xclick-subscriptions&item_name={$item_name}{$trial}&a3={$amount}&p3={$config["meta"]["billing_cycle_number"]}&t3={$config["meta"]["billing_cycle_type"]}&src=1&sra={$recurring_retry}{$recurring_times}";
     return $amount > 0 ? $query_string : false;
 }
 public function admin_update_payment($form, $entry_id)
 {
     check_admin_referer('gforms_save_entry', 'gforms_save_entry');
     //update payment information in admin, need to use this function so the lead data is updated before displayed in the sidebar info section
     $entry = GFFormsModel::get_lead($entry_id);
     if ($this->payment_details_editing_disabled($entry, 'update')) {
         return;
     }
     //get payment fields to update
     $payment_status = rgpost('payment_status');
     //when updating, payment status may not be editable, if no value in post, set to lead payment status
     if (empty($payment_status)) {
         $payment_status = $entry['payment_status'];
     }
     $payment_amount = GFCommon::to_number(rgpost('payment_amount'));
     $payment_transaction = rgpost('paypal_transaction_id');
     $payment_date = rgpost('payment_date');
     if (empty($payment_date)) {
         $payment_date = gmdate('y-m-d H:i:s');
     } else {
         //format date entered by user
         $payment_date = date('Y-m-d H:i:s', strtotime($payment_date));
     }
     global $current_user;
     $user_id = 0;
     $user_name = 'System';
     if ($current_user && ($user_data = get_userdata($current_user->ID))) {
         $user_id = $current_user->ID;
         $user_name = $user_data->display_name;
     }
     $entry['payment_status'] = $payment_status;
     $entry['payment_amount'] = $payment_amount;
     $entry['payment_date'] = $payment_date;
     $entry['transaction_id'] = $payment_transaction;
     // if payment status does not equal approved/paid or the lead has already been fulfilled, do not continue with fulfillment
     if (($payment_status == 'Approved' || $payment_status == 'Paid') && !$entry['is_fulfilled']) {
         $action['id'] = $payment_transaction;
         $action['type'] = 'complete_payment';
         $action['transaction_id'] = $payment_transaction;
         $action['amount'] = $payment_amount;
         $action['entry_id'] = $entry['id'];
         $this->complete_payment($entry, $action);
         $this->fulfill_order($entry, $payment_transaction, $payment_amount);
     }
     //update lead, add a note
     GFAPI::update_entry($entry);
     GFFormsModel::add_note($entry['id'], $user_id, $user_name, sprintf(__('Payment information was manually updated. Status: %s. Amount: %s. Transaction Id: %s. Date: %s', 'gravityformspaypal'), $entry['payment_status'], GFCommon::to_money($entry['payment_amount'], $entry['currency']), $payment_transaction, $entry['payment_date']));
 }
Beispiel #25
0
 /**
  * Get init script and all necessary data for conditional logic.
  *
  * @todo: Replace much of the field value retrieval with a get_original_value() method in GF_Field class.
  *
  * @param       $form
  * @param array $field_values
  *
  * @return string
  */
 private static function get_conditional_logic($form, $field_values = array())
 {
     $logics = '';
     $dependents = '';
     $fields_with_logic = array();
     $default_values = array();
     foreach ($form['fields'] as $field) {
         /* @var GF_Field $field */
         $field_deps = self::get_conditional_logic_fields($form, $field->id);
         $field_dependents[$field->id] = !empty($field_deps) ? $field_deps : array();
         //use section's logic if one exists
         $section = RGFormsModel::get_section($form, $field->id);
         $section_logic = !empty($section) ? rgar($section, 'conditionalLogic') : null;
         $field_logic = $field->type != 'page' ? $field->conditionalLogic : null;
         //page break conditional logic will be handled during the next button click
         $next_button_logic = !empty($field->nextButton) && !empty($field->nextButton['conditionalLogic']) ? $field->nextButton['conditionalLogic'] : null;
         if (!empty($field_logic) || !empty($next_button_logic)) {
             $field_section_logic = array('field' => $field_logic, 'nextButton' => $next_button_logic, 'section' => $section_logic);
             $logics .= $field->id . ': ' . GFCommon::json_encode($field_section_logic) . ',';
             $fields_with_logic[] = $field->id;
             $peers = $field->type == 'section' ? GFCommon::get_section_fields($form, $field->id) : array($field);
             $peer_ids = array();
             foreach ($peers as $peer) {
                 $peer_ids[] = $peer->id;
             }
             $dependents .= $field->id . ': ' . GFCommon::json_encode($peer_ids) . ',';
         }
         //-- Saving default values so that they can be restored when toggling conditional logic ---
         $field_val = '';
         $input_type = $field->get_input_type();
         $inputs = $field->get_entry_inputs();
         //get parameter value if pre-populate is enabled
         if ($field->allowsPrepopulate) {
             if ($input_type == 'checkbox') {
                 $field_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 if (!is_array($field_val)) {
                     $field_val = explode(',', $field_val);
                 }
             } elseif (is_array($inputs)) {
                 $field_val = array();
                 foreach ($inputs as $input) {
                     $field_val["input_{$input['id']}"] = RGFormsModel::get_parameter_value(rgar($input, 'name'), $field_values, $field);
                 }
             } elseif ($input_type == 'time') {
                 // maintained for backwards compatibility. The Time field now has an inputs array.
                 $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 if (!empty($parameter_val) && preg_match('/^(\\d*):(\\d*) ?(.*)$/', $parameter_val, $matches)) {
                     $field_val = array();
                     $field_val[] = esc_attr($matches[1]);
                     //hour
                     $field_val[] = esc_attr($matches[2]);
                     //minute
                     $field_val[] = rgar($matches, 3);
                     //am or pm
                 }
             } elseif ($input_type == 'list') {
                 $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 $field_val = is_array($parameter_val) ? $parameter_val : explode(',', str_replace('|', ',', $parameter_val));
                 if (is_array(rgar($field_val, 0))) {
                     $list_values = array();
                     foreach ($field_val as $row) {
                         $list_values = array_merge($list_values, array_values($row));
                     }
                     $field_val = $list_values;
                 }
             } else {
                 $field_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
             }
         }
         //use default value if pre-populated value is empty
         $field_val = $field->get_value_default_if_empty($field_val);
         if (is_array($field->choices) && $input_type != 'list') {
             //radio buttons start at 0 and checkboxes start at 1
             $choice_index = $input_type == 'radio' ? 0 : 1;
             $is_pricing_field = GFCommon::is_pricing_field($field->type);
             foreach ($field->choices as $choice) {
                 if ($input_type == 'checkbox' && $choice_index % 10 == 0) {
                     $choice_index++;
                 }
                 $is_prepopulated = is_array($field_val) ? in_array($choice['value'], $field_val) : $choice['value'] == $field_val;
                 $is_choice_selected = rgar($choice, 'isSelected') || $is_prepopulated;
                 if ($is_choice_selected && $input_type == 'select') {
                     $price = GFCommon::to_number(rgar($choice, 'price')) == false ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                     $val = $is_pricing_field && $field->type != 'quantity' ? $choice['value'] . '|' . $price : $choice['value'];
                     $default_values[$field->id] = $val;
                 } elseif ($is_choice_selected) {
                     if (!isset($default_values[$field->id])) {
                         $default_values[$field->id] = array();
                     }
                     $default_values[$field->id][] = "choice_{$form['id']}_{$field->id}_{$choice_index}";
                 }
                 $choice_index++;
             }
         } elseif (!empty($field_val)) {
             switch ($input_type) {
                 case 'date':
                     // for date fields; that are multi-input; and where the field value is a string
                     // (happens with prepop, default value will always be an array for multi-input date fields)
                     if (is_array($field->inputs) && (!is_array($field_val) || !isset($field_val['m']))) {
                         $format = empty($field->dateFormat) ? 'mdy' : esc_attr($field->dateFormat);
                         $date_info = GFcommon::parse_date($field_val, $format);
                         // converts date to array( 'm' => 1, 'd' => '13', 'y' => '1987' )
                         $field_val = $field->get_date_array_by_format(array($date_info['month'], $date_info['day'], $date_info['year']));
                     }
                     break;
                 case 'time':
                     if (is_array($field_val)) {
                         $ampm_key = key(array_slice($field_val, -1, 1, true));
                         $field_val[$ampm_key] = strtolower($field_val[$ampm_key]);
                     }
                     break;
                 case 'address':
                     $state_input_id = sprintf('%s.4', $field->id);
                     if (isset($field_val[$state_input_id]) && !$field_val[$state_input_id]) {
                         $field_val[$state_input_id] = $field->defaultState;
                     }
                     $country_input_id = sprintf('%s.6', $field->id);
                     if (isset($field_val[$country_input_id]) && !$field_val[$country_input_id]) {
                         $field_val[$country_input_id] = $field->defaultCountry;
                     }
                     break;
             }
             $default_values[$field->id] = $field_val;
         }
     }
     $button_conditional_script = '';
     //adding form button conditional logic if enabled
     if (isset($form['button']['conditionalLogic'])) {
         $logics .= '0: ' . GFCommon::json_encode(array('field' => $form['button']['conditionalLogic'], 'section' => null)) . ',';
         $dependents .= '0: ' . GFCommon::json_encode(array(0)) . ',';
         $fields_with_logic[] = 0;
         $button_conditional_script = "jQuery('#gform_{$form['id']}').submit(" . 'function(event, isButtonPress){' . '    var visibleButton = jQuery(".gform_next_button:visible, .gform_button:visible, .gform_image_button:visible");' . '    return visibleButton.length > 0 || isButtonPress == true;' . '}' . ');';
     }
     if (!empty($logics)) {
         $logics = substr($logics, 0, strlen($logics) - 1);
     }
     //removing last comma;
     if (!empty($dependents)) {
         $dependents = substr($dependents, 0, strlen($dependents) - 1);
     }
     //removing last comma;
     $animation = rgar($form, 'enableAnimation') ? '1' : '0';
     global $wp_locale;
     $number_format = $wp_locale->number_format['decimal_point'] == ',' ? 'decimal_comma' : 'decimal_dot';
     $str = "if(window['jQuery']){" . "if(!window['gf_form_conditional_logic'])" . "window['gf_form_conditional_logic'] = new Array();" . "window['gf_form_conditional_logic'][{$form['id']}] = { logic: { {$logics} }, dependents: { {$dependents} }, animation: {$animation}, defaults: " . json_encode($default_values) . ", fields: " . json_encode($field_dependents) . " }; " . "if(!window['gf_number_format'])" . "window['gf_number_format'] = '" . $number_format . "';" . 'jQuery(document).ready(function(){' . "gf_apply_rules({$form['id']}, " . json_encode($fields_with_logic) . ', true);' . "jQuery('#gform_wrapper_{$form['id']}').show();" . "jQuery(document).trigger('gform_post_conditional_logic', [{$form['id']}, null, true]);" . $button_conditional_script . '} );' . '} ';
     return $str;
 }
Beispiel #26
0
 public static function get_calculation_value($field_id, $form, $lead)
 {
     $filters = array('price', 'value', '');
     $value = false;
     foreach ($filters as $filter) {
         if (is_numeric($value)) {
             //value found, exit loop
             break;
         }
         $value = GFCommon::to_number(GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead));
     }
     if (!$value || !is_numeric($value)) {
         $value = 0;
     }
     return $value;
 }
 /**
  * get input values for recurring payments field
  * @param integer $field_id
  * @return array
  */
 public static function getPost($field_id)
 {
     $recurring = rgpost('gfeway_' . $field_id);
     if (is_array($recurring)) {
         $intervalSize = 1;
         switch ($recurring[6]) {
             case 'weekly':
                 $intervalType = GFEwayRecurringPayment::WEEKS;
                 break;
             case 'fortnightly':
                 $intervalType = GFEwayRecurringPayment::WEEKS;
                 $intervalSize = 2;
                 break;
             case 'monthly':
                 $intervalType = GFEwayRecurringPayment::MONTHS;
                 break;
             case 'quarterly':
                 $intervalType = GFEwayRecurringPayment::MONTHS;
                 $intervalSize = 3;
                 break;
             case 'yearly':
                 $intervalType = GFEwayRecurringPayment::YEARS;
                 break;
             default:
                 // invalid or not selected
                 $intervalType = -1;
                 break;
         }
         $recurring = array('amountInit' => GFCommon::to_number($recurring[1]), 'dateInit' => self::parseDate($recurring[2]), 'amountRecur' => GFCommon::to_number($recurring[3]), 'dateStart' => self::parseDate($recurring[4]), 'dateEnd' => self::parseDate($recurring[5]), 'intervalSize' => $intervalSize, 'intervalType' => $intervalType, 'intervalTypeDesc' => $recurring[6]);
     } else {
         $recurring = false;
     }
     return $recurring;
 }
 protected function get_order_data($feed, $form, $entry)
 {
     $products = GFCommon::get_product_fields($form, $entry);
     $payment_field = $feed["meta"]["transactionType"] == "product" ? $feed["meta"]["paymentAmount"] : $feed["meta"]["recurringAmount"];
     $setup_fee_field = rgar($feed["meta"], "setupFee_enabled") ? $feed["meta"]["setupFee_product"] : false;
     $trial_field = rgar($feed["meta"], "trial_enabled") ? rgars($feed, 'meta/trial_product') : false;
     $amount = 0;
     $line_items = array();
     $discounts = array();
     $fee_amount = 0;
     $trial_amount = 0;
     foreach ($products["products"] as $field_id => $product) {
         $quantity = $product["quantity"] ? $product["quantity"] : 1;
         $product_price = GFCommon::to_number($product['price']);
         $options = array();
         if (is_array(rgar($product, "options"))) {
             foreach ($product["options"] as $option) {
                 if (isset($option['option_name'])) {
                     $options[] = $option["option_name"];
                     $product_price += $option["price"];
                 }
             }
         }
         $is_trial_or_setup_fee = false;
         if (!empty($trial_field) && $trial_field == $field_id) {
             $trial_amount = $product_price * $quantity;
             $is_trial_or_setup_fee = true;
         } else {
             if (!empty($setup_fee_field) && $setup_fee_field == $field_id) {
                 $fee_amount = $product_price * $quantity;
                 $is_trial_or_setup_fee = true;
             }
         }
         //Do not add to line items if the payment field selected in the feed is not the current field.
         if (is_numeric($payment_field) && $payment_field != $field_id) {
             continue;
         }
         //Do not add to line items if the payment field is set to "Form Total" and the current field was used for trial or setup fee.
         if ($is_trial_or_setup_fee && !is_numeric($payment_field)) {
             continue;
         }
         $amount += $product_price * $quantity;
         $description = "";
         if (!empty($options)) {
             $description = __("options: ", "gravityforms") . " " . implode(", ", $options);
         }
         if ($product_price >= 0) {
             $line_items[] = array("id" => $field_id, "name" => $product["name"], "description" => $description, "quantity" => $quantity, "unit_price" => GFCommon::to_number($product_price), "options" => rgar($product, "options"));
         } else {
             $discounts[] = array("id" => $field_id, "name" => $product["name"], "description" => $description, "quantity" => $quantity, "unit_price" => GFCommon::to_number($product_price), "options" => rgar($product, "options"));
         }
     }
     if ($trial_field == "enter_amount") {
         $trial_amount = rgar($feed["meta"], "trial_amount") ? rgar($feed["meta"], "trial_amount") : 0;
     }
     if (!empty($products["shipping"]["name"]) && !is_numeric($payment_field)) {
         $line_items[] = array("id" => "", "name" => $products["shipping"]["name"], "description" => "", "quantity" => 1, "unit_price" => GFCommon::to_number($products["shipping"]["price"]), "is_shipping" => 1);
         $amount += $products["shipping"]["price"];
     }
     return array("payment_amount" => $amount, "setup_fee" => $fee_amount, "trial" => $trial_amount, "line_items" => $line_items, "discounts" => $discounts);
 }
    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();" />&nbsp;&nbsp;
						<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' ? '&nbsp;' : $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">&nbsp;</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']);
                    ?>
&nbsp;</td>
									</tr>
								<?php 
                }
                ?>
								<tr>
									<?php 
                if (empty($products['shipping']['name'])) {
                    ?>
										<td colspan="2" class="emptycell">&nbsp;</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 
    }
 private function get_order_data($feed, $form, $entry)
 {
     $products = GFCommon::get_product_fields($form, $entry);
     $payment_field = $feed["meta"]["transactionType"] == "product" ? $feed["meta"]["paymentAmount"] : $feed["meta"]["recurringAmount"];
     $setup_fee_field = rgar($feed["meta"], "setupFee_enabled") ? $feed["meta"]["setupFee_product"] : false;
     $trial_field = rgar($feed["meta"], "trial_enabled") ? rgars($feed, 'meta/trial_product') : false;
     $amount = 0;
     $line_items = array();
     $fee_amount = 0;
     $trial_amount = 0;
     foreach ($products["products"] as $field_id => $product) {
         $quantity = $product["quantity"] ? $product["quantity"] : 1;
         $product_price = GFCommon::to_number($product['price']);
         $options = array();
         if (is_array(rgar($product, "options"))) {
             foreach ($product["options"] as $option) {
                 $options[] = $option["option_name"];
                 $product_price += $option["price"];
             }
         }
         if (!empty($trial_field) && $trial_field == $field_id) {
             $trial_amount = $product_price * $quantity;
         } else {
             if (!empty($setup_fee_field) && $setup_fee_field == $field_id) {
                 $fee_amount = $product_price * $quantity;
             } else {
                 if (is_numeric($payment_field) && $payment_field != $field_id) {
                     continue;
                 }
                 $amount += $product_price * $quantity;
                 $description = "";
                 if (!empty($options)) {
                     $description = __("options: ", "gravityforms") . " " . implode(", ", $options);
                 }
                 if ($product_price >= 0) {
                     $line_items[] = array("id" => $field_id, "name" => $product["name"], "description" => $description, "quantity" => $quantity, "unit_price" => GFCommon::to_number($product_price));
                 }
             }
         }
     }
     if (!empty($products["shipping"]["name"]) && !is_numeric($payment_field)) {
         $line_items[] = array("id" => "", "name" => $products["shipping"]["name"], "description" => "", "quantity" => 1, "unit_price" => GFCommon::to_number($products["shipping"]["price"]));
         $amount += $products["shipping"]["price"];
     }
     return array("payment_amount" => $amount, "setup_fee" => $fee_amount, "trial" => $trial_amount, "line_items" => $line_items);
 }