function bb_click_array_field_input($input, $field, $value, $lead_id, $form_id)
{
    if ($field["type"] == "bb_click_array") {
        $field_id = IS_ADMIN || $form_id == 0 ? "input_{$id}" : "input_" . $form_id . "_{$id}";
        $input_name = $form_id . '_' . $field["id"];
        $css = isset($field['cssClass']) ? $field['cssClass'] : "";
        $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != "entry" ? "disabled='disabled'" : "";
        $amount = '';
        $clicked = '';
        if (is_array($value)) {
            $amount = esc_attr(rgget($field["id"] . ".1", $value));
            $clicked = rgget($field["id"] . ".5", $value);
        }
        $html = "<div id='{$field_id}' class='ginput_container bb-click-array-" . count($field['choices']) . " " . esc_attr($css) . "'>" . "\n";
        if (is_array($field["choices"])) {
            $choice_id = 0;
            $tabindex = GFCommon::get_tabindex();
            foreach ($field["choices"] as $choice) {
                $id = $field["id"] . '_' . $choice_id;
                $field_value = !empty($choice["value"]) || rgar($field, "enableChoiceValue") ? $choice["value"] : $choice["text"];
                if (rgblank($amount) && RG_CURRENT_VIEW != "entry") {
                    $active = rgar($choice, "isSelected") ? "checked='checked'" : "";
                } else {
                    $active = RGFormsModel::choice_value_match($field, $choice, $amount) ? "checked='checked'" : "";
                }
                if ($active) {
                    $amount = $field_value;
                }
                $field_class = $active ? 's-active' : 's-passive';
                if (rgar($field, 'field_bb_click_array_is_product')) {
                    require_once GFCommon::get_base_path() . '/currency.php';
                    $currency = new RGCurrency(GFCommon::get_currency());
                    $field_value = $currency->to_money($field_value);
                    $field_class .= ' s-currency';
                }
                $html .= sprintf('<div data-clickarray-value="%s" data-choice-id="%s" class="s-html-wrapper %s" id="%s">', esc_attr($field_value), $choice_id, $field_class, $id);
                $html .= sprintf('<div class="s-html-value">%s</div>', $field_value);
                $html .= sprintf("<label for='choice_%s' id='label_%s'>%s</label>", $id, $id, $choice["text"]);
                $html .= '</div>';
                $choice_id++;
            }
            $onblur = !IS_ADMIN ? 'if(jQuery(this).val().replace(" ", "") == "") { jQuery(this).val("' . $other_default_value . '"); }' : '';
            $onkeyup = empty($field["conditionalLogicFields"]) || IS_ADMIN ? '' : "onchange='gf_apply_rules(" . $field["formId"] . "," . GFCommon::json_encode($field["conditionalLogicFields"]) . ");' onkeyup='clearTimeout(__gf_timeout_handle); __gf_timeout_handle = setTimeout(\"gf_apply_rules(" . $field["formId"] . "," . GFCommon::json_encode($field["conditionalLogicFields"]) . ")\", 300);'";
            $value_exists = RGFormsModel::choices_value_match($field, $field["choices"], $value);
            $other_label = empty($field['field_bb_click_array_other_label']) ? 'My Best Gift' : $field['field_bb_click_array_other_label'];
            $other_class = rgar($field, 'enableOtherChoice') ? '' : 'hide';
            $html .= "<label for='input_{$field["formId"]}_{$field["id"]}_1' class='ginput_bb_click_array_other_label " . $other_class . "'>" . $other_label . "</label>";
            $other_class .= rgar($field, 'field_bb_click_array_is_product') ? ' ginput_amount gfield_price gfield_price_' . $field['formId'] . '_' . $field['id'] . '_1 gfield_product_' . $field['formId'] . '_' . $field['id'] . '_1' : '';
            $html .= "<input id='input_{$field["formId"]}_{$field["id"]}_1' name='input_{$field["id"]}_1' type='text' value='" . esc_attr($amount) . "' class='ginput_bb ginput_click_array_other " . $other_class . " " . $field['size'] . "' onblur='{$onblur}' {$tabindex} {$onkeyup} {$disabled_text}>";
            $html .= "<input id='input_{$field["formId"]}_{$field["id"]}_5' name='input_{$field["id"]}_5' type='hidden' value='" . esc_attr($clicked) . "' class='ginput_bb ginput_click_array_clicked'>";
        }
        $html .= "</div>";
        return $html;
    }
    return $input;
}
Example #2
0
 public function get_results_data($form, $fields, $search_criteria = array(), $state_array = array(), $max_execution_time = 15)
 {
     // todo: add hooks to modify $max_execution_time and $page_size?
     $page_size = 150;
     $time_start = microtime(true);
     $form_id = $form['id'];
     $data = array();
     $offset = 0;
     $entry_count = 0;
     $field_data = array();
     if ($state_array) {
         //get counts from state
         $data = $state_array;
         $offset = (int) rgar($data, 'offset');
         unset($data['offset']);
         $entry_count = $offset;
         $field_data = rgar($data, 'field_data');
     } else {
         //initialize counts
         foreach ($fields as $field) {
             $field_type = GFFormsModel::get_input_type($field);
             if (false === isset($field->choices)) {
                 $field_data[$field->id] = 0;
                 continue;
             }
             $choices = $field->choices;
             if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableMultipleRows')) {
                 foreach ($field->gsurveyLikertRows as $row) {
                     foreach ($choices as $choice) {
                         $field_data[$field->id][$row['value']][$choice['value']] = 0;
                     }
                     if (rgar($field, 'gsurveyLikertEnableScoring')) {
                         $field_data[$field->id][$row['value']]['row_score_sum'] = 0;
                     }
                 }
             } else {
                 if (!empty($choices) && is_array($choices)) {
                     foreach ($choices as $choice) {
                         $field_data[$field->id][$choice['value']] = 0;
                     }
                 } else {
                     $field_data[$field->id] = 0;
                 }
             }
             if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableScoring')) {
                 $field_data[$field->id]['sum_of_scores'] = 0;
             }
         }
     }
     $count_search_leads = GFAPI::count_entries($form_id, $search_criteria);
     $data['entry_count'] = $count_search_leads;
     $entries_left = $count_search_leads - $offset;
     while ($entries_left > 0) {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $search_leads_time_start = microtime(true);
         $leads = GFFormsModel::search_leads($form_id, $search_criteria, null, $paging);
         $search_leads_time_end = microtime(true);
         $search_leads_time = $search_leads_time_end - $search_leads_time_start;
         $leads_in_search = count($leads);
         $entry_count += $leads_in_search;
         $leads_processed = 0;
         foreach ($leads as $lead) {
             $lead_time_start = microtime(true);
             foreach ($fields as $field) {
                 $field_type = GFFormsModel::get_input_type($field);
                 $field_id = $field->id;
                 $value = RGFormsModel::get_lead_field_value($lead, $field);
                 if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableMultipleRows')) {
                     if (empty($value)) {
                         continue;
                     }
                     foreach ($value as $value_vector) {
                         if (empty($value_vector)) {
                             continue;
                         }
                         list($row_val, $col_val) = explode(':', $value_vector, 2);
                         if (isset($field_data[$field->id][$row_val]) && isset($field_data[$field->id][$row_val][$col_val])) {
                             $field_data[$field->id][$row_val][$col_val]++;
                             if ($field->gsurveyLikertEnableScoring) {
                                 $field_data[$field->id][$row_val]['row_score_sum'] += $this->get_likert_row_score($row_val, $field, $lead);
                             }
                         }
                     }
                 } elseif ($field_type == 'rank') {
                     $score = count(rgar($field, 'choices'));
                     $values = explode(',', $value);
                     foreach ($values as $ranked_value) {
                         $field_data[$field->id][$ranked_value] += $score;
                         $score--;
                     }
                 } else {
                     if (empty($field->choices)) {
                         if (false === empty($value)) {
                             $field_data[$field_id]++;
                         }
                         continue;
                     }
                     $choices = $field->choices;
                     foreach ($choices as $choice) {
                         $choice_is_selected = false;
                         if (is_array($value)) {
                             $choice_value = rgar($choice, 'value');
                             if (in_array($choice_value, $value)) {
                                 $choice_is_selected = true;
                             }
                         } else {
                             if (RGFormsModel::choice_value_match($field, $choice, $value)) {
                                 $choice_is_selected = true;
                             }
                         }
                         if ($choice_is_selected) {
                             $field_data[$field_id][$choice['value']]++;
                         }
                     }
                 }
                 if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableScoring')) {
                     $field_data[$field->id]['sum_of_scores'] += $this->get_likert_score($field, $lead);
                 }
             }
             $leads_processed++;
             $lead_time_end = microtime(true);
             $total_execution_time = $lead_time_end - $search_leads_time_start;
             $lead_execution_time = $lead_time_end - $lead_time_start;
             if ($total_execution_time + $lead_execution_time > $max_execution_time) {
                 break;
             }
         }
         $data['field_data'] = $field_data;
         if (isset($this->_callbacks['calculation'])) {
             $data = call_user_func($this->_callbacks['calculation'], $data, $form, $fields, $leads);
             $field_data = $data['field_data'];
         }
         $offset += $leads_processed;
         $entries_left -= $leads_processed;
         $time_end = microtime(true);
         $execution_time = $time_end - $time_start;
         if ($entries_left > 0 && $execution_time + $search_leads_time > $max_execution_time) {
             $data['status'] = 'incomplete';
             $data['offset'] = $offset;
             $progress = $data['entry_count'] > 0 ? round($data['offset'] / $data['entry_count'] * 100) : 0;
             $data['progress'] = $progress;
             break;
         }
         if ($entries_left <= 0) {
             $data['status'] = 'complete';
         }
     }
     $data['timestamp'] = time();
     return $data;
 }
 public function get_results_data($form, $fields, $search_criteria = array(), $state_array = array(), $max_execution_time = 15)
 {
     // todo: add hooks to modify $max_execution_time and $page_size?
     $page_size = 150;
     $time_start = microtime(true);
     $form_id = $form["id"];
     $data = array();
     $offset = 0;
     $entry_count = 0;
     $field_data = array();
     if ($state_array) {
         //get counts from state
         $data = $state_array;
         $offset = (int) rgar($data, "offset");
         unset($data["offset"]);
         $entry_count = $offset;
         $field_data = rgar($data, "field_data");
     } else {
         //initialize counts
         foreach ($fields as $field) {
             $field_type = GFFormsModel::get_input_type($field);
             if (false === isset($field["choices"])) {
                 $field_data[$field["id"]] = 0;
                 continue;
             }
             $choices = $field["choices"];
             if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) {
                 foreach ($field["gsurveyLikertRows"] as $row) {
                     foreach ($choices as $choice) {
                         $field_data[$field["id"]][$row["value"]][$choice['value']] = 0;
                     }
                 }
             } else {
                 foreach ($choices as $choice) {
                     $field_data[$field["id"]][$choice['value']] = 0;
                 }
             }
             if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableScoring")) {
                 $field_data[$field["id"]]["sum_of_scores"] = 0;
             }
         }
     }
     $count_search_leads = GFAPI::count_entries($form_id, $search_criteria);
     $data["entry_count"] = $count_search_leads;
     $entries_left = $count_search_leads - $offset;
     while ($entries_left >= 0) {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $search_leads_time_start = microtime(true);
         $leads = GFFormsModel::search_leads($form_id, $search_criteria, null, $paging);
         $search_leads_time_end = microtime(true);
         $search_leads_time = $search_leads_time_end - $search_leads_time_start;
         $leads_in_search = count($leads);
         $entry_count += $leads_in_search;
         foreach ($leads as $lead) {
             foreach ($fields as $field) {
                 $field_type = GFFormsModel::get_input_type($field);
                 $field_id = $field["id"];
                 $value = RGFormsModel::get_lead_field_value($lead, $field);
                 if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) {
                     if (empty($value)) {
                         continue;
                     }
                     foreach ($value as $value_vector) {
                         if (empty($value_vector)) {
                             continue;
                         }
                         list($row_val, $col_val) = explode(":", $value_vector, 2);
                         if (isset($field_data[$field["id"]][$row_val]) && isset($field_data[$field["id"]][$row_val][$col_val])) {
                             $field_data[$field["id"]][$row_val][$col_val]++;
                         }
                     }
                 } elseif ($field_type == "rank") {
                     $score = count(rgar($field, "choices"));
                     $values = explode(",", $value);
                     foreach ($values as $ranked_value) {
                         $field_data[$field["id"]][$ranked_value] += $score;
                         $score--;
                     }
                 } else {
                     if (false === isset($field["choices"])) {
                         if (false === empty($value)) {
                             $field_data[$field_id]++;
                         }
                         continue;
                     }
                     $choices = $field["choices"];
                     foreach ($choices as $choice) {
                         $choice_is_selected = false;
                         if (is_array($value)) {
                             $choice_value = rgar($choice, "value");
                             if (in_array($choice_value, $value)) {
                                 $choice_is_selected = true;
                             }
                         } else {
                             if (RGFormsModel::choice_value_match($field, $choice, $value)) {
                                 $choice_is_selected = true;
                             }
                         }
                         if ($choice_is_selected) {
                             $field_data[$field_id][$choice['value']]++;
                         }
                     }
                 }
                 if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableScoring")) {
                     $field_data[$field["id"]]["sum_of_scores"] += $this->get_likert_score($field, $lead);
                 }
             }
         }
         $data["field_data"] = $field_data;
         if (isset($this->_callbacks["calculation"])) {
             $data = call_user_func($this->_callbacks["calculation"], $data, $form, $fields, $leads);
             $field_data = $data["field_data"];
         }
         $offset += $page_size;
         $entries_left -= $page_size;
         $time_end = microtime(true);
         $execution_time = $time_end - $time_start;
         if ($entries_left > 0 && $execution_time + $search_leads_time > $max_execution_time) {
             $data["status"] = "incomplete";
             $data["offset"] = $offset;
             $progress = $data["entry_count"] > 0 ? round($data["offset"] / $data["entry_count"] * 100) : 0;
             $data["progress"] = $progress;
             break;
         }
         if ($entries_left <= 0) {
             $data["status"] = "complete";
         }
     }
     $data["timestamp"] = time();
     return $data;
 }
