function set_post_content($entry, $form)
{
    //$headers[] = "Content-type: text/html";
    $pending_meta_value = gform_get_meta($entry["id"], "is_pending");
    if ($pending_meta_value == "1") {
        // wp_mail('*****@*****.**', 'Form has been saved', print_r($entry, true), $headers);
        $entry["orderStatus"] = "incomplete";
        $output = GFAPI::update_entry($entry, $entry["id"]);
    } else {
        $entry["orderStatus"] = "complete";
        $entry["unique_id"] = guid();
        //wp_mail('*****@*****.**', 'Getting the Gravity Form Field IDs', print_r($entry, true), $headers);
        //wp_mail('*****@*****.**', 'Getting the Gravity Form Data', print_r($form, true), $headers);
        $output = GFAPI::update_entry($entry, $entry["id"]);
        global $wpdb;
        //look up row in lead table, update asic status and update with eCompanies order number.
        $update = $wpdb->query($wpdb->prepare("UPDATE wp_rg_lead SET unique_id='" . $entry["unique_id"] . "' WHERE id=" . $entry['id'] . " AND form_id=" . $entry['form_id']));
        // wp_mail('*****@*****.**', 'Getting the Gravity Form Field IDs', print_r($update, true), $headers);
    }
}
Exemplo n.º 2
1
function pre_submission_handler($form)
{
    if ($_SERVER["REDIRECT_URL"] == "/edit-page/") {
        //submitted new values that need to be used to update the original entry via $success = GFAPI::update_entry( $entry );
        //var_dump($_POST);
        //Get original entry id
        parse_str($_SERVER["QUERY_STRING"]);
        //will be stored in $entry
        //get the actual entry we want to edit
        $editentry = GFAPI::get_entry($entry);
        //make changes to it from new values in $_POST, this shows only the first field update
        $editentry[1] = $_POST["input_1"];
        //update it
        $updateit = GFAPI::update_entry($editentry);
        if (is_wp_error($updateit)) {
            echo "Error.";
        } else {
            //success, so redirect
            header("Location: http://domain.com/confirmation/");
        }
        //dont process and create new entry
        die;
    } else {
        //any other code you want in this hook for regular entry submit
    }
}
 /**
  * Update entry
  *
  * @param array $entry
  */
 public static function update_entry($entry)
 {
     /*
      * GFFormsModel::update_lead() is no longer in use since version 1.8.8! Instead use GFAPI::update_entry().
      *
      * @see https://github.com/wp-premium/gravityforms/blob/1.8.13/forms_model.php#L587-L624
      * @see https://github.com/wp-premium/gravityforms/blob/1.8.13/includes/api.php#L495-L654
      * @see https://github.com/wp-premium/gravityforms/blob/1.8.7.11/forms_model.php#L587-L621
      */
     if (Pronamic_WP_Pay_Class::method_exists('GFAPI', 'update_entry')) {
         GFAPI::update_entry($entry);
     } elseif (Pronamic_WP_Pay_Class::method_exists('GFFormsModel', 'update_lead')) {
         GFFormsModel::update_lead($entry);
     }
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 public function put_entries($data, $entry_id = null)
 {
     $this->authorize("gravityforms_edit_entries");
     $result = empty($entry_id) ? GFAPI::update_entries($data) : ($result = GFAPI::update_entry($data, $entry_id));
     if (is_wp_error($result)) {
         $response = $this->get_error_response($result);
         $status = $this->get_error_status($result);
     } else {
         $status = 200;
         $response = empty($entry_id) ? __("Entries updated successfully", "gravityforms") : __("Entry updated successfully", "gravityforms");
     }
     $this->end($status, $response);
 }
 /**
  * Used to start a new subscription. Updates the associcated entry with the payment and transaction details and adds an entry note.
  *
  * @param  [array]  $entry           Entry object
  * @param  [string] $subscription_id ID of the subscription
  * @param  [float]  $amount          Numeric amount of the initial subscription payment
  *
  * @return [array]  $entry           Entry Object
  */
 public function start_subscription($entry, $subscription)
 {
     $this->log_debug(__METHOD__ . '(): Processing request.');
     if (!$this->has_subscription($entry)) {
         $entry['payment_status'] = 'Active';
         $entry['payment_amount'] = $subscription['amount'];
         $entry['payment_date'] = gmdate('y-m-d H:i:s');
         $entry['transaction_id'] = $subscription['subscription_id'];
         $entry['transaction_type'] = '2';
         // subscription
         $entry['is_fulfilled'] = '1';
         $result = GFAPI::update_entry($entry);
         $this->add_note($entry['id'], sprintf(esc_html__('Subscription has been created. Subscription Id: %s.', 'gravityforms'), $subscription['subscription_id']), 'success');
         /**
          * Fires when someone starts a subscription
          *
          * @param array $entry Entry Object
          * @param array $subscription The new Subscription object
          */
         do_action('gform_post_subscription_started', $entry, $subscription);
         if (has_filter('gform_post_subscription_started')) {
             $this->log_debug(__METHOD__ . '(): Executing functions hooked to gform_post_subscription_started.');
         }
         $subscription['type'] = 'create_subscription';
         $this->post_payment_action($entry, $subscription);
     }
     return $entry;
 }
 /**
  * Used to start a new subscription. Updates the associcated entry with the payment and transaction details and adds an entry note.
  *
  * @param  [array]  $entry           Entry object
  * @param  [string] $subscription_id ID of the subscription
  * @param  [float]  $amount          Numeric amount of the initial subscription payment
  * @return [bool]   $result
  */
 public function start_subscription($entry, $subscription)
 {
     $entry['payment_status'] = 'Active';
     $entry['payment_amount'] = $subscription['amount'];
     $entry['payment_date'] = gmdate('y-m-d H:i:s');
     $entry['transaction_id'] = $subscription['subscription_id'];
     $entry['transaction_type'] = '2';
     // subscription
     $entry['is_fulfilled'] = true;
     $result = GFAPI::update_entry($entry);
     $this->add_note($entry['id'], sprintf(__('Subscription has been created. Subscriber Id: %s.', 'gravityforms'), $subscription['subscription_id']));
 }
 /**
  * Loop through the fields being edited and if they include Post fields, update the Entry's post object
  *
  * @param array $form Gravity Forms form
  *
  * @return void
  */
 function maybe_update_post_fields($form)
 {
     $post_id = $this->entry['post_id'];
     // Security check
     if (false === GVCommon::has_cap('edit_post', $post_id)) {
         do_action('gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id);
         return;
     }
     $update_entry = false;
     $updated_post = $original_post = get_post($post_id);
     foreach ($this->entry as $field_id => $value) {
         //todo: only run through the edit entry configured fields
         $field = RGFormsModel::get_field($form, $field_id);
         if (class_exists('GF_Fields')) {
             $field = GF_Fields::create($field);
         }
         if (GFCommon::is_post_field($field)) {
             // Get the value of the field, including $_POSTed value
             $value = RGFormsModel::get_field_value($field);
             // Convert the field object in 1.9 to an array for backward compatibility
             $field_array = GVCommon::get_field_array($field);
             switch ($field_array['type']) {
                 case 'post_title':
                 case 'post_content':
                 case 'post_excerpt':
                     $updated_post->{$field_array['type']} = $value;
                     break;
                 case 'post_tags':
                     wp_set_post_tags($post_id, $value, false);
                     break;
                 case 'post_category':
                     $categories = is_array($value) ? array_values($value) : (array) $value;
                     $categories = array_filter($categories);
                     wp_set_post_categories($post_id, $categories, false);
                     // prepare value to be saved in the entry
                     $field = GFCommon::add_categories_as_choices($field, '');
                     // if post_category is type checkbox, then value is an array of inputs
                     if (isset($value[strval($field_id)])) {
                         foreach ($value as $input_id => $val) {
                             $input_name = 'input_' . str_replace('.', '_', $input_id);
                             $this->entry[strval($input_id)] = RGFormsModel::prepare_value($form, $field, $val, $input_name, $this->entry['id']);
                         }
                     } else {
                         $input_name = 'input_' . str_replace('.', '_', $field_id);
                         $this->entry[strval($field_id)] = RGFormsModel::prepare_value($form, $field, $value, $input_name, $this->entry['id']);
                     }
                     break;
                 case 'post_custom_field':
                     $input_type = RGFormsModel::get_input_type($field);
                     $custom_field_name = $field_array['postCustomFieldName'];
                     // Only certain custom field types are supported
                     if (!in_array($input_type, array('list', 'fileupload'))) {
                         update_post_meta($post_id, $custom_field_name, $value);
                     }
                     break;
                 case 'post_image':
                     $value = '';
                     break;
             }
             //ignore fields that have not changed
             if ($value === rgget((string) $field_id, $this->entry)) {
                 continue;
             }
             // update entry
             if ('post_category' !== $field->type) {
                 $this->entry[strval($field_id)] = $value;
             }
             $update_entry = true;
         }
     }
     if ($update_entry) {
         $return_entry = GFAPI::update_entry($this->entry);
         if (is_wp_error($return_entry)) {
             do_action('gravityview_log_error', 'Updating the entry post fields failed', $return_entry);
         } else {
             do_action('gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded');
         }
     }
     $return_post = wp_update_post($updated_post, true);
     if (is_wp_error($return_post)) {
         do_action('gravityview_log_error', 'Updating the post content failed', $return_post);
     } else {
         do_action('gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded');
     }
 }
 /**
  * Delete entries
  * This function is used to delete entries with an ajax request
  * Could use better (or at least some) error handling
  */
 public function maybe_delete_entry()
 {
     if (isset($_POST["mode"]) && $_POST["mode"] == "delete" && isset($_POST["delete_id"]) && isset($_POST["form_id"])) {
         $form_id = $_POST["form_id"];
         $form = GFAPI::get_form($form_id);
         $settings = $this->get_form_settings($form);
         $enable_delete = $settings["enable_delete"];
         $delete_type = $settings["delete_type"];
         if ($enable_delete) {
             $delete_id = $_POST["delete_id"];
             $entry = GFAPI::get_entry($delete_id);
             if (!is_wp_error($entry)) {
                 if ($entry["created_by"] == $this->stickylist_get_current_user() || current_user_can('delete_others_posts') || current_user_can('stickylist_delete_entries')) {
                     if ($_POST["delete_post_id"] != null) {
                         $delete_post_id = $_POST["delete_post_id"];
                     } else {
                         $delete_post_id = "";
                     }
                     if ($delete_type == "trash") {
                         $entry["status"] = "trash";
                         $success = GFAPI::update_entry($entry, $delete_id);
                         if ($delete_post_id != "") {
                             wp_delete_post($delete_post_id, false);
                         }
                     }
                     if ($delete_type == "permanent") {
                         $success = GFAPI::delete_entry($delete_id);
                         if ($delete_post_id != "") {
                             wp_delete_post($delete_post_id, true);
                         }
                     }
                     if ($success) {
                         $notifications = $form["notifications"];
                         $notification_ids = array();
                         foreach ($notifications as $notification) {
                             $notification_type = $notification["stickylist_notification_type"];
                             if ($notification_type == "delete" || $notification_type == "all") {
                                 $id = $notification["id"];
                                 array_push($notification_ids, $id);
                             }
                         }
                         GFCommon::send_notifications($notification_ids, $form, $entry);
                     }
                 }
             }
         }
     }
 }
 protected function process_capture($authorization, $feed, $submission_data, $form, $entry)
 {
     $payment = rgar($authorization, "captured_payment");
     if (empty($payment)) {
         return;
     }
     if ($payment["is_success"]) {
         $entry["transaction_id"] = $payment["transaction_id"];
         $entry["transaction_type"] = "1";
         $entry["is_fulfilled"] = true;
         $entry["currency"] = GFCommon::get_currency();
         $entry["payment_amount"] = $payment["amount"];
         $entry["payment_status"] = "Paid";
         $entry["payment_date"] = gmdate("Y-m-d H:i:s");
         $entry["payment_method"] = $payment["payment_method"];
         $this->insert_transaction($entry["id"], "payment", $entry["transaction_id"], $entry["payment_amount"]);
         GFFormsModel::add_note($entry["id"], 0, "System", sprintf(__("Payment has been captured successfully. Amount: %s. Transaction Id: %s", "gravityforms"), GFCommon::to_money($payment["amount"], $entry["currency"]), $payment["transaction_id"]));
     } else {
         $entry["payment_status"] = "Failed";
         GFFormsModel::add_note($entry["id"], 0, "System", sprintf(__("Payment failed to be captured. Reason: %s", "gravityforms"), $payment["error_message"]));
     }
     GFAPI::update_entry($entry);
     return $entry;
 }
function sticky_set_post_content($entry, $form)
{
    if ($form['isSticky']) {
        if (is_user_logged_in()) {
            $saved_option_key = sticky_getEntryOptionKeyForGF($form);
            $saved_option_value = get_option($saved_option_key);
            // Save the entry ID in wp_options if this is the first time the form is submitted by this user.
            // If we dont have a saved value, we save the entry ID
            if (!$saved_option_value) {
                update_option($saved_option_key, $entry['id']);
                //If we have a saved value, update and delete
            } else {
                // ...as long as the form doesnt allow multiple entries...
                if (!$form['isEnableMulipleEntry']) {
                    // We dont want to loose our starred and read status when we update
                    $original_entry = RGFormsModel::get_lead($saved_option_value);
                    $entry["is_starred"] = $original_entry["is_starred"];
                    // ...unless the user wants us to
                    if (!isset($form['isMarkUnread'])) {
                        $entry["is_read"] = $original_entry["is_read"];
                    }
                    $success = GFAPI::update_entry($entry, $saved_option_value);
                    $success = GFAPI::delete_entry($entry["id"]);
                    // ...and if it does, dont delete or update but save the new entry ID instead so that the sticky form is populated with the latest saved entry.
                } else {
                    update_option($saved_option_key, $entry['id']);
                }
            }
        }
    }
}
Exemplo n.º 12
0
 /**
  * @param $object
  * @param $fields
  *
  * @return mixed
  */
 function update_object($entry_id = '', $entry = array())
 {
     return GFAPI::update_entry($entry_id, $entry);
 }
 /**
  * form entry post-submission processing
  * @param array $entry
  * @param array $form
  * @return array
  */
 public function gformEntryPostSave($entry, $form)
 {
     if (!empty($this->txResult['payment_status'])) {
         foreach ($this->txResult as $key => $value) {
             switch ($key) {
                 case 'payment_status':
                 case 'payment_date':
                 case 'payment_amount':
                 case 'transaction_id':
                 case 'transaction_type':
                 case 'payment_gateway':
                     // custom entry meta must be saved with entry
                 // custom entry meta must be saved with entry
                 case 'authcode':
                     // custom entry meta must be saved with entry
                     // update entry
                     $entry[$key] = $value;
                     break;
                 default:
                     // update entry meta
                     gform_update_meta($entry['id'], $key, $value);
                     break;
             }
         }
         // update the entry
         if (class_exists('GFAPI')) {
             GFAPI::update_entry($entry);
         } else {
             GFFormsModel::update_lead($entry);
         }
     }
     return $entry;
 }
 function gfee_after_submission($tmp_entry, $form)
 {
     // get the original entry we want to edit/update
     GFEE::set_entry_id($_POST['gfee_entry_id']);
     // NEED TO BEEF UP SECURITY HERE AS THIS VALUE CAN BE MODIFIED BY USER TO EDIT SOMEONE ELSE'S ENTRY
     $orig_entry_id = GFEE::$entry_id;
     $orig_entry = GFAPI::get_entry($orig_entry_id);
     // initialize deletefiles variable
     $deletefiles = array();
     // take care of certain fields that need special handling
     foreach ($form['fields'] as $field) {
         // don't touch admin-only fields since front-end can't modify those
         if (!$field['adminOnly']) {
             // handle file uploads
             if ($field['type'] == 'fileupload') {
                 // if user has deleted this file upload, save to list to delete later
                 if ($_POST['delete_file'] == $field['id']) {
                     $delete_file_path = get_file_path_from_gf_entry($orig_entry[$field['id']]);
                     $deletefiles[] = $delete_file_path;
                     // save new file upload field data
                     $orig_entry[$field['id']] = $tmp_entry[$field['id']];
                 }
                 // this currently only supports one file per field
                 if ($tmp_entry[$field['id']]) {
                     // new file(s) uploaded, we need to copy the files because the originals will be deleted with the temp entry by Gravity Forms
                     $file_path = get_file_path_from_gf_entry($tmp_entry[$field['id']]);
                     $tmp_file_path = $file_path . '.tmp';
                     copy($file_path, $tmp_file_path);
                     // save new file upload field data
                     $orig_entry[$field['id']] = $tmp_entry[$field['id']];
                 }
                 // handle checkboxes, address, and name fields
             } elseif ($field['type'] == 'checkbox' || $field['type'] == 'address' || $field['type'] == 'name') {
                 foreach ($field->inputs as $key => $input) {
                     // loop each field input and save it
                     $orig_entry[strval($input['id'])] = $tmp_entry[strval($input['id'])];
                 }
             } else {
                 // save updated field data to original entry
                 $orig_entry[$field['id']] = $tmp_entry[$field['id']];
             }
         }
     }
     // perform update entry with original entry data fields updated
     $update_success = GFAPI::update_entry($orig_entry);
     if ($update_success === true) {
         // delete temporary entry
         $delete_success = GFAPI::delete_entry($tmp_entry['id']);
         // delete any lingering files that shouldn't be around anymore
         foreach ($deletefiles as $filename) {
             if (file_exists($filename)) {
                 unlink($filename);
             }
         }
         // original file(s) should be deleted by Gravity Forms or us, need to rename temp file back to original name
         if ($tmp_file_path) {
             rename($tmp_file_path, $file_path);
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Loop through the fields being edited and if they include Post fields, update the Entry's post object
  *
  * @param array $form Gravity Forms form
  *
  * @return void
  */
 private function maybe_update_post_fields($form)
 {
     $post_id = $this->entry['post_id'];
     // Security check
     if (false === GVCommon::has_cap('edit_post', $post_id)) {
         do_action('gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id);
         return;
     }
     $update_entry = false;
     $updated_post = $original_post = get_post($post_id);
     foreach ($this->entry as $field_id => $value) {
         $field = RGFormsModel::get_field($form, $field_id);
         if (!$field) {
             continue;
         }
         if (GFCommon::is_post_field($field) && 'post_category' !== $field->type) {
             // Get the value of the field, including $_POSTed value
             $value = RGFormsModel::get_field_value($field);
             // Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
             $entry_tmp = $this->entry;
             $entry_tmp["{$field_id}"] = $value;
             switch ($field->type) {
                 case 'post_title':
                     $post_title = $value;
                     if (rgar($form, 'postTitleTemplateEnabled')) {
                         $post_title = $this->fill_post_template($form['postTitleTemplate'], $form, $entry_tmp);
                     }
                     $updated_post->post_title = $post_title;
                     $updated_post->post_name = $post_title;
                     unset($post_title);
                     break;
                 case 'post_content':
                     $post_content = $value;
                     if (rgar($form, 'postContentTemplateEnabled')) {
                         $post_content = $this->fill_post_template($form['postContentTemplate'], $form, $entry_tmp, true);
                     }
                     $updated_post->post_content = $post_content;
                     unset($post_content);
                     break;
                 case 'post_excerpt':
                     $updated_post->post_excerpt = $value;
                     break;
                 case 'post_tags':
                     wp_set_post_tags($post_id, $value, false);
                     break;
                 case 'post_category':
                     break;
                 case 'post_custom_field':
                     if (!empty($field->customFieldTemplateEnabled)) {
                         $value = $this->fill_post_template($field->customFieldTemplate, $form, $entry_tmp, true);
                     }
                     $input_type = RGFormsModel::get_input_type($field);
                     // Only certain custom field types are supported
                     switch ($input_type) {
                         case 'fileupload':
                         case 'list':
                         case 'multiselect':
                             if (!is_string($value)) {
                                 $value = function_exists('wp_json_encode') ? wp_json_encode($value) : json_encode($value);
                             }
                             // break; left intentionally out
                         // break; left intentionally out
                         default:
                             update_post_meta($post_id, $field->postCustomFieldName, $value);
                     }
                     break;
                 case 'post_image':
                     $value = $this->update_post_image($form, $field, $field_id, $value, $this->entry, $post_id);
                     break;
             }
             // update entry after
             $this->entry["{$field_id}"] = $value;
             $update_entry = true;
             unset($entry_tmp);
         }
     }
     if ($update_entry) {
         $return_entry = GFAPI::update_entry($this->entry);
         if (is_wp_error($return_entry)) {
             do_action('gravityview_log_error', 'Updating the entry post fields failed', array('$this->entry' => $this->entry, '$return_entry' => $return_entry));
         } else {
             do_action('gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded');
         }
     }
     $return_post = wp_update_post($updated_post, true);
     if (is_wp_error($return_post)) {
         $return_post->add_data($updated_post, '$updated_post');
         do_action('gravityview_log_error', 'Updating the post content failed', compact('updated_post', 'return_post'));
     } else {
         do_action('gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded', $updated_post);
     }
 }
Exemplo n.º 16
0
 public function put_entries($data, $entry_id = null)
 {
     $capability = apply_filters('gform_web_api_capability_put_entries', 'gravityforms_edit_entries');
     $this->authorize($capability);
     $result = empty($entry_id) ? GFAPI::update_entries($data) : ($result = GFAPI::update_entry($data, $entry_id));
     if (is_wp_error($result)) {
         $response = $this->get_error_response($result);
         $status = $this->get_error_status($result);
     } else {
         $status = 200;
         $response = empty($entry_id) ? __('Entries updated successfully', 'gravityforms') : __('Entry updated successfully', 'gravityforms');
     }
     $this->end($status, $response);
 }
Exemplo n.º 17
0
 function test_assignee_field()
 {
     $form = GFAPI::get_form($this->form_id);
     $assignee_field_properties_json = '{"type":"workflow_assignee_select","id":6,"label":"Assignee","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":93,"pageNumber":1,"choices":"","conditionalLogic":"","displayOnly":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"inputMask":false,"inputMaskValue":"","allowsPrepopulate":false,"gravityflowAssigneeFieldShowUsers":true,"gravityflowAssigneeFieldShowRoles":true,"gravityflowAssigneeFieldShowFields":true,"cssClass":""}';
     $assignee_field_properties = json_decode($assignee_field_properties_json, true);
     $assignee_field_properties['id'] = 999;
     $assignee_field = new Gravity_Flow_Field_Assignee_Select($assignee_field_properties);
     $form['fields'][] = $assignee_field;
     GFAPI::update_form($form);
     $step_settings = array('assignees' => array('assignee_field|999'));
     $step1_id = $this->_add_user_input_step($step_settings);
     $this->_create_entries();
     $entries = GFAPI::get_entries($this->form_id);
     $entry = $entries[0];
     $entry_id = $entry['id'];
     $entry[999] = 'user_id|1';
     GFAPI::update_entry($entry);
     // simulate submission
     gravity_flow()->maybe_process_feed($entry, $form);
     $this->api->process_workflow($entry_id);
     $entry = GFAPI::get_entry($entry_id);
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('pending', $status);
     // Complete
     $step1 = $this->api->get_step($step1_id, $entry);
     $step1->update_user_status(1, 'complete');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('complete', $status);
 }
 function update_object($entry_id, $entry)
 {
     $entry['id'] = $entry_id;
     return GFAPI::update_entry($entry);
 }
Exemplo n.º 19
0
 public function put_entries($data, $entry_id = null)
 {
     $this->log_debug(__METHOD__ . '(): Running.');
     $capability = apply_filters('gform_web_api_capability_put_entries', 'gravityforms_edit_entries');
     $this->authorize($capability);
     $entries = array();
     if (empty($entry_id)) {
         foreach ($data as $entry) {
             $entries[] = $this->maybe_serialize_list_fields($entry);
         }
         $result = GFAPI::update_entries($entries);
     } else {
         $entry = $this->maybe_serialize_list_fields($data);
         $result = GFAPI::update_entry($entry, $entry_id);
     }
     if (is_wp_error($result)) {
         $response = $this->get_error_response($result);
         $status = $this->get_error_status($result);
     } else {
         $status = 200;
         $response = empty($entry_id) ? __('Entries updated successfully', 'gravityforms') : __('Entry updated successfully', 'gravityforms');
     }
     $this->end($status, $response);
 }
 public function updateAuthorizationEntry($entry, $result = array())
 {
     if (isset($result['securesubmit_payment_action']) && $result['securesubmit_payment_action'] == 'authorize' && isset($result['is_success']) && $result['is_success']) {
         $entry['payment_status'] = __('Authorized', 'gravityforms-securesubmit');
         GFAPI::update_entry($entry);
     }
     return $entry;
 }
Exemplo n.º 21
0
 public function admin_update_payment($form, $entry_id)
 {
     check_admin_referer('gforms_save_entry', 'gforms_save_entry');
     //update payment information in admin, need to use this function so the lead data is updated before displayed in the sidebar info section
     $entry = GFFormsModel::get_lead($entry_id);
     if ($this->payment_details_editing_disabled($entry, 'update')) {
         return;
     }
     //get payment fields to update
     $payment_status = rgpost('payment_status');
     //when updating, payment status may not be editable, if no value in post, set to lead payment status
     if (empty($payment_status)) {
         $payment_status = $entry['payment_status'];
     }
     $payment_amount = GFCommon::to_number(rgpost('payment_amount'));
     $payment_transaction = rgpost('paypal_transaction_id');
     $payment_date = rgpost('payment_date');
     if (empty($payment_date)) {
         $payment_date = gmdate('y-m-d H:i:s');
     } else {
         //format date entered by user
         $payment_date = date('Y-m-d H:i:s', strtotime($payment_date));
     }
     global $current_user;
     $user_id = 0;
     $user_name = 'System';
     if ($current_user && ($user_data = get_userdata($current_user->ID))) {
         $user_id = $current_user->ID;
         $user_name = $user_data->display_name;
     }
     $entry['payment_status'] = $payment_status;
     $entry['payment_amount'] = $payment_amount;
     $entry['payment_date'] = $payment_date;
     $entry['transaction_id'] = $payment_transaction;
     // if payment status does not equal approved/paid or the lead has already been fulfilled, do not continue with fulfillment
     if (($payment_status == 'Approved' || $payment_status == 'Paid') && !$entry['is_fulfilled']) {
         $action['id'] = $payment_transaction;
         $action['type'] = 'complete_payment';
         $action['transaction_id'] = $payment_transaction;
         $action['amount'] = $payment_amount;
         $action['entry_id'] = $entry['id'];
         $this->complete_payment($entry, $action);
         $this->fulfill_order($entry, $payment_transaction, $payment_amount);
     }
     //update lead, add a note
     GFAPI::update_entry($entry);
     GFFormsModel::add_note($entry['id'], $user_id, $user_name, sprintf(__('Payment information was manually updated. Status: %s. Amount: %s. Transaction Id: %s. Date: %s', 'gravityformspaypal'), $entry['payment_status'], GFCommon::to_money($entry['payment_amount'], $entry['currency']), $payment_transaction, $entry['payment_date']));
 }
Exemplo n.º 22
0
 public static function aria_after_teacher_submission($form, $entry)
 {
     // Get the query variables from the link
     $student_hash = get_query_var("student_hash", false);
     $teacher_hash = get_query_var("teacher_hash", false);
     // Get field id arrays
     $student_master_field_ids = ARIA_Create_Master_Forms::aria_master_student_field_id_array();
     $teacher_master_field_ids = ARIA_Create_Master_Forms::aria_master_teacher_field_id_array();
     $teacher_public_field_ids = ARIA_Create_Competition::aria_master_teacher_field_id_array();
     // Update the teacher entry in the teacher master.
     $teacher_master_entry = ARIA_Registration_Handler::aria_find_teacher_entry($form["title"], $teacher_hash);
     if (!teacher_entry) {
         wp_die("Error");
     }
     $teacher_master_entry[(string) $teacher_master_field_ids['name']] = $entry[(string) $teacher_public_field_ids['name']];
     $teacher_master_entry[(string) $teacher_master_field_ids['email']] = $entry[(string) $teacher_public_field_ids['email']];
     $teacher_master_entry[(string) $teacher_master_field_ids['phone']] = $entry[(string) $teacher_public_field_ids['phone']];
     $teacher_master_entry[(string) $teacher_master_field_ids['volunteer_preference']] = $entry[(string) $teacher_public_field_ids['volunteer_preference']];
     $teacher_master_entry[(string) $teacher_master_field_ids['volunteer_time']] = $entry[(string) $teacher_public_field_ids['volunteer_time']];
     $teacher_master_entry[(string) $teacher_master_field_ids['is_judging']] = $entry[(string) $teacher_public_field_ids['is_judging']];
     // Update the student entry in the student master.
     $student_master_entry = ARIA_Registration_Handler::aria_find_student_entry($form["title"], $student_hash);
     if (!student_entry) {
         wp_die("Error");
     }
     $student_master_entry[(string) $student_master_field_ids['student_name']] = $entry[(string) $teacher_public_field_ids['student_name']];
     $student_master_entry[(string) $student_master_field_ids['song_1_period']] = $entry[(string) $teacher_public_field_ids['song_1_period']];
     $student_master_entry[(string) $student_master_field_ids['song_1_composer']] = $entry[(string) $teacher_public_field_ids['song_1_composer']];
     $student_master_entry[(string) $student_master_field_ids['song_1_selection']] = $entry[(string) $teacher_public_field_ids['song_1_selection']];
     $student_master_entry[(string) $student_master_field_ids['song_2_period']] = $entry[(string) $teacher_public_field_ids['song_2_period']];
     $student_master_entry[(string) $student_master_field_ids['song_2_composer']] = $entry[(string) $teacher_public_field_ids['song_2_composer']];
     $student_master_entry[(string) $student_master_field_ids['song_2_selection']] = $entry[(string) $teacher_public_field_ids['song_2_selection']];
     $student_master_entry[(string) $student_master_field_ids['theory_score']] = $entry[(string) $teacher_public_field_ids['theory_score']];
     $student_master_entry[(string) $student_master_field_ids['alternate_theory']] = $entry[(string) $teacher_public_field_ids['alternate_theory']];
     $student_master_entry[(string) $student_master_field_ids['competition_format']] = $entry[(string) $teacher_public_field_ids['competition_format']];
     $student_master_entry[(string) $student_master_field_ids['timing_of_pieces']] = $entry[(string) $teacher_public_field_ids['timing_of_pieces']];
     $teacher_result = GFAPI::update_entry($teacher_master_entry);
     $student_result = GFAPI::update_entry($student_master_entry);
 }
 /**
  * Used to start a new subscription. Updates the associcated entry with the payment and transaction details and adds an entry note.
  *
  * @param  [array]  $entry           Entry object
  * @param  [string] $subscription_id ID of the subscription
  * @param  [float]  $amount          Numeric amount of the initial subscription payment
  * @return [array]  $entry           Entry Object
  */
 public function start_subscription($entry, $subscription)
 {
     if (!$this->has_subscription($entry)) {
         $entry['payment_status'] = 'Active';
         $entry['payment_amount'] = $subscription['amount'];
         $entry['payment_date'] = gmdate('y-m-d H:i:s');
         $entry['transaction_id'] = $subscription['subscription_id'];
         $entry['transaction_type'] = '2';
         // subscription
         $entry['is_fulfilled'] = '1';
         $result = GFAPI::update_entry($entry);
         $this->add_note($entry['id'], sprintf(__('Subscription has been created. Subscription Id: %s.', 'gravityforms'), $subscription['subscription_id']), "success");
         do_action("gform_post_subscription_started", $entry, $subscription);
     }
     return $entry;
 }
 /**
  * Update the user's form entry data
  */
 private function update_entry($entry)
 {
     $entry_id = isset($_SESSION['gform_sayg_entry_id_' . $entry['form_id']]) ? $_SESSION['gform_sayg_entry_id_' . $entry['form_id']] : NULL;
     $updated_entry = GFAPI::update_entry($entry, $entry_id);
 }
Exemplo n.º 25
0
 /**
  * update_approved function.
  *
  * @access public
  * @static
  * @param int $lead_id (default: 0)
  * @param int $approved (default: 0)
  * @param int $form_id (default: 0)
  * @param int $approvedcolumn (default: 0)
  * @return boolean True: It worked; False: it failed
  */
 public static function update_approved($entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0)
 {
     if (!class_exists('GFAPI')) {
         do_action('gravityview_log_error', __METHOD__ . 'GFAPI does not exist');
         return false;
     }
     if (empty($approvedcolumn)) {
         $approvedcolumn = self::get_approved_column($form_id);
     }
     //get the entry
     $entry = GFAPI::get_entry($entry_id);
     //update entry
     $entry[(string) $approvedcolumn] = $approved;
     /** @var bool|WP_Error $result */
     $result = GFAPI::update_entry($entry);
     /**
      * GFAPI::update_entry() doesn't trigger `gform_after_update_entry`, so we trigger updating the meta ourselves.
      */
     self::update_approved_meta($entry_id, $approved);
     // add note to entry
     if ($result === true) {
         $note = empty($approved) ? __('Disapproved the Entry for GravityView', 'gravityview') : __('Approved the Entry for GravityView', 'gravityview');
         if (class_exists('GravityView_Entry_Notes')) {
             global $current_user;
             get_currentuserinfo();
             GravityView_Entry_Notes::add_note($entry_id, $current_user->ID, $current_user->display_name, $note);
         }
         /**
          * Destroy the cache for this form
          * @see class-cache.php
          * @since 1.5.1
          */
         do_action('gravityview_clear_form_cache', $form_id);
     } else {
         if (is_wp_error($result)) {
             do_action('gravityview_log_error', __METHOD__ . sprintf(' - Entry approval not updated: %s', $result->get_error_message()));
             $result = false;
         }
     }
     return $result;
 }
 private function update_entry($form, $lead)
 {
     /*
      * Create a new $lead based on the $_POST values and merge 
      * them into the existing $lead array.
      */
     $post_lead = RGFormsModel::create_lead($form);
     /*
      * Final check that the current user can edit the entry 
      */
     if ($lead['created_by'] != $post_lead['created_by']) {
         /*
          * TODO: log error here 
          */
         return false;
     }
     /*
      * Refine the post lead and remove unwanted, restricted and hidden
      */
     $remove_keys = array('id', 'post_id', 'date_created', 'form_id', 'ip', 'source_url', 'user_agent', 'currency', 'created_by');
     foreach ($remove_keys as $k) {
         unset($post_lead[$k]);
     }
     $this->unset_lead_data($post_lead, $this->atts['restricted_fields']);
     $this->unset_lead_data($post_lead, $this->atts['hidden_fields']);
     foreach ($form['fields'] as $field) {
         switch (RGFormsModel::get_input_type($field)) {
             case "captcha":
             case "html":
             case "password":
             case "product":
             case "coupon":
             case "quantity":
             case "shipping":
             case "donation":
             case "total":
             case "singleproduct":
             case "hiddenproduct":
             case "singleshipping":
             case "creditcard":
             case "page":
             case "post_image":
             case "fileupload":
                 if (isset($post_lead[$field['id']])) {
                     unset($post_lead[$field['id']]);
                 }
                 break;
             default:
                 /*
                  * Check if the field is hidden on the form and then set the value to empty in the new array
                  */
                 if (RGFormsModel::is_field_hidden($form, $field, $post_lead)) {
                     /*
                      * Just reset all values to blank (even if they don't actually exist) 
                      * and we will handle the real merging below. This cuts back on checking field types 
                      * and adding particular overrides for particular fields. 
                      */
                     $post_lead[$field['id']] = '';
                     $post_lead[$field['id'] . '.1'] = '';
                     $post_lead[$field['id'] . '.2'] = '';
                     $post_lead[$field['id'] . '.3'] = '';
                     $post_lead[$field['id'] . '.4'] = '';
                     $post_lead[$field['id'] . '.5'] = '';
                     $post_lead[$field['id'] . '.6'] = '';
                 }
                 break;
         }
     }
     /* 
      * Now lets merge down the post lead with the original 
      * array_merge() doesn't function correctly because of the mixed indexes 
      * and array_replace is PHP5.3 and up, so instead we'll manually write the replace function
      */
     foreach ($lead as $key => $val) {
         /*
          * Check if 
          */
         if (isset($post_lead[$key])) {
             $lead[$key] = $post_lead[$key];
         }
     }
     /*
      * Now lets update the entry using the Gravity Forms API
      */
     $update = GFAPI::update_entry($lead);
     if (is_wp_error($update)) {
         /*
          * TODO: log error 
          */
         return false;
     }
     /* we reached hear so the lead was successfully updated */
     return true;
 }
 function gfdo_paypal_successful_payment($entry, $config, $transaction_id, $amount)
 {
     //Gravity Forms + DigitalOcean object
     $GFDO = new GFDigitalOcean();
     //Log it up
     $GFDO->log_debug(__("GFDO - PAYPAL SUCCESFUL PAYMENT"));
     $GFDO->log_debug("ENTRY : " . print_r($entry, true));
     $GFDO->log_debug("CONFIG : " . print_r($config, true));
     //NULL the Droplet
     $newDroplet = null;
     //Get the form
     $form = GFFormsModel::get_form_meta($entry['form_id']);
     //Keep on loggin' in the free world
     $GFDO->log_debug("NEW FORM OBJECT : " . print_r($form, true));
     //Get form settings
     $form_settings = $GFDO->get_form_settings($form);
     //Get add-on settings
     $addon_settings = $GFDO->get_plugin_settings();
     //If it's not enabled, exit
     if (!$addon_settings || !$form_settings || !$form_settings["isEnabled"]) {
         return;
     }
     //API token
     $DOToken = $addon_settings["digitalocean_token"];
     //Return if token empty
     if (empty($DOToken)) {
         return;
     }
     //Get the chosen settings for the droplet
     $droplet_size = $form_settings["selectDropletSize"];
     $droplet_name = $entry[$form_settings["selectDropletName"]];
     $droplet_image = $form_settings["selectDropletImage"];
     $droplet_region = $form_settings["selectDropletRegion"];
     //Get all droplet names
     $allDropletNames = get_all_droplet_names($GFDO->get_plugin_settings());
     //If we don't have any existing droplets, don't bother continuing
     if ($allDropletNames != false) {
         //If the chosen droplet name already exists..
         if (in_array($droplet_name, $allDropletNames)) {
             //Append a '1' to the name if it exists
             $droplet_name = $droplet_name . "1";
         }
     }
     //Update the entry droplet name with our new one
     $entry["droplet_name"] = $droplet_name;
     //Create an API instance
     $adapter = new BuzzAdapter($DOToken);
     $do = new DigitalOceanV2($adapter);
     //Create a droplet object
     $droplet = $do->droplet();
     $form_settings['backupsEnabled'] == 1 ? $anyBackups = true : ($anyBackups = false);
     $form_settings['privateNetworkEnabled'] == 1 ? $anyPN = true : ($anyPN = false);
     //Any SSH keys?
     //Store them if so
     if ($form_settings['SSHKeysEnabled'] == 1) {
         $theSSHKeys = get_ssh_keys_as_array($form_settings);
     } else {
         $theSSHKeys = array();
     }
     //Create the droplet
     try {
         $newDroplet = $droplet->create($droplet_name, $droplet_region, $droplet_size, $droplet_image, $anyBackups, false, $anyPN, $theSSHKeys);
         $GFDO = new GFDigitalOcean();
         $GFDO->log_debug("DROPLET CREATED: " . print_r($newDroplet, true));
         $GFDO->log_debug("droplet_name: " . print_r($droplet_name, true));
         $GFDO->log_debug("droplet_region: " . print_r($droplet_region, true));
         $GFDO->log_debug("droplet_size: " . print_r($droplet_size, true));
         $GFDO->log_debug("droplet_image: " . print_r($droplet_image, true));
         $GFDO->log_debug("droplet_backups: " . print_r($anyBackups, true));
         $GFDO->log_debug("droplet_private_network: " . print_r($anyPN, true));
         $GFDO->log_debug("droplet_ssh_keys: " . print_r($theSSHKeys, true));
         //Get its status
         $dStatus = $newDroplet->status;
         //Get its ID
         $dId = $newDroplet->id;
         //Are domains enabled?
         if ($form_settings['domainEnabled'] == 1 && $form_settings['chooseDomain'] != "" && $dStatus == "new") {
             //2 mins from now
             $nowPlusTwo = time() + 120;
             //Schedule it for 2 mins from now as an event
             wp_schedule_single_event($nowPlusTwo, 'do_domain_for_droplet', array($DOToken, $dId, $entry[$form_settings['chooseDomain']]));
         }
         //Record the Droplet's ID
         $form_settings["droplet_id"] = trim($dId);
         $entry["droplet_id"] = trim($dId);
         //Record SSH Keys
         if (count($theSSHKeys > 0)) {
             $entry["ssh_keys"] = ssh_ids_to_names($addon_settings, $theSSHKeys);
         }
         //and the 'verdict'
         $form_settings["droplet_creation_success"] = trim($dStatus);
         //Save it all
         GFAPI::update_entry($entry);
         $this->save_form_settings($form, $form_settings);
         do_action('gfdo_after_droplet_creation', $newDroplet, $entry, $form);
     } catch (Exception $e) {
         $GFDO = new GFDigitalOcean();
         if ($e !== null) {
             $GFDO->log_debug("DROPLET NOT CREATED: " . $e);
         } else {
             $GFDO->log_debug("DROPLET NOT CREATED: ");
         }
         $GFDO->log_debug("droplet_name: " . print_r($droplet_name, true));
         $GFDO->log_debug("droplet_region: " . print_r($droplet_region, true));
         $GFDO->log_debug("droplet_size: " . print_r($droplet_size, true));
         $GFDO->log_debug("droplet_image: " . print_r($droplet_image, true));
         $GFDO->log_debug("droplet_backups: " . print_r($anyBackups, true));
         $GFDO->log_debug("droplet_private_network: " . print_r($anyPN, true));
         $GFDO->log_debug("droplet_ssh_keys: " . print_r($theSSHKeys, true));
         //Save it all
         GFAPI::update_entry($entry);
         $this->save_form_settings($form, $form_settings);
     }
 }
     $post_entry = (array) $_POST['entry'];
     $entry_id = $_POST['entry_id'];
     $entry = setup_entry($post_entry);
     foreach ($_POST['postData'] as $k => $v) {
         $entry[$k] = $v;
     }
     $entry['id'] = $entry_id;
     $entry['gform_lead_id'] = $post_entry['gform_lead_id'];
     $entry['is_submit_' . $post_entry['form_id']] = 1;
     $entry['gform_submit'] = $post_entry['form_id'];
     $entry['gform_unique_id'] = $post_entry['gform_unique_id'];
     $entry['state_' . $post_entry['form_id']] = $post_entry['state_' . $post_entry['form_id']];
     $entry['gform_target_page_number_' . $post_entry['form_id']] = $post_entry['gform_target_page_number_' . $post_entry['form_id']];
     $entry['gform_source_page_number_' . $post_entry['form_id']] = $post_entry['gform_source_page_number_' . $post_entry['form_id']];
     $entry['gform_field_values'] = $post_entry['gform_field_values'];
     $entry_ids = GFAPI::update_entry($entry, $entry_id);
     if (is_array($entry_ids) === false) {
         echo json_encode(array('success' => $entry_id));
         /****************************************/
         /* $to = '*****@*****.**';
            $subject = 'Edit Entry';
            $message = 'Data: <br/>'. print_r($entry,true);
            $message .= 'Data: <br/>'.print_r($_POST['entry'], true);
            $message .= 'Data: <br/>'.print_r($_POST['postData'], true);
            wp_mail( $to, $subject, $message);*/
         /****************************************/
     } else {
         echo json_encode(array('error' => "Ooops, something went wrong try again later." . $entry_ids));
         /*echo json_encode(array('error'=>$entry_ids));*/
     }
 }
 public static function delete_password($entry, $form)
 {
     $password_fields = self::get_fields_by_type($form, array('password'));
     if (is_array($password_fields)) {
         foreach ($password_fields as $password_field) {
             $entry[$password_field->id] = '';
         }
     }
     GFAPI::update_entry($entry);
     return $entry;
 }
 /**
  * update_approved function.
  *
  * @access public
  * @static
  * @param int $entry_id (default: 0)
  * @param int $approved (default: 0)
  * @param int $form_id (default: 0)
  * @param int $approvedcolumn (default: 0)
  * @return boolean True: It worked; False: it failed
  */
 public static function update_approved($entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0)
 {
     if (!class_exists('GFAPI')) {
         do_action('gravityview_log_error', __METHOD__ . 'GFAPI does not exist');
         return false;
     }
     if (empty($approvedcolumn)) {
         $approvedcolumn = self::get_approved_column($form_id);
     }
     //get the entry
     $entry = GFAPI::get_entry($entry_id);
     //update entry
     $entry[(string) $approvedcolumn] = $approved;
     /** @var bool|WP_Error $result */
     $result = GFAPI::update_entry($entry);
     /**
      * GFAPI::update_entry() doesn't trigger `gform_after_update_entry`, so we trigger updating the meta ourselves.
      */
     self::update_approved_meta($entry_id, $approved, $form_id);
     // add note to entry
     if ($result === true) {
         $note = empty($approved) ? __('Disapproved the Entry for GravityView', 'gravityview') : __('Approved the Entry for GravityView', 'gravityview');
         /**
          * @filter `gravityview/approve_entries/add-note` Add a note when the entry has been approved or disapproved?
          * @since 1.16.3
          * @param bool $add_note True: Yep, add that note! False: Do not, under any circumstances, add that note!
          */
         $add_note = apply_filters('gravityview/approve_entries/add-note', true);
         if ($add_note && class_exists('GravityView_Entry_Notes')) {
             $current_user = wp_get_current_user();
             GravityView_Entry_Notes::add_note($entry_id, $current_user->ID, $current_user->display_name, $note);
         }
         /**
          * Destroy the cache for this form
          * @see class-cache.php
          * @since 1.5.1
          */
         do_action('gravityview_clear_form_cache', $form_id);
     } else {
         if (is_wp_error($result)) {
             do_action('gravityview_log_error', __METHOD__ . sprintf(' - Entry approval not updated: %s', $result->get_error_message()));
             $result = false;
         }
     }
     return $result;
 }