예제 #1
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;
	}
예제 #2
0
 function do_update()
 {
     global $DB, $UD, $conf;
     $Q[] = "CREATE TABLE exp_extensions (\n\t\t\textension_id int(10) unsigned NOT NULL auto_increment,\n\t\t\tclass varchar(50) NOT NULL default '',\n\t\t\tmethod varchar(50) NOT NULL default '',\n\t\t\thook varchar(50) NOT NULL default '',\n\t\t\tsettings text NOT NULL,\n\t\t\tpriority int(2) NOT NULL default '10',\n\t\t\tversion varchar(10) NOT NULL default '',\n\t\t\tenabled char(1) NOT NULL default 'y',\n\t\t\tPRIMARY KEY  (extension_id)\n\t\t)";
     $Q[] = "CREATE TABLE exp_search_log (\n\t\t\tid int(10) NOT NULL auto_increment,\n\t\t\tmember_id int(10) unsigned NOT NULL,\n\t\t\tscreen_name varchar(50) NOT NULL,\n\t\t\tip_address varchar(16) default '0' NOT NULL,\n\t\t\tsearch_date int(10) NOT NULL,\n\t\t\tsearch_type varchar(32) NOT NULL,\n\t\t\tsearch_terms varchar(200) NOT NULL,\n\t\t\tPRIMARY KEY  (id)\n\t\t)";
     $Q[] = "CREATE TABLE exp_entry_versioning (\n\t\t version_id int(10) unsigned NOT NULL auto_increment,  \n\t\t entry_id int(10) unsigned NOT NULL,\n\t\t weblog_id int(4) unsigned NOT NULL,\n\t\t author_id int(10) unsigned NOT NULL,\n\t\t version_date int(10) NOT NULL,\n\t\t version_data mediumtext NOT NULL,\n\t\t PRIMARY KEY (version_id),\n\t\t KEY (entry_id)\n\t\t)";
     $Q[] = "CREATE TABLE exp_relationships (\n\t\t rel_id int(6) unsigned NOT NULL auto_increment,\n\t\t rel_parent_id int(10) NOT NULL default '0',\n\t\t rel_child_id int(10) NOT NULL default '0',\n\t\t rel_type varchar(12) NOT NULL,\n\t\t rel_data mediumtext NOT NULL,\n\t\t PRIMARY KEY (rel_id),\n\t\t KEY (rel_parent_id),\n\t\t KEY (rel_child_id)\n\t\t)";
     /** -------------------------------
     		/**  Is the Forum module installed?
     		/** -------------------------------*/
     $query = $DB->query("SELECT COUNT(*) AS count FROM exp_modules WHERE module_name = 'Forum'");
     if ($query->row['count'] > 0) {
         $Q[] = "ALTER TABLE exp_forum_topics ADD INDEX(last_post_author_id);";
         $query = $DB->query("SELECT forum_permissions, forum_id FROM exp_forums");
         foreach ($query->result as $row) {
             $perms = unserialize(stripslashes($row['forum_permissions']));
             $perms['can_post_reply'] = $perms['can_post_topics'];
             $DB->query("UPDATE exp_forums SET forum_permissions = '" . addslashes(serialize($perms)) . "' \n\t\t\t\t\t\t\tWHERE forum_id = '" . $DB->escape_str($row['forum_id']) . "'");
         }
     }
     /** -------------------------------
     		/**  Is the Gallery module installed?
     		/** -------------------------------*/
     $query = $DB->query("SELECT COUNT(*) AS count FROM exp_modules WHERE module_name = 'Gallery'");
     if ($query->row['count'] > 0) {
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_one char(1) NOT NULL default 'n'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_one_label varchar(80) NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_one_type char(1) NOT NULL default 'i'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_one_list text NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_one_rows tinyint(2) default '8'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_one_formatting char(10) NOT NULL default 'xhtml'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_one_auto_link char(1) NOT NULL default 'y'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_two char(1) NOT NULL default 'n'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_two_label varchar(80) NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_two_type char(1) NOT NULL default 'i'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_two_list text NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_two_rows tinyint(2) default '8'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_two_formatting char(10) NOT NULL default 'xhtml'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_two_auto_link char(1) NOT NULL default 'y'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_three char(1) NOT NULL default 'n'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_three_label varchar(80) NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_three_type char(1) NOT NULL default 'i'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_three_list text NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_three_rows tinyint(2) default '8'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_three_formatting char(10) NOT NULL default 'xhtml'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_three_auto_link char(1) NOT NULL default 'y'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_four char(1) NOT NULL default 'n'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_four_label varchar(80) NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_four_type char(1) NOT NULL default 'i'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_four_list text NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_four_rows tinyint(2) default '8'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_four_formatting char(10) NOT NULL default 'xhtml'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_four_auto_link char(1) NOT NULL default 'y'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_five char(1) NOT NULL default 'n'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_five_label varchar(80) NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_five_type char(1) NOT NULL default 'i'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_five_list text NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_five_rows tinyint(2) default '8'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_five_formatting char(10) NOT NULL default 'xhtml'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_five_auto_link char(1) NOT NULL default 'y'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_six char(1) NOT NULL default 'n'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_six_label varchar(80) NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_six_type char(1) NOT NULL default 'i'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_six_list text NOT NULL";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_six_rows tinyint(2) default '8'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_six_formatting char(10) NOT NULL default 'xhtml'";
         $Q[] = "ALTER TABLE exp_galleries ADD COLUMN gallery_cf_six_auto_link char(1) NOT NULL default 'y'";
         $Q[] = "ALTER TABLE exp_gallery_entries ADD COLUMN custom_field_one text NOT NULL";
         $Q[] = "ALTER TABLE exp_gallery_entries ADD COLUMN custom_field_two text NOT NULL";
         $Q[] = "ALTER TABLE exp_gallery_entries ADD COLUMN custom_field_three text NOT NULL";
         $Q[] = "ALTER TABLE exp_gallery_entries ADD COLUMN custom_field_four text NOT NULL";
         $Q[] = "ALTER TABLE exp_gallery_entries ADD COLUMN custom_field_five text NOT NULL";
         $Q[] = "ALTER TABLE exp_gallery_entries ADD COLUMN custom_field_six text NOT NULL";
     }
     $Q[] = "ALTER TABLE exp_weblog_titles CHANGE COLUMN edit_date edit_date varchar(19) NOT NULL";
     $Q[] = "ALTER TABLE exp_weblog_titles ADD COLUMN view_count_one int(10) unsigned NOT NULL default '0'";
     $Q[] = "ALTER TABLE exp_weblog_titles ADD COLUMN view_count_two int(10) unsigned NOT NULL default '0'";
     $Q[] = "ALTER TABLE exp_weblog_titles ADD COLUMN view_count_three int(10) unsigned NOT NULL default '0'";
     $Q[] = "ALTER TABLE exp_weblog_titles ADD COLUMN view_count_four int(10) unsigned NOT NULL default '0'";
     $Q[] = "ALTER TABLE exp_weblog_titles ADD COLUMN versioning_enabled char(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_weblog_titles ADD COLUMN dst_enabled varchar(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_search ADD COLUMN `custom_fields` TEXT NOT NULL AFTER `query`";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_pre_populate char(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_pre_blog_id int(6) unsigned NOT NULL";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_pre_field_id int(6) unsigned NOT NULL";
     $Q[] = "ALTER TABLE exp_throttle ADD COLUMN locked_out char(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_weblogs ADD COLUMN enable_versioning char(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_weblogs ADD COLUMN enable_qucksave_versioning char(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_weblogs ADD COLUMN max_revisions smallint(4) unsigned NOT NULL default 10";
     $Q[] = "ALTER TABLE exp_member_fields ADD COLUMN m_field_description text NOT NULL";
     $Q[] = "ALTER TABLE exp_member_groups ADD COLUMN can_edit_categories char(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_member_groups ADD COLUMN can_delete_categories char(1) NOT NULL default 'n'";
     $Q[] = "ALTER TABLE exp_member_groups ADD COLUMN include_in_memberlist char(1) NOT NULL default 'y'";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_related_to varchar(12) NOT NULL default 'blog'";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_related_id int(6) unsigned NOT NULL";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_related_orderby varchar(12) NOT NULL default 'date'";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_related_sort varchar(4) NOT NULL default 'desc'";
     $Q[] = "ALTER TABLE exp_weblog_fields ADD COLUMN field_related_max smallint(4) NOT NULL";
     $Q[] = "INSERT INTO exp_specialty_templates(template_id, template_name, data_title, template_data) VALUES ('', 'admin_notify_mailinglist', '" . addslashes(trim(admin_notify_mailinglist_title())) . "', '" . addslashes(admin_notify_mailinglist()) . "')";
     $Q[] = "ALTER TABLE exp_comments ADD INDEX (`weblog_id`)";
     $Q[] = "DELETE FROM exp_throttle";
     $Q[] = "DELETE FROM exp_search";
     // Run the queries
     foreach ($Q as $sql) {
         $DB->query($sql);
     }
     // Update mailing list templates
     $query = $DB->query("SELECT COUNT(*) AS count FROM exp_modules WHERE module_name = 'Mailinglist'");
     if ($query->row['count'] > 0) {
         $DB->query("ALTER TABLE exp_mailing_lists ADD COLUMN list_template text NOT NULL");
         $query = $DB->query("SELECT list_id FROM exp_mailing_lists");
         if ($query->num_rows > 0) {
             foreach ($query->result as $row) {
                 $DB->query("UPDATE exp_mailing_lists SET list_template ='" . addslashes(mailinglist_template()) . "' WHERE list_id = '" . $row['list_id'] . "'");
             }
         }
     }
     // Fetch email character set so we can add it to config file
     $charset = 'utf-8';
     if (!class_exists('EEmail')) {
         if (include './core/core.email.php') {
             $EMAIL = new EEmail(FALSE);
             $charset = $EMAIL->charset;
         }
     }
     // Update config data
     $data['allow_extensions'] = 'n';
     $data['email_charset'] = $charset;
     $data['honor_entry_dst'] = "y";
     $data['allow_member_localization'] = "y";
     $data['banish_masked_ips'] = 'y';
     $data['max_page_loads'] = "10";
     $data['time_interval'] = "8";
     $data['lockout_time'] = '30';
     $data['banishment_type'] = "message";
     $data['banishment_url'] = "";
     $data['banishment_message'] = "You have exceeded the allowed page load frequency.";
     $data['enable_search_log'] = "y";
     $data['max_logged_searches'] = "500";
     $data['webmaster_name'] = '';
     $data['censor_replacement'] = '';
     $data['mailinglist_enabled'] = 'y';
     $data['mailinglist_notify'] = 'n';
     $data['mailinglist_notify_emails'] = '';
     $data['memberlist_order_by'] = "total_posts";
     $data['memberlist_sort_order'] = "desc";
     $data['memberlist_row_limit'] = "20";
     $UD->append_config_file($data);
     unset($conf);
     include 'config' . EXT;
     // This config item is no longer needed
     unset($conf['tmpl_display_mode']);
     $UD->update_config_file(array(), $conf);
     return TRUE;
 }
예제 #3
0
파일: sites.php 프로젝트: realfluid/umbaugh
    /**
     * 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);
        }
    }