コード例 #1
0
 public static function get_transaction_totals($form_id)
 {
     global $wpdb;
     $lead_table_name = RGFormsModel::get_lead_table_name();
     $transaction_table_name = self::get_transaction_table_name();
     $sql = $wpdb->prepare(" SELECT t.transaction_type, sum(t.amount) revenue, count(t.id) transactions\n                                 FROM {$transaction_table_name} t\n                                 INNER JOIN {$lead_table_name} l ON l.id = t.entry_id\n                                 WHERE l.form_id={$form_id}\n                                 GROUP BY t.transaction_type", $form_id);
     $results = $wpdb->get_results($sql, ARRAY_A);
     $totals = array();
     if (is_array($results)) {
         foreach ($results as $result) {
             $totals[$result["transaction_type"]] = array("revenue" => empty($result["revenue"]) ? 0 : $result["revenue"], "transactions" => empty($result["transactions"]) ? 0 : $result["transactions"]);
         }
     }
     return $totals;
 }
コード例 #2
0
 public static function get_transaction_totals($config)
 {
     global $wpdb;
     $lead_table_name = RGFormsModel::get_lead_table_name();
     $transaction_table_name = self::get_transaction_table_name();
     $orders = $config["meta"]["type"] == "subscription" ? "t.transaction_type='signup'" : "is_renewal=0";
     $sql = $wpdb->prepare("SELECT sum(t.amount) revenue, count({$orders}) as orders\r\n                                 FROM {$transaction_table_name} t\r\n                                 INNER JOIN {$lead_table_name} l ON l.id = t.entry_id\r\n                                 INNER JOIN {$wpdb->prefix}rg_lead_meta m ON meta_key='paypalpro_feed_id' AND m.lead_id = l.id\r\n                                 WHERE m.meta_value=%s", $config["id"]);
     $results = $wpdb->get_results($sql, ARRAY_A);
     $totals = array();
     if (is_array($results)) {
         $result = $results[0];
         $totals = array("revenue" => empty($result["revenue"]) ? 0 : $result["revenue"], "orders" => empty($result["orders"]) ? 0 : $result["orders"]);
     }
     return $totals;
 }
コード例 #3
0
 /**
  *
  * @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;
 }
コード例 #4
0
 /**
  *
  * get all gravity lead
  *
  * @param $form_id
  *
  * @since
  */
 public function get_all_gravity_lead($form_id)
 {
     $gravityLeadTableName = RGFormsModel::get_lead_table_name();
     global $wpdb;
     $sql = $wpdb->prepare("SELECT id FROM {$gravityLeadTableName} WHERE form_id=%d AND status='active'", $form_id);
     echo json_encode($wpdb->get_results($sql, ARRAY_A));
 }
コード例 #5
0
 public function detachFormEntry($lead_id)
 {
     $entries = $this->getFormEntryIds();
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Start to detach gravity forms: " . print_r($entries, true));
     if (in_array($lead_id, $entries)) {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Lead id is in the list of entries: " . $lead_id);
         if (class_exists('RGForms')) {
             if (!class_exists('RGFormsModel')) {
                 RGForms::init();
             }
             if (class_exists('RGFormsModel')) {
                 global $wpdb;
                 $lead_table = RGFormsModel::get_lead_table_name();
                 $lead_notes_table = RGFormsModel::get_lead_notes_table_name();
                 $lead_detail_table = RGFormsModel::get_lead_details_table_name();
                 $lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();
                 //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
                 $sql = $wpdb->prepare("DELETE FROM {$lead_table} WHERE id=%d", $lead_id);
                 $wpdb->query($sql);
                 // Remove entry from array
                 $entries = array_values(array_diff($entries, array($lead_id)));
                 $this->_formEntryIds = $entries;
                 $qty = $this->getQuantity();
                 $this->setQuantity($qty - 1);
             }
         }
     }
 }
コード例 #6
0
 public function gform_post_submission($entry, $form)
 {
     global $wpdb;
     $this->options['entries'] = apply_filters($this->name . '_entries', $this->options['entries'], $form);
     if (!$this->options['entries'] || $this->is_delete()) {
         $tables = (object) array('lead_table' => RGFormsModel::get_lead_table_name(), 'lead_notes_table' => RGFormsModel::get_lead_notes_table_name(), 'lead_detail_table' => RGFormsModel::get_lead_details_table_name(), 'lead_detail_long_table' => RGFormsModel::get_lead_details_long_table_name());
         $queries = array($wpdb->prepare("DELETE FROM {$tables->lead_detail_long_table} WHERE lead_detail_id IN (SELECT id FROM {$tables->lead_detail_table} WHERE lead_id = %d)", $entry['id']), $wpdb->prepare("DELETE FROM {$tables->lead_detail_table} WHERE lead_id = %d", $entry['id']), $wpdb->prepare("DELETE FROM {$tables->lead_notes_table} WHERE lead_id = %d", $entry['id']), $wpdb->prepare("DELETE FROM {$tables->lead_table} WHERE id = %d", $entry['id']));
         foreach ($queries as $query) {
             $wpdb->query($query);
         }
     }
     if ($this->is_delete()) {
         wp_delete_post($this->post['ID']);
     }
     // If a custom field is unique, get all the rows and combine them into one
     foreach ($form['fields'] as $field) {
         if ($field['type'] == 'post_custom_field' && isset($field['postCustomFieldUnique'])) {
             $meta = get_post_meta($this->post['ID'], $field['postCustomFieldName']);
             delete_post_meta($this->post['ID'], $field['postCustomFieldName']);
             add_post_meta($this->post['ID'], $field['postCustomFieldName'], is_array($meta) && count($meta) == 1 ? $meta[0] : $meta, true);
         }
     }
 }
コード例 #7
0
ファイル: forms_model.php プロジェクト: novuscory/ACH
 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 = self::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 = strlen($_SERVER["HTTP_USER_AGENT"]) > 250 ? substr($_SERVER["HTTP_USER_AGENT"], 0, 250) : $_SERVER["HTTP_USER_AGENT"];
         $currency = GFCommon::get_currency();
         $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"], self::get_ip(), self::get_current_page_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 = $lead["post_id"];
     foreach ($form["fields"] as $field) {
         //Ignore fields that are marked as display only
         if ($field["displayOnly"] && $field["type"] != "password") {
             continue;
         }
         //ignore pricing fields in the entry detail
         if (RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field($field["type"])) {
             continue;
         }
         //only save fields that are not hidden (except on entry screen)
         if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array())) {
             if (is_array($field["inputs"])) {
                 foreach ($field["inputs"] as $input) {
                     self::save_input($form, $field, $lead, $current_fields, $input["id"]);
                 }
             } else {
                 self::save_input($form, $field, $lead, $current_fields, $field["id"]);
             }
         }
     }
 }
