Ejemplo n.º 1
0
function output_data($pdf, $lead = array(), $form = array(), $fieldData = array())
{
    $pdf->AddPage();
    $dataArray = array(array('Project ID #', 3), array('Project Name', 28), array('Name of person responsible for fire safety at your exhibit', 5), array('Their Email', 15), array('Their phone', 16), array('Description', 19), array('Describe your safety concerns', 12), array('Describe how you plan to keep your exhibit safe', 20), array('Who will be assisting at your exhibit to keep it safe', 11), array('Placement Requirements', 7), array('Do you have Insurance', 9), array('Additional Comments', 13), array('Are you 18 years or older?', 23), array('Signed', 25), array('I am the Parent and/or Legal Guardian of', 26), array('Date', 27));
    $pdf->SetFillColor(190, 210, 247);
    $lineheight = 6;
    foreach ($dataArray as $data) {
        $fieldID = $data[1];
        if (isset($fieldData[$fieldID])) {
            $field = $fieldData[$fieldID];
            $value = RGFormsModel::get_lead_field_value($lead, $field);
            if (RGFormsModel::get_input_type($field) != 'email') {
                $display_value = GFCommon::get_lead_field_display($field, $value);
                $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $lead, $form);
            } else {
                $display_value = $value;
            }
        } else {
            $display_value = '';
        }
        $pdf->MultiCell(0, $lineheight, $data[0] . ': ');
        $pdf->MultiCell(0, $lineheight, $display_value, 0, 'L', true);
        $pdf->Ln();
    }
}
Ejemplo n.º 2
0
function output_data($pdf, $lead = array(), $form = array(), $fieldData = array())
{
    $pdf->AddPage();
    $dataArray = array(array('Project ID #', 3, 'text'), array('Project Name', 38, 'text'), array('Name of person responsible for fire safety at your exhibit', 21, 'text'), array('Their Email', 23, 'text'), array('Their Phone', 24, 'text'), array('Description', 37, 'textarea'), array('Describe your fire safety concerns', 19, 'textarea'), array('Describe how you plan to keep your exhibit safe', 27, 'textarea'), array('Who will be assisting at your exhibit to keep it safe', 20, 'text'), array('Placement Requirements', 7, 'textarea'), array('What is burning', 10, 'text'), array('What is the fuel source', 11, 'text'), array('how much is fuel is burning and in what time period', 12, 'textarea'), array('how much fuel will you have at the event, including tank sizes', 13, 'textarea'), array('where and how is the fuel stored', 14, 'text'), array('Does the valve have an electronic propane sniffer', 15, 'text'), array('Other suppression devices', 16, 'textarea'), array('Do you have insurance?', 18, 'text'), array('Additional comments', 28, 'textarea'), array('Are you 18 years or older?', 30, 'text'), array('Signed', 32, 'text'), array('I am the Parent and/or Legal Guardian of', 33, 'text'), array('Date', 34, 'text'));
    $pdf->SetFillColor(190, 210, 247);
    $lineheight = 6;
    foreach ($dataArray as $data) {
        $fieldID = $data[1];
        if (isset($fieldData[$fieldID])) {
            $field = $fieldData[$fieldID];
            $value = RGFormsModel::get_lead_field_value($lead, $field);
            if (RGFormsModel::get_input_type($field) != 'email') {
                $display_value = GFCommon::get_lead_field_display($field, $value);
                $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $lead, $form);
            } else {
                $display_value = $value;
            }
        } else {
            $display_value = '';
        }
        $pdf->MultiCell(0, $lineheight, $data[0] . ': ');
        $pdf->MultiCell(0, $lineheight, $display_value, 0, 'L', true);
        $pdf->Ln();
    }
}
Ejemplo n.º 3
0
 /**
  * Adds special support for file upload, post image and multi input merge tags.
  */
 public static function preview_special_merge_tags($value, $input_id, $merge_tag, $field)
 {
     // added to prevent overriding :noadmin filter (and other filters that remove fields)
     if (!$value) {
         return $value;
     }
     $input_type = RGFormsModel::get_input_type($field);
     $is_upload_field = in_array($input_type, array('post_image', 'fileupload'));
     $is_multi_input = is_array(rgar($field, 'inputs'));
     $is_input = intval($input_id) != $input_id;
     if (!$is_upload_field && !$is_multi_input) {
         return $value;
     }
     // if is individual input of multi-input field, return just that input value
     if ($is_input) {
         return $value;
     }
     $form = RGFormsModel::get_form_meta($field['formId']);
     $lead = self::create_lead($form);
     $currency = GFCommon::get_currency();
     if (is_array(rgar($field, 'inputs'))) {
         $value = RGFormsModel::get_lead_field_value($lead, $field);
         return GFCommon::get_lead_field_display($field, $value, $currency);
     }
     switch ($input_type) {
         case 'fileupload':
             $value = self::preview_image_value("input_{$field['id']}", $field, $form, $lead);
             $value = self::preview_image_display($field, $form, $value);
             break;
         default:
             $value = self::preview_image_value("input_{$field['id']}", $field, $form, $lead);
             $value = GFCommon::get_lead_field_display($field, $value, $currency);
             break;
     }
     return $value;
 }
