public static function gf_create_user($entry, $form, $fulfilled = false) { self::log_debug("form #{$form['id']} - starting gf_create_user()."); global $wpdb; // if the entry is marked as spam if (rgar($entry, 'status') == 'spam') { self::log_debug('gf_create_user(): aborting. Entry is marked as spam.'); return; } $config = self::get_active_config($form, $entry); $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; // if there is no registration feed or the feed is not active, abandon ship if (!$config || !$config['is_active']) { self::log_debug('gf_create_user(): aborting. No feed or feed is inactive.'); return; } $user_data = self::get_user_data($entry, $form, $config, $is_update_feed); if (!$user_data) { self::log_debug('gf_create_user(): aborting. user_login or user_email are empty.'); return; } // if PayPal Add-on was used for this entry, integrate $paypal_config = self::get_paypal_config($form["id"], $entry); $delay_paypal_registration = 0; $password = ''; if ($paypal_config) { $order_total = GFCommon::get_order_total($form, $entry); // delay the registration IF: // - the delay registration option is checked // - the order total does NOT equal zero (no delay since there will never be a payment) // - the payment has not already been fulfilled $delay_paypal_registration = $paypal_config['meta']['delay_registration']; if ($paypal_config && $delay_paypal_registration && $order_total != 0 && !$fulfilled) { self::log_debug('gf_create_user(): aborting. Registration delayed by PayPal feed configuration.'); //Saving encrypted password in meta gform_update_meta($entry['id'], 'userregistration_password', self::encrypt($user_data['password'])); return; } else { if ($paypal_config && $delay_paypal_registration && $order_total != 0 && $fulfilled) { //reading encrypted password from meta and removing meta $password = gform_get_meta($entry['id'], 'userregistration_password'); if ($password) { $password = self::decrypt($password); gform_delete_meta($entry['id'], 'userregistration_password'); } } } } // provide filter to allow add-ons to disable registration if needed $disable_registration = apply_filters('gform_disable_registration', false, $form, $entry, $fulfilled); if ($disable_registration) { self::log_debug('gf_create_user(): aborting. gform_disable_registration hook was used.'); return; } $user_activation = rgars($config, 'meta/user_activation'); // if about to create user, check if activation required... only use activation if payment is not fulfilled by payment //if manual activation and paypal set to delay registration and paypal fulfilled, need to put in signups table if (!$is_update_feed && $user_activation && !$fulfilled || !$is_update_feed && $user_activation && $fulfilled && $delay_paypal_registration) { require_once self::get_base_path() . '/includes/signups.php'; GFUserSignups::prep_signups_functionality(); $meta = array('lead_id' => $entry['id'], 'user_login' => $user_data['user_login'], 'email' => $user_data['user_email'], 'password' => self::encrypt($user_data['password'])); $meta = apply_filters('gform_user_registration_signup_meta', $meta, $form, $entry, $config); $meta = apply_filters("gform_user_registration_signup_meta_{$form['id']}", $meta, $form, $entry, $config); $ms_options = rgars($config, 'meta/multisite_options'); // save current user details in wp_signups for future activation if (is_multisite() && rgar($ms_options, 'create_site') && ($site_data = self::get_site_data($entry, $form, $config))) { wpmu_signup_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_data['user_login'], $user_data['user_email'], $meta); } else { // wpmu_signup_user() does the following sanitization of the user_login before saving it to the database, // we can run this same code here to allow successful retrievel of the activation_key without actually // changing the user name when it is activated. 'd smith' => 'dsmith', but when activated, username is 'd smith'. $user_data['user_login'] = preg_replace('/\\s+/', '', sanitize_user($user_data['user_login'], true)); self::log_debug("Calling wpmu_signup_user (sends email with activation link) with login: "******" email: " . $user_data['user_email'] . " meta: " . print_r($meta, true)); wpmu_signup_user($user_data['user_login'], $user_data['user_email'], $meta); self::log_debug("Done with wpmu_signup_user"); } $activation_key = $wpdb->get_var($wpdb->prepare("SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s ORDER BY registered DESC LIMIT 1", $user_data['user_login'])); // used for filtering on activation listing UI GFUserSignups::add_signup_meta($entry['id'], $activation_key); // abort current sign up, user must activate return; } if ($is_update_feed) { self::update_user($entry, $form, $config); } else { //only run create_user when manual/email activation NOT set if (!$user_activation) { self::log_debug("in gf_create_user - calling create_user"); self::create_user($entry, $form, $config, $password); } } }
public static function refresh_product_cache($form, $lead, $use_choice_text = false, $use_admin_label = false) { $cache_options = array(array(false, false), array(false, true), array(true, false), array(true, true)); foreach ($form['fields'] as $field) { /* @var $field GF_Field */ if ($field->has_calculation()) { //deleting field value cache for calculated fields $cache_key = 'GFFormsModel::get_lead_field_value_' . $lead['id'] . '_' . $field->id; GFCache::delete($cache_key); } } foreach ($cache_options as $cache_option) { list($use_choice_text, $use_admin_label) = $cache_option; if (gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}")) { gform_delete_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); GFCommon::get_product_fields($form, $lead, $use_choice_text, $use_admin_label); } } }
public static function refresh_product_cache($form, $lead, $use_choice_text = false, $use_admin_label = false) { $cache_options = array(array(false, false), array(false, true), array(true, false), array(true, true)); foreach ($form["fields"] as $field) { if (GFCommon::has_field_calculation($field)) { //deleting field value cache for calculated fields $cache_key = "GFFormsModel::get_lead_field_value_" . $lead["id"] . "_" . $field["id"]; GFCache::delete($cache_key); } } foreach ($cache_options as $cache_option) { list($use_choice_text, $use_admin_label) = $cache_option; if (gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}")) { gform_delete_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); GFCommon::get_product_fields($form, $lead, $use_choice_text, $use_admin_label); } } }
public static function refresh_product_cache($form, $lead, $use_choice_text = false, $use_admin_label = false) { $cache_options = array(array(false, false), array(false, true), array(true, false), array(true, true)); foreach ($cache_options as $cache_option) { list($use_choice_text, $use_admin_label) = $cache_option; if (gform_get_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}")) { gform_delete_meta(rgar($lead, 'id'), "gform_product_info_{$use_choice_text}_{$use_admin_label}"); GFCommon::get_product_fields($form, $lead, $use_choice_text, $use_admin_label); } } }
/** * Updates an entire single Entry object. * * If the date_created value is not set then the current time UTC will be used. * The date_created value, if set, is expected to be in 'Y-m-d H:i:s' format (UTC). * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * @param int $entry_id Optional. If specified, the ID in the Entry object will be ignored * * @return mixed Either True or a WP_Error instance */ public static function update_entry($entry, $entry_id = null) { global $wpdb; if (empty($entry_id)) { if (rgar($entry, 'id')) { $entry_id = absint($entry['id']); } } else { $entry['id'] = absint($entry_id); } if (empty($entry_id)) { return new WP_Error('missing_entry_id', __('Missing entry id', 'gravityforms')); } $current_entry = $original_entry = self::get_entry($entry_id); if (!$current_entry) { return new WP_Error('not_found', __('Entry not found', 'gravityforms'), $entry_id); } if (is_wp_error($current_entry)) { return $current_entry; } // make sure the form id exists $form_id = rgar($entry, 'form_id'); if (empty($form_id)) { $form_id = rgar($current_entry, 'form_id'); } if (false === self::form_id_exists($form_id)) { return new WP_Error('invalid_form_id', __('The form for this entry does not exist', 'gravityforms')); } $entry = apply_filters('gform_entry_pre_update', $entry, $original_entry); // 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']) ? sprintf("'%s'", esc_sql($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'", esc_sql($entry['payment_status'])) : 'NULL'; $payment_date = strtotime(rgar($entry, 'payment_date')) ? "'" . 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'", esc_sql($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']) ? absint($entry['created_by']) : ''; if (empty($user_id)) { $user_id = $current_user && $current_user->ID ? absint($current_user->ID) : 'NULL'; } $transaction_type = isset($entry['transaction_type']) ? intval($entry['transaction_type']) : 'NULL'; $lead_table = GFFormsModel::get_lead_table_name(); $sql = $wpdb->prepare("\n UPDATE {$lead_table}\n SET\n form_id = %d,\n post_id = {$post_id},\n date_created = {$date_created},\n is_starred = %d,\n is_read = %d,\n ip = %s,\n source_url = %s,\n user_agent = %s,\n currency = %s,\n payment_status = {$payment_status},\n payment_date = {$payment_date},\n payment_amount = {$payment_amount},\n transaction_id = {$transaction_id},\n is_fulfilled = {$is_fulfilled},\n created_by = {$user_id},\n transaction_type = {$transaction_type},\n status = %s,\n payment_method = %s\n WHERE\n id = %d\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method, $entry_id); $result = $wpdb->query($sql); if (false === $result) { return new WP_Error('update_entry_properties_failed', __('There was a problem while updating the entry properties', 'gravityforms'), $wpdb->last_error); } // only save field values for fields that currently exist in the form. The rest in $entry will be ignored. The rest in $current_entry will get deleted. $lead_detail_table = GFFormsModel::get_lead_details_table_name(); $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $entry_id)); $form = GFFormsModel::get_form_meta($form_id); $form = gf_apply_filters(array('gform_form_pre_update_entry', $form_id), $form, $entry, $entry_id); foreach ($form['fields'] as $field) { /* @var GF_Field $field */ $type = GFFormsModel::get_input_type($field); if (in_array($type, array('html', 'page', 'section'))) { continue; } $inputs = $field->get_entry_inputs(); if (is_array($inputs)) { foreach ($field->inputs as $input) { $input_id = (string) $input['id']; if (isset($entry[$input_id])) { if ($entry[$input_id] != $current_entry[$input_id]) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $input_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $entry[$input_id]); if (false === $result) { return new WP_Error('update_input_value_failed', __('There was a problem while updating one of the input values for the entry', 'gravityforms'), $wpdb->last_error); } } unset($current_entry[$input_id]); } } } else { $field_id = $field->id; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ''; if ($field_value != $current_entry[$field_id]) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $field_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $field_id, $field_value); if (false === $result) { return new WP_Error('update_field_values_failed', __('There was a problem while updating the field values', 'gravityforms'), $wpdb->last_error); } } unset($current_entry[$field_id]); } } // 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])) { if ($entry[$key] != $current_entry[$key]) { gform_update_meta($entry_id, $key, $entry[$key]); } unset($current_entry[$key]); } } } // now delete remaining values from the old entry if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $meta_key) { if (isset($current_entry[$meta_key])) { gform_delete_meta($entry_id, $meta_key); unset($current_entry[$meta_key]); } } } foreach ($current_entry as $k => $v) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $k); $field = GFFormsModel::get_field($form, $k); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $k, ''); if (false === $result) { return new WP_Error('update_field_values_failed', __('There was a problem while updating the field values', 'gravityforms'), $wpdb->last_error); } } /** * Fires after the Entry is updated. * * @param array $lead The entry object after being updated. * @param array $original_entry The entry object before being updated. */ gf_do_action(array('gform_post_update_entry', $form_id), $entry, $original_entry); return true; }
/** * Updates a single Entry object. * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * @param int $entry_id Optional. If specified, the ID in the Entry object will be ignored * * @return mixed Either True or a WP_Error instance */ public static function update_entry($entry, $entry_id = null) { global $wpdb; if (empty($entry_id)) { $entry_id = $entry["id"]; } if (empty($entry_id)) { return new WP_Error("missing_entry_id", __("Missing entry id", "gravityforms")); } $current_entry = self::get_entry($entry_id); if (!$current_entry) { return new WP_Error("not_found", __("Entry not found", "gravityforms"), $entry_id); } if (is_wp_error($current_entry)) { return $current_entry; } // make sure the form id exists $form_id = rgar($entry, "form_id"); if (empty($form_id)) { $form_id = rgar($current_entry, "form_id"); } 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"]) ? 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")) ? "'" . 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 UPDATE {$lead_table}\n SET\n form_id = %d,\n post_id = {$post_id},\n date_created = {$date_created},\n is_starred = %d,\n is_read = %d,\n ip = %s,\n source_url = %s,\n user_agent = %s,\n currency = %s,\n payment_status = {$payment_status},\n payment_date = {$payment_date},\n payment_amount = {$payment_amount},\n transaction_id = {$transaction_id},\n is_fulfilled = {$is_fulfilled},\n created_by = {$user_id},\n transaction_type = {$transaction_type},\n status = %s,\n payment_method = %s\n WHERE\n id = %d\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method, $entry_id)); if (false === $result) { return new WP_Error("update_entry_properties_failed", __("There was a problem while updating the entry properties", "gravityforms"), $wpdb->last_error); } // only save field values for fields that currently exist in the form. The rest in entry_id will be ignored. The rest in current_entry will get deleted. $lead_detail_table = GFFormsModel::get_lead_details_table_name(); $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $entry_id)); $form = GFFormsModel::get_form_meta($form_id); foreach ($form["fields"] as $field) { $type = GFFormsModel::get_input_type($field); if (in_array($type, array("html", "page", "section"))) { continue; } if (isset($field["inputs"]) && is_array($field["inputs"])) { foreach ($field["inputs"] as $input) { $input_id = (string) $input["id"]; if (isset($entry[$input_id])) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $input_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $entry[$input_id]); if (false === $result) { return new WP_Error("update_input_value_failed", __("There was a problem while updating one of the input values for the entry", "gravityforms"), $wpdb->last_error); } unset($current_entry[$input_id]); } } } else { $field_id = $field["id"]; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ""; $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $field_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $field_id, $field_value); if (false === $result) { return new WP_Error("update_field_values_failed", __("There was a problem while updating the field values", "gravityforms"), $wpdb->last_error); } unset($current_entry[$field_id]); } } // 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]); unset($current_entry[$key]); } } } // now delete remaining values from the old entry if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $meta_key) { if (isset($current_entry[$meta_key])) { gform_delete_meta($entry_id, $meta_key); unset($current_entry[$meta_key]); } } } foreach ($current_entry as $k => $v) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $k); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $k, ""); if (false === $result) { return new WP_Error("update_field_values_failed", __("There was a problem while updating the field values", "gravityforms"), $wpdb->last_error); } } return true; }
public function remove() { $key = $this->get_status_key(); gform_delete_meta($this->step->get_entry_id(), $key); gform_delete_meta($this->step->get_entry_id(), $key . '_timestamp'); }
/** * pluploader_trash_checkbox * * Called by 'gform_update_status' gravity forms action. * Handles the meta data for an entry relating to the deletion * of any plupload files attached the entry. * * @access public * @author Ben Moody */ public function pluploader_trash_checkbox($lead_id, $property_value, $previous_value) { if (isset($property_value) && $property_value === 'trash') { if (isset($_POST['prso_pluploader_delete_uploads']) && $_POST['prso_pluploader_delete_uploads'] === 'on') { //Update delete file meta for this entry gform_update_meta($lead_id, self::$delete_files_meta_key, 'checked'); } else { //Update delete file meta for this entry gform_delete_meta($lead_id, self::$delete_files_meta_key); } } }
/** * Generate the markup for use in the meta box. * * @param array $form The current form. * @param array $entry The current entry. * * @return string */ public function get_panel_markup($form, $entry) { $html = ''; $conversation_id = $this->get_entry_converstaion_id($entry); /* If no Help Scout conversation was created, add a button to create it. */ if (!$conversation_id) { $url = add_query_arg(array('gf_helpscout' => 'process', 'lid' => $entry['id'])); $html .= '<a href="' . esc_url($url) . '" class="button">' . esc_html__('Create Conversation', 'gravityformshelpscout') . '</a>'; } if ($conversation_id) { try { $conversation = $this->api->getConversation($conversation_id); } catch (Exception $e) { gform_delete_meta($entry['id'], 'helpscout_conversation_id'); $this->log_error(__METHOD__ . '(): Could not get Help Scout conversation; ' . $e->getMessage()); return ''; } $html .= esc_html__('Conversation Id', 'gravityformshelpscout') . ': <a href="https://secure.helpscout.net/conversation/' . $conversation->getId() . '/' . $conversation->getNumber() . '/" target="_blank">' . $conversation->getId() . '</a><br /><br />'; $html .= esc_html__('Status', 'gravityformshelpscout') . ': ' . ucwords($conversation->getStatus()) . '<br /><br />'; $html .= esc_html__('Created At', 'gravityformshelpscout') . ': ' . GFCommon::format_Date($conversation->getCreatedAt(), false, 'Y/m/d', true) . '<br /><br />'; $html .= esc_html__('Last Updated At', 'gravityformshelpscout') . ': ' . GFCommon::format_Date($conversation->getModifiedAt(), false, 'Y/m/d', true) . '<br /><br />'; } return $html; }
public static function delete_lead($lead_id) { global $wpdb; if (!GFCommon::current_user_can_any("gravityforms_delete_entries")) { die(__("You don't have adequate permission to delete entries.", "gravityforms")); } do_action("gform_delete_lead", $lead_id); $lead_table = self::get_lead_table_name(); $lead_notes_table = self::get_lead_notes_table_name(); $lead_detail_table = self::get_lead_details_table_name(); $lead_detail_long_table = self::get_lead_details_long_table_name(); //deleting uploaded files self::delete_files($lead_id); //Delete from detail long $sql = $wpdb->prepare(" DELETE FROM {$lead_detail_long_table}\n WHERE lead_detail_id IN(\n SELECT id FROM {$lead_detail_table} WHERE lead_id=%d\n )", $lead_id); $wpdb->query($sql); //Delete from lead details $sql = $wpdb->prepare("DELETE FROM {$lead_detail_table} WHERE lead_id=%d", $lead_id); $wpdb->query($sql); //Delete from lead notes $sql = $wpdb->prepare("DELETE FROM {$lead_notes_table} WHERE lead_id=%d", $lead_id); $wpdb->query($sql); //Delete from lead meta gform_delete_meta($lead_id); //Delete from lead $sql = $wpdb->prepare("DELETE FROM {$lead_table} WHERE id=%d", $lead_id); $wpdb->query($sql); }
/** * Cancels the workflow for the given Entry ID. Removes the assignees, adds a note in the entry's timeline and logs the event. * * @param array $entry The entry * @return bool True for success. False if not currently in a workflow. */ public function cancel_workflow($entry) { $entry_id = absint($entry['id']); $form = GFAPI::get_form($this->form_id); $step = $this->get_current_step($entry); if (!$step) { return false; } $assignees = $step->get_assignees(); foreach ($assignees as $assignee) { $assignee->remove(); } gform_update_meta($entry_id, 'workflow_final_status', 'cancelled'); gform_delete_meta($entry_id, 'workflow_step'); $feedback = esc_html__('Workflow cancelled.', 'gravityflow'); gravity_flow()->add_timeline_note($entry_id, $feedback); gravity_flow()->log_event('workflow', 'cancelled', $form['id'], $entry_id); return true; }
public function process_workflow($form, $entry_id) { $entry = GFAPI::get_entry($entry_id); if (isset($entry['workflow_step'])) { $this->log_debug(__METHOD__ . '() - processing. entry id ' . $entry_id); $step_id = $entry['workflow_step']; $starting_step_id = $step_id; if (empty($step_id) && (empty($entry['workflow_final_status']) || $entry['workflow_final_status'] == 'pending')) { $this->log_debug(__METHOD__ . '() - not yet started workflow. starting.'); // Starting workflow $form_id = absint($form['id']); $step = $this->get_first_step($form_id, $entry); $this->log_event('workflow', 'started', $form['id'], $entry_id); if ($step) { $step->start(); $this->log_debug(__METHOD__ . '() - started.'); } else { $this->log_debug(__METHOD__ . '() - no first step.'); } } else { $this->log_debug(__METHOD__ . '() - resuming workflow.'); $step = $this->get_step($step_id, $entry); } $step_complete = false; if ($step) { $step_id = $step->get_id(); $step_complete = $step->end_if_complete(); $this->log_debug(__METHOD__ . '() - step ' . $step_id . ' complete: ' . ($step_complete ? 'yes' : 'no')); } while ($step_complete && $step) { $this->log_debug(__METHOD__ . '() - getting next step.'); $step = $this->get_next_step($step, $entry, $form); $step_complete = false; if ($step) { $step_id = $step->get_id(); $step_complete = $step->start(); if ($step_complete) { $step->end(); } } $entry['workflow_step'] = $step_id; } if ($step == false) { $this->log_debug(__METHOD__ . '() - ending workflow.'); gform_delete_meta($entry_id, 'workflow_step'); $step_status = gform_get_meta($entry_id, 'workflow_step_status_' . $step_id); if (empty($step_status)) { $step_status = 'complete'; } gform_update_meta($entry_id, 'workflow_final_status', $step_status); gform_delete_meta($entry_id, 'workflow_step_status'); $entry_created_timestamp = strtotime($entry['date_created']); $duration = time() - $entry_created_timestamp; $this->log_event('workflow', 'ended', $form['id'], $entry_id, $step_status, 0, $duration); do_action('gravityflow_workflow_complete', $entry_id, $form, $step_status); // Refresh entry after action. $entry = GFAPI::get_entry($entry_id); GFAPI::send_notifications($form, $entry, 'workflow_complete'); } else { $this->log_debug(__METHOD__ . '() - not ending workflow.'); $step_id = $step->get_id(); gform_update_meta($entry_id, 'workflow_step', $step_id); } do_action('gravityflow_post_process_workflow', $form, $entry_id, $step_id, $starting_step_id); } }
public function create_payment($entry, $action) { if (!$this->is_valid_credentials()) { return; } $feeds = $this->get_feeds_by_entry($entry['id']); $feed = $this->get_feed(rgar($feeds, 0)); // see if a payment should automatically be created for the invoice. if (rgar($feed['meta'], 'createPayment')) { $id = gform_get_meta($entry['id'], 'freshbooks_invoice_id'); $payment = new FreshBooks_Payment(); $payment->invoiceId = $id; $payment->amount = rgar($action, 'amount'); $payment->type = rgar($action, 'payment_method') == 'PayPal' ? 'PayPal' : 'Credit Card'; $payment->notes = rgar($action, 'note'); $this->log_debug(__METHOD__ . '(): Creating a payment => ' . print_r($payment, 1)); $payment->create(); $lastError = $payment->lastError; if (empty($lastError)) { $this->log_debug(__METHOD__ . '(): Payment created.'); $this->handle_note_and_send_by_email(rgar($feed['meta'], 'sendByEmail'), 'invoice', $id, $entry); gform_delete_meta($entry['id'], 'freshbooks_invoice_id'); } else { $this->log_error(__METHOD__ . "(): The following error occurred when trying to create the payment: {$lastError}"); } } }