コード例 #8
0
 public static function save_lead($form, &$lead)
 {
     global $wpdb;
     GFCommon::log_debug(__METHOD__ . '(): Saving entry.');
     $is_form_editor = GFCommon::is_form_editor();
     $is_entry_detail = GFCommon::is_entry_detail();
     $is_admin = $is_form_editor || $is_entry_detail;
     if ($is_admin && !GFCommon::current_user_can_any('gravityforms_edit_entries')) {
         die(esc_html__("You don't have adequate permission to edit entries.", 'gravityforms'));
     }
     $lead_detail_table = self::get_lead_details_table_name();
     $is_new_lead = $lead == null;
     //Inserting lead if null
     if ($is_new_lead) {
         global $current_user;
         $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
         $lead_table = RGFormsModel::get_lead_table_name();
         $user_agent = self::truncate($_SERVER['HTTP_USER_AGENT'], 250);
         $currency = GFCommon::get_currency();
         $source_url = self::truncate(self::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'], self::get_ip(), $source_url, $user_agent, $currency));
         //reading newly created lead id
         $lead_id = $wpdb->insert_id;
         $lead = array('id' => $lead_id);
         GFCommon::log_debug(__METHOD__ . "(): Entry record created in the database. ID: {$lead_id}.");
     }
     $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead['id']));
     $total_fields = array();
     /* @var $calculation_fields GF_Field[] */
     $calculation_fields = array();
     $recalculate_total = false;
     GFCommon::log_debug(__METHOD__ . '(): Saving entry fields.');
     foreach ($form['fields'] as $field) {
         /* @var $field GF_Field */
         // ignore the honeypot field
         if ($field->type == 'honeypot') {
             continue;
         }
         //Ignore fields that are marked as display only
         if ($field->displayOnly && $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;
         }
         $is_entry_update = RG_CURRENT_VIEW == 'entry' || !$is_new_lead;
         $read_value_from_post = $is_new_lead || !isset($lead['date_created']);
         //only save fields that are not hidden (except when updating an entry)
         if ($is_entry_update || !GFFormsModel::is_field_hidden($form, $field, array(), $read_value_from_post ? null : $lead)) {
             // process calculation fields after all fields have been saved (moved after the is hidden check)
             if ($field->has_calculation()) {
                 $calculation_fields[] = $field;
                 continue;
             }
             if ($field->type == 'post_category') {
                 $field = GFCommon::add_categories_as_choices($field, '');
             }
             $inputs = $field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     self::save_input($form, $field, $lead, $current_fields, $input['id']);
                 }
             } else {
                 self::save_input($form, $field, $lead, $current_fields, $field->id);
             }
         }
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $calculation_field) {
             $inputs = $calculation_field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     self::save_input($form, $calculation_field, $lead, $current_fields, $input['id']);
                     self::refresh_lead_field_value($lead['id'], $input['id']);
                 }
             } else {
                 self::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field->id);
                 self::refresh_lead_field_value($lead['id'], $calculation_field->id);
             }
         }
         self::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) {
             self::save_input($form, $total_field, $lead, $current_fields, $total_field->id);
             self::refresh_lead_field_value($lead['id'], $total_field['id']);
         }
     }
     GFCommon::log_debug(__METHOD__ . '(): Finished saving entry fields.');
 }
コード例 #9
0
ファイル: gravityforms.php プロジェクト: 812studio/812studio
 public static function setup()
 {
     global $wpdb;
     $version = GFCommon::$version;
     if (get_option("rg_form_version") != $version) {
         require_once ABSPATH . '/wp-admin/includes/upgrade.php';
         if (!empty($wpdb->charset)) {
             $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
         }
         if (!empty($wpdb->collate)) {
             $charset_collate .= " COLLATE {$wpdb->collate}";
         }
         //------ FORM -----------------------------------------------
         $form_table_name = RGFormsModel::get_form_table_name();
         $sql = "CREATE TABLE " . $form_table_name . " (\n                  id mediumint(8) unsigned not null auto_increment,\n                  title varchar(150) not null,\n                  date_created datetime not null,\n                  is_active tinyint(1) not null default 1,\n                  PRIMARY KEY  (id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ META -----------------------------------------------
         $meta_table_name = RGFormsModel::get_meta_table_name();
         $sql = "CREATE TABLE " . $meta_table_name . " (\n                  form_id mediumint(8) unsigned not null,\n                  display_meta longtext,\n                  entries_grid_meta longtext,\n                  KEY form_id (form_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ FORM VIEW -----------------------------------------------
         $form_view_table_name = RGFormsModel::get_form_view_table_name();
         $sql = "CREATE TABLE " . $form_view_table_name . " (\n                  id bigint(20) unsigned not null auto_increment,\n                  form_id mediumint(8) unsigned not null,\n                  date_created datetime not null,\n                  ip char(15),\n                  count mediumint(8) unsigned not null default 1,\n                  PRIMARY KEY  (id),\n                  KEY form_id (form_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD -----------------------------------------------
         $lead_table_name = RGFormsModel::get_lead_table_name();
         $sql = "CREATE TABLE " . $lead_table_name . " (\n                  id int(10) unsigned not null auto_increment,\n                  form_id mediumint(8) unsigned not null,\n                  post_id bigint(20) unsigned,\n                  date_created datetime not null,\n                  is_starred tinyint(1) not null default 0,\n                  is_read tinyint(1) not null default 0,\n                  ip char(15) not null,\n                  source_url varchar(200) not null default '',\n                  user_agent varchar(250) not null default '',\n                  PRIMARY KEY  (id),\n                  KEY form_id (form_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD NOTES ------------------------------------------
         $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
         $sql = "CREATE TABLE " . $lead_notes_table_name . " (\n                  id int(10) unsigned not null auto_increment,\n                  lead_id int(10) unsigned not null,\n                  user_name varchar(250),\n                  user_id bigint(20),\n                  date_created datetime not null,\n                  value longtext,\n                  PRIMARY KEY  (id),\n                  KEY lead_id (lead_id),\n                  KEY lead_user_key (lead_id,user_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD DETAIL -----------------------------------------
         $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
         $sql = "CREATE TABLE " . $lead_detail_table_name . " (\n                  id bigint(20) unsigned not null auto_increment,\n                  lead_id int(10) unsigned not null,\n                  form_id mediumint(8) unsigned not null,\n                  field_number float not null,\n                  value varchar(" . GFORMS_MAX_FIELD_LENGTH . "),\n                  PRIMARY KEY  (id),\n                  KEY form_id (form_id),\n                  KEY lead_id (lead_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //------ LEAD DETAIL LONG -----------------------------------
         $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
         $sql = "CREATE TABLE " . $lead_detail_long_table_name . " (\n                  lead_detail_id bigint(20) unsigned not null,\n                  value longtext,\n                  KEY lead_detail_key (lead_detail_id)\n                ) {$charset_collate};";
         dbDelta($sql);
         //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
         self::fix_checkbox_value();
     }
     update_option("rg_form_version", $version);
 }
