public function fix()
 {
     if ($this->can_fix()) {
         $forms = GFAPI::get_forms();
         foreach ($forms as $form) {
             $form['enableHoneypot'] = 1;
             GFAPI::update_form($form);
         }
     }
     return $this->run();
 }
 public static function getIdOfMusicDB_Helper()
 {
     $create_competition_form_name = 'ARIA: Create a Competition';
     $create_competition_form_id = NULL;
     $all_active_forms = GFAPI::get_forms();
     foreach ($all_active_forms as $form) {
         if ($form['title'] === $create_competition_form_name) {
             $create_competition_form_id = $form['id'];
         }
     }
     if (!isset($create_competition_form_id)) {
         $create_competition_form_id = -1;
     }
     return $create_competition_form_id;
 }
예제 #3
0
/**
 * This function will find the ID of the form used as the NNMTA music database.
 *
 * This function will iterate through all of the active form objects and return the
 * ID of the form that is used to store all NNMTA music.
 *
 * @since 1.0.0
 * @author KREW
 */
function aria_get_nnmta_database_form_id()
{
    $nnmta_music_database_form_name = 'NNMTA Music Database';
    $nnmta_music_database_form_id = NULL;
    $all_active_forms = GFAPI::get_forms();
    foreach ($all_active_forms as $form) {
        if ($form['title'] === $nnmta_music_database_form_name) {
            $nnmta_music_database_form_id = $form['id'];
        }
    }
    if (!isset($nnmta_music_database_form_id)) {
        wp_die('Form ' . $nnmta_music_database_form_name . ' does not exist. Please create it and try again.');
    }
    return $nnmta_music_database_form_id;
}
/**
 * This function will run on the activation of this plugin.
 *
 * This function is responsible for performing all necessary actions when activated. For
 * example, this function will check to see if a form already exists for creating new
 * music competitions. If no such form exists, this function will create a new form
 * designed specifically for creating new music competitions.
 *
 * @since 1.0.0
 * @author KREW
 */
function aria_create_competition_activation()
{
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
    if (is_plugin_active('gravityforms/gravityforms.php')) {
        $forms = GFAPI::get_forms();
        $create_competition_form_id = aria_get_create_competition_form_id();
        // if the form for creating music competitions does not exist, create a new form
        if ($create_competition_form_id === -1) {
            aria_create_competition_form();
        }
    } else {
        $error_message = 'Error: The Gravity Forms plugin is not active. Please activate';
        $error_message .= ' the Gravity Forms plugin and reactivate this plugin.';
        wp_die($error_message);
    }
}
예제 #5
0
 public function register_strings()
 {
     if (!class_exists('GFAPI') || !function_exists('pll_register_string')) {
         return;
     }
     $forms = GFAPI::get_forms();
     foreach ($forms as $form) {
         $this->form = $form;
         $this->iterate_form($form, function ($value, $key) {
             $name = '';
             // todo: suitable naming
             $group = "Form #{$this->form['id']}: {$this->form['title']}";
             pll_register_string($name, $value, $group);
             $this->registered_strings[] = $value;
         });
     }
 }
 /**
  * Get the settings need to Gravity Forms.
  */
 public static function get_settings()
 {
     // If the gforms plugin is not active.
     if (!class_exists('GFWebAPI')) {
         return false;
     }
     $settings = get_option('gravityformsaddon_gravityformswebapi_settings');
     // If the API is not enabled.
     if (empty($settings) || !$settings['enabled']) {
         return false;
     }
     $forms = [];
     $method = 'GET';
     $expires = strtotime(self::SIGNATURE_EXPIRY);
     foreach (\GFAPI::get_forms() as $form) {
         $get_form_route = 'forms/' . $form['id'];
         $string_to_sign = sprintf('%s:%s:%s:%s', $settings['public_key'], $method, $get_form_route, $expires);
         $forms[$form['id']] = ['get_form' => ['route' => $get_form_route, 'expires' => $expires, 'signature' => self::calculate_signature($string_to_sign, $settings['private_key'])], 'post_submission' => ['route' => 'forms/' . $form['id'] . '/submissions']];
     }
     return ['api_base' => GFWEBAPI_API_BASE_URL, 'api_key' => $settings['public_key'], 'forms' => $forms];
 }
 /**
  * @since 1.15
  * @covers GravityView_Uninstall::fire_everything()
  */
 function test_fire_everything()
 {
     $create_count = 10;
     $form = $this->factory->form->create_and_get();
     $all_forms = GFAPI::get_forms();
     $views = $this->factory->view->create_many($create_count, array('form_id' => $form['id']));
     $entry_ids = $this->factory->entry->create_many($create_count, array('form_id' => $form['id']));
     $connected = gravityview_get_connected_views($form['id']);
     $entry_count = GFAPI::count_entries($form['id']);
     // Make sure the objects were created and connected
     $this->assertEquals($create_count, count(array_filter($views)));
     $this->assertEquals($create_count, count(array_filter($connected)));
     $this->assertEquals($create_count, count(array_filter($entry_ids)));
     $this->_set_up_expected_options();
     ### DO NOT DELETE WHEN THE USER DOESN'T HAVE THE CAPABILITY
     $user = $this->factory->user->create_and_set(array('user_login' => 'administrator', 'user_pass' => 'administrator', 'role' => 'administrator'));
     $this->assertTrue(GVCommon::has_cap('gravityview_uninstall'));
     ### DO NOT DELETE WHEN IT IS NOT SET OR SET TO FALSE
     // TRY deleting when the settings aren't configured.
     $this->_set_up_gravityview_settings(NULL);
     $this->uninstall();
     $this->_check_deleted_options(false);
     // TRY deleting when the Delete setting is set to No
     $this->_set_up_gravityview_settings('0');
     $this->uninstall();
     $this->_check_deleted_options(false);
     ### REALLY DELETE NOW
     // Create the items
     $this->_set_up_gravityview_settings('delete');
     $this->_set_up_notes($entry_ids);
     $this->_set_up_entry_meta($entry_ids, $form);
     $this->uninstall();
     // No Forms should be deleted
     $this->assertEquals($all_forms, GFAPI::get_forms());
     $this->_check_posts();
     $this->_check_entries($form, $entry_count);
     $this->_check_deleted_options();
     $this->_check_deleted_entry_notes($entry_ids);
     $this->_check_deleted_entry_meta($entry_ids);
 }