Example #4
0
 public static function get_select_choices($field, $value = "")
 {
     $choices = "";
     if (RG_CURRENT_VIEW == "entry" && empty($value)) {
         $choices .= "<option value=''></option>";
     }
     if (is_array(rgar($field, "choices"))) {
         foreach ($field["choices"] as $choice) {
             // needed for users upgrading from 1.0
             $field_value = !empty($choice["value"]) || rgget("enableChoiceValue", $field) || $field['type'] == 'post_category' ? $choice["value"] : $choice["text"];
             if (rgget("enablePrice", $field)) {
                 $field_value .= "|" . GFCommon::to_number(rgar($choice, "price"));
             }
             if (rgblank($value) && RG_CURRENT_VIEW != "entry") {
                 $selected = rgar($choice, "isSelected") ? "selected='selected'" : "";
             } else {
                 if (is_array($value)) {
                     $is_match = false;
                     foreach ($value as $item) {
                         if (RGFormsModel::choice_value_match($field, $choice, $item)) {
                             $is_match = true;
                             break;
                         }
                     }
                     $selected = $is_match ? "selected='selected'" : "";
                 } else {
                     $selected = RGFormsModel::choice_value_match($field, $choice, $value) ? "selected='selected'" : "";
                 }
             }
             $choices .= sprintf("<option value='%s' %s>%s</option>", esc_attr($field_value), $selected, esc_html($choice["text"]));
         }
     }
     return $choices;
 }
 public function get_checkbox_choices($value, $disabled_text, $form_id = 0)
 {
     $choices = '';
     $is_entry_detail = $this->is_entry_detail();
     $is_form_editor = $this->is_form_editor();
     if (is_array($this->choices)) {
         $choice_number = 1;
         $count = 1;
         foreach ($this->choices as $choice) {
             if ($choice_number % 10 == 0) {
                 //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10
                 $choice_number++;
             }
             $input_id = $this->id . '.' . $choice_number;
             if ($is_entry_detail || $is_form_editor || $form_id == 0) {
                 $id = $this->id . '_' . $choice_number++;
             } else {
                 $id = $form_id . '_' . $this->id . '_' . $choice_number++;
             }
             if (!isset($_GET['gf_token']) && empty($_POST) && rgar($choice, 'isSelected')) {
                 $checked = "checked='checked'";
             } elseif (is_array($value) && RGFormsModel::choice_value_match($this, $choice, rgget($input_id, $value))) {
                 $checked = "checked='checked'";
             } elseif (!is_array($value) && RGFormsModel::choice_value_match($this, $choice, $value)) {
                 $checked = "checked='checked'";
             } else {
                 $checked = '';
             }
             $logic_event = $this->get_conditional_logic_event('click');
             $tabindex = $this->get_tabindex();
             $choice_value = $choice['value'];
             if ($this->enablePrice) {
                 $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                 $choice_value .= '|' . $price;
             }
             $choice_value = esc_attr($choice_value);
             $choice_markup = "<li class='gchoice_{$id}'>\n\t\t\t\t\t\t\t\t<input name='input_{$input_id}' type='checkbox' {$logic_event} value='{$choice_value}' {$checked} id='choice_{$id}' {$tabindex} {$disabled_text} />\n\t\t\t\t\t\t\t\t<label for='choice_{$id}' id='label_{$id}'>{$choice['text']}</label>\n\t\t\t\t\t\t\t</li>";
             $choices .= gf_apply_filters(array('gform_field_choice_markup_pre_render', $this->formId, $this->id), $choice_markup, $choice, $this, $value);
             $is_entry_detail = $this->is_entry_detail();
             $is_form_editor = $this->is_form_editor();
             $is_admin = $is_entry_detail || $is_form_editor;
             if ($is_admin && RG_CURRENT_VIEW != 'entry' && $count >= 5) {
                 break;
             }
             $count++;
         }
         $total = sizeof($this->choices);
         if ($count < $total) {
             $choices .= "<li class='gchoice_total'>" . sprintf(esc_html__('%d of %d items shown. Edit field to view all', 'gravityforms'), $count, $total) . '</li>';
         }
     }
     return gf_apply_filters(array('gform_field_choices', $this->formId, $this->id), $choices, $this);
 }