コード例 #10
0
 /** Sends an e-mail out, good stuff */
 public function send_notifications($form_id)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     if (!$form) {
         // TODO: Yet, groups will only be sent out in the next schedule
         // TODO: perhaps add a $now = 'group' flag for instant turnaround?
         $this->reschedule_existing();
         return;
     }
     $digest_group = isset($form['digests']['digest_group']) ? $form['digests']['digest_group'] : false;
     $digest_interval = isset($form['digests']['digest_interval']) ? $form['digests']['digest_interval'] : false;
     $digest_report_always = isset($form['digests']['digest_report_always']) ? $form['digests']['digest_report_always'] : false;
     $digest_export_all_fields = isset($form['digests']['digest_export_all_fields']) ? $form['digests']['digest_export_all_fields'] : true;
     $digest_export_field_list = isset($form['digests']['digest_export_field_list']) ? $form['digests']['digest_export_field_list'] : array();
     $forms = array($form['id'] => $form);
     if ($digest_group) {
         /* We may want to send out a group of forms in one e-mail if possible */
         foreach (RGFormsModel::get_forms(true) as $existing_form) {
             if ($existing_form->id == $form_id) {
                 continue;
             }
             // It is I!
             $existing_form = RGFormsModel::get_form_meta($existing_form->id);
             if (!isset($existing_form['digests']['enable_digest'])) {
                 continue;
             }
             // Meh, not interesting
             if (!isset($existing_form['digests']['digest_group'])) {
                 continue;
             }
             // Meh, not interesting
             if (!isset($existing_form['digests']['digest_interval'])) {
                 continue;
             }
             // Meh, not interesting
             if ($existing_form['digests']['digest_group'] == $digest_group) {
                 if ($existing_form['digests']['digest_interval'] == $digest_interval) {
                     $forms[$existing_form['id']] = $existing_form;
                     // Add them all
                 }
             }
         }
     }
     $emails = array();
     /* Gather all the leads and update the last_sent counters */
     foreach ($forms as $i => $form) {
         $last_sent = isset($form['digests']['digest_last_sent']) ? $form['digests']['digest_last_sent'] : 0;
         /* Retrieve form entries newer than the last sent ID */
         global $wpdb;
         $leads_table = RGFormsModel::get_lead_table_name();
         $leads = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$leads_table} WHERE form_id = %d AND id > %d AND status = 'active';", $form['id'], $last_sent));
         if (!sizeof($leads)) {
             if (!$digest_report_always) {
                 continue;
                 // Nothing to report on
             }
         } else {
             /* Update the reported id counter */
             $form['digests']['digest_last_sent'] = $leads[sizeof($leads) - 1]->id;
         }
         if (version_compare(GFCommon::$version, '1.7') >= 0) {
             /* Seems like 1.7 really messed up the meta structure */
             unset($form['notifications']);
             unset($form['confirmations']);
         }
         RGFormsModel::update_form_meta($form['id'], $form);
         $forms[$i]['leads'] = $leads;
         /* Also make a lookup table of all e-mail addresses to forms */
         foreach ($form['digests']['digest_emails'] as $email) {
             if (!isset($emails[$email])) {
                 $emails[$email] = array();
             }
             $emails[$email][] = $form['id'];
         }
     }
     /* Now, let's try and mail stuff */
     foreach ($emails as $email => $form_ids) {
         /* CSV e-mails */
         $report = 'Report generated at ' . date('Y-m-d H:i:s') . "\n";
         $csv_attachment = tempnam(sys_get_temp_dir(), '');
         $csv = fopen($csv_attachment, 'w');
         $from = null;
         $to = null;
         $names = array();
         foreach ($form_ids as $form_id) {
             $form = $forms[$form_id];
             $names[] = $form['title'];
             fputcsv($csv, array('Form: ' . $form['title'] . ' (#' . $form_id . ')'));
             $headers = array('Date Submitted');
             if ($digest_export_all_fields) {
                 foreach ($form['fields'] as $field) {
                     if ($field['label']) {
                         $headers[] = $field['label'];
                     }
                 }
             } else {
                 foreach ($form['fields'] as $field) {
                     if ($field['label'] && in_array($field['id'], $digest_export_field_list)) {
                         $headers[] = $field['label'];
                     }
                 }
             }
             fputcsv($csv, $headers);
             if (!$form['leads']) {
                 /* No new entries (but user has opted to receive digests always) */
                 fputcsv($csv, array(__('No new entries.', self::$textdomain)));
             } else {
                 foreach ($form['leads'] as $lead) {
                     $data = array();
                     $lead_data = RGFormsModel::get_lead($lead->id);
                     $data[] = $lead->date_created;
                     if (!$from) {
                         $from = $lead->date_created;
                     } else {
                         $to = $lead->date_created;
                     }
                     foreach ($form['fields'] as $field) {
                         if (!$field['label']) {
                             continue;
                         }
                         if (!$digest_export_all_fields && !in_array($field['id'], $digest_export_field_list)) {
                             continue;
                         }
                         $raw_data = RGFormsModel::get_lead_field_value($lead_data, $field);
                         if (!is_array($raw_data)) {
                             $data[] = $raw_data;
                         } else {
                             $data[] = implode(', ', array_filter($raw_data));
                         }
                     }
                     fputcsv($csv, $data);
                 }
             }
             fputcsv($csv, array('--'));
             /* new line */
         }
         if (!$to) {
             $to = $from;
         }
         $report .= 'Contains entries from ' . $from . " to {$to}\n";
         $report .= 'See CSV attachment';
         fclose($csv);
         $new_csv_attachment = $csv_attachment . '-' . date('YmdHis') . '.csv';
         rename($csv_attachment, $new_csv_attachment);
         wp_mail($email, apply_filters('gf_digest_email_subject', 'Form Digest Report (CSV): ' . implode(', ', $names), $names, array($from, $to), $new_csv_attachment), $report, null, array($new_csv_attachment));
         if (!defined('GF_DIGEST_DOING_TESTS')) {
             unlink($new_csv_attachment);
         }
     }
     if (version_compare(GFCommon::$version, '1.7') >= 0) {
         /* In 1.7 there seems to be an issue with saving */
         GFFormsModel::flush_current_forms();
     }
 }
