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);
            }
        }
    }
Exemplo n.º 2
0
 public static function setup_database()
 {
     global $wpdb;
     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}";
     }
     //Fixes issue with dbDelta lower-casing table names, which cause problems on case sensitive DB servers.
     add_filter('dbdelta_create_queries', array('RGForms', 'dbdelta_fix_case'));
     /*
      * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
      * As of 4.2, however, WP core moved to utf8mb4, which uses 4 bytes per character. This means that an index which
      * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
      */
     $max_index_length = 191;
     //------ 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              is_trash tinyint(1) not null default 0,\n              PRIMARY KEY  (id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //droping table that was created by mistake in version 1.6.3.2
     $wpdb->query('DROP TABLE IF EXISTS A' . $form_table_name);
     //------ 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              confirmations longtext,\n              notifications longtext,\n              PRIMARY KEY  (form_id)\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 . " (\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 varchar(39) not null,\n              source_url varchar(200) not null default '',\n              user_agent varchar(250) not null default '',\n              currency varchar(5),\n              payment_status varchar(15),\n              payment_date datetime,\n              payment_amount decimal(19,2),\n              payment_method varchar(30),\n              transaction_id varchar(50),\n              is_fulfilled tinyint(1),\n              created_by bigint(20) unsigned,\n              transaction_type tinyint(1),\n              status varchar(20) not null default 'active',\n              PRIMARY KEY  (id),\n              KEY form_id (form_id),\n              KEY status (status)\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              note_type varchar(50),\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 . ' (
           id bigint(20) unsigned not null auto_increment,
           lead_id int(10) unsigned not null,
           form_id mediumint(8) unsigned not null,
           field_number float not null,
           value varchar(' . GFORMS_MAX_FIELD_LENGTH . "),\n              PRIMARY KEY  (id),\n              KEY form_id (form_id),\n              KEY lead_id (lead_id),\n              KEY lead_field_number (lead_id,field_number)\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              PRIMARY KEY  (lead_detail_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     // dropping 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();
     // dropping meta_key and form_id_meta_key (if they exist) to prevent duplicate keys error on upgrade
     if (version_compare(get_option('rg_form_version'), '1.9.8.12', '<')) {
         self::drop_index($lead_meta_table_name, 'meta_key');
         self::drop_index($lead_meta_table_name, 'form_id_meta_key');
     }
     $sql = 'CREATE TABLE ' . $lead_meta_table_name . " (\n              id bigint(20) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null default 0,\n              lead_id bigint(20) unsigned not null,\n              meta_key varchar(255),\n              meta_value longtext,\n              PRIMARY KEY  (id),\n              KEY meta_key (meta_key({$max_index_length})),\n              KEY lead_id (lead_id),\n              KEY form_id_meta_key (form_id,meta_key({$max_index_length}))\n            ) {$charset_collate};";
     dbDelta($sql);
     //------ INCOMPLETE SUBMISSIONS -------------------------------
     $incomplete_submissions_table_name = RGFormsModel::get_incomplete_submissions_table_name();
     $sql = 'CREATE TABLE ' . $incomplete_submissions_table_name . " (\n              uuid char(32) not null,\n              email varchar(255),\n              form_id mediumint(8) unsigned not null,\n              date_created datetime not null,\n              ip varchar(39) not null,\n              source_url longtext not null,\n              submission longtext not null,\n              PRIMARY KEY  (uuid),\n              KEY form_id (form_id)\n            ) {$charset_collate};";
     dbDelta($sql);
     remove_filter('dbdelta_create_queries', array('RGForms', 'dbdelta_fix_case'));
     //fix form_id value needed to update from version 1.6.11
     self::fix_lead_meta_form_id_values();
     //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
     self::fix_checkbox_value();
     //fix leading and trailing spaces in Form objects and entry values
     if (version_compare(get_option('rg_form_version'), '1.8.3.1', '<')) {
         self::fix_leading_and_trailing_spaces();
     }
 }
 /**
  *
  * @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;
 }
Exemplo n.º 4
0
 public static function setup_database()
 {
     global $wpdb;
     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}";
     }
     //Fixes issue with dbDelta lower-casing table names, which cause problems on case sensitive DB servers.
     add_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
     //------ 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              is_trash tinyint(1) not null default 0,\n              PRIMARY KEY  (id)\n            ) {$charset_collate};";
     dbDelta($sql);
     //droping table that was created by mistake in version 1.6.3.2
     $wpdb->query("DROP TABLE IF EXISTS A" . $form_table_name);
     //------ 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              confirmations longtext,\n              notifications longtext,\n              PRIMARY KEY  (form_id)\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 . " (\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 varchar(39) not null,\n              source_url varchar(200) not null default '',\n              user_agent varchar(250) not null default '',\n              currency varchar(5),\n              payment_status varchar(15),\n              payment_date datetime,\n              payment_amount decimal(19,2),\n              payment_method varchar(30),\n              transaction_id varchar(50),\n              is_fulfilled tinyint(1),\n              created_by bigint(20) unsigned,\n              transaction_type tinyint(1),\n              status varchar(20) not null default 'active',\n              PRIMARY KEY  (id),\n              KEY form_id (form_id),\n              KEY status (status)\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              KEY lead_field_number (lead_id,field_number)\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              PRIMARY KEY  (lead_detail_id)\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 . " (\n              id bigint(20) unsigned not null auto_increment,\n              form_id mediumint(8) unsigned not null default 0,\n              lead_id bigint(20) unsigned not null,\n              meta_key varchar(255),\n              meta_value longtext,\n              PRIMARY KEY  (id),\n              KEY meta_key (meta_key),\n              KEY lead_id (lead_id),\n              KEY form_id_meta_key (form_id,meta_key)\n            ) {$charset_collate};";
     dbDelta($sql);
     remove_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
     //fix form_id value needed to update from version 1.6.11
     self::fix_lead_meta_form_id_values();
     //fix checkbox value. needed for version 1.0 and below but won't hurt for higher versions
     self::fix_checkbox_value();
     //fix leading and trailing spaces in Form objects and entry values from versions prior to 1.8.2
     if (version_compare(get_option("rg_form_version"), "1.8.2", "<=")) {
         //uncomment to test
         //self::fix_leading_and_trailing_spaces();
     }
 }
Exemplo n.º 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);
             }
         }
     }
 }
 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);
         }
     }
 }
Exemplo n.º 7
0
    public static function setup_site($blog_id = null)
    {
        if (empty($blog_id)) {
            $blog_id = get_current_blog_id();
        }
        //if a blog id is specified, switch to it
        if (MULTISITE && !switch_to_blog($blog_id)) {
            return;
        }
        global $wpdb;
        $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}";
        }
        //Fixes issue with dbDelta lower-casing table names, which cause problems on case sensitive DB servers.
        add_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
        //------ FORM -----------------------------------------------
        $form_table_name = RGFormsModel::get_form_table_name();
        $sql = "CREATE TABLE " . $form_table_name . " (\n\n              id mediumint(8) unsigned not null auto_increment,\n\n              title varchar(150) not null,\n\n              date_created datetime not null,\n\n              is_active tinyint(1) not null default 1,\n\n              PRIMARY KEY  (id)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //droping table that was created by mistake in version 1.6.3.2
        $wpdb->query("DROP TABLE IF EXISTS A" . $form_table_name);
        //------ META -----------------------------------------------
        $meta_table_name = RGFormsModel::get_meta_table_name();
        $sql = "CREATE TABLE " . $meta_table_name . " (\n\n              form_id mediumint(8) unsigned not null,\n\n              display_meta longtext,\n\n              entries_grid_meta longtext,\n\n              confirmations longtext,\n\n              notifications longtext,\n\n              PRIMARY KEY  (form_id)\n\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 . " (\n\n              id bigint(20) unsigned not null auto_increment,\n\n              form_id mediumint(8) unsigned not null,\n\n              date_created datetime not null,\n\n              ip char(15),\n\n              count mediumint(8) unsigned not null default 1,\n\n              PRIMARY KEY  (id),\n\n              KEY form_id (form_id)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        //------ LEAD -----------------------------------------------
        $lead_table_name = RGFormsModel::get_lead_table_name();
        $sql = "CREATE TABLE " . $lead_table_name . " (\n\n              id int(10) unsigned not null auto_increment,\n\n              form_id mediumint(8) unsigned not null,\n\n              post_id bigint(20) unsigned,\n\n              date_created datetime not null,\n\n              is_starred tinyint(1) not null default 0,\n\n              is_read tinyint(1) not null default 0,\n\n              ip varchar(39) not null,\n\n              source_url varchar(200) not null default '',\n\n              user_agent varchar(250) not null default '',\n\n              currency varchar(5),\n\n              payment_status varchar(15),\n\n              payment_date datetime,\n\n              payment_amount decimal(19,2),\n\n              transaction_id varchar(50),\n\n              is_fulfilled tinyint(1),\n\n              created_by bigint(20) unsigned,\n\n              transaction_type tinyint(1),\n\n              status varchar(20) not null default 'active',\n\n              PRIMARY KEY  (id),\n\n              KEY form_id (form_id),\n\n              KEY status (status)\n\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\n              id int(10) unsigned not null auto_increment,\n\n              lead_id int(10) unsigned not null,\n\n              user_name varchar(250),\n\n              user_id bigint(20),\n\n              date_created datetime not null,\n\n              value longtext,\n\n              PRIMARY KEY  (id),\n\n              KEY lead_id (lead_id),\n\n              KEY lead_user_key (lead_id,user_id)\n\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\n              id bigint(20) unsigned not null auto_increment,\n\n              lead_id int(10) unsigned not null,\n\n              form_id mediumint(8) unsigned not null,\n\n              field_number float not null,\n\n              value varchar(" . GFORMS_MAX_FIELD_LENGTH . "),\n\n              PRIMARY KEY  (id),\n\n              KEY form_id (form_id),\n\n              KEY lead_id (lead_id),\n\n              KEY lead_field_number (lead_id,field_number)\n\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\n              lead_detail_id bigint(20) unsigned not null,\n\n              value longtext,\n\n              PRIMARY KEY  (lead_detail_id)\n\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 . " (\n\n              id bigint(20) unsigned not null auto_increment,\n\n              form_id mediumint(8) unsigned not null default 0,\n\n              lead_id bigint(20) unsigned not null,\n\n              meta_key varchar(255),\n\n              meta_value longtext,\n\n              PRIMARY KEY  (id),\n\n              KEY meta_key (meta_key),\n\n              KEY lead_id (lead_id),\n\n              KEY form_id_meta_key (form_id,meta_key)\n\n            ) {$charset_collate};";
        dbDelta($sql);
        remove_filter('dbdelta_create_queries', array("RGForms", "dbdelta_fix_case"));
        //fix form_id value needed to update from version 1.6.11
        self::fix_lead_meta_form_id_values();
        //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", GFCommon::$version);
        //going back to current blog
        if (MULTISITE) {
            restore_current_blog();
        }
    }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
/**
 * Delete Gravity Forms entry specified
 * @global object $wpdb
 *@param string $lead_id, id of gravity form entry to remove
 */
function ovr_delete_gf_entry($lead_id)
{
    global $wpdb;
    // Prepare variables.
    $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 lead detail long.
    $sql = $wpdb->prepare("DELETE FROM {$lead_detail_long_table} WHERE lead_detail_id IN(SELECT id FROM {$lead_detail_table} WHERE lead_id = %d)", $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);
    // Finally, ensure everything is deleted (like stuff from Addons).
    GFAPI::delete_entry($lead_id);
}