Ejemplo n.º 1
0
 private static function has_price_field($form)
 {
     $has_price_field = false;
     foreach ($form['fields'] as $field) {
         $input_type = GFFormsModel::get_input_type($field);
         $has_price_field = GFCommon::is_product_field($input_type) ? true : $has_price_field;
     }
     return $has_price_field;
 }
Ejemplo n.º 2
0
 /**
  * Return array of fields' id and label, for a given Form ID
  *
  * @access public
  * @param string|array $form_id (default: '') or $form object
  * @return array
  */
 public static function get_form_fields($form = '', $add_default_properties = false, $include_parent_field = true)
 {
     if (!is_array($form)) {
         $form = self::get_form($form);
     }
     $fields = array();
     $has_product_fields = false;
     $has_post_fields = false;
     $has_quiz_fields = false;
     $has_poll_fields = false;
     // If GF_Field exists, we're using GF 1.9+, where add_default_properties has been deprecated.
     if (false === class_exists('GF_Field') && $add_default_properties) {
         $form = RGFormsModel::add_default_properties($form);
     }
     if ($form) {
         foreach ($form['fields'] as $field) {
             if ($include_parent_field || empty($field['inputs'])) {
                 $fields[$field['id']] = array('label' => rgar($field, 'label'), 'parent' => null, 'type' => rgar($field, 'type'), 'adminLabel' => rgar($field, 'adminLabel'), 'adminOnly' => rgar($field, 'adminOnly'));
             }
             if ($add_default_properties && !empty($field['inputs'])) {
                 foreach ($field['inputs'] as $input) {
                     /**
                      * @hack
                      * In case of email/email confirmation, the input for email has the same id as the parent field
                      */
                     if ('email' == rgar($field, 'type') && false === strpos($input['id'], '.')) {
                         continue;
                     }
                     $fields[(string) $input['id']] = array('label' => rgar($input, 'label'), 'customLabel' => rgar($input, 'customLabel'), 'parent' => $field, 'type' => rgar($field, 'type'), 'adminLabel' => rgar($field, 'adminLabel'), 'adminOnly' => rgar($field, 'adminOnly'));
                 }
             }
             /**
              * @since 1.8
              */
             if ('quiz' === $field['type']) {
                 $has_quiz_fields = true;
             }
             /**
              * @since 1.8
              */
             if ('poll' === $field['type']) {
                 $has_poll_fields = true;
             }
             if (GFCommon::is_product_field($field['type'])) {
                 $has_product_fields = true;
             }
             /**
              * @hack Version 1.9
              */
             $field_for_is_post_field = class_exists('GF_Fields') ? (object) $field : (array) $field;
             if (GFCommon::is_post_field($field_for_is_post_field)) {
                 $has_post_fields = true;
             }
         }
     }
     /**
      * @since 1.7
      */
     if ($has_post_fields) {
         $fields['post_id'] = array('label' => __('Post ID', 'gravityview'), 'type' => 'post_id');
     }
     if ($has_product_fields) {
         $fields['payment_status'] = array('label' => __('Payment Status', 'gravityview'), 'type' => 'payment_status');
         $fields['payment_date'] = array('label' => __('Payment Date', 'gravityview'), 'type' => 'payment_date');
         $fields['payment_amount'] = array('label' => __('Payment Amount', 'gravityview'), 'type' => 'payment_amount');
         $fields['payment_method'] = array('label' => __('Payment Method', 'gravityview'), 'type' => 'payment_method');
         $fields['is_fulfilled'] = array('label' => __('Is Fulfilled', 'gravityview'), 'type' => 'is_fulfilled');
         $fields['transaction_id'] = array('label' => __('Transaction ID', 'gravityview'), 'type' => 'transaction_id');
         $fields['transaction_type'] = array('label' => __('Transaction Type', 'gravityview'), 'type' => 'transaction_type');
     }
     /**
      * @since 1.8
      */
     if ($has_quiz_fields) {
         $fields['gquiz_score'] = array('label' => __('Quiz Score Total', 'gravityview'), 'type' => 'quiz_score', 'desc' => __('Displays the number of correct Quiz answers the user submitted.', 'gravityview'));
         $fields['gquiz_percent'] = array('label' => __('Quiz Percentage Grade', 'gravityview'), 'type' => 'quiz_percent', 'desc' => __('Displays the percentage of correct Quiz answers the user submitted.', 'gravityview'));
         $fields['gquiz_grade'] = array('label' => __('Quiz Letter Grade', 'gravityview'), 'type' => 'quiz_grade', 'desc' => __('Displays the Grade the user achieved based on Letter Grading configured in the Quiz Settings.', 'gravityview'));
         $fields['gquiz_is_pass'] = array('label' => __('Quiz Pass/Fail', 'gravityview'), 'type' => 'quiz_is_pass', 'desc' => __('Displays either Passed or Failed based on the Pass/Fail settings configured in the Quiz Settings.', 'gravityview'));
     }
     return $fields;
 }