コード例 #11
0
 /**
  * Shortcode to display the list of completed entries
  */
 function shortcode_gravitylistcompleted($atts)
 {
     global $wpdb;
     $id = $atts['id'];
     /**
      * Only do something if we have a form-id
      */
     if ($id) {
         /**
          * Get the form data
          */
         $form = $this->gravitylist_form[$id];
         /**
          * Get the Attributes with the defaults from the form-settings
          *
          *	id			:	id of the form
          *	rows		:	number of rows to display
          *	title		:	display the form title
          *	debug		:	display field-id and field-type
          *	tquery		:	enabled tQuery support
          *	gfediturl	:	destination-url to edit this record
          *  showtoall	:	show the records to all users or only to form-admin and the record-creator
          *	description	:	display the form description
          *	displaylead	:	display lead-id as first column
          *  requirelogin:	the user must be logged-in to see the entry-list
          *
          */
         extract(shortcode_atts(array('id' => $id, 'rows' => $form['spgfle_rows'], 'debug' => 'false', 'title' => 'true', 'tquery' => $form['spgfle_tquery'], 'showtoall' => $form['spgfle_showtoall'], 'description' => 'true', 'displaylead' => $form['spgfle_displaylead'], 'requirelogin' => $form['spgfle_requirelogin']), $atts));
         $rows = intval($rows);
         $debug = strtolower($debug) == "true" ? true : false;
         $title = strtolower($title) == "true" ? true : false;
         $tquery = strtolower($tquery) == "true" ? true : false;
         $showtoall = strtolower($showtoall) == "true" ? true : false;
         $displaylead = strtolower($displaylead) == "true" ? true : false;
         $description = strtolower($description) == "true" ? true : false;
         $requirelogin = strtolower($requirelogin) == "true" ? true : false;
         /**
          * Check if it's possible to edit 
          * and build the gfediturl
          */
         $gfediturl = $form['spgfle_gfediturl'];
         if (!$form['spgfle_enableedit']) {
             unset($gfediturl);
         }
         if (!is_user_logged_in()) {
             unset($gfediturl);
         }
         if ($gfediturl) {
             $gfediturl = get_permalink($gfediturl);
         }
         /**
          * if requirelogin is set, check if an user is logged in
          */
         if (!$requirelogin || $requirelogin && is_user_logged_in()) {
             $cssclass = $form['spgfle_cssclass'];
             $classes = GFCommon::get_browser_class();
             $html .= "\t<div class=\"{$classes} gform_wrapper {$cssclass}\" id=\"gform_wrapper_{$id}\" >\n";
             /**
              * Display title and description if needed
              */
             $html .= "\t<div class=\"gform_body {$cssclass}\">\n";
             $html .= "\t<br />\n";
             /**
              * Add tQuery support if needed
              */
             if ($tquery) {
                 $tableid = " id=\"gravitylist{$id}\"";
                 if ($form['spgfle_tquerysearch']) {
                     $html .= "<div class=\"gform_tquery_search\">\n";
                     $html .= "\t" . __("Search", 'spgfle') . ": <input id=\"searchinput{$id}\" type=\"text\" class=\"filter\" />\n";
                     $html .= "</div>\n";
                     $html .= "<br />";
                 }
             }
             $html .= "\t<form name=\"gravitylist\" action=\"{$gfediturl}\" method=\"post\">\n";
             $html .= "\t\t<input type=\"hidden\" id=\"gform_edit_id\" name=\"gform_edit_id\" value=\"\" />\n";
             $html .= "\t\t<input type=\"hidden\" id=\"gform_edit_mode\" name=\"gform_edit_mode\" value=\"\" />\n";
             $html .= "\t\t<table class=\"table table-striped table-bordered table-advance table-hover\" {$tableid} cellspacing=\"0\" itemscope=\"itemscope\" itemtype=\"http://schema.org/Table\">\n";
             $html .= "\t\t\t<thead>\n";
             $html .= "\t\t\t\t<tr>\n";
             /**
              * Add a column to display the lead-id
              */
             if ($displaylead) {
                 $html .= "\t\t\t\t\t<th scope=\"col\">" . esc_html('Order ID') . "</th>\n";
             }
             /** 
              * Loop through the Fields
              */
             foreach ((array) $form['fields'] as $field) {
                 /** 
                  * Display 'adminOnly' fields only to form admins
                  */
                 if (!$field['adminOnly'] || GFCommon::current_user_can_any('gravityforms_edit_entries')) {
                     /** 
                      * Only display fields that are checked at the field-settings
                      */
                     if ($field['spgfle_showinlist']) {
                         $html .= "\t\t\t\t\t<th scope=\"col\">" . esc_html($field['label']);
                         if ($debug == true) {
                             $html .= "\t\t\t\t\t<br />{$field['id']}<br />{$field['type']}";
                         }
                         $html .= "\t\t\t\t\t</th>\n";
                     }
                 }
             }
             /** 
              * Add a blank column if we need to link to an edit, view or delete url
              */
             if ($gfediturl) {
                 $html .= "\t\t\t\t\t<th scope=\"col\">&nbsp;</th>\n";
             }
             $html .= "\t\t\t\t</tr>\n";
             $html .= "\t\t\t</thead>\n";
             $html .= "\t\t\t<tbody>\n";
             /** 
              * Create the LIMIT statement
              */
             if (!empty($rows)) {
                 $sqlLimit = "LIMIT {$rows}";
             }
             /**
              * Support for SpGfMySQL-Connect 
              * If we connected the record to a mysql-table and set 'delete lead' to true
              * we have to retrieve the values from the mysql-table
              */
             if ($form['spgfmc_tablename'] && $form['spgfmc_deletelead']) {
                 $leads = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$form['spgfmc_tablename']} ORDER BY lead_id DESC {$sqlLimit}"), ARRAY_A);
             } else {
                 $lead_table_name = RGFormsModel::get_lead_table_name();
                 if (GFCommon::current_user_can_any('gravityforms_edit_entries') || $showtoall) {
                     $leads = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$lead_table_name} WHERE form_id = {$id} AND status = 'active' AND orderStatus = 'complete' ORDER BY id DESC {$sqlLimit}"), ARRAY_A);
                 } else {
                     $leads = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$lead_table_name} WHERE form_id = {$id} AND created_by = %d AND created_by <> 0 AND status = 'active' AND orderStatus = 'complete' ORDER BY id DESC {$sqlLimit}", wp_get_current_user()->ID), ARRAY_A);
                 }
             }
             //echo print_r($leads, true);
             /** 
              * Loop through the Leads
              */
             foreach ($leads as $lead) {
                 if (is_null($lead['id'])) {
                     $lead['id'] = $lead['lead_id'];
                 }
                 if (is_null($lead['lead_id'])) {
                     $lead['lead_id'] = $lead['id'];
                 }
                 //echo print_r($lead, true);
                 /**
                  * Support for Sp-Gf-MySQL-Connect
                  * If we connected the record to a mysql-table and deleted the data
                  * we have to retrieve the values from the mysql-table
                  */
                 if ($form['spgfmc_tablename'] && $form['spgfmc_deletefield']) {
                     if (!$form['spgfmc_spgfmc_deletelead']) {
                         /**
                          * If the lead was not deleted we use the 'lead_id' to
                          * connect the MySQL record with the GF lead
                          */
                         $data = $wpdb->get_row("SELECT * FROM {$form['spgfmc_tablename']} WHERE {$form['spgfmc_field_leadid']} = {$lead['lead_id']}", ARRAY_A);
                         $lead['gform_edit_id'] = $lead['lead_id'];
                     } elseif ($form['spgfmc_spgfmc_deletelead']) {
                         /**
                          * If the lead was deleted we use the already loaded data
                          * But we have to setup some lead values
                          */
                         $data = $lead;
                         $lead['created_by'] = 0;
                         $lead['gform_edit_id'] = $data[$form['spgfmc_primarykey']];
                     } else {
                         /**
                          * We can't load any data
                          */
                         unset($data);
                     }
                     if ($data) {
                         foreach ((array) $form['fields'] as $field) {
                             switch ($field['type']) {
                                 case 'address':
                                     if ($field['spgfmc_fieldname_address1']) {
                                         $lead[$field['id'] . '.1'] = $data[$field['spgfmc_fieldname_address1']];
                                     }
                                     if ($field['spgfmc_fieldname_address1']) {
                                         $lead[$field['id'] . '.2'] = $data[$field['spgfmc_fieldname_address2']];
                                     }
                                     if ($field['spgfmc_fieldname_city']) {
                                         $lead[$field['id'] . '.3'] = $data[$field['spgfmc_fieldname_city']];
                                     }
                                     if ($field['spgfmc_fieldname_state']) {
                                         $lead[$field['id'] . '.4'] = $data[$field['spgfmc_fieldname_state']];
                                     }
                                     if ($field['spgfmc_fieldname_zip']) {
                                         $lead[$field['id'] . '.5'] = $data[$field['spgfmc_fieldname_zip']];
                                     }
                                     if ($field['spgfmc_fieldname_country']) {
                                         $lead[$field['id'] . '.6'] = $data[$field['spgfmc_fieldname_country']];
                                     }
                                     break;
                                 case 'name':
                                     if ($field['spgfmc_fieldname_firstname']) {
                                         $lead[$field['id'] . '.3'] = $data[$field['spgfmc_fieldname_firstname']];
                                     }
                                     if ($field['spgfmc_fieldname_lastname']) {
                                         $lead[$field['id'] . '.6'] = $data[$field['spgfmc_fieldname_lastname']];
                                     }
                                 default:
                                     if ($field['spgfmc_fieldname']) {
                                         $lead[$field['id']] = $data[$field['spgfmc_fieldname']];
                                     }
                                     break;
                             }
                         }
                     }
                 } else {
                     /**
                      * Retrieve the lead
                      */
                     $lead = RGFormsModel::get_lead($lead['id']);
                     $lead['gform_edit_id'] = $lead['id'];
                     if (is_null($lead['lead_id'])) {
                         $lead['lead_id'] = $lead['id'];
                     }
                 }
                 $i = 0;
                 $html .= "\t\t\t\t<tr>\n";
                 //echo print_r($lead, true);
                 /**
                  * Add a column to display the lead-id
                  */
                 if ($displaylead) {
                     $html .= "\t\t\t\t\t<td scope=\"col\" class=\"col{$i}\" width=\"10%\">{$lead['lead_id']}</td>\n";
                 }
                 /** 
                  * Loop through the Fields
                  */
                 foreach ($form['fields'] as $field) {
                     /** 
                      * Display 'adminOnly' fields only to form admins
                      */
                     if (!$field['adminOnly'] || GFCommon::current_user_can_any('gravityforms_edit_entries')) {
                         /** 
                          * Only display fields that are checked at the field-settings
                          */
                         if ($field['spgfle_showinlist']) {
                             $i++;
                             unset($value, $display_value);
                             $value = RGFormsModel::get_lead_field_value($lead, $field);
                             /**
                              * Only the value is stored, but we need to display
                              * the display-data for this value
                              */
                             if ($field['enableChoiceValue'] == '1') {
                                 if (!empty($value)) {
                                     unset($item, $items, $itemcount);
                                     foreach ((array) $value as $single_value) {
                                         if (!empty($single_value)) {
                                             foreach ($field['choices'] as $choices) {
                                                 if ($choices['value'] == $single_value) {
                                                     $items .= '<li>' . $choices['text'] . '</li>';
                                                     $item = $choices['text'];
                                                     $itemcount++;
                                                     break;
                                                 }
                                             }
                                         }
                                     }
                                     if ($itemcount == 1) {
                                         $display_value = $item;
                                     } elseif ($itemcount > 0) {
                                         $display_value = "<ul class='bulleted'>{$items}</ul>";
                                     } else {
                                         $display_value = "";
                                     }
                                 }
                             } else {
                                 $display_value = GFCommon::get_lead_field_display($field, $value, $lead["currency"]);
                             }
                             $html .= "\t\t\t\t\t<td scope=\"col\" class=\"col{$i}\">{$display_value}</td>\n";
                         }
                     }
                 }
                 /**
                  * Display Button to the gfEdit Destination
                  */
                 if ($gfediturl || $gfdeleteurl) {
                     $i++;
                     $html .= "\t\t\t\t\t<td scope=\"col\" class=\"col{$i}\" width=\"25%\">\n";
                     /**
                      * Display the view button
                      */
                     if ($form['spgfle_enableview']) {
                         $html .= "\t\t\t\t\t\t<button class=\"btn default btn-xs blue\" onClick=\"SetHiddenFormSettings({$lead['gform_edit_id']}, 'view')\"><i class=\"fa fa-share\"></i>" . __("PDF", 'spgfle') . "</button>\n";
                     }
                     $html .= "\t\t\t\t\t</td>\n";
                 }
                 $html .= "\t\t\t\t</tr>\n";
             }
             $html .= "\t\t\t</tbody>\n";
             $html .= "\t\t</table>\n";
             if (empty($leads)) {
                 $html .= "<p>No Completed Orders Found</p>\n";
             }
             $html .= "\t</form>\n";
             $html .= "\t</div>\n";
         } else {
             $html = '<p>' . __("You must be logged in.", 'spgfle') . '</p>';
         }
     }
     return $html;
 }
