Exemplo n.º 1
0
 /**
  * Installs the DB tables and data
  *
  * @access	public
  * @return	bool
  */
 function install_tables_and_data()
 {
     // Sites
     $Q[] = "CREATE TABLE `exp_sites` (\n\t\t\t`site_id` int(5) unsigned NOT NULL auto_increment,\n\t\t\t`site_label` varchar(100) NOT NULL default '',\n\t\t\t`site_name` varchar(50) NOT NULL default '',\n\t\t\t`site_description` text NULL,\n\t\t\t`site_system_preferences` mediumtext NOT NULL ,\n\t\t\t`site_member_preferences` TEXT NOT NULL ,\n\t\t\t`site_template_preferences` TEXT NOT NULL ,\n\t\t\t`site_channel_preferences` TEXT NOT NULL ,\n\t\t\t`site_bootstrap_checksums` TEXT NOT NULL ,\n\t\t\t`site_pages` TEXT NOT NULL ,\n\t\t\tPRIMARY KEY `site_id` (`site_id`),\n\t\t\tKEY `site_name` (`site_name`)\n\t\t)";
     // Session data
     $Q[] = "CREATE TABLE exp_sessions (\n\t\t\tsession_id varchar(40) default '0' NOT NULL,\n\t\t\tmember_id int(10) default '0' NOT NULL,\n\t\t\tadmin_sess tinyint(1) default '0' NOT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\tuser_agent varchar(120) NOT NULL,\n\t\t\tlogin_state varchar(32) NULL DEFAULT NULL,\n\t\t\tfingerprint varchar(40) NOT NULL,\n\t\t\tsess_start int(10) unsigned DEFAULT '0' NOT NULL,\n\t\t\tlast_activity int(10) unsigned DEFAULT '0' NOT NULL,\n\t\t\tPRIMARY KEY `session_id` (`session_id`),\n\t\t\tKEY `member_id` (`member_id`),\n\t\t\tKEY `last_activity_idx` (`last_activity`)\n\t\t)";
     // Throttle
     $Q[] = "CREATE TABLE exp_throttle (\n\t\t\tthrottle_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\tlast_activity int(10) unsigned DEFAULT '0' NOT NULL,\n\t\t\thits int(10) unsigned NOT NULL,\n\t\t\tlocked_out char(1) NOT NULL default 'n',\n\t\t\tPRIMARY KEY `throttle_id` (`throttle_id`),\n\t\t\tKEY `ip_address` (`ip_address`),\n\t\t\tKEY `last_activity` (`last_activity`)\n\t\t)";
     // System stats
     $Q[] = "CREATE TABLE exp_stats (\n\t\t\tstat_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\ttotal_members mediumint(7) NOT NULL default '0',\n\t\t\trecent_member_id int(10) default '0' NOT NULL,\n\t\t\trecent_member varchar(50) NOT NULL,\n\t\t\ttotal_entries mediumint(8) default '0' NOT NULL,\n\t\t\ttotal_forum_topics mediumint(8) default '0' NOT NULL,\n\t\t\ttotal_forum_posts mediumint(8) default '0' NOT NULL,\n\t\t\ttotal_comments mediumint(8) default '0' NOT NULL,\n\t\t\tlast_entry_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_forum_post_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_comment_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_visitor_date int(10) unsigned default '0' NOT NULL,\n\t\t\tmost_visitors mediumint(7) NOT NULL default '0',\n\t\t\tmost_visitor_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_cache_clear int(10) unsigned default '0' NOT NULL,\n\t\t\tPRIMARY KEY `stat_id` (`stat_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Online users
     $Q[] = "CREATE TABLE exp_online_users (\n\t\t\tonline_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tmember_id int(10) default '0' NOT NULL,\n\t\t\tin_forum char(1) NOT NULL default 'n',\n\t\t\tname varchar(50) default '0' NOT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\tdate int(10) unsigned default '0' NOT NULL,\n\t\t\tanon char(1) NOT NULL,\n\t\t\tPRIMARY KEY `online_id` (`online_id`),\n\t\t\tKEY `date` (`date`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Actions table
     // Actions are events that require processing. Used by modules class.
     $Q[] = "CREATE TABLE exp_actions (\n\t\t\taction_id int(4) unsigned NOT NULL auto_increment,\n\t\t\tclass varchar(50) NOT NULL,\n\t\t\tmethod varchar(50) NOT NULL,\n\t\t\tcsrf_exempt tinyint(1) UNSIGNED NOT NULL default 0,\n\t\t\tPRIMARY KEY `action_id` (`action_id`)\n\t\t)";
     // Modules table
     // Contains a list of all installed modules
     $Q[] = "CREATE TABLE exp_modules (\n\t\t\tmodule_id int(4) unsigned NOT NULL auto_increment,\n\t\t\tmodule_name varchar(50) NOT NULL,\n\t\t\tmodule_version varchar(12) NOT NULL,\n\t\t\thas_cp_backend char(1) NOT NULL default 'n',\n\t\t\thas_publish_fields char(1) NOT NULL default 'n',\n\t\t\tPRIMARY KEY `module_id` (`module_id`)\n\t\t)";
     // Plugins table
     // Contains a list of all installed plugins
     $Q[] = "CREATE TABLE exp_plugins (\n\t\t\tplugin_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tplugin_name varchar(50) NOT NULL,\n\t\t\tplugin_package varchar(50) NOT NULL,\n\t\t\tplugin_version varchar(12) NOT NULL,\n\t\t\tis_typography_related char(1) NOT NULL default 'n',\n\t\t\tPRIMARY KEY `plugin_id` (`plugin_id`)\n\t\t)";
     // Security Hashes
     // Used to store hashes needed to process forms in 'secure mode'
     $Q[] = "CREATE TABLE exp_security_hashes (\n\t\t\thash_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tdate int(10) unsigned NOT NULL,\n\t\t\tsession_id varchar(40) default '0' NOT NULL,\n\t\t\thash varchar(40) NOT NULL,\n\t\t\tPRIMARY KEY `hash_id` (`hash_id`),\n\t\t\tKEY `session_id` (`session_id`)\n\t\t)";
     // CAPTCHA data
     $Q[] = "CREATE TABLE exp_captcha (\n\t\t\tcaptcha_id bigint(13) unsigned NOT NULL auto_increment,\n\t\t\tdate int(10) unsigned NOT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\tword varchar(20) NOT NULL,\n\t\t\tPRIMARY KEY `captcha_id` (`captcha_id`),\n\t\t\tKEY `word` (`word`)\n\t\t)";
     // Password Lockout
     // If password lockout is enabled, a user only gets
     // four attempts to log-in within a specified period.
     // This table holds the a list of locked out users
     $Q[] = "CREATE TABLE exp_password_lockout (\n\t\t\tlockout_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tlogin_date int(10) unsigned NOT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\tuser_agent varchar(120) NOT NULL,\n\t\t\tusername varchar(50) NOT NULL,\n\t\t\tPRIMARY KEY `lockout_id` (`lockout_id`),\n\t\t\tKEY `login_date` (`login_date`),\n\t\t\tKEY `ip_address` (`ip_address`),\n\t\t\tKEY `user_agent` (`user_agent`)\n\t\t)";
     // Reset password
     // If a user looses their password, this table
     // holds the reset code.
     $Q[] = "CREATE TABLE exp_reset_password (\n\t\t\treset_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tmember_id int(10) unsigned NOT NULL,\n\t\t\tresetcode varchar(12) NOT NULL,\n\t\t\tdate int(10) NOT NULL,\n\t\t\tPRIMARY KEY `reset_id` (`reset_id`)\n\t\t)";
     // Email Cache
     // We store all email messages that are sent from the CP
     $Q[] = "CREATE TABLE exp_email_cache (\n\t\t\tcache_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tcache_date int(10) unsigned default '0' NOT NULL,\n\t\t\ttotal_sent int(6) unsigned NOT NULL,\n\t\t\tfrom_name varchar(70) NOT NULL,\n\t\t\tfrom_email varchar(75) NOT NULL,\n\t\t\trecipient text NOT NULL,\n\t\t\tcc text NOT NULL,\n\t\t\tbcc text NOT NULL,\n\t\t\trecipient_array mediumtext NOT NULL,\n\t\t\tsubject varchar(120) NOT NULL,\n\t\t\tmessage mediumtext NOT NULL,\n\t\t\t`plaintext_alt` MEDIUMTEXT NOT NULL,\n\t\t\tmailtype varchar(6) NOT NULL,\n\t\t\ttext_fmt varchar(40) NOT NULL,\n\t\t\twordwrap char(1) NOT NULL default 'y',\n\t\t\tattachments MEDIUMTEXT,\n\t\t\tPRIMARY KEY `cache_id` (`cache_id`)\n\t\t)";
     // Cached Member Groups
     // We use this table to store the member group assignments
     // for each email that is sent.  Since you can send email
     // to various combinations of members, we store the member
     // group numbers in this table, which is joined to the
     // table above when we need to re-send an email from cache.
     $Q[] = "CREATE TABLE exp_email_cache_mg (\n\t\t\tcache_id int(6) unsigned NOT NULL,\n\t\t\tgroup_id smallint(4) NOT NULL,\n\t\t\tPRIMARY KEY `cache_id_group_id` (`cache_id`, `group_id`)\n\t\t)";
     // We do the same with mailing lists
     $Q[] = "CREATE TABLE exp_email_cache_ml (\n\t\t\tcache_id int(6) unsigned NOT NULL,\n\t\t\tlist_id smallint(4) NOT NULL,\n\t\t\tPRIMARY KEY `cache_id_list_id` (`cache_id`, `list_id`)\n\t\t)";
     // Email Console Cache
     // Emails sent from the member profile email console are saved here.
     $Q[] = "CREATE TABLE exp_email_console_cache (\n\t\t\tcache_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tcache_date int(10) unsigned default '0' NOT NULL,\n\t\t\tmember_id int(10) unsigned NOT NULL,\n\t\t\tmember_name varchar(50) NOT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\trecipient varchar(75) NOT NULL,\n\t\t\trecipient_name varchar(50) NOT NULL,\n\t\t\tsubject varchar(120) NOT NULL,\n\t\t\tmessage mediumtext NOT NULL,\n\t\t\tPRIMARY KEY `cache_id` (`cache_id`)\n\t\t)";
     // Member table
     // Contains the member info
     $Q[] = "CREATE TABLE exp_members (\n\t\t\tmember_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tgroup_id smallint(4) NOT NULL default '0',\n\t\t\tusername varchar(50) NOT NULL,\n\t\t\tscreen_name varchar(50) NOT NULL,\n\t\t\tpassword varchar(128) NOT NULL,\n\t\t\tsalt varchar(128) NOT NULL DEFAULT '',\n\t\t\tunique_id varchar(40) NOT NULL,\n\t\t\tcrypt_key varchar(40) NULL DEFAULT NULL,\n\t\t\tauthcode varchar(10) NULL DEFAULT NULL,\n\t\t\temail varchar(75) NOT NULL,\n\t\t\turl varchar(150) NULL DEFAULT NULL,\n\t\t\tlocation varchar(50) NULL DEFAULT NULL,\n\t\t\toccupation varchar(80) NULL DEFAULT NULL,\n\t\t\tinterests varchar(120) NULL DEFAULT NULL,\n\t\t\tbday_d int(2) NULL DEFAULT NULL,\n\t\t\tbday_m int(2) NULL DEFAULT NULL,\n\t\t\tbday_y int(4) NULL DEFAULT NULL,\n\t\t\taol_im varchar(50) NULL DEFAULT NULL,\n\t\t\tyahoo_im varchar(50) NULL DEFAULT NULL,\n\t\t\tmsn_im varchar(50) NULL DEFAULT NULL,\n\t\t\ticq varchar(50) NULL DEFAULT NULL,\n\t\t\tbio text NULL,\n\t\t\tsignature text NULL,\n\t\t\tavatar_filename varchar(120) NULL DEFAULT NULL,\n\t\t\tavatar_width int(4) unsigned NULL DEFAULT NULL,\n\t\t\tavatar_height int(4) unsigned NULL DEFAULT NULL,\n\t\t\tphoto_filename varchar(120) NULL DEFAULT NULL,\n\t\t\tphoto_width int(4) unsigned NULL DEFAULT NULL,\n\t\t\tphoto_height int(4) unsigned NULL DEFAULT NULL,\n\t\t\tsig_img_filename varchar(120) NULL DEFAULT NULL,\n\t\t\tsig_img_width int(4) unsigned NULL DEFAULT NULL,\n\t\t\tsig_img_height int(4) unsigned NULL DEFAULT NULL,\n\t\t\tignore_list text NULL,\n\t\t\tprivate_messages int(4) unsigned DEFAULT '0' NOT NULL,\n\t\t\taccept_messages char(1) NOT NULL default 'y',\n\t\t\tlast_view_bulletins int(10) NOT NULL default 0,\n\t\t\tlast_bulletin_date int(10) NOT NULL default 0,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\tjoin_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_visit int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_activity int(10) unsigned default '0' NOT NULL,\n\t\t\ttotal_entries mediumint(8) unsigned NOT NULL default '0',\n\t\t\ttotal_comments mediumint(8) unsigned NOT NULL default '0',\n\t\t\ttotal_forum_topics mediumint(8) default '0' NOT NULL,\n\t\t\ttotal_forum_posts mediumint(8) default '0' NOT NULL,\n\t\t\tlast_entry_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_comment_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_forum_post_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_email_date int(10) unsigned default '0' NOT NULL,\n\t\t\tin_authorlist char(1) NOT NULL default 'n',\n\t\t\taccept_admin_email char(1) NOT NULL default 'y',\n\t\t\taccept_user_email char(1) NOT NULL default 'y',\n\t\t\tnotify_by_default char(1) NOT NULL default 'y',\n\t\t\tnotify_of_pm char(1) NOT NULL default 'y',\n\t\t\tdisplay_avatars char(1) NOT NULL default 'y',\n\t\t\tdisplay_signatures char(1) NOT NULL default 'y',\n\t\t\tparse_smileys char(1) NOT NULL default 'y',\n\t\t\tsmart_notifications char(1) NOT NULL default 'y',\n\t\t\tlanguage varchar(50) NOT NULL,\n\t\t\ttimezone varchar(50) NOT NULL,\n\t\t\ttime_format char(2) DEFAULT '12' NOT NULL,\n\t\t\tdate_format varchar(8) DEFAULT '%n/%j/%Y' NOT NULL,\n\t\t\tinclude_seconds char(1) DEFAULT 'n' NOT NULL,\n\t\t\tprofile_theme varchar(32) NULL DEFAULT NULL,\n\t\t\tforum_theme varchar(32) NULL DEFAULT NULL,\n\t\t\ttracker text NULL,\n\t\t\ttemplate_size varchar(2) NOT NULL default '28',\n\t\t\tnotepad text NULL,\n\t\t\tnotepad_size varchar(2) NOT NULL default '18',\n\t\t\tbookmarklets text NULL,\n\t\t\tquick_links text NULL,\n\t\t\tquick_tabs text NULL,\n\t\t\tshow_sidebar char(1) NOT NULL default 'n',\n\t\t\tpmember_id int(10) NOT NULL default '0',\n\t\t\trte_enabled char(1) NOT NULL DEFAULT 'y',\n\t\t\trte_toolset_id int(10) NOT NULL DEFAULT '0',\n\t\t\tcp_homepage varchar(20) NULL DEFAULT NULL,\n\t\t\tcp_homepage_channel varchar(255) NULL DEFAULT NULL,\n\t\t\tcp_homepage_custom varchar(100) NULL DEFAULT NULL,\n\t\t\tPRIMARY KEY `member_id` (`member_id`),\n\t\t\tKEY `group_id` (`group_id`),\n\t\t\tKEY `unique_id` (`unique_id`),\n\t\t\tKEY `password` (`password`)\n\t\t)";
     // CP homepage layout
     // Each member can have their own control panel layout.
     // We store their preferences here.
     $Q[] = "CREATE TABLE exp_member_homepage (\n\t\t\tmember_id int(10) unsigned NOT NULL,\n\t\t\trecent_entries char(1) NOT NULL default 'l',\n\t\t\trecent_entries_order int(3) unsigned NOT NULL default '0',\n\t\t\trecent_comments char(1) NOT NULL default 'l',\n\t\t\trecent_comments_order int(3) unsigned NOT NULL default '0',\n\t\t\trecent_members char(1) NOT NULL default 'n',\n\t\t\trecent_members_order int(3) unsigned NOT NULL default '0',\n\t\t\tsite_statistics char(1) NOT NULL default 'r',\n\t\t\tsite_statistics_order int(3) unsigned NOT NULL default '0',\n\t\t\tmember_search_form char(1) NOT NULL default 'n',\n\t\t\tmember_search_form_order int(3) unsigned NOT NULL default '0',\n\t\t\tnotepad char(1) NOT NULL default 'r',\n\t\t\tnotepad_order int(3) unsigned NOT NULL default '0',\n\t\t\tbulletin_board char(1) NOT NULL default 'r',\n\t\t\tbulletin_board_order int(3) unsigned NOT NULL default '0',\n\t\t\tpmachine_news_feed char(1) NOT NULL default 'n',\n\t\t\tpmachine_news_feed_order int(3) unsigned NOT NULL default '0',\n\t\t\tPRIMARY KEY `member_id` (`member_id`)\n\t\t)";
     // Member Groups table
     $Q[] = "CREATE TABLE exp_member_groups (\n\t\t\t`group_id` smallint(4) unsigned NOT NULL,\n\t\t\t`site_id` int(4) unsigned NOT NULL DEFAULT '1',\n\t\t\t`group_title` varchar(100) NOT NULL,\n\t\t\t`group_description` text NOT NULL,\n\t\t\t`is_locked` char(1) NOT NULL DEFAULT 'y',\n\t\t\t`can_view_offline_system` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_view_online_system` char(1) NOT NULL DEFAULT 'y',\n\t\t\t`can_access_cp` char(1) NOT NULL DEFAULT 'y',\n\t\t\t`can_access_footer_report_bug` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_footer_new_ticket` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_footer_user_guide` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_files` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_design` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_addons` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_members` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_sys_prefs` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_comm` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_utilities` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_data` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_logs` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_admin_channels` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_admin_design` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_members` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_admin_mbr_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_admin_mbr_templates` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_ban_users` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_admin_addons` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_categories` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_categories` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_view_other_entries` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_other_entries` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_assign_post_authors` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_self_entries` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_all_entries` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_view_other_comments` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_own_comments` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_own_comments` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_all_comments` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_all_comments` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_moderate_comments` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_send_cached_email` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_email_member_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_email_from_profile` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_view_profiles` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_html_buttons` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_self` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`mbr_delete_notify_emails` varchar(255) DEFAULT NULL,\n\t\t\t`can_post_comments` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`exclude_from_moderation` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_search` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`search_flood_control` mediumint(5) unsigned NOT NULL,\n\t\t\t`can_send_private_messages` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`prv_msg_send_limit` smallint(5) unsigned NOT NULL DEFAULT '20',\n\t\t\t`prv_msg_storage_limit` smallint(5) unsigned NOT NULL DEFAULT '60',\n\t\t\t`can_attach_in_private_messages` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_send_bulletins` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`include_in_authorlist` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`include_in_memberlist` char(1) NOT NULL DEFAULT 'y',\n\t\t\t`cp_homepage` varchar(20) DEFAULT NULL,\n\t\t\t`cp_homepage_channel` int(10) unsigned NOT NULL DEFAULT '0',\n\t\t\t`cp_homepage_custom` varchar(100) DEFAULT NULL,\n\t\t\t`can_create_entries` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_self_entries` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_upload_new_files` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_files` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_files` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_upload_new_toolsets` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_toolsets` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_toolsets` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_upload_directories` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_upload_directories` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_upload_directories` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_channels` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_channels` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_channels` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_channel_fields` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_channel_fields` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_channel_fields` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_statuses` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_statuses` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_statuses` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_categories` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_member_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_member_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_member_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_members` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_members` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_new_templates` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_templates` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_templates` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_template_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_template_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_template_groups` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_template_partials` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_template_partials` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_template_partials` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_create_template_variables` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_delete_template_variables` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_edit_template_variables` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_security_settings` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_translate` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_import` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`can_access_sql_manager` char(1) NOT NULL DEFAULT 'n',\n\t\t\tPRIMARY KEY `group_id_site_id` (`group_id`, `site_id`)\n\t\t)";
     // Channel access privs
     // Member groups assignment for each channel
     $Q[] = "CREATE TABLE exp_channel_member_groups (\n\t\t\tgroup_id smallint(4) unsigned NOT NULL,\n\t\t\tchannel_id int(6) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `group_id_channel_id` (`group_id`, `channel_id`)\n\t\t)";
     // Module access privs
     // Member Group assignment for each module
     $Q[] = "CREATE TABLE exp_module_member_groups (\n\t\t\tgroup_id smallint(4) unsigned NOT NULL,\n\t\t\tmodule_id mediumint(5) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `group_id_module_id` (`group_id`, `module_id`)\n\t\t)";
     // Template Group access privs
     // Member group assignment for each template group
     $Q[] = "CREATE TABLE exp_template_member_groups (\n\t\t\tgroup_id smallint(4) unsigned NOT NULL,\n\t\t\ttemplate_group_id mediumint(5) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `group_id_template_group_id` (`group_id`, `template_group_id`)\n\t\t)";
     // Member Custom Fields
     // Stores the defenition of each field
     $Q[] = "CREATE TABLE exp_member_fields (\n\t\t\tm_field_id int(4) unsigned NOT NULL auto_increment,\n\t\t\tm_field_name varchar(32) NOT NULL,\n\t\t\tm_field_label varchar(50) NOT NULL,\n\t\t\tm_field_description text NOT NULL,\n\t\t\tm_field_type varchar(12) NOT NULL default 'text',\n\t\t\tm_field_list_items text NOT NULL,\n\t\t\tm_field_ta_rows tinyint(2) default '8',\n\t\t\tm_field_maxl smallint(3) NULL DEFAULT NULL,\n\t\t\tm_field_width varchar(6) NULL DEFAULT NULL,\n\t\t\tm_field_search char(1) NOT NULL default 'y',\n\t\t\tm_field_required char(1) NOT NULL default 'n',\n\t\t\tm_field_public char(1) NOT NULL default 'y',\n\t\t\tm_field_reg char(1) NOT NULL default 'n',\n\t\t\tm_field_cp_reg char(1) NOT NULL default 'n',\n\t\t\tm_field_fmt char(5) NOT NULL default 'none',\n\t\t\tm_field_show_fmt char(1) NOT NULL default 'y',\n\t\t\tm_field_order int(3) unsigned NULL DEFAULT NULL,\n\t\t\tm_field_text_direction char(3) DEFAULT 'ltr',\n\t\t\tPRIMARY KEY `m_field_id` (`m_field_id`)\n\t\t\t)";
     // Member Data
     // Stores the actual data
     $Q[] = "CREATE TABLE exp_member_data (\n\t\t\tmember_id int(10) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `member_id` (`member_id`)\n\t\t)";
     // Channel Table
     // @confirm: I changed comment_max_chars from a NULL default to 5000 - DA
     $Q[] = "CREATE TABLE exp_channels (\n\t\t\tchannel_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tchannel_name varchar(40) NOT NULL,\n\t\t\tchannel_title varchar(100) NOT NULL,\n\t\t\tchannel_url varchar(100) NOT NULL,\n\t\t\tchannel_description varchar(255) NULL DEFAULT NULL,\n\t\t\tchannel_lang varchar(12) NOT NULL,\n\t\t\ttotal_entries mediumint(8) default '0' NOT NULL,\n\t\t\ttotal_comments mediumint(8) default '0' NOT NULL,\n\t\t\tlast_entry_date int(10) unsigned default '0' NOT NULL,\n\t\t\tlast_comment_date int(10) unsigned default '0' NOT NULL,\n\t\t\tcat_group varchar(255) NULL DEFAULT NULL,\n\t\t\tstatus_group int(4) unsigned NULL DEFAULT NULL,\n\t\t\tdeft_status varchar(50) NOT NULL default 'open',\n\t\t\tfield_group int(4) unsigned NULL DEFAULT NULL,\n\t\t\tsearch_excerpt int(4) unsigned NULL DEFAULT NULL,\n\t\t\tdeft_category varchar(60) NULL DEFAULT NULL,\n\t\t\tdeft_comments char(1) NOT NULL default 'y',\n\t\t\tchannel_require_membership char(1) NOT NULL default 'y',\n\t\t\tchannel_max_chars int(5) unsigned NULL DEFAULT NULL,\n\t\t\tchannel_html_formatting char(4) NOT NULL default 'all',\n\t\t\textra_publish_controls char(1) NOT NULL default 'n',\n\t\t\tchannel_allow_img_urls char(1) NOT NULL default 'y',\n\t\t\tchannel_auto_link_urls char(1) NOT NULL default 'n',\n\t\t\tchannel_notify char(1) NOT NULL default 'n',\n\t\t\tchannel_notify_emails varchar(255) NULL DEFAULT NULL,\n\t\t\tcomment_url varchar(80) NULL DEFAULT NULL,\n\t\t\tcomment_system_enabled char(1) NOT NULL default 'y',\n\t\t\tcomment_require_membership char(1) NOT NULL default 'n',\n\t\t\tcomment_moderate char(1) NOT NULL default 'n',\n\t\t\tcomment_max_chars int(5) unsigned NULL DEFAULT '5000',\n\t\t\tcomment_timelock int(5) unsigned NOT NULL default '0',\n\t\t\tcomment_require_email char(1) NOT NULL default 'y',\n\t\t\tcomment_text_formatting char(5) NOT NULL default 'xhtml',\n\t\t\tcomment_html_formatting char(4) NOT NULL default 'safe',\n\t\t\tcomment_allow_img_urls char(1) NOT NULL default 'n',\n\t\t\tcomment_auto_link_urls char(1) NOT NULL default 'y',\n\t\t\tcomment_notify char(1) NOT NULL default 'n',\n\t\t\tcomment_notify_authors char(1) NOT NULL default 'n',\n\t\t\tcomment_notify_emails varchar(255) NULL DEFAULT NULL,\n\t\t\tcomment_expiration int(4) unsigned NOT NULL default '0',\n\t\t\tsearch_results_url varchar(80) NULL DEFAULT NULL,\n\t\t\trss_url varchar(80) NULL DEFAULT NULL,\n\t\t\tenable_versioning char(1) NOT NULL default 'n',\n\t\t\tmax_revisions smallint(4) unsigned NOT NULL default 10,\n\t\t\tdefault_entry_title varchar(100) NULL DEFAULT NULL,\n\t\t\ttitle_field_label varchar(100) NOT NULL DEFAULT 'Title',\n\t\t\turl_title_prefix varchar(80) NULL DEFAULT NULL,\n\t\t\tlive_look_template int(10) UNSIGNED NOT NULL default 0,\n\t\t\tPRIMARY KEY `channel_id` (`channel_id`),\n\t\t\tKEY `cat_group` (`cat_group`),\n\t\t\tKEY `status_group` (`status_group`),\n\t\t\tKEY `field_group` (`field_group`),\n\t\t\tKEY `channel_name` (`channel_name`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Channel Titles
     // We store channel titles separately from channel data
     $Q[] = "CREATE TABLE exp_channel_titles (\n\t\t\tentry_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tchannel_id int(4) unsigned NOT NULL,\n\t\t\tauthor_id int(10) unsigned NOT NULL default 0,\n\t\t\tforum_topic_id int(10) unsigned NULL DEFAULT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\ttitle varchar(200) NOT NULL,\n\t\t\turl_title varchar(200) NOT NULL,\n\t\t\tstatus varchar(50) NOT NULL,\n\t\t\tversioning_enabled char(1) NOT NULL default 'n',\n\t\t\tview_count_one int(10) unsigned NOT NULL default 0,\n\t\t\tview_count_two int(10) unsigned NOT NULL default 0,\n\t\t\tview_count_three int(10) unsigned NOT NULL default 0,\n\t\t\tview_count_four int(10) unsigned NOT NULL default 0,\n\t\t\tallow_comments varchar(1) NOT NULL default 'y',\n\t\t\tsticky varchar(1) NOT NULL default 'n',\n\t\t\tentry_date int(10) NOT NULL,\n\t\t\tyear char(4) NOT NULL,\n\t\t\tmonth char(2) NOT NULL,\n\t\t\tday char(3) NOT NULL,\n\t\t\texpiration_date int(10) NOT NULL default 0,\n\t\t\tcomment_expiration_date int(10) NOT NULL default 0,\n\t\t\tedit_date bigint(14),\n\t\t\trecent_comment_date int(10) NULL DEFAULT NULL,\n\t\t\tcomment_total int(4) unsigned NOT NULL default 0,\n\t\t\tPRIMARY KEY `entry_id` (`entry_id`),\n\t\t\tKEY `channel_id` (`channel_id`),\n\t\t\tKEY `author_id` (`author_id`),\n\t\t\tKEY `url_title` (`url_title`),\n\t\t\tKEY `status` (`status`),\n\t\t\tKEY `entry_date` (`entry_date`),\n\t\t\tKEY `expiration_date` (`expiration_date`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Channel Titles Autosave
     // Used for the autosave functionality
     $Q[] = "CREATE TABLE exp_channel_entries_autosave (\n\t\t\tentry_id int(10) unsigned NOT NULL auto_increment,\n\t\t\toriginal_entry_id int(10) unsigned NOT NULL,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tchannel_id int(4) unsigned NOT NULL,\n\t\t\tauthor_id int(10) unsigned NOT NULL default 0,\n\t\t\tforum_topic_id int(10) unsigned NULL DEFAULT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\ttitle varchar(100) NOT NULL,\n\t\t\turl_title varchar(75) NOT NULL,\n\t\t\tstatus varchar(50) NOT NULL,\n\t\t\tversioning_enabled char(1) NOT NULL default 'n',\n\t\t\tview_count_one int(10) unsigned NOT NULL default 0,\n\t\t\tview_count_two int(10) unsigned NOT NULL default 0,\n\t\t\tview_count_three int(10) unsigned NOT NULL default 0,\n\t\t\tview_count_four int(10) unsigned NOT NULL default 0,\n\t\t\tallow_comments varchar(1) NOT NULL default 'y',\n\t\t\tsticky varchar(1) NOT NULL default 'n',\n\t\t\tentry_date int(10) NOT NULL,\n\t\t\tyear char(4) NOT NULL,\n\t\t\tmonth char(2) NOT NULL,\n\t\t\tday char(3) NOT NULL,\n\t\t\texpiration_date int(10) NOT NULL default 0,\n\t\t\tcomment_expiration_date int(10) NOT NULL default 0,\n\t\t\tedit_date bigint(14),\n\t\t\trecent_comment_date int(10) NULL DEFAULT NULL,\n\t\t\tcomment_total int(4) unsigned NOT NULL default 0,\n\t\t\tentry_data text NULL,\n\t\t\tPRIMARY KEY `entry_id` (`entry_id`),\n\t\t\tKEY `channel_id` (`channel_id`),\n\t\t\tKEY `author_id` (`author_id`),\n\t\t\tKEY `url_title` (`url_title`),\n\t\t\tKEY `status` (`status`),\n\t\t\tKEY `entry_date` (`entry_date`),\n\t\t\tKEY `expiration_date` (`expiration_date`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     $Q[] = "CREATE TABLE exp_entry_versioning (\n\t\t\tversion_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tentry_id int(10) unsigned NOT NULL,\n\t\t\tchannel_id int(4) unsigned NOT NULL,\n\t\t\tauthor_id int(10) unsigned NOT NULL,\n\t\t\tversion_date int(10) NOT NULL,\n\t\t\tversion_data mediumtext NOT NULL,\n\t\t\tPRIMARY KEY `version_id` (`version_id`),\n\t\t\tKEY `entry_id` (`entry_id`)\n\t\t)";
     // Channel Custom Field Groups
     $Q[] = "CREATE TABLE exp_field_groups (\n\t\t\tgroup_id int(4) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_name varchar(50) NOT NULL,\n\t\t\tPRIMARY KEY `group_id` (`group_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Channel Custom Field Definitions
     $Q[] = "CREATE TABLE exp_channel_fields (\n\t\t\tfield_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_id int(4) unsigned NOT NULL,\n\t\t\tfield_name varchar(32) NOT NULL,\n\t\t\tfield_label varchar(50) NOT NULL,\n\t\t\tfield_instructions TEXT NULL,\n\t\t\tfield_type varchar(50) NOT NULL default 'text',\n\t\t\tfield_list_items text NOT NULL,\n\t\t\tfield_pre_populate char(1) NOT NULL default 'n',\n\t\t\tfield_pre_channel_id int(6) unsigned NULL DEFAULT NULL,\n\t\t\tfield_pre_field_id int(6) unsigned NULL DEFAULT NULL,\n\t\t\tfield_ta_rows tinyint(2) default '8',\n\t\t\tfield_maxl smallint(3) NULL DEFAULT NULL,\n\t\t\tfield_required char(1) NOT NULL default 'n',\n\t\t\tfield_text_direction CHAR(3) NOT NULL default 'ltr',\n\t\t\tfield_search char(1) NOT NULL default 'n',\n\t\t\tfield_is_hidden char(1) NOT NULL default 'n',\n\t\t\tfield_fmt varchar(40) NOT NULL default 'xhtml',\n\t\t\tfield_show_fmt char(1) NOT NULL default 'y',\n\t\t\tfield_order int(3) unsigned NOT NULL,\n\t\t\tfield_content_type varchar(20) NOT NULL default 'any',\n\t\t\tfield_settings text NULL,\n\t\t\tPRIMARY KEY `field_id` (`field_id`),\n\t\t\tKEY `group_id` (`group_id`),\n\t\t\tKEY `field_type` (`field_type`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Frontend Channel Form Settings
     $Q[] = "CREATE TABLE `exp_channel_form_settings` (\n\t\t\t`channel_form_settings_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`site_id` int(4) unsigned NOT NULL DEFAULT '0',\n\t\t\t`channel_id` int(6) unsigned NOT NULL DEFAULT '0',\n\t\t\t`default_status` varchar(50) NOT NULL DEFAULT 'open',\n\t\t\t`allow_guest_posts` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`default_author` int(11) NOT NULL DEFAULT '0',\n\t\t\tPRIMARY KEY `channel_form_settings_id` (`channel_form_settings_id`),\n\t\t\tKEY `site_id` (`site_id`),\n\t\t\tKEY `channel_id` (`channel_id`)\n\t\t)";
     // Relationships table
     $Q[] = "CREATE TABLE exp_relationships (\n\t\t\trelationship_id int(6) UNSIGNED NOT NULL auto_increment,\n\t\t\tparent_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\tchild_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\tfield_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\tgrid_field_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\tgrid_col_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\tgrid_row_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\t`order` int(10) UNSIGNED NOT NULL default 0,\n\t\t\tPRIMARY KEY `relationship_id` (`relationship_id`),\n\t\t\tKEY `parent_id` (`parent_id`),\n\t\t\tKEY `child_id` (`child_id`),\n\t\t\tKEY `field_id` (`field_id`),\n\t\t\tKEY `grid_row_id` (`grid_row_id`)\n\t\t)";
     // Channel data
     $Q[] = "CREATE TABLE exp_channel_data (\n\t\t\tentry_id int(10) unsigned NOT NULL,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tchannel_id int(4) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `entry_id` (`entry_id`),\n\t\t\tKEY `channel_id` (`channel_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Status Groups
     $Q[] = "CREATE TABLE exp_status_groups (\n\t\t\tgroup_id int(4) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_name varchar(50) NOT NULL,\n\t\t\tPRIMARY KEY `group_id` (`group_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Status data
     $Q[] = "CREATE TABLE exp_statuses (\n\t\t\tstatus_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_id int(4) unsigned NOT NULL,\n\t\t\tstatus varchar(50) NOT NULL,\n\t\t\tstatus_order int(3) unsigned NOT NULL,\n\t\t\thighlight varchar(30) NOT NULL,\n\t\t\tPRIMARY KEY `status_id` (`status_id`),\n\t\t\tKEY `group_id` (`group_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Status "no access"
     // Stores groups that can not access certain statuses
     $Q[] = "CREATE TABLE exp_status_no_access (\n\t\t\tstatus_id int(6) unsigned NOT NULL,\n\t\t\tmember_group smallint(4) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `status_id_member_group` (`status_id`, `member_group`)\n\t\t)";
     // Category Groups
     $Q[] = "CREATE TABLE exp_category_groups (\n\t\t\tgroup_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_name varchar(50) NOT NULL,\n\t\t\tsort_order char(1) NOT NULL default 'a',\n\t\t\texclude_group TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t`field_html_formatting` char(4) NOT NULL default 'all',\n\t\t\t`can_edit_categories` TEXT NULL,\n\t\t\t`can_delete_categories` TEXT NULL,\n\t\t\tPRIMARY KEY `group_id` (`group_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Category data
     $Q[] = "CREATE TABLE exp_categories (\n\t\t\tcat_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_id int(6) unsigned NOT NULL,\n\t\t\tparent_id int(4) unsigned NOT NULL,\n\t\t\tcat_name varchar(100) NOT NULL,\n\t\t\t`cat_url_title` varchar(75) NOT NULL,\n\t\t\tcat_description text NULL,\n\t\t\tcat_image varchar(120) NULL,\n\t\t\tcat_order int(4) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `cat_id` (`cat_id`),\n\t\t\tKEY `group_id` (`group_id`),\n\t\t\tKEY `cat_name` (`cat_name`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_category_fields` (\n\t\t\t`field_id` int(6) unsigned NOT NULL auto_increment,\n\t\t\t`site_id` int(4) unsigned NOT NULL default 1,\n\t\t\t`group_id` int(4) unsigned NOT NULL,\n\t\t\t`field_name` varchar(32) NOT NULL default '',\n\t\t\t`field_label` varchar(50) NOT NULL default '',\n\t\t\t`field_type` varchar(12) NOT NULL default 'text',\n\t\t\t`field_list_items` text NOT NULL,\n\t\t\t`field_maxl` smallint(3) NOT NULL default 128,\n\t\t\t`field_ta_rows` tinyint(2) NOT NULL default 8,\n\t\t\t`field_default_fmt` varchar(40) NOT NULL default 'none',\n\t\t\t`field_show_fmt` char(1) NOT NULL default 'y',\n\t\t\t`field_text_direction` CHAR(3) NOT NULL default 'ltr',\n\t\t\t`field_required` char(1) NOT NULL default 'n',\n\t\t\t`field_order` int(3) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `field_id` (`field_id`),\n\t\t\tKEY `site_id` (`site_id`),\n\t\t\tKEY `group_id` (`group_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_category_field_data` (\n\t\t\t`cat_id` int(4) unsigned NOT NULL,\n\t\t\t`site_id` int(4) unsigned NOT NULL default 1,\n\t\t\t`group_id` int(4) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `cat_id` (`cat_id`),\n\t\t\tKEY `site_id` (`site_id`),\n\t\t\tKEY `group_id` (`group_id`)\n\t\t)";
     // Category posts
     // This table stores the channel entry ID and the category IDs
     // that are assigned to it
     $Q[] = "CREATE TABLE exp_category_posts (\n\t\t\tentry_id int(10) unsigned NOT NULL,\n\t\t\tcat_id int(10) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `entry_id_cat_id` (`entry_id`, `cat_id`)\n\t\t)";
     // Control panel log
     $Q[] = "CREATE TABLE exp_cp_log (\n\t\t\tid int(10) NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tmember_id int(10) unsigned NOT NULL,\n\t\t\tusername varchar(32) NOT NULL,\n\t\t\tip_address varchar(45) default '0' NOT NULL,\n\t\t\tact_date int(10) NOT NULL,\n\t\t\taction varchar(200) NOT NULL,\n\t\t\tPRIMARY KEY `id` (`id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Control panel search
     $Q[] = "CREATE TABLE `exp_cp_search_index` (\n\t\t\t`search_id` int(10) UNSIGNED NOT NULL auto_increment,\n\t\t\t`controller` varchar(20) default NULL,\n\t\t\t`method` varchar(50) default NULL,\n\t\t\t`language` varchar(20) default NULL,\n\t\t\t`access` varchar(50) default NULL,\n\t\t\t`keywords` text,\n\t\t\tPRIMARY KEY `search_id` (`search_id`),\n\t\t\tFULLTEXT(`keywords`)\n\t\t) ENGINE=MyISAM ";
     // HTML buttons
     // These are the buttons that appear on the PUBLISH page.
     // Each member can have their own set of buttons
     $Q[] = "CREATE TABLE exp_html_buttons (\n\t\t\tid int(10) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tmember_id int(10) default 0 NOT NULL,\n\t\t\ttag_name varchar(32) NOT NULL,\n\t\t\ttag_open varchar(120) NOT NULL,\n\t\t\ttag_close varchar(120) NOT NULL,\n\t\t\taccesskey varchar(32) NOT NULL,\n\t\t\ttag_order int(3) unsigned NOT NULL,\n\t\t\ttag_row char(1) NOT NULL default 1,\n\t\t\tclassname varchar(20) NULL DEFAULT NULL,\n\t\t\tPRIMARY KEY `id` (`id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Layout Publish
     // Custom layout for for the publish page.
     $Q[] = "CREATE TABLE exp_layout_publish (\n\t\t\tlayout_id int(10) UNSIGNED NOT NULL auto_increment,\n\t\t\tsite_id int(4) UNSIGNED NOT NULL default 1,\n\t\t\tchannel_id int(4) UNSIGNED NOT NULL default 0,\n\t\t\tlayout_name varchar(50) NOT NULL,\n\t\t\tfield_layout text,\n\t\t\tPRIMARY KEY(`layout_id`),\n\t\t\tKEY `site_id` (`site_id`),\n\t\t\tKEY `channel_id` (`channel_id`)\n\t\t)";
     $Q[] = "CREATE TABLE exp_layout_publish_member_groups (\n\t\t\tlayout_id int(10) UNSIGNED NOT NULL,\n\t\t\tgroup_id int(4) UNSIGNED NOT NULL,\n\t\t\tPRIMARY KEY `layout_id_group_id` (`layout_id`, `group_id`)\n\t\t)";
     // Template Groups
     $Q[] = "CREATE TABLE exp_template_groups (\n\t\t\tgroup_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_name varchar(50) NOT NULL,\n\t\t\tgroup_order int(3) unsigned NOT NULL,\n\t\t\tis_site_default char(1) NOT NULL default 'n',\n\t\t\tPRIMARY KEY `group_id` (`group_id`),\n\t\t\tKEY `site_id` (`site_id`),\n\t\t\tKEY `group_name_idx` (`group_name`),\n\t\t\tKEY `group_order_idx` (`group_order`)\n\t\t)";
     // Template data
     $Q[] = "CREATE TABLE exp_templates (\n\t\t\ttemplate_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tgroup_id int(6) unsigned NOT NULL,\n\t\t\ttemplate_name varchar(50) NOT NULL,\n\t\t\ttemplate_type varchar(16) NOT NULL default 'webpage',\n\t\t\ttemplate_data mediumtext NULL,\n\t\t\ttemplate_notes text NULL,\n\t\t\tedit_date int(10) NOT NULL DEFAULT 0,\n\t\t\tlast_author_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\tcache char(1) NOT NULL default 'n',\n\t\t\trefresh int(6) unsigned NOT NULL default 0,\n\t\t\tno_auth_bounce varchar(50) NOT NULL default '',\n\t\t\tenable_http_auth CHAR(1) NOT NULL default 'n',\n\t\t\tallow_php char(1) NOT NULL default 'n',\n\t\t\tphp_parse_location char(1) NOT NULL default 'o',\n\t\t\thits int(10) unsigned NOT NULL default 0,\n\t\t\tprotect_javascript char(1) NOT NULL default 'n',\n\t\t\tPRIMARY KEY `template_id` (`template_id`),\n\t\t\tKEY `group_id` (`group_id`),\n\t\t\tKEY `template_name` (`template_name`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Template Routes
     $Q[] = "CREATE TABLE `exp_template_routes` (\n\t\t\t`route_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`template_id` int(10) unsigned NOT NULL,\n\t\t\t`order` int(10) unsigned DEFAULT NULL,\n\t\t\t`route` varchar(512) DEFAULT NULL,\n\t\t\t`route_parsed` varchar(512) DEFAULT NULL,\n\t\t\t`route_required` char(1) NOT NULL DEFAULT 'n',\n\t\t\tPRIMARY KEY (`route_id`),\n\t\t\tKEY `template_id` (`template_id`)\n\t\t)";
     // Template "no access"
     // Since each template can be made private to specific member groups
     // we store member IDs of people who can not access certain templates
     $Q[] = "CREATE TABLE exp_template_no_access (\n\t\t\ttemplate_id int(6) unsigned NOT NULL,\n\t\t\tmember_group smallint(4) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `template_id_member_group` (`template_id`, `member_group`)\n\t\t)";
     // Specialty Templates
     // This table contains the various specialty templates, like:
     // Admin notification of new members
     // Admin notification of comments
     // Membership activation instruction
     // Member lost password instructions
     // Validated member notification
     $Q[] = "CREATE TABLE exp_specialty_templates (\n\t\t\ttemplate_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tenable_template char(1) NOT NULL default 'y',\n\t\t\ttemplate_name varchar(50) NOT NULL,\n\t\t\tdata_title varchar(80) NOT NULL,\n\t\t\ttemplate_type varchar(16) NULL,\n\t\t\ttemplate_subtype varchar(16) NULL,\n\t\t\ttemplate_data text NOT NULL,\n\t\t\ttemplate_notes text NULL,\n\t\t\tedit_date int(10) NOT NULL DEFAULT 0,\n\t\t\tlast_author_id int(10) UNSIGNED NOT NULL default 0,\n\t\t\tPRIMARY KEY `template_id` (`template_id`),\n\t\t\tKEY `template_name` (`template_name`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Global variables
     // These are user-definable variables
     $Q[] = "CREATE TABLE exp_global_variables (\n\t\t\tvariable_id int(6) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tvariable_name varchar(50) NOT NULL,\n\t\t\tvariable_data text NOT NULL,\n\t\t\tPRIMARY KEY `variable_id` (`variable_id`),\n\t\t\tKEY `variable_name` (`variable_name`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Snippets
     // These are user-definable early-parsed variables
     // for holding dynamic content
     $Q[] = "CREATE TABLE `exp_snippets` (\n\t\t\t`snippet_id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t`site_id` int(4) NOT NULL,\n\t\t\t`snippet_name` varchar(75) NOT NULL,\n\t\t\t`snippet_contents` text NULL,\n\t\t\tPRIMARY KEY (`snippet_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Revision tracker
     // This is our versioning table, used to store each
     // change that is made to a template.
     $Q[] = "CREATE TABLE exp_revision_tracker (\n\t\t\ttracker_id int(10) unsigned NOT NULL auto_increment,\n\t\t\titem_id int(10) unsigned NOT NULL,\n\t\t\titem_table varchar(20) NOT NULL,\n\t\t\titem_field varchar(20) NOT NULL,\n\t\t\titem_date int(10) NOT NULL,\n\t\t\titem_author_id int(10) UNSIGNED NOT NULL,\n\t\t\titem_data mediumtext NOT NULL,\n\t\t\tPRIMARY KEY `tracker_id` (`tracker_id`),\n\t\t\tKEY `item_id` (`item_id`)\n\t\t)";
     // Upload preferences
     $Q[] = "CREATE TABLE exp_upload_prefs (\n\t\t\tid int(4) unsigned NOT NULL auto_increment,\n\t\t\tsite_id INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tname varchar(50) NOT NULL,\n\t\t\tserver_path varchar(255) NOT NULL default '',\n\t\t\turl varchar(100) NOT NULL,\n\t\t\tallowed_types varchar(3) NOT NULL default 'img',\n\t\t\tdefault_modal_view varchar(5) NOT NULL default 'list',\n\t\t\tmax_size varchar(16) NULL DEFAULT NULL,\n\t\t\tmax_height varchar(6) NULL DEFAULT NULL,\n\t\t\tmax_width varchar(6) NULL DEFAULT NULL,\n\t\t\tproperties varchar(120) NULL DEFAULT NULL,\n\t\t\tpre_format varchar(120) NULL DEFAULT NULL,\n\t\t\tpost_format varchar(120) NULL DEFAULT NULL,\n\t\t\tfile_properties varchar(120) NULL DEFAULT NULL,\n\t\t\tfile_pre_format varchar(120) NULL DEFAULT NULL,\n\t\t\tfile_post_format varchar(120) NULL DEFAULT NULL,\n\t\t\tcat_group varchar(255) NULL DEFAULT NULL,\n\t\t\tbatch_location varchar(255) NULL DEFAULT NULL,\n\t\t\tmodule_id int(4) NOT NULL DEFAULT 0,\n\t\t\tPRIMARY KEY `id` (`id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     // Upload "no access"
     // We store the member groups that can not access various upload destinations
     $Q[] = "CREATE TABLE exp_upload_no_access (\n\t\t\tupload_id int(6) unsigned NOT NULL,\n\t\t\tmember_group smallint(4) unsigned NOT NULL,\n\t\t\tPRIMARY KEY `upload_id_member_group` (`upload_id`, `member_group`)\n\t\t)";
     // Private messaging tables
     $Q[] = "CREATE TABLE exp_message_attachments (\n\t\t\tattachment_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tsender_id int(10) unsigned NOT NULL default 0,\n\t\t\tmessage_id int(10) unsigned NOT NULL default 0,\n\t\t\tattachment_name varchar(50) NOT NULL default '',\n\t\t\tattachment_hash varchar(40) NOT NULL default '',\n\t\t\tattachment_extension varchar(20) NOT NULL default '',\n\t\t\tattachment_location varchar(150) NOT NULL default '',\n\t\t\tattachment_date int(10) unsigned NOT NULL default 0,\n\t\t\tattachment_size int(10) unsigned NOT NULL default 0,\n\t\t\tis_temp char(1) NOT NULL default 'y',\n\t\t\tPRIMARY KEY `attachment_id` (`attachment_id`)\n\t\t)";
     $Q[] = "CREATE TABLE exp_message_copies (\n\t\t\tcopy_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tmessage_id int(10) unsigned NOT NULL default 0,\n\t\t\tsender_id int(10) unsigned NOT NULL default 0,\n\t\t\trecipient_id int(10) unsigned NOT NULL default 0,\n\t\t\tmessage_received char(1) NOT NULL default 'n',\n\t\t\tmessage_read char(1) NOT NULL default 'n',\n\t\t\tmessage_time_read int(10) unsigned NOT NULL default 0,\n\t\t\tattachment_downloaded char(1) NOT NULL default 'n',\n\t\t\tmessage_folder int(10) unsigned NOT NULL default 1,\n\t\t\tmessage_authcode varchar(10) NOT NULL default '',\n\t\t\tmessage_deleted char(1) NOT NULL default 'n',\n\t\t\tmessage_status varchar(10) NOT NULL default '',\n\t\t\tPRIMARY KEY `copy_id` (`copy_id`),\n\t\t\tKEY `message_id` (`message_id`),\n\t\t\tKEY `recipient_id` (`recipient_id`),\n\t\t\tKEY `sender_id` (`sender_id`)\n\t\t)";
     $Q[] = "CREATE TABLE exp_message_data (\n\t\t\tmessage_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tsender_id int(10) unsigned NOT NULL default 0,\n\t\t\tmessage_date int(10) unsigned NOT NULL default 0,\n\t\t\tmessage_subject varchar(255) NOT NULL default '',\n\t\t\tmessage_body text NOT NULL,\n\t\t\tmessage_tracking char(1) NOT NULL default 'y',\n\t\t\tmessage_attachments char(1) NOT NULL default 'n',\n\t\t\tmessage_recipients varchar(200) NOT NULL default '',\n\t\t\tmessage_cc varchar(200) NOT NULL default '',\n\t\t\tmessage_hide_cc char(1) NOT NULL default 'n',\n\t\t\tmessage_sent_copy char(1) NOT NULL default 'n',\n\t\t\ttotal_recipients int(5) unsigned NOT NULL default 0,\n\t\t\tmessage_status varchar(25) NOT NULL default '',\n\t\t\tPRIMARY KEY `message_id` (`message_id`),\n\t\t\tKEY `sender_id` (`sender_id`)\n\t\t)";
     $Q[] = "CREATE TABLE exp_message_folders (\n\t\t\tmember_id int(10) unsigned NOT NULL default 0,\n\t\t\tfolder1_name varchar(50) NOT NULL default 'InBox',\n\t\t\tfolder2_name varchar(50) NOT NULL default 'Sent',\n\t\t\tfolder3_name varchar(50) NOT NULL default '',\n\t\t\tfolder4_name varchar(50) NOT NULL default '',\n\t\t\tfolder5_name varchar(50) NOT NULL default '',\n\t\t\tfolder6_name varchar(50) NOT NULL default '',\n\t\t\tfolder7_name varchar(50) NOT NULL default '',\n\t\t\tfolder8_name varchar(50) NOT NULL default '',\n\t\t\tfolder9_name varchar(50) NOT NULL default '',\n\t\t\tfolder10_name varchar(50) NOT NULL default '',\n\t\t\tPRIMARY KEY `member_id` (`member_id`)\n\t\t)";
     $Q[] = "CREATE TABLE exp_message_listed (\n\t\t\tlisted_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tmember_id int(10) unsigned NOT NULL default 0,\n\t\t\tlisted_member int(10) unsigned NOT NULL default 0,\n\t\t\tlisted_description varchar(100) NOT NULL default '',\n\t\t\tlisted_type varchar(10) NOT NULL default 'blocked',\n\t\t\tPRIMARY KEY `listed_id` (`listed_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_extensions` (\n\t\t\t`extension_id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t`class` varchar(50) NOT NULL default '',\n\t\t\t`method` varchar(50) NOT NULL default '',\n\t\t\t`hook` varchar(50) NOT NULL default '',\n\t\t\t`settings` text NOT NULL,\n\t\t\t`priority` int(2) NOT NULL default '10',\n\t\t\t`version` varchar(10) NOT NULL default '',\n\t\t\t`enabled` char(1) NOT NULL default 'y',\n\t\t\tPRIMARY KEY `extension_id` (`extension_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_member_search`(\n\t\t\t`search_id` varchar(32) NOT NULL,\n\t\t\t`site_id` INT(4) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\t`search_date` int(10) unsigned NOT NULL,\n\t\t\t`keywords` varchar(200) NOT NULL,\n\t\t\t`fields` varchar(200) NOT NULL,\n\t\t\t`member_id` int(10) unsigned NOT NULL,\n\t\t\t`ip_address` varchar(45) default '0' NOT NULL,\n\t\t\t`total_results` int(8) unsigned NOT NULL,\n\t\t\t`query` text NOT NULL,\n\t\t\tPRIMARY KEY `search_id` (`search_id`),\n\t\t\tKEY `member_id` (`member_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_member_bulletin_board` (\n\t\t\t`bulletin_id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t`sender_id` int(10) unsigned NOT NULL,\n\t\t\t`bulletin_group` int(8) unsigned NOT NULL,\n\t\t\t`bulletin_date` int(10) unsigned NOT NULL,\n\t\t\t`hash` varchar(10) NOT NULL DEFAULT '',\n\t\t\t`bulletin_expires` int(10) unsigned NOT NULL DEFAULT 0,\n\t\t\t`bulletin_message` text NOT NULL,\n\t\t\tPRIMARY KEY `bulletin_id` (`bulletin_id`),\n\t\t\tKEY `sender_id` (`sender_id`),\n\t\t\tKEY `hash` (`hash`)\n\t\t)";
     // Entity type table
     $Q[] = "CREATE TABLE `exp_content_types` (\n\t\t\t`content_type_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`name` varchar(50) NOT NULL DEFAULT '',\n\t\t\tPRIMARY KEY (`content_type_id`),\n\t\t\tKEY `name` (`name`)\n\t\t)";
     // Fieldtype table
     $Q[] = "CREATE TABLE exp_fieldtypes (\n\t\t\tfieldtype_id int(4) unsigned NOT NULL auto_increment,\n\t\t\tname varchar(50) NOT NULL,\n\t\t\tversion varchar(12) NOT NULL,\n\t\t\tsettings text NULL,\n\t\t\thas_global_settings char(1) default 'n',\n\t\t\tPRIMARY KEY `fieldtype_id` (`fieldtype_id`)\n\t\t)";
     // Files table
     $Q[] = "CREATE TABLE `exp_files` (\n\t\t\t`file_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`site_id` int(4) unsigned DEFAULT '1',\n\t\t\t`title` varchar(255) DEFAULT NULL,\n\t\t\t`upload_location_id` int(4) unsigned DEFAULT '0',\n\t\t\t`mime_type` varchar(255) DEFAULT NULL,\n\t\t\t`file_name` varchar(255) DEFAULT NULL,\n\t\t\t`file_size` int(10) DEFAULT '0',\n\t\t\t`description` text,\n\t\t\t`credit` varchar(255) DEFAULT NULL,\n\t\t\t`location` varchar(255) DEFAULT NULL,\n\t\t\t`uploaded_by_member_id` int(10) unsigned DEFAULT '0',\n\t\t\t`upload_date` int(10) DEFAULT NULL,\n\t\t\t`modified_by_member_id` int(10) unsigned DEFAULT '0',\n\t\t\t`modified_date` int(10) DEFAULT NULL,\n\t\t\t`file_hw_original` varchar(20) NOT NULL DEFAULT '',\n\t\t\tPRIMARY KEY (`file_id`),\n\t\t\tKEY `upload_location_id` (`upload_location_id`),\n\t\t\tKEY `site_id` (`site_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_file_categories` (\n\t\t\t`file_id` int(10) unsigned DEFAULT NULL,\n\t\t\t`cat_id` int(10) unsigned DEFAULT NULL,\n\t\t\t`sort` int(10) unsigned DEFAULT '0',\n\t\t\t`is_cover` char(1) DEFAULT 'n',\n\t\t\tKEY `file_id` (`file_id`),\n\t\t\tKEY `cat_id` (`cat_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_file_dimensions` (\n\t\t\t`id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`site_id` int(4) unsigned NOT NULL DEFAULT '1',\n\t\t\t`upload_location_id` int(4) unsigned DEFAULT NULL,\n\t\t\t\t`title` varchar(255) DEFAULT '',\n\t\t\t`short_name` varchar(255) DEFAULT '',\n\t\t\t`resize_type` varchar(50) DEFAULT '',\n\t\t\t`width` int(10) DEFAULT '0',\n\t\t\t`height` int(10) DEFAULT '0',\n\t\t\t`watermark_id` int(4) unsigned DEFAULT NULL,\n\t\t\tPRIMARY KEY (`id`),\n\t\t\tKEY `upload_location_id` (`upload_location_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_file_watermarks` (\n\t\t\t`wm_id` int(4) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`wm_name` varchar(80) DEFAULT NULL,\n\t\t\t`wm_type` varchar(10) DEFAULT 'text',\n\t\t\t`wm_image_path` varchar(100) DEFAULT NULL,\n\t\t\t`wm_test_image_path` varchar(100) DEFAULT NULL,\n\t\t\t`wm_use_font` char(1) DEFAULT 'y',\n\t\t\t`wm_font` varchar(30) DEFAULT NULL,\n\t\t\t`wm_font_size` int(3) unsigned DEFAULT NULL,\n\t\t\t`wm_text` varchar(100) DEFAULT NULL,\n\t\t\t`wm_vrt_alignment` varchar(10) DEFAULT 'top',\n\t\t\t`wm_hor_alignment` varchar(10) DEFAULT 'left',\n\t\t\t`wm_padding` int(3) unsigned DEFAULT NULL,\n\t\t\t`wm_opacity` int(3) unsigned DEFAULT NULL,\n\t\t\t`wm_hor_offset` int(4) unsigned DEFAULT NULL,\n\t\t\t`wm_vrt_offset` int(4) unsigned DEFAULT NULL,\n\t\t\t`wm_x_transp` int(4) DEFAULT NULL,\n\t\t\t`wm_y_transp` int(4) DEFAULT NULL,\n\t\t\t`wm_font_color` varchar(7) DEFAULT NULL,\n\t\t\t`wm_use_drop_shadow` char(1) DEFAULT 'y',\n\t\t\t`wm_shadow_distance` int(3) unsigned DEFAULT NULL,\n\t\t\t`wm_shadow_color` varchar(7) DEFAULT NULL,\n\t\t\tPRIMARY KEY (`wm_id`)\n\t\t)";
     // Developer log table
     $Q[] = "CREATE TABLE `exp_developer_log` (\n\t\t\t`log_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`timestamp` int(10) unsigned NOT NULL,\n\t\t\t`viewed` char(1) NOT NULL DEFAULT 'n',\n\t\t\t`description` text NULL,\n\t\t\t`function` varchar(100) NULL,\n\t\t\t`line` int(10) unsigned NULL,\n\t\t\t`file` varchar(255) NULL,\n\t\t\t`deprecated_since` varchar(10) NULL,\n\t\t\t`use_instead` varchar(100) NULL,\n\t\t\t`template_id` int(10) unsigned NOT NULL default 0,\n\t\t\t`template_name` varchar(100) NULL,\n\t\t\t`template_group` varchar(100) NULL,\n\t\t\t`addon_module` varchar(100) NULL,\n\t\t\t`addon_method` varchar(100) NULL,\n\t\t\t`snippets` text NULL,\n\t\t\t`hash` char(32) NOT NULL,\n\t\t\tPRIMARY KEY (`log_id`)\n\t\t)";
     // Remember me table
     $Q[] = "CREATE TABLE `exp_remember_me` (\n\t\t\t`remember_me_id` varchar(40) NOT NULL DEFAULT '0',\n\t\t\t`member_id` int(10) DEFAULT '0',\n\t\t\t`ip_address` varchar(45) DEFAULT '0',\n\t\t\t`user_agent` varchar(120) DEFAULT '',\n\t\t\t`admin_sess` tinyint(1) DEFAULT '0',\n\t\t\t`site_id` int(4) DEFAULT '1',\n\t\t\t`expiration` int(10) DEFAULT '0',\n\t\t\t`last_refresh` int(10) DEFAULT '0',\n\t\t\tPRIMARY KEY (`remember_me_id`),\n\t\t\tKEY `member_id` (`member_id`)\n\t\t)";
     $Q[] = "CREATE TABLE `exp_grid_columns` (\n\t\t\t`col_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`field_id` int(10) unsigned DEFAULT NULL,\n\t\t\t`content_type` varchar(50) DEFAULT NULL,\n\t\t\t`col_order` int(3) unsigned DEFAULT NULL,\n\t\t\t`col_type` varchar(50) DEFAULT NULL,\n\t\t\t`col_label` varchar(50) DEFAULT NULL,\n\t\t\t`col_name` varchar(32) DEFAULT NULL,\n\t\t\t`col_instructions` text,\n\t\t\t`col_required` char(1) DEFAULT NULL,\n\t\t\t`col_search` char(1) DEFAULT NULL,\n\t\t\t`col_width` int(3) unsigned DEFAULT NULL,\n\t\t\t`col_settings` text,\n\t\t\tPRIMARY KEY (`col_id`),\n\t\t\tKEY `field_id` (`field_id`)\n\t\t)";
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     //  Specialty Templates
     //  - The methods are by default in email_data.php but can be overloaded if there is a
     //	speciality_templates.php file in the chosen Site Theme folder
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, edit_date, data_title, template_data) VALUES ('offline_template', 'system', " . time() . ", '', '" . addslashes(offline_template()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, edit_date, data_title, template_data) VALUES ('message_template', 'system', " . time() . ", '', '" . addslashes(message_template()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('admin_notify_reg', 'email', 'members', " . time() . ", '" . addslashes(trim(admin_notify_reg_title())) . "', '" . addslashes(admin_notify_reg()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('admin_notify_entry', 'email', 'content', " . time() . ", '" . addslashes(trim(admin_notify_entry_title())) . "', '" . addslashes(admin_notify_entry()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('admin_notify_comment', 'email', 'comments', " . time() . ", '" . addslashes(trim(admin_notify_comment_title())) . "', '" . addslashes(admin_notify_comment()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('mbr_activation_instructions', 'email', 'members', " . time() . ", '" . addslashes(trim(mbr_activation_instructions_title())) . "', '" . addslashes(mbr_activation_instructions()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('forgot_password_instructions', 'email', 'members', " . time() . ", '" . addslashes(trim(forgot_password_instructions_title())) . "', '" . addslashes(forgot_password_instructions()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('validated_member_notify', 'email', 'members', " . time() . ", '" . addslashes(trim(validated_member_notify_title())) . "', '" . addslashes(validated_member_notify()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('decline_member_validation', 'email', 'members', " . time() . ", '" . addslashes(trim(decline_member_validation_title())) . "', '" . addslashes(decline_member_validation()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('comment_notification', 'email', 'comments', " . time() . ", '" . addslashes(trim(comment_notification_title())) . "', '" . addslashes(comment_notification()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('comments_opened_notification', 'email', 'comments', " . time() . ", '" . addslashes(trim(comments_opened_notification_title())) . "', '" . addslashes(comments_opened_notification()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('private_message_notification', 'email', 'private_messages', " . time() . ", '" . addslashes(trim(private_message_notification_title())) . "', '" . addslashes(private_message_notification()) . "')";
     $Q[] = "INSERT INTO exp_specialty_templates(template_name, template_type, template_subtype, edit_date, data_title, template_data) VALUES ('pm_inbox_full', 'email', 'private_messages', " . time() . ", '" . addslashes(trim(pm_inbox_full_title())) . "', '" . addslashes(pm_inbox_full()) . "')";
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     //  Default Site Data - CANNOT BE CHANGED
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     // Register the default admin
     //		$quick_link = 'My Site|'.$this->userdata['site_url'].$this->userdata['site_index'].'|1';
     $quick_link = '';
     $Q[] = "INSERT INTO exp_members (group_id, username, password, salt, unique_id, email, screen_name, join_date, ip_address, timezone, quick_links, language)\n\t\t\tVALUES (\n\t\t\t\t'1',\n\t\t\t\t'" . ee()->db->escape_str($this->userdata['username']) . "',\n\t\t\t\t'" . $this->userdata['password'] . "',\n\t\t\t\t'" . ee()->db->escape_str($this->userdata['salt']) . "',\n\t\t\t\t'" . $this->userdata['unique_id'] . "',\n\t\t\t\t'" . ee()->db->escape_str($this->userdata['email_address']) . "',\n\t\t\t\t'" . ee()->db->escape_str($this->userdata['screen_name']) . "',\n\t\t\t\t'" . $this->now . "',\n\t\t\t\t'" . ee()->input->ip_address() . "',\n\t\t\t\t'" . $this->userdata['default_site_timezone'] . "',\n\t\t\t\t'{$quick_link}',\n\t\t\t\t'" . ee()->db->escape_str($this->userdata['deft_lang']) . "')";
     $Q[] = "INSERT INTO exp_member_homepage (member_id, recent_entries_order, recent_comments_order, site_statistics_order, notepad_order, pmachine_news_feed)\n\t\t\tVALUES ('1', '1', '2', '1', '2', 'l')";
     $Q[] = "INSERT INTO exp_member_data (member_id) VALUES ('1')";
     // Default system stats
     $Q[] = "INSERT INTO exp_stats (total_members, total_entries, last_entry_date, recent_member, recent_member_id, last_cache_clear)\n\t\t\tVALUES ('1', '0', '" . $this->now . "', '" . ee()->db->escape_str($this->userdata['screen_name']) . "', '1', '" . $this->now . "')";
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     //  Customizable Site Data, Woot!
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     // Default Site
     $site = array('site_id' => 1, 'site_label' => $this->userdata['site_label'], 'site_name' => $this->userdata['site_name'], 'site_system_preferences' => '', 'site_member_preferences' => '', 'site_template_preferences' => '', 'site_channel_preferences' => '', 'site_bootstrap_checksums' => '', 'site_pages' => '');
     $Q[] = ee()->db->insert_string('sites', $site);
     // Member Groups
     $member_groups = array(array('group_title' => 'Super Admin', 'group_id' => 1, 'can_view_offline_system' => 'y', 'can_access_cp' => 'y', 'can_access_footer_report_bug' => 'y', 'can_access_footer_new_ticket' => 'y', 'can_access_footer_user_guide' => 'y', 'can_upload_new_files' => 'y', 'can_edit_files' => 'y', 'can_delete_files' => 'y', 'can_upload_new_toolsets' => 'y', 'can_edit_toolsets' => 'y', 'can_delete_toolsets' => 'y', 'can_create_upload_directories' => 'y', 'can_edit_upload_directories' => 'y', 'can_delete_upload_directories' => 'y', 'can_access_files' => 'y', 'can_access_design' => 'y', 'can_access_addons' => 'y', 'can_access_members' => 'y', 'can_access_sys_prefs' => 'y', 'can_access_comm' => 'y', 'can_access_utilities' => 'y', 'can_access_data' => 'y', 'can_access_logs' => 'y', 'can_admin_channels' => 'y', 'can_create_channels' => 'y', 'can_edit_channels' => 'y', 'can_delete_channels' => 'y', 'can_create_channel_fields' => 'y', 'can_edit_channel_fields' => 'y', 'can_delete_channel_fields' => 'y', 'can_create_statuses' => 'y', 'can_delete_statuses' => 'y', 'can_edit_statuses' => 'y', 'can_create_categories' => 'y', 'can_create_member_groups' => 'y', 'can_delete_member_groups' => 'y', 'can_edit_member_groups' => 'y', 'can_admin_design' => 'y', 'can_create_members' => 'y', 'can_edit_members' => 'y', 'can_delete_members' => 'y', 'can_admin_mbr_groups' => 'y', 'can_admin_mbr_templates' => 'y', 'can_ban_users' => 'y', 'can_admin_addons' => 'y', 'can_create_new_templates' => 'y', 'can_edit_templates' => 'y', 'can_delete_templates' => 'y', 'can_create_template_groups' => 'y', 'can_edit_template_groups' => 'y', 'can_delete_template_groups' => 'y', 'can_create_template_partials' => 'y', 'can_edit_template_partials' => 'y', 'can_delete_template_partials' => 'y', 'can_create_template_variables' => 'y', 'can_delete_template_variables' => 'y', 'can_edit_template_variables' => 'y', 'can_edit_categories' => 'y', 'can_delete_categories' => 'y', 'can_view_other_entries' => 'y', 'can_edit_other_entries' => 'y', 'can_assign_post_authors' => 'y', 'can_delete_self_entries' => 'y', 'can_delete_all_entries' => 'y', 'can_view_other_comments' => 'y', 'can_edit_own_comments' => 'y', 'can_delete_own_comments' => 'y', 'can_edit_all_comments' => 'y', 'can_delete_all_comments' => 'y', 'can_moderate_comments' => 'y', 'can_send_cached_email' => 'y', 'can_email_member_groups' => 'y', 'can_email_from_profile' => 'y', 'can_view_profiles' => 'y', 'can_edit_html_buttons' => 'y', 'can_delete_self' => 'y', 'exclude_from_moderation' => 'y', 'can_send_private_messages' => 'y', 'can_attach_in_private_messages' => 'y', 'can_send_bulletins' => 'y', 'include_in_authorlist' => 'y', 'search_flood_control' => '0'), array('group_title' => 'Banned', 'group_id' => 2, 'can_access_cp' => 'n', 'can_view_online_system' => 'n', 'can_search' => 'n', 'can_post_comments' => 'n', 'include_in_memberlist' => 'n', 'search_flood_control' => '60'), array('group_title' => 'Guests', 'group_id' => 3, 'can_access_cp' => 'n', 'search_flood_control' => '10'), array('group_title' => 'Pending', 'group_id' => 4, 'can_access_cp' => 'n', 'search_flood_control' => '10'), array('group_title' => 'Members', 'group_id' => 5, 'can_access_cp' => 'n', 'can_email_from_profile' => 'y', 'can_view_profiles' => 'y', 'can_edit_html_buttons' => 'y', 'can_delete_self' => 'y', 'can_send_private_messages' => 'y', 'can_attach_in_private_messages' => 'y', 'search_flood_control' => '10'));
     $member_group_defaults = array('group_description' => '');
     $add_quotes = function ($value) {
         return is_string($value) ? "'{$value}'" : $value;
     };
     foreach ($member_groups as $group) {
         // Merge in defaults
         $group = array_merge($member_group_defaults, $group);
         $Q[] = "INSERT INTO exp_member_groups\n\t\t\t\t(" . implode(', ', array_keys($group)) . ")\n\t\t\t\tVALUES (" . implode(', ', array_map($add_quotes, $group)) . ")";
     }
     // default statuses - these are really always needed
     $Q[] = "INSERT INTO `exp_status_groups` (`group_id`, `site_id`, `group_name`) VALUES (1, 1, 'Default')";
     $Q[] = "INSERT INTO exp_statuses (group_id, status, status_order, highlight) VALUES ('1', 'open', '1', '009933')";
     $Q[] = "INSERT INTO exp_statuses (group_id, status, status_order, highlight) VALUES ('1', 'closed', '2', '990000')";
     include EE_APPPATH . 'config/html_buttons.php';
     $buttoncount = 1;
     foreach ($installation_defaults as $button) {
         $Q[] = "INSERT INTO exp_html_buttons (site_id, member_id, tag_name, tag_open, tag_close, accesskey, tag_order, tag_row, classname)\n\t\t\t\tvalues (1, '0', '" . $predefined_buttons[$button]['tag_name'] . "', '" . $predefined_buttons[$button]['tag_open'] . "', '" . $predefined_buttons[$button]['tag_close'] . "', '" . $predefined_buttons[$button]['accesskey'] . "', '" . $buttoncount++ . "', '1', '" . $predefined_buttons[$button]['classname'] . "')";
     }
     // Default field types
     $default_fts = array('select', 'text', 'textarea', 'date', 'file', 'grid', 'multi_select', 'checkboxes', 'radio', 'relationship', 'rte');
     foreach ($default_fts as $name) {
         $fieldtype = (require SYSPATH . '/ee/EllisLab/Addons/' . $name . '/addon.setup.php');
         $Q[] = "INSERT INTO `exp_fieldtypes`\n\t\t\t\t(`name`,`version`,`settings`,`has_global_settings`)\n\t\t\t\tVALUES ('" . $name . "','" . $fieldtype['version'] . "','YTowOnt9','n')";
     }
     // Add Grid as a content type
     $Q[] = "INSERT INTO `exp_content_types` (`name`) VALUES ('grid')";
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     //  Create DB tables and insert data
     // --------------------------------------------------------------------
     // --------------------------------------------------------------------
     foreach (ee()->db->list_tables(TRUE) as $kill) {
         ee()->db->query('DROP TABLE IF EXISTS ' . $kill);
     }
     foreach ($Q as $sql) {
         if (strncmp($sql, 'CREATE TABLE', 12) == 0) {
             $sql .= 'ENGINE=' . $this->default_engine . ' ';
             if (UTF8_ENABLED === TRUE) {
                 $sql .= 'DEFAULT CHARACTER SET ' . ee()->db->escape_str(ee()->db->char_set) . ' COLLATE ' . ee()->db->escape_str(ee()->db->dbcollat);
             }
         }
         if (ee()->db->query($sql) === FALSE) {
             foreach ($this->DB->list_tables(TRUE) as $kill) {
                 ee()->db->query('DROP TABLE IF EXISTS ' . $kill);
             }
             return FALSE;
         }
     }
     return TRUE;
 }
Exemplo n.º 2
0
	/**
	 * Installs the DB tables and data
	 *
	 * @access	public
	 * @return	bool
	 */
	function install_tables_and_data()
	{
		// Sites
		
		$Q[] = "CREATE TABLE `exp_sites` (
			  `site_id` int(5) unsigned NOT NULL auto_increment,
			  `site_label` varchar(100) NOT NULL default '',
			  `site_name` varchar(50) NOT NULL default '',
			  `site_description` text NULL,
			  `site_system_preferences` TEXT NOT NULL ,
			  `site_mailinglist_preferences` TEXT NOT NULL ,
			  `site_member_preferences` TEXT NOT NULL ,
			  `site_template_preferences` TEXT NOT NULL ,
			  `site_channel_preferences` TEXT NOT NULL ,
			  `site_bootstrap_checksums` TEXT NOT NULL ,
			  PRIMARY KEY `site_id` (`site_id`),
			  KEY `site_name` (`site_name`)
			  )";

		// Session data
		
		$Q[] = "CREATE TABLE exp_sessions (
			  session_id varchar(40) default '0' NOT NULL,
			  site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			  member_id int(10) default '0' NOT NULL,
			  admin_sess tinyint(1) default '0' NOT NULL,
			  ip_address varchar(16) default '0' NOT NULL,
			  user_agent varchar(50) NOT NULL,
			  last_activity int(10) unsigned DEFAULT '0' NOT NULL,
			  PRIMARY KEY `session_id` (`session_id`),
			  KEY `member_id` (`member_id`),
			  KEY `site_id` (`site_id`)
			)";
		
		// Throttle
		
		$Q[] = "CREATE TABLE exp_throttle (
			  throttle_id int(10) unsigned NOT NULL auto_increment, 
			  ip_address varchar(16) default '0' NOT NULL,
			  last_activity int(10) unsigned DEFAULT '0' NOT NULL,
			  hits int(10) unsigned NOT NULL,
			  locked_out char(1) NOT NULL default 'n',
			  PRIMARY KEY `throttle_id` (`throttle_id`),
			  KEY `ip_address` (`ip_address`),
			  KEY `last_activity` (`last_activity`)
			)";
			
		
		// System stats
		
		$Q[] = "CREATE TABLE exp_stats (
			  stat_id int(10) unsigned NOT NULL auto_increment,
			  site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			  total_members mediumint(7) NOT NULL default '0',
			  recent_member_id int(10) default '0' NOT NULL,
			  recent_member varchar(50) NOT NULL,
			  total_entries mediumint(8) default '0' NOT NULL,
			  total_forum_topics mediumint(8) default '0' NOT NULL,
			  total_forum_posts mediumint(8) default '0' NOT NULL,
			  total_comments mediumint(8) default '0' NOT NULL,
			  last_entry_date int(10) unsigned default '0' NOT NULL,
			  last_forum_post_date int(10) unsigned default '0' NOT NULL,
			  last_comment_date int(10) unsigned default '0' NOT NULL,
			  last_visitor_date int(10) unsigned default '0' NOT NULL, 
			  most_visitors mediumint(7) NOT NULL default '0',
			  most_visitor_date int(10) unsigned default '0' NOT NULL,
			  last_cache_clear int(10) unsigned default '0' NOT NULL,
			  PRIMARY KEY `stat_id` (`stat_id`),
			  KEY `site_id` (`site_id`)
			)";
		
		
		// Online users
		
		$Q[] = "CREATE TABLE exp_online_users (
			 online_id int(10) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 member_id int(10) default '0' NOT NULL,
			 in_forum char(1) NOT NULL default 'n',
			 name varchar(50) default '0' NOT NULL,
			 ip_address varchar(16) default '0' NOT NULL,
			 date int(10) unsigned default '0' NOT NULL,
			 anon char(1) NOT NULL,
			 PRIMARY KEY `online_id` (`online_id`),
			 KEY `date` (`date`),
			 KEY `site_id` (`site_id`)
			)";
		
		
		// Actions table
		// Actions are events that require processing. Used by modules class.
		
		$Q[] = "CREATE TABLE exp_actions (
			 action_id int(4) unsigned NOT NULL auto_increment,
			 class varchar(50) NOT NULL,
			 method varchar(50) NOT NULL,
			 PRIMARY KEY `action_id` (`action_id`)
			)";
		
		// Accessories table
		// Contains a list and permissions for all installed accessories

		$Q[] = "CREATE TABLE `exp_accessories` (
				`accessory_id` int(10) unsigned NOT NULL auto_increment,
				`class` varchar(75) NOT NULL default '',
				`member_groups` varchar(50) NOT NULL default 'all',
				`controllers` text NULL,
				`accessory_version` VARCHAR(12) NOT NULL,
				PRIMARY KEY `accessory_id` (`accessory_id`)
				)";

		// Modules table
		// Contains a list of all installed modules
		
		$Q[] = "CREATE TABLE exp_modules (
			 module_id int(4) unsigned NOT NULL auto_increment,
			 module_name varchar(50) NOT NULL,
			 module_version varchar(12) NOT NULL,
			 has_cp_backend char(1) NOT NULL default 'n',
			 has_publish_fields char(1) NOT NULL default 'n',
			 PRIMARY KEY `module_id` (`module_id`)
			)";
		
		// Security Hashes
		// Used to store hashes needed to process forms in 'secure mode'
		
		$Q[] = "CREATE TABLE exp_security_hashes (
			 hash_id int(10) unsigned NOT NULL auto_increment,
			 date int(10) unsigned NOT NULL,
			 ip_address varchar(16) default '0' NOT NULL,
			 hash varchar(40) NOT NULL,
			 PRIMARY KEY `hash_id` (`hash_id`),
			 KEY `hash` (`hash`)
			)";
		
		// CAPTCHA data
		
		$Q[] = "CREATE TABLE exp_captcha (
			 captcha_id bigint(13) unsigned NOT NULL auto_increment,
			 date int(10) unsigned NOT NULL,
			 ip_address varchar(16) default '0' NOT NULL,
			 word varchar(20) NOT NULL,
			 PRIMARY KEY `captcha_id` (`captcha_id`),
			 KEY `word` (`word`)
			)";
		
		// Password Lockout
		// If password lockout is enabled, a user only gets
		// four attempts to log-in within a specified period.
		// This table holds the a list of locked out users
		
		$Q[] = "CREATE TABLE exp_password_lockout (
			 lockout_id int(10) unsigned NOT NULL auto_increment,
			 login_date int(10) unsigned NOT NULL,
			 ip_address varchar(16) default '0' NOT NULL,
			 user_agent varchar(50) NOT NULL,
			 username varchar(50) NOT NULL,
			 PRIMARY KEY `lockout_id` (`lockout_id`),
			 KEY `login_date` (`login_date`),
			 KEY `ip_address` (`ip_address`),
			 KEY `user_agent` (`user_agent`)
			)";
		
		// Reset password
		// If a user looses their password, this table
		// holds the reset code.
		
		$Q[] = "CREATE TABLE exp_reset_password (
			  reset_id int(10) unsigned NOT NULL auto_increment,
			  member_id int(10) unsigned NOT NULL,
			  resetcode varchar(12) NOT NULL,
			  date int(10) NOT NULL,
			  PRIMARY KEY `reset_id` (`reset_id`)
			)";
		
		// Email Cache
		// We store all email messages that are sent from the CP
		
		$Q[] = "CREATE TABLE exp_email_cache (
			cache_id int(6) unsigned NOT NULL auto_increment,
			cache_date int(10) unsigned default '0' NOT NULL,
			total_sent int(6) unsigned NOT NULL,
			from_name varchar(70) NOT NULL,
			from_email varchar(70) NOT NULL,
			recipient text NOT NULL,
			cc text NOT NULL,
			bcc text NOT NULL,
			recipient_array mediumtext NOT NULL,
			subject varchar(120) NOT NULL,
			message mediumtext NOT NULL,
			`plaintext_alt` MEDIUMTEXT NOT NULL,
			mailinglist char(1) NOT NULL default 'n',
			mailtype varchar(6) NOT NULL,
			text_fmt varchar(40) NOT NULL,
			wordwrap char(1) NOT NULL default 'y',
			priority char(1) NOT NULL default '3',
			PRIMARY KEY `cache_id` (`cache_id`)
			)";
		
		// Cached Member Groups
		// We use this table to store the member group assignments
		// for each email that is sent.  Since you can send email
		// to various combinations of members, we store the member
		// group numbers in this table, which is joined to the 
		// table above when we need to re-send an email from cache.
		
		$Q[] = "CREATE TABLE exp_email_cache_mg (
			  cache_id int(6) unsigned NOT NULL,
			  group_id smallint(4) NOT NULL,
			  PRIMARY KEY `cache_id_group_id` (`cache_id`, `group_id`)
			)";
		
		// We do the same with mailing lists
		
		$Q[] = "CREATE TABLE exp_email_cache_ml (
			  cache_id int(6) unsigned NOT NULL,
			  list_id smallint(4) NOT NULL,
			  PRIMARY KEY `cache_id_list_id` (`cache_id`, `list_id`)
			)";
		
		// Email Console Cache
		// Emails sent from the member profile email console are saved here.
		
		$Q[] = "CREATE TABLE exp_email_console_cache (
			  cache_id int(6) unsigned NOT NULL auto_increment,
			  cache_date int(10) unsigned default '0' NOT NULL,
			  member_id int(10) unsigned NOT NULL,
			  member_name varchar(50) NOT NULL,
			  ip_address varchar(16) default '0' NOT NULL,
			  recipient varchar(70) NOT NULL,
			  recipient_name varchar(50) NOT NULL,
			  subject varchar(120) NOT NULL,
			  message mediumtext NOT NULL,
			  PRIMARY KEY `cache_id` (`cache_id`)
			)";
		
		// Member table
		// Contains the member info
				 
		$Q[] = "CREATE TABLE exp_members (
			  member_id int(10) unsigned NOT NULL auto_increment,
			  group_id smallint(4) NOT NULL default '0',
			  username varchar(50) NOT NULL,
			  screen_name varchar(50) NOT NULL,
			  password varchar(40) NOT NULL,
			  unique_id varchar(40) NOT NULL,
			  crypt_key varchar(40) NULL DEFAULT NULL,
			  authcode varchar(10) NULL DEFAULT NULL,
			  email varchar(72) NOT NULL,
			  url varchar(150) NULL DEFAULT NULL,
			  location varchar(50) NULL DEFAULT NULL,
			  occupation varchar(80) NULL DEFAULT NULL,
			  interests varchar(120) NULL DEFAULT NULL,
			  bday_d int(2) NULL DEFAULT NULL,
			  bday_m int(2) NULL DEFAULT NULL,
			  bday_y int(4) NULL DEFAULT NULL,
			  aol_im varchar(50) NULL DEFAULT NULL,
			  yahoo_im varchar(50) NULL DEFAULT NULL,
			  msn_im varchar(50) NULL DEFAULT NULL,
			  icq varchar(50) NULL DEFAULT NULL,
			  bio text NULL,
			  signature text NULL,
			  avatar_filename varchar(120) NULL DEFAULT NULL,
			  avatar_width int(4) unsigned NULL DEFAULT NULL,
			  avatar_height int(4) unsigned NULL DEFAULT NULL,  
			  photo_filename varchar(120) NULL DEFAULT NULL,
			  photo_width int(4) unsigned NULL DEFAULT NULL,
			  photo_height int(4) unsigned NULL DEFAULT NULL,  
			  sig_img_filename varchar(120) NULL DEFAULT NULL,
			  sig_img_width int(4) unsigned NULL DEFAULT NULL,
			  sig_img_height int(4) unsigned NULL DEFAULT NULL,
			  ignore_list text NULL,
			  private_messages int(4) unsigned DEFAULT '0' NOT NULL,
			  accept_messages char(1) NOT NULL default 'y',
			  last_view_bulletins int(10) NOT NULL default 0,
			  last_bulletin_date int(10) NOT NULL default 0,
			  ip_address varchar(16) default '0' NOT NULL,
			  join_date int(10) unsigned default '0' NOT NULL,
			  last_visit int(10) unsigned default '0' NOT NULL, 
			  last_activity int(10) unsigned default '0' NOT NULL, 
			  total_entries smallint(5) unsigned NOT NULL default '0',
			  total_comments smallint(5) unsigned NOT NULL default '0',
			  total_forum_topics mediumint(8) default '0' NOT NULL,
			  total_forum_posts mediumint(8) default '0' NOT NULL,
			  last_entry_date int(10) unsigned default '0' NOT NULL,
			  last_comment_date int(10) unsigned default '0' NOT NULL,
			  last_forum_post_date int(10) unsigned default '0' NOT NULL,
			  last_email_date int(10) unsigned default '0' NOT NULL,
			  in_authorlist char(1) NOT NULL default 'n',
			  accept_admin_email char(1) NOT NULL default 'y',
			  accept_user_email char(1) NOT NULL default 'y',
			  notify_by_default char(1) NOT NULL default 'y',
			  notify_of_pm char(1) NOT NULL default 'y',
			  display_avatars char(1) NOT NULL default 'y',
			  display_signatures char(1) NOT NULL default 'y',
			  parse_smileys char(1) NOT NULL default 'y',
			  smart_notifications char(1) NOT NULL default 'y',
			  language varchar(50) NOT NULL,
			  timezone varchar(8) NOT NULL,
			  daylight_savings char(1) default 'n' NOT NULL,
			  localization_is_site_default char(1) NOT NULL default 'n',
			  time_format char(2) default 'us' NOT NULL,
			  cp_theme varchar(32) NULL DEFAULT NULL,
			  profile_theme varchar(32) NULL DEFAULT NULL,
			  forum_theme varchar(32) NULL DEFAULT NULL,
			  tracker text NULL,
			  template_size varchar(2) NOT NULL default '20',
			  notepad text NULL,
			  notepad_size varchar(2) NOT NULL default '18',
			  quick_links text NULL,
			  quick_tabs text NULL,
			  show_sidebar char(1) NOT NULL default 'y',			
			  pmember_id int(10) NOT NULL default '0',
			  PRIMARY KEY `member_id` (`member_id`),
			  KEY `group_id` (`group_id`),
			  KEY `unique_id` (`unique_id`),
			  KEY `password` (`password`)
			)";
		
		// CP homepage layout
		// Each member can have their own control panel layout.
		// We store their preferences here.
		
		$Q[] = "CREATE TABLE exp_member_homepage (
			 member_id int(10) unsigned NOT NULL,
			 recent_entries char(1) NOT NULL default 'l',
			 recent_entries_order int(3) unsigned NOT NULL default '0',
			 recent_comments char(1) NOT NULL default 'l',
			 recent_comments_order int(3) unsigned NOT NULL default '0',
			 recent_members char(1) NOT NULL default 'n',
			 recent_members_order int(3) unsigned NOT NULL default '0',
			 site_statistics char(1) NOT NULL default 'r',
			 site_statistics_order int(3) unsigned NOT NULL default '0',
			 member_search_form char(1) NOT NULL default 'n',
			 member_search_form_order int(3) unsigned NOT NULL default '0',
			 notepad char(1) NOT NULL default 'r',
			 notepad_order int(3) unsigned NOT NULL default '0',
			 bulletin_board char(1) NOT NULL default 'r',
			 bulletin_board_order int(3) unsigned NOT NULL default '0',
			 pmachine_news_feed char(1) NOT NULL default 'n',
			 pmachine_news_feed_order int(3) unsigned NOT NULL default '0',
			 PRIMARY KEY `member_id` (`member_id`)
			)";
		
		
		// Member Groups table
		
		$Q[] = "CREATE TABLE exp_member_groups (
			  group_id smallint(4) unsigned NOT NULL,
			  site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			  group_title varchar(100) NOT NULL,
			  group_description text NOT NULL,
			  is_locked char(1) NOT NULL default 'y', 
			  can_view_offline_system char(1) NOT NULL default 'n', 
			  can_view_online_system char(1) NOT NULL default 'y', 
			  can_access_cp char(1) NOT NULL default 'y', 
			  can_access_content char(1) NOT NULL default 'n',
			  can_access_publish char(1) NOT NULL default 'n',
			  can_access_edit char(1) NOT NULL default 'n',
			  can_access_files char(1) NOT NULL default 'n',
			  can_access_design char(1) NOT NULL default 'n',
			  can_access_addons char(1) NOT NULL default 'n',
			  can_access_modules char(1) NOT NULL default 'n',
			  can_access_extensions char(1) NOT NULL default 'n',
			  can_access_accessories char(1) NOT NULL default 'n',
			  can_access_plugins char(1) NOT NULL default 'n',
			  can_access_members char(1) NOT NULL default 'n',
			  can_access_admin char(1) NOT NULL default 'n',
			  can_access_sys_prefs char(1) NOT NULL default 'n',
			  can_access_content_prefs char(1) NOT NULL default 'n',
			  can_access_tools char(1) NOT NULL default 'n',
			  can_access_comm char(1) NOT NULL default 'n',
			  can_access_utilities char(1) NOT NULL default 'n',
			  can_access_data char(1) NOT NULL default 'n',
			  can_access_logs char(1) NOT NULL default 'n',
			  can_admin_channels char(1) NOT NULL default 'n',
			  can_admin_design char(1) NOT NULL default 'n',
			  can_admin_members char(1) NOT NULL default 'n',
			  can_delete_members char(1) NOT NULL default 'n',
			  can_admin_mbr_groups char(1) NOT NULL default 'n',
			  can_admin_mbr_templates char(1) NOT NULL default 'n',
			  can_ban_users char(1) NOT NULL default 'n',
			  can_admin_modules char(1) NOT NULL default 'n',
			  can_admin_templates char(1) NOT NULL default 'n',
			  can_admin_accessories char(1) NOT NULL default 'n',
			  can_edit_categories char(1) NOT NULL default 'n',
			  can_delete_categories char(1) NOT NULL default 'n',
			  can_view_other_entries char(1) NOT NULL default 'n',
			  can_edit_other_entries char(1) NOT NULL default 'n',
			  can_assign_post_authors char(1) NOT NULL default 'n',
			  can_delete_self_entries char(1) NOT NULL default 'n',
			  can_delete_all_entries char(1) NOT NULL default 'n',
			  can_view_other_comments char(1) NOT NULL default 'n',
			  can_edit_own_comments char(1) NOT NULL default 'n',
			  can_delete_own_comments char(1) NOT NULL default 'n',
			  can_edit_all_comments char(1) NOT NULL default 'n',
			  can_delete_all_comments char(1) NOT NULL default 'n',
			  can_moderate_comments char(1) NOT NULL default 'n',
			  can_send_email char(1) NOT NULL default 'n',
			  can_send_cached_email char(1) NOT NULL default 'n',
			  can_email_member_groups char(1) NOT NULL default 'n',
			  can_email_mailinglist char(1) NOT NULL default 'n',
			  can_email_from_profile char(1) NOT NULL default 'n',
			  can_view_profiles char(1) NOT NULL default 'n',
			  can_edit_html_buttons char(1) NOT NULL DEFAULT 'n',
			  can_delete_self char(1) NOT NULL default 'n',
			  mbr_delete_notify_emails varchar(255) NULL DEFAULT NULL,
			  can_post_comments char(1) NOT NULL default 'n', 
			  exclude_from_moderation char(1) NOT NULL default 'n',
			  can_search char(1) NOT NULL default 'n',
			  search_flood_control mediumint(5) unsigned NOT NULL,
			  can_send_private_messages char(1) NOT NULL default 'n',
			  prv_msg_send_limit smallint unsigned NOT NULL default '20',
			  prv_msg_storage_limit smallint unsigned NOT NULL default '60',
			  can_attach_in_private_messages char(1) NOT NULL default 'n', 
			  can_send_bulletins char(1) NOT NULL default 'n',
			  include_in_authorlist char(1) NOT NULL default 'n',
			  include_in_memberlist char(1) NOT NULL default 'y',
			  include_in_mailinglists char(1) NOT NULL default 'y',
			  PRIMARY KEY `group_id_site_id` (`group_id`, `site_id`)
			)";		
		
		// Channel access privs
		// Member groups assignment for each channel
		
		$Q[] = "CREATE TABLE exp_channel_member_groups (
			  group_id smallint(4) unsigned NOT NULL,
			  channel_id int(6) unsigned NOT NULL,
			  PRIMARY KEY `group_id_channel_id` (`group_id`, `channel_id`)
			)";
		
		// Module access privs
		// Member Group assignment for each module
		
		$Q[] = "CREATE TABLE exp_module_member_groups (
			  group_id smallint(4) unsigned NOT NULL,
			  module_id mediumint(5) unsigned NOT NULL,
			  PRIMARY KEY `group_id_module_id` (`group_id`, `module_id`)
			)";
		
		
		// Template Group access privs
		// Member group assignment for each template group
		
		$Q[] = "CREATE TABLE exp_template_member_groups (
			  group_id smallint(4) unsigned NOT NULL,
			  template_group_id mediumint(5) unsigned NOT NULL,
			  PRIMARY KEY `group_id_template_group_id` (`group_id`, `template_group_id`)
			)";		
		
		// Member Custom Fields
		// Stores the defenition of each field
		
		$Q[] = "CREATE TABLE exp_member_fields (
			 m_field_id int(4) unsigned NOT NULL auto_increment,
			 m_field_name varchar(32) NOT NULL,
			 m_field_label varchar(50) NOT NULL,
			 m_field_description text NOT NULL, 
			 m_field_type varchar(12) NOT NULL default 'text',
			 m_field_list_items text NOT NULL,
			 m_field_ta_rows tinyint(2) default '8',
			 m_field_maxl smallint(3) NOT NULL,
			 m_field_width varchar(6) NOT NULL,
			 m_field_search char(1) NOT NULL default 'y',
			 m_field_required char(1) NOT NULL default 'n',
			 m_field_public char(1) NOT NULL default 'y',
			 m_field_reg char(1) NOT NULL default 'n',
			 m_field_cp_reg char(1) NOT NULL default 'n',
			 m_field_fmt char(5) NOT NULL default 'none',
			 m_field_order int(3) unsigned NOT NULL,
			 PRIMARY KEY `m_field_id` (`m_field_id`)
			)";
		
		// Member Data
		// Stores the actual data
		
		$Q[] = "CREATE TABLE exp_member_data (
			 member_id int(10) unsigned NOT NULL,
			 PRIMARY KEY `member_id` (`member_id`)
			)";
		
		// Channel Table

		// @confirm: I changed comment_max_chars from a NULL default to 5000 - DA

		$Q[] = "CREATE TABLE exp_channels (
			 channel_id int(6) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 channel_name varchar(40) NOT NULL,
			 channel_title varchar(100) NOT NULL,
			 channel_url varchar(100) NOT NULL,
			 channel_description varchar(225) NULL DEFAULT NULL,
			 channel_lang varchar(12) NOT NULL,
			 total_entries mediumint(8) default '0' NOT NULL,
			 total_comments mediumint(8) default '0' NOT NULL,
			 last_entry_date int(10) unsigned default '0' NOT NULL,
			 last_comment_date int(10) unsigned default '0' NOT NULL,
			 cat_group varchar(255) NULL DEFAULT NULL, 
			 status_group int(4) unsigned NULL DEFAULT NULL,
			 deft_status varchar(50) NOT NULL default 'open',
			 field_group int(4) unsigned NULL DEFAULT NULL,
			 search_excerpt int(4) unsigned NULL DEFAULT NULL,
			 deft_category varchar(60) NULL DEFAULT NULL,
			 deft_comments char(1) NOT NULL default 'y',
			 channel_require_membership char(1) NOT NULL default 'y',
			 channel_max_chars int(5) unsigned NULL DEFAULT NULL,
			 channel_html_formatting char(4) NOT NULL default 'all',
			 channel_allow_img_urls char(1) NOT NULL default 'y',
			 channel_auto_link_urls char(1) NOT NULL default 'y', 
			 channel_notify char(1) NOT NULL default 'n',
			 channel_notify_emails varchar(255) NULL DEFAULT NULL,
			 comment_url varchar(80) NULL DEFAULT NULL,
			 comment_system_enabled char(1) NOT NULL default 'y',
			 comment_require_membership char(1) NOT NULL default 'n',
			 comment_use_captcha char(1) NOT NULL default 'n',
			 comment_moderate char(1) NOT NULL default 'n',
			 comment_max_chars int(5) unsigned NULL DEFAULT '5000',
			 comment_timelock int(5) unsigned NOT NULL default '0',
			 comment_require_email char(1) NOT NULL default 'y',
			 comment_text_formatting char(5) NOT NULL default 'xhtml',
			 comment_html_formatting char(4) NOT NULL default 'safe',
			 comment_allow_img_urls char(1) NOT NULL default 'n',
			 comment_auto_link_urls char(1) NOT NULL default 'y',
			 comment_notify char(1) NOT NULL default 'n',
			 comment_notify_authors char(1) NOT NULL default 'n',
			 comment_notify_emails varchar(255) NULL DEFAULT NULL,
			 comment_expiration int(4) unsigned NOT NULL default '0',
			 search_results_url varchar(80) NULL DEFAULT NULL,
			 ping_return_url varchar(80) NULL DEFAULT NULL, 
			 show_button_cluster char(1) NOT NULL default 'y',
			 rss_url varchar(80) NULL DEFAULT NULL,
			 enable_versioning char(1) NOT NULL default 'n',
			 max_revisions smallint(4) unsigned NOT NULL default 10,
			 default_entry_title varchar(100) NULL DEFAULT NULL,
			 url_title_prefix varchar(80) NULL DEFAULT NULL,
			 live_look_template int(10) UNSIGNED NOT NULL default 0,
			 PRIMARY KEY `channel_id` (`channel_id`),
			 KEY `cat_group` (`cat_group`),
			 KEY `status_group` (`status_group`),
			 KEY `field_group` (`field_group`),
			 KEY `site_id` (`site_id`)
			)";
		
		// Channel Titles
		// We store channel titles separately from channel data
		
		$Q[] = "CREATE TABLE exp_channel_titles (
			 entry_id int(10) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 channel_id int(4) unsigned NOT NULL,
			 author_id int(10) unsigned NOT NULL default 0,
			 pentry_id int(10) NOT NULL default 0,
			 forum_topic_id int(10) unsigned NULL DEFAULT NULL,
			 ip_address varchar(16) NOT NULL,
			 title varchar(100) NOT NULL,
			 url_title varchar(75) NOT NULL,
			 status varchar(50) NOT NULL,
			 versioning_enabled char(1) NOT NULL default 'n',
			 view_count_one int(10) unsigned NOT NULL default 0,
			 view_count_two int(10) unsigned NOT NULL default 0,
			 view_count_three int(10) unsigned NOT NULL default 0,
			 view_count_four int(10) unsigned NOT NULL default 0,
			 allow_comments varchar(1) NOT NULL default 'y',
			 sticky varchar(1) NOT NULL default 'n',
			 entry_date int(10) NOT NULL,
			 dst_enabled varchar(1) NOT NULL default 'n',
			 year char(4) NOT NULL,
			 month char(2) NOT NULL,
			 day char(3) NOT NULL,
			 expiration_date int(10) NOT NULL default 0,
			 comment_expiration_date int(10) NOT NULL default 0,
			 edit_date bigint(14),
			 recent_comment_date int(10) NULL DEFAULT NULL,
			 comment_total int(4) unsigned NOT NULL default 0,
			 PRIMARY KEY `entry_id` (`entry_id`),
			 KEY `channel_id` (`channel_id`),
			 KEY `author_id` (`author_id`),
			 KEY `url_title` (`url_title`),
			 KEY `status` (`status`),
			 KEY `entry_date` (`entry_date`),
			 KEY `expiration_date` (`expiration_date`),
			 KEY `site_id` (`site_id`)
			)";

		// Channel Titles Autosave
		// Used for the autosave functionality
		$Q[] = "CREATE TABLE exp_channel_entries_autosave (
			 entry_id int(10) unsigned NOT NULL auto_increment,
			 original_entry_id int(10) unsigned NOT NULL,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 channel_id int(4) unsigned NOT NULL,
			 author_id int(10) unsigned NOT NULL default 0,
			 pentry_id int(10) NOT NULL default 0,
			 forum_topic_id int(10) unsigned NULL DEFAULT NULL,
			 ip_address varchar(16) NOT NULL,
			 title varchar(100) NOT NULL,
			 url_title varchar(75) NOT NULL,
			 status varchar(50) NOT NULL,
			 versioning_enabled char(1) NOT NULL default 'n',
			 view_count_one int(10) unsigned NOT NULL default 0,
			 view_count_two int(10) unsigned NOT NULL default 0,
			 view_count_three int(10) unsigned NOT NULL default 0,
			 view_count_four int(10) unsigned NOT NULL default 0,
			 allow_comments varchar(1) NOT NULL default 'y',
			 sticky varchar(1) NOT NULL default 'n',
			 entry_date int(10) NOT NULL,
			 dst_enabled varchar(1) NOT NULL default 'n',
			 year char(4) NOT NULL,
			 month char(2) NOT NULL,
			 day char(3) NOT NULL,
			 expiration_date int(10) NOT NULL default 0,
			 comment_expiration_date int(10) NOT NULL default 0,
			 edit_date bigint(14),
			 recent_comment_date int(10) NULL DEFAULT NULL,
			 comment_total int(4) unsigned NOT NULL default 0,
			 entry_data text NULL,
			 PRIMARY KEY `entry_id` (`entry_id`),
			 KEY `channel_id` (`channel_id`),
			 KEY `author_id` (`author_id`),
			 KEY `url_title` (`url_title`),
			 KEY `status` (`status`),
			 KEY `entry_date` (`entry_date`),
			 KEY `expiration_date` (`expiration_date`),
			 KEY `site_id` (`site_id`)
			)";
		
		$Q[] = "CREATE TABLE exp_entry_versioning (
			 version_id int(10) unsigned NOT NULL auto_increment,  
			 entry_id int(10) unsigned NOT NULL,
			 channel_id int(4) unsigned NOT NULL,
			 author_id int(10) unsigned NOT NULL,
			 version_date int(10) NOT NULL,
			 version_data mediumtext NOT NULL,
			 PRIMARY KEY `version_id` (`version_id`),
			 KEY `entry_id` (`entry_id`)
			)";		
		
		// Channel Custom Field Groups
		
		$Q[] = "CREATE TABLE exp_field_groups (
			 group_id int(4) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_name varchar(50) NOT NULL,
			 PRIMARY KEY `group_id` (`group_id`),
			 KEY `site_id` (`site_id`)
			)"; 
		
		// Channel Custom Field Definitions
		
		$Q[] = "CREATE TABLE exp_channel_fields (
			 field_id int(6) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_id int(4) unsigned NOT NULL, 
			 field_name varchar(32) NOT NULL,
			 field_label varchar(50) NOT NULL,
			 field_instructions TEXT NULL,
			 field_type varchar(50) NOT NULL default 'text',
			 field_list_items text NOT NULL,
			 field_pre_populate char(1) NOT NULL default 'n', 
			 field_pre_channel_id int(6) unsigned NULL DEFAULT NULL,
			 field_pre_field_id int(6) unsigned NULL DEFAULT NULL,
			 field_related_to varchar(12) NOT NULL default 'channel',
			 field_related_id int(6) unsigned NOT NULL default 0,
			 field_related_orderby varchar(12) NOT NULL default 'date',
			 field_related_sort varchar(4) NOT NULL default 'desc',
			 field_related_max smallint(4) NOT NULL default 0,
			 field_ta_rows tinyint(2) default '8',
			 field_maxl smallint(3) NULL DEFAULT NULL,
			 field_required char(1) NOT NULL default 'n',
			 field_text_direction CHAR(3) NOT NULL default 'ltr',
			 field_search char(1) NOT NULL default 'n',
			 field_is_hidden char(1) NOT NULL default 'n',
			 field_fmt varchar(40) NOT NULL default 'xhtml',
			 field_show_fmt char(1) NOT NULL default 'y',
			 field_order int(3) unsigned NOT NULL,
			 field_content_type varchar(20) NOT NULL default 'any',
			 field_settings text NULL,
			 PRIMARY KEY `field_id` (`field_id`),
			 KEY `group_id` (`group_id`),
			 KEY `site_id` (`site_id`)
			)";
		
		
		// Relationships table
		
		$Q[] = "CREATE TABLE exp_relationships (
			 rel_id int(6) unsigned NOT NULL auto_increment,
			 rel_parent_id int(10) NOT NULL default 0,
			 rel_child_id int(10) NOT NULL default 0,
			 rel_type varchar(12) NOT NULL,
			 rel_data mediumtext NOT NULL,
			 reverse_rel_data mediumtext NOT NULL,
			 PRIMARY KEY `rel_id` (`rel_id`),
			 KEY `rel_parent_id` (`rel_parent_id`),
			 KEY `rel_child_id` (`rel_child_id`)
			)";
		
		
		// Field formatting definitions
		$Q[] = "CREATE TABLE exp_field_formatting (
			 formatting_id int(10) unsigned NOT NULL auto_increment,
			 field_id int(10) unsigned NOT NULL,
			 field_fmt varchar(40) NOT NULL,
			 PRIMARY KEY `formatting_id` (`formatting_id`)
			)";
		
		// Channel data
		$Q[] = "CREATE TABLE exp_channel_data (
			 entry_id int(10) unsigned NOT NULL,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 channel_id int(4) unsigned NOT NULL,
			 PRIMARY KEY `entry_id` (`entry_id`),
			 KEY `channel_id` (`channel_id`),
			 KEY `site_id` (`site_id`)
			)";

		// Ping Status
		// This table saves the status of the xml-rpc ping buttons
		// that were selected when an entry was submitted.  This
		// enables us to set the buttons to the same state when editing
		
		$Q[] = "CREATE TABLE exp_entry_ping_status (
			 entry_id int(10) unsigned NOT NULL,
			 ping_id int(10) unsigned NOT NULL,
			 PRIMARY KEY `entry_id_ping_id` (`entry_id`, `ping_id`)
			)";
		
		// Status Groups
		
		$Q[] = "CREATE TABLE exp_status_groups (
			 group_id int(4) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_name varchar(50) NOT NULL,
			 PRIMARY KEY `group_id` (`group_id`),
			 KEY `site_id` (`site_id`)
			)"; 
		
		// Status data
		
		$Q[] = "CREATE TABLE exp_statuses (
			 status_id int(6) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_id int(4) unsigned NOT NULL,
			 status varchar(50) NOT NULL,
			 status_order int(3) unsigned NOT NULL,
			 highlight varchar(30) NOT NULL,
			 PRIMARY KEY `status_id` (`status_id`),
			 KEY `group_id` (`group_id`),
			 KEY `site_id` (`site_id`)
			)"; 
		
		// Status "no access" 
		// Stores groups that can not access certain statuses
		
		$Q[] = "CREATE TABLE exp_status_no_access (
			 status_id int(6) unsigned NOT NULL,
			 member_group smallint(4) unsigned NOT NULL,
			 PRIMARY KEY `status_id_member_group` (`status_id`, `member_group`)
			)";		
		
		// Category Groups
		
		$Q[] = "CREATE TABLE exp_category_groups (
			 group_id int(6) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_name varchar(50) NOT NULL,
			 sort_order char(1) NOT NULL default 'a',
			 `field_html_formatting` char(4) NOT NULL default 'all',
			 `can_edit_categories` TEXT NULL,
			 `can_delete_categories` TEXT NULL,
			 PRIMARY KEY `group_id` (`group_id`),
			 KEY `site_id` (`site_id`)
			)"; 
		
		// Category data
		
		$Q[] = "CREATE TABLE exp_categories (
			 cat_id int(10) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_id int(6) unsigned NOT NULL,
			 parent_id int(4) unsigned NOT NULL,
			 cat_name varchar(100) NOT NULL,
			 `cat_url_title` varchar(75) NOT NULL,
			 cat_description text NULL,
			 cat_image varchar(120) NULL,
			 cat_order int(4) unsigned NOT NULL,
			 PRIMARY KEY `cat_id` (`cat_id`),
			 KEY `group_id` (`group_id`),
			 KEY `cat_name` (`cat_name`),
			 KEY `site_id` (`site_id`)
			)";
		
		$Q[] = "CREATE TABLE `exp_category_fields` (
			`field_id` int(6) unsigned NOT NULL auto_increment,
			`site_id` int(4) unsigned NOT NULL default 1,
			`group_id` int(4) unsigned NOT NULL,
			`field_name` varchar(32) NOT NULL default '',
			`field_label` varchar(50) NOT NULL default '',
			`field_type` varchar(12) NOT NULL default 'text',
			`field_list_items` text NOT NULL,
			`field_maxl` smallint(3) NOT NULL default 128,
			`field_ta_rows` tinyint(2) NOT NULL default 8,
			`field_default_fmt` varchar(40) NOT NULL default 'none',
			`field_show_fmt` char(1) NOT NULL default 'y',
			`field_text_direction` CHAR(3) NOT NULL default 'ltr',
			`field_required` char(1) NOT NULL default 'n',
			`field_order` int(3) unsigned NOT NULL,
			PRIMARY KEY `field_id` (`field_id`),
			KEY `site_id` (`site_id`),
			KEY `group_id` (`group_id`)
			)";
				
		$Q[] = "CREATE TABLE `exp_category_field_data` (
			`cat_id` int(4) unsigned NOT NULL,
			`site_id` int(4) unsigned NOT NULL default 1,
			`group_id` int(4) unsigned NOT NULL,
			PRIMARY KEY `cat_id` (`cat_id`),
			KEY `site_id` (`site_id`),
			KEY `group_id` (`group_id`)				
			)";
		
		
		// Category posts
		// This table stores the channel entry ID and the category IDs
		// that are assigned to it
		
		$Q[] = "CREATE TABLE exp_category_posts (
			 entry_id int(10) unsigned NOT NULL,
			 cat_id int(10) unsigned NOT NULL,
			 PRIMARY KEY `entry_id_cat_id` (`entry_id`, `cat_id`)
			)"; 
		
		// Control panel log
		
		$Q[] = "CREATE TABLE exp_cp_log (
			  id int(10) NOT NULL auto_increment,
			  site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			  member_id int(10) unsigned NOT NULL,
			  username varchar(32) NOT NULL,
			  ip_address varchar(16) default '0' NOT NULL,
			  act_date int(10) NOT NULL,
			  action varchar(200) NOT NULL,
			  PRIMARY KEY `id` (`id`),
			  KEY `site_id` (`site_id`)
			)"; 
		
		// Control panel search
		
		$Q[] = "CREATE TABLE `exp_cp_search_index` (
				`search_id` int(10) UNSIGNED NOT NULL auto_increment, 
				`controller` varchar(20) default NULL, 
				`method` varchar(50) default NULL,
				`language` varchar(20) default NULL, 
				`access` varchar(50) default NULL, 
				`keywords` text, 
				PRIMARY KEY `search_id` (`search_id`),
				FULLTEXT(`keywords`) 
		) TYPE=MyISAM "; 
		
		// HTML buttons
		// These are the buttons that appear on the PUBLISH page.
		// Each member can have their own set of buttons
		
		$Q[] = "CREATE TABLE exp_html_buttons (
			  id int(10) unsigned NOT NULL auto_increment,
			  site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			  member_id int(10) default 0 NOT NULL,
			  tag_name varchar(32) NOT NULL,
			  tag_open varchar(120) NOT NULL,
			  tag_close varchar(120) NOT NULL,
			  accesskey varchar(32) NOT NULL,
			  tag_order int(3) unsigned NOT NULL,
			  tag_row char(1) NOT NULL default 1,
			  classname varchar(20) NULL DEFAULT NULL,
			  PRIMARY KEY `id` (`id`),
			  KEY `site_id` (`site_id`)
			)";		
		
		// Layout Publish
		// Custom layout for for the publish page.
		$Q[] = "CREATE TABLE exp_layout_publish (
			  layout_id int(10) UNSIGNED NOT NULL auto_increment,
			  site_id int(4) UNSIGNED NOT NULL default 1,
			  member_group int(4) UNSIGNED NOT NULL default 0,
			  channel_id int(4) UNSIGNED NOT NULL default 0,
			  field_layout text,
			  PRIMARY KEY  (`layout_id`),
			  KEY `site_id` (`site_id`),
			  KEY `member_group` (`member_group`),
			  KEY `channel_id` (`channel_id`)
		)";
		
		// Ping Servers
		// Each member can have their own set ping server definitions
		
		$Q[] = "CREATE TABLE exp_ping_servers (
			  id int(10) unsigned NOT NULL auto_increment,
			  site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			  member_id int(10) default 0 NOT NULL,
			  server_name varchar(32) NOT NULL,
			  server_url varchar(150) NOT NULL,
			  port varchar(4) NOT NULL default '80',
			  ping_protocol varchar(12) NOT NULL default 'xmlrpc',
			  is_default char(1) NOT NULL default 'y',
			  server_order int(3) unsigned NOT NULL,
			  PRIMARY KEY `id` (`id`),
			  KEY `site_id` (`site_id`)
			)";		
		
		// Template Groups
		
		$Q[] = "CREATE TABLE exp_template_groups (
			 group_id int(6) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_name varchar(50) NOT NULL,
			 group_order int(3) unsigned NOT NULL,
			 is_site_default char(1) NOT NULL default 'n',
			 PRIMARY KEY `group_id` (`group_id`),
			 KEY `site_id` (`site_id`)
			)";
		
		// Template data
		
		$Q[] = "CREATE TABLE exp_templates (
			 template_id int(10) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 group_id int(6) unsigned NOT NULL,
			 template_name varchar(50) NOT NULL,
			 save_template_file char(1) NOT NULL default 'n',
			 template_type varchar(16) NOT NULL default 'webpage',
			 template_data mediumtext NULL,
			 template_notes text NULL,
			 edit_date int(10) NOT NULL DEFAULT 0,
			 last_author_id int(10) UNSIGNED NOT NULL default 0,
			 cache char(1) NOT NULL default 'n',
			 refresh int(6) unsigned NOT NULL default 0,
			 no_auth_bounce varchar(50) NOT NULL default '',
			 enable_http_auth CHAR(1) NOT NULL default 'n',
			 allow_php char(1) NOT NULL default 'n',
			 php_parse_location char(1) NOT NULL default 'o',
			 hits int(10) unsigned NOT NULL default 0,
			 PRIMARY KEY `template_id` (`template_id`),
			 KEY `group_id` (`group_id`),
			 KEY `site_id` (`site_id`)
			)"; 
		
		// Template "no access"
		// Since each template can be made private to specific member groups
		// we store member IDs of people who can not access certain templates
		
		$Q[] = "CREATE TABLE exp_template_no_access (
			 template_id int(6) unsigned NOT NULL,
			 member_group smallint(4) unsigned NOT NULL,
			 PRIMARY KEY `template_id_member_group` (`template_id`, `member_group`)
			)";
		
		// Specialty Templates
		// This table contains the various specialty templates, like:
		// Admin notification of new members
		// Admin notification of comments
		// Membership activation instruction
		// Member lost password instructions
		// Validated member notification
		// Remove from mailinglist notification
		
		$Q[] = "CREATE TABLE exp_specialty_templates (
			 template_id int(6) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 enable_template char(1) NOT NULL default 'y',
			 template_name varchar(50) NOT NULL,
			 data_title varchar(80) NOT NULL,
			 template_data text NOT NULL,
			 PRIMARY KEY `template_id` (`template_id`),
			 KEY `template_name` (`template_name`),
			 KEY `site_id` (`site_id`)
			)"; 
		
		// Global variables
		// These are user-definable variables
		
		$Q[] = "CREATE TABLE exp_global_variables (
			 variable_id int(6) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 variable_name varchar(50) NOT NULL,
			 variable_data text NOT NULL,
			 PRIMARY KEY `variable_id` (`variable_id`),
			 KEY `variable_name` (`variable_name`),
			 KEY `site_id` (`site_id`)
			)";

		// Snippets
		// These are user-definable early-parsed variables
		// for holding dynamic content
		
		$Q[] = "CREATE TABLE `exp_snippets` (
				`snippet_id` int(10) unsigned NOT NULL auto_increment,
				`site_id` int(4) NOT NULL,
				`snippet_name` varchar(75) NOT NULL,
				`snippet_contents` text NULL,
				PRIMARY KEY (`snippet_id`),
				KEY `site_id` (`site_id`)
				)";
						
		// Revision tracker
		// This is our versioning table, used to store each
		// change that is made to a template.
		
		$Q[] = "CREATE TABLE exp_revision_tracker (
			 tracker_id int(10) unsigned NOT NULL auto_increment,  
			 item_id int(10) unsigned NOT NULL,
			 item_table varchar(20) NOT NULL,
			 item_field varchar(20) NOT NULL,
			 item_date int(10) NOT NULL,
			 item_author_id int(10) UNSIGNED NOT NULL,
			 item_data mediumtext NOT NULL,
			 PRIMARY KEY `tracker_id` (`tracker_id`),
			 KEY `item_id` (`item_id`)
			)";
					
		// Upload preferences
				
		$Q[] = "CREATE TABLE exp_upload_prefs (
			 id int(4) unsigned NOT NULL auto_increment,
			 site_id INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 name varchar(50) NOT NULL,
			 server_path varchar(150) NOT NULL default '',
			 url varchar(100) NOT NULL,
			 allowed_types varchar(3) NOT NULL default 'img',
			 max_size varchar(16) NULL DEFAULT NULL,
			 max_height varchar(6) NULL DEFAULT NULL,
			 max_width varchar(6) NULL DEFAULT NULL,
			 properties varchar(120) NULL DEFAULT NULL,
			 pre_format varchar(120) NULL DEFAULT NULL,
			 post_format varchar(120) NULL DEFAULT NULL,
			 file_properties varchar(120) NULL DEFAULT NULL,
			 file_pre_format varchar(120) NULL DEFAULT NULL,
			 file_post_format varchar(120) NULL DEFAULT NULL,
			 PRIMARY KEY `id` (`id`),
			 KEY `site_id` (`site_id`)
			)";
		
		// Upload "no access"
		// We store the member groups that can not access various upload destinations
		
		$Q[] = "CREATE TABLE exp_upload_no_access (
			 upload_id int(6) unsigned NOT NULL,
			 upload_loc varchar(3) NOT NULL,
			 member_group smallint(4) unsigned NOT NULL,
			 PRIMARY KEY `upload_id_member_group` (`upload_id`, `member_group`)
			)";

		// Private messaging tables

		$Q[] = "CREATE TABLE exp_message_attachments (
			  attachment_id int(10) unsigned NOT NULL auto_increment,
			  sender_id int(10) unsigned NOT NULL default 0,
			  message_id int(10) unsigned NOT NULL default 0,
			  attachment_name varchar(50) NOT NULL default '',
			  attachment_hash varchar(40) NOT NULL default '',
			  attachment_extension varchar(20) NOT NULL default '',
			  attachment_location varchar(150) NOT NULL default '',
			  attachment_date int(10) unsigned NOT NULL default 0,
			  attachment_size int(10) unsigned NOT NULL default 0,
			  is_temp char(1) NOT NULL default 'y',
			  PRIMARY KEY `attachment_id` (`attachment_id`)
			)";
		
		$Q[] = "CREATE TABLE exp_message_copies (
			  copy_id int(10) unsigned NOT NULL auto_increment,
			  message_id int(10) unsigned NOT NULL default 0,
			  sender_id int(10) unsigned NOT NULL default 0,
			  recipient_id int(10) unsigned NOT NULL default 0,
			  message_received char(1) NOT NULL default 'n',
			  message_read char(1) NOT NULL default 'n',
			  message_time_read int(10) unsigned NOT NULL default 0,
			  attachment_downloaded char(1) NOT NULL default 'n',
			  message_folder int(10) unsigned NOT NULL default 1,
			  message_authcode varchar(10) NOT NULL default '',
			  message_deleted char(1) NOT NULL default 'n',
			  message_status varchar(10) NOT NULL default '',
			  PRIMARY KEY `copy_id` (`copy_id`),
			  KEY `message_id` (`message_id`),
			  KEY `recipient_id` (`recipient_id`),
			  KEY `sender_id` (`sender_id`)
			)";
		
		$Q[] = "CREATE TABLE exp_message_data (
			  message_id int(10) unsigned NOT NULL auto_increment,
			  sender_id int(10) unsigned NOT NULL default 0,
			  message_date int(10) unsigned NOT NULL default 0,
			  message_subject varchar(255) NOT NULL default '',
			  message_body text NOT NULL,
			  message_tracking char(1) NOT NULL default 'y',
			  message_attachments char(1) NOT NULL default 'n',
			  message_recipients varchar(200) NOT NULL default '',
			  message_cc varchar(200) NOT NULL default '',
			  message_hide_cc char(1) NOT NULL default 'n',
			  message_sent_copy char(1) NOT NULL default 'n',
			  total_recipients int(5) unsigned NOT NULL default 0,
			  message_status varchar(25) NOT NULL default '',
			  PRIMARY KEY `message_id` (`message_id`),
			  KEY `sender_id` (`sender_id`)
			)";
		
		$Q[] = "CREATE TABLE exp_message_folders (
			  member_id int(10) unsigned NOT NULL default 0,
			  folder1_name varchar(50) NOT NULL default 'InBox',
			  folder2_name varchar(50) NOT NULL default 'Sent',
			  folder3_name varchar(50) NOT NULL default '',
			  folder4_name varchar(50) NOT NULL default '',
			  folder5_name varchar(50) NOT NULL default '',
			  folder6_name varchar(50) NOT NULL default '',
			  folder7_name varchar(50) NOT NULL default '',
			  folder8_name varchar(50) NOT NULL default '',
			  folder9_name varchar(50) NOT NULL default '',
			  folder10_name varchar(50) NOT NULL default '',
			  PRIMARY KEY `member_id` (`member_id`)
			)";
		
		$Q[] = "CREATE TABLE exp_message_listed (
			  listed_id int(10) unsigned NOT NULL auto_increment,
			  member_id int(10) unsigned NOT NULL default 0,
			  listed_member int(10) unsigned NOT NULL default 0,
			  listed_description varchar(100) NOT NULL default '',
			  listed_type varchar(10) NOT NULL default 'blocked',
			  PRIMARY KEY `listed_id` (`listed_id`)
			)";
		
		$Q[] = "CREATE TABLE `exp_extensions` (
				`extension_id` int(10) unsigned NOT NULL auto_increment,
				`class` varchar(50) NOT NULL default '',
				`method` varchar(50) NOT NULL default '',
				`hook` varchar(50) NOT NULL default '',
				`settings` text NOT NULL,
				`priority` int(2) NOT NULL default '10',
				`version` varchar(10) NOT NULL default '',
				`enabled` char(1) NOT NULL default 'y',
				PRIMARY KEY `extension_id` (`extension_id`)
			)";
		
		$Q[] = "CREATE TABLE `exp_member_search`  (
			 `search_id` varchar(32) NOT NULL,
			 `site_id` INT(4) UNSIGNED NOT NULL DEFAULT 1,
			 `search_date` int(10) unsigned NOT NULL,
			 `keywords` varchar(200) NOT NULL,
			 `fields` varchar(200) NOT NULL,
			 `member_id` int(10) unsigned NOT NULL,
			 `ip_address` varchar(16) NOT NULL,
			 `total_results` int(8) unsigned NOT NULL,
			 `query` text NOT NULL,
			 PRIMARY KEY `search_id` (`search_id`),
			 KEY `member_id` (`member_id`),
			 KEY `site_id` (`site_id`)
		 )";
				 
		$Q[] =	"CREATE TABLE `exp_member_bulletin_board` (
			`bulletin_id` int(10) unsigned NOT NULL auto_increment,
			`sender_id` int(10) unsigned NOT NULL,
			`bulletin_group` int(8) unsigned NOT NULL,
			`bulletin_date` int(10) unsigned NOT NULL,
			`hash` varchar(10) NOT NULL DEFAULT '',
			`bulletin_expires` int(10) unsigned NOT NULL DEFAULT 0,
			`bulletin_message` text NOT NULL,
			PRIMARY KEY `bulletin_id` (`bulletin_id`),
			KEY `sender_id` (`sender_id`),
			KEY `hash` (`hash`)
			)";
		
		// Fieldtype table
		$Q[] = "CREATE TABLE exp_fieldtypes (
				fieldtype_id int(4) unsigned NOT NULL auto_increment, 
				name varchar(50) NOT NULL, 
				version varchar(12) NOT NULL, 
				settings text NULL, 
				has_global_settings char(1) default 'n', 
        		PRIMARY KEY `fieldtype_id` (`fieldtype_id`)
		)";

		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		//  Specialty Templates
		//  - The methods are by default in email_data.php but can be overloaded if there is a 
		//	speciality_templates.php file in the chosen Site Theme folder
		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('offline_template', '', '".addslashes(offline_template())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('message_template', '', '".addslashes(message_template())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('admin_notify_reg', '".addslashes(trim(admin_notify_reg_title()))."', '".addslashes(admin_notify_reg())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('admin_notify_entry', '".addslashes(trim(admin_notify_entry_title()))."', '".addslashes(admin_notify_entry())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('admin_notify_mailinglist', '".addslashes(trim(admin_notify_mailinglist_title()))."', '".addslashes(admin_notify_mailinglist())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('admin_notify_comment', '".addslashes(trim(admin_notify_comment_title()))."', '".addslashes(admin_notify_comment())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('mbr_activation_instructions', '".addslashes(trim(mbr_activation_instructions_title()))."', '".addslashes(mbr_activation_instructions())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('forgot_password_instructions', '".addslashes(trim(forgot_password_instructions_title()))."', '".addslashes(forgot_password_instructions())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('reset_password_notification', '".addslashes(trim(reset_password_notification_title()))."', '".addslashes(reset_password_notification())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('validated_member_notify', '".addslashes(trim(validated_member_notify_title()))."', '".addslashes(validated_member_notify())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('decline_member_validation', '".addslashes(trim(decline_member_validation_title()))."', '".addslashes(decline_member_validation())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('mailinglist_activation_instructions', '".addslashes(trim(mailinglist_activation_instructions_title()))."', '".addslashes(mailinglist_activation_instructions())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('comment_notification', '".addslashes(trim(comment_notification_title()))."', '".addslashes(comment_notification())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('comments_opened_notification', '".addslashes(trim(comments_opened_notification_title()))."', '".addslashes(comments_opened_notification())."')";		
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('private_message_notification', '".addslashes(trim(private_message_notification_title()))."', '".addslashes(private_message_notification())."')";
		$Q[] = "INSERT INTO exp_specialty_templates(template_name, data_title, template_data) VALUES ('pm_inbox_full', '".addslashes(trim(pm_inbox_full_title()))."', '".addslashes(pm_inbox_full())."')";
		
		
		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		//  Default Site Data - CANNOT BE CHANGED
		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		
		// Register the default admin
		//		$quick_link = 'My Site|'.$this->userdata['site_url'].$this->userdata['site_index'].'|1';
		$quick_link = '';
		
		$Q[] = "INSERT INTO exp_members (group_id, username, password, unique_id, email, screen_name, join_date, ip_address, timezone, daylight_savings, total_entries, last_entry_date, quick_links, language) 
				VALUES ('1', '".$this->EE->db->escape_str($this->userdata['username'])."', '".$this->userdata['password']."', '".$this->userdata['unique_id']."', '".$this->EE->db->escape_str($this->userdata['email_address'])."', '".$this->EE->db->escape_str($this->userdata['screen_name'])."', '".$this->now."', '".$this->EE->input->ip_address()."', '".$this->userdata['server_timezone']."', '".$this->userdata['daylight_savings']."', '1', '".$this->now."', '$quick_link', '".$this->EE->db->escape_str($this->userdata['deft_lang'])."')";
		
		$Q[] = "INSERT INTO exp_member_homepage (member_id, recent_entries_order, recent_comments_order, site_statistics_order, notepad_order, pmachine_news_feed) 
				VALUES ('1', '1', '2', '1', '2', 'l')";
		
		$Q[] = "INSERT INTO exp_member_data (member_id) VALUES ('1')";
		
		// Default system stats
		
		$Q[] = "INSERT INTO exp_stats (total_members, total_entries, last_entry_date, recent_member, recent_member_id, last_cache_clear)
				VALUES ('1', '1', '".$this->now."', '".$this->EE->db->escape_str($this->userdata['screen_name'])."', '1', '".$this->now."')";
		
		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		//  Customizable Site Data, Woot!
		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		
		// Default Site
		$site = array(
						'site_id' 		=> 1,
						'site_label'	=> $this->userdata['site_label'],
						'site_name'		=> $this->userdata['site_name'],
						'site_system_preferences'		=> '',
						'site_mailinglist_preferences'	=> '',
						'site_member_preferences'		=> '',
						'site_template_preferences'		=> '',
						'site_channel_preferences'		=> '',
						'site_bootstrap_checksums'		=> ''
					);
						
		$Q[] = $this->EE->db->insert_string('exp_sites', $site);
				
		$Q[] = "INSERT INTO exp_member_groups VALUES ('1', 1, 'Super Admins', '', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y',  'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', '', 'y', 'y', 'y', '0', 'y', '20', '60', 'y', 'y', 'y', 'y', 'y')";
		$Q[] = "INSERT INTO exp_member_groups VALUES ('2', 1, 'Banned', '', 'y', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', '', 'n', 'n', 'n', '60', 'n', '20', '60', 'n', 'n', 'n', 'n', 'n')";
		$Q[] = "INSERT INTO exp_member_groups VALUES ('3', 1, 'Guests', '', 'y', 'n', 'y', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'y', 'n', 'n', '', 'y', 'n', 'y', '15', 'n', '20', '60', 'n', 'n', 'n', 'n', 'n')";
		$Q[] = "INSERT INTO exp_member_groups VALUES ('4', 1, 'Pending', '', 'y', 'n', 'y', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'y', 'n', 'n', '', 'y', 'n', 'y', '15', 'n', '20', '60', 'n', 'n', 'n', 'n', 'n')";
		$Q[] = "INSERT INTO exp_member_groups VALUES ('5', 1, 'Members', '', 'y', 'n', 'y', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'y', 'y', 'y', 'n', '', 'y', 'n', 'y', '10', 'y', '20', '60', 'y', 'n', 'n', 'y', 'y')";

		// default statuses - these are really always needed
		$Q[] = "INSERT INTO `exp_status_groups` (`group_id`, `site_id`, `group_name`) VALUES 
				(1, 1, 'Statuses')";
	
		$Q[] = "INSERT INTO exp_statuses (group_id, status, status_order, highlight) VALUES ('1', 'open', '1', '009933')";
		$Q[] = "INSERT INTO exp_statuses (group_id, status, status_order, highlight) VALUES ('1', 'closed', '2', '990000')";

		include(EE_APPPATH.'config/html_buttons.php');

		$buttoncount = 1;

		foreach ($installation_defaults as $button)
		{
			$Q[] = "INSERT INTO exp_html_buttons (site_id, member_id, tag_name, tag_open, tag_close, accesskey, tag_order, tag_row, classname)
											values (1, '0', '".$predefined_buttons[$button]['tag_name']."', '".$predefined_buttons[$button]['tag_open']."', '".$predefined_buttons[$button]['tag_close']."', '".$predefined_buttons[$button]['accesskey']."', '".$buttoncount++."', '1', '".$predefined_buttons[$button]['classname']."')";
		}
	
		// Default field types
		$default_fts = array('select', 'text', 'textarea', 'date', 'file', 'multi_select', 'checkboxes', 'radio', 'rel');
		
		foreach($default_fts as $name)
		{
			$Q[] = "INSERT INTO `exp_fieldtypes` (`name`,`version`,`settings`,`has_global_settings`) VALUES ('".$name."','1.0','YTowOnt9','n')";
		}

		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		//  Create DB tables and insert data
		// --------------------------------------------------------------------
		// --------------------------------------------------------------------
		
		foreach($this->EE->db->list_tables(TRUE) as $kill)
		{
			$this->EE->db->query('DROP TABLE IF EXISTS '.$kill);
		}
				
		foreach($Q as $sql)
		{    
			if (UTF8_ENABLED === TRUE && strncmp($sql, 'CREATE TABLE', 12) == 0)
			{
				$sql .= 'DEFAULT CHARACTER SET '.$this->EE->db->escape_str($this->EE->db->char_set).' COLLATE '.$this->EE->db->escape_str($this->EE->db->dbcollat);
			}
			
			if ($this->EE->db->query($sql) === FALSE)
			{
				foreach($this->DB->list_tables(TRUE) as $kill)
				{
					$this->EE->db->query('DROP TABLE IF EXISTS '.$kill);
				}
				
				return FALSE;
								
			}
		}
		
		return TRUE;
	}
Exemplo n.º 3
0
    /**
     * Update or create a site
     *
     * Inserts or updates the site settings
     *
     * @access	public
     * @return	void
     */
    function update_site()
    {
        if (!$this->cp->allowed_group('can_admin_sites')) {
            show_error(lang('unauthorized_access'));
        }
        $this->_add_edit_validation();
        if ($this->form_validation->run() == FALSE) {
            return $this->add_edit_site();
        }
        // If the $site_id variable is present we are editing
        $edit = $this->input->post('site_id') && is_numeric($_POST['site_id']) ? TRUE : FALSE;
        $do_comments = $this->db->table_exists('comments');
        $error = array();
        if ($edit == FALSE) {
            if (!file_exists(APPPATH . 'language/' . $this->config->item('deft_lang') . '/email_data.php')) {
                show_error(lang('unable_to_locate_specialty'));
            } else {
                require APPPATH . 'language/' . $this->config->item('deft_lang') . '/email_data.php';
            }
        }
        // Create/Update Site
        $data = array('site_name' => $this->input->post('site_name'), 'site_label' => $this->input->post('site_label'), 'site_description' => $this->input->post('site_description'), 'site_bootstrap_checksums' => '');
        if ($edit == FALSE) {
            // This is ugly, but the proper defaults are done by the config lib below
            $others = array('system_preferences', 'mailinglist_preferences', 'member_preferences', 'template_preferences', 'channel_preferences');
            $this->load->model('addons_model');
            if ($this->addons_model->module_installed('pages')) {
                $others[] = 'pages';
            }
            foreach ($others as $field) {
                $data['site_' . $field] = '';
            }
            $this->db->insert('sites', $data);
            $insert_id = $this->db->insert_id();
            $site_id = $insert_id;
            $success_msg = lang('site_created');
        } else {
            // Grab old data
            $old = $this->db->get_where('sites', array('site_id' => $this->input->post('site_id')));
            // Short name change, possibly need to update the template file folder
            if ($old->row('site_name') != $this->input->post('site_name')) {
                $prefs = $old->row('site_template_preferences');
                $prefs = unserialize(base64_decode($prefs));
                if ($basepath = $prefs['tmpl_file_basepath']) {
                    $basepath = preg_replace("#([^/])/*\$#", "\\1/", $basepath);
                    // trailing slash
                    if (@is_dir($basepath . $old->row('site_name'))) {
                        @rename($basepath . $old->row('site_name'), $basepath . $_POST['site_name']);
                    }
                }
            }
            $this->db->update('sites', $data, array('site_id' => $this->input->post('site_id')));
            $site_id = $_POST['site_id'];
            $success_msg = lang('site_updated');
        }
        $this->logger->log_action($success_msg . NBS . NBS . $_POST['site_label']);
        // Site Specific Stats Created
        if ($edit === FALSE) {
            $query = $this->db->get_where('stats', array('site_id' => '1'));
            foreach ($query->result_array() as $row) {
                $data = $row;
                $data['site_id'] = $site_id;
                $data['last_entry_date'] = 0;
                $data['last_cache_clear'] = 0;
                unset($data['stat_id']);
                $this->db->insert('stats', $data);
            }
        }
        // New Prefs Creation
        if ($edit === FALSE) {
            foreach (array('system', 'channel', 'template', 'mailinglist', 'member') as $type) {
                $prefs = array();
                foreach ($this->config->divination($type) as $value) {
                    $prefs[$value] = $this->config->item($value);
                    $prefs['save_tmpl_files'] = 'n';
                    $prefs['tmpl_file_basepath'] = '';
                }
                $this->config->update_site_prefs($prefs, $site_id);
            }
        }
        // Create HTML Buttons for New Site
        if ($edit == FALSE) {
            $query = $this->db->get_where('html_buttons', array('site_id' => $this->config->item('site_id'), 'member_id' => 0));
            if ($query->num_rows() > 0) {
                foreach ($query->result_array() as $row) {
                    unset($row['id']);
                    $row['site_id'] = $site_id;
                    $this->db->insert('html_buttons', $row);
                }
            }
        }
        // Create Specialty Templates for New Site
        if ($edit == FALSE) {
            $Q = array();
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'offline_template', '', '" . addslashes(offline_template()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'message_template', '', '" . addslashes(message_template()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'admin_notify_reg', '" . addslashes(trim(admin_notify_reg_title())) . "', '" . addslashes(admin_notify_reg()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'admin_notify_entry', '" . addslashes(trim(admin_notify_entry_title())) . "', '" . addslashes(admin_notify_entry()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'admin_notify_mailinglist', '" . addslashes(trim(admin_notify_mailinglist_title())) . "', '" . addslashes(admin_notify_mailinglist()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'admin_notify_comment', '" . addslashes(trim(admin_notify_comment_title())) . "', '" . addslashes(admin_notify_comment()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'mbr_activation_instructions', '" . addslashes(trim(mbr_activation_instructions_title())) . "', '" . addslashes(mbr_activation_instructions()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'forgot_password_instructions', '" . addslashes(trim(forgot_password_instructions_title())) . "', '" . addslashes(forgot_password_instructions()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'validated_member_notify', '" . addslashes(trim(validated_member_notify_title())) . "', '" . addslashes(validated_member_notify()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'decline_member_validation', '" . addslashes(trim(decline_member_validation_title())) . "', '" . addslashes(decline_member_validation()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'mailinglist_activation_instructions', '" . addslashes(trim(mailinglist_activation_instructions_title())) . "', '" . addslashes(mailinglist_activation_instructions()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'comment_notification', '" . addslashes(trim(comment_notification_title())) . "', '" . addslashes(comment_notification()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'comments_opened_notification', '" . addslashes(trim(comments_opened_notification_title())) . "', '" . addslashes(comments_opened_notification()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'private_message_notification', '" . addslashes(trim(private_message_notification_title())) . "', '" . addslashes(private_message_notification()) . "')";
            $Q[] = "insert into exp_specialty_templates(site_id, template_name, data_title, template_data) values ('" . $this->db->escape_str($site_id) . "', 'pm_inbox_full', '" . addslashes(trim(pm_inbox_full_title())) . "', '" . addslashes(pm_inbox_full()) . "')";
            foreach ($Q as $sql) {
                $this->db->query($sql);
            }
        }
        // New Member Groups
        if ($edit == FALSE) {
            $query = $this->db->get_where('member_groups', array('site_id' => $this->config->item('site_id')));
            foreach ($query->result_array() as $row) {
                $data = $row;
                $data['site_id'] = $site_id;
                $this->db->insert('member_groups', $data);
            }
        }
        // Moving of Data?
        if ($edit == FALSE) {
            $channel_ids = array();
            $moved = array();
            $entries = array();
            $upload_updates = array();
            foreach ($_POST as $key => $value) {
                // Channels Moving
                if (substr($key, 0, strlen('channel_')) == 'channel_' && $value != 'nothing' && is_numeric(substr($key, strlen('channel_')))) {
                    $old_channel_id = substr($key, strlen('channel_'));
                    if ($value == 'move') {
                        $moved[$old_channel_id] = '';
                        // Update the channels tables
                        $tables = array('channels', 'channel_titles', 'channel_data');
                        // Are we updating comments?
                        if ($do_comments == TRUE) {
                            $tables[] = 'comments';
                        }
                        foreach ($tables as $table) {
                            $this->db->update($table, array('site_id' => $site_id), array('channel_id' => $old_channel_id));
                        }
                        $channel_ids[$old_channel_id] = $old_channel_id;
                        // Stats, Groups, For Later
                    } elseif ($value == 'duplicate' or $value == 'duplicate_all') {
                        $query = $this->db->get_where('channels', array('channel_id' => $old_channel_id));
                        if ($query->num_rows() == 0) {
                            continue;
                        }
                        $row = $query->row_array();
                        // Uniqueness checks
                        foreach (array('channel_name', 'channel_title') as $check) {
                            $count = $this->db->where('site_id', $site_id)->like($check, $row[$check], 'after')->count_all_results('channels');
                            if ($count > 0) {
                                $row[$check] = $row[$check] . '-' . ($count + 1);
                            }
                        }
                        $row['site_id'] = $site_id;
                        unset($row['channel_id']);
                        $this->db->insert('channels', $row);
                        $channel_ids[$old_channel_id] = $this->db->insert_id();
                        // exp_channel_member_groups
                        $query = $this->db->select('group_id')->get_where('channel_member_groups', array('channel_id' => $old_channel_id));
                        if ($query->num_rows() > 0) {
                            foreach ($query->result_array() as $row) {
                                $this->db->insert('channel_member_groups', array('channel_id' => $channel_ids[$old_channel_id], 'group_id' => $row['group_id']));
                            }
                        }
                        /** -----------------------------------------
                        				/**  Duplicating Entries Too
                        				/**  - Duplicates, Entries, Data.
                        				/**  - We try to reassigen relationships further down during $moved processing
                        				/**  - Forum Topics and Pages are NOT duplicated
                        				/** -----------------------------------------*/
                        if ($value == 'duplicate_all') {
                            $moved[$old_channel_id] = '';
                            $query = $this->db->get_where('channel_titles', array('channel_id' => $old_channel_id));
                            $entries[$old_channel_id] = array();
                            foreach ($query->result_array() as $row) {
                                $old_entry_id = $row['entry_id'];
                                $row['site_id'] = $site_id;
                                unset($row['entry_id']);
                                $row['channel_id'] = $channel_ids[$old_channel_id];
                                $this->db->insert('channel_titles', $row);
                                $entries[$old_channel_id][$old_entry_id] = $this->db->insert_id();
                            }
                            $query = $this->db->get_where('channel_data', array('channel_id' => $old_channel_id));
                            foreach ($query->result_array() as $row) {
                                $row['site_id'] = $site_id;
                                $row['entry_id'] = $entries[$old_channel_id][$row['entry_id']];
                                $row['channel_id'] = $channel_ids[$old_channel_id];
                                $this->db->insert('channel_data', $row);
                            }
                            if ($do_comments == TRUE) {
                                $query = $this->db->get_where('comments', array('channel_id' => $old_channel_id));
                            }
                            if ($do_comments == TRUE && $query->num_rows() > 0) {
                                $comments = array();
                                unset($query->result[0]['comment_id']);
                                $fields = array_keys($query->row_array(0));
                                unset($fields['0']);
                                foreach ($query->result_array() as $row) {
                                    unset($row['comment_id']);
                                    $row['site_id'] = $site_id;
                                    $row['entry_id'] = $entries[$old_channel_id][$row['entry_id']];
                                    $row['channel_id'] = $channel_ids[$old_channel_id];
                                    $row['edit_date'] = $row['edit_date'] == '' ? 0 : $row['edit_date'];
                                    $comments[] = $row;
                                }
                                // do inserts in batches so the data movement isn't _completely_ insane...
                                for ($i = 0, $total = count($comments); $i < $total; $i = $i + 100) {
                                    $this->db->insert_batch('comments', array_slice($comments, $i, 100));
                                }
                                unset($comments);
                            }
                            if (!empty($entries[$old_channel_id])) {
                                $query = $this->db->where_in('entry_id', array_flip($entries[$old_channel_id]))->get('category_posts');
                                foreach ($query->result_array() as $row) {
                                    $row['entry_id'] = $entries[$old_channel_id][$row['entry_id']];
                                    $this->db->insert('category_posts', $row);
                                }
                            }
                        }
                    }
                }
                // Upload Directory Moving
                if (substr($key, 0, strlen('upload_')) == 'upload_' && $value != 'nothing' && is_numeric(substr($key, strlen('upload_')))) {
                    $upload_id = substr($key, strlen('upload_'));
                    if ($value == 'move') {
                        $data = array('site_id' => $site_id);
                        $this->db->where('id', $this->db->escape_str($upload_id));
                        $this->db->update('upload_prefs', $data);
                        $this->db->where('upload_location_id', $this->db->escape_str($upload_id));
                        $this->db->update('file_dimensions', $data);
                    } else {
                        $query = $this->db->get_where('upload_prefs', array('id' => $upload_id));
                        if ($query->num_rows() == 0) {
                            continue;
                        }
                        $row = $query->row_array();
                        // Uniqueness checks
                        foreach (array('name') as $check) {
                            $count = $this->db->where('site_id', $site_id)->like($check, $row[$check], 'after')->count_all_results('upload_prefs');
                            if ($count > 0) {
                                $row[$check] = $row[$check] . '-' . ($count + 1);
                            }
                        }
                        $row['site_id'] = $site_id;
                        unset($row['id']);
                        $this->db->insert('upload_prefs', $row);
                        $new_upload_id = $this->db->insert_id();
                        $upload_updates[$upload_id] = $new_upload_id;
                        $disallowed_query = $this->db->select('member_group, upload_loc')->get_where('upload_no_access', array('upload_id' => $upload_id));
                        if ($disallowed_query->num_rows() > 0) {
                            foreach ($disallowed_query->result_array() as $row) {
                                $this->db->insert('upload_no_access', array('upload_id' => $new_upload_id, 'upload_loc' => $row['upload_loc'], 'member_group' => $row['member_group']));
                            }
                        }
                        // Get image manipulations to duplicate
                        $this->db->where('upload_location_id', $this->db->escape_str($upload_id));
                        $image_manipulations = $this->db->get('file_dimensions')->result_array();
                        // Duplicate image manipulations
                        foreach ($image_manipulations as $row) {
                            unset($row['id']);
                            // Set new site ID and upload location ID
                            $row['site_id'] = $site_id;
                            $row['upload_location_id'] = $new_upload_id;
                            $this->db->insert('file_dimensions', $row);
                        }
                    }
                }
                // Global Template Variables
                if (substr($key, 0, strlen('global_variables_')) == 'global_variables_' && $value != 'nothing' && is_numeric(substr($key, strlen('global_variables_')))) {
                    $move_site_id = substr($key, strlen('global_variables_'));
                    if ($value == 'move') {
                        $this->db->update('global_variables', array('site_id' => $site_id), array('site_id' => $move_site_id));
                    } else {
                        $query = $this->db->get_where('global_variables', array('site_id' => $move_site_id));
                        if ($query->num_rows() == 0) {
                            continue;
                        }
                        $row = $query->row_array();
                        foreach ($query->result_array() as $row) {
                            // Uniqueness checks
                            foreach (array('variable_name') as $check) {
                                $count = $this->db->where('site_id', $site_id)->like($check, $row[$check], 'after')->count_all_results('global_variables');
                                if ($count > 0) {
                                    $row[$check] = $row[$check] . '-' . ($count + 1);
                                }
                            }
                            $row['site_id'] = $site_id;
                            unset($row['variable_id']);
                            $this->db->insert('global_variables', $row);
                        }
                    }
                }
                // Template Group and Template Moving
                if (substr($key, 0, strlen('template_group_')) == 'template_group_' && $value != 'nothing' && is_numeric(substr($key, strlen('template_group_')))) {
                    $group_id = substr($key, strlen('template_group_'));
                    if ($value == 'move') {
                        foreach (array('templates', 'template_groups') as $table) {
                            $this->db->update($table, array('site_id' => $site_id), array('group_id' => $group_id));
                        }
                    } else {
                        $query = $this->db->get_where('template_groups', array('group_id' => $group_id));
                        if ($query->num_rows() == 0) {
                            continue;
                        }
                        $row = $query->row_array();
                        // Uniqueness checks
                        foreach (array('group_name') as $check) {
                            $count = $this->db->where('site_id', $site_id)->like($check, $row[$check], 'after')->count_all_results('template_groups');
                            if ($count > 0) {
                                $row[$check] = $row[$check] . '-' . ($count + 1);
                            }
                        }
                        // Create New Group
                        $row['site_id'] = $site_id;
                        unset($row['group_id']);
                        $this->db->insert('template_groups', $row);
                        $new_group_id = $this->db->insert_id();
                        // Member Group Access to Template Groups
                        $query = $this->db->get_where('template_member_groups', array('template_group_id' => $query->row('group_id')));
                        if ($query->num_rows() > 0) {
                            foreach ($query->result_array() as $row) {
                                $this->db->insert('template_member_groups', array('template_group_id' => $new_group_id, 'group_id' => $row['group_id']));
                            }
                        }
                        // Create Templates for New Template Group
                        $query = $this->db->get_where('templates', array('group_id' => $group_id));
                        if ($query->num_rows() == 0) {
                            continue;
                        }
                        foreach ($query->result_array() as $row) {
                            $original_id = $row['template_id'];
                            $row['site_id'] = $site_id;
                            $row['group_id'] = $new_group_id;
                            unset($row['template_id']);
                            $this->db->insert('templates', $row);
                            $new_template_id = $this->db->insert_id();
                            // Template/Page Access
                            $access_query = $this->db->get_where('template_no_access', array('template_id' => $original_id));
                            if ($query->num_rows() > 0) {
                                foreach ($access_query->result_array() as $access_row) {
                                    $this->db->insert('exp_template_no_access', array('template_id' => $new_template_id, 'member_group' => $access_row['member_group']));
                                }
                            }
                        }
                    }
                }
            }
            // Additional Channel Moving Work - Stats/Groups
            if (count($channel_ids) > 0) {
                $status = array();
                $fields = array();
                $categories = array();
                $category_groups = array();
                $field_match = array();
                $cat_field_match = array();
                // Load DB Forge, we'll need this for some alters later on
                $this->load->dbforge();
                foreach ($channel_ids as $old_channel => $new_channel) {
                    $query = $this->db->select('cat_group, status_group, field_group')->get_where('channels', array('channel_id' => $new_channel));
                    $row = $query->row_array();
                    // Duplicate Status Group
                    $status_group = $query->row('status_group');
                    if (!empty($status_group)) {
                        if (!isset($status[$status_group])) {
                            $squery = $this->db->select('group_name')->get_where('status_groups', array('group_id' => $status_group));
                            $row = $squery->row_array();
                            // Uniqueness checks
                            foreach (array('group_name') as $check) {
                                $count = $this->db->where('site_id', $site_id)->like($check, $row[$check], 'after')->count_all_results('status_groups');
                                if ($count > 0) {
                                    $row[$check] = $row[$check] . '-' . ($count + 1);
                                }
                            }
                            $this->db->insert('status_groups', array('site_id' => $site_id, 'group_name' => $row['group_name']));
                            $status[$status_group] = $this->db->insert_id();
                            $squery = $this->db->get_where('statuses', array('group_id' => $status_group));
                            if ($squery->num_rows() > 0) {
                                foreach ($squery->result_array() as $row) {
                                    $row['site_id'] = $site_id;
                                    unset($row['status_id']);
                                    $row['group_id'] = $status[$status_group];
                                    $this->db->insert('statuses', $row);
                                }
                            }
                        }
                        // Update Channel With New Group ID
                        $this->db->update('exp_channels', array('status_group' => $status[$status_group]), array('channel_id' => $new_channel));
                    }
                    // Duplicate Field Group
                    $field_group = $query->row('field_group');
                    if (!empty($field_group)) {
                        if (!isset($fields[$field_group])) {
                            $fquery = $this->db->select('group_name')->get_where('field_groups', array('group_id' => $field_group));
                            $fq_group_name = $fquery->row('group_name');
                            // Uniqueness checks
                            foreach (array('group_name') as $check) {
                                $count = $this->db->where('site_id', $site_id)->like($check, $fquery->row($check), 'after')->count_all_results('field_groups');
                                if ($count > 0) {
                                    $fq_group_name = $fquery->row($check) . '-' . ($count + 1);
                                }
                            }
                            $this->db->insert('field_groups', array('site_id' => $site_id, 'group_name' => $fq_group_name));
                            $fields[$field_group] = $this->db->insert_id();
                            // New Fields Created for New Field Group
                            $fquery = $this->db->get_where('channel_fields', array('group_id' => $field_group));
                            if ($fquery->num_rows() > 0) {
                                foreach ($fquery->result_array() as $row) {
                                    $format_query = $this->db->select('field_fmt')->get_where('field_formatting', array('field_id' => $row['field_id']));
                                    $old_field_id = $row['field_id'];
                                    $row['site_id'] = $site_id;
                                    unset($row['field_id']);
                                    $row['group_id'] = $fields[$field_group];
                                    // Uniqueness checks
                                    foreach (array('field_name', 'field_label') as $check) {
                                        $count = $this->db->where(array('site_id' => $site_id, 'group_id' => $field_group))->like($check, $row[$check], 'after')->count_all_results('channel_fields');
                                        if ($count > 0) {
                                            $row[$check] = $row[$check] . '-' . ($count + 1);
                                        }
                                    }
                                    $this->db->insert('channel_fields', $row);
                                    $field_id = $this->db->insert_id();
                                    $field_match[$old_field_id] = $field_id;
                                    // Channel Data Field Creation, Whee!
                                    if ($row['field_type'] == 'date' or $row['field_type'] == 'relationship') {
                                        $columns = array('field_id_' . $field_id => array('type' => 'int', 'constraint' => 10, 'null' => FALSE, 'default' => 0), 'field_ft_' . $field_id => array('type' => 'tinytext', 'null' => TRUE));
                                        if ($row['field_type'] == 'date') {
                                            $columns['field_dt_' . $field_id] = array('type' => 'varchar', 'constraint' => 8);
                                        }
                                        $this->dbforge->add_column('channel_data', $columns);
                                    } elseif ($row['field_type'] == 'grid') {
                                        $this->load->library('api');
                                        $this->api->instantiate('channel_fields');
                                        $this->api_channel_fields->fetch_installed_fieldtypes();
                                        $this->load->model('grid_model');
                                        $this->load->dbforge();
                                        ee()->dbforge->add_column('channel_data', array('field_id_' . $field_id => array('type' => 'int', 'constraint' => 10), 'field_ft_' . $field_id => array('type' => 'tinytext')));
                                        $this->grid_model->create_field($field_id, 'channel');
                                        $columns = $this->grid_model->get_columns_for_field($old_field_id, 'channel');
                                        foreach ($columns as $column) {
                                            unset($column['col_id']);
                                            $column['field_id'] = $field_id;
                                            $column['col_settings'] = json_encode($column['col_settings']);
                                            $this->grid_model->save_col_settings($column);
                                        }
                                    } else {
                                        $columns = array('field_id_' . $field_id => array('type' => 'text', 'null' => TRUE), 'field_ft_' . $field_id => array('type' => 'tinytext', 'null' => TRUE));
                                        switch ($row['field_content_type']) {
                                            case 'numeric':
                                                $columns['field_id_' . $field_id]['type'] = 'float';
                                                $columns['field_id_' . $field_id]['default'] = 0;
                                                break;
                                            case 'integer':
                                                $columns['field_id_' . $field_id]['type'] = 'int';
                                                $columns['field_id_' . $field_id]['default'] = 0;
                                                break;
                                        }
                                        $this->dbforge->add_column('channel_data', $columns);
                                        // Replace NULL values
                                        if ($type == 'text') {
                                            $this->db->update('channel_data', array("field_id_{$field_id}" => ''));
                                        }
                                    }
                                    // Duplicate Each Fields Formatting Options Too
                                    if ($format_query->result_array() > 0) {
                                        foreach ($format_query->result_array() as $format_row) {
                                            $this->db->insert('field_formatting', array('field_id' => $field_id, 'field_fmt' => $format_row['field_fmt']));
                                        }
                                    }
                                }
                            }
                        }
                        // Update Channel With New Group ID
                        //  Synce up a few new fields in the channel table
                        $channel_results = $this->db->select('search_excerpt')->get_where('channels', array('channel_id' => $old_channel));
                        $channel_data['search_excerpt'] = '';
                        if ($channel_results->num_rows() > 0) {
                            $channel_row = $channel_results->row_array();
                            if (isset($field_match[$channel_row['search_excerpt']])) {
                                $channel_data['search_excerpt'] = $field_match[$channel_row['search_excerpt']];
                            }
                        }
                        $this->db->update('channels', array('field_group' => $fields[$field_group], 'search_excerpt' => (int) $channel_data['search_excerpt']), array('channel_id' => $new_channel));
                        // Moved Channel?  Need Old Field Group
                        if (isset($moved[$old_channel])) {
                            $moved[$old_channel] = $field_group;
                        }
                    }
                    // Duplicate Category Group(s)
                    $cat_group = $query->row('cat_group');
                    if (!empty($cat_group)) {
                        $new_insert_group = array();
                        foreach (explode('|', $query->row('cat_group')) as $cat_group) {
                            if (isset($category_groups[$cat_group])) {
                                $new_insert_group[] = $category_groups[$cat_group];
                                continue;
                            }
                            $gquery = $this->db->select('group_name')->get_where('category_groups', array('group_id' => $cat_group));
                            if ($gquery->num_rows() == 0) {
                                continue;
                            }
                            $gquery_row = $gquery->row();
                            // Uniqueness checks
                            foreach (array('group_name') as $check) {
                                $count = $this->db->where('site_id', $site_id)->like($check, $gquery->row($check), 'after')->count_all_results('category_groups');
                                if ($count > 0) {
                                    $gquery_row->{$check} = $gquery->row($check) . '-' . ($count + 1);
                                }
                            }
                            $gquery_row->site_id = $site_id;
                            unset($gquery_row->group_id);
                            $this->db->insert('category_groups', $gquery_row);
                            $category_groups[$cat_group] = $this->db->insert_id();
                            $new_insert_group[] = $category_groups[$cat_group];
                            // Custom Category Fields
                            $fquery = $this->db->get_where('category_fields', array('group_id' => $cat_group));
                            if ($fquery->num_rows() > 0) {
                                foreach ($fquery->result_array() as $row) {
                                    // Uniqueness checks
                                    foreach (array('field_name') as $check) {
                                        $count = $this->db->where('site_id', $site_id)->like($check, $row[$check], 'after')->count_all_results('category_fields');
                                        if ($count > 0) {
                                            $row[$check] = $row[$check] . '-' . ($count + 1);
                                        }
                                    }
                                    $old_field_id = $row['field_id'];
                                    $row['site_id'] = $site_id;
                                    unset($row['field_id']);
                                    $row['group_id'] = $category_groups[$cat_group];
                                    $this->db->insert('category_fields', $row);
                                    $field_id = $this->db->insert_id();
                                    $cat_field_match[$old_field_id] = $field_id;
                                    // Custom Catagory Field Data Creation, Whee!
                                    $columns = array('field_id_' . $field_id => array('type' => 'text', 'null' => TRUE), 'field_ft_' . $field_id => array('type' => 'varchar', 'constraint' => 40, 'null' => TRUE, 'default' => 'none'));
                                    $this->dbforge->add_column('category_field_data', $columns);
                                    $this->db->update('category_field_data', array("field_ft_{$field_id}" => $row['field_default_fmt']));
                                }
                            }
                            // New Categories Created for New Category Group
                            $cquery = $this->db->get_where('categories', array('group_id' => $cat_group));
                            if ($cquery->num_rows() > 0) {
                                foreach ($cquery->result_array() as $row) {
                                    $fields_query = $this->db->get_where('category_field_data', array('cat_id' => $row['cat_id']));
                                    // Uniqueness checks
                                    foreach (array('cat_url_title') as $check) {
                                        $count = $this->db->where('site_id', $site_id)->like($check, $row[$check], 'after')->count_all_results('categories');
                                        if ($count > 0) {
                                            $row[$check] = $row[$check] . '-' . ($count + 1);
                                        }
                                    }
                                    $old_cat_id = $row['cat_id'];
                                    $row['site_id'] = $site_id;
                                    unset($row['cat_id']);
                                    $row['group_id'] = $category_groups[$cat_group];
                                    $row['parent_id'] = ($row['parent_id'] == '0' or !isset($categories[$row['parent_id']])) ? '0' : $categories[$row['parent_id']];
                                    $this->db->insert('categories', $row);
                                    $cat_id = $this->db->insert_id();
                                    $categories[$old_cat_id] = $cat_id;
                                    // Duplicate Field Data Too
                                    if ($fields_query->num_rows() > 0) {
                                        $fields_query_row = $fields_query->row_array();
                                        $fields_query_row['site_id'] = $site_id;
                                        $fields_query_row['group_id'] = $category_groups[$cat_group];
                                        $fields_query_row['cat_id'] = $cat_id;
                                        foreach ($fquery->result_array() as $fq_row) {
                                            if ($fields_query_row["field_id_{$fq_row['field_id']}"] != '') {
                                                $fields_query_row['field_id_' . $cat_field_match[$fq_row['field_id']]] = $fields_query_row["field_id_{$fq_row['field_id']}"];
                                                $fields_query_row["field_id_{$fq_row['field_id']}"] = '';
                                            }
                                        }
                                        $this->db->insert('category_field_data', $fields_query_row);
                                    }
                                }
                            }
                        }
                        $new_insert_group = implode('|', $new_insert_group);
                    } else {
                        $new_insert_group = '';
                    }
                    // Update Channel With New Group ID
                    $this->db->update('channels', array('cat_group' => $new_insert_group), array('channel_id' => $new_channel));
                }
                /** -----------------------------------------
                				/**  Move Data Over For Moveed Channels/Entries
                				/**  - Find Old Fields from Old Site Field Group, Move Data to New Fields, Zero Old Fields
                				/**  - Reassign Categories for New Channels Based On $categories array
                				/** -----------------------------------------*/
                if (count($moved) > 0) {
                    $moved_relationships = array();
                    // Relationship Field Checking? - For 'duplicate_all' for channels, NOT enabled
                    if (count($entries) > 0) {
                        $complete_entries = array();
                        foreach ($entries as $old_channel => $its_entries) {
                            $complete_entries = array_merge($complete_entries, $its_entries);
                        }
                        $rel_check = empty($complete_entries) ? FALSE : TRUE;
                        // Find Relationships for Old Entry IDs That Have Been Moveed
                        if ($rel_check) {
                            $query = $this->db->where_in('parent_id', array_flip($complete_entries))->get('relationships');
                            if ($query->num_rows() > 0) {
                                foreach ($query->result_array() as $row) {
                                    // Only If Child Moveed As Well...
                                    if (isset($complete_entries[$row['child_id']])) {
                                        $old_rel_id = $row['relationship_id'];
                                        unset($row['relationship_id']);
                                        $row['child_id'] = $complete_entries[$row['child_id']];
                                        $row['parent_id'] = $complete_entries[$row['parent_id']];
                                        $this->db->insert('relationships', $row);
                                        $moved_relationships[$old_rel_id] = $this->db->insert_id();
                                    }
                                }
                            }
                        }
                    }
                    // Moving Field Data for Moved Entries
                    // We need to change the directory for any moved fields - if the directory was duplicated
                    // Create the string here- then replace the placeholder with the correct field id
                    if (count($upload_updates)) {
                        $file_string = 'CASE ';
                        foreach ($upload_updates as $old_dir => $new_dir) {
                            $file_string .= "WHEN field_id_a8bxdee LIKE '{filedir_" . $old_dir . "}%' THEN REPLACE(field_id_a8bxdee, '{filedir_" . $old_dir . "}', '{filedir_" . $new_dir . "}') ";
                        }
                        $file_string .= 'ELSE field_id_a8bxdee END ';
                    } else {
                        $file_string = 'field_id_a8bxdee ';
                    }
                    foreach ($moved as $channel_id => $field_group) {
                        $query = $this->db->select('field_id, field_type')->get_where('channel_fields', array('group_id' => $field_group));
                        if (isset($entries[$channel_id])) {
                            $channel_id = $channel_ids[$channel_id];
                            // Moved Entries, New Channel ID Used
                        }
                        if ($query->num_rows() > 0) {
                            $related_fields = array();
                            foreach ($query->result_array() as $row) {
                                if (!isset($field_match[$row['field_id']])) {
                                    continue;
                                }
                                if ($row['field_type'] == 'file') {
                                    $this->db->query("UPDATE exp_channel_data \r\n\t\t\t\t\t\t\t\t\t\tSET `field_id_" . $this->db->escape_str($field_match[$row['field_id']]) . "` = " . str_replace('a8bxdee', $row['field_id'], $file_string) . "WHERE channel_id = '" . $this->db->escape_str($channel_id) . "'");
                                    $this->db->set('field_id_' . $row['field_id'], NULL);
                                    $this->db->where('channel_id', $channel_id)->update('channel_data');
                                } else {
                                    // Set the new field to be the same as the old field
                                    $this->db->set("field_id_{$field_match[$row['field_id']]}", '`field_id_' . $row['field_id'] . '`', FALSE);
                                    $null_type = ($row['field_type'] == 'date' or $row['field_type'] == 'relationship' or $row['field_type'] == 'grid') ? 0 : NULL;
                                    $this->db->set('field_id_' . $row['field_id'], $null_type);
                                    $this->db->where('channel_id', $channel_id)->update('channel_data');
                                }
                                $this->db->set("field_ft_{$field_match[$row['field_id']]}", '`field_ft_' . $row['field_id'] . '`', FALSE);
                                $this->db->set('field_ft_' . $row['field_id'], NULL);
                                $this->db->where('channel_id', $channel_id)->update('channel_data');
                                if ($row['field_type'] == 'date') {
                                    // Set the new field to be the same as the old field
                                    $this->db->set("field_dt_{$field_match[$row['field_id']]}", '`field_dt_' . $row['field_id'] . '`', FALSE);
                                    $this->db->set('field_dt_' . $row['field_id'], NULL);
                                    $this->db->where('channel_id', $channel_id)->update('channel_data');
                                }
                                if ($row['field_type'] == 'relationship') {
                                    $related_fields[] = 'field_ft_' . $field_match[$row['field_id']];
                                    // We used this for moved relationships, see above
                                }
                            }
                            // Modifying Field Data for Related Entries
                            if (count($related_fields) > 0 && count($moved_relationships) > 0) {
                                $query = $this->db->query('SELECT ' . implode(',', $related_fields) . ' FROM exp_channel_data
									 WHERE (' . implode(" != 0 OR ", $related_fields) . ')');
                                if ($query->num_rows() > 0) {
                                    foreach ($query->result_array() as $row) {
                                        foreach ($row as $key => $value) {
                                            if ($value != '0' && isset($moved_relationships[$value])) {
                                                $this->db->update('channel_data', array($key => $moved_relationships[$value]), array($key => $value));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // Category Reassignment
                        $query = $this->db->select('cp.entry_id')->from('category_posts cp')->join('channel_titles wt', 'wt.entry_id = cp.entry_id')->where('wt.channel_id', $channel_id)->get();
                        if ($query->num_rows() > 0) {
                            $entry_ids = array();
                            foreach ($query->result_array() as $row) {
                                $entry_ids[] = $row['entry_id'];
                            }
                            foreach ($categories as $old_cat => $new_cat) {
                                $this->db->where_in('entry_id', $entry_ids)->update('category_posts', array('cat_id' => $new_cat), array('cat_id' => $old_cat));
                            }
                        }
                    }
                }
            }
        }
        // Check to see if there's a status group
        if ($edit === FALSE) {
            $this->load->model('status_model');
            $count = $this->status_model->get_status_groups($site_id)->row('count');
            if ($count > 0) {
                $this->status_model->insert_statuses('Statuses', $site_id);
            }
        }
        // Refresh Sites List
        $assigned_sites = array();
        if ($this->session->userdata['group_id'] == 1) {
            $result = $this->db->select('site_id, site_label')->order_by('site_label')->get('sites');
        } elseif ($this->session->userdata['assigned_sites'] != '') {
            $result = $this->db->select('site_id, site_label')->where_in('site_id', explode('|', $this->session->userdata['assigned_sites']))->order_by('site_label')->get('sites');
        }
        if (($this->session->userdata['group_id'] == 1 or $this->session->userdata['assigned_sites'] != '') && $result->num_rows() > 0) {
            foreach ($result->result_array() as $row) {
                $assigned_sites[$row['site_id']] = $row['site_label'];
            }
        }
        $this->session->userdata['assigned_sites'] = $assigned_sites;
        // Update site stats
        $original_site_id = $this->config->item('site_id');
        $this->config->set_item('site_id', $site_id);
        if ($do_comments === TRUE) {
            $this->stats->update_comment_stats();
        }
        $this->stats->update_member_stats();
        $this->stats->update_channel_stats();
        $this->config->set_item('site_id', $original_site_id);
        // View Sites List
        if ($edit === TRUE) {
            $this->functions->redirect(BASE . AMP . 'C=sites' . AMP . 'M=manage_sites&updated_id=' . $site_id);
        } else {
            $this->functions->redirect(BASE . AMP . 'C=sites' . AMP . 'M=manage_sites&created_id=' . $site_id);
        }
    }