Ejemplo n.º 3
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 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);
 }
 /**
  *
  * Fill-in the saved values into the form inputs
  *
  * @param string $field_content Always empty.
  * @param GF_Field $field
  * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
  * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
  * @param int $form_id Form ID
  *
  * @return mixed
  */
 function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id)
 {
     // If the form has been submitted, then we don't need to pre-fill the values,
     // Except for fileupload type - run always!!
     if ($this->is_edit_entry_submission() && 'fileupload' !== $field->type || GFCommon::is_product_field($field->type)) {
         return $field_content;
     }
     // Turn on Admin-style display for file upload fields only
     if ('fileupload' === $field->type) {
         $_GET['page'] = 'gf_entries';
     }
     // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
     $field->adminOnly = false;
     /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
     // add categories as choices for Post Category field
     if ('post_category' === $field->type) {
         $field = GFCommon::add_categories_as_choices($field, $value);
     }
     /**
      * @filter `gravityview/edit_entry/pre_populate/override` Allow the pre-populated value to override saved value in Edit Entry form. By default, pre-populate mechanism only kicks on empty fields.
      * @param boolean True: override saved values; False: don't override (default)
      * @param $field GF_Field object Gravity Forms field object
      * @since 1.13
      */
     $override_saved_value = apply_filters('gravityview/edit_entry/pre_populate/override', false, $field);
     // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
     if (isset($field->inputs) && is_array($field->inputs) && !in_array($field->type, array('time', 'date'))) {
         $field_value = array();
         // only accept pre-populated values if the field doesn't have any choice selected.
         $allow_pre_populated = $field->allowsPrepopulate;
         foreach ((array) $field->inputs as $input) {
             $input_id = strval($input['id']);
             if (!empty($this->entry[$input_id])) {
                 $field_value[$input_id] = 'post_category' === $field->type ? GFCommon::format_post_category($this->entry[$input_id], true) : $this->entry[$input_id];
                 $allow_pre_populated = false;
             }
         }
         $pre_value = $field->get_value_submission(array(), false);
         $field_value = !$allow_pre_populated && !($override_saved_value && !empty($pre_value)) ? $field_value : $pre_value;
     } else {
         $id = intval($field->id);
         // get pre-populated value if exists
         $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value($field->inputName, array(), $field) : '';
         // saved field entry value (if empty, fallback to the pre-populated value, if exists)
         // or pre-populated value if not empty and set to override saved value
         $field_value = !empty($this->entry[$id]) && !($override_saved_value && !empty($pre_value)) ? $this->entry[$id] : $pre_value;
         // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
         if ('post_category' === $field->type && !empty($field_value)) {
             $categories = array();
             foreach (explode(',', $field_value) as $cat_string) {
                 $categories[] = GFCommon::format_post_category($cat_string, true);
             }
             $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode('', $categories);
         }
     }
     // if value is empty get the default value if defined
     $field_value = $field->get_value_default_if_empty($field_value);
     /**
      * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
      * @since 1.11
      * @param mixed $field_value field value used to populate the input
      * @param object $field Gravity Forms field object ( Class GF_Field )
      */
     $field_value = apply_filters('gravityview/edit_entry/field_value', $field_value, $field);
     // Prevent any PHP warnings, like undefined index
     ob_start();
     $return = $field->get_field_input($this->form, $field_value, $this->entry);
     // If there was output, it's an error
     $warnings = ob_get_clean();
     if (!empty($warnings)) {
         do_action('gravityview_log_error', __METHOD__ . $warnings, $field_value);
     }
     /**
      * Unset hack $_GET['page'] = 'gf_entries'
      * We need the fileupload html field to render with the proper id
      *  ( <li id="field_80_16" ... > )
      */
     unset($_GET['page']);
     return $return;
 }
 /**
  *
  * Fill-in the saved values into the form inputs
  *
  * @param string $field_content Always empty. Returning not-empty overrides the input.
  * @param GF_Field $field
  * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
  * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
  * @param int $form_id Form ID
  *
  * @return mixed
  */
 function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id)
 {
     $gv_field = GravityView_Fields::get_associated_field($field);
     // If the form has been submitted, then we don't need to pre-fill the values,
     // Except for fileupload type and when a field input is overridden- run always!!
     if ($this->is_edit_entry_submission() && !in_array($field->type, array('fileupload', 'post_image')) && false === ($gv_field && is_callable(array($gv_field, 'get_field_input'))) || !empty($field_content) || in_array($field->type, array('honeypot')) || GFCommon::is_product_field($field->type)) {
         return $field_content;
     }
     // Turn on Admin-style display for file upload fields only
     if ('fileupload' === $field->type) {
         $_GET['page'] = 'gf_entries';
     }
     // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
     $field->adminOnly = false;
     /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
     // add categories as choices for Post Category field
     if ('post_category' === $field->type) {
         $field = GFCommon::add_categories_as_choices($field, $value);
     }
     $field_value = $this->get_field_value($field);
     /**
      * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
      * @since 1.11
      * @param mixed $field_value field value used to populate the input
      * @param object $field Gravity Forms field object ( Class GF_Field )
      */
     $field_value = apply_filters('gravityview/edit_entry/field_value', $field_value, $field);
     /**
      * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
      * @since 1.17
      * @param mixed $field_value field value used to populate the input
      * @param GF_Field $field Gravity Forms field object
      */
     $field_value = apply_filters('gravityview/edit_entry/field_value_' . $field->type, $field_value, $field);
     // Prevent any PHP warnings, like undefined index
     ob_start();
     if ($gv_field && is_callable(array($gv_field, 'get_field_input'))) {
         /** @var GF_Field $gv_field */
         $return = $gv_field->get_field_input($this->form, $field_value, $this->entry, $field);
     } else {
         $return = $field->get_field_input($this->form, $field_value, $this->entry);
     }
     // If there was output, it's an error
     $warnings = ob_get_clean();
     if (!empty($warnings)) {
         do_action('gravityview_log_error', __METHOD__ . $warnings, $field_value);
     }
     /**
      * Unset hack $_GET['page'] = 'gf_entries'
      * We need the fileupload html field to render with the proper id
      *  ( <li id="field_80_16" ... > )
      */
     unset($_GET['page']);
     return $return;
 }
