/** * Adds a single Entry object. * * Intended to be used for importing an entry object. The usual hooks that are triggered while saving entries are not fired here. * Checks that the form id, field ids and entry meta exist and ignores legacy values (i.e. values for fields that no longer exist). * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * * @return mixed Either the new Entry ID or a WP_Error instance */ public static function add_entry($entry) { global $wpdb; if (!is_array($entry)) { return new WP_Error("invalid_entry_object", __("The entry object must be an array", "gravityforms")); } // make sure the form id exists $form_id = rgar($entry, "form_id"); if (empty($form_id)) { return new WP_Error("empty_form_id", __("The form id must be specified", "gravityforms")); } if (false === self::form_id_exists($form_id)) { return new WP_Error("invalid_form_id", __("The form for this entry does not exist", "gravityforms")); } // use values in the entry object if present $post_id = isset($entry["post_id"]) ? intval($entry["post_id"]) : 'NULL'; $date_created = isset($entry["date_created"]) && $entry["date_created"] != "" ? sprintf("'%s'", mysql_real_escape_string($entry["date_created"])) : "utc_timestamp()"; $is_starred = isset($entry["is_starred"]) ? $entry["is_starred"] : 0; $is_read = isset($entry["is_read"]) ? $entry["is_read"] : 0; $ip = isset($entry["ip"]) ? $entry["ip"] : GFFormsModel::get_ip(); $source_url = isset($entry["source_url"]) ? $entry["source_url"] : GFFormsModel::get_current_page_url(); $user_agent = isset($entry["user_agent"]) ? $entry["user_agent"] : "API"; $currency = isset($entry["currency"]) ? $entry["currency"] : GFCommon::get_currency(); $payment_status = isset($entry["payment_status"]) ? sprintf("'%s'", mysql_real_escape_string($entry["payment_status"])) : 'NULL'; $payment_date = strtotime(rgar($entry, "payment_date")) ? sprintf("'%s'", gmdate('Y-m-d H:i:s', strtotime("{$entry["payment_date"]}"))) : "NULL"; $payment_amount = isset($entry["payment_amount"]) ? (double) $entry["payment_amount"] : 'NULL'; $payment_method = isset($entry["payment_method"]) ? $entry["payment_method"] : ''; $transaction_id = isset($entry["transaction_id"]) ? sprintf("'%s'", mysql_real_escape_string($entry["transaction_id"])) : 'NULL'; $is_fulfilled = isset($entry["is_fulfilled"]) ? intval($entry["is_fulfilled"]) : 'NULL'; $status = isset($entry["status"]) ? $entry["status"] : "active"; global $current_user; $user_id = isset($entry["created_by"]) ? mysql_real_escape_string($entry["created_by"]) : ""; if (empty($user_id)) { $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL'; } $transaction_type = isset($entry["transaction_type"]) ? intval($entry["transaction_type"]) : 'NULL'; $lead_table = GFFormsModel::get_lead_table_name(); $result = $wpdb->query($wpdb->prepare("\n INSERT INTO {$lead_table}\n (form_id, post_id, date_created, is_starred, is_read, ip, source_url, user_agent, currency, payment_status, payment_date, payment_amount, transaction_id, is_fulfilled, created_by, transaction_type, status, payment_method)\n VALUES\n (%d, {$post_id}, {$date_created}, %d, %d, %s, %s, %s, %s, {$payment_status}, {$payment_date}, {$payment_amount}, {$transaction_id}, {$is_fulfilled}, {$user_id}, {$transaction_type}, %s, %s)\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method)); if (false === $result) { return new WP_Error("insert_entry_properties_failed", __("There was a problem while inserting the entry properties", "gravityforms"), $wpdb->last_error); } // reading newly created lead id $entry_id = $wpdb->insert_id; $entry["id"] = $entry_id; // only save field values for fields that currently exist in the form $form = GFFormsModel::get_form_meta($form_id); foreach ($form["fields"] as $field) { if (in_array($field["type"], array("html", "page", "section"))) { continue; } if (isset($field["inputs"]) && is_array($field["inputs"])) { foreach ($field["inputs"] as $input) { $input_id = $input["id"]; if (isset($entry[(string) $input_id])) { $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $input_id, $entry[(string) $input_id]); if (false === $result) { return new WP_Error("insert_input_value_failed", __("There was a problem while inserting one of the input values for the entry", "gravityforms"), $wpdb->last_error); } } } } else { $field_id = $field["id"]; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ""; $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $field_id, $field_value); if (false === $result) { return new WP_Error("insert_field_values_failed", __("There was a problem while inserting the field values", "gravityforms"), $wpdb->last_error); } } } // add save the entry meta values - only for the entry meta currently available for the form, ignore the rest $entry_meta = GFFormsModel::get_entry_meta($form_id); if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $key) { if (isset($entry[$key])) { gform_update_meta($entry_id, $key, $entry[$key]); } } } return $entry_id; }
/** * Updates a single field of an entry. * * @since 1.9 * @access public * @static * * @param int $entry_id The ID of the Entry object * @param string $input_id The id of the input to be updated. For single input fields such as text, paragraph, website, drop down etc... this will be the same as the field ID. * For multi input fields such as name, address, checkboxes, etc... the input id will be in the format {FIELD_ID}.{INPUT NUMBER}. ( i.e. "1.3" ) * The $input_id can be obtained by inspecting the key for the specified field in the $entry object. * * @param mixed $value The value to which the field should be set * * @return bool Whether the entry property was updated successfully */ public static function update_entry_field($entry_id, $input_id, $value) { global $wpdb; $entry = self::get_entry($entry_id); if (is_wp_error($entry)) { return $entry; } $form = self::get_form($entry['form_id']); if (!$form) { return false; } $field = GFFormsModel::get_field($form, $input_id); $input_id_min = (double) $input_id - 0.0001; $input_id_max = (double) $input_id + 0.0001; $lead_details_table_name = GFFormsModel::get_lead_details_table_name(); $lead_detail_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$lead_details_table_name} WHERE lead_id=%d AND field_number BETWEEN %s AND %s", $entry_id, $input_id_min, $input_id_max)); $result = true; if (!isset($entry[$input_id]) || $entry[$input_id] != $value) { $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $value); } return $result; }
/** * Updates a single field of an entry. * * @since 1.9 * @access public * @static * * @param int $entry_id The ID of the Entry object * @param string $input_id The id of the input to be updated. For single input fields such as text, paragraph, website, drop down etc... this will be the same as the field ID. * For multi input fields such as name, address, checkboxes, etc... the input id will be in the format {FIELD_ID}.{INPUT NUMBER}. ( i.e. "1.3" ) * The $input_id can be obtained by inspecting the key for the specified field in the $entry object. * * @param mixed $value The value to which the field should be set * * @return bool Whether the entry property was updated successfully */ public static function update_entry_field($entry_id, $input_id, $value) { global $wpdb; $entry = self::get_entry($entry_id); $form = self::get_form($entry['form_id']); $field = GFFormsModel::get_field($form, $input_id); $lead_detail_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}rg_lead_detail WHERE lead_id=%d AND CAST(field_number as DECIMAL(4,2))=%s", $entry_id, $input_id)); $result = true; if (!isset($entry[$input_id]) || $entry[$input_id] != $value) { $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $value); } return $result; }
/** * Updates a single field of an entry. * * @since 1.9 * @access public * @static * * @param int $entry_id The ID of the Entry object * @param string $input_id The id of the input to be updated. For single input fields such as text, paragraph, website, drop down etc... this will be the same as the field ID. * For multi input fields such as name, address, checkboxes, etc... the input id will be in the format {FIELD_ID}.{INPUT NUMBER}. ( i.e. "1.3" ) * The $input_id can be obtained by inspecting the key for the specified field in the $entry object. * * @param mixed $value The value to which the field should be set * * @return bool Whether the entry property was updated successfully */ function mf_update_entry_field($entry_id, $input_id, $value) { global $wpdb; $entry = GFAPI::get_entry($entry_id); if (is_wp_error($entry)) { return $entry; } $form = GFAPI::get_form($entry['form_id']); if (!$form) { return false; } $field = GFFormsModel::get_field($form, $input_id); $lead_detail_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}rg_lead_detail WHERE lead_id=%d AND CAST(field_number AS CHAR) ='%s'", $entry_id, $input_id)); $result = true; if (!isset($entry[$input_id]) || $entry[$input_id] != $value) { $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $value); } return $result; }
function clear_cc($entry, $form) { GFFormsModel::update_lead_field_value($form, $entry, '', '', '9', ''); GFFormsModel::update_lead_field_value($form, $entry, '', '', '10', ''); GFFormsModel::update_lead_field_value($form, $entry, '', '', '11', ''); GFFormsModel::update_lead_field_value($form, $entry, '', '', '13', ''); }