public static function replace_merge_tags($form)
 {
     $current_page = isset(GFFormDisplay::$submission[$form['id']]) ? GFFormDisplay::$submission[$form['id']]['page_number'] : 1;
     $replace_merge_tags_in_labels = apply_filters('gppc_replace_merge_tags_in_labels', false, $form);
     // get all HTML fields on the current page
     foreach ($form['fields'] as &$field) {
         if ($replace_merge_tags_in_labels) {
             // @todo: add support for individual input labels
             $label = GFCommon::get_label($field);
             if (gp_preview_submission()->has_any_merge_tag($label)) {
                 $field['label'] = self::preview_replace_variables($label, $form);
             }
         }
         // skip all fields on the first page
         if (rgar($field, 'pageNumber') <= 1) {
             continue;
         }
         $default_value = rgar($field, 'defaultValue');
         if (gp_preview_submission()->has_any_merge_tag($default_value)) {
             $field['defaultValue'] = rgar($field, 'pageNumber') != $current_page ? '' : self::preview_replace_variables($default_value, $form);
         }
         // only run 'content' filter for fields on the current page
         if (rgar($field, 'pageNumber') != $current_page) {
             continue;
         }
         $html_content = rgar($field, 'content');
         if (gp_preview_submission()->has_any_merge_tag($html_content)) {
             $field['content'] = self::preview_replace_variables($html_content, $form);
         }
     }
     return $form;
 }
 /**
  * Loads the matching meta data for the currently set form id
  * @return boolean true on success and false on failure
  */
 public function load()
 {
     if (!defined('WPINC') || !$this->_post_id || !class_exists('GFAPI')) {
         return false;
     }
     $lead = \GFAPI::get_entry($this->_post_id);
     $form = \GFAPI::get_form($lead['form_id']);
     $values = array();
     foreach ($form['fields'] as $field) {
         if (isset($field["inputs"]) && is_array($field['inputs'])) {
             foreach ($field['inputs'] as $input) {
                 // Extract best label
                 $key = $input['label'] ? $input['label'] : \GFCommon::get_label($field, (string) $input["id"]);
                 // Redundant formatting
                 $key = strtolower(str_replace(array(' '), array('_'), $key));
                 $value = isset($lead[(string) $input['id']]) ? $lead[(string) $input['id']] : "";
                 $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES);
             }
         } elseif (!rgar($field, 'displayOnly')) {
             // Extract best label
             $key = isset($field['adminLabel']) && $field['adminLabel'] != "" ? $field['adminLabel'] : ($field['label'] ? $field['label'] : \GFCommon::get_label($field));
             // More redundant formatting
             $key = strtolower(str_replace(array(' '), array('_'), $key));
             $value = isset($lead[$field['id']]) ? $lead[$field['id']] : "";
             $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES);
         }
     }
     try {
         $this->assign($values);
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     return true;
 }
 public function load_form_data($lead, $form_id = '')
 {
     $form_id = is_numeric($form_id) ? $form_id : (isset($lead['form_id']) ? $lead['form_id'] : $lead['id']);
     // No form id
     if (!$form_id) {
         return false;
     }
     $form = \GFAPI::get_form($form_id);
     // Invalid form ID
     if (!$form) {
         return false;
     }
     $file_fields = array();
     $url_field = array();
     $values = array();
     foreach ($form['fields'] as $field) {
         if (isset($field["inputs"]) && is_array($field['inputs'])) {
             foreach ($field['inputs'] as $input) {
                 // Extract best label
                 $key = $input['label'] ? $input['label'] : \GFCommon::get_label($field, (string) $input["id"]);
                 // Redundant formatting
                 $key = strtolower(str_replace(array(' '), array('_'), $key));
                 $value = isset($lead[(string) $input['id']]) ? $lead[(string) $input['id']] : "";
                 $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES);
             }
         } elseif (!rgar($field, 'displayOnly')) {
             // Extract best label
             $key = isset($field['adminLabel']) && $field['adminLabel'] != "" ? $field['adminLabel'] : ($field['label'] ? $field['label'] : \GFCommon::get_label($field));
             // More redundant formatting
             $key = strtolower(str_replace(array(' '), array('_'), $key));
             $value = isset($lead[$field['id']]) ? $lead[$field['id']] : "";
             $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES);
         }
     }
     $values['logo'] = $this->logo ? $this->logo : $values['logo'];
     // An image field being re-assign from post file data
     try {
         $this->assign($values);
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     if (!$this->product_id && isset($lead['source_url'])) {
         // only needed if used in conjunction with woocommerce fulfillment
         $this->product_id = url_to_postid($lead['source_url']);
     }
     return true;
 }
Beispiel #4
0
 public static function select_export_form()
 {
     check_ajax_referer('rg_select_export_form', 'rg_select_export_form');
     $form_id = intval($_POST['form_id']);
     $form = RGFormsModel::get_form_meta($form_id);
     /**
      * Filters through the Form Export Page
      *
      * @param int $form_id The ID of the form to export
      * @param int $form The Form Object of the form to export
      */
     $form = gf_apply_filters('gform_form_export_page', $form_id, $form);
     $filter_settings = GFCommon::get_field_filter_settings($form);
     $filter_settings_json = json_encode($filter_settings);
     $fields = array();
     $form = GFExport::add_default_export_fields($form);
     if (is_array($form['fields'])) {
         /* @var GF_Field $field */
         foreach ($form['fields'] as $field) {
             $inputs = $field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     $fields[] = array($input['id'], GFCommon::get_label($field, $input['id']));
                 }
             } else {
                 if (!$field->displayOnly) {
                     $fields[] = array($field->id, GFCommon::get_label($field));
                 }
             }
         }
     }
     $field_json = GFCommon::json_encode($fields);
     die("EndSelectExportForm({$field_json}, {$filter_settings_json});");
 }
 private static function get_field_merge_tag($form, $field_id)
 {
     $field = self::get_field($form, $field_id);
     if (!$field) {
         return false;
     }
     return '{' . GFCommon::get_label($field, $field_id) . ':' . $field_id . '}';
 }
Beispiel #6
0
 public static function start_export($form)
 {
     $form_id = $form['id'];
     $fields = $_POST['export_field'];
     $start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00');
     $end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59');
     $search_criteria['status'] = 'active';
     $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
     if (!empty($start_date)) {
         $search_criteria['start_date'] = $start_date;
     }
     if (!empty($end_date)) {
         $search_criteria['end_date'] = $end_date;
     }
     $sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info');
     GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}");
     GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}");
     $form = self::add_default_export_fields($form);
     $entry_count = GFAPI::count_entries($form_id, $search_criteria);
     $page_size = 100;
     $offset = 0;
     //Adding BOM marker for UTF-8
     $lines = chr(239) . chr(187) . chr(191);
     // set the separater
     $separator = gf_apply_filters('gform_export_separator', $form_id, ',', $form_id);
     $field_rows = self::get_field_row_count($form, $fields, $entry_count);
     //writing header
     $headers = array();
     foreach ($fields as $field_id) {
         $field = RGFormsModel::get_field($form, $field_id);
         $label = gf_apply_filters('gform_entries_field_header_pre_export', array($form_id, $field_id), GFCommon::get_label($field, $field_id), $form, $field);
         $value = str_replace('"', '""', $label);
         GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}");
         $headers[$field_id] = $value;
         $subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
         if ($subrow_count == 0) {
             $lines .= '"' . $value . '"' . $separator;
         } else {
             for ($i = 1; $i <= $subrow_count; $i++) {
                 $lines .= '"' . $value . ' ' . $i . '"' . $separator;
             }
         }
         GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
     }
     $lines = substr($lines, 0, strlen($lines) - 1) . "\n";
     //paging through results for memory issues
     while ($entry_count > 0) {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
         $leads = gf_apply_filters('gform_leads_before_export', $form_id, $leads, $form, $paging);
         foreach ($leads as $lead) {
             foreach ($fields as $field_id) {
                 switch ($field_id) {
                     case 'date_created':
                         $lead_gmt_time = mysql2date('G', $lead['date_created']);
                         $lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
                         $value = date_i18n('Y-m-d H:i:s', $lead_local_time, true);
                         break;
                     default:
                         $field = RGFormsModel::get_field($form, $field_id);
                         $value = is_object($field) ? $field->get_value_export($lead, $field_id, false, true) : rgar($lead, $field_id);
                         $value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead);
                         GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}");
                         break;
                 }
                 if (isset($field_rows[$field_id])) {
                     $list = empty($value) ? array() : unserialize($value);
                     foreach ($list as $row) {
                         $row_values = array_values($row);
                         $row_str = implode('|', $row_values);
                         $lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator;
                     }
                     //filling missing subrow columns (if any)
                     $missing_count = intval($field_rows[$field_id]) - count($list);
                     for ($i = 0; $i < $missing_count; $i++) {
                         $lines .= '""' . $separator;
                     }
                 } else {
                     $value = maybe_unserialize($value);
                     if (is_array($value)) {
                         $value = implode('|', $value);
                     }
                     $lines .= '"' . str_replace('"', '""', $value) . '"' . $separator;
                 }
             }
             $lines = substr($lines, 0, strlen($lines) - 1);
             GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
             $lines .= "\n";
         }
         $offset += $page_size;
         $entry_count -= $page_size;
         if (!seems_utf8($lines)) {
             $lines = utf8_encode($lines);
         }
         $lines = apply_filters('gform_export_lines', $lines);
         echo $lines;
         $lines = '';
     }
     /**
      * Fires after exporting all the entries in form
      *
      * @param array $form The Form object to get the entries from
      * @param string $start_date The start date for when the export of entries should take place
      * @param string $end_date The end date for when the export of entries should stop
      * @param array $fields The specified fields where the entries should be exported from
      */
     do_action('gform_post_export_entries', $form, $start_date, $end_date, $fields);
 }
 public function ajax_get_results()
 {
     $output = array();
     $html = "";
     $form_id = rgpost("id");
     $form = GFFormsModel::get_form_meta($form_id);
     $form = apply_filters("gform_form_pre_results_{$form_id}", apply_filters("gform_form_pre_results", $form));
     $search_criteria["status"] = "active";
     $fields = $this->get_fields($form);
     $total_entries = GFAPI::count_entries($form_id, $search_criteria);
     if ($total_entries == 0) {
         $html = __("No results.", "gravityforms");
     } else {
         $search_criteria = array();
         $search_criteria["field_filters"] = GFCommon::get_field_filters_from_post();
         $start_date = rgpost("start");
         $end_date = rgpost("end");
         if ($start_date) {
             $search_criteria["start_date"] = $start_date;
         }
         if ($end_date) {
             $search_criteria["end_date"] = $end_date;
         }
         $search_criteria["status"] = "active";
         $output["s"] = http_build_query($search_criteria);
         $state_array = null;
         if (isset($_POST["state"])) {
             $state = $_POST["state"];
             $posted_check_sum = rgpost("checkSum");
             $generated_check_sum = self::generate_checksum($state);
             $state_array = json_decode(base64_decode($state), true);
             if ($generated_check_sum !== $posted_check_sum) {
                 $output["status"] = "complete";
                 $output["html"] = __('There was an error while processing the entries. Please contact support.', "gravityforms");
                 echo json_encode($output);
                 die;
             }
         }
         $data = isset($this->_callbacks["data"]) ? call_user_func($this->_callbacks["data"], $form, $fields, $search_criteria, $state_array) : $this->get_results_data($form, $fields, $search_criteria, $state_array);
         $entry_count = $data["entry_count"];
         if ("incomplete" === rgar($data, "status")) {
             $state = base64_encode(json_encode($data));
             $output["status"] = "incomplete";
             $output["stateObject"] = $state;
             $output["checkSum"] = self::generate_checksum($state);
             $output["html"] = sprintf(__('Entries processed: %1$d of %2$d', "gravityforms"), rgar($data, "offset"), $entry_count);
             echo json_encode($output);
             die;
         }
         if ($total_entries > 0) {
             $html = isset($this->_callbacks["markup"]) ? call_user_func($this->_callbacks["markup"], $html, $data, $form, $fields) : "";
             if (empty($html)) {
                 foreach ($fields as $field) {
                     $field_id = $field['id'];
                     $html .= "<div class='gresults-results-field' id='gresults-results-field-{$field_id}'>";
                     $html .= "<div class='gresults-results-field-label'>" . esc_html(GFCommon::get_label($field)) . "</div>";
                     $html .= "<div>" . self::get_field_results($form_id, $data, $field, $search_criteria) . "</div>";
                     $html .= "</div>";
                 }
             }
         } else {
             $html .= __("No results", "gravityforms");
         }
     }
     $output["html"] = $html;
     $output["status"] = "complete";
     $output["searchCriteria"] = $search_criteria;
     echo json_encode($output);
     die;
 }