Ejemplo n.º 4
0
    public static function get_lead_row($lid, $atts, $fields)
    {
        ob_start();
        /*
         * Get our lead information 
         */
        $lead = GFAPI::get_entry($lid);
        /*
         * Update the created by date 
         */
        $lead['date_created_usa'] = date('m/d/Y', strtotime($lead['date_created']));
        $lead['date_created'] = date('d/m/Y', strtotime($lead['date_created']));
        /*
         * Loop through the columns 
         */
        foreach ($atts['columns'] as $cid) {
            ?>
                <td class="gfpdfe_<?php 
            echo $cid;
            ?>
">
                <?php 
            if (is_numeric($cid)) {
                $value = RGFormsModel::get_lead_field_value($lead, $fields[$cid]);
                echo GFPDFEntryDetail::pdf_get_lead_field_display($fields[$cid], $value, $lead['currency']);
            } else {
                echo array_key_exists($cid, $lead) ? $lead[$cid] : '';
            }
            ?>
                </td>
            <?php 
        }
        $html = ob_get_contents();
        ob_end_flush();
        return $html;
    }
 /**
  * Sticky List shortcode function
  *
  */
 function stickylist_shortcode($atts)
 {
     $shortcode_id = shortcode_atts(array('id' => '1', 'user' => '', 'showto' => ''), $atts);
     $form_id = $shortcode_id['id'];
     $user_id = $shortcode_id['user'];
     $showto = $shortcode_id['showto'];
     $form = GFAPI::get_form($form_id);
     $settings = $this->get_form_settings($form);
     $enable_list = $this->get_sticky_setting("enable_list", $settings);
     $show_entries_to = $this->get_sticky_setting("show_entries_to", $settings);
     $max_entries = $this->get_sticky_setting("max_entries", $settings);
     $enable_clickable = $this->get_sticky_setting("enable_clickable", $settings);
     $enable_postlink = $this->get_sticky_setting("enable_postlink", $settings);
     $link_label = $this->get_sticky_setting("link_label", $settings);
     $enable_view = $this->get_sticky_setting("enable_view", $settings);
     $enable_view_label = $this->get_sticky_setting("enable_view_label", $settings);
     $enable_edit = $this->get_sticky_setting("enable_edit", $settings);
     $enable_edit_label = $this->get_sticky_setting("enable_edit_label", $settings);
     $new_entry_id = $this->get_sticky_setting("new_entry_id", $settings);
     $enable_delete = $this->get_sticky_setting("enable_delete", $settings);
     $enable_delete_label = $this->get_sticky_setting("enable_delete_label", $settings);
     $confirm_delete = $this->get_sticky_setting("confirm_delete", $settings);
     $confirm_delete_text = $this->get_sticky_setting("confirm_delete_text", $settings);
     $enable_duplicate = $this->get_sticky_setting("enable_duplicate", $settings);
     $enable_duplicate_label = $this->get_sticky_setting("enable_duplicate_label", $settings);
     $action_column_header = $this->get_sticky_setting("action_column_header", $settings);
     $enable_sort = $this->get_sticky_setting("enable_sort", $settings);
     $initial_sort = $this->get_sticky_setting("initial_sort", $settings);
     $initial_sort_direction = $this->get_sticky_setting("initial_sort_direction", $settings);
     $enable_search = $this->get_sticky_setting("enable_search", $settings);
     $embedd_page = $this->get_sticky_setting("embedd_page", $settings);
     $enable_pagination = $this->get_sticky_setting("enable_pagination", $settings);
     $page_entries = $this->get_sticky_setting("page_entries", $settings);
     if (isset($settings["custom_embedd_page"]) && $settings["custom_embedd_page"] != "") {
         $embedd_page = $settings["custom_embedd_page"];
     }
     if (isset($showto) && $showto != "") {
         $show_entries_to = $showto;
     }
     if ($enable_list) {
         if ($user_id != "") {
             $current_user_id = $user_id;
         } else {
             $current_user_id = $this->stickylist_get_current_user();
         }
         //Set max nr of entries to be shown
         if ($max_entries == "") {
             $max_entries = 999999;
         }
         if ($enable_sort && $initial_sort) {
             if ($initial_sort == "date_added") {
                 $sorting = array();
             } else {
                 $sorting = array('key' => $initial_sort, 'direction' => $initial_sort_direction);
             }
         } else {
             $sorting = array();
         }
         $paging = array('offset' => 0, 'page_size' => $max_entries);
         if ($show_entries_to === "creator") {
             $search_criteria["field_filters"][] = array("key" => "status", "value" => "active");
             $search_criteria["field_filters"][] = array("key" => "created_by", "value" => $current_user_id);
             $entries = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
         } elseif ($show_entries_to === "loggedin") {
             if (is_user_logged_in()) {
                 $search_criteria["field_filters"][] = array("key" => "status", "value" => "active");
                 $entries = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
             }
         } elseif ($show_entries_to === "everyone") {
             $search_criteria["field_filters"][] = array("key" => "status", "value" => "active");
             $entries = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
         } else {
             $user = wp_get_current_user();
             if (in_array($show_entries_to, (array) $user->roles) || in_array("administrator", (array) $user->roles)) {
                 $search_criteria["field_filters"][] = array("key" => "status", "value" => "active");
                 $entries = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
             }
         }
         if (!empty($entries)) {
             if ($initial_sort == "date_added" && $initial_sort_direction == "ASC") {
                 $entries = array_reverse($entries);
             }
             $entries = apply_filters('filter_entries', $entries);
             $list_html = "<div id='sticky-list-wrapper_{$form_id}'>";
             if ($enable_sort && $enable_search) {
                 $list_html .= "<input class='search' placeholder='" . __("Search", "sticky-list") . "' />";
             }
             $list_html .= "<table class='sticky-list'><thead><tr>";
             $fields = $form["fields"];
             $i = 0;
             foreach ($fields as $field) {
                 if (isset($field["stickylistField"]) && $field["stickylistField"] != "") {
                     if (isset($field["stickylistFieldLabel"]) && $field["stickylistFieldLabel"] != "") {
                         $label = $field["stickylistFieldLabel"];
                     } else {
                         $label = $field["label"];
                     }
                     $class_label = "header-" . str_replace(" ", "-", strtolower($label));
                     $list_html .= "<th class='sort {$class_label}' data-sort='sort-{$i}'>{$label}</th>";
                     $i++;
                 }
             }
             if ($enable_view || $enable_edit || $enable_delete || $enable_postlink || $enable_duplicate) {
                 $list_html .= "<th class='sticky-action'>{$action_column_header}</th>";
             }
             $list_html .= "</tr></thead><tbody class='list'>";
             foreach ($entries as $entry) {
                 $entry_id = $entry["id"];
                 $list_html .= "<tr>";
                 $i = 0;
                 foreach ($form["fields"] as $field) {
                     if (isset($field["stickylistField"]) && $field["stickylistField"] != "") {
                         $field_value = RGFormsModel::get_lead_field_value($entry, $field);
                         $tdClass = "stickylist-" . $field["type"];
                         $nowrap = "";
                         if (isset($field["stickylistFieldNoWrap"]) && $field["stickylistFieldNoWrap"] != "") {
                             $nowrap = " sticky-nowrap";
                         }
                         if ($field["type"] == "post_custom_field" && $field["inputType"] == "fileupload") {
                             $custom_file_upload = true;
                         } else {
                             $custom_file_upload = false;
                         }
                         if ($field["type"] == "product" || $field["type"] == "shipping" || $field["type"] == "option") {
                             if (is_array($field_value)) {
                                 if ($field["type"] == "option") {
                                     foreach ($field_value as &$option) {
                                         $option = substr($option, 0, strpos($option, "|"));
                                     }
                                     $field_value = array_filter($field_value);
                                     $field_value = implode(", ", $field_value);
                                 } else {
                                     $field_value = end($field_value);
                                 }
                                 $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$field_value}</td>";
                             } else {
                                 $field_value = substr($field_value, 0, strpos($field_value, "|"));
                                 $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$field_value}</td>";
                             }
                         } elseif (is_array($field_value)) {
                             ksort($field_value);
                             $field_values = "";
                             foreach ($field_value as $field => $value) {
                                 $field_values .= $value . " ";
                             }
                             $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$field_values}</td>";
                         } elseif ($field["type"] == "fileupload" || $field["type"] == "post_image" || $custom_file_upload == true) {
                             $field_value = strtok($field_value, "|");
                             $file_name = basename($field_value);
                             if ($enable_clickable && $field_value != "") {
                                 $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'><a href='{$field_value}'>{$file_name}</a></td>";
                             } else {
                                 $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$file_name}</td>";
                             }
                         } elseif ($field["type"] == "date" && $field_value != "") {
                             $field_value = $this->format_the_date($field_value, $field["dateFormat"]);
                             $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$field_value}</td>";
                         } elseif ($field["type"] == "website" && $field_value != "") {
                             $tdClass = "stickylist-url";
                             $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'><a href='{$field_value}'>{$field_value}</a></td>";
                         } elseif ($field["type"] == "post_category" && $field_value != "") {
                             $tdClass = "stickylist-category";
                             $field_value = strtok($field_value, ":");
                             $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$field_value}</td>";
                         } elseif ($field["type"] == "list" && $field_value != "") {
                             if (is_array(maybe_unserialize($field_value))) {
                                 $list = maybe_unserialize($field_value);
                                 $field_value = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator($list)), FALSE);
                                 $field_value = implode(", ", $field_value);
                                 $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$field_value}</td>";
                             }
                         } else {
                             $list_html .= "<td class='sort-{$i} {$nowrap} {$tdClass}'>{$field_value}</td>";
                         }
                         $i++;
                     }
                 }
                 if ($enable_view || $enable_edit || $enable_delete || $enable_postlink || $enable_duplicate) {
                     $list_html .= "<td class='sticky-action'>";
                     if ($enable_view) {
                         $list_html .= "\n                                        <form action='{$embedd_page}' method='post'>\n                                            <button class='sticky-list-view submit'>{$enable_view_label}</button>\n                                            <input type='hidden' name='mode' value='view'>\n                                            <input type='hidden' name='view_id' value='{$entry_id}'>\n                                        </form>";
                     }
                     if ($enable_edit) {
                         if ($entry["created_by"] == $this->stickylist_get_current_user() || current_user_can('edit_others_posts') || current_user_can('stickylist_edit_entries')) {
                             $list_html .= "\n                                            <form action='{$embedd_page}' method='post'>\n                                                <button class='sticky-list-edit submit'>{$enable_edit_label}</button>\n                                                <input type='hidden' name='mode' value='edit'>\n                                                <input type='hidden' name='edit_id' value='{$entry_id}'>\n                                            </form>";
                         }
                     }
                     if ($enable_delete) {
                         if ($entry["created_by"] == $this->stickylist_get_current_user() || current_user_can('delete_others_posts') || current_user_can('stickylist_delete_entries')) {
                             $list_html .= "\n                                            <button class='sticky-list-delete submit'>{$enable_delete_label}</button>\n                                            <input type='hidden' name='delete_id' class='sticky-list-delete-id' value='{$entry_id}'>\n                                        ";
                             if ($entry["post_id"] != null) {
                                 $delete_post_id = $entry["post_id"];
                                 $list_html .= "<input type='hidden' name='delete_post_id' class='sticky-list-delete-post-id' value='{$delete_post_id}'>";
                             }
                         }
                     }
                     if ($enable_postlink && $entry["post_id"] != NULL) {
                         $permalink = get_permalink($entry["post_id"]);
                         $list_html .= "<button class='sticky-list-postlink submit' onclick='document.location.href=\"{$permalink}\"'>{$link_label}</button>";
                     }
                     if ($enable_duplicate) {
                         $list_html .= "\n                                        <form action='{$embedd_page}' method='post'>\n                                            <button class='sticky-list-duplicate submit'>{$enable_duplicate_label}</button>\n                                            <input type='hidden' name='mode' value='duplicate'>\n                                            <input type='hidden' name='duplicate_id' value='{$entry_id}'>\n                                        </form>";
                     }
                     $list_html .= "</td>";
                 }
                 $list_html .= "</tr>";
             }
             $list_html .= "</tbody></table>";
             if ($enable_pagination && $page_entries < count($entries)) {
                 $list_html .= "<ul class='pagination'></ul>";
             }
             $list_html .= "</div>";
             if ($enable_sort || $enable_pagination) {
                 $sort_fileds = "";
                 for ($a = 0; $a < $i; $a++) {
                     $sort_fileds .= "'sort-{$a}',";
                 }
                 $list_html .= "<script src='" . plugins_url('gravity-forms-sticky-list/js/list.min.js') . "'></script>";
                 if ($enable_pagination) {
                     $list_html .= "<script src='" . plugins_url('gravity-forms-sticky-list/js/list.pagination.min.js') . "'></script>";
                 }
                 if ($enable_sort && $enable_pagination) {
                     $list_html .= "<script>var options = { valueNames: [{$sort_fileds}], page: {$page_entries}, plugins: [ ListPagination({ outerWindow: 1 }) ] };var userList = new List('sticky-list-wrapper_{$form_id}', options); function callback() { window.listUpdated() } userList.on('updated', callback);</script><style>table.sticky-list th:not(.sticky-action) {cursor: pointer;}</style>";
                 } elseif ($enable_sort && !$enable_pagination) {
                     $list_html .= "<script>var options = { valueNames: [{$sort_fileds}] };var userList = new List('sticky-list-wrapper_{$form_id}', options);</script><style>table.sticky-list th:not(.sticky-action) {cursor: pointer;}</style>";
                 } elseif (!$enable_sort && $enable_pagination) {
                     $list_html .= "<script>var options = { valueNames: ['xxx'], page: {$page_entries}, plugins: [ ListPagination({ outerWindow: 1 }) ] };var userList = new List('sticky-list-wrapper_{$form_id}', options); function callback() { window.listUpdated() } userList.on('updated', callback);</script></style>";
                 }
             }
             if ($enable_delete) {
                 $ajax_delete = plugin_dir_url(__FILE__) . 'ajax-delete.php';
                 $ajax_spinner = plugin_dir_url(__FILE__) . 'img/ajax-spinner.gif';
                 $delete_failed = __('Delete failed', 'sticky-list');
                 $list_html .= "\n                            <img src='{$ajax_spinner}' style='display: none;'>\n                            <script>\n                            jQuery(document).ready(function(\$) {\n\n                                window.listUpdated = function(){\n\n                                    \$('.sticky-list-delete').click(function(event) {\n\n                                        event.stopImmediatePropagation()\n                                    \n                                        var delete_id       = \$(this).siblings('.sticky-list-delete-id').val();\n                                        var delete_post_id  = \$(this).siblings('.sticky-list-delete-post-id').val();\n                                        var current_button  = \$(this);\n                                        var current_row     = current_button.parent().parent();\n                                        var confirm_delete  = {$confirm_delete};\n                                        \n                                        if(confirm_delete == 1) {\n                                            var confirm_dialog = confirm('{$confirm_delete_text}');\n                                        }                         \n\n                                        if (confirm_dialog == true || confirm_delete != 1) {\n\n                                            current_button.html('<img src=\\'{$ajax_spinner}\\'>');\n                                            \n                                            \$.post( '', { mode: 'delete', delete_id: delete_id, delete_post_id: delete_post_id, form_id: '{$form_id}' })\n                                            .done(function() {\n                                                current_button.html('');\n                                                current_row.css({   \n                                                    background: '#fbdcdc',\n                                                    color: '#fff'\n                                                });\n                                                current_row.hide('slow');\n                                            })\n                                            .fail(function() {\n                                                current_button.html('{$delete_failed}');\n                                            })\n                                        }\n                                    });   \n                                }\n\n                                window.listUpdated();\n                            });\n                            </script>\n                        ";
             }
         } else {
             $list_html = $settings["empty_list_text"] . "<br>";
         }
         return $list_html;
     }
 }
 public static function replace_field_variable($text, $form, $lead, $url_encode, $esc_html, $nl2br, $format, $input_id, $match, $esc_attr = false)
 {
     $field = RGFormsModel::get_field($form, $input_id);
     if (!$field instanceof GF_Field) {
         $field = GF_Fields::create($field);
     }
     $value = RGFormsModel::get_lead_field_value($lead, $field);
     $raw_value = $value;
     if (is_array($value)) {
         $value = rgar($value, $input_id);
     }
     $value = self::format_variable_value($value, $url_encode, $esc_html, $format, $nl2br);
     // modifier will be at index 4 unless used in a conditional shortcode in which case it would be at index 5
     $i = $match[0][0] == '{' ? 4 : 5;
     $modifier = strtolower(rgar($match, $i));
     $value = $field->get_value_merge_tag($value, $input_id, $lead, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br);
     if (!in_array($field->type, array('html', 'section', 'signature'))) {
         $value = self::encode_shortcodes($value);
     }
     if ($esc_attr) {
         $value = esc_attr($value);
     }
     if ($modifier == 'label') {
         $value = empty($value) ? '' : $field->label;
     } else {
         if ($modifier == 'qty' && $field->type == 'product') {
             //getting quantity associated with product field
             $products = self::get_product_fields($form, $lead, false, false);
             $value = 0;
             foreach ($products['products'] as $product_id => $product) {
                 if ($product_id == $field->id) {
                     $value = $product['quantity'];
                 }
             }
         }
     }
     //Encoding left curly bracket so that merge tags entered in the front end are displayed as is and not parsed
     $value = self::encode_merge_tag($value);
     //filter can change merge tag value
     $value = apply_filters('gform_merge_tag_filter', $value, $input_id, $modifier, $field, $raw_value);
     if ($value === false) {
         $value = '';
     }
     if ($match[0][0] != '{') {
         // replace the merge tag in the conditional shortcode merge_tag attr
         $value = str_replace($match[1], $value, $match[0]);
     }
     $text = str_replace($match[0], $value, $text);
     return $text;
 }