Example #6
0
 public static function get_select_choices($field, $value = "")
 {
     $choices = "";
     if (RG_CURRENT_VIEW == "entry" && empty($value)) {
         $choices .= "<option value=''></option>";
     }
     if (is_array($field["choices"])) {
         foreach ($field["choices"] as $choice) {
             //needed for users upgrading from 1.0
             $field_value = !empty($choice["value"]) || $field["enableChoiceValue"] ? $choice["value"] : $choice["text"];
             if ($field["enablePrice"]) {
                 $field_value .= "|" . GFCommon::to_number($choice["price"]);
             }
             if (empty($value) && RG_CURRENT_VIEW != "entry") {
                 $selected = $choice["isSelected"] ? "selected='selected'" : "";
             } else {
                 $selected = RGFormsModel::choice_value_match($field, $choice, $value) ? "selected='selected'" : "";
             }
             $choices .= sprintf("<option value='%s' %s>%s</option>", esc_attr($field_value), $selected, esc_html($choice["text"]));
         }
     }
     return $choices;
 }
 public static function get_select_choices($field, $value = '')
 {
     $choices = '';
     if (RG_CURRENT_VIEW == 'entry' && empty($value) && empty($field->placeholder)) {
         $choices .= "<option value=''></option>";
     }
     if (is_array($field->choices)) {
         if (GFFormsModel::get_input_type($field) == 'select' && !empty($field->placeholder)) {
             $selected = empty($value) ? "selected='selected'" : '';
             $choices .= sprintf("<option value='' %s class='gf_placeholder'>%s</option>", $selected, esc_html($field->placeholder));
         }
         foreach ($field->choices as $choice) {
             //needed for users upgrading from 1.0
             $field_value = !empty($choice['value']) || $field->enableChoiceValue || $field->type == 'post_category' ? $choice['value'] : $choice['text'];
             if ($field->enablePrice) {
                 $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                 $field_value .= '|' . $price;
             }
             if (!isset($_GET['gf_token']) && empty($_POST) && rgblank($value) && RG_CURRENT_VIEW != 'entry') {
                 $selected = rgar($choice, 'isSelected') ? "selected='selected'" : '';
             } else {
                 if (is_array($value)) {
                     $is_match = false;
                     foreach ($value as $item) {
                         if (RGFormsModel::choice_value_match($field, $choice, $item)) {
                             $is_match = true;
                             break;
                         }
                     }
                     $selected = $is_match ? "selected='selected'" : '';
                 } else {
                     $selected = RGFormsModel::choice_value_match($field, $choice, $value) ? "selected='selected'" : '';
                 }
             }
             $choice_markup = sprintf("<option value='%s' %s>%s</option>", esc_attr($field_value), $selected, esc_html($choice['text']));
             $choices .= gf_apply_filters('gform_field_choice_markup_pre_render', array($field->formId, $field->id), $choice_markup, $choice, $field, $value);
         }
     }
     return $choices;
 }
 /**
  * Returns the markup for the rating choices.
  *
  * @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission.
  * @param string $disabled_text The input disabled attribute when in the form editor or entry detail page.
  * @param int $form_id The ID of the current form.
  *
  * @return string
  */
 public function get_rating_choices($value, $disabled_text, $form_id)
 {
     $content = '';
     $is_form_editor = $this->is_form_editor();
     if (is_array($this->choices)) {
         // choices reversed in the form editor from version 2.1.1
         if ($this->reversed) {
             $this->choices = array_reverse($this->choices);
         }
         $choice_id = 0;
         $count = 1;
         $logic_event = $this->get_conditional_logic_event('click');
         foreach ($this->choices as $choice) {
             if ($is_form_editor || $form_id == 0) {
                 $id = $this->id . '_' . $choice_id++;
             } else {
                 $id = $form_id . '_' . $this->id . '_' . $choice_id++;
             }
             $choice_label = $choice['text'];
             $field_value = !empty($choice['value']) || $this->enableChoiceValue ? $choice['value'] : $choice['text'];
             if (rgblank($value) && RG_CURRENT_VIEW != 'entry') {
                 $checked = rgar($choice, 'isSelected') ? "checked='checked'" : '';
             } else {
                 $checked = RGFormsModel::choice_value_match($this, $choice, $value) ? "checked='checked'" : '';
             }
             $content .= sprintf("<input name='input_%d' type='radio' value='%s' %s id='choice_%s' %s %s %s /><label for='choice_%s' title='%s'>%s</label>", $this->id, esc_attr($field_value), $checked, $id, $logic_event, $this->get_tabindex(), $disabled_text, $id, esc_attr($choice_label), $choice_label);
             if ($is_form_editor && $count >= 5) {
                 break;
             }
             $count++;
         }
     }
     return $content;
 }