コード例 #12
0
ファイル: plugin.php プロジェクト: healthcommcore/osnap
 public static function get_form_values($form_id)
 {
     global $wpdb;
     $ret = false;
     //$lid = $wpdb->get_var(sprintf("SELECT DISTINCT id FROM %s WHERE form_id = %d AND created_by=%d ORDER BY id DESC LIMIT 1", RGFormsModel::get_lead_table_name(), $form_id, wp_get_current_user()->ID));
     // added by slaven 3/28/13
     // see http://software.troydesign.it/php/wordpress/adminsingle-gravity-forms-add-on.html
     // allows editing of entry by ID
     $rid = (int) $_GET['rid'];
     // Requested ID
     if ($rid) {
         // SLAVEN
         //echo "<h4>RID:".$rid."</h4>";
         $lid = $wpdb->get_var(sprintf("SELECT DISTINCT id FROM %s WHERE form_id = %d AND created_by=%d AND id=%d", RGFormsModel::get_lead_table_name(), $form_id, wp_get_current_user()->ID, $rid));
     } else {
         // SLAVEN
         //echo "<h4>NO RID</h4>";
         $lid = $wpdb->get_var(sprintf("SELECT DISTINCT id FROM %s WHERE form_id = %d AND created_by=%d ORDER BY id DESC LIMIT 1", RGFormsModel::get_lead_table_name(), $form_id, wp_get_current_user()->ID));
     }
     if ($lid) {
         $meta = RGFormsModel::get_form_meta($form_id);
         $lead = RGFormsModel::get_lead($lid);
         $ret = array('lead' => $lead, 'meta' => $meta);
     }
     return $ret;
 }