Ejemplo n.º 7
0
 /**
  * Get items
  *
  * @see Pronamic_Pay_PaymentDataInterface::get_items()
  * @return Pronamic_IDeal_Items
  */
 public function get_items()
 {
     $items = new Pronamic_IDeal_Items();
     $number = 0;
     // Products
     $products = GFCommon::get_product_fields($this->form, $this->lead);
     foreach ($products['products'] as $product) {
         $description = $product['name'];
         $price = GFCommon::to_number($product['price']);
         $quantity = $product['quantity'];
         $item = new Pronamic_IDeal_Item();
         $item->setNumber($number++);
         $item->setDescription($description);
         $item->setPrice($price);
         $item->setQuantity($quantity);
         $items->addItem($item);
         if (isset($product['options']) && is_array($product['options'])) {
             foreach ($product['options'] as $option) {
                 $description = $option['option_label'];
                 $price = GFCommon::to_number($option['price']);
                 $item = new Pronamic_IDeal_Item();
                 $item->setNumber($number++);
                 $item->setDescription($description);
                 $item->setPrice($price);
                 $item->setQuantity($quantity);
                 // Product quantity
                 $items->addItem($item);
             }
         }
     }
     // Shipping
     if (isset($products['shipping'])) {
         $shipping = $products['shipping'];
         if (isset($shipping['price']) && !empty($shipping['price'])) {
             $description = $shipping['name'];
             $price = GFCommon::to_number($shipping['price']);
             $quantity = 1;
             $item = new Pronamic_IDeal_Item();
             $item->setNumber($number++);
             $item->setDescription($description);
             $item->setPrice($price);
             $item->setQuantity($quantity);
             $items->addItem($item);
         }
     }
     // Donations
     $donation_fields = GFCommon::get_fields_by_type($this->form, array('donation'));
     foreach ($donation_fields as $i => $field) {
         $value = RGFormsModel::get_lead_field_value($this->lead, $field);
         if (!empty($value)) {
             $description = '';
             if (isset($field['adminLabel']) && !empty($field['adminLabel'])) {
                 $description = $field['adminLabel'];
             } elseif (isset($field['label'])) {
                 $description = $field['label'];
             }
             $separator_position = strpos($value, '|');
             if (false !== $separator_position) {
                 $label = substr($value, 0, $separator_position);
                 $value = substr($value, $separator_position + 1);
                 $description .= ' - ' . $label;
             }
             $price = GFCommon::to_number($value);
             $quantity = 1;
             $item = new Pronamic_IDeal_Item();
             $item->setNumber($i);
             $item->setDescription($description);
             $item->setQuantity($quantity);
             $item->setPrice($price);
             $items->addItem($item);
         }
     }
     return $items;
 }
