/**
  *
  * @global type $wpdb
  */
 function entries_import()
 {
     $wform = $_REQUEST['form'];
     $gform = $_REQUEST['gform'];
     $entry_index = $_REQUEST['entry_index'];
     $this->init();
     $field_map = maybe_unserialize(get_site_option('rt_wufoo_' . $wform . '_field_map'));
     $f = new RGFormsModel();
     $c = new GFCommon();
     $gform_meta = RGFormsModel::get_form_meta($gform);
     try {
         $entries = $this->wufoo->getEntries($wform, 'forms', 'pageStart=' . $entry_index . '&pageSize=' . RT_WUFOO_IMPORT_PAGE_SIZE);
     } catch (Exception $rt_importer_e) {
         $this->error($rt_importer_e);
     }
     $this->op = array();
     foreach ($entries as $index => $entry) {
         $lead_exists_id = $this->is_imported($entry->EntryId);
         print_r($lead_exists_id);
         if (!$lead_exists_id) {
             foreach ($field_map as $g_id => $w_id) {
                 if (isset($w_id) && $w_id != '') {
                     $this->op[$g_id] = '';
                     $field_meta = RGFormsModel::get_field($gform_meta, $g_id);
                     if ($field_meta['type'] == 'fileupload') {
                         $this->op[$g_id] = $this->import_file_upload($entry, $w_id);
                     } else {
                         $this->import_regular_field($wform, $entry, $g_id, $w_id, $field_meta);
                     }
                 }
             }
             $currency = $c->get_currency();
             $ip = $f->get_ip();
             $page = $f->get_current_page_url();
             $lead_table = $f->get_lead_table_name();
             $lead_id = $this->insert_lead($entry, $lead_table, $ip, $currency, $page, $wform, $gform);
         }
         if ($lead_id) {
             foreach ($this->op as $inputid => $value) {
                 $this->insert_fields($lead_id, $gform, $inputid, $value);
             }
             //Insert comments as notes for the corresponding user map
             $comments = $this->get_comments_by_entry($wform, $entry->EntryId);
             if (isset($comments) && !empty($comments)) {
                 foreach ($comments as $comment) {
                     $this->move_comments_for_entry($comment, $f->get_lead_notes_table_name(), $lead_id, $wform);
                 }
             }
         } else {
             $lead_id = $lead_exists_id;
         }
         gform_update_meta($lead_id, 'rt_wufoo_entry_id', $entry->EntryId);
     }
     //update_site_option('rt_wufoo_' . $wform . '_entry_complete_count','0');
     echo count($entries) + $entry_index;
     die;
 }
 /**
  * Adapted from forms_model.php, RGFormsModel::save_lead($Form, $lead)
  * @param  array $form Form object.
  * @param  array $lead Lead object
  * @return void
  */
 public static function save_lead($form, &$lead)
 {
     global $wpdb;
     if (IS_ADMIN && !GFCommon::current_user_can_any("gravityforms_edit_entries")) {
         die(__("You don't have adequate permission to edit entries.", "gravityforms"));
     }
     $lead_detail_table = RGFormsModel::get_lead_details_table_name();
     //Inserting lead if null
     if ($lead == null) {
         global $current_user;
         $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
         $lead_table = RGFormsModel::get_lead_table_name();
         $user_agent = RGFormsModel::truncate($_SERVER["HTTP_USER_AGENT"], 250);
         $currency = GFCommon::get_currency();
         $source_url = RGFormsModel::truncate(RGFormsModel::get_current_page_url(), 200);
         $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form["id"], RGFormsModel::get_ip(), $source_url, $user_agent, $currency));
         //reading newly created lead id
         $lead_id = $wpdb->insert_id;
         $lead = array("id" => $lead_id);
     }
     $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead["id"]));
     $original_post_id = rgget("post_id", $lead);
     $total_fields = array();
     $calculation_fields = array();
     $recalculate_total = false;
     foreach ($form["fields"] as $field) {
         //Ignore fields that are marked as display only
         if (rgget("displayOnly", $field) && $field["type"] != "password") {
             continue;
         }
         //ignore pricing fields in the entry detail
         if (RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field($field["type"])) {
             continue;
         }
         //process total field after all fields have been saved
         if ($field["type"] == "total") {
             $total_fields[] = $field;
             continue;
         }
         //only save fields that are not hidden (except on entry screen)
         if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array(), $lead)) {
             // process calculation fields after all fields have been saved (moved after the is hidden check)
             if (GFCommon::has_field_calculation($field)) {
                 $calculation_fields[] = $field;
                 continue;
             }
             if ($field['type'] == 'post_category') {
                 $field = GFCommon::add_categories_as_choices($field, '');
             }
             if (isset($field["inputs"]) && is_array($field["inputs"])) {
                 foreach ($field["inputs"] as $input) {
                     RGFormsModel::save_input($form, $field, $lead, $current_fields, $input["id"]);
                 }
             } else {
                 RGFormsModel::save_input($form, $field, $lead, $current_fields, $field["id"]);
             }
         }
         //Refresh lead to support conditionals (not optimal but...)
         $lead = RGFormsModel::get_lead($lead['id']);
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $calculation_field) {
             if (isset($calculation_field["inputs"]) && is_array($calculation_field["inputs"])) {
                 foreach ($calculation_field["inputs"] as $input) {
                     RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input["id"]);
                     RGFormsModel::refresh_lead_field_value($lead["id"], $input["id"]);
                 }
             } else {
                 RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field["id"]);
                 RGFormsModel::refresh_lead_field_value($lead["id"], $calculation_field["id"]);
             }
         }
         RGFormsModel::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
     }
     //saving total field as the last field of the form.
     if (!empty($total_fields)) {
         foreach ($total_fields as $total_field) {
             GFCommon::log_debug("Saving total field.");
             RGFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field["id"]);
         }
     }
 }