コード例 #13
0
ファイル: forms_model.php プロジェクト: 812studio/812studio
 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 = self::get_lead_details_table_name();
     //Inserting lead if null
     if ($lead == null) {
         $lead_table = RGFormsModel::get_lead_table_name();
         $user_agent = strlen($_SERVER["HTTP_USER_AGENT"]) > 250 ? substr($_SERVER["HTTP_USER_AGENT"], 0, 250) : $_SERVER["HTTP_USER_AGENT"];
         $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent) VALUES(%d, %s, %s, utc_timestamp(), %s)", $form["id"], self::get_ip(), self::get_current_page_url(), $user_agent));
         //reading newly created lead id
         $lead_id = $wpdb->get_var("SELECT LAST_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 = $lead["post_id"];
     foreach ($form["fields"] as $field) {
         //only save fields that are not hidden (except on entry screen)
         if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array())) {
             if (is_array($field["inputs"])) {
                 foreach ($field["inputs"] as $input) {
                     self::save_input($form, $field, $lead, $current_fields, $input["id"]);
                 }
             } else {
                 self::save_input($form, $field, $lead, $current_fields, $field["id"]);
             }
         }
     }
     //update post_id field if a post was created
     if ($lead["post_id"] != $original_post_id) {
         $wpdb->update($lead_table, array("post_id" => $lead["post_id"]), array("id" => $lead["id"]), array("%d"), array("%d"));
     }
 }