Ejemplo n.º 7
0
 public static function failed_state_validation($form_id, $field, $value)
 {
     global $_gf_state;
     //if field can be populated dynamically, disable state validation
     if ($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 = json_decode(base64_decode($_POST["state_{$form_id}"]), true);
         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 = json_decode($state[0], true);
     }
     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;
 }
Ejemplo n.º 8
0
 public static function export_feed($entry, $form, $feed)
 {
     $resubscribe = $feed["meta"]["resubscribe"] ? true : false;
     $email = $entry[$feed["meta"]["field_map"]["email"]];
     $name = "";
     if (!empty($feed["meta"]["field_map"]["fullname"])) {
         $name = self::get_name($entry, $feed["meta"]["field_map"]["fullname"]);
     }
     $merge_vars = array();
     foreach ($feed["meta"]["field_map"] 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]);
             $name = count($ary) > 0 ? $ary[0] : "";
             $merge_vars[] = array("Key" => $var_key, "Value" => $name);
         } else {
             if (RGFormsModel::get_input_type($field) == "checkbox") {
                 foreach ($field["inputs"] as $input) {
                     $index = (string) $input["id"];
                     if (!rgempty($index, $entry)) {
                         $merge_vars[] = array("Key" => $var_key, "Value" => $entry[$index]);
                     }
                 }
             } else {
                 if (!in_array($var_key, array('email', 'fullname'))) {
                     $merge_vars[] = array("Key" => $var_key, "Value" => $entry[$field_id]);
                 }
             }
         }
     }
     $subscriber = array('EmailAddress' => $email, 'Name' => $name, 'CustomFields' => $merge_vars, 'Resubscribe' => $resubscribe);
     $api = new CS_REST_Subscribers($feed["meta"]["contact_list_id"], self::get_api_key());
     $api->add($subscriber);
 }
