/** * Deletes a single Entry. * * @since 1.8 * @access public * @static * * @param int $entry_id The ID of the Entry object * * @return mixed Either true for success or a WP_Error instance */ public static function delete_entry($entry_id) { $entry = GFFormsModel::get_lead($entry_id); if (empty($entry)) { return new WP_Error("invalid_entry_id", sprintf(__("Invalid entry id: %s", "gravityforms"), $entry_id), $entry_id); } GFFormsModel::delete_lead($entry_id); return true; }
function get_entry() { if (!self::$_entry) { $entry_id = $this->get_entry_id(); if (!$entry_id) { return false; } $entry = GFFormsModel::get_lead($entry_id); if (empty($entry)) { return false; } self::$_entry = $entry; } return self::$_entry; }
/** * Revoke referral on refund * * @access public * @uses GFFormsModel::get_lead() * * @param int $reference * @param object $referral * @return string */ public function reference_link($reference = 0, $referral) { if (empty($referral->context) || 'gravityforms' != $referral->context) { return $reference; } $entry = GFFormsModel::get_lead($reference); $url = admin_url('admin.php?page=gf_entries&view=entry&id=' . $entry['form_id'] . '&lid=' . $reference); return '<a href="' . esc_url($url) . '">' . $reference . '</a>'; }
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'])); }
/** * @param $lead_id */ function euzakupki_order_status_email_notification($lead_id) { $lead = GFFormsModel::get_lead($lead_id); if (!$lead) { return; } $form = RGFormsModel::get_form_meta($lead['form_id']); if (!$form) { return; } $config = euzakupki_get_form_config($lead['form_id']); if (!$config) { return; } $notifications = json_decode($config['notifications'], ARRAY_A); $ids = array(); foreach ($notifications as $item) { if (!isset($item['isActive'])) { continue; } $ids[] = $item['id']; } GFCommon::send_notifications($ids, $form, $lead); }
/** * update payment status if it has changed * @param array $form * @param int $lead_id */ public function gformAfterUpdateEntry($form, $lead_id) { // make sure we have permission check_admin_referer('gforms_save_entry', 'gforms_save_entry'); // check that save action is for update if (strtolower(rgpost('save')) != 'update') { return; } // make sure payment is one of ours (probably) $payment_gateway = gform_get_meta($lead_id, 'payment_gateway'); if (empty($payment_gateway) && GFEwayPlugin::isEwayForm($form['id'], $form['fields']) || $payment_gateway != 'gfeway') { return; } // make sure we have a new payment status $payment_status = rgpost('payment_status'); if (empty($payment_status)) { return; } // update payment status $lead = GFFormsModel::get_lead($lead_id); $lead['payment_status'] = $payment_status; GFFormsModel::update_lead($lead); }
/** * Helper function to get a single entry * * @param int $lead_id Lead ID * @return array */ private function get_lead($lead_id) { return \GFFormsModel::get_lead($lead_id); }
public static function callback_gform_update_is_starred($lead_id, $status) { $lead = GFFormsModel::get_lead($lead_id); $form = self::get_form($lead['form_id']); self::log(sprintf(__('Lead #%1$d %2$s on "%3$s" form', 'stream'), $lead_id, $status ? __('starred', 'stream') : __('unstarred', 'stream'), $form['title']), array('lead_id' => $lead_id, 'form_title' => $form['title'], 'form_id' => $form['id'], 'status' => $status), $lead_id, 'entries', 'updated'); }
public function get_survey_field_content($content, $field, $value, $lead_id, $form_id, $lead = null) { if ($field['type'] != 'survey') { return $content; } $sub_type = rgar($field, 'inputType'); switch ($sub_type) { case 'likert': $multiple_rows = rgar($field, 'gsurveyLikertEnableMultipleRows'); $field_id = $field['id']; $num_rows = $multiple_rows ? count($field['gsurveyLikertRows']) : 1; $table_id = "id='input_{$form_id}_{$field_id}'"; $content = "<div class='ginput_container'>"; $content .= "<table {$table_id} class='gsurvey-likert'>"; $content .= '<tr>'; if ($multiple_rows) { $content .= "<td class='gsurvey-likert-row-label'></td>"; } $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != 'entry' || IS_ADMIN && RG_CURRENT_VIEW == 'entry' && 'edit' != rgpost('screen_mode') ? "disabled='disabled'" : ''; foreach ($field['choices'] as $choice) { $content .= "<td class='gsurvey-likert-choice-label'>"; $content .= $choice['text']; $content .= '</td>'; } $content .= '</tr>'; $row_id = 1; for ($i = 1; $i <= $num_rows; $i++) { //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10 if ($row_id % 10 == 0) { $row_id++; } $row_text = $field['gsurveyLikertRows'][$i - 1]['text']; $row_value = $field['gsurveyLikertRows'][$i - 1]['value']; $content .= '<tr>'; if ($multiple_rows) { $content .= "<td class='gsurvey-likert-row-label'>{$row_text}</td>"; } $choice_id = 1; foreach ($field['choices'] as $choice) { //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10 if ($choice_id % 10 == 0) { $choice_id++; } $id = $field['id'] . '_' . $row_id . '_' . $choice_id; $field_value = $multiple_rows ? $row_value . ':' . $choice['value'] : $choice['value']; $cell_class = 'gsurvey-likert-choice'; $checked = ''; $selected = false; if (rgblank($value) && empty($lead)) { $checked = ''; } else { if ($multiple_rows) { $input_name = $field['id'] . '.' . $row_id; if (is_array($value) && isset($value[$input_name])) { $response_value = $value[$input_name]; $selected = $response_value == $field_value ? true : false; } else { if ($lead == null) { $lead = GFFormsModel::get_lead($lead_id); } if (false === $lead) { $selected = false; } else { $response_col_val = $this->get_likert_col_val_for_row_from_entry($row_value, $field_id, $lead); $selected = $response_col_val == $choice['value'] ? true : false; } } } else { $selected = $choice['value'] == $value ? true : false; } } if ($selected) { $checked = "checked='checked'"; $cell_class = $cell_class . ' gsurvey-likert-selected'; } $logic_event = empty($field['conditionalLogicFields']) || IS_ADMIN ? '' : "onclick='gf_apply_rules(" . $field['formId'] . ',' . GFCommon::json_encode($field['conditionalLogicFields']) . ");'"; $tabindex = GFCommon::get_tabindex(); $content .= "<td class='{$cell_class}'>"; if ($multiple_rows) { // $input_id = sprintf('input_%d.%d', $field_id, $row_id); } else { $input_id = sprintf('input_%d', $field_id); } $content .= sprintf("<input name='{$input_id}' type='radio' {$logic_event} value='%s' %s id='choice_%s' {$tabindex} %s />", esc_attr($field_value), $checked, $id, $disabled_text); $content .= '</td>'; $choice_id++; } $row_id++; $content .= '</tr>'; } $content .= '</table>'; $content .= '</div>'; break; case 'rank': $field_id = $field['id']; $input_id = "gsurvey-rank-{$form_id}-{$field_id}"; $content = "<div class='ginput_container'>"; $content .= "<ul id='{$input_id}' class='gsurvey-rank'>"; $handle_image_url = $this->get_base_url() . '/images/arrow-handle.png'; $choice_id = 0; $count = 1; $choices = array(); if (false === empty($value)) { $ordered_values = explode(',', $value); foreach ($ordered_values as $ordered_value) { $choices[] = array('value' => $ordered_value, 'text' => RGFormsModel::get_choice_text($field, $ordered_value)); } } else { $choices = $field['choices']; } foreach ($choices as $choice) { $id = $field['id'] . '_' . $choice_id++; $field_value = !empty($choice['value']) || rgar($field, 'enableChoiceValue') ? $choice['value'] : $choice['text']; $content .= sprintf("<li data-index='{$choice_id}' class='gsurvey-rank-choice choice_%s' id='{$field_value}' ><img src='{$handle_image_url}' alt='' />%s</li>", $id, $choice['text']); if (IS_ADMIN && RG_CURRENT_VIEW != 'entry' && $count >= 5) { break; } $count++; } $content .= '</ul>'; $content .= sprintf("<input type='hidden' id='{$input_id}-hidden' name='input_%d' />", $field_id); $content .= '</div>'; break; case 'rating': $field_id = $field['id']; $div_id = "input_{$form_id}_{$field_id}"; $disabled_text = IS_ADMIN && RG_CURRENT_VIEW != 'entry' ? "disabled='disabled'" : ''; $content = "<div class='gsurvey-rating-wrapper'><div id='{$div_id}' class='gsurvey-rating'>"; $choice_id = 0; $count = 1; // choices reversed in the form editor from version 2.1.1 if (rgar($field, 'reversed')) { $field['choices'] = array_reverse($field['choices']); } foreach ($field['choices'] as $choice) { $id = $field['id'] . '_' . $choice_id++; $field_value = !empty($choice['value']) || rgar($field, 'enableChoiceValue') ? $choice['value'] : $choice['text']; if (rgblank($value) && RG_CURRENT_VIEW != 'entry') { $checked = rgar($choice, 'isSelected') ? "checked='checked'" : ''; } else { $checked = RGFormsModel::choice_value_match($field, $choice, $value) ? "checked='checked'" : ''; } $logic_event = empty($field['conditionalLogicFields']) || IS_ADMIN ? '' : "onclick='gf_apply_rules(" . $field['formId'] . ',' . GFCommon::json_encode($field['conditionalLogicFields']) . ");'"; $tabindex = GFCommon::get_tabindex(); $choice_label = $choice['text']; $content .= sprintf("<input name='input_%d' type='radio' {$logic_event} value='%s' %s id='choice_%s' {$tabindex} %s /><label for='choice_%s' title='%s'>%s</label>", $field_id, esc_attr($field_value), $checked, $id, $disabled_text, $id, $choice_label, $choice_label); if (IS_ADMIN && RG_CURRENT_VIEW != 'entry' && $count >= 5) { break; } $count++; } $content .= '</div></div>'; } return $content; }
public function maybe_process_status_update($form, $entry) { $feedback = false; $form_id = $form['id']; if (isset($_POST['gforms_save_entry']) && check_admin_referer('gforms_save_entry', 'gforms_save_entry')) { $new_status = rgpost('gravityflow_status'); if (!in_array($new_status, array('in_progress', 'complete'))) { return false; } // Loading files that have been uploaded to temp folder $files = GFCommon::json_decode(stripslashes(RGForms::post('gform_uploaded_files'))); if (!is_array($files)) { $files = array(); } GFFormsModel::$uploaded_files[$form_id] = $files; $validation = $this->validate_status_update($new_status, $form); if (is_wp_error($validation)) { return $validation; } $editable_fields = $this->get_editable_fields(); $previous_assignees = $this->get_assignees(); $this->save_entry($form, $entry, $editable_fields); remove_action('gform_after_update_entry', array(gravity_flow(), 'filter_after_update_entry')); do_action('gform_after_update_entry', $form, $entry['id']); do_action("gform_after_update_entry_{$form['id']}", $form, $entry['id']); $entry = GFFormsModel::get_lead($entry['id']); $entry = GFFormsModel::set_entry_meta($entry, $form); $this->refresh_entry(); GFCache::flush(); $this->maybe_adjust_assignment($previous_assignees); if ($token = gravity_flow()->decode_access_token()) { $assignee_key = sanitize_text_field($token['sub']); } else { $user = wp_get_current_user(); $assignee_key = 'user_id|' . $user->ID; } $assignee = new Gravity_Flow_Assignee($assignee_key, $this); $feedback = $this->process_assignee_status($assignee, $new_status, $form); } return $feedback; }
function euzakupki_dotpay_callback($response) { $lead = GFFormsModel::get_lead($response['control']); if (!$lead) { return; } // Return if payment completed if ($lead['payment_status'] == 'completed') { return; } $t_status = $response['t_status']; switch ($t_status) { case 2: $payment_status = 'completed'; $customer_balance = get_user_meta($lead['created_by'], 'balance', true); @($customer_balance = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $customer_balance)); $customer_balance = unserialize($customer_balance); $new_amount = euzakupki_pln_to_euro($response['amount']); $new_fund = array('amount' => $new_amount, 'date' => $response['t_date'], 'reason' => __('Пополнение баланса DotPay', 'euzakupki')); $customer_balance[] = $new_fund; $res = update_user_meta($lead['created_by'], 'balance', serialize($customer_balance)); break; default: $payment_status = 'error'; break; } $lead['payment_status'] = $payment_status; $lead['payment_date'] = $response['t_date']; $lead['payment_amount'] = $response['amount']; $lead['transaction_id'] = $response['t_id']; $lead['transaction_type'] = $response['channel']; $lead['payment_method'] = $response['p_info']; // Update lead and entry. Set transaction result data. GFFormsModel::update_lead($lead); // Write log $filename = get_template_directory() . '/logs/dotpay.log'; if (!file_exists($filename)) { $log = array(); } else { $log = file_get_contents($filename); @($log = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $log)); $log = unserialize($log); } $log[] = $response; $log = serialize($log); $handle = fopen($filename, 'w+'); fwrite($handle, $log); fclose($handle); }