コード例 #14
0
    public static function setup($force_setup = false)
    {
        global $wpdb;
        $version = GFCommon::$version;
        if (get_option("rg_form_version") != $version || $force_setup) {
            $error = "";
            if (!self::has_database_permission($error)) {
                ?>
                <div class='error' style="padding:15px;"><?php 
                echo $error;
                ?>
</div>
                <?php 
            }
            require_once ABSPATH . '/wp-admin/includes/upgrade.php';
            if (!empty($wpdb->charset)) {
                $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
            }
            if (!empty($wpdb->collate)) {
                $charset_collate .= " COLLATE {$wpdb->collate}";
            }
            //------ FORM -----------------------------------------------
            $form_table_name = RGFormsModel::get_form_table_name();
            $sql = "CREATE TABLE " . $form_table_name . " (\r\n                  id mediumint(8) unsigned not null auto_increment,\r\n                  title varchar(150) not null,\r\n                  date_created datetime not null,\r\n                  is_active tinyint(1) not null default 1,\r\n                  PRIMARY KEY  (id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ META -----------------------------------------------
            $meta_table_name = RGFormsModel::get_meta_table_name();
            $sql = "CREATE TABLE " . $meta_table_name . " (\r\n                  form_id mediumint(8) unsigned not null,\r\n                  display_meta longtext,\r\n                  entries_grid_meta longtext,\r\n                  PRIMARY KEY  (form_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //droping outdated form_id index (if one exists)
            self::drop_index($meta_table_name, 'form_id');
            //------ FORM VIEW -----------------------------------------------
            $form_view_table_name = RGFormsModel::get_form_view_table_name();
            $sql = "CREATE TABLE " . $form_view_table_name . " (\r\n                  id bigint(20) unsigned not null auto_increment,\r\n                  form_id mediumint(8) unsigned not null,\r\n                  date_created datetime not null,\r\n                  ip char(15),\r\n                  count mediumint(8) unsigned not null default 1,\r\n                  PRIMARY KEY  (id),\r\n                  KEY form_id (form_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD -----------------------------------------------
            $lead_table_name = RGFormsModel::get_lead_table_name();
            $sql = "CREATE TABLE " . $lead_table_name . " (\r\n                  id int(10) unsigned not null auto_increment,\r\n                  form_id mediumint(8) unsigned not null,\r\n                  post_id bigint(20) unsigned,\r\n                  date_created datetime not null,\r\n                  is_starred tinyint(1) not null default 0,\r\n                  is_read tinyint(1) not null default 0,\r\n                  ip varchar(39) not null,\r\n                  source_url varchar(200) not null default '',\r\n                  user_agent varchar(250) not null default '',\r\n                  currency varchar(5),\r\n                  payment_status varchar(15),\r\n                  payment_date datetime,\r\n                  payment_amount decimal(19,2),\r\n                  transaction_id varchar(50),\r\n                  is_fulfilled tinyint(1),\r\n                  created_by bigint(20) unsigned,\r\n                  transaction_type tinyint(1),\r\n                  status varchar(20) not null default 'active',\r\n                  PRIMARY KEY  (id),\r\n                  KEY form_id (form_id),\r\n                  KEY status (status)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD NOTES ------------------------------------------
            $lead_notes_table_name = RGFormsModel::get_lead_notes_table_name();
            $sql = "CREATE TABLE " . $lead_notes_table_name . " (\r\n                  id int(10) unsigned not null auto_increment,\r\n                  lead_id int(10) unsigned not null,\r\n                  user_name varchar(250),\r\n                  user_id bigint(20),\r\n                  date_created datetime not null,\r\n                  value longtext,\r\n                  PRIMARY KEY  (id),\r\n                  KEY lead_id (lead_id),\r\n                  KEY lead_user_key (lead_id,user_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD DETAIL -----------------------------------------
            $lead_detail_table_name = RGFormsModel::get_lead_details_table_name();
            $sql = "CREATE TABLE " . $lead_detail_table_name . " (\r\n                  id bigint(20) unsigned not null auto_increment,\r\n                  lead_id int(10) unsigned not null,\r\n                  form_id mediumint(8) unsigned not null,\r\n                  field_number float not null,\r\n                  value varchar(" . GFORMS_MAX_FIELD_LENGTH . "),\r\n                  PRIMARY KEY  (id),\r\n                  KEY form_id (form_id),\r\n                  KEY lead_id (lead_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //------ LEAD DETAIL LONG -----------------------------------
            $lead_detail_long_table_name = RGFormsModel::get_lead_details_long_table_name();
            $sql = "CREATE TABLE " . $lead_detail_long_table_name . " (\r\n                  lead_detail_id bigint(20) unsigned not null,\r\n                  value longtext,\r\n                  PRIMARY KEY  (lead_detail_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //droping outdated form_id index (if one exists)
            self::drop_index($lead_detail_long_table_name, 'lead_detail_key');
            //------ LEAD META -----------------------------------
            $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
            $sql = "CREATE TABLE " . $lead_meta_table_name . " (\r\n                  id bigint(20) unsigned not null auto_increment,\r\n                  lead_id bigint(20) unsigned not null,\r\n                  meta_key varchar(255),\r\n                  meta_value longtext,\r\n                  PRIMARY KEY  (id),\r\n                  KEY meta_key (meta_key),\r\n                  KEY lead_id (lead_id)\r\n                ) {$charset_collate};";
            dbDelta($sql);
            //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
            self::fix_checkbox_value();
            //auto-setting license key based on value configured via the GF_LICENSE_KEY constant or the gf_license_key variable
            global $gf_license_key;
            $license_key = defined("GF_LICENSE_KEY") && empty($gf_license_key) ? GF_LICENSE_KEY : $gf_license_key;
            if (!empty($license_key)) {
                update_option("rg_gforms_key", md5($license_key));
            }
            //auto-setting recaptcha keys based on value configured via the constant or global variable
            global $gf_recaptcha_public_key, $gf_recaptcha_private_key;
            $private_key = defined("GF_RECAPTCHA_PRIVATE_KEY") && empty($gf_recaptcha_private_key) ? GF_RECAPTCHA_PRIVATE_KEY : $gf_recaptcha_private_key;
            if (!empty($private_key)) {
                update_option("rg_gforms_captcha_private_key", $private_key);
            }
            $public_key = defined("GF_RECAPTCHA_PUBLIC_KEY") && empty($gf_recaptcha_public_key) ? GF_RECAPTCHA_PUBLIC_KEY : $gf_recaptcha_public_key;
            if (!empty($public_key)) {
                update_option("rg_gforms_captcha_public_key", $public_key);
            }
            //Auto-importing forms based on GF_IMPORT_FILE AND GF_THEME_IMPORT_FILE
            if (defined("GF_IMPORT_FILE") && !get_option("gf_imported_file")) {
                GFExport::import_file(GF_IMPORT_FILE);
                update_option("gf_imported_file", true);
            }
            //adds empty index.php files to upload folders. only for v1.5.2 and below
            if (version_compare(get_option("rg_form_version"), "1.6", "<")) {
                self::add_empty_index_files();
            }
            update_option("rg_form_version", $version);
        }
        //Import theme specific forms if configured. Will only import forms once per theme.
        if (defined("GF_THEME_IMPORT_FILE")) {
            $themes = get_option("gf_imported_theme_file");
            if (!is_array($themes)) {
                $themes = array();
            }
            //if current theme has already imported it's forms, don't import again
            $theme = get_template();
            if (!isset($themes[$theme])) {
                //importing forms
                GFExport::import_file(get_stylesheet_directory() . "/" . GF_THEME_IMPORT_FILE);
                //adding current theme to the list of imported themes. So that forms are not imported again for it.
                $themes[$theme] = true;
                update_option("gf_imported_theme_file", $themes);
            }
        }
    }