Ejemplo n.º 9
0
 public static function failed_state_validation($form_id, $field, $value)
 {
     global $_gf_state;
     if (!GFCommon::is_product_field($field["type"] && $field["type"] != "donation")) {
         return false;
     } else {
         if (!in_array($field["inputType"], array("singleshipping", "singleproduct", "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;
         $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;
 }
Ejemplo n.º 10
0
function getmetaData($entry_id)
{
    $return = '';
    $metaData = mf_get_form_meta('entry_id', $entry_id);
    foreach ($metaData as $data) {
        $entry = GFAPI::get_entry($data->lead_id);
        //check if entry-id is valid
        if (is_array($entry)) {
            //display entry data
            $formPull = GFAPI::get_form($data->form_id);
            $return .= '<h2>' . $formPull['title'] . '</h2>';
            $return .= '<table>';
            foreach ($formPull['fields'] as $formFields) {
                $gwreadonly_enable = isset($formFields['gwreadonly_enable']) ? $formFields['gwreadonly_enable'] : 0;
                //exclude page breaks and the entry fields used to verify the entry
                // and the display only fields from the additional forms
                if ($formFields['type'] != 'page' && $formFields['inputName'] != 'entry-id' && $formFields['inputName'] != 'contact-email' && $gwreadonly_enable != 1) {
                    $display_empty_fields = false;
                    switch (RGFormsModel::get_input_type($formFields)) {
                        case 'section':
                            if (!GFCommon::is_section_empty($formFields, $formPull, $entry) || $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($formFields));
                                ?>
</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($formFields->type)) {
                                $has_product_fields = true;
                                continue;
                            }
                            $value = RGFormsModel::get_lead_field_value($entry, $formFields);
                            $display_value = GFCommon::get_lead_field_display($formFields, $value, $entry['currency']);
                            $display_value = apply_filters('gform_entry_field_value', $display_value, $formFields, $entry, $formPull);
                            if ($display_empty_fields || !empty($display_value) || $display_value === '0') {
                                $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($formFields)) . '</td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" class="entry-view-field-value">' . $display_value . '</td>
                                            </tr>';
                                $content = apply_filters('gform_field_content', $content, $formFields, $value, $entry['id'], $formPull['id']);
                                $return .= $content;
                            }
                            break;
                    }
                }
            }
            $return .= '</table>';
        }
    }
    return $return;
}
Ejemplo n.º 11
0
    public static function lead_detail($Form, $lead, $allow_display_empty_fields = false, $inline = true, $options = array())
    {
        if (!class_exists('GFEntryList')) {
            require_once GFCommon::get_base_path() . "/entry_list.php";
        }
        global $current_user, $_gform_directory_approvedcolumn;
        get_currentuserinfo();
        $display_empty_fields = '';
        $allow_display_empty_fields = true;
        if ($allow_display_empty_fields) {
            $display_empty_fields = @rgget("gf_display_empty_fields", $_COOKIE);
        }
        if (empty($options)) {
            $options = self::directory_defaults();
        }
        // There is no edit link
        if (isset($_GET['edit']) || RGForms::post("action") === "update") {
            // Process editing leads
            $lead = self::edit_lead_detail($Form, $lead, $options);
            if (RGForms::post("action") !== "update") {
                return;
            }
        }
        extract($options);
        ?>
			<table cellspacing="0" class="widefat fixed entry-detail-view">
			<?php 
        $title = str_replace('%%formtitle%%', $Form["title"], str_replace('%%leadid%%', $lead['id'], $entrydetailtitle));
        if (!empty($title) && $inline) {
            ?>
				<thead>
					<tr>
						<th id="details" colspan="2" scope="col">
						<?php 
            $title = apply_filters('kws_gf_directory_detail_title', apply_filters('kws_gf_directory_detail_title_' . (int) $lead['id'], array($title, $lead), true), true);
            if (is_array($title)) {
                echo $title[0];
            } else {
                echo $title;
            }
            ?>
						</th>
					</tr>
				</thead>
				<?php 
        }
        ?>
				<tbody>
					<?php 
        $count = 0;
        $has_product_fields = false;
        $field_count = sizeof($Form["fields"]);
        $display_value = '';
        foreach ($Form["fields"] as $field) {
            // Don't show fields defined as hide in single.
            if (!empty($field['hideInSingle'])) {
                if (self::has_access("gravityforms_directory")) {
                    echo "\n\t\t\t\t\t\t\t\t\t" . '<!-- ' . sprintf(esc_html__('(Admin-only notice) Field #%d not shown: "Hide This Field in Single Entry View" was selected.', 'gravity-forms-addons'), $field['id']) . ' -->' . "\n\n";
                }
                continue;
            }
            $count++;
            $is_last = $count >= $field_count ? true : false;
            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;
                case "post_image":
                    $value = RGFormsModel::get_lead_field_value($lead, $field);
                    $valueArray = explode("|:|", $value);
                    @(list($url, $title, $caption, $description) = $valueArray);
                    if (!empty($url)) {
                        $value = $display_value = self::render_image_link($url, $lead, $options, $title, $caption, $description);
                    }
                    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"]);
                    break;
            }
            // end switch
            $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>
                                <th colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</th>
                            </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;
            }
        }
        // End foreach
        $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 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 $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 
                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 
            }
        }
        // Edit link
        if (!empty($options['useredit']) && is_user_logged_in() && intval($current_user->ID) === intval($lead['created_by']) || !empty($options['adminedit']) && self::has_access("gravityforms_directory")) {
            if (!empty($options['adminedit']) && self::has_access("gravityforms_directory")) {
                $editbuttontext = apply_filters('kws_gf_directory_edit_entry_text_admin', __("Edit Entry", 'gravity-forms-addons'));
            } else {
                $editbuttontext = apply_filters('kws_gf_directory_edit_entry_text_user', __("Edit Your Entry", 'gravity-forms-addons'));
            }
            ?>
						<tr>
							<th scope="row" class="entry-view-field-name"><?php 
            echo esc_html(apply_filters('kws_gf_directory_edit_entry_th', __("Edit", "gravity-forms-addons")));
            ?>
</th>
							<td class="entry-view-field-value useredit"><a href="<?php 
            echo add_query_arg(array('edit' => wp_create_nonce('edit' . $lead['id'] . $Form["id"])));
            ?>
"><?php 
            echo $editbuttontext;
            ?>
</a></td>
						</tr>
					<?php 
        }
        ?>
				</tbody>
			</table>
			<?php 
    }
 /**
  * Returns the value of the selected field.
  *
  * @param array $form The form object currently being processed.
  * @param array $entry The entry object currently being processed.
  * @param string $field_id The ID of the field being processed.
  *
  * @return array
  */
 public function get_field_value($form, $entry, $field_id)
 {
     $field_value = '';
     switch (strtolower($field_id)) {
         case 'form_title':
             $field_value = rgar($form, 'title');
             break;
         case 'date_created':
             $date_created = rgar($entry, strtolower($field_id));
             if (empty($date_created)) {
                 //the date created may not yet be populated if this function is called during the validation phase and the entry is not yet created
                 $field_value = gmdate('Y-m-d H:i:s');
             } else {
                 $field_value = $date_created;
             }
             break;
         case 'ip':
         case 'source_url':
             $field_value = rgar($entry, strtolower($field_id));
             break;
         default:
             $field = GFFormsModel::get_field($form, $field_id);
             if (is_object($field)) {
                 $is_integer = $field_id == intval($field_id);
                 $input_type = RGFormsModel::get_input_type($field);
                 if ($is_integer && $input_type == 'address') {
                     $field_value = $this->get_full_address($entry, $field_id);
                 } elseif ($is_integer && $input_type == 'name') {
                     $field_value = $this->get_full_name($entry, $field_id);
                 } elseif ($is_integer && $input_type == 'checkbox') {
                     foreach ($field->inputs as $input) {
                         $index = (string) $input['id'];
                         $field_value[] = $this->maybe_override_field_value(rgar($entry, $index), $form, $entry, $index);
                     }
                 } elseif ($input_type == 'multiselect') {
                     $value = $this->maybe_override_field_value(rgar($entry, $field_id), $form, $entry, $field_id);
                     if (!empty($value)) {
                         $field_value = explode(',', $value);
                     }
                 } elseif (GFCommon::is_product_field($field->type) && $field->enablePrice) {
                     $ary = explode('|', rgar($entry, $field_id));
                     $field_value = count($ary) > 0 ? $ary[0] : '';
                 } else {
                     if (is_callable(array('GF_Field', 'get_value_export'))) {
                         $field_value = $field->get_value_export($entry, $field_id);
                     } else {
                         $field_value = rgar($entry, $field_id);
                     }
                 }
                 if (!in_array($input_type, array('checkbox', 'multiselect'))) {
                     $field_value = $this->maybe_override_field_value($field_value, $form, $entry, $field_id);
                 }
             } else {
                 $field_value = $this->maybe_override_field_value(rgar($entry, $field_id), $form, $entry, $field_id);
             }
     }
     return $field_value;
 }