Example #9
0
 public function get_radio_choices($value = '', $disabled_text, $form_id = 0)
 {
     $choices = '';
     $is_entry_detail = $this->is_entry_detail();
     $is_form_editor = $this->is_form_editor();
     $is_admin = $is_entry_detail || $is_form_editor;
     if (is_array($this->choices)) {
         $choice_id = 0;
         $other_default_value = '';
         // add 'other' choice to choices if enabled
         if ($this->enableOtherChoice) {
             $other_default_value = GFCommon::get_other_choice_value();
             $this->choices[] = array('text' => $other_default_value, 'value' => 'gf_other_choice', 'isSelected' => false, 'isOtherChoice' => true);
         }
         $logic_event = $this->get_conditional_logic_event('click');
         $count = 1;
         foreach ($this->choices as $choice) {
             if ($is_entry_detail || $is_form_editor || $form_id == 0) {
                 $id = $this->id . '_' . $choice_id++;
             } else {
                 $id = $form_id . '_' . $this->id . '_' . $choice_id++;
             }
             $field_value = !empty($choice['value']) || $this->enableChoiceValue ? $choice['value'] : $choice['text'];
             if ($this->enablePrice) {
                 $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                 $field_value .= '|' . $price;
             }
             if (rgblank($value) && RG_CURRENT_VIEW != 'entry') {
                 $checked = rgar($choice, 'isSelected') ? "checked='checked'" : '';
             } else {
                 $checked = RGFormsModel::choice_value_match($this, $choice, $value) ? "checked='checked'" : '';
             }
             $tabindex = $this->get_tabindex();
             $label = sprintf("<label for='choice_%s' id='label_%s'>%s</label>", $id, $id, $choice['text']);
             $input_focus = '';
             // handle 'other' choice
             if (rgar($choice, 'isOtherChoice')) {
                 $onfocus = !$is_admin ? 'jQuery(this).prev("input")[0].click(); if(jQuery(this).val() == "' . $other_default_value . '") { jQuery(this).val(""); }' : '';
                 $onblur = !$is_admin ? 'if(jQuery(this).val().replace(" ", "") == "") { jQuery(this).val("' . $other_default_value . '"); }' : '';
                 $onkeyup = $this->get_conditional_logic_event('keyup');
                 $input_focus = !$is_admin ? "onfocus=\"jQuery(this).next('input').focus();\"" : '';
                 $value_exists = RGFormsModel::choices_value_match($this, $this->choices, $value);
                 if ($value == 'gf_other_choice' && rgpost("input_{$this->id}_other")) {
                     $other_value = rgpost("input_{$this->id}_other");
                 } elseif (!$value_exists && !empty($value)) {
                     $other_value = $value;
                     $value = 'gf_other_choice';
                     $checked = "checked='checked'";
                 } else {
                     $other_value = $other_default_value;
                 }
                 $label = "<input id='input_{$this->formId}_{$this->id}_other' name='input_{$this->id}_other' type='text' value='" . esc_attr($other_value) . "' aria-label='" . esc_attr__('Other', 'gravityforms') . "' onfocus='{$onfocus}' onblur='{$onblur}' {$tabindex} {$onkeyup} {$disabled_text} />";
             }
             $choice_markup = sprintf("<li class='gchoice_{$id}'><input name='input_%d' type='radio' value='%s' %s id='choice_%s' {$tabindex} %s {$logic_event} %s />%s</li>", $this->id, esc_attr($field_value), $checked, $id, $disabled_text, $input_focus, $label);
             $choices .= gf_apply_filters(array('gform_field_choice_markup_pre_render', $this->formId, $this->id), $choice_markup, $choice, $this, $value);
             if ($is_form_editor && $count >= 5) {
                 break;
             }
             $count++;
         }
         $total = sizeof($this->choices);
         if ($count < $total) {
             $choices .= "<li class='gchoice_total'>" . sprintf(esc_html__('%d of %d items shown. Edit field to view all', 'gravityforms'), $count, $total) . '</li>';
         }
     }
     return gf_apply_filters(array('gform_field_choices', $this->formId), $choices, $this);
 }
