Exemple #1
0
 public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1)
 {
     /**
      * Provides the ability to modify the options used to display the form
      *
      * @param array An array of Form Arguments when adding it to a page/post (Like the ID, Title, AJAX or not, etc)
      */
     $form_args = apply_filters('gform_form_args', compact('form_id', 'display_title', 'display_description', 'force_display', 'field_values', 'ajax', 'tabindex'));
     extract($form_args);
     //looking up form id by form name
     if (!is_numeric($form_id)) {
         $form_id = RGFormsModel::get_form_id($form_id);
     }
     //reading form metadata
     $form = GFAPI::get_form($form_id);
     $form = self::maybe_add_review_page($form);
     $action = remove_query_arg('gf_token');
     //disable ajax if form has a reCAPTCHA field (not supported).
     if ($ajax && self::has_recaptcha_field($form)) {
         $ajax = false;
     }
     if (isset($_POST['gform_send_resume_link'])) {
         $save_email_confirmation = self::handle_save_email_confirmation($form, $ajax);
         if (is_wp_error($save_email_confirmation)) {
             // Failed email validation
             $resume_token = rgpost('gform_resume_token');
             $resume_token = sanitize_key($resume_token);
             $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values($resume_token);
             if ($incomplete_submission_info['form_id'] == $form_id) {
                 $submission_details_json = $incomplete_submission_info['submission'];
                 $submission_details = json_decode($submission_details_json, true);
                 $partial_entry = $submission_details['partial_entry'];
                 $form = self::update_confirmation($form, $partial_entry, 'form_saved');
                 $confirmation_message = rgar($form['confirmation'], 'message');
                 $nl2br = rgar($form['confirmation'], 'disableAutoformat') ? false : true;
                 $confirmation_message = GFCommon::replace_variables($confirmation_message, $form, $partial_entry, false, true, $nl2br);
                 return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax);
             }
         } else {
             return $save_email_confirmation;
         }
     }
     $is_postback = false;
     $is_valid = true;
     $confirmation_message = '';
     //If form was submitted, read variables set during form submission procedure
     $submission_info = isset(self::$submission[$form_id]) ? self::$submission[$form_id] : false;
     if (rgar($submission_info, 'saved_for_later') == true) {
         $resume_token = $submission_info['resume_token'];
         $confirmation_message = rgar($submission_info, 'confirmation_message');
         return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax);
     }
     $partial_entry = $submitted_values = false;
     if (isset($_GET['gf_token'])) {
         $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values($_GET['gf_token']);
         if ($incomplete_submission_info['form_id'] == $form_id) {
             $submission_details_json = $incomplete_submission_info['submission'];
             $submission_details = json_decode($submission_details_json, true);
             $partial_entry = $submission_details['partial_entry'];
             $submitted_values = $submission_details['submitted_values'];
             $field_values = $submission_details['field_values'];
             GFFormsModel::$unique_ids[$form_id] = $submission_details['gform_unique_id'];
             GFFormsModel::$uploaded_files[$form_id] = $submission_details['files'];
             self::set_submission_if_null($form_id, 'resuming_incomplete_submission', true);
             self::set_submission_if_null($form_id, 'form_id', $form_id);
             $max_page_number = self::get_max_page_number($form);
             $page_number = $submission_details['page_number'] > $max_page_number ? $max_page_number : $submission_details['page_number'];
             self::set_submission_if_null($form_id, 'page_number', $page_number);
         }
     }
     if (!is_array($partial_entry)) {
         /**
          * A filter that allows disabling of the form view counter
          *
          * @param int $form_id The Form ID to filter when disabling the form view counter
          * @param bool Default set to false (view counter enabled), can be set to true to disable the counter
          */
         $view_counter_disabled = gf_apply_filters(array('gform_disable_view_counter', $form_id), false);
         if ($submission_info) {
             $is_postback = true;
             $is_valid = rgar($submission_info, 'is_valid') || rgar($submission_info, 'is_confirmation');
             $form = $submission_info['form'];
             $lead = $submission_info['lead'];
             $confirmation_message = rgget('confirmation_message', $submission_info);
             if ($is_valid && !RGForms::get('is_confirmation', $submission_info)) {
                 if ($submission_info['page_number'] == 0) {
                     /**
                      * Fired after form submission
                      *
                      * @param array $lead The Entry object
                      * @param array $form The Form object
                      */
                     gf_do_action(array('gform_post_submission', $form['id']), $lead, $form);
                 } else {
                     /**
                      * Fired after the page changes on a multi-page form
                      *
                      * @param array $form                                  The Form object
                      * @param int   $submission_info['source_page_number'] The page that was submitted
                      * @param int   $submission_info['page_number']        The page that the user is being sent to
                      */
                     gf_do_action(array('gform_post_paging', $form['id']), $form, $submission_info['source_page_number'], $submission_info['page_number']);
                 }
             }
         } elseif (!current_user_can('administrator') && !$view_counter_disabled) {
             RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']);
         }
     }
     if (rgar($form, 'enableHoneypot')) {
         $form['fields'][] = self::get_honeypot_field($form);
     }
     //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end
     $form = gf_apply_filters(array('gform_pre_render', $form_id), $form, $ajax, $field_values);
     if ($form == null) {
         return '<p>' . esc_html__('Oops! We could not locate your form.', 'gravityforms') . '</p>';
     }
     $has_pages = self::has_pages($form);
     //calling tab index filter
     GFCommon::$tab_index = gf_apply_filters(array('gform_tabindex', $form_id), $tabindex, $form);
     //Don't display inactive forms
     if (!$force_display && !$is_postback) {
         $form_info = RGFormsModel::get_form($form_id);
         if (empty($form_info) || !$form_info->is_active) {
             return '';
         }
         // If form requires login, check if user is logged in
         if (rgar($form, 'requireLogin')) {
             if (!is_user_logged_in()) {
                 return empty($form['requireLoginMessage']) ? '<p>' . esc_html__('Sorry. You must be logged in to view this form.', 'gravityforms') . '</p>' : '<p>' . GFCommon::gform_do_shortcode($form['requireLoginMessage']) . '</p>';
             }
         }
     }
     // show the form regardless of the following validations when force display is set to true
     if (!$force_display || $is_postback) {
         $form_schedule_validation = self::validate_form_schedule($form);
         // if form schedule validation fails AND this is not a postback, display the validation error
         // if form schedule validation fails AND this is a postback, make sure is not a valid submission (enables display of confirmation message)
         if ($form_schedule_validation && !$is_postback || $form_schedule_validation && $is_postback && !$is_valid) {
             return $form_schedule_validation;
         }
         $entry_limit_validation = self::validate_entry_limit($form);
         // refer to form schedule condition notes above
         if ($entry_limit_validation && !$is_postback || $entry_limit_validation && $is_postback && !$is_valid) {
             return $entry_limit_validation;
         }
     }
     $form_string = '';
     //When called via a template, this will enqueue the proper scripts
     //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event
     self::enqueue_form_scripts($form, $ajax);
     $is_form_editor = GFCommon::is_form_editor();
     $is_entry_detail = GFCommon::is_entry_detail();
     $is_admin = $is_form_editor || $is_entry_detail;
     if (empty($confirmation_message)) {
         $wrapper_css_class = GFCommon::get_browser_class() . ' gform_wrapper';
         if (!$is_valid) {
             $wrapper_css_class .= ' gform_validation_error';
         }
         $form_css_class = esc_attr(rgar($form, 'cssClass'));
         //Hiding entire form if conditional logic is on to prevent 'hidden' fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied.
         $style = self::has_conditional_logic($form) ? "style='display:none'" : '';
         $custom_wrapper_css_class = !empty($form_css_class) ? " {$form_css_class}_wrapper" : '';
         $form_string .= "\n                <div class='{$wrapper_css_class}{$custom_wrapper_css_class}' id='gform_wrapper_{$form_id}' " . $style . '>';
         $default_anchor = $has_pages || $ajax ? true : false;
         $use_anchor = gf_apply_filters(array('gform_confirmation_anchor', $form_id), $default_anchor);
         if ($use_anchor !== false) {
             $form_string .= "<a id='gf_{$form_id}' class='gform_anchor' ></a>";
             $action .= "#gf_{$form_id}";
         }
         $target = $ajax ? "target='gform_ajax_frame_{$form_id}'" : '';
         $form_css_class = !empty($form['cssClass']) ? "class='{$form_css_class}'" : '';
         $action = esc_url($action);
         $form_string .= gf_apply_filters(array('gform_form_tag', $form_id), "<form method='post' enctype='multipart/form-data' {$target} id='gform_{$form_id}' {$form_css_class} action='{$action}'>", $form);
         if ($display_title || $display_description) {
             $form_string .= "\n                        <div class='gform_heading'>";
             if ($display_title) {
                 $form_string .= "\n                            <h3 class='gform_title'>" . $form['title'] . '</h3>';
             }
             if ($display_description) {
                 $form_string .= "\n                            <span class='gform_description'>" . rgar($form, 'description') . '</span>';
             }
             $form_string .= '
                     </div>';
         }
         $current_page = self::get_current_page($form_id);
         if ($has_pages && !$is_admin) {
             if ($form['pagination']['type'] == 'percentage') {
                 $form_string .= self::get_progress_bar($form, $form_id, $confirmation_message);
             } else {
                 if ($form['pagination']['type'] == 'steps') {
                     $form_string .= "\n                    <div id='gf_page_steps_{$form_id}' class='gf_page_steps'>";
                     $pages = isset($form['pagination']['pages']) ? $form['pagination']['pages'] : array();
                     for ($i = 0, $count = sizeof($pages); $i < $count; $i++) {
                         $step_number = $i + 1;
                         $active_class = $step_number == $current_page ? ' gf_step_active' : '';
                         $first_class = $i == 0 ? ' gf_step_first' : '';
                         $last_class = $i + 1 == $count ? ' gf_step_last' : '';
                         $complete_class = $step_number < $current_page ? ' gf_step_completed' : '';
                         $previous_class = $step_number + 1 == $current_page ? ' gf_step_previous' : '';
                         $next_class = $step_number - 1 == $current_page ? ' gf_step_next' : '';
                         $pending_class = $step_number > $current_page ? ' gf_step_pending' : '';
                         $classes = 'gf_step' . $active_class . $first_class . $last_class . $complete_class . $previous_class . $next_class . $pending_class;
                         $classes = GFCommon::trim_all($classes);
                         $form_string .= "\n                        <div id='gf_step_{$form_id}_{$step_number}' class='{$classes}'><span class='gf_step_number'>{$step_number}</span>&nbsp;<span class='gf_step_label'>{$pages[$i]}</span></div>";
                     }
                     $form_string .= "\n                        <div class='gf_step_clear'></div>\n                    </div>";
                 }
             }
         }
         if ($is_postback && !$is_valid) {
             $validation_message = "<div class='validation_error'>" . esc_html__('There was a problem with your submission.', 'gravityforms') . ' ' . esc_html__('Errors have been highlighted below.', 'gravityforms') . '</div>';
             $form_string .= gf_apply_filters(array('gform_validation_message', $form_id), $validation_message, $form);
         }
         $form_string .= "\n                        <div class='gform_body'>";
         //add first page if this form has any page fields
         if ($has_pages) {
             $style = self::is_page_active($form_id, 1) ? '' : "style='display:none;'";
             $class = !empty($form['firstPageCssClass']) ? " {$form['firstPageCssClass']}" : '';
             $class = esc_attr($class);
             $form_string .= "<div id='gform_page_{$form_id}_1' class='gform_page{$class}' {$style}>\n                                    <div class='gform_page_fields'>";
         }
         $description_class = rgar($form, 'descriptionPlacement') == 'above' ? 'description_above' : 'description_below';
         $sublabel_class = rgar($form, 'subLabelPlacement') == 'above' ? 'form_sublabel_above' : 'form_sublabel_below';
         $form_string .= "<ul id='gform_fields_{$form_id}' class='" . GFCommon::get_ul_classes($form) . "'>";
         if (is_array($form['fields'])) {
             foreach ($form['fields'] as $field) {
                 /* @var GF_Field $field */
                 $field->conditionalLogicFields = self::get_conditional_logic_fields($form, $field->id);
                 if (is_array($submitted_values)) {
                     $field_value = rgar($submitted_values, $field->id);
                 } else {
                     $field_value = GFFormsModel::get_field_value($field, $field_values);
                 }
                 $form_string .= self::get_field($field, $field_value, false, $form, $field_values);
             }
         }
         $form_string .= '
                         </ul>';
         if ($has_pages) {
             $previous_button_alt = rgempty('imageAlt', $form['lastPageButton']) ? __('Previous Page', 'gravityforms') : $form['lastPageButton']['imageAlt'];
             $previous_button = self::get_form_button($form['id'], "gform_previous_button_{$form['id']}", $form['lastPageButton'], __('Previous', 'gravityforms'), 'gform_previous_button', $previous_button_alt, self::get_current_page($form_id) - 1);
             /**
              * Filter through the form previous button when paged
              *
              * @param int $form_id The Form ID to filter through
              * @param string $previous_button The HTML rendered button (rendered with the form ID and the function get_form_button)
              * @param array $form The Form object to filter through
              */
             $previous_button = gf_apply_filters(array('gform_previous_button', $form_id), $previous_button, $form);
             $form_string .= '</div>' . self::gform_footer($form, 'gform_page_footer ' . $form['labelPlacement'], $ajax, $field_values, $previous_button, $display_title, $display_description, $is_postback) . '
                     </div>';
             //closes gform_page
         }
         $form_string .= '</div>';
         //closes gform_body
         //suppress form footer for multi-page forms (footer will be included on the last page
         if (!$has_pages) {
             $form_string .= self::gform_footer($form, 'gform_footer ' . $form['labelPlacement'], $ajax, $field_values, '', $display_title, $display_description, $tabindex);
         }
         $form_string .= '
                     </form>
                     </div>';
         if ($ajax && $is_postback) {
             global $wp_scripts;
             $form_string = apply_filters('gform_ajax_iframe_content', '<!DOCTYPE html><html><head>' . "<meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $form_string . '</body></html>');
         }
         if ($ajax && !$is_postback) {
             $spinner_url = gf_apply_filters(array('gform_ajax_spinner_url', $form_id), GFCommon::get_base_url() . '/images/spinner.gif', $form);
             $scroll_position = array('default' => '', 'confirmation' => '');
             if ($use_anchor !== false) {
                 $scroll_position['default'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gform_wrapper_{$form_id}').offset().top);";
                 $scroll_position['confirmation'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gforms_confirmation_message_{$form_id}').offset().top);";
             }
             $iframe_style = defined('GF_DEBUG') && GF_DEBUG ? 'display:block;width:600px;height:300px;border:1px solid #eee;' : 'display:none;width:0px;height:0px;';
             $is_html5 = RGFormsModel::is_html5_enabled();
             $iframe_title = $is_html5 ? " title='Ajax Frame'" : '';
             $form_string .= "\n                <iframe style='{$iframe_style}' src='about:blank' name='gform_ajax_frame_{$form_id}' id='gform_ajax_frame_{$form_id}'" . $iframe_title . "></iframe>\n                <script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . '' . 'jQuery(document).ready(function($){' . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery('#gform_ajax_frame_{$form_id}').load( function(){" . "var contents = jQuery(this).contents().find('*').html();" . "var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;" . 'if(!is_postback){return;}' . "var form_content = jQuery(this).contents().find('#gform_wrapper_{$form_id}');" . "var is_confirmation = jQuery(this).contents().find('#gform_confirmation_wrapper_{$form_id}').length > 0;" . "var is_redirect = contents.indexOf('gformRedirect(){') >= 0;" . 'var is_form = form_content.length > 0 && ! is_redirect && ! is_confirmation;' . 'if(is_form){' . "jQuery('#gform_wrapper_{$form_id}').html(form_content.html());" . "setTimeout( function() { /* delay the scroll by 50 milliseconds to fix a bug in chrome */ {$scroll_position['default']} }, 50 );" . "if(window['gformInitDatepicker']) {gformInitDatepicker();}" . "if(window['gformInitPriceFields']) {gformInitPriceFields();}" . "var current_page = jQuery('#gform_source_page_number_{$form_id}').val();" . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery(document).trigger('gform_page_loaded', [{$form_id}, current_page]);" . "window['gf_submitting_{$form_id}'] = false;" . '}' . 'else if(!is_redirect){' . "var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message_{$form_id}').html();" . 'if(!confirmation_content){' . 'confirmation_content = contents;' . '}' . 'setTimeout(function(){' . "jQuery('#gform_wrapper_{$form_id}').replaceWith('<' + 'div id=\\'gforms_confirmation_message_{$form_id}\\' class=\\'gform_confirmation_message_{$form_id} gforms_confirmation_message\\'' + '>' + confirmation_content + '<' + '/div' + '>');" . "{$scroll_position['confirmation']}" . "jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}]);" . "window['gf_submitting_{$form_id}'] = false;" . '}, 50);' . '}' . 'else{' . "jQuery('#gform_{$form_id}').append(contents);" . "if(window['gformRedirect']) {gformRedirect();}" . '}' . "jQuery(document).trigger('gform_post_render', [{$form_id}, current_page]);" . '} );' . '} );' . apply_filters('gform_cdata_close', '') . '</script>';
         }
         $is_first_load = !$is_postback;
         if (!$ajax || $is_first_load) {
             self::register_form_init_scripts($form, $field_values, $ajax);
             if (apply_filters('gform_init_scripts_footer', false)) {
                 add_action('wp_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'), 20);
                 add_action('gform_preview_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'));
             } else {
                 $form_string .= self::get_form_init_scripts($form);
                 $form_string .= "<script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . " jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [{$form_id}, {$current_page}]) } ); " . apply_filters('gform_cdata_close', '') . '</script>';
             }
         }
         return gf_apply_filters(array('gform_get_form_filter', $form_id), $form_string, $form);
     } else {
         $progress_confirmation = '';
         //check admin setting for whether the progress bar should start at zero
         $start_at_zero = rgars($form, 'pagination/display_progressbar_on_confirmation');
         $start_at_zero = apply_filters('gform_progressbar_start_at_zero', $start_at_zero, $form);
         //show progress bar on confirmation
         if ($start_at_zero && $has_pages && !$is_admin && ($form['confirmation']['type'] == 'message' && $form['pagination']['type'] == 'percentage')) {
             $progress_confirmation = self::get_progress_bar($form, $form_id, $confirmation_message);
             if ($ajax) {
                 $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $progress_confirmation . '</body></html>');
             }
         } else {
             //return regular confirmation message
             if ($ajax) {
                 $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $confirmation_message . '</body></html>');
             } else {
                 $progress_confirmation = $confirmation_message;
             }
         }
         return $progress_confirmation;
     }
 }
 public static function evaluate_conditional_logic($logic, $form, $lead)
 {
     if (!$logic || !is_array($logic["rules"])) {
         return true;
     }
     $match_count = 0;
     if (is_array($logic["rules"])) {
         foreach ($logic["rules"] as $rule) {
             $source_field = GFFormsModel::get_field($form, $rule["fieldId"]);
             $field_value = empty($lead) ? GFFormsModel::get_field_value($source_field, array()) : GFFormsModel::get_lead_field_value($lead, $source_field);
             $is_value_match = GFFormsModel::is_value_match($field_value, $rule["value"], $rule["operator"], $source_field);
             if ($is_value_match) {
                 $match_count++;
             }
         }
     }
     $do_action = $logic["logicType"] == "all" && $match_count == sizeof($logic["rules"]) || $logic["logicType"] == "any" && $match_count > 0;
     return $do_action;
 }
 /**
  * Get the posted values from the edit form submission
  *
  * @hack
  * @uses GFFormsModel::get_field_value()
  * @param  mixed $value Existing field value, before edit
  * @param  array $lead  Gravity Forms entry array
  * @param  array $field Gravity Forms field array
  * @return string        [description]
  */
 public function get_field_value($value, $lead, $field)
 {
     // The form's not being edited; use the original value
     if (!$this->is_edit_entry_submission()) {
         return $value;
     }
     return GFFormsModel::get_field_value($field, $lead, true);
 }
 public static function get_form($form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1)
 {
     //		echo  "$form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 1 ";
     /**
      * @To do tomorrow
      * datact if its approved or not => done
      * Lacking will find the correct container and hide it.
      * /app/wwwroot/wp-content/plugins/gravityforms/includes/fields/class-gf-field-creditcard.php
      * /app/wwwroot/wp-content/themes/TPO10/functions.php
      * /app/wwwroot/wp-content/plugins/gravityforms/form_display
      */
     /**
      * STEPS
      *
      * Find way how to filter if approved or not => done
      * Find the actual html of the credit cards fields
      */
     // gform_lead_id = 1137
     // [gform_edit_id] => 1137
     // [input_id] => 1137
     // [input_payment_status] => approved
     //EDIT
     // gform_edit_id = 1137
     // input_id = 1137
     // [input_form_id] => 75
     // [input_payment_status] => approved
     // [gform_submit] => 75
     //IF CLICK NEXT
     /**
      * [gform_lead_id] => 1137
      * GET DATA BY THAT ID CHECK IF APPROVED OR NOT APPROVED
      */
     //IF EDIT
     /**
      * [input_payment_status] => approved
      * [input_id] => 1137
      * [gform_edit_id] => 1137
      * [input_form_id] => 75
      */
     //		print_r($_POST);
     //		echo "total post " . count($_POST) . '<br>';
     //		if (count($_POST) > 1) {
     //
     //			$form_id_lead = $_POST['gform_edit_id'];
     //			$form_id = $_POST['input_form_id'];
     //			if (empty($form_id_lead)) {
     //				$form_id_lead = $_POST['gform_lead_id'];
     //			}
     //			if (empty($form_id)) {
     //				$form_id = $_POST['gform_submit'];
     //			}
     //
     //			$paymentStatus = '';
     //			$isApproved = false;
     //			if (!empty($form_id) and !empty($form_id_lead)) {
     //				//				echo "form id is not empty <br>";
     //				global $wpdb;
     //				$results = $wpdb->get_results("SELECT * FROM wp_rg_lead WHERE form_id = $form_id AND id = $form_id_lead", 'ARRAY_A');
     //
     //				//				echo "<pre>";
     //				//				echo "result from db";
     //				//				print_r($results);
     //				//
     //				//				echo "result from post";
     //				//				print_r($_POST);
     //				//
     //				//				echo "</pre>";
     //				// echo "This is the form printed <br> form id " . $form_id;
     //				// provides the ability to modify the options used to display the form
     //
     //
     //
     //				if ($_POST['input_payment_status'] == 'approved' || $_POST['input_payment_status'] == 'approve' || $_POST['input_payment_status'] == 'Approved') {
     //					//echo "approved<br>";
     //					//add code to hide credit card
     //					$isApproved = true;
     //					$paymentStatus = $_POST['input_payment_status'];
     //
     //				}
     //				if ($results[0]['payment_status'] == 'approved' || $results[0]['payment_status'] == 'approve' || $results[0]['payment_status'] == 'Approved') {
     //					//echo "approved<br>";
     //					//add code to hide credit card
     //					$isApproved = true;
     //					$paymentStatus = $results[0]['payment_status'];
     //				} else {
     //					//do nothing
     //					// echo "not approved<br>";
     //				}
     //
     //				// echo "form id " . $form_id . '<br>';
     //				// echo "lead id " . $form_id_lead . '<br>';
     //				// echo "status " . $results[0]['payment_status'] . '<br>';
     //
     //				// echo "db status = " . $results[0][0]['payment_status'] . '<br>';
     //				// echo "form id " . $form_id . '<br>';
     //				// cho "lead id " . $form_id_lead . '<br>';
     //
     //			} else {
     //				// echo "form id is  empty <br>";
     //			}  // end if
     //		} //end if form
     /**
      * Get the value for the wp_users.user_status
      * and set the if user type is member or none member
      * if member then hide credit card if not then show credit card
      */
     //        global $current_user;
     //        if($current_user->user_status == 0) {
     //            $userType = 'none member';
     //        } else {
     //            $userType = 'member';
     //        }
     /**
      * Another option above but prefer for above code because it's short
      * Set it to true when when you want to use it.
      * same function to above code.
      */
     if (false) {
         global $wpdb;
         $user_ID = get_current_user_id();
         $userInfo = $wpdb->get_results("SELECT * FROM wp_users WHERE ID = " . $user_ID, 'ARRAY_A');
         if ($userInfo[0]['user_status'] == 0) {
             $userType = 'none member';
         } else {
             $userType = 'member';
         }
     }
     // $currentUserInfo = get_currentuserinfo();
     //echo "<pre>";
     // print_r($userInfo);
     //print_r($currentUserInfo);
     //echo "id " . $current_user->user_status;
     //echo "</pre>";
     //echo "user status " . $current_user->user_status;
     // exit;
     /**
      * Original code from this plugin
      */
     $form_args = apply_filters('gform_form_args', compact('form_id', 'display_title', 'display_description', 'force_display', 'field_values', 'ajax', 'tabindex'));
     extract($form_args);
     //looking up form id by form name
     if (!is_numeric($form_id)) {
         $form_id = RGFormsModel::get_form_id($form_id);
     }
     //reading form metadata
     //check code line
     $form = RGFormsModel::get_form_meta($form_id, true);
     // echo "<pre>";
     // print_r($form);
     //echo "<pre>";
     // echo 'title ' . $form['title'] . '<br>';
     // echo 'desc ' . $form['description'] . '<br>';
     // echo 'fields <br>';
     // print( $form['fields'] );
     // $fields_array  =  (array) $form['fields'];
     // echo "<pre>";
     // print_r($fields_array);
     // echo "</pre>";
     // echo "feld " . $fields_array[0]->type . '<br>';
     // exit;
     $action = remove_query_arg('gf_token');
     //disable ajax if form has a reCAPTCHA field (not supported).
     if ($ajax && self::has_recaptcha_field($form)) {
         $ajax = false;
     }
     if (isset($_POST['gform_send_resume_link'])) {
         $save_email_confirmation = self::handle_save_email_confirmation($form, $ajax);
         if (is_wp_error($save_email_confirmation)) {
             // Failed email validation
             $resume_token = rgpost('gform_resume_token');
             $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values(rgpost('gform_resume_token'));
             if ($incomplete_submission_info['form_id'] == $form_id) {
                 $submission_details_json = $incomplete_submission_info['submission'];
                 $submission_details = json_decode($submission_details_json, true);
                 $partial_entry = $submission_details['partial_entry'];
                 $form = self::update_confirmation($form, $partial_entry, 'form_saved');
                 $confirmation_message = rgar($form['confirmation'], 'message');
                 $nl2br = rgar($form['confirmation'], 'disableAutoformat') ? false : true;
                 $confirmation_message = GFCommon::replace_variables($confirmation_message, $form, $partial_entry, false, true, $nl2br);
                 return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax);
             }
         } else {
             return $save_email_confirmation;
         }
     }
     $is_postback = false;
     $is_valid = true;
     $confirmation_message = '';
     //If form was submitted, read variables set during form submission procedure
     $submission_info = isset(self::$submission[$form_id]) ? self::$submission[$form_id] : false;
     if (rgar($submission_info, 'saved_for_later') == true) {
         $resume_token = $submission_info['resume_token'];
         $confirmation_message = rgar($submission_info, 'confirmation_message');
         return self::handle_save_confirmation($form, $resume_token, $confirmation_message, $ajax);
     }
     $partial_entry = $submitted_values = false;
     if (isset($_GET['gf_token'])) {
         $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values($_GET['gf_token']);
         if ($incomplete_submission_info['form_id'] == $form_id) {
             $submission_details_json = $incomplete_submission_info['submission'];
             $submission_details = json_decode($submission_details_json, true);
             $partial_entry = $submission_details['partial_entry'];
             $submitted_values = $submission_details['submitted_values'];
             $field_values = $submission_details['field_values'];
             GFFormsModel::$unique_ids[$form_id] = $submission_details['gform_unique_id'];
             GFFormsModel::$uploaded_files[$form_id] = $submission_details['files'];
             self::set_submission_if_null($form_id, 'resuming_incomplete_submission', true);
             self::set_submission_if_null($form_id, 'form_id', $form_id);
             self::set_submission_if_null($form_id, 'page_number', $submission_details['page_number']);
         }
     }
     if (!is_array($partial_entry)) {
         $view_counter_disabled = gf_apply_filters('gform_disable_view_counter', $form_id, false);
         if ($submission_info) {
             $is_postback = true;
             $is_valid = rgar($submission_info, 'is_valid') || rgar($submission_info, 'is_confirmation');
             $form = $submission_info['form'];
             $lead = $submission_info['lead'];
             $confirmation_message = rgget('confirmation_message', $submission_info);
             if ($is_valid && !RGForms::get('is_confirmation', $submission_info)) {
                 if ($submission_info['page_number'] == 0) {
                     //post submission hook
                     gf_do_action('gform_post_submission', $form['id'], $lead, $form);
                 } else {
                     //change page hook
                     gf_do_action('gform_post_paging', $form['id'], $form, $submission_info['source_page_number'], $submission_info['page_number']);
                 }
             }
         } elseif (!current_user_can('administrator') && !$view_counter_disabled) {
             RGFormsModel::insert_form_view($form_id, $_SERVER['REMOTE_ADDR']);
         }
     }
     if (rgar($form, 'enableHoneypot')) {
         $form['fields'][] = self::get_honeypot_field($form);
     }
     // print test
     // echo " submition id " . $form['id'] . '<br>';
     //Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end
     //check this part
     $form = gf_apply_filters('gform_pre_render', $form_id, $form, $ajax, $field_values);
     // echo "<pre>";
     //
     // print_r($form);
     //
     // echo "<pre>";
     if ($form == null) {
         return '<p>' . esc_html__('Oops! We could not locate your form.', 'gravityforms') . '</p>';
     }
     $has_pages = self::has_pages($form);
     //calling tab index filter
     GFCommon::$tab_index = gf_apply_filters('gform_tabindex', $form_id, $tabindex, $form);
     //Don't display inactive forms
     if (!$force_display && !$is_postback) {
         //check here..
         $form_info = RGFormsModel::get_form($form_id);
         if (empty($form_info) || !$form_info->is_active) {
             return '';
         }
         // If form requires login, check if user is logged in
         if (rgar($form, 'requireLogin')) {
             if (!is_user_logged_in()) {
                 return empty($form['requireLoginMessage']) ? '<p>' . esc_html__('Sorry. You must be logged in to view this form.', 'gravityforms') . '</p>' : '<p>' . GFCommon::gform_do_shortcode($form['requireLoginMessage']) . '</p>';
             }
         }
     }
     // show the form regardless of the following validations when force display is set to true
     if (!$force_display || $is_postback) {
         $form_schedule_validation = self::validate_form_schedule($form);
         // if form schedule validation fails AND this is not a postback, display the validation error
         // if form schedule validation fails AND this is a postback, make sure is not a valid submission (enables display of confirmation message)
         if ($form_schedule_validation && !$is_postback || $form_schedule_validation && $is_postback && !$is_valid) {
             return $form_schedule_validation;
         }
         $entry_limit_validation = self::validate_entry_limit($form);
         // refer to form schedule condition notes above
         if ($entry_limit_validation && !$is_postback || $entry_limit_validation && $is_postback && !$is_valid) {
             return $entry_limit_validation;
         }
     }
     $form_string = '';
     //When called via a template, this will enqueue the proper scripts
     //When called via a shortcode, this will be ignored (too late to enqueue), but the scripts will be enqueued via the enqueue_scripts event
     self::enqueue_form_scripts($form, $ajax);
     $is_form_editor = GFCommon::is_form_editor();
     $is_entry_detail = GFCommon::is_entry_detail();
     $is_admin = $is_form_editor || $is_entry_detail;
     if (empty($confirmation_message)) {
         $wrapper_css_class = GFCommon::get_browser_class() . ' gform_wrapper';
         if (!$is_valid) {
             $wrapper_css_class .= ' gform_validation_error';
         }
         //Hiding entire form if conditional logic is on to prevent 'hidden' fields from blinking. Form will be set to visible in the conditional_logic.php after the rules have been applied.
         $style = self::has_conditional_logic($form) ? "style='display:none'" : '';
         $custom_wrapper_css_class = !empty($form['cssClass']) ? " {$form['cssClass']}_wrapper" : '';
         $form_string .= "\n                <div class='{$wrapper_css_class}{$custom_wrapper_css_class}' id='gform_wrapper_{$form_id}' " . $style . '>';
         $default_anchor = $has_pages || $ajax ? true : false;
         $use_anchor = gf_apply_filters('gform_confirmation_anchor', $form_id, $default_anchor);
         if ($use_anchor !== false) {
             $form_string .= "<a id='gf_{$form_id}' name='gf_{$form_id}' class='gform_anchor' ></a>";
             $action .= "#gf_{$form_id}";
         }
         $target = $ajax ? "target='gform_ajax_frame_{$form_id}'" : '';
         $form_css_class = !empty($form['cssClass']) ? "class='{$form['cssClass']}'" : '';
         $action = esc_url($action);
         $form_string .= gf_apply_filters('gform_form_tag', $form_id, "<form method='post' enctype='multipart/form-data' {$target} id='gform_{$form_id}' {$form_css_class} action='{$action}'>", $form);
         if ($display_title || $display_description) {
             $form_string .= "\n                        <div class='gform_heading'>";
             if ($display_title) {
                 $form_string .= "\n                            <h3 class='gform_title'>" . $form['title'] . '</h3>';
             }
             if ($display_description) {
                 $form_string .= "\n                            <span class='gform_description'>" . rgar($form, 'description') . '</span>';
             }
             $form_string .= '
                     </div>';
         }
         $current_page = self::get_current_page($form_id);
         if ($has_pages && !$is_admin) {
             if ($form['pagination']['type'] == 'percentage') {
                 $form_string .= self::get_progress_bar($form, $form_id, $confirmation_message);
             } else {
                 if ($form['pagination']['type'] == 'steps') {
                     $form_string .= "\n                    <div id='gf_page_steps_{$form_id}' class='gf_page_steps'>";
                     $pages = isset($form['pagination']['pages']) ? $form['pagination']['pages'] : array();
                     for ($i = 0, $count = sizeof($pages); $i < $count; $i++) {
                         $step_number = $i + 1;
                         $active_class = $step_number == $current_page ? ' gf_step_active' : '';
                         $first_class = $i == 0 ? ' gf_step_first' : '';
                         $last_class = $i + 1 == $count ? ' gf_step_last' : '';
                         $complete_class = $step_number < $current_page ? ' gf_step_completed' : '';
                         $previous_class = $step_number + 1 == $current_page ? ' gf_step_previous' : '';
                         $next_class = $step_number - 1 == $current_page ? ' gf_step_next' : '';
                         $pending_class = $step_number > $current_page ? ' gf_step_pending' : '';
                         $classes = 'gf_step' . $active_class . $first_class . $last_class . $complete_class . $previous_class . $next_class . $pending_class;
                         $classes = GFCommon::trim_all($classes);
                         $form_string .= "\n                        <div id='gf_step_{$form_id}_{$step_number}' class='{$classes}'><span class='gf_step_number'>{$step_number}</span>&nbsp;<span class='gf_step_label'>{$pages[$i]}</span></div>";
                     }
                     $form_string .= "\n                        <div class='gf_step_clear'></div>\n                    </div>";
                 }
             }
         }
         if ($is_postback && !$is_valid) {
             $validation_message = "<div class='validation_error'>" . esc_html__('There was a problem with your submission.', 'gravityforms') . ' ' . esc_html__('Errors have been highlighted below.', 'gravityforms') . '</div>';
             $form_string .= gf_apply_filters('gform_validation_message', $form_id, $validation_message, $form);
         }
         $form_string .= "\n                        <div class='gform_body'>";
         //add first page if this form has any page fields
         if ($has_pages) {
             $style = self::is_page_active($form_id, 1) ? '' : "style='display:none;'";
             $class = !empty($form['firstPageCssClass']) ? " {$form['firstPageCssClass']}" : '';
             $form_string .= "<div id='gform_page_{$form_id}_1' class='gform_page{$class}' {$style}>\n                                    <div class='gform_page_fields'>";
         }
         $description_class = rgar($form, 'descriptionPlacement') == 'above' ? 'description_above' : 'description_below';
         $sublabel_class = rgar($form, 'subLabelPlacement') == 'above' ? 'form_sublabel_above' : 'form_sublabel_below';
         $form_string .= "<ul id='gform_fields_{$form_id}' class='" . GFCommon::get_ul_classes($form) . "'>";
         /**
          * Here the field is being filtered
          * So if detect credit card then no credit card will show.
          *
          * Documentation:
          *
          * 1.) DB:
          * - tpocom_dash.wp_rg_lead.payment_status = "approved" or NULL
          *
          * 2.) Form.Hidden Field:
          * - Field Label: "payment status"
          * - Parameter Name: "payment_status_value"
          *
          * 3.) Form.Credit Card:
          * - Advance
          * - Enable condition logic "Hide" this field "all" of the following match "payment status" is "approved"
          */
         /**
          * @var $paymentStatus - will hold the variable if approved or not approved.
          * It is declared first line of this function, you can see the condition there.
          *
          * @var $field->inputName - set to "payment_status_value" <- this is the parameter name.
          * that's the string we set the setting up the form in the GUI at admin area.
          */
         /**
          * @var userType = member or none member
          */
         // $userType = 'member';
         // $paymentStatus = 'approved';
         // $userType = 'member';
         // get membership type
         // get payment status
         $paymentStatus = self::getPaymentStatus($form);
         $memberShipStatus = self::getMembershipStatus();
         $fieldValue = self::filterPaymentAndMemberShip($paymentStatus, $memberShipStatus);
         //			 echo "payment status $paymentStatus membership status $memberShipStatus field value = $fieldValue <br>";
         if (is_array($form['fields'])) {
             $counter = 0;
             foreach ($form['fields'] as $field) {
                 /**
                  * Hide through form condition
                  */
                 if ($field->inputName == 'member_type_value') {
                     $form_string .= self::get_field($field, $fieldValue, false, $form, $field_values);
                 } else {
                     $field->conditionalLogicFields = self::get_conditional_logic_fields($form, $field->id);
                     if (is_array($submitted_values)) {
                         $field_value = $submitted_values[$field->id];
                     } else {
                         $field_value = GFFormsModel::get_field_value($field, $field_values);
                     }
                     $form_string .= self::get_field($field, $field_value, false, $form, $field_values);
                 }
             }
         }
         $form_string .= '
                         </ul>';
         if ($has_pages) {
             $previous_button = self::get_form_button($form['id'], "gform_previous_button_{$form['id']}", $form['lastPageButton'], __('Previous', 'gravityforms'), 'gform_previous_button', __('Previous Page', 'gravityforms'), self::get_current_page($form_id) - 1);
             $previous_button = gf_apply_filters('gform_previous_button', $form_id, $previous_button, $form);
             $form_string .= '</div>' . self::gform_footer($form, 'gform_page_footer ' . $form['labelPlacement'], $ajax, $field_values, $previous_button, $display_title, $display_description, $is_postback) . '
                     </div>';
             //closes gform_page
         }
         $form_string .= '</div>';
         //closes gform_body
         //suppress form footer for multi-page forms (footer will be included on the last page
         if (!$has_pages) {
             $form_string .= self::gform_footer($form, 'gform_footer ' . $form['labelPlacement'], $ajax, $field_values, '', $display_title, $display_description, $tabindex);
         }
         // echo "submition id 1 " . $form['id'] . '<br>';
         $form_string .= '
                     </form>
                     </div>';
         if ($ajax && $is_postback) {
             global $wp_scripts;
             $form_string = apply_filters('gform_ajax_iframe_content', '<!DOCTYPE html><html><head>' . "<meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $form_string . '</body></html>');
         }
         if ($ajax && !$is_postback) {
             $spinner_url = gf_apply_filters('gform_ajax_spinner_url', $form_id, GFCommon::get_base_url() . '/images/spinner.gif', $form);
             $scroll_position = array('default' => '', 'confirmation' => '');
             if ($use_anchor !== false) {
                 $scroll_position['default'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gform_wrapper_{$form_id}').offset().top);";
                 $scroll_position['confirmation'] = is_numeric($use_anchor) ? 'jQuery(document).scrollTop(' . intval($use_anchor) . ');' : "jQuery(document).scrollTop(jQuery('#gforms_confirmation_message_{$form_id}').offset().top);";
             }
             $iframe_style = defined('GF_DEBUG') && GF_DEBUG ? 'display:block;width:600px;height:300px;border:1px solid #eee;' : 'display:none;width:0px;height:0px;';
             $is_html5 = RGFormsModel::is_html5_enabled();
             $iframe_title = $is_html5 ? " title='Ajax Frame'" : '';
             $form_string .= "\n                <iframe style='{$iframe_style}' src='about:blank' name='gform_ajax_frame_{$form_id}' id='gform_ajax_frame_{$form_id}'" . $iframe_title . "></iframe>\n                <script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . '' . 'jQuery(document).ready(function($){' . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery('#gform_ajax_frame_{$form_id}').load( function(){" . "var contents = jQuery(this).contents().find('*').html();" . "var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;" . 'if(!is_postback){return;}' . "var form_content = jQuery(this).contents().find('#gform_wrapper_{$form_id}');" . "var is_confirmation = jQuery(this).contents().find('#gform_confirmation_wrapper_{$form_id}').length > 0;" . "var is_redirect = contents.indexOf('gformRedirect(){') >= 0;" . 'var is_form = form_content.length > 0 && ! is_redirect && ! is_confirmation;' . 'if(is_form){' . "jQuery('#gform_wrapper_{$form_id}').html(form_content.html());" . "setTimeout( function() { /* delay the scroll by 50 milliseconds to fix a bug in chrome */ {$scroll_position['default']} }, 50 );" . "if(window['gformInitDatepicker']) {gformInitDatepicker();}" . "if(window['gformInitPriceFields']) {gformInitPriceFields();}" . "var current_page = jQuery('#gform_source_page_number_{$form_id}').val();" . "gformInitSpinner( {$form_id}, '{$spinner_url}' );" . "jQuery(document).trigger('gform_page_loaded', [{$form_id}, current_page]);" . "window['gf_submitting_{$form_id}'] = false;" . '}' . 'else if(!is_redirect){' . "var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message_{$form_id}').html();" . 'if(!confirmation_content){' . 'confirmation_content = contents;' . '}' . 'setTimeout(function(){' . "jQuery('#gform_wrapper_{$form_id}').replaceWith('<' + 'div id=\\'gforms_confirmation_message_{$form_id}\\' class=\\'gform_confirmation_message_{$form_id} gforms_confirmation_message\\'' + '>' + confirmation_content + '<' + '/div' + '>');" . "{$scroll_position['confirmation']}" . "jQuery(document).trigger('gform_confirmation_loaded', [{$form_id}]);" . "window['gf_submitting_{$form_id}'] = false;" . '}, 50);' . '}' . 'else{' . "jQuery('#gform_{$form_id}').append(contents);" . "if(window['gformRedirect']) {gformRedirect();}" . '}' . "jQuery(document).trigger('gform_post_render', [{$form_id}, current_page]);" . '} );' . '} );' . apply_filters('gform_cdata_close', '') . '</script>';
         }
         $is_first_load = !$is_postback;
         if (!$ajax || $is_first_load) {
             self::register_form_init_scripts($form, $field_values, $ajax);
             if (apply_filters('gform_init_scripts_footer', false)) {
                 add_action('wp_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'), 20);
                 add_action('gform_preview_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'));
             } else {
                 $form_string .= self::get_form_init_scripts($form);
                 $form_string .= "<script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . " jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [{$form_id}, {$current_page}]) } ); " . apply_filters('gform_cdata_close', '') . '</script>';
             }
         }
         return gf_apply_filters('gform_get_form_filter', $form_id, $form_string, $form);
     } else {
         $progress_confirmation = '';
         //check admin setting for whether the progress bar should start at zero
         $start_at_zero = rgars($form, 'pagination/display_progressbar_on_confirmation');
         $start_at_zero = apply_filters('gform_progressbar_start_at_zero', $start_at_zero, $form);
         //show progress bar on confirmation
         if ($start_at_zero && $has_pages && !$is_admin && ($form['confirmation']['type'] == 'message' && $form['pagination']['type'] == 'percentage')) {
             $progress_confirmation = self::get_progress_bar($form, $form_id, $confirmation_message);
             if ($ajax) {
                 $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $progress_confirmation . '</body></html>');
             }
         } else {
             //return regular confirmation message
             if ($ajax) {
                 $progress_confirmation = apply_filters('gform_ajax_iframe_content', "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $confirmation_message . '</body></html>');
             } else {
                 $progress_confirmation = $confirmation_message;
             }
         }
         return $progress_confirmation;
     }
 }
 public static function evaluate_conditional_logic($logic, $form, $lead)
 {
     if (!$logic || !is_array(rgar($logic, 'rules'))) {
         return true;
     }
     $entry_meta_keys = array_keys(GFFormsModel::get_entry_meta($form['id']));
     $match_count = 0;
     if (is_array($logic['rules'])) {
         foreach ($logic['rules'] as $rule) {
             if (in_array($rule['fieldId'], $entry_meta_keys)) {
                 $is_value_match = GFFormsModel::is_value_match(rgar($lead, $rule['fieldId']), $rule['value'], $rule['operator'], $rule, $form);
             } else {
                 $source_field = GFFormsModel::get_field($form, $rule['fieldId']);
                 $field_value = empty($lead) ? GFFormsModel::get_field_value($source_field, array()) : GFFormsModel::get_lead_field_value($lead, $source_field);
                 $is_value_match = GFFormsModel::is_value_match($field_value, $rule['value'], $rule['operator'], $source_field, $rule, $form);
             }
             if ($is_value_match) {
                 $match_count++;
             }
         }
     }
     $do_action = $logic['logicType'] == 'all' && $match_count == sizeof($logic['rules']) || $logic['logicType'] == 'any' && $match_count > 0;
     return $do_action;
 }
 public function validate_status_update($new_status, $form)
 {
     $note = rgpost('gravityflow_note');
     $valid = true;
     switch ($this->note_mode) {
         case 'required':
             $valid = !empty($note);
             break;
         case 'required_if_in_progress':
             if ($new_status == 'in_progress' && empty($note)) {
                 $valid = false;
             }
             break;
         case 'required_if_complete':
             if ($new_status == 'complete' && empty($note)) {
                 $valid = false;
             }
     }
     if (!$valid) {
         $form['workflow_note'] = array('failed_validation' => true, 'validation_message' => esc_html__('A note is required'));
     }
     $editable_fields = $this->get_editable_fields();
     foreach ($form['fields'] as $field) {
         /* @var GF_Field $field */
         if (in_array($field->id, $editable_fields)) {
             $value = GFFormsModel::get_field_value($field);
             if ($field->get_input_type() == 'fileupload') {
                 $entry = $this->get_entry();
                 $input_name = 'input_' . $field->id;
                 $form_id = $form['id'];
                 $value = null;
                 if (isset($entry[$field->id])) {
                     $value = $entry[$field->id];
                 }
                 if (!empty($_FILES[$input_name]) && !empty($_FILES[$input_name]['name'])) {
                     $file_path = GFFormsModel::get_file_upload_path($form['id'], $_FILES[$input_name]['name']);
                     $value = $file_path['url'];
                 } else {
                     $_FILES[$input_name] = array('name' => '', 'size' => '');
                 }
                 if ($field->multipleFiles) {
                     if (isset(GFFormsModel::$uploaded_files[$form_id][$input_name])) {
                         $value = empty($value) ? '[]' : $value;
                         $value = stripslashes_deep($value);
                         $value = GFFormsModel::prepare_value($form, $field, $value, $input_name, $entry['id'], array());
                     }
                 } else {
                     GFFormsModel::$uploaded_files[$form_id][$input_name] = $value;
                 }
                 $original_value = GFFormsModel::get_lead_field_value($entry, $field);
                 if (empty($value) && !empty($original_value)) {
                     continue;
                 }
                 $_POST[$input_name] = $value;
                 if ($field->isRequired && empty($value)) {
                     $field->failed_validation = true;
                     $field->validation_message = empty($field->errorMessage) ? __('This field is required.', 'gravityforms') : $field->errorMessage;
                     $valid = false;
                 }
                 $field->validate($value, $form);
                 if ($field->failed_validation) {
                     $valid = false;
                 }
                 continue;
             }
             if ($field->isRequired && $field->is_value_submission_empty($form['id'])) {
                 $field->failed_validation = true;
                 $field->validation_message = empty($field->errorMessage) ? __('This field is required.', 'gravityforms') : $field->errorMessage;
                 $valid = false;
             } else {
                 $field->validate($value, $form);
                 if ($field->failed_validation) {
                     $valid = false;
                 }
             }
         }
     }
     $validation_result = array('is_valid' => $valid, 'form' => $form);
     $validation_result = apply_filters('gravityflow_validation_user_input', $validation_result, $this);
     if (!is_wp_error($validation_result)) {
         if (!$validation_result['is_valid']) {
             $valid = new WP_Error('validation_result', esc_html__('There was a problem while updating your form.', 'gravityflow'), $validation_result);
         }
     }
     return $valid;
 }
 /**
  * Evaluates a routing rule.
  *
  * @param $routing_rule
  *
  * @return bool Is the routing rule a match?
  */
 public function evaluate_routing_rule($routing_rule)
 {
     gravity_flow()->log_debug(__METHOD__ . '(): rule:' . print_r($routing_rule, true));
     $entry = $this->get_entry();
     $form_id = $this->get_form_id();
     $entry_meta_keys = array_keys(GFFormsModel::get_entry_meta($form_id));
     $form = GFAPI::get_form($form_id);
     if (in_array($routing_rule['fieldId'], $entry_meta_keys)) {
         $is_value_match = GFFormsModel::is_value_match(rgar($entry, $routing_rule['fieldId']), $routing_rule['value'], $routing_rule['operator'], null, $routing_rule, $form);
     } else {
         $source_field = GFFormsModel::get_field($form, $routing_rule['fieldId']);
         $field_value = empty($entry) ? GFFormsModel::get_field_value($source_field, array()) : GFFormsModel::get_lead_field_value($entry, $source_field);
         $is_value_match = GFFormsModel::is_value_match($field_value, $routing_rule['value'], $routing_rule['operator'], $source_field, $routing_rule, $form);
     }
     gravity_flow()->log_debug(__METHOD__ . '(): is_match:' . print_r($is_value_match, true));
     return $is_value_match;
 }