Ejemplo n.º 13
0
 /**
  * Return array of fields' id and label, for a given Form ID
  *
  * @access public
  * @param string|array $form_id (default: '') or $form object
  * @param bool $add_default_properties
  * @param bool $include_parent_field
  * @return array
  */
 public static function get_form_fields($form = '', $add_default_properties = false, $include_parent_field = true)
 {
     if (!is_array($form)) {
         $form = self::get_form($form);
     }
     $fields = array();
     $has_product_fields = false;
     $has_post_fields = false;
     if ($form) {
         foreach ($form['fields'] as $field) {
             if ($include_parent_field || empty($field['inputs'])) {
                 $fields["{$field->id}"] = array('label' => rgar($field, 'label'), 'parent' => null, 'type' => rgar($field, 'type'), 'adminLabel' => rgar($field, 'adminLabel'), 'adminOnly' => rgar($field, 'adminOnly'));
             }
             if ($add_default_properties && !empty($field->inputs)) {
                 foreach ($field->inputs as $input) {
                     /**
                      * @hack
                      * In case of email/email confirmation, the input for email has the same id as the parent field
                      */
                     if ('email' === $field->type && false === strpos($input['id'], '.')) {
                         continue;
                     }
                     $fields["{$input['id']}"] = array('label' => rgar($input, 'label'), 'customLabel' => rgar($input, 'customLabel'), 'parent' => $field, 'type' => rgar($field, 'type'), 'adminLabel' => rgar($field, 'adminLabel'), 'adminOnly' => rgar($field, 'adminOnly'));
                 }
             }
             if (GFCommon::is_product_field($field->type)) {
                 $has_product_fields = true;
             }
             if (GFCommon::is_post_field($field)) {
                 $has_post_fields = true;
             }
         }
     }
     /**
      * @since 1.7
      */
     if ($has_post_fields) {
         $fields['post_id'] = array('label' => __('Post ID', 'gravityview'), 'type' => 'post_id');
     }
     if ($has_product_fields) {
         $payment_fields = GravityView_Fields::get_all('pricing');
         foreach ($payment_fields as $payment_field) {
             if (isset($fields["{$payment_field->name}"])) {
                 continue;
             }
             $fields["{$payment_field->name}"] = array('label' => $payment_field->label, 'desc' => $payment_field->description, 'type' => $payment_field->name);
         }
     }
     /**
      * @filter `gravityview/common/get_form_fields` Modify the form fields shown in the Add Field field picker.
      * @since 1.17
      * @param array $fields Associative array of fields, with keys as field type, values an array with the following keys: (string) `label` (required), (string) `type` (required), `desc`, (string) `customLabel`, (GF_Field) `parent`, (string) `adminLabel`, (bool)`adminOnly`
      * @param array $form GF Form array
      * @param bool $include_parent_field Whether to include the parent field when getting a field with inputs
      */
     $fields = apply_filters('gravityview/common/get_form_fields', $fields, $form, $include_parent_field);
     return $fields;
 }