Example #3
0
/**
 * Duplicates the contents of a specified entry id into the specified form
 * Adapted from forms_model.php, RGFormsModel::save_lead($Form, $lead) and
 * gravity -forms-addons.php for the gravity forms addon plugin
 * @param  array $form Form object.
 * @param  array $lead Lead object
 * @return void
 */
function duplicate_entry_data($form_change, $current_entry_id)
{
    global $wpdb;
    $lead_table = GFFormsModel::get_lead_table_name();
    $lead_detail_table = GFFormsModel::get_lead_details_table_name();
    $lead_meta_table = GFFormsModel::get_lead_meta_table_name();
    //pull existing entries information
    $current_lead = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$lead_table}          WHERE      id=%d", $current_entry_id));
    $current_fields = $wpdb->get_results($wpdb->prepare("SELECT wp_rg_lead_detail.field_number, wp_rg_lead_detail.value, wp_rg_lead_detail_long.value as long_detail FROM {$lead_detail_table} left outer join wp_rg_lead_detail_long on  wp_rg_lead_detail_long.lead_detail_id = wp_rg_lead_detail.id WHERE lead_id=%d", $current_entry_id));
    // new lead
    $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
    $user_agent = GFCommon::truncate_url($_SERVER["HTTP_USER_AGENT"], 250);
    $currency = GFCommon::get_currency();
    $source_url = GFCommon::truncate_url(RGFormsModel::get_current_page_url(), 200);
    $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form_change, RGFormsModel::get_ip(), $source_url, $user_agent, $currency));
    $lead_id = $wpdb->insert_id;
    echo 'Entry ' . $lead_id . ' created in Form ' . $form_change;
    //add a note to the new entry
    $results = mf_add_note($lead_id, 'Copied Entry ID:' . $current_entry_id . ' into form ' . $form_change . '. New Entry ID =' . $lead_id);
    foreach ($current_fields as $row) {
        $fieldValue = $row->field_number != 303 ? $row->value : 'Proposed';
        $wpdb->query($wpdb->prepare("INSERT INTO {$lead_detail_table}(lead_id, form_id, field_number, value) VALUES(%d, %s, %s, %s)", $lead_id, $form_change, $row->field_number, $fieldValue));
        //if detail long is set, add row for new record
        if ($row->long_detail != 'NULL') {
            $lead_detail_id = $wpdb->insert_id;
            $wpdb->query($wpdb->prepare("INSERT INTO wp_rg_lead_detail_long(lead_detail_id, value) VALUES(%d, %s)", $lead_detail_id, $row->long_detail));
        }
    }
}
Example #4
0
 public static function paypalpro_validation($validation_result)
 {
     $config = self::is_ready_for_capture($validation_result);
     if (!$config) {
         return $validation_result;
     }
     require_once self::get_base_path() . "/data.php";
     // Determine if feed specific api settings are enabled
     $local_api_settings = array();
     if ($config["meta"]["api_settings_enabled"] == 1) {
         $local_api_settings = self::get_local_api_settings($config);
     }
     // Billing
     $card_field = self::get_creditcard_field($validation_result["form"]);
     $card_number = rgpost("input_{$card_field["id"]}_1");
     $card_type = GFCommon::get_card_type($card_number);
     $expiration_date = rgpost("input_{$card_field["id"]}_2");
     $country = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["country"]));
     $country = class_exists('GF_Field_Address') ? GF_Fields::get('address')->get_country_code($country) : GFCommon::get_country_code($country);
     $billing = array();
     $billing['CREDITCARDTYPE'] = $card_type["slug"];
     $billing['ACCT'] = $card_number;
     $billing['EXPDATE'] = $expiration_date[0] . $expiration_date[1];
     $billing['CVV2'] = rgpost("input_{$card_field["id"]}_3");
     $billing['STREET'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["address1"]));
     $billing['STREET2'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["address2"]));
     $billing['CITY'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["city"]));
     $billing['STATE'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["state"]));
     $billing['ZIP'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["zip"]));
     $billing['COUNTRYCODE'] = $country == "UK" ? "GB" : $country;
     $billing['CURRENCYCODE'] = GFCommon::get_currency();
     // Customer Contact
     $billing['FIRSTNAME'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["first_name"]));
     $billing['LASTNAME'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["last_name"]));
     $billing['EMAIL'] = rgpost('input_' . str_replace(".", "_", $config["meta"]["customer_fields"]["email"]));
     $lead = RGFormsModel::create_lead($validation_result["form"]);
     $product_billing_data = self::get_product_billing_data($validation_result["form"], $lead, $config);
     $amount = $product_billing_data["amount"];
     $products = $product_billing_data["products"];
     $billing = array_merge($billing, $product_billing_data["billing"]);
     if ($config["meta"]["type"] == "product") {
         if ($amount == 0) {
             //blank out credit card field if this is the last page
             if (self::is_last_page($validation_result["form"])) {
                 $_POST["input_{$card_field["id"]}_1"] = "";
             }
             //creating dummy transaction response if there are any visible product fields in the form
             if (self::has_visible_products($validation_result["form"])) {
                 self::$transaction_response = array("transaction_id" => "N/A", "amount" => 0, "transaction_type" => 1, 'config_id' => $config['id']);
             }
             return $validation_result;
         }
         //setting up a one time payment
         $ip = RGFormsModel::get_ip();
         $billing['PAYMENTACTION'] = "Sale";
         $billing['IPADDRESS'] = $ip == "::1" ? "127.0.0.1" : $ip;
         $billing['RETURNFMFDETAILS'] = "1";
         $billing['BUTTONSOURCE'] = 'gravityforms';
         $billing['AMT'] = $amount;
         $billing['NOTIFYURL'] = get_bloginfo("url") . "/?page=gf_paypalpro_ipn";
         self::log_debug("Sending one time payment.");
         $response = self::post_to_paypal("DoDirectPayment", $billing, $local_api_settings, $validation_result["form"], $lead);
         if (!empty($response) && !empty($response["TRANSACTIONID"])) {
             self::$transaction_response = array("transaction_id" => $response["TRANSACTIONID"], "subscription_amount" => 0, "initial_payment_amount" => $response["AMT"], "transaction_type" => 1, 'config_id' => $config['id']);
             self::log_debug("Payment successful.");
             return $validation_result;
         } else {
             // Payment was not succesful, need to display error message
             self::log_error("Payment was NOT successful.");
             return self::set_validation_result($validation_result, $_POST, $response, "capture");
         }
     } else {
         //setting up a recurring payment
         $billing['PROFILESTARTDATE'] = gmdate(DATE_ATOM);
         $billing['SUBSCRIBERNAME'] = $billing['FIRSTNAME'] . " " . $billing['LASTNAME'];
         $billing['MAXFAILEDPAYMENTS'] = "0";
         $interval_unit = self::get_interval_unit($config["meta"]["billing_cycle_type"]);
         $interval_length = $config["meta"]["billing_cycle_number"];
         $billing['BILLINGPERIOD'] = $interval_unit;
         $billing['BILLINGFREQUENCY'] = $interval_length;
         $billing['TOTALBILLINGCYCLES'] = $config["meta"]["recurring_times"];
         $billing['AMT'] = $amount;
         //setup fee
         $setup_fee_amount = 0;
         if ($config["meta"]["setup_fee_enabled"]) {
             $setup_fee_product = rgar($products["products"], $config["meta"]["setup_fee_amount_field"]);
             if (!empty($setup_fee_product)) {
                 $setup_fee_amount = self::get_product_price($setup_fee_product);
                 $billing['INITAMT'] = $setup_fee_amount;
             }
         }
         //trial
         $trial_amount = 0;
         if ($config["meta"]["trial_period_enabled"]) {
             if ($config["meta"]["trial_type"] == "paid") {
                 $trial_product = rgar($products["products"], $config["meta"]["trial_amount_field"]);
                 $trial_amount = empty($trial_product) ? 0 : self::get_product_price($trial_product);
                 $billing["TRIALAMT"] = $trial_amount;
             }
             $billing["TRIALBILLINGPERIOD"] = self::get_interval_unit($config["meta"]["trial_period_type"]);
             $billing["TRIALBILLINGFREQUENCY"] = $config["meta"]["trial_period_number"];
             $billing["TRIALTOTALBILLINGCYCLES"] = $config["meta"]["trial_recurring_times"];
         }
         self::log_debug("Sending recurring payment to PayPal.");
         $response = self::post_to_paypal("CreateRecurringPaymentsProfile", $billing, $local_api_settings, $validation_result["form"], $lead);
         if (!empty($response) && !empty($response["PROFILEID"])) {
             self::$transaction_response = array("transaction_id" => rgar($response, "TRANSACTIONID"), "subscription_id" => $response["PROFILEID"], "subscription_amount" => $billing['AMT'], "initial_payment_amount" => $setup_fee_amount, "transaction_type" => 2, 'config_id' => $config['id']);
             self::log_debug("Recurring payment setup successful.");
             return $validation_result;
         } else {
             // Payment was not successful, need to display error message
             self::log_error("Recurring payment was NOT successful.");
             return self::set_validation_result($validation_result, $_POST, $response, "recurring");
         }
     }
 }