Exemple #8
0
    public static function evaluate_conditional_logic($logic, $form, $lead) {

        if(!$logic || !is_array(rgar($logic,"rules")))
            return true;

        $entry_meta_keys = array_keys(GFFormsModel::get_entry_meta($form["id"]));
        $match_count = 0;
        if(is_array($logic["rules"])){
            foreach($logic["rules"] as $rule) {

                if (in_array($rule["fieldId"], $entry_meta_keys)){
                        $is_value_match = GFFormsModel::is_value_match(rgar($lead,$rule["fieldId"]), $rule["value"], $rule["operator"]);;
                } else {
                    $source_field = GFFormsModel::get_field($form, $rule["fieldId"]);
                    $field_value = empty($lead) ? GFFormsModel::get_field_value($source_field, array()) : GFFormsModel::get_lead_field_value($lead, $source_field);
                    $is_value_match = GFFormsModel::is_value_match($field_value, $rule["value"], $rule["operator"], $source_field);
                }

                if($is_value_match)
                    $match_count++;

            }
        }

        $do_action = ($logic["logicType"] == "all" && $match_count == sizeof($logic["rules"]) ) || ($logic["logicType"] == "any"  && $match_count > 0);
        return $do_action;
    }
Exemple #9
0
 public function get_field_value($field)
 {
     $field_values = $submitted_values = false;
     if (isset($_GET['gf_token'])) {
         $incomplete_submission_info = GFFormsModel::get_incomplete_submission_values($_GET['gf_token']);
         if ($incomplete_submission_info['form_id'] == $field['formId']) {
             $submission_details_json = $incomplete_submission_info['submission'];
             $submission_details = json_decode($submission_details_json, true);
             $submitted_values = $submission_details['submitted_values'];
             $field_values = $submission_details['field_values'];
         }
     }
     if (is_array($submitted_values)) {
         $value = $submitted_values[$field->id];
     } else {
         $value = GFFormsModel::get_field_value($field, $field_values);
     }
     $choices = (array) rgar($field, 'choices');
     // if value is not available from post or prepop, check the choices (if field has choices)
     if (!$value && !empty($choices)) {
         $values = array();
         $index = 1;
         foreach ($choices as $choice) {
             if ($index % 10 == 0) {
                 $index++;
             }
             if ($choice['isSelected']) {
                 $full_input_id = sprintf('%d.%d', $field['id'], $index);
                 $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                 $choice_value = $field['type'] == 'product' ? sprintf('%s|%s', $choice['value'], $price) : $choice['value'];
                 $values[$full_input_id] = $choice_value;
             }
             $index++;
         }
         $input_type = GFFormsModel::get_input_type($field);
         // if no choice is preselected and this is a select, get the first choice's value since it will be selected by default in the browser
         if (empty($values) && $input_type == 'select') {
             $values[] = rgars($choices, '0/value');
         }
         switch ($input_type) {
             case 'multiselect':
                 $value = implode(',', $values);
                 break;
             case 'checkbox':
                 $value = $values;
                 break;
             default:
                 $value = reset($values);
                 break;
         }
     }
     return $value;
 }
    /**
     * @param $form
     * @param $entry
     * @param bool|false $allow_display_empty_fields
     * @param array $editable_fields
     * @param Gravity_Flow_Step|null $current_step
     */
    public static function entry_detail_grid($form, $entry, $allow_display_empty_fields = false, $editable_fields = array(), $current_step = null)
    {
        $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 = (bool) apply_filters('gravityflow_entry_detail_grid_display_empty_fields', $display_empty_fields, $form, $entry);
        $condtional_logic_enabled = $current_step && $current_step->conditional_logic_editable_fields_enabled;
        self::register_form_init_scripts($form, array(), $condtional_logic_enabled);
        if (apply_filters('gform_init_scripts_footer', false)) {
            add_action('wp_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'), 20);
            add_action('gform_preview_footer', create_function('', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');'));
        } else {
            echo GFFormDisplay::get_form_init_scripts($form);
            $current_page = 1;
            $scripts = "<script type='text/javascript'>" . apply_filters('gform_cdata_open', '') . " jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [{$form_id}, {$current_page}]) } ); " . apply_filters('gform_cdata_close', '') . '</script>';
            echo $scripts;
        }
        ?>

		<input type="hidden" name="action" id="action" value="" />
			<input type="hidden" name="save" id="action" value="Update" />
		<input type="hidden" name="screen_mode" id="screen_mode" value="<?php 
        echo esc_attr(rgpost('screen_mode'));
        ?>