Ejemplo n.º 8
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.º 9
0
 /**
  * Given an entry and a form field id, calculate the entry value for that field.
  *
  * @access public
  * @param array $entry
  * @param integer $field
  * @return null|string
  */
 public static function field_value($entry, $field_settings, $format = 'html')
 {
     if (empty($entry['form_id']) || empty($field_settings['id'])) {
         return NULL;
     }
     $gravityview_view = GravityView_View::getInstance();
     if (class_exists('GFCache')) {
         /**
          * Gravity Forms' GFCache function was thrashing the database, causing double the amount of time for the field_value() method to run.
          *
          * The reason is that the cache was checking against a field value stored in a transient every time `GFFormsModel::get_lead_field_value()` is called.
          *
          * What we're doing here is telling the GFCache that it's already checked the transient and the value is false, forcing it to just use the non-cached data, which is actually faster.
          *
          * @hack
          * @since  1.3
          * @param  string $cache_key Field Value transient key used by Gravity Forms
          * @param mixed false Setting the value of the cache to false so that it's not used by Gravity Forms' GFFormsModel::get_lead_field_value() method
          * @param boolean false Tell Gravity Forms not to store this as a transient
          * @param  int 0 Time to store the value. 0 is maximum amount of time possible.
          */
         GFCache::set("GFFormsModel::get_lead_field_value_" . $entry["id"] . "_" . $field_settings["id"], false, false, 0);
     }
     $field_id = $field_settings['id'];
     $form = $gravityview_view->getForm();
     $field = gravityview_get_field($form, $field_id);
     $field_type = RGFormsModel::get_input_type($field);
     if ($field_type) {
         $field_type = $field['type'];
         $value = RGFormsModel::get_lead_field_value($entry, $field);
     } else {
         // For non-integer field types (`id`, `date_created`, etc.)
         $field_type = $field_id;
         $field['type'] = $field_id;
         $value = isset($entry[$field_type]) ? $entry[$field_type] : NULL;
     }
     // Prevent any PHP warnings that may be generated
     ob_start();
     $display_value = GFCommon::get_lead_field_display($field, $value, $entry["currency"], false, $format);
     if ($errors = ob_get_clean()) {
         do_action('gravityview_log_error', 'GravityView_API[field_value] Errors when calling GFCommon::get_lead_field_display()', $errors);
     }
     $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $entry, $form);
     // prevent the use of merge_tags for non-admin fields
     if (!empty($field['adminOnly'])) {
         $display_value = self::replace_variables($display_value, $form, $entry);
     }
     // Check whether the field exists in /includes/fields/{$field_type}.php
     // This can be overridden by user template files.
     $field_exists = $gravityview_view->locate_template("fields/{$field_type}.php");
     // Set the field data to be available in the templates
     $gravityview_view->setCurrentField(array('form' => $form, 'field_id' => $field_id, 'field' => $field, 'field_settings' => $field_settings, 'value' => $value, 'display_value' => $display_value, 'format' => $format, 'entry' => $entry, 'field_type' => $field_type));
     if ($field_exists) {
         do_action('gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_exists));
         ob_start();
         load_template($field_exists, false);
         $output = ob_get_clean();
     } else {
         // Backup; the field template doesn't exist.
         $output = $display_value;
     }
     $field_settings = $gravityview_view->getCurrentField('field_settings');
     /**
      * Link to the single entry by wrapping the output in an anchor tag
      *
      * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
      *
      */
     if (!empty($field_settings['show_as_link'])) {
         $output = self::entry_link_html($entry, $output, array(), $field_settings);
     }
     /**
      * @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number`
      * @since 1.6
      * @param string $output HTML value output
      * @param array  $entry The GF entry array
      * @param  array $field_settings Settings for the particular GV field
      */
     $output = apply_filters('gravityview_field_entry_value_' . $field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     /**
      * @filter `gravityview_field_entry_value` Modify the field value output for all field types
      * @param string $output HTML value output
      * @param array  $entry The GF entry array
      * @param  array $field_settings Settings for the particular GV field
      * @param array $field_data  {@since 1.6}
      */
     $output = apply_filters('gravityview_field_entry_value', $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     return $output;
 }
Ejemplo n.º 10
0
 /**
  * Return an array of results including HTML formatted data.
  *
  * @param array $form The current form.
  * @param array $lead The current entry.
  * @param bool $show_question Indicates if the quiz question (label) should also be included in the markup.
  *
  * @return array
  */
 public function get_quiz_results($form, $lead = array(), $show_question = true)
 {
     $total_score = 0;
     $output['fields'] = array();
     $output['summary'] = '<div class="gquiz-container">';
     $fields = GFAPI::get_fields_by_type($form, array('quiz'));
     $pass_percent = $this->get_form_setting($form, 'passPercent');
     $grades = $this->get_form_setting($form, 'grades');
     $max_score = $this->get_max_score($form);
     foreach ($fields as $field) {
         $weighted_score_enabled = $field->gquizWeightedScoreEnabled;
         $value = RGFormsModel::get_lead_field_value($lead, $field);
         $field_score = 0;
         $field_markup = '<div class="gquiz-field">';
         if ($show_question) {
             $field_markup .= '    <div class="gquiz-field-label">';
             $field_markup .= GFCommon::get_label($field);
             $field_markup .= '    </div>';
         }
         $field_markup .= '    <div class="gquiz-field-choice">';
         $field_markup .= '    <ul>';
         // for checkbox inputs with multiple correct choices
         $completely_correct = true;
         $choices = $field->choices;
         foreach ($choices as $choice) {
             $is_choice_correct = isset($choice['gquizIsCorrect']) && $choice['gquizIsCorrect'] == '1' ? true : false;
             $choice_weight = isset($choice['gquizWeight']) ? (double) $choice['gquizWeight'] : 1;
             $choice_class = $is_choice_correct ? 'gquiz-correct-choice ' : '';
             $response_matches_choice = false;
             $user_responded = true;
             if (is_array($value)) {
                 foreach ($value as $item) {
                     if (RGFormsModel::choice_value_match($field, $choice, $item)) {
                         $response_matches_choice = true;
                         break;
                     }
                 }
             } elseif (empty($value)) {
                 $response_matches_choice = false;
                 $user_responded = false;
             } else {
                 $response_matches_choice = RGFormsModel::choice_value_match($field, $choice, $value) ? true : false;
             }
             $is_response_correct = $is_choice_correct && $response_matches_choice;
             if ($response_matches_choice && $weighted_score_enabled) {
                 $field_score += $choice_weight;
             }
             if ($field->inputType == 'checkbox') {
                 $is_response_wrong = !$is_choice_correct && $response_matches_choice || $is_choice_correct && !$response_matches_choice || $is_choice_correct && !$user_responded;
             } else {
                 $is_response_wrong = !$is_choice_correct && $response_matches_choice || $is_choice_correct && !$user_responded;
             }
             $indicator_markup = '';
             if ($is_response_correct) {
                 $indicator_markup = '<img src="' . $this->_correct_indicator_url . '" />';
                 $choice_class .= 'gquiz-correct-response ';
             } elseif ($is_response_wrong) {
                 $indicator_markup = '<img src="' . $this->_incorrect_indicator_url . '" />';
                 $completely_correct = false;
                 $choice_class .= 'gquiz-incorrect-response ';
             }
             /**
              * More control over the indication for any type of answer
              *
              * @param string $indicator_markup The indicator HTML/text for an answer
              * @param array $form The Form object to filter through
              * @param array $field The Field Object to filter through
              * @param mixed $choice The Choice object for the quiz
              * @param array $lead The Lead Object to filter through
              * @param bool $is_response_correct True or false if the response is correct, can be used to change indicators
              * @param bool $is_response_wrong True or false if the response is incorrect, can be used to change indicators
              */
             $indicator_markup = apply_filters('gquiz_answer_indicator', $indicator_markup, $form, $field, $choice, $lead, $is_response_correct, $is_response_wrong);
             $choice_class_markup = empty($choice_class) ? '' : 'class="' . $choice_class . '"';
             $field_markup .= "<li {$choice_class_markup}>";
             $field_markup .= $choice['text'] . $indicator_markup;
             $field_markup .= '</li>';
         }
         // end foreach choice
         $field_markup .= '    </ul>';
         $field_markup .= '    </div>';
         if ($field->gquizShowAnswerExplanation) {
             $field_markup .= '<div class="gquiz-answer-explanation">';
             $field_markup .= $field->gquizAnswerExplanation;
             $field_markup .= '</div>';
         }
         $field_markup .= '</div>';
         if (!$weighted_score_enabled && $completely_correct) {
             $field_score += 1;
         }
         $output['summary'] .= $field_markup;
         array_push($output['fields'], array('id' => $field->id, 'markup' => $field_markup, 'is_correct' => $completely_correct, 'score' => $field_score));
         $total_score += $field_score;
     }
     // end foreach field
     $total_score = max($total_score, 0);
     $output['summary'] .= '</div>';
     $output['score'] = $total_score;
     $total_percent = $max_score > 0 ? $total_score / $max_score * 100 : 0;
     $output['percent'] = round($total_percent);
     $total_grade = $this->get_grade($grades, $total_percent);
     $output['grade'] = $total_grade;
     $is_pass = $total_percent >= $pass_percent ? true : false;
     $output['is_pass'] = $is_pass;
     return $output;
 }
 public static function get_default_field_results($form_id, $field, $search_criteria, $offset, $page_size)
 {
     $field_results = "";
     $paging = array('offset' => $offset, 'page_size' => $page_size);
     $sorting = array('key' => "date_created", 'direction' => "DESC");
     $leads = GFFormsModel::search_leads($form_id, $search_criteria, $sorting, $paging);
     foreach ($leads as $lead) {
         $value = RGFormsModel::get_lead_field_value($lead, $field);
         $content = apply_filters("gform_entries_field_value", $value, $form_id, $field["id"], $lead);
         $field_results .= "<li>{$content}</li>";
     }
     return $field_results;
 }
Ejemplo n.º 12
0
 /**
  * Cycles through all entries, counts responses and returns an associative array with the data for each field.
  * It's then optionally cached later according to the user settings.
  *
  * @param int $form_id The form ID.
  * @param array $gpoll_data The poll results data.
  *
  * @return array
  */
 public function gpoll_get_data($form_id, $gpoll_data = array())
 {
     $time_start = microtime(true);
     $max_execution_time = 20;
     //seconds
     $totals = RGFormsModel::get_form_counts($form_id);
     $total = $totals['total'];
     $form_meta = RGFormsModel::get_form_meta($form_id);
     $form_meta = apply_filters("gform_polls_form_pre_results_{$form_id}", apply_filters('gform_polls_form_pre_results', $form_meta));
     $poll_fields = array();
     foreach ($form_meta['fields'] as $field) {
         if ($field->type !== 'poll') {
             continue;
         }
         $poll_fields[] = clone $field;
     }
     $sort_field_number = 0;
     $sort_direction = 'DESC';
     $search = '';
     $offset = 0;
     $page_size = 200;
     $star = null;
     $read = null;
     $is_numeric_sort = false;
     $start_date = null;
     $end_date = null;
     $status = 'active';
     $field_counter = 0;
     if (empty($gpoll_data)) {
         //first build list of fields to count and later count the entries
         //it's split up this way to avoid a timeout on large resultsets
         foreach ($poll_fields as $poll_field) {
             $fieldid = $poll_field->id;
             $gpoll_field_data = array('field_label' => $poll_field->label, 'field_id' => $fieldid, 'type' => $poll_field->type, 'inputType' => $poll_field->inputType);
             $gpoll_data['fields'][$field_counter] = $gpoll_field_data;
             $gpoll_input_data = array();
             //for checkboxes
             if ($poll_field->inputType == 'checkbox') {
                 $input_counter = 0;
                 foreach ($poll_field->inputs as $input) {
                     $inputid = str_replace('.', '_', $input['id']);
                     $gpoll_input_data = array('input_id' => "#choice_{$inputid}", 'label' => $input['label']);
                     $gpoll_data['fields'][$field_counter]['inputs'][$input_counter] = $gpoll_input_data;
                     $input_counter += 1;
                 }
             } else {
                 //for radio & dropdowns
                 $choice_counter = 0;
                 if ($poll_field->enableOtherChoice) {
                     $choice_index = count($poll_field->choices);
                     $choices = $poll_field->choices;
                     $choices[$choice_index]['text'] = esc_html__('Other', 'gravityformspolls');
                     $choices[$choice_index]['value'] = 'gpoll_other';
                     $poll_field->choices = $choices;
                 }
                 foreach ($poll_field->choices as $choice) {
                     $gpoll_input_data = array('input_id' => "#choice_{$fieldid}_{$choice_counter}", 'label' => $choice['text']);
                     $gpoll_data['fields'][$field_counter]['inputs'][$choice_counter] = $gpoll_input_data;
                     $choice_counter += 1;
                 }
             }
             $field_counter += 1;
             $i = $offset;
         }
     } else {
         $i = $gpoll_data['offset'];
         unset($gpoll_data['offset']);
     }
     $precision = apply_filters('gform_polls_percentage_precision', 0, $form_id);
     //get leads in groups of $page_size to avoid timeouts
     while ($i <= $total) {
         $field_counter = 0;
         $get_leads_time_start = microtime(true);
         $entries = RGFormsModel::get_leads($form_id, $sort_field_number, $sort_direction, $search, $i, $page_size, null, null, false, null, null);
         $get_leads_time_end = microtime(true);
         $get_leads_time = $get_leads_time_end - $get_leads_time_start;
         //loop through each field currently on the form and count the entries for each choice
         foreach ($poll_fields as $poll_field) {
             if (isset($gpoll_data['fields'][$field_counter]['total_entries'])) {
                 $field_total_entries = $gpoll_data['fields'][$field_counter]['total_entries'];
             } else {
                 $field_total_entries = 0;
             }
             foreach ($entries as $entry) {
                 $entry_value = RGFormsModel::get_lead_field_value($entry, $poll_field);
                 if (false === empty($entry_value)) {
                     $field_total_entries++;
                 }
             }
             $gpoll_data['fields'][$field_counter]['total_entries'] = $field_total_entries;
             $gpoll_input_data = array();
             // checkboxes store entries differently to radio & dropdowns
             if ($poll_field->inputType == 'checkbox') {
                 //for checkboxes
                 // loop through all the choices and count the entries for each choice
                 $input_counter = 0;
                 foreach ($poll_field->inputs as $input) {
                     // running total of entries for each set of entries
                     if (isset($gpoll_data['fields'][$field_counter]['inputs'][$input_counter]['total_entries'])) {
                         $total_entries = $gpoll_data['fields'][$field_counter]['inputs'][$input_counter]['total_entries'];
                     } else {
                         $total_entries = 0;
                     }
                     $entry_index = 1;
                     // loop through all the entries and count the entries for the choice
                     foreach ($entries as $entry) {
                         // loop through each item in the lead object and pick out the entries for this field id
                         foreach ($entry as $key => $entry_value) {
                             // checkboxes store the key as [field number].[input index] (e.g. 2.1 or 2.2)
                             // so convert to integer to identify all the responses inside the lead object for this field id
                             if (intval($key) == $poll_field->id) {
                                 //compare the user's response with the current choice
                                 if ($entry_value == $poll_field->choices[$input_counter]['value']) {
                                     // found a response for this choice so continue to the next lead
                                     $total_entries++;
                                     break;
                                 }
                             }
                         }
                         $entry_index += 1;
                     }
                     //calculate the ratio of total number of responses counted to the total number of entries for this form
                     $ratio = 0;
                     if ($field_total_entries != 0) {
                         $ratio = round($total_entries / $field_total_entries * 100, $precision);
                     }
                     //store the data
                     $gpoll_data['fields'][$field_counter]['inputs'][$input_counter]['value'] = $poll_field->choices[$input_counter]['value'];
                     $gpoll_data['fields'][$field_counter]['inputs'][$input_counter]['total_entries'] = $total_entries;
                     $gpoll_data['fields'][$field_counter]['inputs'][$input_counter]['ratio'] = $ratio;
                     $input_counter += 1;
                 }
             } else {
                 // for radio & dropdowns
                 $choice_counter = 0;
                 // loop through each choice and count the responses
                 foreach ($poll_field->choices as $choice) {
                     // running total of entries for each set of entries
                     if (isset($gpoll_data['fields'][$field_counter]['inputs'][$choice_counter]['total_entries'])) {
                         $total_entries = $gpoll_data['fields'][$field_counter]['inputs'][$choice_counter]['total_entries'];
                     } else {
                         $total_entries = 0;
                     }
                     // count responses for 'Other'
                     if (rgar($choice, 'value') == 'gpoll_other') {
                         $possible_choices = array();
                         foreach ($poll_field->choices as $possible_choice) {
                             array_push($possible_choices, rgar($possible_choice, 'value'));
                         }
                         foreach ($entries as $entry) {
                             $entry_value = RGFormsModel::get_lead_field_value($entry, $poll_field);
                             if (!empty($entry_value) && !in_array($entry_value, $possible_choices)) {
                                 $total_entries++;
                             }
                         }
                     } else {
                         // count entries
                         foreach ($entries as $entry) {
                             $entry_value = RGFormsModel::get_lead_field_value($entry, $poll_field);
                             if ($entry_value === rgar($choice, 'value')) {
                                 $total_entries++;
                             }
                         }
                     }
                     // calculate the ratio of total number of responses counted to the total number of entries for this form
                     $ratio = 0;
                     if ($field_total_entries != 0) {
                         $ratio = round($total_entries / $field_total_entries * 100, $precision);
                     }
                     //store the data
                     $gpoll_data['fields'][$field_counter]['inputs'][$choice_counter]['value'] = rgar($choice, 'value');
                     $gpoll_data['fields'][$field_counter]['inputs'][$choice_counter]['total_entries'] = $total_entries;
                     $gpoll_data['fields'][$field_counter]['inputs'][$choice_counter]['ratio'] = $ratio;
                     $choice_counter += 1;
                 }
             }
             $field_counter += 1;
         }
         $i += $page_size;
         $time_end = microtime(true);
         $execution_time = $time_end - $time_start;
         $gpoll_data['execution_time'] = isset($gpoll_data['execution_time']) ? $gpoll_data['execution_time'] + $execution_time : $execution_time;
         $gpoll_data['incomplete'] = false;
         if ($execution_time + $get_leads_time > $max_execution_time) {
             $gpoll_data['incomplete'] = true;
             $gpoll_data['offset'] = $i;
             break;
         }
     }
     //end while
     return $gpoll_data;
 }
Ejemplo n.º 13
0
 /**
  * Given an entry and a form field id, calculate the entry value for that field.
  *
  * @access public
  * @param array $entry
  * @param array $field
  * @return null|string
  */
 public static function field_value($entry, $field_settings, $format = 'html')
 {
     if (empty($entry['form_id']) || empty($field_settings['id'])) {
         return NULL;
     }
     $gravityview_view = GravityView_View::getInstance();
     $field_id = $field_settings['id'];
     $form = $gravityview_view->getForm();
     $field = gravityview_get_field($form, $field_id);
     if ($field && is_numeric($field_id)) {
         // Used as file name of field template in GV.
         // Don't use RGFormsModel::get_input_type( $field ); we don't care if it's a radio input; we want to know it's a 'quiz' field
         $field_type = $field->type;
         $value = RGFormsModel::get_lead_field_value($entry, $field);
     } else {
         $field = GravityView_Fields::get_associated_field($field_id);
         $field_type = $field_id;
         // Used as file name of field template in GV
     }
     // If a Gravity Forms Field is found, get the field display
     if ($field) {
         // Prevent any PHP warnings that may be generated
         ob_start();
         $display_value = GFCommon::get_lead_field_display($field, $value, $entry["currency"], false, $format);
         if ($errors = ob_get_clean()) {
             do_action('gravityview_log_error', 'GravityView_API[field_value] Errors when calling GFCommon::get_lead_field_display()', $errors);
         }
         $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $entry, $form);
         // prevent the use of merge_tags for non-admin fields
         if (!empty($field->adminOnly)) {
             $display_value = self::replace_variables($display_value, $form, $entry);
         }
     } else {
         $value = $display_value = rgar($entry, $field_id);
         $display_value = $value;
     }
     // Check whether the field exists in /includes/fields/{$field_type}.php
     // This can be overridden by user template files.
     $field_path = $gravityview_view->locate_template("fields/{$field_type}.php");
     // Set the field data to be available in the templates
     $gravityview_view->setCurrentField(array('form' => $form, 'field_id' => $field_id, 'field' => $field, 'field_settings' => $field_settings, 'value' => $value, 'display_value' => $display_value, 'format' => $format, 'entry' => $entry, 'field_type' => $field_type, 'field_path' => $field_path));
     if (!empty($field_path)) {
         do_action('gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_path));
         ob_start();
         load_template($field_path, false);
         $output = ob_get_clean();
     } else {
         // Backup; the field template doesn't exist.
         $output = $display_value;
     }
     // Get the field settings again so that the field template can override the settings
     $field_settings = $gravityview_view->getCurrentField('field_settings');
     /**
      * @filter `gravityview_field_entry_value_{$field_type}_pre_link` Modify the field value output for a field type before Show As Link setting is applied. Example: `gravityview_field_entry_value_number_pre_link`
      * @since 1.16
      * @param string $output HTML value output
      * @param array  $entry The GF entry array
      * @param array  $field_settings Settings for the particular GV field
      * @param array  $field Field array, as fetched from GravityView_View::getCurrentField()
      */
     $output = apply_filters('gravityview_field_entry_value_' . $field_type . '_pre_link', $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     /**
      * Link to the single entry by wrapping the output in an anchor tag
      *
      * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
      *
      */
     if (!empty($field_settings['show_as_link']) && !gv_empty($output, false, false)) {
         $link_atts = empty($field_settings['new_window']) ? array() : array('target' => '_blank');
         $output = self::entry_link_html($entry, $output, $link_atts, $field_settings);
     }
     /**
      * @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number`
      * @since 1.6
      * @param string $output HTML value output
      * @param array  $entry The GF entry array
      * @param  array $field_settings Settings for the particular GV field
      * @param array $field Current field being displayed
      */
     $output = apply_filters('gravityview_field_entry_value_' . $field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     /**
      * @filter `gravityview_field_entry_value` Modify the field value output for all field types
      * @param string $output HTML value output
      * @param array  $entry The GF entry array
      * @param  array $field_settings Settings for the particular GV field
      * @param array $field_data  {@since 1.6}
      */
     $output = apply_filters('gravityview_field_entry_value', $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     return $output;
 }
</h2></div>
				                                    </td>
				                                </tr>
				                                <?php 
                break;
            case "captcha":
            case "html":
            case "password":
                //ignore certain fields
                break;
            case "creditcard":
                $content1 = "<tr valign='top'><td class='detail-view'><label class='detail-label'>Credit Card Payment</label></td></tr>";
                echo $content1;
                break;
            default:
                $value = RGFormsModel::get_lead_field_value($lead, $field);
                $td_id = "field_" . $form_id . "_" . $field_id;
                $content = "<tr valign='top'><td class='detail-view' id='{$td_id}'><label class='detail-label'>" . esc_html(GFCommon::get_label($field)) . "</label>" . GFCommon::get_field_input($field, $value, $lead["id"]) . "</td></tr>";
                $content = apply_filters("gform_field_content", $content, $field, $value, $lead["id"], $form["id"]);
                echo $content;
                break;
        }
    }
    ?>
				                    </tbody>
				                </table>
				                <br/>
				                <div class="gform_footer">
				                    <input type="hidden" name="gform_unique_id" value="" />
				                    <input type="hidden" name="gform_uploaded_files" id='gform_uploaded_files_<?php 
    echo $form_id;
    private function show_edit_form()
    {
        /*
         * The user created the entry, so show them the form!
         */
        if (self::$allowed_edit === false) {
            /*
             * TODO add error log message here 
             */
            return false;
        }
        ob_start();
        $form = self::$form;
        $lead = self::$lead;
        $form_id = $form['id'];
        $field_values = array();
        $is_postback = false;
        /*
         * Validate form, if submitted 
         */
        if (isset($_POST['gform_submit'])) {
            $is_postback = true;
            $is_valid = $this->validate($form, $field_values);
            if ($is_valid) {
                /*
                 * TODO, save the form and show an update message 
                 */
                if ($this->update_entry($form, $lead)) {
                    GFPDFEWidgetsAndShortcode_PDFDisplay::$message = __('Your entry and PDF(s) has been successfully updated.', 'pdfextended');
                } else {
                    GFPDFEWidgetsAndShortcode_PDFDisplay::$error = __('There was a problem updating your entry. Please try again.', 'pdfextended');
                }
                return false;
            }
        }
        ?>

		<div id="gform_wrapper_<?php 
        echo self::$form['id'];
        ?>
" class='gform_wrapper'>
			<form id="gform_<?php 
        echo self::$form['id'];
        ?>
" method="post">
				<div id='gform_page_<?php 
        echo self::$form['id'];
        ?>
_1'>
	                 <div class='gform_page_fields'>	

						<?php 
        if ($is_postback && !$is_valid) {
            $validation_message = "<div class='validation_error'>" . __("There was a problem with your submission.", "gravityforms") . " " . __("Errors have been highlighted below.", "gravityforms") . "</div>";
            echo apply_filters("gform_validation_message_{$form["id"]}", apply_filters("gform_validation_message", $validation_message, $form), $form);
        }
        ?>

	                 	<ul id='gform_fields_<?php 
        echo self::$form['id'];
        ?>
' class='gform_fields'>
				        					               
				                    <?php 
        foreach ($form["fields"] as $field) {
            $field_id = $field["id"];
            /*
             * If $field_id should be hidden...
             */
            if (in_array($field_id, $this->atts['hidden_fields'])) {
                continue;
            }
            $field["conditionalLogicFields"] = GFFormDisplay::get_conditional_logic_fields($form, $field["id"]);
            $input_type = RGFormsModel::get_input_type($field);
            $error_class = rgget("failed_validation", $field) ? "gfield_error" : "";
            $admin_only_class = rgget("adminOnly", $field) ? "field_admin_only" : "";
            $selectable_class = IS_ADMIN ? "selectable" : "";
            $hidden_class = in_array($input_type, array("hidden", "hiddenproduct")) ? "gform_hidden" : "";
            $section_class = $field["type"] == "section" ? "gsection" : "";
            $page_class = $field["type"] == "page" ? "gpage" : "";
            $html_block_class = $field["type"] == "html" ? "gfield_html" : "";
            $html_formatted_class = $field["type"] == "html" && !IS_ADMIN && !rgget("disableMargins", $field) ? "gfield_html_formatted" : "";
            $html_no_follows_desc_class = $field["type"] == "html" && !IS_ADMIN && !self::prev_field_has_description(self::$form, $field["id"]) ? "gfield_no_follows_desc" : "";
            $calculation_class = RGFormsModel::get_input_type($field) == 'number' && GFCommon::has_field_calculation($field) ? 'gfield_calculation' : '';
            $calculation_class = RGFormsModel::get_input_type($field) == 'calculation' ? 'gfield_calculation' : '';
            $product_suffix = '_' . self::$form['id'] . '_' . rgget("productField", $field);
            $option_class = $field["type"] == "option" ? "gfield_price gfield_price{$product_suffix} gfield_option{$product_suffix}" : "";
            $quantity_class = $field["type"] == "quantity" ? "gfield_price gfield_price{$product_suffix} gfield_quantity{$product_suffix}" : "";
            $shipping_class = $field["type"] == "shipping" ? "gfield_price gfield_shipping gfield_shipping_{$form["id"]}" : "";
            $product_class = $field["type"] == "product" ? "gfield_price gfield_price_{$form["id"]}_{$field["id"]} gfield_product_{$form["id"]}_{$field["id"]}" : "";
            $hidden_product_class = $input_type == "hiddenproduct" ? "gfield_hidden_product" : "";
            $donation_class = $field["type"] == "donation" ? "gfield_price gfield_price_{$form["id"]}_{$field["id"]} gfield_donation_{$form["id"]}_{$field["id"]}" : "";
            $required_class = rgar($field, "isRequired") ? "gfield_contains_required" : "";
            $creditcard_warning_class = $input_type == "creditcard" && !GFCommon::is_ssl() ? "gfield_creditcard_warning" : "";
            $custom_class = IS_ADMIN ? "" : rgget("cssClass", $field);
            $css_class = "{$selectable_class} gfield {$error_class} {$section_class} {$admin_only_class} {$custom_class} {$hidden_class} {$html_block_class} {$html_formatted_class} {$html_no_follows_desc_class} {$option_class} {$quantity_class} {$product_class} {$donation_class} {$shipping_class} {$page_class} {$required_class} {$hidden_product_class} {$creditcard_warning_class} {$calculation_class}";
            $css_class = apply_filters("gform_field_css_class_" . self::$form["id"], apply_filters("gform_field_css_class", trim($css_class), $field, self::$form), $field, self::$form);
            $style = !empty($form) && !IS_ADMIN && RGFormsModel::is_field_hidden(self::$form, $field, $field_values) ? "style='display:none;'" : "";
            switch (RGFormsModel::get_input_type($field)) {
                case "captcha":
                case "html":
                case "password":
                case "product":
                case "coupon":
                case "quantity":
                case "shipping":
                case "donation":
                case "total":
                case "singleproduct":
                case "hiddenproduct":
                case "singleshipping":
                case "creditcard":
                case "page":
                case "post_image":
                case "fileupload":
                    //ignore certain fields
                    continue;
                    break;
                default:
                    if (isset($field['productField']) && (int) $field['productField'] > 0 || $field['type'] == 'shipping') {
                        continue;
                    }
                    /*
                     * Ensure our restricted field values stay the same (as they aren't push through the $_POST data)
                     */
                    if (in_array($field_id, $this->atts['restricted_fields'])) {
                        $value = RGFormsModel::get_lead_field_value($lead, $field);
                    } else {
                        /*
                         * Check if we have POST data, or whether we pull the details from the entry itself 
                         * This is useful when the validation fails
                         */
                        $value = $is_postback ? RGFormsModel::get_field_value($field) : RGFormsModel::get_lead_field_value($lead, $field);
                    }
                    $id = "field_" . $form['id'] . "_" . $field_id;
                    /* $content = " <li id='{$id}' class='$css_class' $style><label class='detail-label'>" . esc_html(GFCommon::get_label($field)) . "</label>" .
                    				                                           GFCommon::get_field_input($field, $value, $lead["id"], $form['id']) . "</li>";
                    
                    				                                $content = apply_filters("gform_field_content", $content, $field, $value, self::$lead["id"], self::$form["id"]);*/
                    //$content = "<li id='{$id}' class='$css_class' $style>" . GFFormDisplay::get_field_content($field, $value, true, $form['id']) . '</li>';
                    $field_content = GFFormDisplay::get_field_content($field, $value, true, $form['id']);
                    $field_container = "<li id='{$id}' class='{$css_class}' {$style}>{FIELD_CONTENT}</li>";
                    $field_container = apply_filters('gform_field_container', $field_container, $field, $form, $css_class, $style, $field_content);
                    $field_container = apply_filters("gform_field_container_{$form['id']}", $field_container, $field, $form, $css_class, $style, $field_content);
                    $field_container = apply_filters("gform_field_container_{$form['id']}_{$field['id']}", $field_container, $field, $form, $css_class, $style, $field_content);
                    $field_markup = str_replace('{FIELD_CONTENT}', $field_content, $field_container);
                    if (in_array($field_id, $this->atts['restricted_fields'])) {
                        $field_markup = str_replace('<input', '<input disabled', $field_markup);
                        $field_markup = str_replace('<textarea', '<textarea disabled', $field_markup);
                    }
                    echo $field_markup;
                    break;
            }
        }
        $field_values_str = is_array($field_values) ? http_build_query($field_values) : $field_values;
        ?>
				              

						            <input type='hidden' class='gform_hidden' name='is_submit_<?php 
        echo $form['id'];
        ?>
' value='1' />
						            <input type='hidden' class='gform_hidden' name='gform_submit' value='<?php 
        echo $form['id'];
        ?>
' />
						            <input type='hidden' class='gform_hidden' name='gform_unique_id' value='<?php 
        echo esc_attr(GFFormsModel::get_form_unique_id($form['id']));
        ?>
' />
						            <input type='hidden' class='gform_hidden' name='state_<?php 
        echo $form['id'];
        ?>
' value='<?php 
        GFFormDisplay::get_state($form, $field_values);
        ?>
' />						            
						            <input type='hidden' name='gform_field_values' value='<?php 
        echo esc_attr($field_values_str);
        ?>
' />					

				                    <?php 
        $button_input = self::get_form_button($form["id"], "gform_submit_button_{$form["id"]}", $form["button"], __("Submit", "gravityforms"), "button gform_button", __("Submit", "gravityforms"));
        echo $button_input;
        ?>
				         	
				         	</ul>
				        </div>
				    </div>
			</form>				    
         </div>

        <?php 
        $html = ob_get_contents();
        ob_end_clean();
        return $html;
    }
Ejemplo n.º 16
0
 public function display_confirmation($confirmation, $form, $lead, $ajax)
 {
     $poll_fields = GFCommon::get_fields_by_type($form, array('poll'));
     $display_confirmation = false;
     $display_results = false;
     if (empty($poll_fields)) {
         return $confirmation;
     }
     $form_id = $form['id'];
     $override = false;
     $field_values = array();
     if (isset($_POST['gform_field_values'])) {
         $field_values = wp_parse_args($_POST['gform_field_values']);
     }
     // shortcode attributes override form settings
     if (rgar($field_values, 'gpoll_enabled') == '1') {
         $field_values = wp_parse_args($_POST['gform_field_values']);
         $show_results_link = rgar($field_values, 'gpoll_show_results_link');
         $show_results_link = $show_results_link == '1' ? true : false;
         $style = rgar($field_values, 'gpoll_style');
         $percentages = rgar($field_values, 'gpoll_percentages');
         $percentages = $percentages == '1' ? true : false;
         $counts = rgar($field_values, 'gpoll_counts');
         $counts = $counts == '1' ? true : false;
         $cookie = rgar($field_values, 'gpoll_cookie');
         $display_results = rgar($field_values, 'gpoll_display_results');
         $display_results = $display_results == '1' ? true : false;
         $display_confirmation = rgar($field_values, 'gpoll_confirmation');
         $display_confirmation = $display_confirmation == '1' ? true : false;
         $checksum = rgar($field_values, 'gpoll_checksum');
         if ($checksum == $this->generate_checksum($display_results, $show_results_link, $cookie, $display_confirmation, $percentages, $counts, $style)) {
             $override = true;
         }
     }
     if (false === $override) {
         $style = $this->get_form_setting($form, 'style');
         $percentages = $this->get_form_setting($form, 'showPercentages');
         $counts = $this->get_form_setting($form, 'showCounts');
         $display_results = $this->get_form_setting($form, 'displayResults');
         $display_confirmation = true;
     }
     $submitted_fields = array();
     foreach ($poll_fields as $field) {
         $field_id = $field['id'];
         $entry_value = RGFormsModel::get_lead_field_value($lead, $field);
         if (is_array($entry_value)) {
             $entry_value = implode('', $entry_value);
         }
         if (false === empty($entry_value)) {
             $submitted_fields[] = $field_id;
         }
     }
     if ($display_confirmation && $display_results) {
         //confirmation message plus results
         //override in the case of headers already sent or ajax = true
         if (is_array($confirmation) && array_key_exists('redirect', $confirmation)) {
             $confirmation = '';
         }
         //override confirmation if it's a redirect
         $str_pos = strpos($confirmation, 'gformRedirect');
         if (false !== $str_pos) {
             $confirmation = '';
         }
         $has_confirmation_wrapper = false !== strpos($confirmation, 'gform_confirmation_wrapper') ? true : false;
         if ($has_confirmation_wrapper) {
             $confirmation = substr($confirmation, 0, strlen($confirmation) - 6);
         }
         //remove the closing div of the wrapper
         $has_confirmation_message = false !== strpos($confirmation, 'gforms_confirmation_message') ? true : false;
         if ($has_confirmation_message) {
             $confirmation = substr($confirmation, 0, strlen($confirmation) - 6);
         } else {
             $confirmation .= "<div id='gforms_confirmation_message' class='gform_confirmation_message_{$form_id}'>";
         }
         $results = $this->gpoll_get_results($form['id'], $submitted_fields, $style, $percentages, $counts, $lead);
         $confirmation .= $results['summary'] . '</div>';
         if ($has_confirmation_wrapper) {
             $confirmation .= '</div>';
         }
     } elseif (!$display_confirmation && $display_results) {
         //only the results without the confirmation message
         $results = $this->gpoll_get_results($form['id'], $submitted_fields, $style, $percentages, $counts, $lead);
         $results_summary = $results['summary'];
         $confirmation = sprintf("<div id='gforms_confirmation_message' class='gform_confirmation_message_{$form_id}'>%s</div>", $results_summary);
     } elseif (!$display_confirmation && !$display_results) {
         $confirmation = "<div id='gforms_confirmation_message' class='gform_confirmation_message_{$form_id}'></div>";
     }
     return $confirmation;
 }
Ejemplo n.º 17
0
 public static function is_optin($form, $settings, $entry)
 {
     $config = $settings["meta"];
     $field = RGFormsModel::get_field($form, $config["optin_field_id"]);
     if (empty($field) || !$config["optin_enabled"]) {
         return true;
     }
     $operator = $config["optin_operator"];
     $field_value = RGFormsModel::get_lead_field_value($entry, $field);
     $is_value_match = RGFormsModel::is_value_match($field_value, $config["optin_value"]);
     $is_visible = !RGFormsModel::is_field_hidden($form, $field, array(), $entry);
     $is_match = $is_value_match && $is_visible;
     $is_optin = $operator == "is" && $is_match || $operator == "isnot" && !$is_match;
     return $is_optin;
 }
Ejemplo n.º 18
0
 private static function get_defaults($lead, $field, $form_array)
 {
     $value = RGFormsModel::get_lead_field_value($lead, $field);
     $display = self::get_lead_field_display($field, $value, $lead['currency']);
     return self::assign_form($field, $display, $form_array);
 }
Ejemplo n.º 19
0
 public static function get_product_fields($form, $lead, $use_choice_text = false)
 {
     $products = array();
     foreach ($form["fields"] as $field) {
         $id = $field["id"];
         $lead_value = RGFormsModel::get_lead_field_value($lead, $field);
         $quantity_field = self::get_product_fields_by_type($form, array("quantity"), $id);
         $quantity = sizeof($quantity_field) > 0 ? RGFormsModel::get_lead_field_value($lead, $quantity_field[0]) : 1;
         switch ($field["type"]) {
             case "product":
                 //if single product, get values from the multiple inputs
                 if (is_array($lead_value)) {
                     $product_quantity = sizeof($quantity_field) == 0 ? $lead_value[$id . ".3"] : $quantity;
                     if (empty($product_quantity)) {
                         continue;
                     }
                     if (!$products[$id]) {
                         $products[$id] = array();
                     }
                     $products[$id]["name"] = $lead_value[$id . ".1"];
                     $products[$id]["price"] = $lead_value[$id . ".2"];
                     $products[$id]["quantity"] = $product_quantity;
                 } else {
                     if (!empty($lead_value)) {
                         if (empty($quantity)) {
                             continue;
                         }
                         if (!$products[$id]) {
                             $products[$id] = array();
                         }
                         if ($field["inputType"] == "price") {
                             $name = $field["label"];
                             $price = $lead_value;
                         } else {
                             list($name, $price) = explode("|", $lead_value);
                         }
                         $products[$id]["name"] = !$use_choice_text ? $name : RGFormsModel::get_choice_text($field, $name);
                         $products[$id]["price"] = $price;
                         $products[$id]["quantity"] = $quantity;
                         $products[$id]["options"] = array();
                     }
                 }
                 if (isset($products[$id])) {
                     $options = self::get_product_fields_by_type($form, array("option"), $id);
                     foreach ($options as $option) {
                         $option_value = RGFormsModel::get_lead_field_value($lead, $option);
                         $option_label = empty($option["adminLabel"]) ? $option["label"] : $option["adminLabel"];
                         if (is_array($option_value)) {
                             foreach ($option_value as $value) {
                                 $option_info = self::get_option_info($value, $option, $use_choice_text);
                                 $products[$id]["options"][] = array("field_label" => $option["label"], "option_name" => $option_info["name"], "option_label" => $option_label . ": " . $option_info["name"], "price" => $option_info["price"]);
                             }
                         } else {
                             if (!empty($option_value)) {
                                 $option_info = self::get_option_info($option_value, $option, $use_choice_text);
                                 $products[$id]["options"][] = array("field_label" => $option["label"], "option_name" => $option_info["name"], "option_label" => $option_label . ": " . $option_info["name"], "price" => $option_info["price"]);
                             }
                         }
                     }
                 }
                 break;
         }
     }
     $shipping_field = self::get_fields_by_type($form, array("shipping"));
     if (!empty($shipping_field)) {
         $shipping_price = RGFormsModel::get_lead_field_value($lead, $shipping_field[0]);
         $shipping_name = $shipping_field[0]["label"];
         if ($shipping_field[0]["inputType"] != "singleshipping") {
             list($shipping_method, $shipping_price) = explode("|", $shipping_price);
             $shipping_name = $shipping_field[0]["label"] . " ({$shipping_method})";
         }
     }
     $shipping_price = self::to_number($shipping_price);
     return array("products" => $products, "shipping" => array("name" => $shipping_name, "price" => $shipping_price));
 }
Ejemplo n.º 20
0
 private static function get_entry_value($field_id, $entry, $name_fields)
 {
     foreach ($name_fields as $name_field) {
         if ($field_id == $name_field["id"]) {
             $value = RGFormsModel::get_lead_field_value($entry, $name_field);
             return GFCommon::get_lead_field_display($name_field, $value);
         }
     }
     return $entry[$field_id];
 }
Ejemplo n.º 21
0
 private static function get_akismet_field($field_type, $form, $lead)
 {
     $fields = GFCommon::get_fields_by_type($form, array($field_type));
     if (empty($fields)) {
         return "";
     }
     $value = RGFormsModel::get_lead_field_value($lead, $fields[0]);
     switch ($field_type) {
         case "name":
             $value = GFCommon::get_lead_field_display($fields[0], $value);
             break;
     }
     return $value;
 }
Ejemplo n.º 22
0
 private static function get_donation_query_string($form, $entry)
 {
     $fields = "";
     //getting all donation fields
     $donations = GFCommon::get_fields_by_type($form, array("donation"));
     $total = 0;
     $purpose = "";
     foreach ($donations as $donation) {
         $value = RGFormsModel::get_lead_field_value($entry, $donation);
         list($name, $price) = explode("|", $value);
         if (empty($price)) {
             $price = $name;
             $name = $donation["label"];
         }
         $purpose .= $name . ", ";
         $price = GFCommon::to_number($price);
         $total += $price;
     }
     //using product fields for donation if there aren't any legacy donation fields in the form
     if ($total == 0) {
         //getting all product fields
         $products = GFCommon::get_product_fields($form, $entry, true);
         foreach ($products["products"] as $product) {
             $options = "";
             if (is_array($product["options"]) && !empty($product["options"])) {
                 $options = " (";
                 foreach ($product["options"] as $option) {
                     $options .= $option["option_name"] . ", ";
                 }
                 $options = substr($options, 0, strlen($options) - 2) . ")";
             }
             $quantity = GFCommon::to_number($product["quantity"]);
             $quantity_label = $quantity > 1 ? $quantity . " " : "";
             $purpose .= $quantity_label . $product["name"] . $options . ", ";
         }
         $total = GFCommon::get_order_total($form, $entry);
     }
     if (!empty($purpose)) {
         $purpose = substr($purpose, 0, strlen($purpose) - 2);
     }
     $purpose = urlencode($purpose);
     //truncating to maximum length allowed by PayPal
     if (strlen($purpose) > 127) {
         $purpose = substr($purpose, 0, 124) . "...";
     }
     $fields = "&amount={$total}&item_name={$purpose}&cmd=_donations";
     return $total > 0 ? $fields : false;
 }
 public function get_product_fields($form, $lead, $use_choice_text = false, $use_admin_label = false)
 {
     $products = array();
     foreach ($form["fields"] as $field) {
         $id = $field["id"];
         $lead_value = RGFormsModel::get_lead_field_value($lead, $field);
         $quantity_field = GFCommon::get_product_fields_by_type($form, array("quantity"), $id);
         $quantity = sizeof($quantity_field) > 0 ? RGFormsModel::get_lead_field_value($lead, $quantity_field[0]) : 1;
         switch ($field["type"]) {
             case "product":
                 //ignore products that have been hidden by conditional logic
                 $is_hidden = RGFormsModel::is_field_hidden($form, $field, array(), $lead);
                 if ($is_hidden) {
                     continue;
                 }
                 //if single product, get values from the multiple inputs
                 if (is_array($lead_value)) {
                     $product_quantity = sizeof($quantity_field) == 0 && !rgar($field, "disableQuantity") ? rgget($id . ".3", $lead_value) : $quantity;
                     if (empty($product_quantity)) {
                         continue;
                     }
                     if (!rgget($id, $products)) {
                         $products[$id] = array();
                     }
                     $products[$id]["name"] = $use_admin_label && !rgempty("adminLabel", $field) ? $field["adminLabel"] : $lead_value[$id . ".1"];
                     $products[$id]["price"] = rgar($lead_value, $id . ".2");
                     $products[$id]["quantity"] = $product_quantity;
                 } else {
                     if (!empty($lead_value)) {
                         if (empty($quantity)) {
                             continue;
                         }
                         if (!rgar($products, $id)) {
                             $products[$id] = array();
                         }
                         if ($field["inputType"] == "price") {
                             $name = $field["label"];
                             $price = $lead_value;
                         } else {
                             list($name, $price) = explode("|", $lead_value);
                         }
                         $products[$id]["name"] = !$use_choice_text ? $name : RGFormsModel::get_choice_text($field, $name);
                         $products[$id]["price"] = $price;
                         $products[$id]["quantity"] = $quantity;
                         $products[$id]["options"] = array();
                     }
                 }
                 if (isset($products[$id])) {
                     $options = GFCommon::get_product_fields_by_type($form, array("option"), $id);
                     foreach ($options as $option) {
                         $option_value = RGFormsModel::get_lead_field_value($lead, $option);
                         $option_label = empty($option["adminLabel"]) ? $option["label"] : $option["adminLabel"];
                         if (is_array($option_value)) {
                             foreach ($option_value as $value) {
                                 $option_info = GFCommon::get_option_info($value, $option, $use_choice_text);
                                 if (!empty($option_info)) {
                                     $products[$id]["options"][] = array("field_label" => rgar($option, "label"), "option_name" => rgar($option_info, "name"), "option_label" => $option_label . ": " . rgar($option_info, "name"), "price" => rgar($option_info, "price"));
                                 }
                             }
                         } else {
                             if (!empty($option_value)) {
                                 $option_info = GFCommon::get_option_info($option_value, $option, $use_choice_text);
                                 $products[$id]["options"][] = array("field_label" => rgar($option, "label"), "option_name" => rgar($option_info, "name"), "option_label" => $option_label . ": " . rgar($option_info, "name"), "price" => rgar($option_info, "price"));
                             }
                         }
                     }
                 }
                 break;
         }
     }
     $shipping_field = GFCommon::get_fields_by_type($form, array("shipping"));
     $shipping_price = $shipping_name = "";
     if (!empty($shipping_field) && !RGFormsModel::is_field_hidden($form, $shipping_field[0], array(), $lead)) {
         $shipping_price = RGFormsModel::get_lead_field_value($lead, $shipping_field[0]);
         $shipping_name = $shipping_field[0]["label"];
         if ($shipping_field[0]["inputType"] != "singleshipping") {
             list($shipping_method, $shipping_price) = explode("|", $shipping_price);
             $shipping_name = $shipping_field[0]["label"] . " ({$shipping_method})";
         }
     }
     $shipping_price = GFCommon::to_number($shipping_price);
     $product_info = array("products" => $products, "shipping" => array("name" => $shipping_name, "price" => $shipping_price));
     $product_info = apply_filters("gform_product_info_{$form["id"]}", apply_filters("gform_product_info", $product_info, $form, $lead), $form, $lead);
     return $product_info;
 }
 /**
  * Return the Likert column text for the stored entry value.
  *
  * @param string|array $value The field value.
  * @param array|false $entry The Entry Object currently being processed.
  * @param string|false $field_id The field or input ID currently being processed.
  * @param bool|false $include_row_text Should the row text be returned along with the column text?
  *
  * @return string
  */
 public function get_column_text($value, $entry = false, $field_id = false, $include_row_text = false)
 {
     if ($this->gsurveyLikertEnableMultipleRows) {
         $row_id = $this->get_row_id($field_id);
         $values = !empty($entry) ? RGFormsModel::get_lead_field_value($entry, $this) : $value;
         if ($row_id && is_array($values)) {
             foreach ($values as $value) {
                 if (!empty($value)) {
                     list($row_val, $col_val) = rgexplode(':', $value, 2);
                     if ($row_id == $row_val) {
                         $choice_text = $this->get_choice_text($col_val);
                         return $include_row_text ? sprintf('%s: %s', $this->get_row_label($field_id), $choice_text) : $choice_text;
                     }
                 }
             }
         }
         return '';
     } else {
         return $this->get_choice_text($value);
     }
 }
Ejemplo n.º 25
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 
    }
Ejemplo n.º 26
0
 public function is_group_condition_met($group, $form, $entry)
 {
     if (!$group['enabled']) {
         $this->log_debug(__METHOD__ . '(): Group not enabled. Returning false.');
         return false;
     } elseif ($group['decision'] == 'always') {
         $this->log_debug(__METHOD__ . '(): Group decision is always. Returning true.');
         return true;
     }
     $field = RGFormsModel::get_field($form, $group['field_id']);
     if (!is_object($field)) {
         $this->log_debug(__METHOD__ . "(): Field #{$group['field_id']} not found. Returning true.");
         return true;
     } else {
         $field_value = RGFormsModel::get_lead_field_value($entry, $field);
         $is_value_match = RGFormsModel::is_value_match($field_value, $group['value'], $group['operator'], $field);
         $this->log_debug(__METHOD__ . "(): Add to group if field #{$group['field_id']} value {$group['operator']} '{$group['value']}'. Is value match? " . var_export($is_value_match, 1));
         return $is_value_match;
     }
 }
Ejemplo n.º 27
0
 public static function mtd_transform_entry_data($entry)
 {
     $data = array();
     $root_element["type"] = "root";
     $root_element["title"] = $entry["id"] . ": " . $entry["date_created"];
     $root_element["id"] = "id-entry-" . $entry["id"];
     $form_id = rgar($entry, "form_id");
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = $form["fields"];
     foreach ($fields as $field) {
         $field_data = array();
         $field_data["header"] = $field["label"];
         $elements = array();
         $value = RGFormsModel::get_lead_field_value($entry, $field);
         if (is_array($value) && isset($field["choices"])) {
             $choices = rgar($field, "choices");
             foreach ($choices as $choice) {
                 $found = false;
                 foreach ($value as $item) {
                     if ($item == rgar($choice, "value")) {
                         $found = true;
                         break;
                     }
                 }
                 $element = array();
                 $element["type"] = "checkbox";
                 $element["caption"] = $choice["text"];
                 $element["value"] = $found;
                 $elements[] = $element;
             }
         } else {
             $element = array();
             $element["type"] = "string";
             $element["caption"] = GFFormsModel::get_choice_text($field, $value);
             $elements[] = $element;
         }
         $field_data["elements"] = $elements;
         $data[] = $field_data;
     }
     $root_element["sections"] = $data;
     return $root_element;
 }
 public static function is_group_condition_met($group, $form, $entry)
 {
     $field = RGFormsModel::get_field($form, $group['field_id']);
     $field_value = RGFormsModel::get_lead_field_value($entry, $field);
     $is_value_match = RGFormsModel::is_value_match($field_value, $group['value'], $group['operator'], $field);
     if (!$group['enabled']) {
         return false;
     } else {
         if ($group['decision'] == 'always' || empty($field)) {
             return true;
         } else {
             return $is_value_match;
         }
     }
 }
Ejemplo n.º 29
0
 public static function get_default_field_results($form_id, $field, $search_criteria, &$offset, $page_size, &$more_remaining = false)
 {
     $field_results = '';
     $sorting = array('key' => 'date_created', 'direction' => 'DESC');
     $c = 0;
     do {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $leads = GFFormsModel::search_leads($form_id, $search_criteria, $sorting, $paging);
         foreach ($leads as $lead) {
             $value = RGFormsModel::get_lead_field_value($lead, $field);
             $content = apply_filters('gform_entries_field_value', $value, $form_id, $field->id, $lead);
             if (is_array($content)) {
                 $content = join(' ', $content);
             }
             if (!empty($content)) {
                 $field_results .= "<li>{$content}</li>";
                 $c++;
             }
         }
         $offset += $page_size;
     } while ($c < $page_size && !empty($leads));
     if (!empty($leads)) {
         $more_remaining = true;
     }
     return $field_results;
 }
Ejemplo n.º 30
0
 public static function mtd_transform_entry_data($entry)
 {
     $data = array();
     $root_element['type'] = 'root';
     $root_element['title'] = $entry['id'] . ': ' . $entry['date_created'];
     $root_element['id'] = 'id-entry-' . $entry['id'];
     $form_id = rgar($entry, 'form_id');
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = $form['fields'];
     foreach ($fields as $field) {
         $field_data = array();
         $field_data['header'] = $field->label;
         $elements = array();
         $value = RGFormsModel::get_lead_field_value($entry, $field);
         if (is_array($value) && isset($field->choices)) {
             $choices = $field->choices;
             foreach ($choices as $choice) {
                 $found = false;
                 foreach ($value as $item) {
                     if ($item == rgar($choice, 'value')) {
                         $found = true;
                         break;
                     }
                 }
                 $element = array();
                 $element['type'] = 'checkbox';
                 $element['caption'] = $choice['text'];
                 $element['value'] = $found;
                 $elements[] = $element;
             }
         } else {
             $element = array();
             $element['type'] = 'string';
             $element['caption'] = GFFormsModel::get_choice_text($field, $value);
             $elements[] = $element;
         }
         $field_data['elements'] = $elements;
         $data[] = $field_data;
     }
     $root_element['sections'] = $data;
     return $root_element;
 }