コード例 #15
0
 function get_lead_count($form_id, $search, $star = null, $read = null, $column, $approved = false, $leads = array(), $start_date = null, $end_date = null, $limituser = false)
 {
     global $wpdb, $current_user;
     if (!is_numeric($form_id)) {
         return "";
     }
     $detail_table_name = RGFormsModel::get_lead_details_table_name();
     $lead_table_name = RGFormsModel::get_lead_table_name();
     $star_filter = $star !== null ? $wpdb->prepare("AND is_starred=%d ", $star) : "";
     $read_filter = $read !== null ? $wpdb->prepare("AND is_read=%d ", $read) : "";
     if (function_exists('gform_get_meta')) {
         $status_filter = $wpdb->prepare(" AND status=%s ", 'active');
     } else {
         $status_filter = '';
     }
     $start_date_filter = empty($start_date) ? "" : " AND datediff(date_created, '{$start_date}') >=0";
     $end_date_filter = empty($end_date) ? "" : " AND datediff(date_created, '{$end_date}') <=0";
     $search_term = "%{$search}%";
     $search_filter = empty($search) ? "" : $wpdb->prepare("AND ld.value LIKE %s", $search_term);
     $user_filter = '';
     if ($limituser) {
         get_currentuserinfo();
         if ((int) $current_user->ID !== 0 || $current_user->ID === 0 && apply_filters('kws_gf_show_entries_if_not_logged_in', apply_filters('kws_gf_treat_not_logged_in_as_user', true))) {
             if (!empty($current_user->ID)) {
                 $user_filter = $wpdb->prepare(" AND l.created_by=%d ", $current_user->ID);
             } else {
                 $user_filter = $wpdb->prepare(" AND (created_by IS NULL OR created_by=%d)", $current_user->ID);
             }
         } else {
             return false;
         }
     }
     $in_filter = "";
     if ($approved) {
         $in_filter = $wpdb->prepare("l.id IN (SELECT lead_id from {$detail_table_name} WHERE field_number BETWEEN %f AND %f) AND", $column - 0.001, $column + 0.001);
         // This will work once all the fields are converted to the meta_key after 1.6
         #$search_filter .= $wpdb->prepare(" AND m.meta_key = 'is_approved' AND m.meta_value = %s", 1);
     }
     $sql = "SELECT count(distinct l.id) FROM {$lead_table_name} as l,\n\t\t\t\t{$detail_table_name} as ld";
     #		$sql .= function_exists('gform_get_meta') ? " INNER JOIN wp_rg_lead_meta m ON l.id = m.lead_id " : ""; // After 1.6
     $sql .= "\n\t\t\t\tWHERE {$in_filter}\n\t\t\t\tl.form_id={$form_id}\n\t\t\t\tAND ld.form_id={$form_id}\n\t\t\t\tAND l.id = ld.lead_id\n\t\t\t\t{$star_filter}\n\t\t\t\t{$read_filter}\n\t\t\t\t{$status_filter}\n\t\t\t\t{$user_filter}\n\t\t\t\t{$start_date_filter}\n\t\t\t\t{$end_date_filter}\n\t\t\t\t{$search_filter}";
     return $wpdb->get_var($sql);
 }
コード例 #16
0
 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 = self::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 = strlen($_SERVER["HTTP_USER_AGENT"]) > 250 ? substr($_SERVER["HTTP_USER_AGENT"], 0, 250) : $_SERVER["HTTP_USER_AGENT"];
         $currency = GFCommon::get_currency();
         $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"], self::get_ip(), self::get_current_page_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_field = null;
     $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_field = $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())) {
             // process calculation fields after all fields have been saved
             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) {
                     self::save_input($form, $field, $lead, $current_fields, $input["id"]);
                 }
             } else {
                 self::save_input($form, $field, $lead, $current_fields, $field["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) {
                     self::save_input($form, $calculation_field, $lead, $current_fields, $input["id"]);
                 }
             } else {
                 self::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field["id"]);
             }
         }
         self::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
     }
     //saving total field as the last field of the form.
     if ($total_field) {
         self::save_input($form, $total_field, $lead, $current_fields, $total_field["id"]);
     }
 }
コード例 #17
0
				<td class='rtlib_delete column-rtlib_delete aligncenter'><a
						id="rtlib-delete--<?php 
        echo esc_attr($gravity_field->id);
        ?>
" class="rtlib_delete_mapping"
						style="color: red; cursor: pointer" data-mapping-id="<?php 
        echo esc_attr($gravity_field->id);
        ?>
"><span class="dashicons dashicons-no-alt"></span></a>
					<img class="rt-lib-spinner" src="<?php 
        echo admin_url() . 'images/spinner.gif';
        ?>
" />
				</td>
				<?php 
        $gravityLeadTableName = RGFormsModel::get_lead_table_name();
        global $wpdb;
        $sql = $wpdb->prepare("SELECT id FROM {$gravityLeadTableName} WHERE form_id=%d AND status='active'", $gravity_field->form_id);
        ?>
				<script><?php 
        echo 'var arr_lead_id_' . $gravity_field->form_id . ' = ' . json_encode($wpdb->get_results($sql, ARRAY_A));
        ?>
</script>
			</tr>
		<?php 
    }
} else {
    ?>
	<tr>
		<td colspan='5'><?php 
    echo esc_attr(_e('No Mapping Found!'));
コード例 #18
0
ファイル: gravityforms.php プロジェクト: kidaak/gravityforms
 private static function fix_lead_meta_form_id_values()
 {
     global $wpdb;
     $lead_meta_table_name = RGFormsModel::get_lead_meta_table_name();
     $lead_table_name = RGFormsModel::get_lead_table_name();
     $sql = "UPDATE {$lead_meta_table_name} lm,{$lead_table_name} l SET lm.form_id = l.form_id\n\t\t\t\tWHERE lm.form_id=0 AND lm.lead_id = l.id;\n\t\t\t\t";
     $wpdb->get_results($sql);
 }
コード例 #19
0
/**
 * Finds Gravity forms data over 1 week old and submits it to ovr_delete_gf_entry to be removed
 * To be scheduled by a wp_cron task
 * @global object $wpdb
 */
function ovr_delete_old_gf_data()
{
    global $wpdb;
    $lead_table = RGFormsModel::get_lead_table_name();
    $now = new DateTime();
    // subtract 1 week from current date
    $date = $now->sub(new DateInterval('P1W'));
    $sql = $wpdb->prepare("SELECT id FROM {$lead_table} WHERE date_created <= %s", $date->format('Y-m-d 00:00:00'));
    $results = $wpdb->get_results($sql);
    foreach ($results as $result) {
        ovr_delete_gf_entry($result->id);
    }
}