" />

		<table cellspacing="0" class="widefat fixed entry-detail-view">
			<thead>
			<tr>
				<th id="details">
					<?php 
        $title = sprintf('%s : %s %s', esc_html($form['title']), __('Entry # ', 'gravityflow'), absint($entry['id']));
        echo apply_filters('gravityflow_title_entry_detail', $title, $form, $entry);
        ?>
				</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', 'gravityflow');
            ?>
</label>
					<?php 
        }
        ?>
				</th>
			</tr>
			</thead>
			<tbody class="<?php 
        echo GFCommon::get_ul_classes($form);
        ?>
">
			<?php 
        $count = 0;
        $field_count = sizeof($form['fields']);
        $has_product_fields = false;
        $display_fields_mode = $current_step ? $current_step->display_fields_mode : 'all_fields';
        $display_fields_selected = $current_step && is_array($current_step->display_fields_selected) ? $current_step->display_fields_selected : array();
        foreach ($form['fields'] as &$field) {
            /* @var GF_Field $field */
            $display_field = true;
            if ($display_fields_mode == 'selected_fields') {
                if (!in_array($field->id, $display_fields_selected)) {
                    $display_field = false;
                }
            } else {
                if (GFFormsModel::is_field_hidden($form, $field, array(), $entry)) {
                    $display_field = false;
                }
            }
            $display_field = (bool) apply_filters('gravityflow_workflow_detail_display_field', $display_field, $field, $form, $entry, $current_step);
            switch (RGFormsModel::get_input_type($field)) {
                case 'section':
                    if (!GFCommon::is_section_empty($field, $form, $entry) || $display_empty_fields) {
                        $count++;
                        $is_last = $count >= $field_count ? true : false;
                        ?>
							<tr>
								<td colspan="2" class="entry-view-section-break<?php 
                        echo $is_last ? ' lastrow' : '';
                        ?>
"><?php 
                        echo esc_html(rgar($field, 'label'));
                        ?>
</td>
							</tr>
						<?php 
                    }
                    break;
                case 'captcha':
                case 'password':
                case 'page':
                    //ignore captcha, password, page field
                    break;
                case 'html':
                    if ($display_field) {
                        ?>
							<tr>
								<td colspan="2" class="entry-view-field-value"><?php 
                        echo $field->content;
                        ?>
</td>
							</tr>
							<?php 
                    }
                    break;
                default:
                    $field_id = $field->id;
                    if (in_array($field_id, $editable_fields)) {
                        if ($current_step->conditional_logic_editable_fields_enabled) {
                            $field->conditionalLogicFields = GFFormDisplay::get_conditional_logic_fields($form, $field->id);
                        }
                        if (GFCommon::is_product_field($field->type)) {
                            $has_product_fields = true;
                        }
                        $posted_step_id = rgpost('step_id');
                        if ($posted_step_id == $current_step->get_id()) {
                            $value = GFFormsModel::get_field_value($field);
                        } else {
                            $value = GFFormsModel::get_lead_field_value($entry, $field);
                            if ($field->get_input_type() == 'email' && $field->emailConfirmEnabled) {
                                $_POST['input_' . $field->id . '_2'] = $value;
                            }
                        }
                        if ($field->get_input_type() == 'fileupload') {
                            $field->_is_entry_detail = true;
                        }
                        $content = self::get_field_content($field, $value, $form, $entry);
                        $content = apply_filters('gform_field_content', $content, $field, $value, $entry['id'], $form['id']);
                        $content = apply_filters('gravityflow_field_content', $content, $field, $value, $entry['id'], $form['id']);
                        echo $content;
                    } else {
                        //$field->conditionalLogic = null;
                        if (!$display_field) {
                            continue;
                        }
                        if (GFCommon::is_product_field($field->type)) {
                            $has_product_fields = true;
                        }
                        $value = RGFormsModel::get_lead_field_value($entry, $field);
                        $conditional_logic_fields = GFFormDisplay::get_conditional_logic_fields($form, $field->id);
                        if (!empty($conditional_logic_fields)) {
                            $field->conditionalLogicFields = $conditional_logic_fields;
                            $field_input = self::get_field_input($field, $value, $entry['id'], $form_id, $form);
                            echo '<div style="display:none;"">' . $field_input . '</div>';
                        }
                        if ($field->type == 'product') {
                            if ($field->has_calculation()) {
                                $product_name = trim($value[$field->id . '.1']);
                                $price = trim($value[$field->id . '.2']);
                                $quantity = trim($value[$field->id . '.3']);
                                if (empty($product_name)) {
                                    $value[$field->id . '.1'] = $field->get_field_label(false, $value);
                                }
                                if (empty($price)) {
                                    $value[$field->id . '.2'] = '0';
                                }
                                if (empty($quantity)) {
                                    $value[$field->id . '.3'] = '0';
                                }
                            }
                        }
                        $input_type = $field->get_input_type();
                        if ($input_type == 'hiddenproduct') {
                            $display_value = $value[$field->id . '.2'];
                        } else {
                            $display_value = GFCommon::get_lead_field_display($field, $value, $entry['currency']);
                        }
                        $display_value = apply_filters('gform_entry_field_value', $display_value, $field, $entry, $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(rgar($field, 'label')) . '</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, $entry['id'], $form['id']);
                            $content = apply_filters('gravityflow_field_content', $content, $field, $value, $entry['id'], $form['id']);
                            echo $content;
                        }
                    }
                    break;
            }
        }
        $products = array();
        if ($has_product_fields) {
            $products = GFCommon::get_product_fields($form, $entry);
            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', 'gravityflow'), $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', 'gravityflow'), $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', 'gravityflow'), $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', 'gravityflow'), $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', 'gravityflow'), $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, $entry['currency']);
                    ?>