예제 #8
0
function aria_activation_func()
{
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
    if (is_plugin_active('gravityforms/gravityforms.php')) {
        aria_create_teacher_form("Sample Created");
        aria_create_student_form("Sample Created");
        // Get all forms from gravity forms
        $forms = GFAPI::get_forms();
        // Set the form index of the Competition Creation Form.
        $competition_creation_form_title = "ARIA: Create a Competition";
        $index = -1;
        // Loop through each form to see if the form was previously created.
        foreach ($forms as $form) {
            if ($form['title'] == "ARIA: Create a Competition") {
                $index = $form['id'];
            }
        }
        // form does not exist; create new form
        if ($index == -1) {
            $result = aria_create_competition_form();
        }
    }
}
예제 #9
0
 public function upgrade($previous_version)
 {
     if (version_compare($previous_version, '1.0.5') == -1) {
         $forms = GFAPI::get_forms(true);
         foreach ($forms as $form) {
             $entries = GFAPI::get_entries($form['id']);
             $fields = GFAPI::get_fields_by_type($form, 'repeater');
             foreach ($entries as $entry) {
                 foreach ($fields as $field) {
                     if (array_key_exists($field['id'], $entry)) {
                         $dataArray = GFFormsModel::unserialize($entry[$field['id']]);
                         $dataUpdated = false;
                         if (!is_array($dataArray)) {
                             continue;
                         }
                         foreach ($dataArray as $repeaterChildId => $repeaterChild) {
                             foreach ($repeaterChild as $repeatedFieldId => $repeatedField) {
                                 if (!is_array($repeatedField)) {
                                     if ($repeatedField !== '[gfRepeater-section]') {
                                         $dataUpdated = true;
                                         $dataArray[$repeaterChildId][$repeatedFieldId] = array($repeatedField);
                                     }
                                 } elseif (reset($repeatedField) == '[gfRepeater-section]') {
                                     $dataUpdated = true;
                                     $dataArray[$repeaterChildId][$repeatedFieldId] = reset($repeatedField);
                                 }
                             }
                         }
                         if ($dataUpdated) {
                             GFAPI::update_entry_field($entry['id'], $field['id'], maybe_serialize($dataArray));
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Function for returning related forms.
  *
  * This function will return an associative array that maps the titles of
  * the associated forms in a music competition (student, student master,
  * teacher, and teacher master) to their respective form IDs.
  *
  * @param $prepended_title	String	The prepended portion of the competition title.
  *
  * @author KREW
  * @since 1.0.0
  */
 public static function aria_find_related_forms_ids($prepended_title)
 {
     // make sure to get all forms! check this
     $all_forms = GFAPI::get_forms();
     $form_ids = array(self::STUDENT_FORM => null, self::STUDENT_MASTER => null, self::TEACHER_FORM => null, self::TEACHER_MASTER => null);
     $student_form = $prepended_title . " Student Registration";
     $student_master_form = $prepended_title . " Student Master";
     $teacher_form = $prepended_title . " Teacher Registration";
     $teacher_master_form = $prepended_title . " Teacher Master";
     $all_competition_forms = array($student_form, $student_master_form, $teacher_form, $teacher_master_form);
     foreach ($all_forms as $form) {
         switch ($form["title"]) {
             case $student_form:
                 $form_ids[self::STUDENT_FORM] = $form["id"];
                 break;
             case $student_master_form:
                 $form_ids[self::STUDENT_MASTER] = $form["id"];
                 break;
             case $teacher_form:
                 $form_ids[self::TEACHER_FORM] = $form["id"];
                 break;
             case $teacher_master_form:
                 $form_ids[self::TEACHER_MASTER] = $form["id"];
                 break;
             default:
                 break;
         }
     }
     // make sure all forms exist
     foreach ($form_ids as $key => $value) {
         if (!isset($value)) {
             wp_die('Error: The form titled ' . $all_competition_forms[$key] . " does not exist.");
         }
     }
     return $form_ids;
 }
예제 #11
0
    function form_id_box_content()
    {
        $form_id = get_post_meta(get_the_ID(), 'form_id', true);
        $gForms = RGFormsModel::get_forms(null, 'title');
        if (!$gForms) {
            echo '<p>Não encontramos nenhum formulário cadastrado, entre no seu plugin de formulário de contato ou <a href="admin.php?page=gf_new_form">clique aqui para criar um novo.</a></p>';
        } else {
            ?>
		    	<div class="rd-select-form">
			        <select name="form_id">
			            <option value=""> </option>
			            <?php 
            foreach ($gForms as $gForm) {
                echo "<option value=" . $gForm->id . selected($form_id, $gForm->id, false) . ">" . $gForm->title . "</option>";
            }
            ?>
			        </select>
			    </div>
		    <?php 
            $gf_forms = GFAPI::get_forms();
            $form_map = get_post_meta(get_the_ID(), 'gf_mapped_fields', true);
            foreach ($gf_forms as $form) {
                if ($form['id'] == $form_id) {
                    echo '<h4>Como os campos abaixo irão se chamar no RD Station?</h4>';
                    foreach ($form['fields'] as $field) {
                        if (!empty($form_map[$field['id']])) {
                            $value = $form_map[$field['id']];
                        } else {
                            $value = '';
                        }
                        echo '<p class="rd-fields-mapping"><span class="rd-fields-mapping-label">' . $field['label'] . '</span> <span class="dashicons dashicons-arrow-right-alt"></span> <input type="text" name="gf_mapped_fields[' . $field['id'] . ']" value="' . $value . '">';
                    }
                }
            }
        }
    }
 /**
  * Upgrading functions
  * 
  * @since 1.5.0
  */
 public function upgrade($previous_version)
 {
     // If the version is below 1.5.0, we need to move the form specific settings
     if (version_compare($previous_version, "1.5.0") == -1) {
         $forms = GFAPI::get_forms(true);
         foreach ($forms as $form) {
             $this->upgrade_old_form_settings($form);
         }
     }
     // If the version is below 1.6.0, we need to convert any form settings to a feed
     if (version_compare($previous_version, "1.6.0") == -1) {
         $forms = GFAPI::get_forms(true);
         foreach ($forms as $form) {
             $this->upgrade_settings_to_feed($form);
         }
     }
 }
예제 #13
0
 /**
  * Returns the list of available forms
  *
  * @access public
  * @param mixed $form_id
  * @return array Empty array if GFAPI isn't available or no forms. Otherwise, associative array with id, title keys
  */
 public static function get_forms()
 {
     $forms = array();
     if (class_exists('GFAPI')) {
         $gf_forms = GFAPI::get_forms();
         foreach ($gf_forms as $form) {
             $forms[] = array('id' => $form['id'], 'title' => $form['title']);
         }
     }
     return $forms;
 }
예제 #14
0
 /**
  * Register Gravity Forms with Polylang.
  *
  * @used-by Actions\"init"
  */
 public function wp_init()
 {
     $forms = GFAPI::get_forms();
     if (is_array($forms)) {
         foreach ($forms as $form) {
             $this->register_strings($form);
         }
     }
 }
 public function app_settings_fields()
 {
     $forms = GFAPI::get_forms();
     $choices = array();
     foreach ($forms as $form) {
         $form_id = absint($form['id']);
         $feeds = $this->get_feeds($form_id);
         if (!empty($feeds)) {
             $choices[] = array('label' => esc_html($form['title']), 'name' => 'publish_form_' . absint($form['id']));
         }
     }
     if (!empty($choices)) {
         $published_forms_fields = array(array('name' => 'form_ids', 'label' => esc_html__('Published', 'gravityflow'), 'type' => 'checkbox', 'choices' => $choices));
     } else {
         $published_forms_fields = array(array('name' => 'no_workflows', 'label' => '', 'type' => 'html', 'html' => esc_html__('No workflow steps have been added to any forms yet.', 'gravityflow')));
     }
     $settings = array();
     if (!is_multisite() || is_multisite() && is_main_site() && !defined('GRAVITY_FLOW_LICENSE_KEY')) {
         $settings[] = array('title' => esc_html__('Settings', 'gravityflow'), 'fields' => array(array('name' => 'license_key', 'label' => esc_html__('License Key', 'gravityflow'), 'type' => 'text', 'validation_callback' => array($this, 'license_validation'), 'feedback_callback' => array($this, 'license_feedback'), 'error_message' => __('Invalid license', 'gravityflow'), 'class' => 'large', 'default_value' => ''), array('name' => 'background_updates', 'label' => esc_html__('Background Updates', 'gravityflow'), 'tooltip' => __('Set this to ON to allow Gravity Flow to download and install bug fixes and security updates automatically in the background. Requires a valid license key.', 'gravityflow'), 'type' => 'radio', 'horizontal' => true, 'default_value' => false, 'choices' => array(array('label' => __('On', 'gravityflow'), 'value' => true), array('label' => __('Off', 'gravityflow'), 'value' => false)))));
     }
     $settings[] = array('title' => esc_html__('Published Workflow Forms', 'gravityflow'), 'description' => esc_html__('Select the forms you wish to publish on the Submit page.', 'gravityflow'), 'fields' => $published_forms_fields);
     $settings[] = array('id' => 'save_button', 'fields' => array(array('id' => 'save_button', 'name' => 'save_button', 'type' => 'save', 'value' => __('Update Settings', 'gravityflow'), 'messages' => array('success' => __('Settings updated successfully', 'gravityflow'), 'error' => __('There was an error while saving the settings', 'gravityflow')))));
     return $settings;
 }
예제 #16
0
function mf_sidebar_dup($form_id, $lead)
{
    // Load Fields to show on entry info
    $forms = GFAPI::get_forms(true, false);
    echo '<h4><label class="detail-label" for="entry_form_copy">Duplicate/Copy Entry ID ' . $lead['id'] . '</label></h4>';
    echo 'Into Form:<br/>';
    echo '<select style="width:250px" name="entry_form_copy">';
    foreach ($forms as $choice) {
        $selected = '';
        if ($choice['id'] == $form_id) {
            $selected = ' selected ';
        }
        echo '<option ' . $selected . ' value="' . $choice['id'] . '">' . $choice['title'] . '</option>';
    }
    echo '</select><Br/><br/><input type="submit" name="duplicate_entry_id" value="Duplicate Entry" class="button"
	 style="width:auto;padding-bottom:2px;"
	 onclick="jQuery(\'#action\').val(\'duplicate_entry_id\');"/><br />';
}
function cfp_opinionshare_gform_field()
{
    $options = get_option('cfp_opinionshare_options');
    if ($options['cfp_opinionshare_gformchk_0'] == 1) {
        if (class_exists("GFForms")) {
            GFForms::include_addon_framework();
            $forms = GFAPI::get_forms();
            $i = 0;
            $f = 0;
            if (count($forms) != 0) {
                echo '<select name="cfp_opinionshare_options[cfp_opinionshare_gform_0]">';
                foreach ($forms as $form) {
                    // echo '<pre>';
                    // print_r($form);
                    // echo '</pre>';
                    // echo $form[title].' - '.$form[id].'<br/>';
                    echo '<option value="' . $form[id] . '" ' . selected($options['cfp_opinionshare_gform_0'], $form[id], false) . '>' . $form[title] . '</option>';
                }
                echo '</select>';
            } else {
                echo 'No Forms Found';
            }
        } else {
            echo '<p><span class="dashicons dashicons-warning"></span> <strong class="red">Please install Gravity Forms</strong></p><p>Opinion Share uses Gravity Forms to provide feedback as to why your customer was unhappy with their service. Please install <a href="http://www.gravityforms.com/">Gravity Forms</a>.';
        }
    } else {
        $authorbox = isset($options['authorbox_template']) ? $options['authorbox_template'] : '';
        $authorbox = esc_textarea($authorbox);
        //sanitise output
        $settings = array('textarea_name' => 'cfp_opinionshare_options[authorbox_template]');
        wp_editor($authorbox, 'right_editor', $settings);
    }
}
    /**
     * Registers the Blog Admin Page.
     *
     * @return void
     */
    function display_settings_Admin_GForms_TMP()
    {
        $unauthorized = false;
        if (!current_user_can('manage_options')) {
            $unauthorized = __('You do not have sufficient permissions to edit these settings.');
        }
        if ($unauthorized) {
            echo "<p>{$unauthorized}</p>\n";
            return;
        }
        $this->print_notices_Admin_GForms_TMP();
        $is_multisite = is_multisite();
        $is_token_authorized = $this->is_api_authorized_GForms_TMP();
        $this->display_auth_Admin_GForms_TMP();
        if ($is_token_authorized) {
            $gforms_tmp_admin_client_name = get_option('gforms_tmp_admin_client_name', false);
            $gforms_tmp_admin_client_id = get_option('gforms_tmp_admin_client_id', false);
            $gforms_tmp_active = get_option('gforms_tmp_active', false);
            $gforms_tmp_last_update = get_option('gforms_tmp_last_update', false);
            $gforms_tmp_admin_forms = get_option('gforms_tmp_admin_forms', array());
            $gforms = GFAPI::get_forms();
            $date = 'Y/m/d g:i:s a';
            ?>
<hr />

<h2><?php 
            echo __('Lead Client Settings', 'gforms-tmp');
            ?>
</h2>

<br />

<form method="post" action="<?php 
            echo admin_url('admin.php');
            ?>
">

            <?php 
            wp_nonce_field('gforms-tmp-edit-settings');
            ?>

            <input type="hidden" name="action"
		value="settings_update_admin_gforms_tmp" /> <input type="hidden"
		id="is_token_authorized"
		value="<?php 
            echo $is_token_authorized ? 1 : 0;
            ?>
" />

	<table class="form-table">

		<tr>

			<th scope="row"><?php 
            _e('Lead Client Name');
            ?>
</th>

			<td><input type="text" name="gforms_tmp_admin_client_name"
				id="gforms_tmp_admin_client_name"
				value="<?php 
            echo esc_attr($gforms_tmp_admin_client_name);
            ?>
"
				class="regular-text" size="33" /></td>

		</tr>

		<tr>

			<th scope="row"><?php 
            _e('Account ID');
            ?>
</th>

			<td><input type="text" name="gforms_tmp_admin_client_id"
				id="gforms_tmp_admin_client_id"
				value="<?php 
            echo $gforms_tmp_admin_client_id;
            ?>
" size="4"
				style="width: 50px;" /></td>

		</tr>

		<tr>
			<th scope="row"><?php 
            _e('Enable Plugin');
            ?>
</th>

			<td><label> <input type="checkbox" name="gforms_tmp_active"
					id="gforms_tmp_active" value="1"
					<?php 
            checked((bool) $gforms_tmp_active && $gforms_tmp_admin_client_id, true);
            ?>
					<?php 
            disabled((bool) $gforms_tmp_admin_client_id && $is_token_authorized, false);
            ?>
					title="<?php 
            echo (!$is_token_authorized ? "Plugin disabled until it has been authorized. " : "") . (!$gforms_tmp_admin_client_id ? "Enter Client ID." : "");
            ?>
" />
			</label><br /></td>

		</tr>

		<tr>

			<th scope="row"><?php 
            _e('Select Active GravityForm(s)');
            ?>
</th>

			<td><select id="gforms_tmp_admin_forms"
				name="gforms_tmp_admin_forms[]" multiple="multiple"
				style="min-width: 200px;">
					<option value=""><?php 
            esc_html_e('Use all forms', 'gforms-tmp');
            ?>
</option>
                            <?php 
            foreach ($gforms as $gform) {
                $selected = in_array($gform["id"], $gforms_tmp_admin_forms) ? ' selected="selected" ' : '';
                ?>
                                <option
						value="<?php 
                echo absint($gform["id"]);
                ?>
"
						<?php 
                echo $selected;
                ?>
><?php 
                echo esc_html($gform["title"]);
                ?>
</option>
                                <?php 
            }
            ?>
                        </select></td>

		</tr>

		<tr>

			<th scope="row"><?php 
            _e('Last Updated');
            ?>
</th>

			<td><label><?php 
            echo !$gforms_tmp_last_update ? __('Never') : mysql2date($date, date('Y-m-d h:i:s', $gforms_tmp_last_update));
            ?>
</label>

				<input name="gforms_tmp_last_update" type="hidden"
				id="gforms_tmp_last_update"
				value="<?php 
            echo $gforms_tmp_last_update;
            ?>
" /></td>

		</tr>

	</table>

            <?php 
            submit_button();
            ?>

        </form>



<script type="text/javascript">
			jQuery(document).ready(function($) {

				$('#gforms_tmp_admin_client_id').on('blur', function(e) {

					var hints = $.map($('#gforms_tmp_active').prop("title").split("."), $.trim);

					var idx = hints.indexOf("Enter Account ID");

					if (!$(this).val()) {

						$('#gforms_tmp_active').addClass('disabled').attr("disabled", "disabled").removeAttr("checked");

						if (idx < 0) {
							hints.push("Enter Account ID");
						}

					} else if ("1" == $("#is_token_authorized").val()) {

						$('#gforms_tmp_active').removeClass('disabled').removeAttr("disabled");

						if (idx >= 0) {
							hints.splice(idx, 1);
						}

					}

					$('#gforms_tmp_active').prop("title", hints.join(". "));

				});

			});

        </script>

<?php 
        }
    }
 function get_multi_entry_enabled()
 {
     $enabled_ids = array();
     $forms = GFAPI::get_forms();
     foreach ($forms as $form) {
         $forms_settings = $this->get_form_settings($form);
         if (!empty($forms_settings) && $forms_settings['enabled'] == 1) {
             $enabled_ids[] = $form['id'];
         }
     }
     return $enabled_ids;
 }
예제 #20
0
 private static function get_field_filters_where($form_id, $search_criteria)
 {
     global $wpdb;
     $field_filters = rgar($search_criteria, "field_filters");
     $search_operator = self::get_search_operator($search_criteria);
     if (empty($field_filters)) {
         return false;
     }
     unset($field_filters["mode"]);
     $sql_array = array();
     $lead_details_table_name = GFFormsModel::get_lead_details_table_name();
     $lead_meta_table_name = GFFormsModel::get_lead_meta_table_name();
     if (is_array($form_id)) {
         $in_str_arr = array_fill(0, count($form_id), '%s');
         $in_str = esc_sql(join(",", $in_str_arr));
         $form_id_where = $wpdb->prepare("AND form_id IN ({$in_str})", $form_id);
     } else {
         $form_id_where = $form_id > 0 ? $wpdb->prepare("AND form_id=%d", $form_id) : "";
     }
     $info_column_keys = self::get_lead_db_columns();
     $entry_meta = self::get_entry_meta(is_array($form_id) ? 0 : $form_id);
     array_push($info_column_keys, "id");
     foreach ($field_filters as $search) {
         $key = rgar($search, "key");
         if ("entry_id" === $key) {
             $key = "id";
         }
         if (in_array($key, $info_column_keys)) {
             continue;
         }
         $val = rgar($search, "value");
         $operator = isset($search["operator"]) ? strtolower($search["operator"]) : "=";
         if ("is" == $operator) {
             $operator = "=";
         }
         if ("isnot" == $operator) {
             $operator = "<>";
         }
         if ("contains" == $operator) {
             $operator = "like";
         }
         $search_term = "like" == $operator ? "%{$val}%" : $val;
         $search_type = rgar($search, "type");
         if (empty($search_type)) {
             if (empty($key)) {
                 $search_type = "global";
             } elseif (is_numeric($key)) {
                 $search_type = "field";
             } else {
                 $search_type = "meta";
             }
         }
         switch ($search_type) {
             case "field":
                 $upper_field_number_limit = (string) (int) $key === $key ? (double) $key + 0.9999 : (double) $key + 0.0001;
                 /* doesn't support "<>" for checkboxes */
                 $field_query = $wpdb->prepare("\n                        l.id IN\n                        (\n                        SELECT\n                        lead_id\n                        from {$lead_details_table_name}\n                        WHERE (field_number BETWEEN %s AND %s AND value {$operator} %s)\n                        {$form_id_where}\n                        )", (double) $key - 0.0001, $upper_field_number_limit, $search_term);
                 if (empty($val) || "%%" === $val || "<>" === $operator) {
                     $skipped_field_query = $wpdb->prepare("\n                            l.id NOT IN\n                            (\n                            SELECT\n                            lead_id\n                            from {$lead_details_table_name}\n                            WHERE (field_number BETWEEN %s AND %s)\n                            {$form_id_where}\n                            )", (double) $key - 0.0001, $upper_field_number_limit, $search_term);
                     $field_query = "(" . $field_query . " OR " . $skipped_field_query . ")";
                 }
                 $sql_array[] = $field_query;
                 /*
                 //supports "<>" for checkboxes but it doesn't scale
                 $sql_array[] = $wpdb->prepare("l.id IN
                                 (SELECT lead_id
                                 FROM
                                     (
                                         SELECT lead_id, value
                                         FROM $lead_details_table_name
                                         WHERE form_id = %d
                                         AND (field_number BETWEEN %s AND %s)
                                         GROUP BY lead_id
                                         HAVING value $operator %s
                                     ) ld
                                 )
                                 ", $form_id, (float)$key - 0.0001, $upper_field_number_limit, $val );
                 */
                 break;
             case "global":
                 // include choice text
                 $forms = array();
                 if ($form_id == 0) {
                     $forms = GFAPI::get_forms();
                 } elseif (is_array($form_id)) {
                     foreach ($form_id as $id) {
                         $forms[] = GFAPI::get_form($id);
                     }
                 } else {
                     $forms[] = GFAPI::get_form($form_id);
                 }
                 $choice_texts_clauses = array();
                 foreach ($forms as $form) {
                     if (isset($form['fields'])) {
                         $choice_texts_clauses_for_form = array();
                         foreach ($form['fields'] as $field) {
                             $choice_texts_clauses_for_field = array();
                             if (isset($field['choices']) && is_array($field['choices'])) {
                                 foreach ($field['choices'] as $choice) {
                                     if ($operator == '=' && strtolower($choice['text']) == strtolower($val) || $operator == 'like' && strpos(strtolower($choice['text']), strtolower($val)) !== false) {
                                         if (rgar($field, 'gsurveyLikertEnableMultipleRows')) {
                                             $choice_value = '%' . $choice['value'] . '%';
                                             $choice_search_operator = 'like';
                                         } else {
                                             $choice_value = $choice['value'];
                                             $choice_search_operator = '=';
                                         }
                                         $choice_texts_clauses_for_field[] = $wpdb->prepare("field_number BETWEEN %s AND %s AND value {$choice_search_operator} %s", (double) $field['id'] - 0.0001, (double) $field['id'] + 0.9999, $choice_value);
                                     }
                                 }
                             }
                             if (!empty($choice_texts_clauses_for_field)) {
                                 $choice_texts_clauses_for_form[] = join(' OR ', $choice_texts_clauses_for_field);
                             }
                         }
                     }
                     if (!empty($choice_texts_clauses_for_form)) {
                         $choice_texts_clauses[] = '(l.form_id = ' . $form['id'] . ' AND (' . join(' OR ', $choice_texts_clauses_for_form) . ' ))';
                     }
                 }
                 $choice_texts_clause = '';
                 if (!empty($choice_texts_clauses)) {
                     $choice_texts_clause = join(' OR ', $choice_texts_clauses);
                     $choice_texts_clause = "\n\t\t\t\t\t\tl.id IN (\n                        SELECT\n                        lead_id\n                        FROM {$lead_details_table_name}\n                        WHERE {$choice_texts_clause} ) OR ";
                 }
                 $choice_value_clause = $wpdb->prepare("value {$operator} %s", $search_term);
                 $sql_array[] = '(' . $choice_texts_clause . $choice_value_clause . ')';
                 break;
             case "meta":
                 /* doesn't support "<>" for multiple values of the same key */
                 $meta = rgar($entry_meta, $key);
                 $placeholder = rgar($meta, "is_numeric") ? "%s" : "%s";
                 $search_term = "like" == $operator ? "%{$val}%" : $val;
                 $sql_array[] = $wpdb->prepare("\n                        l.id IN\n                        (\n                        SELECT\n                        lead_id\n                        FROM {$lead_meta_table_name}\n                        WHERE meta_key=%s AND meta_value {$operator} {$placeholder}\n                        {$form_id_where}\n                        )", $search["key"], $search_term);
                 break;
         }
     }
     $sql = empty($sql_array) ? "" : join(" " . $search_operator . " ", $sql_array);
     return $sql;
 }
예제 #21
0
    function filters()
    {
        $start_date = isset($_REQUEST['start-date']) ? sanitize_text_field($_REQUEST['start-date']) : null;
        $end_date = isset($_REQUEST['end-date']) ? sanitize_text_field($_REQUEST['end-date']) : null;
        $status = isset($_REQUEST['status']) ? $_REQUEST['status'] : '';
        $filter_form_id = empty($_REQUEST['form-id']) ? '' : absint($_REQUEST['form-id']);
        $filter_entry_id = empty($_REQUEST['entry-id']) ? '' : absint($_REQUEST['entry-id']);
        $field_filters = null;
        $forms = GFAPI::get_forms();
        foreach ($forms as $form) {
            $form_filters = GFCommon::get_field_filter_settings($form);
            $empty_filter = array('key' => '', 'text' => esc_html__('Fields', 'gravityforms'), 'operators' => array());
            array_unshift($form_filters, $empty_filter);
            $field_filters[$form['id']] = $form_filters;
        }
        $search_field_ids = isset($_REQUEST['f']) ? $_REQUEST['f'] : '';
        $search_field_id = $search_field_ids && is_array($search_field_ids) ? $search_field_ids[0] : '';
        $init_field_id = $search_field_id;
        $search_operators = isset($_REQUEST['o']) ? $_REQUEST['o'] : '';
        $search_operator = $search_operators && is_array($search_operators) ? $search_operators[0] : false;
        $init_field_operator = empty($search_operator) ? 'contains' : $search_operator;
        $values = isset($_REQUEST['v']) ? $_REQUEST['v'] : '';
        $value = $values && is_array($values) ? $values[0] : 0;
        $init_filter_vars = array('mode' => 'off', 'filters' => array(array('field' => $init_field_id, 'operator' => $init_field_operator, 'value' => $value)));
        ?>
		<div id="gravityflow-status-filters">

			<div id="gravityflow-status-date-filters">

				<input placeholder="ID" type="text" name="entry-id" id="entry-id" class="small-text"
				       value="<?php 
        echo $filter_entry_id;
        ?>
"/>
				<?php 
        if (empty($this->constraint_filters['start_date'])) {
            ?>
					<label for="start-date"><?php 
            esc_html_e('Start:', 'gravityflow');
            ?>
</label>
					<input type="text" id="start-date" name="start-date" class="datepicker medium-text ymd_dash"
					       value="<?php 
            echo $start_date;
            ?>
" placeholder="yyyy/mm/dd"/>
				<?php 
        }
        ?>

				<?php 
        if (empty($this->constraint_filters['start_date'])) {
            ?>
					<label for="end-date"><?php 
            esc_html_e('End:', 'gravityflow');
            ?>
</label>
					<input type="text" id="end-date" name="end-date" class="datepicker medium-text ymd_dash"
					       value="<?php 
            echo $end_date;
            ?>
" placeholder="yyyy/mm/dd"/>
				<?php 
        }
        ?>
				<?php 
        if (!empty($this->constraint_filters['form_id'])) {
            ?>
					<input type="hidden" name="form-id"
					       value="<?php 
            echo esc_attr($this->constraint_filters['form_id']);
            ?>
">
				<?php 
        } else {
            ?>
					<select id="gravityflow-form-select" name="form-id">
						<?php 
            $selected = selected('', $filter_form_id, false);
            printf('<option value="" %s >%s</option>', $selected, esc_html__('Workflow Form', 'gravityflow'));
            $forms = GFAPI::get_forms();
            foreach ($forms as $form) {
                $form_id = absint($form['id']);
                $steps = gravity_flow()->get_steps($form_id);
                if (!empty($steps)) {
                    $selected = selected($filter_form_id, $form_id, false);
                    printf('<option value="%d" %s>%s</option>', $form_id, $selected, esc_html($form['title']));
                }
            }
            ?>
					</select>
					<div id="entry_filters" style="display:inline-block;"></div>
				<?php 
        }
        ?>

				<input type="submit" class="button-secondary" value="<?php 
        esc_html_e('Apply', 'gravityflow');
        ?>
"/>

				<?php 
        if (!empty($status)) {
            ?>
					<input type="hidden" name="status" value="<?php 
            echo esc_attr($status);
            ?>
"/>
				<?php 
        }
        ?>
				<?php 
        if (!empty($start_date) || !empty($end_date) || !empty($filter_form_id) | !empty($filter_entry_id)) {
            ?>
					<a href="<?php 
            echo esc_url($this->base_url);
            ?>
"
					   class="button-secondary"><?php 
            esc_html_e('Clear Filter', 'gravityflow');
            ?>
</a>
				<?php 
        }
        ?>
			</div>
			<?php 
        $this->search_box(esc_html__('Search', 'gravityflow'), 'gravityflow-search');
        ?>
		</div>

		<script>
			(function ($) {
				$(document).ready(function () {
					var gformFieldFilters = <?php 
        echo json_encode($field_filters);
        ?>
,
						gformInitFilter = <?php 
        echo json_encode($init_filter_vars);
        ?>
;
					var $form_select = $('#gravityflow-form-select');
					var filterFormId = $form_select.val();
					var $entry_filters = $('#entry_filters');
					if (filterFormId) {
						$entry_filters.gfFilterUI(gformFieldFilters[filterFormId], gformInitFilter, false);
						if ($('.gform-filter-field').val() === '') {
							$('.gform-filter-operator').hide();
							$('.gform-filter-value').hide();
						}
					}
					$form_select.change(function () {
						filterFormId = $form_select.val();
						if (filterFormId) {
							$entry_filters.gfFilterUI(gformFieldFilters[filterFormId], gformInitFilter, false);
							$('.gform-filter-field').val('');
							$('.gform-filter-operator').hide();
							$('.gform-filter-value').hide();
						} else {
							$entry_filters.html('');
						}

					});
					$('#entry_filters').on('change', '.gform-filter-field', function () {
						if ($('.gform-filter-field').val() === '') {
							$('.gform-filter-operator').hide();
							$('.gform-filter-value').hide();
						}
					});
				});

			})(jQuery);


		</script>

		<?php 
    }
 public function wp_ajax_gfe_util()
 {
     $criteria = $_POST['criteria'];
     //: Check if criteria exists and is in the correct format ://
     if (!isset($criteria) || empty($criteria) || !is_array($criteria)) {
         die;
     }
     //: Check for non-null method parameter exist ://
     if (!isset($criteria['method']) || empty($criteria['method'])) {
         die;
     }
     //: Check for criteria and set defaults ://
     $start_date = !empty($criteria['start_date']) ? $criteria['start_date'] : date('Y-m-d', 0);
     $end_date = !empty($criteria['end_date']) ? $criteria['end_date'] : current_time('Y-m-d');
     $search_criteria = array('start_date' => sanitize_text_field($start_date), 'end_date' => sanitize_text_field($end_date));
     //: Get form ids if not empty or set to all forms ://
     $forms = !empty($criteria['form_id']) ? array(GFAPI::get_form(sanitize_key($criteria['form_id']))) : GFAPI::get_forms();
     $response = array('criteria' => array('method' => sanitize_key($criteria['method']), 'start_date' => sanitize_text_field($start_date), 'end_date' => sanitize_text_field($end_date)), 'results' => array());
     switch (sanitize_key($criteria['method'])) {
         //: Count entries ://
         case 'count':
             $total_count = 0;
             foreach ($forms as $form) {
                 $entry_count = GFAPI::count_entries($form['id'], $search_criteria);
                 $response['results'][] = array('id' => $form['id'], 'title' => $form['title'], 'entry_count' => $entry_count);
                 $total_count += $entry_count;
             }
             break;
             //: Export Entries ://
         //: Export Entries ://
         case 'export':
             //: Todo ://
             die;
             break;
     }
     wp_send_json($response);
     die;
 }
 private function getMappedForm($leadFormId)
 {
     $gForms = GFAPI::get_forms();
     foreach ($gForms as $gForm) {
         if (isset($gForm['mapped_lead_form']) && is_array($gForm['mapped_lead_form']) && in_array($leadFormId, $gForm['mapped_lead_form'])) {
             return $gForm['id'];
         }
     }
     return null;
 }
예제 #24
0
/**
 * Add a BuddyPress group selector to the Steps UI
 *
 * @since 1.0.0
 *
 * @param integer $step_id The given step's post ID
 * @param integer $post_id The given parent post's post ID
 */
function badgeos_gravityforms_step_etc_select($step_id, $post_id)
{
    $current_trigger = get_post_meta($step_id, '_badgeos_gravityforms_trigger', true);
    $current_object_id = (int) get_post_meta($step_id, '_badgeos_gravityforms_object_id', true);
    $current_object_arg1 = (int) get_post_meta($step_id, '_badgeos_gravityforms_object_arg1', true);
    $current_object_arg2 = get_post_meta($step_id, '_badgeos_gravityforms_object_arg2', true);
    $current_object_arg1 = empty($current_object_arg1) ? '' : $current_object_arg1;
    $current_object_arg2 = empty($current_object_arg2) ? '' : $current_object_arg2;
    // Forms
    echo '<select name="badgeos_gravityforms_form_id" class="select-form-id">';
    echo '<option value="">' . __('Any Form', 'badgeos-gravityforms') . '</option>';
    // Loop through all objects
    $objects = GFAPI::get_forms();
    $field_select = '';
    if (!empty($objects)) {
        foreach ($objects as $object) {
            $selected = '';
            if (in_array($current_trigger, array('gform_after_submission'))) {
                $selected = selected($current_object_id, $object['id'], false);
            }
            echo '<option' . $selected . ' value="' . $object['id'] . '">' . esc_html($object['title']) . '</option>';
        }
    }
    echo '</select>';
    echo '<input name="badgeos_gravityforms_field_id" class="input-field-id" placeholder="Field ID" value="' . $current_object_arg1 . '" />';
    echo '<input name="badgeos_gravityforms_field_value" class="input-field-value" placeholder="Field Value" value="' . $current_object_arg2 . '" />';
    // $field_select = '<select name="badgeos_gravityforms_field_id" class="select-field-id">'
    // 							. '<option value="">' . __( 'Any Field', 'badgeos-gravityforms' )
    // 							. $field_select
    // 							. '</select>';
    // $field_input = '<input name="badgeos_gravityforms_field_value" class="input-field-value">';
    // if ( in_array( $current_trigger, array( 'badgeos_gravityforms_form_completed_specific' ) ) )
    // 	$gffield = (int) $current_object_arg1;
    // if ( empty( $gffield ) )
    // 	$gffield = '';
    // echo '<span><input name="badgeos_gravityforms_form_field" class="input-form-field" type="text" value="' . $gffield . '" size="3" maxlength="3" placeholder="100" />%</span>';
    // // Lessons
    // echo '<select name="badgeos_gravityforms_lesson_id" class="select-lesson-id">';
    // echo '<option value="">' . __( 'Any Lesson', 'badgeos-gravityforms' ) . '</option>';
    // // Loop through all objects
    // $objects = get_posts( array(
    // 	'post_type' => 'gfform-entry',
    // 	'post_status' => 'publish',
    // 	'posts_per_page' => -1
    // ) );
    // if ( !empty( $objects ) ) {
    // 	foreach ( $objects as $object ) {
    // 		$selected = '';
    // 		if ( in_array( $current_trigger, array( 'gravityforms_form_completed' ) ) )
    // 			$selected = selected( $current_object_id, $object->ID, false );
    // 		echo '<option' . $selected . ' value="' . $object->ID . '">' . esc_html( get_the_title( $object->ID ) ) . '</option>';
    // 	}
    // }
    // echo '</select>';
    // // Topics
    // echo '<select name="badgeos_gravityforms_topic_id" class="select-topic-id">';
    // echo '<option value="">' . __( 'Any Topic', 'badgeos-gravityforms' ) . '</option>';
    // // Loop through all objects
    // $objects = get_posts( array(
    // 	'post_type' => 'sfwd-topic',
    // 	'post_status' => 'publish',
    // 	'posts_per_page' => -1
    // ) );
    // if ( !empty( $objects ) ) {
    // 	foreach ( $objects as $object ) {
    // 		$selected = '';
    // 		if ( in_array( $current_trigger, array( 'gravityforms_topic_completed' ) ) )
    // 			$selected = selected( $current_object_id, $object->ID, false );
    // 		echo '<option' . $selected . ' value="' . $object->ID . '">' . esc_html( get_the_title( $object->ID ) ) . '</option>';
    // 	}
    // }
    // echo '</select>';
    // // Courses
    // echo '<select name="badgeos_gravityforms_course_id" class="select-course-id">';
    // echo '<option value="">' . __( 'Any Course', 'badgeos-gravityforms' ) . '</option>';
    // // Loop through all objects
    // $objects = get_posts( array(
    // 	'post_type' => 'sfwd-courses',
    // 	'post_status' => 'publish',
    // 	'posts_per_page' => -1
    // ) );
    // if ( !empty( $objects ) ) {
    // 	foreach ( $objects as $object ) {
    // 		$selected = '';
    // 		if ( in_array( $current_trigger, array( 'gravityforms_course_completed' ) ) )
    // 			$selected = selected( $current_object_id, $object->ID, false );
    // 		echo '<option' . $selected . ' value="' . $object->ID . '">' . esc_html( get_the_title( $object->ID ) ) . '</option>';
    // 	}
    // }
    // echo '</select>';
    // // Course Category
    // echo '<select name="badgeos_gravityforms_course_category_id" class="select-course-category-id">';
    // echo '<option value="">' . __( 'Any Form Tag', 'badgeos-gravityforms' ) . '</option>';
    // // Loop through all objects
    // $objects = get_terms( 'post_tag', array(
    // 	'hide_empty' => false
    // ) );
    // if ( !empty( $objects ) ) {
    // 	foreach ( $objects as $object ) {
    // 		$selected = '';
    // 		if ( in_array( $current_trigger, array( 'badgeos_gravityforms_course_completed_tag' ) ) )
    // 			$selected = selected( $current_object_id, $object->term_id, false );
    // 		echo '<option' . $selected . ' value="' . $object->term_id . '">' . esc_html( $object->name ) . '</option>';
    // 	}
    // }
    // echo '</select>';
}
    /**
     * Displays user custom meta fields.
     *
     * @since v1.0.0
     * @access private
     *
     * @param WP_User $user The currently being edited user.
     */
    function show_extra_profile_fields($user)
    {
        if (!current_user_can('manage_options')) {
            return;
        }
        $roles = $user->roles;
        $user_role = array_shift($roles);
        switch ($user_role) {
            case 'site_section_manager':
                ?>
				<tr>
					<th><label for="site-sections">Site Section(s)</label></th>

					<td>
						<?php 
                $sections = get_posts(array('post_type' => 'page', 'meta_key' => '_rbm_is_section', 'meta_value' => '1', 'posts_per_page' => -1));
                $user_sections = (array) get_user_meta($user->ID, 'site_sections', true);
                if (!empty($sections) && !is_wp_error($sections)) {
                    ?>
							<select name="site_sections[]" id="site-sections" multiple class="rbm-select2"
							        style="max-width: 300px;">
								<?php 
                    foreach ($sections as $section) {
                        ?>
									<option value="<?php 
                        echo $section->ID;
                        ?>
"
										<?php 
                        echo in_array($section->ID, $user_sections) ? 'selected' : '';
                        ?>
>
										<?php 
                        echo get_the_title($section);
                        ?>
									</option>
								<?php 
                    }
                    ?>
							</select>
						<?php 
                }
                ?>
					</td>
				</tr>
				<?php 
                break;
            case 'forms_manager':
                ?>
				<tr>
					<th><label for="user_forms">Form(s)</label></th>

					<td>
						<?php 
                $forms = GFAPI::get_forms();
                $user_forms = (array) get_user_meta($user->ID, 'user_forms', true);
                if (!empty($forms) && !is_wp_error($forms)) {
                    ?>
							<select name="user_forms[]" id="user_forms" multiple class="rbm-select2"
							        style="max-width: 300px;">
								<?php 
                    foreach ($forms as $form) {
                        ?>
									<option value="<?php 
                        echo $form['id'];
                        ?>
"
										<?php 
                        echo in_array($form['id'], $user_forms) ? 'selected' : '';
                        ?>
>
										<?php 
                        echo $form['title'];
                        ?>
									</option>
								<?php 
                    }
                    ?>
							</select>
						<?php 
                }
                ?>
					</td>
				</tr>
				<?php 
                break;
        }
    }
 private static function get_field_filters_where($form_id, $search_criteria)
 {
     global $wpdb;
     $field_filters = rgar($search_criteria, 'field_filters');
     $search_operator = self::get_search_operator($search_criteria);
     if (empty($field_filters)) {
         return false;
     }
     unset($field_filters['mode']);
     $sql_array = array();
     $lead_details_table_name = GFFormsModel::get_lead_details_table_name();
     $lead_meta_table_name = GFFormsModel::get_lead_meta_table_name();
     if (is_array($form_id)) {
         $in_str_arr = array_fill(0, count($form_id), '%d');
         $in_str = join(',', $in_str_arr);
         $form_id_where = $wpdb->prepare("AND form_id IN ({$in_str})", $form_id);
     } else {
         $form_id_where = $form_id > 0 ? $wpdb->prepare('AND form_id=%d', $form_id) : '';
     }
     $info_column_keys = self::get_lead_db_columns();
     $entry_meta = self::get_entry_meta(is_array($form_id) ? 0 : $form_id);
     array_push($info_column_keys, 'id');
     foreach ($field_filters as $search) {
         $key = rgar($search, 'key');
         if ('entry_id' === $key) {
             $key = 'id';
         }
         if (in_array($key, $info_column_keys)) {
             continue;
         }
         $val = rgar($search, 'value');
         $operator = isset($search['operator']) ? strtolower($search['operator']) : '=';
         if ('is' == $operator) {
             $operator = '=';
         }
         if ('isnot' == $operator) {
             $operator = '<>';
         }
         if ('contains' == $operator) {
             $operator = 'like';
         }
         $search_term = 'like' == $operator ? "%{$val}%" : $val;
         $search_type = rgar($search, 'type');
         if (empty($search_type)) {
             if (empty($key)) {
                 $search_type = 'global';
             } elseif (is_numeric($key)) {
                 $search_type = 'field';
             } else {
                 $search_type = 'meta';
             }
         }
         switch ($search_type) {
             case 'field':
                 $is_number_field = false;
                 if ($operator != 'like' && !is_array($form_id) && $form_id > 0) {
                     $form = GFAPI::get_form($form_id);
                     $field = self::get_field($form, $key);
                     if (self::get_input_type($field) == 'number') {
                         $is_number_field = true;
                     }
                 }
                 $search_term_placeholder = rgar($search, 'is_numeric') || $is_number_field ? '%f' : '%s';
                 if (is_array($search_term)) {
                     if (in_array($operator, array('=', 'in'))) {
                         $operator = 'IN';
                         // Override operator
                     } elseif (in_array($operator, array('!=', '<>', 'not in'))) {
                         $operator = 'NOT IN';
                         // Override operator
                     }
                     // Format in SQL and sanitize the strings in the list
                     $search_terms = array_fill(0, count($search_term), '%s');
                     $search_term_placeholder = $wpdb->prepare('( ' . implode(', ', $search_terms) . ' )', $search_term);
                     $search_term = '';
                     // Set to blank, still gets passed to wpdb::prepare below but isn't used
                 }
                 $upper_field_number_limit = (string) (int) $key === $key ? (double) $key + 0.9999 : (double) $key + 0.0001;
                 /* doesn't support "<>" for checkboxes */
                 $field_query = $wpdb->prepare("\n                        l.id IN\n                        (\n                        SELECT\n                        lead_id\n                        from {$lead_details_table_name}\n                        WHERE (field_number BETWEEN %s AND %s AND value {$operator} {$search_term_placeholder})\n                        {$form_id_where}\n                        )", (double) $key - 0.0001, $upper_field_number_limit, $search_term);
                 if (empty($val) || '%%' === $val || '<>' === $operator) {
                     $skipped_field_query = $wpdb->prepare("\n                            l.id NOT IN\n                            (\n                            SELECT\n                            lead_id\n                            from {$lead_details_table_name}\n                            WHERE (field_number BETWEEN %s AND %s)\n                            {$form_id_where}\n                            )", (double) $key - 0.0001, $upper_field_number_limit, $search_term);
                     $field_query = '(' . $field_query . ' OR ' . $skipped_field_query . ')';
                 }
                 $sql_array[] = $field_query;
                 /*
                 //supports '<>' for checkboxes but it doesn't scale
                 $sql_array[] = $wpdb->prepare("l.id IN
                                 (SELECT lead_id
                                 FROM
                                     (
                                         SELECT lead_id, value
                                         FROM $lead_details_table_name
                                         WHERE form_id = %d
                                         AND (field_number BETWEEN %s AND %s)
                                         GROUP BY lead_id
                                         HAVING value $operator %s
                                     ) ld
                                 )
                                 ", $form_id, (float)$key - 0.0001, $upper_field_number_limit, $val );
                 */
                 break;
             case 'global':
                 // include choice text
                 $forms = array();
                 if ($form_id == 0) {
                     $forms = GFAPI::get_forms();
                 } elseif (is_array($form_id)) {
                     foreach ($form_id as $id) {
                         $forms[] = GFAPI::get_form($id);
                     }
                 } else {
                     $forms[] = GFAPI::get_form($form_id);
                 }
                 $choice_texts_clauses = array();
                 foreach ($forms as $form) {
                     if (isset($form['fields'])) {
                         $choice_texts_clauses_for_form = array();
                         foreach ($form['fields'] as $field) {
                             /* @var GF_Field $field */
                             $choice_texts_clauses_for_field = array();
                             if (is_array($field->choices)) {
                                 foreach ($field->choices as $choice) {
                                     if ($operator == '=' && strtolower($choice['text']) == strtolower($val) || $operator == 'like' && !empty($val) && strpos(strtolower($choice['text']), strtolower($val)) !== false) {
                                         if ($field->gsurveyLikertEnableMultipleRows) {
                                             $choice_value = '%' . $choice['value'] . '%';
                                             $choice_search_operator = 'like';
                                         } else {
                                             $choice_value = $choice['value'];
                                             $choice_search_operator = '=';
                                         }
                                         $choice_texts_clauses_for_field[] = $wpdb->prepare("(field_number BETWEEN %s AND %s AND value {$choice_search_operator} %s)", (double) $field->id - 0.0001, (double) $field->id + 0.9999, $choice_value);
                                     }
                                 }
                             }
                             if (!empty($choice_texts_clauses_for_field)) {
                                 $choice_texts_clauses_for_form[] = join(' OR ', $choice_texts_clauses_for_field);
                             }
                         }
                     }
                     if (!empty($choice_texts_clauses_for_form)) {
                         $choice_texts_clauses[] = '(l.form_id = ' . $form['id'] . ' AND (' . join(' OR ', $choice_texts_clauses_for_form) . ' ))';
                     }
                 }
                 $choice_texts_clause = '';
                 if (!empty($choice_texts_clauses)) {
                     $choice_texts_clause = join(' OR ', $choice_texts_clauses);
                     $choice_texts_clause = "\n\t\t\t\t\t\tl.id IN (\n                        SELECT\n                        lead_id\n                        FROM {$lead_details_table_name}\n                        WHERE {$choice_texts_clause} ) OR ";
                 }
                 $choice_value_clause = $wpdb->prepare("value {$operator} %s", $search_term);
                 $sql_array[] = '(' . $choice_texts_clause . $choice_value_clause . ')';
                 break;
             case 'meta':
                 /* doesn't support '<>' for multiple values of the same key */
                 $meta = rgar($entry_meta, $key);
                 $placeholder = rgar($meta, 'is_numeric') ? '%s' : '%s';
                 $search_term = 'like' == $operator ? "%{$val}%" : $val;
                 if (is_array($search_term)) {
                     if (in_array($operator, array('=', 'in'))) {
                         $operator = 'IN';
                     } elseif (in_array($operator, array('!=', '<>', 'not in'))) {
                         $operator = 'NOT IN';
                     }
                     $search_terms = array_fill(0, count($search_term), '%s');
                     $placeholder = $wpdb->prepare('( ' . implode(', ', $search_terms) . ' )', $search_term);
                     $search_term = '';
                 }
                 $sql_array[] = $wpdb->prepare("\n                        l.id IN\n                        (\n                        SELECT\n                        lead_id\n                        FROM {$lead_meta_table_name}\n                        WHERE meta_key=%s AND meta_value {$operator} {$placeholder}\n                        {$form_id_where}\n                        )", $search['key'], $search_term);
                 break;
         }
     }
     $sql = empty($sql_array) ? '' : join(' ' . $search_operator . ' ', $sql_array);
     return $sql;
 }
예제 #27
0
 /**
  * This function will return the title of a form given its ID.
  *
  * This function will return the title of a form in the event where only
  * the form ID is known (gform_after_submission). If no such form exists for
  * the given ID, the function will return -1.
  *
  * @param   $form_id   Integer   The id of the form to search form_id
  *
  * @since 1.0.0
  * @author KREW
  */
 public static function aria_find_form_title_from_id($form_id)
 {
     $all_forms = GFAPI::get_forms();
     $title = null;
     foreach ($all_forms as $form) {
         if ($form["id"] == $form_id) {
             $title = $form["title"];
         }
     }
     if (!isset($title)) {
         $title = -1;
     }
     return $title;
 }