Ejemplo n.º 14
0
 /**
  *
  * Fill-in the saved values into the form inputs
  *
  * @param string $field_content Always empty.
  * @param GF_Field $field
  * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
  * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
  * @param int $form_id Form ID
  *
  * @return mixed
  */
 function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id)
 {
     // If the form has been submitted, then we don't need to pre-fill the values,
     // Except for fileupload type - run always!!
     if ($this->is_edit_entry_submission() && 'fileupload' !== $field->type || GFCommon::is_product_field($field->type)) {
         return $field_content;
     }
     // Turn on Admin-style display for file upload fields only
     if ('fileupload' === $field->type) {
         $_GET['page'] = 'gf_entries';
     }
     // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
     $field->adminOnly = false;
     /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
     // add categories as choices for Post Category field
     if ('post_category' === $field->type) {
         $field = GFCommon::add_categories_as_choices($field, $value);
     }
     // We're dealing with multiple inputs (e.g. checkbox)
     if (isset($field->inputs) && is_array($field->inputs)) {
         $field_value = array();
         // only accept pre-populated values if the field doesn't have any choice selected.
         $allow_pre_populated = true;
         foreach ((array) $field->inputs as $input) {
             $input_id = strval($input['id']);
             if (!empty($this->entry[$input_id])) {
                 $allow_pre_populated = false;
                 $field_value[$input_id] = 'post_category' === $field->type ? GFCommon::format_post_category($this->entry[$input_id], true) : $this->entry[$input_id];
             }
         }
         if ($allow_pre_populated) {
             $field_value = $field->get_value_submission(array(), false);
         }
     } else {
         $id = intval($field->id);
         // get pre-populated value if exists
         $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value($field->inputName, array(), $field) : '';
         // saved field entry value (if empty, fallback to the pre-populated value, if exists)
         $field_value = !empty($this->entry[$id]) ? $this->entry[$id] : $pre_value;
         // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
         if ('post_category' === $field->type && !empty($field_value)) {
             $categories = array();
             foreach (explode(',', $field_value) as $cat_string) {
                 $categories[] = GFCommon::format_post_category($cat_string, true);
             }
             $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode('', $categories);
         }
     }
     // if value is empty get the default value if defined
     $field_value = $field->get_value_default_if_empty($field_value);
     // Prevent any PHP warnings, like undefined index
     ob_start();
     $return = $field->get_field_input($this->form, $field_value, $this->entry);
     // If there was output, it's an error
     $warnings = ob_get_clean();
     if (!empty($warnings)) {
         do_action('gravityview_log_error', __METHOD__ . $warnings);
     }
     /**
      * Unset hack $_GET['page'] = 'gf_entries'
      * We need the fileupload html field to render with the proper id
      *  ( <li id="field_80_16" ... > )
      */
     unset($_GET['page']);
     return $return;
 }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 public static function lead_detail_grid_array($form, $lead)
 {
     $form_id = $form['id'];
     $form_array = self::set_form_array_common($form, $lead, $form_id);
     $has_product_fields = false;
     foreach ($form['fields'] as $field) {
         /*
          * Add field descriptions to the $form_data array 
          */
         if (isset($field['description'])) {
             $form_array['field_descriptions'][$field['id']] = $field['description'];
         }
         switch (RGFormsModel::get_input_type($field)) {
             case 'section':
             case 'html':
                 $form_array = self::get_html($field, $form_array);
                 break;
             case 'captcha':
             case 'password':
             case 'page':
                 //ignore captcha, password and page
                 break;
             case 'signature':
                 $form_array = self::get_signature($form, $lead, $field, $form_array);
                 break;
             case 'fileupload':
                 $form_array = self::get_fileupload($form, $lead, $field, $form_array);
                 break;
             case 'list':
                 /*
                  * We want list to run both this and the deafult so don't call break.
                  * Get the list array and store it outside of [field] in a new key called ['list']
                  */
                 $form_array = self::get_default_list($lead, $field, $form_array);
             case 'select':
             case 'multiselect':
             case 'radio':
                 if ($field['type'] == 'quiz') {
                     $form_array = self::get_quiz_radios($form, $lead, $field, $form_array);
                 } elseif ($field['type'] == 'poll' || $field['type'] == 'survey') {
                     $form_array = self::get_poll_radios($form, $lead, $field, $form_array);
                 } else {
                     /* store values in regular [field] array */
                     $form_array = self::get_the_list($lead, $field, $form_array);
                 }
                 break;
             case 'likert':
                 $form_array['survey']['likert'][$field['id']] = self::get_the_likert($form, $lead, $field, $form_array);
                 break;
             case 'rank':
                 $form_array['survey']['rank'][$field['id']] = self::get_the_rank($form, $lead, $field, $form_array);
                 break;
             case 'rating':
                 $form_array['survey']['rating'][$field['id']] = self::get_the_rank($form, $lead, $field, $form_array);
                 break;
             case 'checkbox':
                 /* Only process non-survey checkbox fields */
                 if ($field['type'] == 'checkbox') {
                     $form_array = self::get_the_list($lead, $field, $form_array);
                     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;
                 }
                 $form_array = self::get_defaults($lead, $field, $form_array);
                 break;
         }
     }
     $form_array = self::get_product_array($form, $lead, $has_product_fields, $form_array);
     return $form_array;
 }