</td>
										<td><?php 
                    echo GFCommon::to_money($subtotal, $entry['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'], $entry['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', 'gravityflow');
                ?>
</td>
									<td class="grandtotal_amount"><?php 
                echo GFCommon::to_money($total, $entry['currency']);
                ?>
</td>
								</tr>
								</tfoot>
							</table>
						</td>
					</tr>

				<?php 
            }
        }
        ?>
			</tbody>
		</table>
		<div class="gform_footer">
			<input type="hidden" name="gform_unique_id" value="" />
			<input type="hidden" name="is_submit_<?php 
        echo $form_id;
        ?>
" value="1" />
			<input type="hidden" name="step_id" value="<?php 
        echo $current_step ? $current_step->get_id() : '';
        ?>
" />
			<?php 
        if (GFCommon::has_multifile_fileupload_field($form) || !empty(GFFormsModel::$uploaded_files[$form_id])) {
            $files = !empty(GFFormsModel::$uploaded_files[$form_id]) ? GFCommon::json_encode(GFFormsModel::$uploaded_files[$form_id]) : '';
            $files_input = "<input type='hidden' name='gform_uploaded_files' id='gform_uploaded_files_{$form_id}' value='" . str_replace("'", '&#039;', $files) . "' />";
            echo $files_input;
        }
        //GFFormDisplay::print_form_scripts( $form, false );
        ?>
		</div>

	<?php 
    }