Beispiel #8
0
 private static function get_form_fields($form)
 {
     $fields = array();
     if (is_array($form["fields"])) {
         foreach ($form["fields"] as $field) {
             if (isset($field["inputs"]) && is_array($field["inputs"])) {
                 foreach ($field["inputs"] as $input) {
                     $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
                 }
             } else {
                 if (!rgar($field, 'displayOnly')) {
                     $fields[] = array($field["id"], GFCommon::get_label($field));
                 }
             }
         }
     }
     return $fields;
 }
Beispiel #9
0
 public static function get_submitted_fields($form, $lead, $display_empty = false, $use_text = false, $format = "html", $use_admin_label = false, $merge_tag = "", $options = "")
 {
     $field_data = "";
     if ($format == "html") {
         $field_data = '<table width="99%" border="0" cellpadding="1" cellspacing="0" bgcolor="#EAEAEA"><tr><td>
                         <table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">';
     }
     $options_array = explode(",", $options);
     $no_admin = in_array("noadmin", $options_array);
     $no_hidden = in_array("nohidden", $options_array);
     $has_product_fields = false;
     foreach ($form["fields"] as $field) {
         $field_value = "";
         $field_label = $use_admin_label && !rgempty("adminLabel", $field) ? rgar($field, "adminLabel") : esc_html(GFCommon::get_label($field));
         switch ($field["type"]) {
             case "captcha":
                 break;
             case "section":
                 if (!GFCommon::is_section_empty($field, $form, $lead) || $display_empty) {
                     switch ($format) {
                         case "text":
                             $field_value = "--------------------------------\n{$field_label}\n\n";
                             break;
                         default:
                             $field_value = sprintf('<tr>
                                                         <td colspan="2" style="font-size:14px; font-weight:bold; background-color:#EEE; border-bottom:1px solid #DFDFDF; padding:7px 7px">%s</td>
                                                    </tr>', $field_label);
                             break;
                     }
                 }
                 $field_value = apply_filters("gform_merge_tag_filter", $field_value, $merge_tag, $options, $field, $field_label);
                 $field_data .= $field_value;
                 break;
             case "password":
                 //ignore password fields
                 break;
             default:
                 //ignore product fields as they will be grouped together at the end of the grid
                 if (self::is_product_field($field["type"])) {
                     $has_product_fields = true;
                     continue;
                 } else {
                     if (RGFormsModel::is_field_hidden($form, $field, array(), $lead)) {
                         //ignore fields hidden by conditional logic
                         continue;
                     }
                 }
                 $raw_field_value = RGFormsModel::get_lead_field_value($lead, $field);
                 $field_value = GFCommon::get_lead_field_display($field, $raw_field_value, rgar($lead, "currency"), $use_text, $format, "email");
                 $display_field = true;
                 //depending on parameters, don't display adminOnly or hidden fields
                 if ($no_admin && rgar($field, "adminOnly")) {
                     $display_field = false;
                 } else {
                     if ($no_hidden && RGFormsModel::get_input_type($field) == "hidden") {
                         $display_field = false;
                     }
                 }
                 //if field is not supposed to be displayed, pass false to filter. otherwise, pass field's value
                 if (!$display_field) {
                     $field_value = false;
                 }
                 $field_value = apply_filters("gform_merge_tag_filter", $field_value, $merge_tag, $options, $field, $raw_field_value);
                 if ($field_value === false) {
                     continue;
                 }
                 if (!empty($field_value) || strlen($field_value) > 0 || $display_empty) {
                     switch ($format) {
                         case "text":
                             $field_data .= "{$field_label}: {$field_value}\n\n";
                             break;
                         default:
                             $field_data .= sprintf('<tr bgcolor="#EAF2FA">
                                                         <td colspan="2">
                                                             <font style="font-family: sans-serif; font-size:12px;"><strong>%s</strong></font>
                                                         </td>
                                                    </tr>
                                                    <tr bgcolor="#FFFFFF">
                                                         <td width="20">&nbsp;</td>
                                                         <td>
                                                             <font style="font-family: sans-serif; font-size:12px;">%s</font>
                                                         </td>
                                                    </tr>', $field_label, empty($field_value) && strlen($field_value) == 0 ? "&nbsp;" : $field_value);
                             break;
                     }
                 }
         }
     }
     if ($has_product_fields) {
         $field_data .= self::get_submitted_pricing_fields($form, $lead, $format, $use_text, $use_admin_label);
     }
     if ($format == "html") {
         $field_data .= '</table>
                     </td>
                </tr>
            </table>';
     }
     return $field_data;
 }
 private static function get_field_merge_tag($form, $field_id)
 {
     $field = self::get_field($form, $field_id);
     if (!$field) {
         return false;
     }
     return "{" . GFCommon::get_label($field, $field_id) . ":" . $field_id . "}";
 }
 public static function select_export_form()
 {
     check_ajax_referer("rg_select_export_form", "rg_select_export_form");
     $form_id = intval($_POST["form_id"]);
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     $form = GFExport::add_default_export_fields($form);
     if (is_array($form["fields"])) {
         foreach ($form["fields"] as $field) {
             if (is_array(rgar($field, "inputs"))) {
                 foreach ($field["inputs"] as $input) {
                     $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
                 }
             } else {
                 if (!rgar($field, "displayOnly")) {
                     $fields[] = array($field["id"], GFCommon::get_label($field));
                 }
             }
         }
     }
     $field_json = GFCommon::json_encode($fields);
     die("EndSelectExportForm({$field_json});");
 }
function gffd_get_form_fields($form)
{
    $fields = array();
    if (is_array($form["fields"])) {
        foreach ($form["fields"] as $field) {
            if (is_array(gffd_rgar($field, 'inputs'))) {
                foreach ($field["inputs"] as $input) {
                    $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
                }
            } else {
                if (!gffd_rgar($field, 'displayOnly')) {
                    $fields[] = array($field["id"], GFCommon::get_label($field));
                }
            }
        }
    }
    return $fields;
}
 public function get_column_value_amount($feed)
 {
     $form = $this->get_current_form();
     $field_id = $feed["meta"]["transactionType"] == "subscription" ? $feed["meta"]["recurringAmount"] : $feed["meta"]["paymentAmount"];
     if ($field_id == "form_total") {
         $label = __("Form Total", "gravityforms");
     } else {
         $field = GFFormsModel::get_field($form, $field_id);
         $label = GFCommon::get_label($field);
     }
     return $label;
 }
 public function ajax_get_results()
 {
     $output = array();
     $html = "";
     $form_id = rgpost("id");
     $form = GFFormsModel::get_form_meta($form_id);
     $form = apply_filters("gform_form_pre_results_{$form_id}", apply_filters("gform_form_pre_results", $form));
     $search_criteria = array();
     $fields = $this->get_fields($form);
     $total_entries = GFFormsModel::count_search_leads($form_id, $search_criteria);
     if ($total_entries == 0) {
         $html = __("No results.", "gravityforms");
     } else {
         $filter_fields = rgpost("f");
         if (is_array($filter_fields)) {
             $filter_types = rgpost("t");
             $filter_operators = rgpost("o");
             $filter_values = rgpost("v");
             for ($i = 0; $i < count($filter_fields); $i++) {
                 $field_filter = array();
                 $field_filter["type"] = "field";
                 $key = $filter_fields[$i];
                 $filter_type = $filter_types[$i];
                 $operator = $filter_operators[$i];
                 $val = $filter_values[$i];
                 $strpos_row_key = strpos($key, "|");
                 if ($strpos_row_key !== false) {
                     //multi-row
                     $key_array = explode("|", $key);
                     $key = $key_array[0];
                     $val = $key_array[1] . ":" . $val;
                 }
                 $field_filter["key"] = $key;
                 $field_filter["type"] = $filter_type;
                 $field_filter["operator"] = $operator;
                 $field_filter["value"] = $val;
                 $search_criteria[] = $field_filter;
             }
         }
         $start_date = rgpost("start");
         $end_date = rgpost("end");
         if ($start_date) {
             $search_criteria[] = array('key' => 'date_created', 'type' => 'info', 'operator' => '>=', 'value' => $start_date);
         }
         if ($end_date) {
             $search_criteria[] = array('key' => 'date_created', 'type' => 'info', 'operator' => '<=', 'value' => $end_date);
         }
         $search_criteria[] = array("type" => "info", "key" => "status", "value" => "active");
         $output["s"] = http_build_query($search_criteria);
         $state_array = null;
         if (isset($_POST["state"])) {
             $state = $_POST["state"];
             $posted_check_sum = rgpost("checkSum");
             $generated_check_sum = self::generate_checksum($state);
             $state_array = json_decode(base64_decode($state), true);
             if ($generated_check_sum !== $posted_check_sum) {
                 $output["status"] = "complete";
                 $output["html"] = __('There was an error while processing the entries. Please contact support.', "gravityforms");
                 echo json_encode($output);
                 die;
             }
         }
         $data = $this->get_results_data($form, $fields, $search_criteria, $state_array);
         $entry_count = $data["entry_count"];
         if ("incomplete" === rgar($data, "status")) {
             $state = base64_encode(json_encode($data));
             $output["status"] = "incomplete";
             $output["stateObject"] = $state;
             $output["checkSum"] = self::generate_checksum($state);
             $output["html"] = sprintf(__('Entries processed: %1$d of %2$d', "gravityforms"), rgar($data, "offset"), $entry_count);
             echo json_encode($output);
             die;
         }
         if ($total_entries > 0) {
             $html = isset($this->_callbacks["markup"]) ? call_user_func($this->_callbacks["markup"], $html, $data, $form, $fields) : "";
             if (empty($html)) {
                 foreach ($fields as $field) {
                     $field_id = $field['id'];
                     $html .= "<div class='gresults-results-field' id='gresults-results-field-{$field_id}'>";
                     $html .= "<div class='gresults-results-field-label'>" . esc_html(GFCommon::get_label($field)) . "</div>";
                     $html .= "<div>" . self::get_field_results($form_id, $data, $field, $search_criteria) . "</div>";
                     $html .= "</div>";
                 }
             }
         } else {
             $html .= __("No results", "gravityforms");
         }
     }
     $output["html"] = $html;
     $output["status"] = "complete";
     $output["searchCriteria"] = $search_criteria;
     echo json_encode($output);
     die;
 }
 public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false)
 {
     if (empty($input_id) || absint($input_id) == $input_id) {
         $selected = array();
         foreach ($this->inputs as $input) {
             $index = (string) $input['id'];
             if (!rgempty($index, $entry)) {
                 $selected[] = GFCommon::selection_display(rgar($entry, $index), $this, rgar($entry, 'currency'), $use_text);
             }
         }
         return implode(', ', $selected);
     } elseif ($is_csv) {
         $value = $this->is_checkbox_checked($input_id, GFCommon::get_label($this, $input_id), $entry);
         return empty($value) ? '' : $value;
     } else {
         return GFCommon::selection_display(rgar($entry, $input_id), $this, rgar($entry, 'currency'), $use_text);
     }
 }
Beispiel #16
0
 public static function start_export($form)
 {
     $form_id = $form["id"];
     $fields = $_POST["export_field"];
     $start_date = $_POST["export_date_start"];
     $end_date = $_POST["export_date_end"];
     //adding default fields
     array_push($form["fields"], array("id" => "id", "label" => __("Entry Id", "gravityforms")));
     array_push($form["fields"], array("id" => "date_created", "label" => __("Entry Date", "gravityforms")));
     array_push($form["fields"], array("id" => "ip", "label" => __("User IP", "gravityforms")));
     array_push($form["fields"], array("id" => "source_url", "label" => __("Source Url", "gravityforms")));
     array_push($form["fields"], array("id" => "payment_status", "label" => __("Payment Status", "gravityforms")));
     array_push($form["fields"], array("id" => "payment_date", "label" => __("Payment Date", "gravityforms")));
     array_push($form["fields"], array("id" => "transaction_id", "label" => __("Transaction Id", "gravityforms")));
     $entry_count = RGFormsModel::get_lead_count($form_id, "", null, null, $start_date, $end_date);
     $page_size = 200;
     $offset = 0;
     //Adding BOM marker for UTF-8
     $lines = chr(239) . chr(187) . chr(191);
     //writing header
     foreach ($fields as $field_id) {
         $field = RGFormsModel::get_field($form, $field_id);
         $value = '"' . str_replace('"', '""', GFCommon::get_label($field, $field_id)) . '"';
         $lines .= "{$value},";
     }
     $lines = substr($lines, 0, strlen($lines) - 1) . "\n";
     //paging through results for memory issues
     while ($entry_count > 0) {
         $leads = RGFormsModel::get_leads($form_id, "date_created", "DESC", "", $offset, $page_size, null, null, false, $start_date, $end_date);
         foreach ($leads as $lead) {
             foreach ($fields as $field_id) {
                 $long_text = "";
                 if (strlen($lead[$field_id]) >= GFORMS_MAX_FIELD_LENGTH) {
                     $long_text = RGFormsModel::get_field_value_long($lead["id"], $field_id);
                 }
                 $value = !empty($long_text) ? $long_text : $lead[$field_id];
                 $lines .= '"' . str_replace('"', '""', $value) . '",';
             }
             $lines = substr($lines, 0, strlen($lines) - 1);
             $lines .= "\n";
         }
         $offset += $page_size;
         $entry_count -= $page_size;
         if (!seems_utf8($lines)) {
             $lines = utf8_encode($lines);
         }
         echo $lines;
         $lines = "";
     }
 }
 public static function start_export($form)
 {
     $form_id = $form['id'];
     $fields = $_POST['export_field'];
     $start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00');
     $end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59');
     $search_criteria['status'] = 'active';
     $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
     if (!empty($start_date)) {
         $search_criteria['start_date'] = $start_date;
     }
     if (!empty($end_date)) {
         $search_criteria['end_date'] = $end_date;
     }
     $sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info');
     GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}");
     GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}");
     $form = self::add_default_export_fields($form);
     $entry_count = GFAPI::count_entries($form_id, $search_criteria);
     $page_size = 100;
     $offset = 0;
     //Adding BOM marker for UTF-8
     $lines = chr(239) . chr(187) . chr(191);
     // set the separater
     $separator = apply_filters('gform_export_separator_' . $form_id, apply_filters('gform_export_separator', ',', $form_id), $form_id);
     $field_rows = self::get_field_row_count($form, $fields, $entry_count);
     //writing header
     $headers = array();
     foreach ($fields as $field_id) {
         $field = RGFormsModel::get_field($form, $field_id);
         $value = str_replace('"', '""', GFCommon::get_label($field, $field_id));
         GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}");
         $headers[$field_id] = $str = preg_replace('/[^a-z\\d ]/i', '', $value);
         $subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
         if ($subrow_count == 0) {
             $lines .= '"' . $value . '"' . $separator;
         } else {
             for ($i = 1; $i <= $subrow_count; $i++) {
                 $lines .= '"' . $value . ' ' . $i . '"' . $separator;
             }
         }
         GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
     }
     $lines = substr($lines, 0, strlen($lines) - 1) . "\n";
     //paging through results for memory issues
     while ($entry_count > 0) {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
         $leads = apply_filters("gform_leads_before_export_{$form_id}", apply_filters('gform_leads_before_export', $leads, $form, $paging), $form, $paging);
         foreach ($leads as $lead) {
             foreach ($fields as $field_id) {
                 switch ($field_id) {
                     case 'date_created':
                         $lead_gmt_time = mysql2date('G', $lead['date_created']);
                         $lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
                         $value = date_i18n('Y-m-d H:i:s', $lead_local_time, true);
                         break;
                     default:
                         $long_text = '';
                         if (strlen(rgar($lead, $field_id)) >= GFORMS_MAX_FIELD_LENGTH - 10) {
                             $long_text = RGFormsModel::get_field_value_long($lead, $field_id, $form);
                         }
                         $value = !empty($long_text) ? $long_text : rgar($lead, $field_id);
                         $field = RGFormsModel::get_field($form, $field_id);
                         $input_type = RGFormsModel::get_input_type($field);
                         if ($input_type == 'checkbox') {
                             //pass in label value that has not had quotes escaped so the is_checkbox_checked function compares the unchanged label value with the lead value
                             $header_label_not_escaped = GFCommon::get_label($field, $field_id);
                             $value = GFFormsModel::is_checkbox_checked($field_id, $header_label_not_escaped, $lead, $form);
                             if ($value === false) {
                                 $value = '';
                             }
                         } else {
                             if ($input_type == 'fileupload' && $field->multipleFiles) {
                                 $value = !empty($value) ? implode(' , ', json_decode($value, true)) : '';
                             }
                         }
                         $value = preg_replace('/[^a-z\\d ]/i', '', $value);
                         $value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead);
                         GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}");
                         break;
                 }
                 if (isset($field_rows[$field_id])) {
                     $list = empty($value) ? array() : unserialize($value);
                     foreach ($list as $row) {
                         $row_values = array_values($row);
                         $row_str = implode('|', $row_values);
                         $lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator;
                     }
                     //filling missing subrow columns (if any)
                     $missing_count = intval($field_rows[$field_id]) - count($list);
                     for ($i = 0; $i < $missing_count; $i++) {
                         $lines .= '""' . $separator;
                     }
                 } else {
                     $value = maybe_unserialize($value);
                     if (is_array($value)) {
                         $value = implode('|', $value);
                     }
                     $lines .= '"' . str_replace('"', '""', $value) . '"' . $separator;
                 }
             }
             $lines = substr($lines, 0, strlen($lines) - 1);
             GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
             $lines .= "\n";
         }
         $offset += $page_size;
         $entry_count -= $page_size;
         if (!seems_utf8($lines)) {
             $lines = utf8_encode($lines);
         }
         if (function_exists('mb_convert_encoding')) {
             // Convert the contents to UTF-16LE which has wider support than UTF-8.
             // This fixes an issue with special characters in Excel for Mac.
             $lines = mb_convert_encoding($lines, 'UTF-16LE', 'UTF-8');
         }
         echo $lines;
         $lines = '';
     }
 }
    private static function get_notification_ui_settings($notification)
    {
        /**
         * These variables are used to convenient "wrap" child form settings in the appropriate HTML.
         */
        $subsetting_open = '
            <td colspan="2" class="gf_sub_settings_cell">
                <div class="gf_animate_sub_settings">
                    <table>
                        <tr>';
        $subsetting_close = '
                        </tr>
                    </table>
                </div>
            </td>';
        $ui_settings = array();
        $form_id = rgget('id');
        $form = RGFormsModel::get_form_meta($form_id);
        $form = apply_filters('gform_admin_pre_render_' . $form_id, apply_filters('gform_admin_pre_render', $form));
        $is_valid = empty(GFCommon::$errors);
        ob_start();
        ?>

		<tr valign="top" <?php 
        echo rgar($notification, 'isDefault') ? "style='display:none'" : '';
        ?>
 >
			<th scope="row">
				<label for="gform_notification_name">
					<?php 
        esc_html_e('Name', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_name');
        ?>
				</label>
			</th>
			<td>
				<input type="text" class="fieldwidth-2" name="gform_notification_name" id="gform_notification_name" value="<?php 
        echo esc_attr(rgget('name', $notification));
        ?>
" />
			</td>
		</tr> <!-- / name -->
		<?php 
        $ui_settings['notification_name'] = ob_get_contents();
        ob_clean();
        ?>

		<?php 
        $notification_events = array('form_submission' => esc_html__('Form is submitted', 'gravityforms'));
        if (rgars($form, 'save/enabled')) {
            $notification_events['form_saved'] = esc_html__('Form is saved', 'gravityforms');
            $notification_events['form_save_email_requested'] = esc_html__('Save and continue email is requested', 'gravityforms');
        }
        $notification_events = apply_filters('gform_notification_events', $notification_events, $form);
        $event_style = count($notification_events) == 1 || rgar($notification, 'isDefault') ? "style='display:none'" : '';
        ?>
		<tr valign="top" <?php 
        echo $event_style;
        ?>
>
			<th scope="row">
				<label for="gform_notification_event">
					<?php 
        esc_html_e('Event', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_event');
        ?>
				</label>

			</th>
			<td>
				<select name="gform_notification_event" id="gform_notification_event">
					<?php 
        foreach ($notification_events as $code => $label) {
            ?>
						<option value="<?php 
            echo esc_attr($code);
            ?>
" <?php 
            selected(rgar($notification, 'event'), $code);
            ?>
><?php 
            echo esc_html($label);
            ?>
</option>
					<?php 
        }
        ?>
				</select>
			</td>
		</tr> <!-- / event -->
		<?php 
        $ui_settings['notification_event'] = ob_get_contents();
        ob_clean();
        ?>

		<?php 
        $notification_to_type = !rgempty('gform_notification_to_type') ? rgpost('gform_notification_to_type') : rgar($notification, 'toType');
        if (empty($notification_to_type)) {
            $notification_to_type = 'email';
        }
        $is_invalid_email_to = !$is_valid && !self::is_valid_notification_to();
        $send_to_class = $is_invalid_email_to ? 'gfield_error' : '';
        ?>
		<tr valign="top" class='<?php 
        echo esc_attr($send_to_class);
        ?>
' <?php 
        echo $notification_to_type == 'hidden' ? 'style="display:none;"' : '';
        ?>
>
			<th scope="row">
				<label for="gform_notification_to_email">
					<?php 
        esc_html_e('Send To', 'gravityforms');
        ?>
<span class="gfield_required">*</span>
					<?php 
        gform_tooltip('notification_send_to_email');
        ?>
				</label>

			</th>
			<td>
				<input type="radio" id="gform_notification_to_type_email" name="gform_notification_to_type" <?php 
        checked('email', $notification_to_type);
        ?>
 value="email" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_email_container').show('slow');" />
				<label for="gform_notification_to_type_email" class="inline">
					<?php 
        esc_html_e('Enter Email', 'gravityforms');
        ?>
				</label>
				&nbsp;&nbsp;
				<input type="radio" id="gform_notification_to_type_field" name="gform_notification_to_type" <?php 
        checked('field', $notification_to_type);
        ?>
 value="field" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_field_container').show('slow');" />
				<label for="gform_notification_to_type_field" class="inline">
					<?php 
        esc_html_e('Select a Field', 'gravityforms');
        ?>
				</label>
				&nbsp;&nbsp;
				<input type="radio" id="gform_notification_to_type_routing" name="gform_notification_to_type" <?php 
        checked('routing', $notification_to_type);
        ?>
 value="routing" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_routing_container').show('slow');" />
				<label for="gform_notification_to_type_routing" class="inline">
					<?php 
        esc_html_e('Configure Routing', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_send_to_routing');
        ?>
				</label>
			</td>
		</tr> <!-- / to email type -->
		<?php 
        $ui_settings['notification_to_email_type'] = ob_get_contents();
        ob_clean();
        if ($notification_to_type == 'hidden') {
            $ui_settings['notification_to_email_type'] = '<input type="hidden" name="gform_notification_to_type" value="hidden" />';
        }
        ?>

		<tr id="gform_notification_to_email_container" class="notification_to_container <?php 
        echo esc_attr($send_to_class);
        ?>
" <?php 
        echo $notification_to_type != 'email' ? "style='display:none';" : '';
        ?>
>
			<?php 
        echo $subsetting_open;
        ?>
			<th scope="row"><?php 
        esc_html_e('Send to Email', 'gravityforms');
        ?>
</th>
			<td>
				<?php 
        $to_email = rgget('toType', $notification) == 'email' ? rgget('to', $notification) : '';
        ?>
				<input type="text" name="gform_notification_to_email" id="gform_notification_to_email" value="<?php 
        echo esc_attr($to_email);
        ?>
" class="fieldwidth-1" />

				<?php 
        if (rgpost('gform_notification_to_type') == 'email' && $is_invalid_email_to) {
            ?>
					<span class="validation_message"><?php 
            esc_html_e('Please enter a valid email address', 'gravityforms');
            ?>
.</span>
				<?php 
        }
        ?>
			</td>
			<?php 
        echo $subsetting_close;
        ?>
		</tr> <!-- / to email -->
		<?php 
        $ui_settings['notification_to_email'] = ob_get_contents();
        ob_clean();
        ?>

		<?php 
        $email_fields = apply_filters("gform_email_fields_notification_admin_{$form['id']}", apply_filters('gform_email_fields_notification_admin', GFCommon::get_email_fields($form), $form), $form);
        ?>
		<tr id="gform_notification_to_field_container" class="notification_to_container <?php 
        echo esc_attr($send_to_class);
        ?>
" <?php 
        echo $notification_to_type != 'field' ? "style='display:none';" : '';
        ?>
>
			<?php 
        echo $subsetting_open;
        ?>
			<th scope="row"><?php 
        esc_html_e('Send to Field', 'gravityforms');
        ?>
</th>
			<td>
				<?php 
        if (!empty($email_fields)) {
            ?>
					<select name="gform_notification_to_field" id="gform_notification_to_field">
						<option value=""><?php 
            esc_html_e('Select an email field', 'gravityforms');
            ?>
</option>
						<?php 
            $to_field = rgget('toType', $notification) == 'field' ? rgget('to', $notification) : '';
            foreach ($email_fields as $field) {
                ?>
							<option value="<?php 
                echo esc_attr($field->id);
                ?>
" <?php 
                echo selected($field->id, $to_field);
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
						<?php 
            }
            ?>
					</select>
				<?php 
        } else {
            ?>
					<div class="error_base">
						<p><?php 
            esc_html_e('Your form does not have an email field. Add an email field to your form and try again.', 'gravityforms');
            ?>
</p>
					</div>
				<?php 
        }
        ?>
			</td>
			<?php 
        echo $subsetting_close;
        ?>
		</tr> <!-- / to email field -->
		<?php 
        $ui_settings['notification_to_email_field'] = ob_get_contents();
        ob_clean();
        ?>

		<tr id="gform_notification_to_routing_container" class="notification_to_container <?php 
        echo esc_attr($send_to_class);
        ?>
" <?php 
        echo $notification_to_type != 'routing' ? "style='display:none';" : '';
        ?>
>
			<?php 
        echo $subsetting_open;
        ?>
			<td colspan="2">
				<div id="gform_notification_to_routing_rules">
					<?php 
        $routing_fields = self::get_routing_fields($form, '0');
        if (empty($routing_fields)) {
            ?>
						<div class="gold_notice">
							<p><?php 
            esc_html_e('To use notification routing, your form must have a field supported by conditional logic.', 'gravityforms');
            ?>
</p>
						</div>
					<?php 
        } else {
            if (empty($notification['routing'])) {
                $notification['routing'] = array(array());
            }
            $count = sizeof($notification['routing']);
            $routing_list = ',';
            for ($i = 0; $i < $count; $i++) {
                $routing_list .= $i . ',';
                $routing = $notification['routing'][$i];
                $is_invalid_rule = !$is_valid && $_POST['gform_notification_to_type'] == 'routing' && !self::is_valid_notification_email(rgar($routing, 'email'));
                $class = $is_invalid_rule ? "class='grouting_rule_error'" : '';
                ?>
							<div style='width:99%' <?php 
                echo $class;
                ?>
>
								<?php 
                esc_html_e('Send to', 'gravityforms');
                ?>
								<input type="text" id="routing_email_<?php 
                echo $i;
                ?>
" value="<?php 
                echo esc_attr(rgar($routing, 'email'));
                ?>
" onkeyup="SetRouting(<?php 
                echo $i;
                ?>
);" />
								<?php 
                esc_html_e('if', 'gravityforms');
                ?>
								<select id="routing_field_id_<?php 
                echo $i;
                ?>
" class='gfield_routing_select' onchange='jQuery("#routing_value_<?php 
                echo $i;
                ?>
").replaceWith(GetRoutingValues(<?php 
                echo $i;
                ?>
, jQuery(this).val())); SetRouting(<?php 
                echo $i;
                ?>
); '><?php 
                echo self::get_routing_fields($form, rgar($routing, 'fieldId'));
                ?>
</select>
								<select id="routing_operator_<?php 
                echo $i;
                ?>
" onchange="SetRouting(<?php 
                echo $i;
                ?>
)" class="gform_routing_operator">
									<option value="is" <?php 
                echo rgar($routing, 'operator') == 'is' ? "selected='selected'" : '';
                ?>
><?php 
                esc_html_e('is', 'gravityforms');
                ?>
</option>
									<option value="isnot" <?php 
                echo rgar($routing, 'operator') == 'isnot' ? "selected='selected'" : '';
                ?>
><?php 
                esc_html_e('is not', 'gravityforms');
                ?>
</option>
									<option value=">" <?php 
                echo rgar($routing, 'operator') == '>' ? "selected='selected'" : '';
                ?>
><?php 
                esc_html_e('greater than', 'gravityforms');
                ?>
</option>
									<option value="<" <?php 
                echo rgar($routing, 'operator') == '<' ? "selected='selected'" : '';
                ?>
><?php 
                esc_html_e('less than', 'gravityforms');
                ?>
</option>
									<option value="contains" <?php 
                echo rgar($routing, 'operator') == 'contains' ? "selected='selected'" : '';
                ?>
><?php 
                esc_html_e('contains', 'gravityforms');
                ?>
</option>
									<option value="starts_with" <?php 
                echo rgar($routing, 'operator') == 'starts_with' ? "selected='selected'" : '';
                ?>
><?php 
                esc_html_e('starts with', 'gravityforms');
                ?>
</option>
									<option value="ends_with" <?php 
                echo rgar($routing, 'operator') == 'ends_with' ? "selected='selected'" : '';
                ?>
><?php 
                esc_html_e('ends with', 'gravityforms');
                ?>
</option>
								</select>
								<?php 
                echo self::get_field_values($i, $form, rgar($routing, 'fieldId'), rgar($routing, 'value'));
                ?>

								<a class='gf_insert_field_choice' title='add another rule' onclick='SetRouting(<?php 
                echo $i;
                ?>
); InsertRouting(<?php 
                echo $i + 1;
                ?>
);'><i class='gficon-add'></i></a>

								<?php 
                if ($count > 1) {
                    ?>
									<img src='<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/remove.png' id='routing_delete_<?php 
                    echo $i;
                    ?>
' title='remove this email routing' alt='remove this email routing' class='delete_field_choice' style='cursor:pointer;' onclick='DeleteRouting(<?php 
                    echo $i;
                    ?>
);' />
								<?php 
                }
                ?>
							</div>
						<?php 
            }
            if ($is_invalid_rule) {
                ?>
							<span class="validation_message"><?php 
                esc_html_e('Please enter a valid email address for all highlighted routing rules above.', 'gravityforms');
                ?>
</span>
						<?php 
            }
            ?>
						<input type="hidden" name="routing_count" id="routing_count" value="<?php 
            echo $routing_list;
            ?>
" />
					<?php 
        }
        ?>
				</div>
			</td>
			<?php 
        echo $subsetting_close;
        ?>
		</tr> <!-- / to routing -->
		<?php 
        $ui_settings['notification_to_routing'] = ob_get_contents();
        ob_clean();
        ?>

		<tr valign="top">
			<th scope="row">
				<label for="gform_notification_from_name">
					<?php 
        esc_html_e('From Name', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_from_name');
        ?>
				</label>
			</th>
			<td>
				<input type="text" class="fieldwidth-2 merge-tag-support mt-position-right mt-hide_all_fields" name="gform_notification_from_name" id="gform_notification_from_name" value="<?php 
        echo esc_attr(rgget('fromName', $notification));
        ?>
" />
			</td>
		</tr> <!-- / from name -->
		<?php 
        $ui_settings['notification_from_name'] = ob_get_contents();
        ob_clean();
        ?>

		<tr valign="top">
			<th scope="row">
				<label for="gform_notification_from">
					<?php 
        esc_html_e('From Email', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_from_email');
        ?>
				</label>
			</th>
			<td>
				<input type="text" class="fieldwidth-2 merge-tag-support mt-position-right mt-hide_all_fields" name="gform_notification_from" id="gform_notification_from" value="<?php 
        echo rgempty('from', $notification) ? '{admin_email}' : esc_attr(rgget('from', $notification));
        ?>
" />
			</td>
		</tr> <!-- / to from email -->
		<?php 
        $ui_settings['notification_from'] = ob_get_contents();
        ob_clean();
        ?>

		<tr valign="top">
			<th scope="row">
				<label for="gform_notification_reply_to">
					<?php 
        $is_invalid_reply_to = !$is_valid && !self::is_valid_notification_email(rgar($notification, 'replyTo'));
        $class = $is_invalid_reply_to ? ' gfield_error' : '';
        ?>
					<?php 
        esc_html_e('Reply To', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_reply_to');
        ?>
				</label>
			</th>
			<td>
				<input type="text" name="gform_notification_reply_to" id="gform_notification_reply_to" class="merge-tag-support mt-hide_all_fields fieldwidth-2<?php 
        echo $class;
        ?>
" value="<?php 
        echo esc_attr(rgget('replyTo', $notification));
        ?>
" />
			</td>
		</tr> <!-- / reply to -->
		<?php 
        $ui_settings['notification_reply_to'] = ob_get_contents();
        ob_clean();
        ?>

		<tr valign="top">
			<th scope="row">
				<label for="gform_notification_bcc">
					<?php 
        esc_html_e('BCC', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_bcc');
        ?>
				</label>
			</th>
			<td>
				<?php 
        $is_invalid_bcc = !$is_valid && !self::is_valid_notification_email(rgar($notification, 'bcc'));
        $class = $is_invalid_bcc ? ' gfield_error' : '';
        ?>
				<input type="text" name="gform_notification_bcc" id="gform_notification_bcc" value="<?php 
        echo esc_attr(rgget('bcc', $notification));
        ?>
" class="merge-tag-support mt-hide_all_fields fieldwidth-2<?php 
        echo $class;
        ?>
" />
			</td>
		</tr> <!-- / bcc -->
		<?php 
        $ui_settings['notification_bcc'] = ob_get_contents();
        ob_clean();
        ?>

		<?php 
        $is_invalid_subject = !$is_valid && empty($_POST['gform_notification_subject']);
        $subject_class = $is_invalid_subject ? "class='gfield_error'" : '';
        ?>
		<tr valign="top" <?php 
        echo $subject_class;
        ?>
>
			<th scope="row">
				<label for="gform_notification_subject">
					<?php 
        esc_html_e('Subject', 'gravityforms');
        ?>
<span class="gfield_required">*</span>
				</label>
			</th>
			<td>
				<input type="text" name="gform_notification_subject" id="gform_notification_subject" class="fieldwidth-1 merge-tag-support mt-hide_all_fields mt-position-right" value="<?php 
        echo esc_attr(rgar($notification, 'subject'));
        ?>
" />
				<?php 
        if ($is_invalid_subject) {
            ?>
					<span class="validation_message"><?php 
            esc_html_e('Please enter a subject for the notification email', 'gravityforms');
            ?>
</span><?php 
        }
        ?>
			</td>
		</tr> <!-- / subject -->
		<?php 
        $ui_settings['notification_subject'] = ob_get_contents();
        ob_clean();
        ?>

		<?php 
        $is_invalid_message = !$is_valid && empty($_POST['gform_notification_message']);
        $message_class = $is_invalid_message ? "class='gfield_error'" : '';
        ?>
		<tr valign="top" <?php 
        echo $message_class;
        ?>
>
			<th scope="row">
				<label for="gform_notification_message">
					<?php 
        esc_html_e('Message', 'gravityforms');
        ?>
<span class="gfield_required">*</span>
				</label>
			</th>
			<td>

				<span class="mt-gform_notification_message"></span>

				<?php 
        if (GFCommon::is_wp_version('3.3')) {
            wp_editor(rgar($notification, 'message'), 'gform_notification_message', array('autop' => false, 'editor_class' => 'merge-tag-support mt-wp_editor mt-manual_position mt-position-right'));
        } else {
            ?>
					<textarea name="gform_notification_message" id="gform_notification_message" class="fieldwidth-1 fieldheight-1"><?php 
            echo esc_html($notification['message']);
            ?>
</textarea><?php 
        }
        if ($is_invalid_message) {
            ?>
					<span class="validation_message"><?php 
            esc_html_e('Please enter a message for the notification email', 'gravityforms');
            ?>
</span><?php 
        }
        ?>
			</td>
		</tr> <!-- / message -->
		<?php 
        $ui_settings['notification_message'] = ob_get_contents();
        ob_clean();
        ?>

		<tr valign="top">
			<th scope="row">
				<label for="gform_notification_disable_autoformat">
					<?php 
        esc_html_e('Auto-formatting', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_autoformat');
        ?>
				</label>
			</th>
			<td>
				<input type="checkbox" name="gform_notification_disable_autoformat" id="gform_notification_disable_autoformat" value="1" <?php 
        echo empty($notification['disableAutoformat']) ? '' : "checked='checked'";
        ?>
/>
				<label for="form_notification_disable_autoformat" class="inline">
					<?php 
        esc_html_e('Disable auto-formatting', 'gravityforms');
        ?>
					<?php 
        gform_tooltip('notification_autoformat');
        ?>
				</label>
			</td>
		</tr> <!-- / disable autoformat -->
		<?php 
        $ui_settings['notification_disable_autoformat'] = ob_get_contents();
        ob_clean();
        ?>

		<tr valign="top" <?php 
        echo rgar($notification, 'isDefault') ? 'style=display:none;' : '';
        ?>
 >
			<th scope="row">
				<label for="gform_notification_conditional_logic">
					<?php 
        esc_html_e('Conditional Logic', 'gravityforms');
        gform_tooltip('notification_conditional_logic');
        ?>
				</label>
			</th>
			<td>
				<input type="checkbox" id="notification_conditional_logic" onclick="SetConditionalLogic(this.checked); ToggleConditionalLogic(false, 'notification');" <?php 
        checked(is_array(rgar($notification, 'conditionalLogic')), true);
        ?>
 />
				<label for="notification_conditional_logic" class="inline"><?php 
        esc_html_e('Enable conditional logic', 'gravityforms');
        gform_tooltip('notification_conditional_logic');
        ?>
</label>
				<br />
			</td>
		</tr> <!-- / conditional logic -->
		<tr>
			<td colspan="2">
				<div id="notification_conditional_logic_container" class="gf_animate_sub_settings" style="padding-left:10px;">
					<!-- content dynamically created from form_admin.js -->
				</div>
			</td>
		</tr>

		<?php 
        $ui_settings['notification_conditional_logic'] = ob_get_contents();
        ob_clean();
        ?>

		<?php 
        ob_end_clean();
        $ui_settings = apply_filters("gform_notification_ui_settings_{$form_id}", apply_filters('gform_notification_ui_settings', $ui_settings, $notification, $form), $notification, $form);
        return $ui_settings;
    }
Beispiel #19
0
    private static function get_notification_ui_settings($notification)
    {
        /**
         * These variables are used to convenient "wrap" child form settings in the appropriate HTML.
         */
        $subsetting_open = '
            <td colspan="2" class="gf_sub_settings_cell">
                <div class="gf_animate_sub_settings">
                    <table>
                        <tr>';
        $subsetting_close = '
                        </tr>
                    </table>
                </div>
            </td>';
        $ui_settings = array();
        $form_id = rgget('id');
        $form = RGFormsModel::get_form_meta($form_id);
        $form = apply_filters("gform_admin_pre_render_" . $form_id, apply_filters("gform_admin_pre_render", $form));
        $is_valid = empty(GFCommon::$errors);
        ob_start();
        ?>

        <tr valign="top">
            <th scope="row">
                <label for="gform_notification_name">
                    <?php 
        _e("Name", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_name");
        ?>
                </label>
            </th>
            <td>
                <input type="text" class="fieldwidth-2" name="gform_notification_name" id="gform_notification_name" value="<?php 
        echo esc_attr(rgget("name", $notification));
        ?>
"/>
            </td>
        </tr> <!-- / name -->
        <?php 
        $ui_settings['notification_name'] = ob_get_contents();
        ob_clean();
        ?>

        <?php 
        $notification_events = apply_filters("gform_notification_events", array("form_submission" => __("Form is submitted", "gravityforms")));
        $event_style = count($notification_events) == 1 ? "style='display:none'" : "";
        ?>
        <tr valign="top" <?php 
        echo $event_style;
        ?>
>
            <th scope="row">
                <label for="gform_notification_event">
                    <?php 
        _e("Event", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_event");
        ?>
                </label>

            </th>
            <td>
                <select name="gform_notification_event" id="gform_notification_event">
                <?php 
        foreach ($notification_events as $code => $label) {
            ?>
                    <option value="<?php 
            echo esc_attr($code);
            ?>
" <?php 
            selected(rgar($notification, 'event'), $code);
            ?>
><?php 
            echo esc_html($label);
            ?>
</option>
                    <?php 
        }
        ?>
                </select>
            </td>
        </tr> <!-- / event -->
        <?php 
        $ui_settings['notification_event'] = ob_get_contents();
        ob_clean();
        ?>

        <?php 
        $notification_to_type = !rgempty("gform_notification_to_type") ? rgpost("gform_notification_to_type") : rgar($notification, "toType");
        if (empty($notification_to_type)) {
            $notification_to_type = "email";
        }
        $is_invalid_email_to = !$is_valid && !self::is_valid_notification_to();
        $send_to_class = $is_invalid_email_to ? "gfield_error" : "";
        ?>
        <tr valign="top" class='<?php 
        echo $send_to_class;
        ?>
'>
            <th scope="row">
                <label for="gform_notification_to_email">
                    <?php 
        _e("Send To", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                    <?php 
        gform_tooltip("notification_send_to_email");
        ?>
                </label>

            </th>
            <td>
                <input type="radio" id="gform_notification_to_type_email" name="gform_notification_to_type" <?php 
        checked("email", $notification_to_type);
        ?>
 value="email" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_email_container').show('slow');"/>
                <label for="gform_notification_to_type_email" class="inline">
                    <?php 
        _e("Enter Email", "gravityforms");
        ?>
                </label>
                &nbsp;&nbsp;
                <input type="radio" id="gform_notification_to_type_field" name="gform_notification_to_type" <?php 
        checked("field", $notification_to_type);
        ?>
 value="field" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_field_container').show('slow');"/>
                <label for="gform_notification_to_type_field" class="inline">
                    <?php 
        _e("Select a Field", "gravityforms");
        ?>
                </label>
                &nbsp;&nbsp;
                <input type="radio" id="gform_notification_to_type_routing" name="gform_notification_to_type" <?php 
        checked("routing", $notification_to_type);
        ?>
 value="routing" onclick="jQuery('.notification_to_container').hide(); jQuery('#gform_notification_to_routing_container').show('slow');"/>
                <label for="gform_notification_to_type_routing" class="inline">
                    <?php 
        _e("Configure Routing", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_send_to_routing");
        ?>
                </label>
            </td>
        </tr> <!-- / to email type -->
        <?php 
        $ui_settings['notification_to_email_type'] = ob_get_contents();
        ob_clean();
        ?>

        <tr id="gform_notification_to_email_container" class="notification_to_container <?php 
        echo $send_to_class;
        ?>
" <?php 
        echo $notification_to_type != "email" ? "style='display:none';" : "";
        ?>
>
            <?php 
        echo $subsetting_open;
        ?>
            <th scope="row"><?php 
        _e("Send to Email", "gravityforms");
        ?>
</th>
            <td>
                <?php 
        $to_email = rgget("toType", $notification) == "email" ? rgget("to", $notification) : "";
        ?>
                <input type="text" name="gform_notification_to_email" id="gform_notification_to_email" value="<?php 
        echo esc_attr($to_email);
        ?>
" class="fieldwidth-1" />

                <?php 
        if (rgpost("gform_notification_to_type") == "email" && $is_invalid_email_to) {
            ?>
                    <span class="validation_message"><?php 
            _e("Please enter a valid email address", "gravityforms");
            ?>
</span>
                <?php 
        }
        ?>
            </td>
            <?php 
        echo $subsetting_close;
        ?>
        </tr> <!-- / to email -->
        <?php 
        $ui_settings['notification_to_email'] = ob_get_contents();
        ob_clean();
        ?>

        <?php 
        $email_fields = apply_filters("gform_email_fields_notification_admin_{$form["id"]}", apply_filters("gform_email_fields_notification_admin", GFCommon::get_email_fields($form), $form), $form);
        ?>
        <tr id="gform_notification_to_field_container" class="notification_to_container <?php 
        echo $send_to_class;
        ?>
" <?php 
        echo $notification_to_type != "field" ? "style='display:none';" : "";
        ?>
>
            <?php 
        echo $subsetting_open;
        ?>
            <th scope="row"><?php 
        _e("Send to Field", "gravityforms");
        ?>
</th>
            <td>
                <?php 
        if (!empty($email_fields)) {
            ?>
                    <select name="gform_notification_to_field" id="gform_notification_to_field">
                        <option value=""><?php 
            _e("Select an email field", "gravityforms");
            ?>
</option>
                        <?php 
            $to_field = rgget("toType", $notification) == "field" ? rgget("to", $notification) : "";
            foreach ($email_fields as $field) {
                ?>
                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo selected($field["id"], $to_field);
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
                            <?php 
            }
            ?>
                    </select>
                <?php 
        } else {
            ?>
                    <div class="error_base"><p><?php 
            _e("Your form does not have an email field. Add an email field to your form and try again.", "gravityforms");
            ?>
</p></div>
                <?php 
        }
        ?>
            </td>
            <?php 
        echo $subsetting_close;
        ?>
        </tr> <!-- / to email field -->
        <?php 
        $ui_settings['notification_to_email_field'] = ob_get_contents();
        ob_clean();
        ?>

        <tr id="gform_notification_to_routing_container" class="notification_to_container <?php 
        echo $send_to_class;
        ?>
" <?php 
        echo $notification_to_type != "routing" ? "style='display:none';" : "";
        ?>
>
            <?php 
        echo $subsetting_open;
        ?>
            <td colspan="2">
                <div id="gform_notification_to_routing_rules">
                    <?php 
        $routing_fields = self::get_routing_fields($form, "0");
        if (empty($routing_fields)) {
            //if(empty(){
            ?>
                        <div class="gold_notice">
                            <p><?php 
            _e("To use notification routing, your form must have a field supported by conditional logic.", "gravityforms");
            ?>
</p>
                        </div>
                        <?php 
        } else {
            if (empty($notification["routing"])) {
                $notification["routing"] = array(array());
            }
            $count = sizeof($notification["routing"]);
            $routing_list = ",";
            for ($i = 0; $i < $count; $i++) {
                $routing_list .= $i . ",";
                $routing = $notification["routing"][$i];
                $is_invalid_rule = !$is_valid && $_POST["gform_notification_to_type"] == "routing" && !self::is_valid_notification_email(rgar($routing, 'email'));
                $class = $is_invalid_rule ? "class='grouting_rule_error'" : "";
                ?>
                            <div style='width:99%' <?php 
                echo $class;
                ?>
>
                                <?php 
                _e("Send to", "gravityforms");
                ?>
 <input type="text" id="routing_email_<?php 
                echo $i;
                ?>
" value="<?php 
                echo rgar($routing, "email");
                ?>
" onkeyup="SetRouting(<?php 
                echo $i;
                ?>
);"/>
                                <?php 
                _e("if", "gravityforms");
                ?>
 <select id="routing_field_id_<?php 
                echo $i;
                ?>
" class='gfield_routing_select' onchange='jQuery("#routing_value_<?php 
                echo $i;
                ?>
").replaceWith(GetRoutingValues(<?php 
                echo $i;
                ?>
, jQuery(this).val())); SetRouting(<?php 
                echo $i;
                ?>
); '><?php 
                echo self::get_routing_fields($form, rgar($routing, "fieldId"));
                ?>
</select>
                                <select id="routing_operator_<?php 
                echo $i;
                ?>
" onchange="SetRouting(<?php 
                echo $i;
                ?>
)" class="gform_routing_operator">
                                    <option value="is" <?php 
                echo rgar($routing, "operator") == "is" ? "selected='selected'" : "";
                ?>
><?php 
                _e("is", "gravityforms");
                ?>
</option>
                                    <option value="isnot" <?php 
                echo rgar($routing, "operator") == "isnot" ? "selected='selected'" : "";
                ?>
><?php 
                _e("is not", "gravityforms");
                ?>
</option>
                                    <option value=">" <?php 
                echo rgar($routing, "operator") == ">" ? "selected='selected'" : "";
                ?>
><?php 
                _e("greater than", "gravityforms");
                ?>
</option>
                                    <option value="<" <?php 
                echo rgar($routing, "operator") == "<" ? "selected='selected'" : "";
                ?>
><?php 
                _e("less than", "gravityforms");
                ?>
</option>
                                    <option value="contains" <?php 
                echo rgar($routing, "operator") == "contains" ? "selected='selected'" : "";
                ?>
><?php 
                _e("contains", "gravityforms");
                ?>
</option>
                                    <option value="starts_with" <?php 
                echo rgar($routing, "operator") == "starts_with" ? "selected='selected'" : "";
                ?>
><?php 
                _e("starts with", "gravityforms");
                ?>
</option>
                                    <option value="ends_with" <?php 
                echo rgar($routing, "operator") == "ends_with" ? "selected='selected'" : "";
                ?>
><?php 
                _e("ends with", "gravityforms");
                ?>
</option>
                                </select>
                                <?php 
                echo self::get_field_values($i, $form, rgar($routing, "fieldId"), rgar($routing, "value"));
                ?>

                                <a class='gf_insert_field_choice' title='add another rule' onclick='SetRouting(<?php 
                echo $i;
                ?>
); InsertRouting(<?php 
                echo $i + 1;
                ?>
);'><i class='fa fa-plus-square'></i></a>

                                <?php 
                if ($count > 1) {
                    ?>
                                    <img src='<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/remove.png' id='routing_delete_<?php 
                    echo $i;
                    ?>
' title='remove this email routing' alt='remove this email routing' class='delete_field_choice' style='cursor:pointer;' onclick='DeleteRouting(<?php 
                    echo $i;
                    ?>
);' />
                                <?php 
                }
                ?>
                            </div>
                        <?php 
            }
            if ($is_invalid_rule) {
                ?>
                            <span class="validation_message"><?php 
                _e("Please enter a valid email address for all highlighted routing rules above.", "gravityforms");
                ?>
</span>
                        <?php 
            }
            ?>
                        <input type="hidden" name="routing_count" id="routing_count" value="<?php 
            echo $routing_list;
            ?>
"/>
                    <?php 
        }
        ?>
                </div>
            </td>
            <?php 
        echo $subsetting_close;
        ?>
        </tr> <!-- / to routing -->
        <?php 
        $ui_settings['notification_to_routing'] = ob_get_contents();
        ob_clean();
        ?>

        <tr valign="top">
            <th scope="row">
                <label for="gform_notification_from_name">
                    <?php 
        _e("From Name", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_from_name");
        ?>
                </label>
            </th>
            <td>
                <input type="text" class="fieldwidth-2 merge-tag-support mt-position-right mt-hide_all_fields" name="gform_notification_from_name" id="gform_notification_from_name" value="<?php 
        echo esc_attr(rgget("fromName", $notification));
        ?>
"/>
            </td>
        </tr> <!-- / from name -->
        <?php 
        $ui_settings['notification_from_name'] = ob_get_contents();
        ob_clean();
        ?>

        <tr valign="top">
            <th scope="row">
                <label for="gform_notification_from">
                    <?php 
        _e("From Email", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_from_email");
        ?>
                </label>
            </th>
            <td>
                <input type="text" class="fieldwidth-2 merge-tag-support mt-position-right mt-hide_all_fields" name="gform_notification_from" id="gform_notification_from" value="<?php 
        echo rgempty("from", $notification) ? "{admin_email}" : esc_attr(rgget("from", $notification));
        ?>
"/>
            </td>
        </tr> <!-- / to from email -->
        <?php 
        $ui_settings['notification_from'] = ob_get_contents();
        ob_clean();
        ?>

        <tr valign="top">
            <th scope="row">
                <label for="gform_notification_reply_to">
                    <?php 
        _e("Reply To", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_reply_to");
        ?>
                </label>
            </th>
            <td>
                <input type="text" name="gform_notification_reply_to" id="gform_notification_reply_to" class="merge-tag-support mt-hide_all_fields" value="<?php 
        echo esc_attr(rgget("replyTo", $notification));
        ?>
" class="fieldwidth-2" />
            </td>
        </tr> <!-- / reply to -->
        <?php 
        $ui_settings['notification_reply_to'] = ob_get_contents();
        ob_clean();
        ?>

        <tr valign="top">
            <th scope="row">
                <label for="gform_notification_bcc">
                    <?php 
        _e("BCC", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_bcc");
        ?>
                </label>
            </th>
            <td>
                <input type="text" name="gform_notification_bcc" id="gform_notification_bcc" value="<?php 
        echo esc_attr(rgget("bcc", $notification));
        ?>
" class="fieldwidth-1" />
            </td>
        </tr> <!-- / bcc -->
        <?php 
        $ui_settings['notification_bcc'] = ob_get_contents();
        ob_clean();
        ?>

        <?php 
        $is_invalid_subject = !$is_valid && empty($_POST["gform_notification_subject"]);
        $subject_class = $is_invalid_subject ? "class='gfield_error'" : "";
        ?>
        <tr valign="top" <?php 
        echo $subject_class;
        ?>
>
            <th scope="row">
                <label for="gform_notification_subject">
                    <?php 
        _e("Subject", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                </label>
            </th>
            <td>
                <input type="text" name="gform_notification_subject" id="gform_notification_subject" class="fieldwidth-1 merge-tag-support mt-hide_all_fields mt-position-right" value="<?php 
        echo esc_attr(rgar($notification, "subject"));
        ?>
" />
                <?php 
        if ($is_invalid_subject) {
            ?>
                    <span class="validation_message"><?php 
            _e("Please enter a subject for the notification email", "gravityforms");
            ?>
</span><?php 
        }
        ?>
            </td>
        </tr> <!-- / subject -->
        <?php 
        $ui_settings['notification_subject'] = ob_get_contents();
        ob_clean();
        ?>

        <?php 
        $is_invalid_message = !$is_valid && empty($_POST["gform_notification_message"]);
        $message_class = $is_invalid_message ? "class='gfield_error'" : "";
        ?>
        <tr valign="top" <?php 
        echo $message_class;
        ?>
>
            <th scope="row">
                <label for="gform_notification_message">
                    <?php 
        _e("Message", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                </label>
            </th>
            <td>

                <span class="mt-gform_notification_message"></span>

                <?php 
        if (GFCommon::is_wp_version("3.3")) {
            wp_editor(rgar($notification, "message"), "gform_notification_message", array("autop" => false, "editor_class" => "merge-tag-support mt-wp_editor mt-manual_position mt-position-right"));
        } else {
            ?>
                    <textarea name="gform_notification_message" id="gform_notification_message" class="fieldwidth-1 fieldheight-1" ><?php 
            echo esc_html($notification["message"]);
            ?>
</textarea><?php 
        }
        if ($is_invalid_message) {
            ?>
                    <span class="validation_message"><?php 
            _e("Please enter a message for the notification email", "gravityforms");
            ?>
</span><?php 
        }
        ?>
            </td>
        </tr> <!-- / message -->
        <?php 
        $ui_settings['notification_message'] = ob_get_contents();
        ob_clean();
        ?>

        <tr valign="top">
            <th scope="row">
                <label for="gform_notification_disable_autoformat">
                    <?php 
        _e("Auto-formatting", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_autoformat");
        ?>
                </label>
            </th>
            <td>
                <input type="checkbox" name="gform_notification_disable_autoformat" id="gform_notification_disable_autoformat" value="1" <?php 
        echo empty($notification["disableAutoformat"]) ? "" : "checked='checked'";
        ?>
/>
                <label for="form_notification_disable_autoformat" class="inline">
                    <?php 
        _e("Disable auto-formatting", "gravityforms");
        ?>
                    <?php 
        gform_tooltip("notification_autoformat");
        ?>
                </label>
            </td>
        </tr> <!-- / disable autoformat -->
        <?php 
        $ui_settings['notification_disable_autoformat'] = ob_get_contents();
        ob_clean();
        ?>

        <tr valign="top">
            <th scope="row">
                <label for="gform_notification_conditional_logic">
                    <?php 
        _e("Conditional Logic", "gravityforms");
        gform_tooltip("notification_conditional_logic");
        ?>
                </label>
            </th>
            <td>
                <input type="checkbox" id="notification_conditional_logic" onclick="SetConditionalLogic(this.checked); ToggleConditionalLogic(false, 'notification');" <?php 
        checked(is_array(rgar($notification, "conditionalLogic")), true);
        ?>
 />
                <label for="notification_conditional_logic" class="inline"><?php 
        _e("Enable conditional logic", "gravityforms");
        gform_tooltip("notification_conditional_logic");
        ?>
</label>
                <br/>
            </td>
        </tr> <!-- / conditional logic -->
        <tr>
            <td colspan="2">
                <div id="notification_conditional_logic_container" class="gf_animate_sub_settings" style="padding-left:10px;">
                    <!-- content dynamically created from form_admin.js -->
                </div>
            </td>
        </tr>

        <?php 
        $ui_settings['notification_conditional_logic'] = ob_get_contents();
        ob_clean();
        ?>

        <?php 
        ob_end_clean();
        $ui_settings = apply_filters("gform_notification_ui_settings_{$form_id}", apply_filters('gform_notification_ui_settings', $ui_settings, $notification, $form), $notification, $form);
        return $ui_settings;
    }
 public static function select_export_form()
 {
     check_ajax_referer("rg_select_export_form", "rg_select_export_form");
     $form_id = intval($_POST["form_id"]);
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     //Adding default fields
     array_push($form["fields"], array("id" => "id", "label" => __("Entry Id", "gravityforms")));
     array_push($form["fields"], array("id" => "date_created", "label" => __("Entry Date", "gravityforms")));
     array_push($form["fields"], array("id" => "ip", "label" => __("User IP", "gravityforms")));
     array_push($form["fields"], array("id" => "source_url", "label" => __("Source Url", "gravityforms")));
     array_push($form["fields"], array("id" => "payment_status", "label" => __("Payment Status", "gravityforms")));
     array_push($form["fields"], array("id" => "payment_date", "label" => __("Payment Date", "gravityforms")));
     array_push($form["fields"], array("id" => "transaction_id", "label" => __("Transaction Id", "gravityforms")));
     if (is_array($form["fields"])) {
         foreach ($form["fields"] as $field) {
             if (is_array(rgar($field, "inputs"))) {
                 foreach ($field["inputs"] as $input) {
                     $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
                 }
             } else {
                 if (!rgar($field, "displayOnly")) {
                     $fields[] = array($field["id"], GFCommon::get_label($field));
                 }
             }
         }
     }
     $field_json = GFCommon::json_encode($fields);
     die("EndSelectExportForm({$field_json});");
 }
 public function get_form_fields_as_choices($form, $args = array())
 {
     $fields = array();
     if (!is_array($form['fields'])) {
         return $fields;
     }
     $args = wp_parse_args($args, array('field_types' => array(), 'input_types' => array()));
     foreach ($form['fields'] as $field) {
         $input_type = GFFormsModel::get_input_type($field);
         if (!empty($args['input_types']) && !in_array($input_type, $args['input_types'])) {
             continue;
         }
         if (is_array(rgar($field, 'inputs'))) {
             // if this is an address field, add full name to the list
             if ($input_type == 'address') {
                 $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field) . ' (' . __('Full', 'gravityforms') . ')');
             }
             // if this is a name field, add full name to the list
             if ($input_type == 'name') {
                 $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . ' (' . __('Full', 'gravityforms') . ')');
             }
             // if this is a checkbox field, add to the list
             if ($input_type == 'checkbox') {
                 $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field) . ' (' . __('Selected', 'gravityforms') . ')');
             }
             foreach ($field['inputs'] as $input) {
                 $fields[] = array('value' => $input['id'], 'label' => GFCommon::get_label($field, $input['id']));
             }
         } else {
             if (!rgar($field, 'displayOnly')) {
                 $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field));
             }
         }
     }
     return $fields;
 }
 public function get_column_value_amount($feed)
 {
     $form = $this->get_current_form();
     $field_id = $feed['meta']['transactionType'] == 'subscription' ? rgars($feed, 'meta/recurringAmount') : rgars($feed, 'meta/paymentAmount');
     if ($field_id == 'form_total') {
         $label = esc_html__('Form Total', 'gravityforms');
     } else {
         $field = GFFormsModel::get_field($form, $field_id);
         $label = GFCommon::get_label($field);
     }
     return $label;
 }
Beispiel #23
0
 /**
  * Retrieve the field label.
  *
  * @param bool $force_frontend_label Should the frontend label be displayed in the admin even if an admin label is configured.
  * @param string $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission.
  *
  * @return string
  */
 public function get_field_label($force_frontend_label, $value)
 {
     $field_label = $force_frontend_label ? $this->label : GFCommon::get_label($this);
     if (($this->inputType == 'singleproduct' || $this->inputType == 'calculation') && !rgempty($this->id . '.1', $value)) {
         $field_label = rgar($value, $this->id . '.1');
     }
     return $field_label;
 }
 /**
  * Retrieve an array of form fields formatted for select, radio and checkbox settings fields.
  * 
  * @access public
  * @param array $form - The form object
  * @param array $args - Additional settings to check for (field and input types to include, callback for applicable input type)
  *
  * @return array The array of formatted form fields
  */
 public function get_form_fields_as_choices($form, $args = array())
 {
     $fields = array();
     if (!is_array($form['fields'])) {
         return $fields;
     }
     $args = wp_parse_args($args, array('field_types' => array(), 'input_types' => array(), 'callback' => false));
     foreach ($form['fields'] as $field) {
         $input_type = GFFormsModel::get_input_type($field);
         $is_applicable_input_type = empty($args['input_types']) || in_array($input_type, $args['input_types']);
         if (is_callable($args['callback'])) {
             $is_applicable_input_type = call_user_func($args['callback'], $is_applicable_input_type, $field, $form);
         }
         if (!$is_applicable_input_type) {
             continue;
         }
         if (!empty($args['property']) && (!isset($field->{$args}['property']) || $field->{$args}['property'] != $args['property_value'])) {
             continue;
         }
         $inputs = $field->get_entry_inputs();
         if (is_array($inputs)) {
             // if this is an address field, add full name to the list
             if ($input_type == 'address') {
                 $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Full', 'gravityforms') . ')');
             }
             // if this is a name field, add full name to the list
             if ($input_type == 'name') {
                 $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Full', 'gravityforms') . ')');
             }
             // if this is a checkbox field, add to the list
             if ($input_type == 'checkbox') {
                 $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Selected', 'gravityforms') . ')');
             }
             foreach ($inputs as $input) {
                 $fields[] = array('value' => $input['id'], 'label' => GFCommon::get_label($field, $input['id']));
             }
         } elseif ($input_type == 'list' && $field->enableColumns) {
             $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Full', 'gravityforms') . ')');
             $col_index = 0;
             foreach ($field->choices as $column) {
                 $fields[] = array('value' => $field->id . '.' . $col_index, 'label' => GFCommon::get_label($field) . ' (' . rgar($column, 'text') . ')');
                 $col_index++;
             }
         } elseif (!$field->displayOnly) {
             $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field));
         } else {
             $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field));
         }
     }
     return $fields;
 }
 public static function get_field_content($field, $value = "", $force_frontend_label = false, $form_id = 0)
 {
     $id = $field["id"];
     $size = rgar($field, "size");
     $validation_message = rgget("failed_validation", $field) && !empty($field["validation_message"]) ? sprintf("<div class='gfield_description validation_message'>%s</div>", $field["validation_message"]) : "";
     $duplicate_disabled = array('captcha', 'post_title', 'post_content', 'post_excerpt', 'total', 'shipping', 'creditcard');
     $duplicate_field_link = !in_array($field['type'], $duplicate_disabled) ? "<a class='field_duplicate_icon' id='gfield_duplicate_{$id}' title='" . __("click to duplicate this field", "gravityforms") . "' href='#' onclick='StartDuplicateField(this); return false;'>" . __("Duplicate", "gravityforms") . "</a>" : "";
     $duplicate_field_link = apply_filters("gform_duplicate_field_link", $duplicate_field_link);
     $delete_field_link = "<a class='field_delete_icon' id='gfield_delete_{$id}' title='" . __("click to delete this field", "gravityforms") . "' href='#' onclick='StartDeleteField(this); return false;'>" . __("Delete", "gravityforms") . "</a>";
     $delete_field_link = apply_filters("gform_delete_field_link", $delete_field_link);
     $field_type_title = GFCommon::get_field_type_title($field["type"]);
     $admin_buttons = IS_ADMIN ? "<div class='gfield_admin_icons'><div class='gfield_admin_header_title'>{$field_type_title} : " . __("Field ID", "gravityforms") . " {$field["id"]}</div>" . $delete_field_link . $duplicate_field_link . "<a class='field_edit_icon edit_icon_collapsed' title='" . __("click to edit this field", "gravityforms") . "'>" . __("Edit", "gravityforms") . "</a></div>" : "";
     $field_label = $force_frontend_label ? $field["label"] : GFCommon::get_label($field);
     if (rgar($field, "inputType") == "singleproduct" && !rgempty($field["id"] . ".1", $value)) {
         $field_label = rgar($value, $field["id"] . ".1");
     }
     $field_id = IS_ADMIN || $form_id == 0 ? "input_{$id}" : "input_" . $form_id . "_{$id}";
     $required_div = IS_ADMIN || rgar($field, "isRequired") ? sprintf("<span class='gfield_required'>%s</span>", $field["isRequired"] ? "*" : "") : "";
     $target_input_id = "";
     $is_description_above = rgar($field, "descriptionPlacement") == "above";
     switch (RGFormsModel::get_input_type($field)) {
         case "section":
             $description = self::get_description(rgget("description", $field), "gsection_description");
             $field_content = sprintf("%s<h2 class='gsection_title'>%s</h2>%s", $admin_buttons, esc_html($field_label), $description);
             break;
         case "page":
             //only executed on the form editor in the admin
             $page_label = __("Page Break", "gravityforms");
             $src = GFCommon::get_base_url() . "/images/gf_pagebreak_inline.png";
             $field_content = "{$admin_buttons} <label class='gfield_label'>&nbsp;</label><img src='{$src}' alt='{$page_label}' title='{$page_label}' />";
             break;
         case "adminonly_hidden":
         case "hidden":
         case "html":
             $field_content = !IS_ADMIN ? "{FIELD}" : ($field_content = sprintf("%s<label class='gfield_label' for='%s'>%s</label>{FIELD}", $admin_buttons, $field_id, esc_html($field_label)));
             break;
         case "checkbox":
         case "radio":
             $description = self::get_description(rgget("description", $field), "gfield_description");
             if ($is_description_above) {
                 $field_content = sprintf("%s<label class='gfield_label'>%s%s</label>%s{FIELD}%s", $admin_buttons, esc_html($field_label), $required_div, $description, $validation_message);
             } else {
                 $field_content = sprintf("%s<label class='gfield_label'>%s%s</label>{FIELD}%s%s", $admin_buttons, esc_html($field_label), $required_div, $description, $validation_message);
             }
             break;
         case "name":
             switch (rgar($field, "nameFormat")) {
                 case "simple":
                     $target_input_id = $field_id;
                     break;
                 case "extended":
                     $target_input_id = $field_id . "_2";
                     break;
                 default:
                     $target_input_id = $field_id . "_3";
             }
         case "address":
             if (empty($target_input_id)) {
                 $target_input_id = $field_id . "_1";
             }
         default:
             if (empty($target_input_id)) {
                 $target_input_id = $field_id;
             }
             $description = self::get_description(rgget("description", $field), "gfield_description");
             if ($is_description_above) {
                 $field_content = sprintf("%s<label class='gfield_label' for='%s'>%s%s</label>%s{FIELD}%s", $admin_buttons, $target_input_id, esc_html($field_label), $required_div, $description, $validation_message);
             } else {
                 $field_content = sprintf("%s<label class='gfield_label' for='%s'>%s%s</label>{FIELD}%s%s", $admin_buttons, $target_input_id, esc_html($field_label), $required_div, $description, $validation_message);
             }
             break;
     }
     if (RGFormsModel::get_input_type($field) == "creditcard" && !GFCommon::is_ssl() && !IS_ADMIN) {
         $field_content = "<div class='gfield_creditcard_warning_message'>" . __("This page is unsecured. Do not enter a real credit card number. Use this field only for testing purposes. ", "gravityforms") . "</div>" . $field_content;
     }
     $value = self::default_if_empty($field, $value);
     $field_content = str_replace("{FIELD}", GFCommon::get_field_input($field, $value, 0, $form_id), $field_content);
     $field_content = apply_filters("gform_field_content", $field_content, $field, $value, 0, $form_id);
     return $field_content;
 }