Ejemplo n.º 17
0
    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 
    }
Ejemplo n.º 18
0
    public static function displayGravityForm($entryId, $textMode = false, $email = false)
    {
        $out = '';
        $formId = self::getGravityFormIdForEntry($entryId);
        require_once GFCommon::get_base_path() . "/entry_detail.php";
        $form = RGFormsModel::get_form_meta($formId);
        $lead = RGFormsModel::get_lead($entryId);
        if (!$textMode) {
            ob_start();
            echo '<table class="form-table entry-details"><tbody>';
            $count = 0;
            $field_count = sizeof($form["fields"]);
            foreach ($form["fields"] as $field) {
                $count++;
                $is_last = $count >= $field_count ? true : false;
                switch (RGFormsModel::get_input_type($field)) {
                    case "section":
                        ?>
                  <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":
                        //ignore captcha field
                        break;
                    default:
                        if (GFCommon::is_product_field($field["type"])) {
                            $has_product_fields = true;
                        }
                        $value = RGFormsModel::get_lead_field_value($lead, $field);
                        $display_value = GFCommon::get_lead_field_display($field, $value, $lead["currency"], Cart66Setting::getValue('gravity_display_option_labels'));
                        $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $lead, $form);
                        if (isset($display_empty_fields) && $display_empty_fields || !empty($display_value) || $display_value === "0") {
                            $count++;
                            if (!isset($has_product_fields)) {
                                $has_product_fields = false;
                            }
                            $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;
                            if ($email) {
                                $content = '
                        <tr>
                            <td style="color:#555;font-size:12px;padding:4px 7px;vertical-align:top;text-align:right" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . ': </td>
                            <td style="color:#555;font-size:12px;padding:4px 7px;vertical-align:top" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td>
                        </tr>';
                            } else {
                                $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;
                }
            }
            echo '</tbody></table>';
            $out = ob_get_contents();
            ob_end_clean();
        } else {
            $count = 0;
            $field_count = sizeof($form["fields"]);
            if (is_array($form["fields"])) {
                foreach ($form["fields"] as $field) {
                    $count++;
                    $is_last = $count >= $field_count ? true : false;
                    switch (RGFormsModel::get_input_type($field)) {
                        case "section":
                            $out .= "\t" . GFCommon::get_label($field) . "\n";
                            break;
                        case "captcha":
                        case "html":
                            //ignore captcha field
                            break;
                        default:
                            $value = RGFormsModel::get_lead_field_value($lead, $field);
                            $display_value = strip_tags(str_replace('</li>', "\t\t", GFCommon::get_lead_field_display($field, $value)));
                            if (!empty($display_value) || $display_value === "0") {
                                $out .= "\t" . GFCommon::get_label($field) . ': ';
                                $out .= empty($display_value) && $display_value !== "0" ? " " : $display_value;
                                $out .= "\n";
                            }
                            break;
                    }
                }
            }
            $out .= "\n";
        }
        return $out;
    }