Example #10
0
 public function get_survey_field_content($content, $field, $value, $lead_id, $form_id, $lead = null)
 {
     if ($field['type'] != 'survey') {
         return $content;
     }
     $sub_type = rgar($field, 'inputType');
     switch ($sub_type) {
         case 'likert':
             $multiple_rows = rgar($field, 'gsurveyLikertEnableMultipleRows');
             $field_id = $field['id'];
             $num_rows = $multiple_rows ? count($field['gsurveyLikertRows']) : 1;
             $table_id = "id='input_{$form_id}_{$field_id}'";
             $content = "<div class='ginput_container'>";
             $content .= "<table {$table_id} class='gsurvey-likert'>";
             $content .= '<tr>';
             if ($multiple_rows) {
                 $content .= "<td class='gsurvey-likert-row-label'></td>";
             }
             $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != 'entry' || IS_ADMIN && RG_CURRENT_VIEW == 'entry' && 'edit' != rgpost('screen_mode') ? "disabled='disabled'" : '';
             foreach ($field['choices'] as $choice) {
                 $content .= "<td class='gsurvey-likert-choice-label'>";
                 $content .= $choice['text'];
                 $content .= '</td>';
             }
             $content .= '</tr>';
             $row_id = 1;
             for ($i = 1; $i <= $num_rows; $i++) {
                 //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10
                 if ($row_id % 10 == 0) {
                     $row_id++;
                 }
                 $row_text = $field['gsurveyLikertRows'][$i - 1]['text'];
                 $row_value = $field['gsurveyLikertRows'][$i - 1]['value'];
                 $content .= '<tr>';
                 if ($multiple_rows) {
                     $content .= "<td class='gsurvey-likert-row-label'>{$row_text}</td>";
                 }
                 $choice_id = 1;
                 foreach ($field['choices'] as $choice) {
                     //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10
                     if ($choice_id % 10 == 0) {
                         $choice_id++;
                     }
                     $id = $field['id'] . '_' . $row_id . '_' . $choice_id;
                     $field_value = $multiple_rows ? $row_value . ':' . $choice['value'] : $choice['value'];
                     $cell_class = 'gsurvey-likert-choice';
                     $checked = '';
                     $selected = false;
                     if (rgblank($value) && empty($lead)) {
                         $checked = '';
                     } else {
                         if ($multiple_rows) {
                             $input_name = $field['id'] . '.' . $row_id;
                             if (is_array($value) && isset($value[$input_name])) {
                                 $response_value = $value[$input_name];
                                 $selected = $response_value == $field_value ? true : false;
                             } else {
                                 if ($lead == null) {
                                     $lead = GFFormsModel::get_lead($lead_id);
                                 }
                                 if (false === $lead) {
                                     $selected = false;
                                 } else {
                                     $response_col_val = $this->get_likert_col_val_for_row_from_entry($row_value, $field_id, $lead);
                                     $selected = $response_col_val == $choice['value'] ? true : false;
                                 }
                             }
                         } else {
                             $selected = $choice['value'] == $value ? true : false;
                         }
                     }
                     if ($selected) {
                         $checked = "checked='checked'";
                         $cell_class = $cell_class . ' gsurvey-likert-selected';
                     }
                     $logic_event = empty($field['conditionalLogicFields']) || IS_ADMIN ? '' : "onclick='gf_apply_rules(" . $field['formId'] . ',' . GFCommon::json_encode($field['conditionalLogicFields']) . ");'";
                     $tabindex = GFCommon::get_tabindex();
                     $content .= "<td class='{$cell_class}'>";
                     if ($multiple_rows) {
                         //
                         $input_id = sprintf('input_%d.%d', $field_id, $row_id);
                     } else {
                         $input_id = sprintf('input_%d', $field_id);
                     }
                     $content .= sprintf("<input name='{$input_id}' type='radio' {$logic_event} value='%s' %s id='choice_%s' {$tabindex} %s />", esc_attr($field_value), $checked, $id, $disabled_text);
                     $content .= '</td>';
                     $choice_id++;
                 }
                 $row_id++;
                 $content .= '</tr>';
             }
             $content .= '</table>';
             $content .= '</div>';
             break;
         case 'rank':
             $field_id = $field['id'];
             $input_id = "gsurvey-rank-{$form_id}-{$field_id}";
             $content = "<div class='ginput_container'>";
             $content .= "<ul id='{$input_id}' class='gsurvey-rank'>";
             $handle_image_url = $this->get_base_url() . '/images/arrow-handle.png';
             $choice_id = 0;
             $count = 1;
             $choices = array();
             if (false === empty($value)) {
                 $ordered_values = explode(',', $value);
                 foreach ($ordered_values as $ordered_value) {
                     $choices[] = array('value' => $ordered_value, 'text' => RGFormsModel::get_choice_text($field, $ordered_value));
                 }
             } else {
                 $choices = $field['choices'];
             }
             foreach ($choices as $choice) {
                 $id = $field['id'] . '_' . $choice_id++;
                 $field_value = !empty($choice['value']) || rgar($field, 'enableChoiceValue') ? $choice['value'] : $choice['text'];
                 $content .= sprintf("<li data-index='{$choice_id}' class='gsurvey-rank-choice choice_%s' id='{$field_value}' ><img src='{$handle_image_url}'  alt='' />%s</li>", $id, $choice['text']);
                 if (IS_ADMIN && RG_CURRENT_VIEW != 'entry' && $count >= 5) {
                     break;
                 }
                 $count++;
             }
             $content .= '</ul>';
             $content .= sprintf("<input type='hidden' id='{$input_id}-hidden' name='input_%d' />", $field_id);
             $content .= '</div>';
             break;
         case 'rating':
             $field_id = $field['id'];
             $div_id = "input_{$form_id}_{$field_id}";
             $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != 'entry' ? "disabled='disabled'" : '';
             $content = "<div class='gsurvey-rating-wrapper'><div id='{$div_id}' class='gsurvey-rating'>";
             $choice_id = 0;
             $count = 1;
             // choices reversed in the form editor from version 2.1.1
             if (rgar($field, 'reversed')) {
                 $field['choices'] = array_reverse($field['choices']);
             }
             foreach ($field['choices'] as $choice) {
                 $id = $field['id'] . '_' . $choice_id++;
                 $field_value = !empty($choice['value']) || rgar($field, 'enableChoiceValue') ? $choice['value'] : $choice['text'];
                 if (rgblank($value) && RG_CURRENT_VIEW != 'entry') {
                     $checked = rgar($choice, 'isSelected') ? "checked='checked'" : '';
                 } else {
                     $checked = RGFormsModel::choice_value_match($field, $choice, $value) ? "checked='checked'" : '';
                 }
                 $logic_event = empty($field['conditionalLogicFields']) || IS_ADMIN ? '' : "onclick='gf_apply_rules(" . $field['formId'] . ',' . GFCommon::json_encode($field['conditionalLogicFields']) . ");'";
                 $tabindex = GFCommon::get_tabindex();
                 $choice_label = $choice['text'];
                 $content .= sprintf("<input name='input_%d' type='radio' {$logic_event} value='%s' %s id='choice_%s' {$tabindex} %s /><label for='choice_%s' title='%s'>%s</label>", $field_id, esc_attr($field_value), $checked, $id, $disabled_text, $id, $choice_label, $choice_label);
                 if (IS_ADMIN && RG_CURRENT_VIEW != 'entry' && $count >= 5) {
                     break;
                 }
                 $count++;
             }
             $content .= '</div></div>';
     }
     return $content;
 }
 /**
  * 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;
 }
function prso_theme_gform_field_choices($choices, $field)
{
    //Init vars
    $type = 'radio';
    $choices = NULL;
    if (!is_admin()) {
        //Change html content for text input and address fields
        if ($field['type'] === 'radio' || $field['type'] === 'checkbox') {
            if ($field['type'] === 'checkbox') {
                $type = 'checkbox';
            }
            if (is_array($field["choices"])) {
                $choice_id = 0;
                // add "other" choice to choices if enabled
                if (rgar($field, 'enableOtherChoice')) {
                    $other_default_value = GFCommon::get_other_choice_value();
                    $field["choices"][] = array('text' => $other_default_value, 'value' => 'gf_other_choice', 'isSelected' => false, 'isOtherChoice' => true);
                }
                //$logic_event = GFCommon::get_logic_event($field, "click");
                $count = 1;
                foreach ($field["choices"] as $choice) {
                    $id = $field["id"] . '_' . $choice_id++;
                    $field_value = !empty($choice["value"]) || rgar($field, "enableChoiceValue") ? $choice["value"] : $choice["text"];
                    if (rgget("enablePrice", $field)) {
                        $field_value .= "|" . GFCommon::to_number(rgar($choice, "price"));
                    }
                    if (RG_CURRENT_VIEW != "entry") {
                        $checked = rgar($choice, "isSelected") ? "checked='checked'" : "";
                    } else {
                        $checked = RGFormsModel::choice_value_match($field, $choice, $value) ? "checked='checked'" : "";
                    }
                    $tabindex = GFCommon::get_tabindex();
                    $label = sprintf("%s</label>", $choice["text"]);
                    $input_focus = '';
                    // handle "other" choice
                    if (rgar($choice, 'isOtherChoice')) {
                        $onfocus = !IS_ADMIN ? 'jQuery(this).prev("input").attr("checked", true); if(jQuery(this).val() == "' . $other_default_value . '") { jQuery(this).val(""); }' : '';
                        $onblur = !IS_ADMIN ? 'if(jQuery(this).val().replace(" ", "") == "") { jQuery(this).val("' . $other_default_value . '"); }' : '';
                        $input_focus = !IS_ADMIN ? "onfocus=\"jQuery(this).next('input').focus();\"" : "";
                        $value_exists = RGFormsModel::choices_value_match($field, $field["choices"], $value);
                        if ($value == 'gf_other_choice' && rgpost("input_{$field["id"]}_other")) {
                            $other_value = rgpost("input_{$field["id"]}_other");
                        } else {
                            if (!$value_exists && !empty($value)) {
                                $other_value = $value;
                                $value = 'gf_other_choice';
                                $checked = "checked='checked'";
                            } else {
                                $other_value = $other_default_value;
                            }
                        }
                        $label = "<input name='input_{$field["id"]}_other' type='text' value='" . esc_attr($other_value) . "' onfocus='{$onfocus}' onblur='{$onblur}' {$tabindex} {$disabled_text} />";
                    }
                    $choices .= sprintf("<li class='gchoice_{$id}'><label for='choice_%s'><input name='input_%d' type='{$type}' value='%s' %s id='choice_%s' {$tabindex} %s />&nbsp;%s</li>", $field["id"], $field["id"], esc_attr($field_value), $checked, $id, $input_focus, $label);
                    if (IS_ADMIN && RG_CURRENT_VIEW != "entry" && $count >= 5) {
                        break;
                    }
                    $count++;
                }
                $total = sizeof($field["choices"]);
                if ($count < $total) {
                    $choices .= "<li class='gchoice_total'>" . sprintf(__("%d of %d items shown. Edit field to view all", "gravityforms"), $count, $total) . "</li>";
                }
            }
        }
    }
    return $choices;
}
Example #13
0
 public static function get_entries_data($form, $fields, $search_criteria = array(), $state_array = array())
 {
     $view_slug = rgpost("view");
     //todo: add hooks to modify $max_execution_time and $page_size
     $max_execution_time = 25;
     //seconds
     $page_size = 200;
     $time_start = microtime(true);
     $data = array();
     $offset = 0;
     $entry_count = 0;
     $field_data = array();
     $form_id = $form['id'];
     if ($state_array) {
         //get counts from state
         $data = $state_array;
         $offset = (int) rgar($data, "offset");
         $entry_count = $offset;
         $field_data = rgar($data, "field_data");
     } else {
         //initialize counts
         foreach ($fields as $field) {
             $field_type = GFFormsModel::get_input_type($field);
             if (false === isset($field["choices"])) {
                 $field_data[$field["id"]] = 0;
                 continue;
             }
             $choices = $field["choices"];
             if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) {
                 foreach ($field["gsurveyLikertRows"] as $row) {
                     foreach ($choices as $choice) {
                         $field_data[$field["id"]][$row["value"]][$choice['value']] = 0;
                     }
                 }
             } else {
                 foreach ($choices as $choice) {
                     $field_data[$field["id"]][$choice['value']] = 0;
                 }
             }
         }
     }
     $count_search_leads = GFFormsModel::count_search_leads($form_id, $search_criteria);
     $data["entry_count"] = $count_search_leads;
     $entries_left = $count_search_leads - $offset;
     while ($entries_left >= 0) {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $search_leads_time_start = microtime(true);
         $leads = GFFormsModel::search_leads($form_id, $search_criteria, null, $paging);
         $search_leads_time_end = microtime(true);
         $search_leads_time = $search_leads_time_end - $search_leads_time_start;
         $leads_in_search = count($leads);
         $entry_count += $leads_in_search;
         foreach ($leads as $lead) {
             foreach ($fields as $field) {
                 $field_type = GFFormsModel::get_input_type($field);
                 $field_id = $field["id"];
                 $value = RGFormsModel::get_lead_field_value($lead, $field);
                 if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) {
                     if (empty($value)) {
                         continue;
                     }
                     foreach ($value as $value_vector) {
                         if (empty($value_vector)) {
                             continue;
                         }
                         list($row_val, $col_val) = explode(":", $value_vector, 2);
                         if (isset($field_data[$field["id"]][$row_val]) && isset($field_data[$field["id"]][$row_val][$col_val])) {
                             $field_data[$field["id"]][$row_val][$col_val]++;
                         }
                     }
                 } elseif ($field_type == "rank") {
                     $score = count(rgar($field, "choices"));
                     $values = explode(",", $value);
                     foreach ($values as $ranked_value) {
                         $field_data[$field["id"]][$ranked_value] += $score;
                         $score--;
                     }
                 } else {
                     if (false === isset($field["choices"])) {
                         if (false === empty($value)) {
                             $field_data[$field_id]++;
                         }
                         continue;
                     }
                     $choices = $field["choices"];
                     foreach ($choices as $choice) {
                         $choice_is_selected = false;
                         if (is_array($value)) {
                             $choice_value = rgar($choice, "value");
                             if (in_array($choice_value, $value)) {
                                 $choice_is_selected = true;
                             }
                         } else {
                             if (RGFormsModel::choice_value_match($field, $choice, $value)) {
                                 $choice_is_selected = true;
                             }
                         }
                         if ($choice_is_selected) {
                             $field_data[$field_id][$choice['value']]++;
                         }
                     }
                 }
             }
         }
         $data["field_data"] = $field_data;
         $data = apply_filters("gresults_entries_data_" . $view_slug, $data, $form, $fields, $leads);
         if ($leads_in_search < $page_size) {
             $data["status"] = "complete";
             break;
         }
         $offset += $page_size;
         $entries_left -= $page_size;
         $time_end = microtime(true);
         $execution_time = $time_end - $time_start;
         if ($execution_time + $search_leads_time > $max_execution_time) {
             $data["status"] = "incomplete";
             $data["offset"] = $offset;
             break;
         }
     }
     return $data;
 }