Beispiel #26
0
 public static function get_form_fields($form_id)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     //Adding default fields
     array_push($form["fields"], array("id" => "date_created", "label" => __("Entry Date", "gravityformscampaignmonitor")));
     array_push($form["fields"], array("id" => "ip", "label" => __("User IP", "gravityformscampaignmonitor")));
     array_push($form["fields"], array("id" => "source_url", "label" => __("Source Url", "gravityformscampaignmonitor")));
     if (is_array($form["fields"])) {
         foreach ($form["fields"] as $field) {
             if (is_array(rgar($field, "inputs"))) {
                 //If this is a name field, add full name to the list
                 if (RGFormsModel::get_input_type($field) == "name") {
                     $fields[] = array($field["id"], GFCommon::get_label($field) . " (" . __("Full", "gravityformscampaignmonitor") . ")");
                 }
                 foreach ($field["inputs"] as $input) {
                     $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
                 }
             } else {
                 if (!rgar($field, "displayOnly")) {
                     $fields[] = array($field["id"], GFCommon::get_label($field));
                 }
             }
         }
     }
     return $fields;
 }
    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 
    }
Beispiel #28
0
 private static function get_bp_gform_fields($form)
 {
     $fields = array();
     if (is_array($form["fields"])) {
         foreach ($form["fields"] as $field) {
             $inputs = $field instanceof GF_Field ? $field->get_entry_inputs() : rgar($field, 'inputs');
             if (is_array($inputs) && !empty($inputs)) {
                 if (RGFormsModel::get_input_type($field) == "checkbox") {
                     $fields[] = array($field["id"], GFCommon::get_label($field));
                     continue;
                 }
                 if (RGFormsModel::get_input_type($field) == "address" || RGFormsModel::get_input_type($field) == "name") {
                     $fields[] = array($field["id"], GFCommon::get_label($field) . " (" . __("Full", "gravityformsuserregistration") . ")");
                 }
                 foreach ($inputs as $input) {
                     $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
                 }
             } else {
                 if (!rgar($field, 'displayOnly')) {
                     $fields[] = array($field["id"], GFCommon::get_label($field));
                 }
             }
         }
     }
     return $fields;
 }
