/** * Processes a status update for a specified assignee of the current step of the specified entry. * * @param $entry_id * @param string $assignee_key */ function post_entries_assignees($entry_id, $assignee_key = null) { global $HTTP_RAW_POST_DATA; $capability = apply_filters('gravityflow_web_api_capability_post_entries_assignees', 'gravityflow_create_steps'); $this->authorize($capability); if (empty($assignee_key)) { $this->end(400, 'Bad request'); } $entry = GFAPI::get_entry($entry_id); if (empty($entry)) { $this->end(404, 'Entry not found'); } $form_id = absint($entry['form_id']); $api = new Gravity_Flow_API($form_id); $step = $api->get_current_step($entry); $assignee = new Gravity_Flow_Assignee($assignee_key, $step); if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents('php://input'); } $data = json_decode($HTTP_RAW_POST_DATA, true); $new_status = $data['status']; $form = GFAPI::get_form($form_id); $step->process_assignee_status($assignee, $new_status, $form); $api->process_workflow($entry_id); $response = 'Status updated successfully'; $this->end(200, $response); }
public static function initialise_form_edit() { /* * If we aren't editing our form, don't do anything */ if (empty($_GET['action']) || empty($_GET['lid']) || !is_user_logged_in()) { return false; } $lid = isset($_GET['lid']) ? (int) $_GET['lid'] : 0; self::$lead = $lead = GFAPI::get_entry($lid); self::$form = $form = GFAPI::get_form(self::$lead['form_id']); if (!self::check_user_permission(self::$lead)) { return false; } self::$allowed_edit = true; if (!class_exists('GFFormDisplay')) { require_once GFCommon::get_base_path() . "/form_display.php"; } $field_values = RGForms::post("gform_field_values"); /* * Include appropriate css/javascript here... */ GFFormDisplay::enqueue_form_scripts($form, false); GFFormDisplay::add_init_script($form["id"], "conditional_logic", GFFormDisplay::ON_PAGE_RENDER, self::get_conditional_logic($form, $field_values)); GFFormDisplay::add_init_script($form["id"], "pricing", GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_pricing_init_script($form)); $chosen_script = GFFormDisplay::get_chosen_init_script($form); GFFormDisplay::add_init_script($form["id"], "chosen", GFFormDisplay::ON_PAGE_RENDER, $chosen_script); GFFormDisplay::add_init_script($form["id"], "chosen", GFFormDisplay::ON_CONDITIONAL_LOGIC, $chosen_script); GFFormDisplay::add_init_script($form['id'], 'input_mask', GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_input_mask_init_script($form)); GFFormDisplay::add_init_script($form['id'], 'calculation', GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_calculations_init_script($form)); GFFormDisplay::add_init_script($form['id'], 'currency_format', GFFormDisplay::ON_PAGE_RENDER, GFFormDisplay::get_currency_format_init_script($form)); return true; }
function aura_get_master_aura_form_details($form, $ajax_enabled, $field_values) { // Get details from master form. $ar_form = GFAPI::get_form(1); $au_search_criteria = array('status' => array('active', 'trash')); $ar_entries = GFAPI::get_entries(1, $au_search_criteria); $body_part = array(); // To hold description associated with bodypart/color. $pos_color = array(); $neg_color = array(); $bp = array(); // Pull details from aura details form to display in this form. // Index each entry by 'body part' foreach ($ar_entries as $entry) { if ($entry['1'] == '') { continue; } else { $idx = $entry['1']; $bp[] = array('text' => $entry['1'], 'value' => $entry['1']); if ($entry['2'] != '') { $body_part[$idx]['pos_color'][$entry['2']] = $entry['4']; // Set pos colour value to description $needle = array('text' => $entry['2'], 'value' => $entry['2']); if (!in_array($needle, $pos_color)) { $pos_color[] = $needle; } } if ($entry['3'] != '') { $body_part[$idx]['neg_color'][$entry['3']] = $entry['5']; $needle = array('text' => $entry['3'], 'value' => $entry['3']); if (!in_array($needle, $neg_color)) { $neg_color[] = $needle; } } } } // To display description using JS $json_bp = json_encode($body_part); /* $html = '<input type="hidden" name="aura_body_part"' . 'id="aura_body_part_id"' . 'value=' . $json_bp . ' />' ; */ // HACK/REVISIT: Creating JS var safe? $html = '<script type="text/javascript"> var g_aura_body_part=' . $json_bp . '</script>'; echo $html; $form['fields'][5]['choices'] = $bp; $form['fields'][6]['choices'] = $pos_color; $form['fields'][8]['choices'] = $neg_color; // Default display $form['fields'][5]['placeholder'] = 'Pick choice from list below'; $form['fields'][6]['placeholder'] = 'Pick choice from list below'; $form['fields'][8]['placeholder'] = 'Pick choice from list below'; // $form['fields'][7]['choices'] = $pos_color_descr; // $form['fields'][9]['choices'] = $neg_color_descr; return $form; }
public function get_this_field_value_entry_list($value, $form_id, $field_id, $entry) { $form = GFAPI::get_form($form_id); $field = GFFormsmodel::get_field($form, $field_id); if ($this->is_this_field_type($field)) { $value = $this->get_value_entry_list($value, $form_id, $field_id, $entry); } return $value; }
function feed_settings_fields() { if (is_numeric($_GET['id'])) { $feed_form_id = $_GET['id']; $form = GFAPI::get_form($feed_form_id); } $args = array('field_types' => array(), 'input_types' => array('text', 'name', 'email'), 'callback' => false); $fields = GFAddOn::get_form_fields_as_choices($form, $args); return array(array('title' => 'Postmatic', 'fields' => array(array('name' => 'feed_name', 'label' => 'Feed Name', 'type' => 'text'), array('name' => 'first_name', 'label' => 'First Name Field', 'type' => 'select', 'choices' => $fields), array('name' => 'last_name', 'label' => 'Last Name Field', 'type' => 'select', 'choices' => $fields), array('name' => 'email', 'label' => 'Email Field', 'type' => 'select', 'choices' => $fields, 'required' => true), array('name' => 'condition', 'tooltip' => "Configure the event that riggers the user to be subscribed to your Postmatic feed.", 'label' => 'Condition', 'type' => 'feed_condition', 'checkbox_label' => 'Enable condition for this subscription', 'instructions' => 'Subscribe this user if')))); }
function wpfg_lookup_gravityform($form_id) { if (!class_exists('GFAPI')) { return false; } $form = GFAPI::get_form($form_id); if ($form['title']) { return $form['title']; } return false; }
/** * Returns all the form objects * * @since 1.8.11.5 * @access public * @static * * @param bool $active * @param bool $trash * * @return mixed The array of Forms */ public static function get_forms($active = true, $trash = false) { $form_ids = GFFormsModel::get_form_ids($active, $trash); if (empty($form_ids)) { return array(); } $forms = array(); foreach ($form_ids as $form_id) { $forms[] = GFAPI::get_form($form_id); } return $forms; }
function getFormInitScripts() { if (intval(get_query_var('getFormInitScripts')) != '') { require_once GFCommon::get_base_path() . '/form_display.php'; $form = GFAPI::get_form(get_query_var('getFormInitScripts')); $field_values = array(); // the array of parameter names and values if any fields are being populated GFFormDisplay::register_form_init_scripts($form, $field_values); $form_string = GFFormDisplay::get_form_init_scripts($form); echo strip_tags($form_string); exit; } }
/** * Returns the form object for a given Form ID. * * @access public * @param mixed $form_id * @return mixed False: no form ID specified or Gravity Forms isn't active. Array: Form returned from Gravity Forms */ public static function get_form($form_id) { if (empty($form_id)) { return false; } if (class_exists('GFAPI')) { return GFAPI::get_form($form_id); } if (class_exists('RGFormsModel')) { return RGFormsModel::get_form($form_id); } return false; }
/** * Returns the form object for a given Form ID. * * @access public * @param mixed $form_id * @return mixed False: no form ID specified or Gravity Forms isn't active. Array: Form returned from Gravity Forms */ public static function get_form($form_id) { if (empty($form_id)) { return false; } // Only get_form_meta is cached. ::facepalm:: if (class_exists('RGFormsModel')) { return GFFormsModel::get_form_meta($form_id); } if (class_exists('GFAPI')) { return GFAPI::get_form($form_id); } return false; }
public function load_form_data($lead, $form_id = '') { $form_id = is_numeric($form_id) ? $form_id : (isset($lead['form_id']) ? $lead['form_id'] : $lead['id']); // No form id if (!$form_id) { return false; } $form = \GFAPI::get_form($form_id); // Invalid form ID if (!$form) { return false; } $file_fields = array(); $url_field = array(); $values = array(); foreach ($form['fields'] as $field) { if (isset($field["inputs"]) && is_array($field['inputs'])) { foreach ($field['inputs'] as $input) { // Extract best label $key = $input['label'] ? $input['label'] : \GFCommon::get_label($field, (string) $input["id"]); // Redundant formatting $key = strtolower(str_replace(array(' '), array('_'), $key)); $value = isset($lead[(string) $input['id']]) ? $lead[(string) $input['id']] : ""; $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES); } } elseif (!rgar($field, 'displayOnly')) { // Extract best label $key = isset($field['adminLabel']) && $field['adminLabel'] != "" ? $field['adminLabel'] : ($field['label'] ? $field['label'] : \GFCommon::get_label($field)); // More redundant formatting $key = strtolower(str_replace(array(' '), array('_'), $key)); $value = isset($lead[$field['id']]) ? $lead[$field['id']] : ""; $values[$key] = htmlentities(stripslashes($value), ENT_QUOTES); } } $values['logo'] = $this->logo ? $this->logo : $values['logo']; // An image field being re-assign from post file data try { $this->assign($values); } catch (Exception $e) { $error = $e->getMessage(); } if (!$this->product_id && isset($lead['source_url'])) { // only needed if used in conjunction with woocommerce fulfillment $this->product_id = url_to_postid($lead['source_url']); } return true; }
/** * Save function stores class data as Wordpress meta data * @return boolean true on success and false on failure * */ public function save() { throw new NotImplementedException(); if (!defined('WPINC') || !$this->_post_id || !class_exists('GFAPI')) { return false; } $lead = GFAPI::get_entry($this->_post_id); $form = GFAPI::get_form($lead['form_id']); $values = array(); foreach ($form['fields'] as $field) { $key = $field['adminLabel'] ? $field['adminLabel'] : strtolower($field['label']); $value = $lead[$field['id']]; $values[$key] = $value; } $success = GFAPI::update_entry($this->_data, $this->_post_id); return $success; }
/** * Get form object and insert review page, if necessary. * * @param int $form_id The ID of the Form * @return mixed The form meta array or false */ public static function maybe_add_review_page($form_id) { $form = GFAPI::get_form($form_id); /* Setup default review page parameters. */ $review_page = array('button_text' => __('Review Form', 'gravityforms'), 'content' => '', 'is_enabled' => false); /* Prepare partial entry for review page. */ $partial_entry = GFFormsModel::create_lead($form); /** * A filter for setting up the review page * * @param array $review_page The review page parameters * @param array $form The current form object * @param array $partial_entry The partial entry for the form */ $review_page = gf_apply_filters('gform_review_page', $form['id'], $review_page, $form, $partial_entry); if (rgar($review_page, 'is_enabled')) { $form = self::insert_review_page($form, $review_page); } return $form; }
function rotary_form_field_column_selector_choices($acf_field) { global $id; // reset choices $acf_field['choices'] = array(); $gf_form_id = get_field('field_gravity_form_id', $id); if ($gf_form_id) { $gf_form = GFAPI::get_form($gf_form_id); if (is_array($gf_form)) { foreach ($gf_form['fields'] as $gf_field) { $acf_field['choices'][$gf_field->id] = $gf_field->label; } } else { $error = '<div><p class="alert" style="font-weight:bold;color:red;text-align:center;">Sorry, I can\'t find form ' . $gf_form_id . '</p></div>'; echo $error; } // return the field } return $acf_field; }
function set_post_content($entry, $form) { //getting post $post = get_post($entry['post_id']); $posta = $wp_query->post; $postid = $post->ID; //setting grid variables $petition_form_contain = '"container"'; $petition_form_row = '"row"'; $petition_form_col_1 = '"col-md-1"'; $petition_form_col_4_off_1 = '"col-md-4 col-md-offset-1"'; $petition_form_col_5 = '"col-md-5"'; $petition_form_col_6_off_1 = '"col-md-6 col-md-offset-1"'; //other variables $petition_form = '"petition-privacy"'; $petition_form_petf = '"petfsize"'; $quoteone = '"'; //setting up the petition form $formid = 1; $form_count = RGFormsModel::get_form_counts($formid); $form_count_disp = $form_count['total']; $form_id_step = $form_count_disp + 32; $form_id = 2; $form = GFAPI::get_form($form_id); $form_add_new = GFAPI::add_form($form); $form_id = $form_id_step; $form = GFAPI::get_form($form_id); $form['title'] = 'Petition Form ID' . ' ' . $form_id; $result = GFAPI::update_form($form); //changing post content $post->post_content = "<div class={$petition_form_col_4_off_1}>[gravityform id ={$quoteone}{$form_id_step}{$quoteone}]</div><div class={$petition_form_contain}><div class={$petition_form_row}>\r\n<div class={$petition_form_col_6_off_1}><div class={$petition_form_petf}>" . rgar($entry, '4') . "</div></div><div class={$petition_form_col_5}></div></div></div>"; //updating post wp_update_post($post); //adding form ID $post_id = $postid; $meta_key = 'field_petition_form_id'; $meta_value = $form_id_step; add_post_meta($post_id, $meta_key, $meta_value); }
/** * Load the form fields for the given form id into the private $_fields array */ public function load($formId) { global $wpdb; $metaTable = Cart66Common::getTableName('rg_form_meta', ''); $sql = "select display_meta from {$metaTable} where form_id = {$formId}"; $meta = unserialize($wpdb->get_var($sql)); if (class_exists('GFAPI')) { // enable support for GF 1.8 API $form = GFAPI::get_form($formId); if ($form && count($form['fields'])) { $this->_fields = $form['fields']; } else { throw new Cart66Exception("Unable to load Gravity Form: {$formId}"); } } else { if (count($meta['fields'])) { $this->_fields = $meta['fields']; } else { throw new Cart66Exception("Unable to load Gravity Form: {$formId}"); } } }
public static function list_page($form_ids, $is_admin) { if (empty($form_ids)) { esc_html_e("You haven't submitted any workflow forms yet.", 'gravityflow'); return; } $items = array(); foreach ($form_ids as $form_id) { $form = GFAPI::get_form($form_id); if (!$form) { continue; } $title = sprintf('<div class="gravityflow-initiate-form-title">%s</div>', rgar($form, 'title')); $description = sprintf('<div class="gravityflow-initiate-form-description">%s</div>', rgar($form, 'description')); $form_id = absint($form_id); $url = $is_admin ? admin_url('admin.php?page=gravityflow-submit&id=' . $form_id) : add_query_arg(array('page' => 'gravityflow-submit', 'id' => $form_id)); $block = sprintf('<a href="%s"><div class="panel">%s%s</div></a>', $url, $title, $description); $items[] = sprintf('<li id="gravityflow-initiate-form-%d">%s</li>', $form_id, $block); } $list = sprintf('<ul id="gravityflow-initiate-list">%s</a></ul>', join('', $items)); echo $list; }
public static function update_gravity_form($post_id) { if (self::$formID === false || self::$fieldID === false) { return; } $formValues = get_field('contact_form_options', $post_id); if ($post_id == self::$optionsID) { $form = GFAPI::get_form(self::$formID); $first = true; foreach ($form['fields'] as $key => $value) { if ($form['fields'][$key]->id == self::$fieldID) { $form['fields'][$key]->choices = array(); foreach ($formValues as $key2 => $value2) { $form['fields'][$key]->choices[] = array('text' => $value2['subject'], 'value' => self::encrypt($value2['email']), 'isSelected' => $first); if ($first == true) { $first = false; } } } } GFAPI::update_form($form); } }
function au_list_aura_details() { $ar_form = GFAPI::get_form(1); $ar_field_len = sizeof($ar_form['fields']); echo "<br>"; // Now print all the entries $au_search_criteria = array('status' => array('active', 'trash')); $ar_entries = GFAPI::get_entries(1, $au_search_criteria); $descr = array(); $remedy = array(); foreach ($ar_entries as $ar_row) { $descr[] = count($ar_row[4] != 0) ? $ar_row[4] : "<>"; $remedy[] = count($ar_row[5] != 0) ? $ar_row[5] : "<>"; } echo "<br><b> Description: </b>"; foreach ($descr as $d) { echo $d; } echo "<br><br><b> Remedial Measures </b>"; foreach ($remedy as $r) { echo $r; } }
public static function gravityforms_send_entry_to_jdb($id) { $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } error_log('gravityforms_send_entry_to_jdb'); $entry_id = $id; $entry = GFAPI::get_entry($entry_id); $form = GFAPI::get_form($entry['form_id']); //$jdb_encoded_entry = gravityforms_to_jdb_record($entry,$row[0],$row[1]); $jdb_encoded_entry = http_build_query(self::gravityforms_to_jdb_record($entry, $entry_id, $form)); $synccontents = '"' . $mysqli->real_escape_string($jdb_encoded_entry) . '"'; $results_on_send = self::gravityforms_send_record_to_jdb($entry_id, $jdb_encoded_entry); $results_on_send_prepared = '"' . $mysqli->real_escape_string($results_on_send) . '"'; // MySqli Insert Query $insert_row = $mysqli->query("INSERT INTO `wp_rg_lead_jdb_sync`(`lead_id`, `synccontents`, `jdb_response`) VALUES ({$entry_id},{$synccontents}, {$results_on_send_prepared})"); if ($insert_row) { error_log('Success! Response from JDB was: ' . $results_on_send . '<br />'); } else { die('Error : (' . $mysqli->errno . ') ' . $mysqli->error); } }
// echo "Total contacts " . $resource_request_bgl360->trusteesTotalContacts . '<br>'; // // $resource_request_bgl360->setTrusteesContacts($resource_request_bgl360->trusteesContacts, 0); // echo "contacts full name 0 = " . $resource_request_bgl360->trusteesContactsFullName . '<br>'; // $resource_request_bgl360->setTrusteesContacts($resource_request_bgl360->trusteesContacts, 1); // echo "contacts full name 1 = " . $resource_request_bgl360->trusteesContactsFullName . '<br>'; //trustees $numMembers = count($members); //echo 'Members: '.print_r($response,true); $fundState = $fundDetails['postalAddress']['state']; $fundName = $fundDetails['name']; $fundAbn = $fundDetails['abn']; $postalAddress = $fundDetails['postalAddress']['streetLine1'] . ' ' . $fundDetails['postalAddress']['streetLine2']; $estDate = date("d/m/Y", strtotime($fundDetails['estDate'])); $formId = (int) $_POST['documentList']; $form = GFAPI::get_form($formId); $title = $form['title']; $current_user = wp_get_current_user(); $user_id = $current_user->ID; $entry = array(); $entry['form_id'] = $formId; $entry['created_by'] = $user_id; $entry['orderStatus'] = 'incomplete'; switch ($formId) { // New SMSF case 6: $fundDetails = new \App\FundDetails($fundDetailsData); $trustees = new \App\Trustees($trusteesData, 0); $entry['2'] = $fundDetails->fundName; $entry['137'] = 'BGL360 Import ' . date('d-m-Y'); $entry['139'] = $fundDetails->fundPostalAddress;
/** * format_value() * * This filter is applied to the $value after it is loaded from the db and before it is returned to the template * * @type filter * @since 3.6 * @date 23/01/13 * * @param $value (mixed) the value which was loaded from the database * @param $post_id (mixed) the $post_id from which the value was loaded * @param $field (array) the field array holding all the field options * * @return $value (mixed) the modified value */ function format_value($value, $post_id, $field) { if (!$value or empty($value)) { return false; } if (is_array($value) && !empty($value)) { $form_objects = array(); foreach ($value as $k => $v) { $form = GFAPI::get_form($v); if (!is_wp_error($form)) { $form_objects[$k] = $form; } } return !empty($form_objects) ? $form_objects : false; } else { $form = GFAPI::get_form(intval($value)); return !is_wp_error($form) ? $form : false; } }
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; }
/** * Get form file fields for feed field settings. * * @access public * @param string $module (default: 'contact') * @return array $fields */ public function get_file_fields_for_feed_setting($module = 'contact') { /* Setup choices array. */ $choices = array(); /* Get the form. */ $form = GFAPI::get_form(rgget('id')); /* Get file fields for the form. */ $file_fields = GFAPI::get_fields_by_type($form, array('fileupload'), true); if (!empty($file_fields)) { foreach ($file_fields as $field) { $choices[] = array('name' => $module . 'Attachments[' . $field->id . ']', 'label' => $field->label, 'default_value' => 0); } } return $choices; }
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> <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 function get_results($form_id) { $this->authorize("gravityforms_view_entries"); $s = rgget("s"); // search criteria $search_criteria = false === empty($s) && is_array($s) ? $s : array(); $form = GFAPI::get_form($form_id); if (!$form) { self::die_not_found(); } // for the Web API return all fields $fields = rgar($form, "fields"); $form_id = $form["id"]; $key = $this->get_results_cache_key($form_id, $fields, $search_criteria); $key_tmp = "tmp" . $key; $data = get_option($key, array()); $cache_meta = $this->get_results_cache_meta($form_id); // add the cache meta early so form editor updates can test for valid field hash if (empty($cache_meta)) { $this->update_results_cache_meta($form_id, $fields, 0); } $cache_expiry = rgar($cache_meta, "timestamp"); $cache_timestamp = isset($data["timestamp"]) ? $data["timestamp"] : 0; $cache_expired = $cache_expiry ? $cache_expiry > $cache_timestamp : false; // check for valid cached results first if (!empty($data) && "complete" == rgar($data, "status") && !$cache_expired) { $results = $data; $status = 200; if (isset($results["progress"])) { unset($results["progress"]); } } else { $state = get_option($key_tmp); if (empty($state) || "complete" == rgar($data, "status") && $cache_expired) { if (!class_exists("GFResults")) { require_once GFCommon::get_base_path() . "/includes/addon/class-gf-results.php"; } $gf_results = new GFResults($this->_slug, array()); $max_execution_time = 5; $results = $gf_results->get_results_data($form, $fields, $search_criteria, $state, $max_execution_time); if ("complete" == $results["status"]) { $status = 200; if (false == empty($state)) { delete_option($key_tmp); } } else { if (false === empty($data) && "complete" == rgar($data, "status") && $cache_expired) { $data["status"] = "expired"; $data["progress"] = $results["progress"]; $this->update_results_cache($key, $data); } $this->update_results_cache($key_tmp, $results); $this->schedule_results_cron($form, $fields, $search_criteria); if ($data) { $results = $data; } $status = 202; } } else { // The cron task is recursive, not periodic, so system restarts, script timeouts and memory issues can prevent the cron from restarting. // Check timestamp and kick off the cron again if it appears to have stopped $state_timestamp = rgar($state, "timestamp"); $state_age = time() - $state_timestamp; if ($state_age > 180 && !$this->results_cron_is_scheduled($form, $fields, $search_criteria)) { $this->schedule_results_cron($form, $fields, $search_criteria); } if (false === empty($data) && "expired" == rgar($data, "status")) { $results = $data; } else { $results = $state; } $status = 202; } } $fields = $results["field_data"]; // add choice labels to the results so the client doesn't need to cross-reference with the form object $results["field_data"] = $this->results_data_add_labels($form, $fields); $this->end($status, $results); }
/** * Returns the field ID of the first field of the desired type. * * @access public * @param string $field_type * @param int $subfield_id (default: null) * @param int $form_id (default: null) * @return string */ public function get_first_field_by_type($field_type, $subfield_id = null, $form_id = null, $return_first_only = true) { /* Get the current form ID. */ if (rgblank($form_id)) { $form_id = rgget('id'); } /* Get the form. */ $form = GFAPI::get_form($form_id); /* Get the request field type for the form. */ $fields = GFAPI::get_fields_by_type($form, array($field_type)); if (count($fields) == 0 || count($fields) > 1 && $return_first_only) { return null; } else { if (rgblank($subfield_id)) { return $fields[0]->id; } else { return $fields[0]->id . '.' . $subfield_id; } } }
/** * Target of gform_before_delete_field hook. Sets relevant payment feeds to inactive when the credit card field is deleted. * * @param $form_id . ID of the form being edited. * @param $field_id . ID of the field being deleted. */ public function before_delete_field($form_id, $field_id) { if ($this->_requires_credit_card) { $form = GFAPI::get_form($form_id); $field = $this->get_credit_card_field($form); if (is_object($field) && $field->id == $field_id) { $feeds = $this->get_feeds($form_id); foreach ($feeds as $feed) { if ($feed['is_active']) { $this->update_feed_active($feed['id'], 0); } } } } }
/** * Updates the entry status * * Called via AJAX * Passes data off to either RGFormsModel::update_lead_property or RGFormsModel::delete_lead * * @access public * @static * @see RGFormsModel::update_lead_property * @see RGFormsModel::delete_lead */ public static function update_lead_status() { check_ajax_referer('gf_delete_entry'); $status = rgpost('status'); $lead_id = rgpost('entry'); $entry = GFAPI::get_entry($lead_id); $form = GFAPI::get_form($entry['form_id']); switch ($status) { case 'unspam': RGFormsModel::update_lead_property($lead_id, 'status', 'active'); break; case 'delete': if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { RGFormsModel::delete_lead($lead_id); } break; default: RGFormsModel::update_lead_property($lead_id, 'status', $status); break; } require_once 'entry_list.php'; $filter_links = GFEntryList::get_filter_links($form); $counts = array(); foreach ($filter_links as $filter_link) { $id = $filter_link['id'] == '' ? 'all' : $filter_link['id']; $counts[$id . '_count'] = $filter_link['count']; } $x = new WP_Ajax_Response(); $x->add(array('what' => 'gf_entry', 'id' => $lead_id, 'supplemental' => $counts)); $x->send(); }
public function start_cancel_subscription() { check_ajax_referer("gaddon_cancel_subscription", "gaddon_cancel_subscription"); $entry_id = $_POST["entry_id"]; $entry = GFAPI::get_entry($entry_id); $form = GFAPI::get_form($entry["form_id"]); $feed = $this->get_payment_feed($entry, $form); if ($this->cancel_subscription($entry, $feed)) { die('1'); } else { die('0'); } }