wpdb = $wpdb; $this->plugin_settings = $wpdb->prefix . 'ai_app_onsite_plugin_settings'; $this->app_properties = $wpdb->prefix . 'ai_app_onsite_app_properties'; $this->model_settings = $wpdb->prefix . 'ai_app_onsite_model_settings'; $this->field_selector_settings = $wpdb->prefix . 'ai_app_onsite_field_selector_settings'; $this->prompt_editor = $wpdb->prefix . 'ai_app_onsite_prompt_editor'; $this->user_statistics = $wpdb->prefix . 'ai_app_onsite_user_statistics'; } public function ai_app_onsite_create_table() { // Define table names with the proper prefix $plugin_settings = $this->plugin_settings; $app_properties = $this->app_properties; $model_settings = $this->model_settings; $field_selector_settings = $this->field_selector_settings; $prompt_editor = $this->prompt_editor; $user_statistics = $this->user_statistics; // Table name with WordPress prefix $plugin_settings_table = $plugin_settings; $app_properties_table = $app_properties; $model_settings_table = $model_settings; $field_selector_settings_table = $field_selector_settings; $prompt_editor_table = $prompt_editor; $user_statistics_table = $user_statistics; // SQL queries to create the tables (without prepare for static queries) $sql_settings = "CREATE TABLE IF NOT EXISTS $plugin_settings_table ( id INT(11) NOT NULL AUTO_INCREMENT, app_id INT(30) NOT NULL, agree_terms BOOLEAN, app_selector TEXT, app_email VARCHAR(300), banned_words TEXT, banned_words_csv TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id) )"; $sql_app_properties = "CREATE TABLE IF NOT EXISTS $app_properties_table ( id INT(11) NOT NULL AUTO_INCREMENT, app_id INT(30) NOT NULL, app_name TEXT, app_name_show TEXT, app_logo TEXT, app_disclaimer VARCHAR(300), app_description VARCHAR(1000), submit_button_txt TEXT, title_color TEXT, font_color TEXT, bg_color TEXT, app_corner TEXT, app_height TEXT, short_code_genrated VARCHAR(30) DEFAULT 'NO', created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id) )"; $sql_model_settings = "CREATE TABLE IF NOT EXISTS $model_settings_table ( id INT(11) NOT NULL AUTO_INCREMENT, app_id INT(30) NOT NULL, openai_key VARCHAR(255), key_status VARCHAR(11), model VARCHAR(255), temperature FLOAT DEFAULT '1.0', f_penalty FLOAT DEFAULT '1.0', p_penalty FLOAT DEFAULT '1.0', max_tokens INT DEFAULT '1', top_p FLOAT DEFAULT '1.0', created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id) )"; $sql_field_selector_settings = "CREATE TABLE IF NOT EXISTS $field_selector_settings_table ( id INT(30) NOT NULL AUTO_INCREMENT, app_id INT(30) NOT NULL, field_uniqueid VARCHAR(30) NOT NULL, field_id VARCHAR(300) NOT NULL, app_width VARCHAR(30) NOT NULL, field_type VARCHAR(30) NOT NULL, field_label VARCHAR(300) NOT NULL, field_maxchar VARCHAR(20) NOT NULL, field_dropdown_options TEXT, field_sample_text VARCHAR(300) NOT NULL, field_require_field_status TINYINT(1) NOT NULL, field_include_in_export_email TINYINT(1) NOT NULL, field_position INT(30) NOT NULL, field_tag VARCHAR(1000) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id) )"; $sql_prompt_editor = "CREATE TABLE IF NOT EXISTS $prompt_editor_table ( id INT(30) NOT NULL AUTO_INCREMENT, app_id INT(30) NOT NULL, prompt LONGTEXT NOT NULL, prompt_html LONGTEXT NOT NULL, ai_response_style VARCHAR(30), ai_response_tone VARCHAR(30), eg_ai_output VARCHAR(1000), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id) )"; $sql_user_statistics = "CREATE TABLE IF NOT EXISTS $user_statistics_table ( id INT(30) NOT NULL AUTO_INCREMENT, app_id INT(30) NOT NULL, user_ip VARCHAR(255) NOT NULL, prompt TEXT, user_geolocation TEXT, response_id VARCHAR(255) NOT NULL, data TEXT, used_token VARCHAR(255) NOT NULL, feedback VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id) )"; // Array of SQL queries for all tables $sql_queries = array( $sql_settings, $sql_app_properties, $sql_model_settings, $sql_field_selector_settings, $sql_prompt_editor, $sql_user_statistics, ); // Execute the SQL queries require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $success = true; foreach ($sql_queries as $temp) { dbDelta($temp); } return $success; } public function ai_app_onsite_drop_table() { // Define the table names with the proper prefix $plugin_settings_table = $this->plugin_settings; $app_properties_table = $this->app_properties; $model_settings_table = $this->model_settings; $field_selector_settings_table = $this->field_selector_settings; $prompt_editor_table = $this->prompt_editor; $user_statistics_table = $this->user_statistics; // Drop the tables to delete all data securely $this->wpdb->query("DROP TABLE IF EXISTS $plugin_settings_table"); $this->wpdb->query("DROP TABLE IF EXISTS $app_properties_table"); $this->wpdb->query("DROP TABLE IF EXISTS $model_settings_table"); $this->wpdb->query("DROP TABLE IF EXISTS $field_selector_settings_table"); $this->wpdb->query("DROP TABLE IF EXISTS $prompt_editor_table"); $this->wpdb->query("DROP TABLE IF EXISTS $user_statistics_table"); } } }