Beispiel #29
0
 public function ajax_get_results()
 {
     // tooltips
     require_once GFCommon::get_base_path() . '/tooltips.php';
     add_filter('gform_tooltips', array($this, 'add_tooltips'));
     $output = array();
     $html = '';
     $form_id = rgpost('id');
     $form = GFFormsModel::get_form_meta($form_id);
     $form = gf_apply_filters(array('gform_form_pre_results', $form_id), $form);
     $search_criteria['status'] = 'active';
     $fields = $this->get_fields($form);
     $total_entries = GFAPI::count_entries($form_id, $search_criteria);
     if ($total_entries == 0) {
         $html = esc_html__('No results.', 'gravityforms');
     } else {
         $search_criteria = array();
         $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
         $start_date = rgpost('start');
         $end_date = rgpost('end');
         if ($start_date) {
             $search_criteria['start_date'] = $start_date;
         }
         if ($end_date) {
             $search_criteria['end_date'] = $end_date;
         }
         $search_criteria['status'] = 'active';
         $output['s'] = http_build_query($search_criteria);
         $state_array = null;
         if (isset($_POST['state'])) {
             $state = $_POST['state'];
             $posted_check_sum = rgpost('checkSum');
             $generated_check_sum = self::generate_checksum($state);
             $state_array = json_decode(base64_decode($state), true);
             if ($generated_check_sum !== $posted_check_sum) {
                 $output['status'] = 'complete';
                 $output['html'] = esc_html__('There was an error while processing the entries. Please contact support.', 'gravityforms');
                 echo json_encode($output);
                 die;
             }
         }
         $data = isset($this->_callbacks['data']) ? call_user_func($this->_callbacks['data'], $form, $fields, $search_criteria, $state_array) : $this->get_results_data($form, $fields, $search_criteria, $state_array);
         $entry_count = $data['entry_count'];
         if ('incomplete' === rgar($data, 'status')) {
             $state = base64_encode(json_encode($data));
             $output['status'] = 'incomplete';
             $output['stateObject'] = $state;
             $output['checkSum'] = self::generate_checksum($state);
             $output['html'] = sprintf(esc_html__('Entries processed: %1$d of %2$d', 'gravityforms'), rgar($data, 'offset'), $entry_count);
             echo json_encode($output);
             die;
         }
         if ($total_entries > 0) {
             $html = isset($this->_callbacks['markup']) ? call_user_func($this->_callbacks['markup'], $html, $data, $form, $fields) : '';
             if (empty($html)) {
                 foreach ($fields as $field) {
                     $field_id = $field->id;
                     $html .= "<div class='gresults-results-field' id='gresults-results-field-{$field_id}'>";
                     $html .= "<div class='gresults-results-field-label'>" . esc_html(GFCommon::get_label($field)) . '</div>';
                     $html .= '<div>' . self::get_field_results($form_id, $data, $field, $search_criteria) . '</div>';
                     $html .= '</div>';
                 }
             }
         } else {
             $html .= esc_html__('No results', 'gravityforms');
         }
     }
     $output['html'] = $html;
     $output['status'] = 'complete';
     $output['searchCriteria'] = $search_criteria;
     echo json_encode($output);
     die;
 }
Beispiel #30
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 
    }