Example #1
0
function __wps__notification_trigger_schedule() {
	__wps__notification_do_jobs('cron');
}
Example #2
0
function __wps__plugin_debug() {

/* ============================================================================================================================ */

	global $wpdb, $current_user;
	wp_get_current_user();

 	$wpdb->show_errors();

  	$fail = "<span style='color:red; font-weight:bold;'>";
  	$fail2 = "</span><br /><br />";
 	
  	echo '<div class="wrap">';
        	
	  	echo '<div id="icon-themes" class="icon32"><br /></div>';
	  	echo '<h2>'.sprintf(__('%s Installation', "wp-symposium"), WPS_WL).'</h2>';
	  	
	  	// ********** Note about WP Symposium Pro
	  	$reminder = '';
		$reminder .= '<div style="margin-top:10px; margin-bottom:10px; background-color:#fcc;padding:10px;border-radius:5px;border:1px solid #9a9;">';
			$reminder .= sprintf(__('Please note, this is the WP Symposium plugin. <a href="%s">WP Symposium Pro</a> is a separate plugin - the next generation of the plugin - and <a href="%s">available here</a> on the WordPress repository.', WPS_TEXT_DOMAIN), 'http://wordpress.org/plugins/wp-symposium-pro', 'http://wordpress.org/plugins/wp-symposium-pro');
		$reminder .= '</div>';
		echo $reminder;

	  	// ********** Summary
		echo '<div style="margin-top:10px; margin-bottom:10px">';
			echo sprintf(__("Visit this page to complete installation; after you add a %s shortcode to a page; change pages with %s shortcodes; if you change WordPress Permalinks; or if you experience problems.", WPS_TEXT_DOMAIN), WPS_WL, WPS_WL);
		echo '</div>';

		// Check for activated/deactivated sub-plugins	 
		if (isset($_POST['__wps__installation_update']) && $_POST['__wps__installation_update'] == 'Y') {
			// Network activations
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__events_main_network_activated', isset($_POST['__wps__events_main_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__forum_network_activated', isset($_POST['__wps__forum_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__profile_network_activated', isset($_POST['__wps__profile_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__mail_network_activated', isset($_POST['__wps__mail_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__members_network_activated', isset($_POST['__wps__members_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__add_notification_bar_network_activated', isset($_POST['__wps__add_notification_bar_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__facebook_network_activated', isset($_POST['__wps__facebook_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__gallery_network_activated', isset($_POST['__wps__gallery_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__groups_network_activated', isset($_POST['__wps__groups_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__lounge_main_network_activated', isset($_POST['__wps__lounge_main_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__mobile_network_activated', isset($_POST['__wps__mobile_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__news_main_network_activated', isset($_POST['__wps__news_main_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__profile_plus_network_activated', isset($_POST['__wps__profile_plus_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__rss_main_network_activated', isset($_POST['__wps__rss_main_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__mailinglist_network_activated', isset($_POST['__wps__mailinglist_network_activated']), true);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__wysiwyg_network_activated', isset($_POST['__wps__wysiwyg_network_activated']), true);
			// Site specific
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__events_main_activated', isset($_POST['__wps__events_main_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__forum_activated', isset($_POST['__wps__forum_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__profile_activated', isset($_POST['__wps__profile_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__mail_activated', isset($_POST['__wps__mail_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__members_activated', isset($_POST['__wps__members_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__add_notification_bar_activated', isset($_POST['__wps__add_notification_bar_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__facebook_activated', isset($_POST['__wps__facebook_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__gallery_activated', isset($_POST['__wps__gallery_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__groups_activated', isset($_POST['__wps__groups_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__lounge_main_activated', isset($_POST['__wps__lounge_main_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__mobile_activated', isset($_POST['__wps__mobile_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__news_main_activated', isset($_POST['__wps__news_main_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__profile_plus_activated', isset($_POST['__wps__profile_plus_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__rss_main_activated', isset($_POST['__wps__rss_main_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__mailinglist_activated', isset($_POST['__wps__mailinglist_activated']), false);
			__wps__update_option(WPS_OPTIONS_PREFIX.'__wps__wysiwyg_activated', isset($_POST['__wps__wysiwyg_activated']), false);
		}

		if (isset($_POST['symposium_validation_code'])):
            $clean = preg_replace('/[^,;a-zA-Z0-9_-]/','',$_POST['symposium_validation_code']);
			__wps__update_option(WPS_OPTIONS_PREFIX.'_activation_code', $clean, true);
        endif;

		// Do check for Bronze plugins and activation code
		$has_bronze_plug_actived = has_bronze_plug_actived();

		$show_super_admin = (is_super_admin() && __wps__is_wpmu());
				
		echo "<div style='margin-top:15px; margin-bottom:15px; '>";

			$colspan = 5;
			if ( $show_super_admin ) $colspan = 6;

			echo '<form action="admin.php?page=symposium_debug" method="POST">';
			echo '<input type="hidden" name="__wps__installation_update" value="Y" />';
			echo '<table class="widefat">';
			echo '<thead>';
			echo '<tr>';
			if ( $show_super_admin )
				echo '<th width="10px">'.__('Network&nbsp;Activated', WPS_TEXT_DOMAIN).'</th>';
			echo '<th width="10px">'.__('Activated', WPS_TEXT_DOMAIN).'</th>';
			echo '<th width="150px">'.__('Feature', WPS_TEXT_DOMAIN).'</th>';
			echo '<th>'.__('WordPress page/URL Found', WPS_TEXT_DOMAIN).'</th>';
			echo '<th  style="text-align:center;width:90px;">'.__('Status', WPS_TEXT_DOMAIN);
			if (current_user_can('update_core'))
				echo ' [<a href="javascript:void(0);" id="symposium_url">?</a>]</tg>';
			if (current_user_can('update_core'))
				echo '<th class="symposium_url">'.sprintf(__('%s Settings', WPS_TEXT_DOMAIN), WPS_WL_SHORT).'</th>';
			echo '</tr>';
			echo '</thead>';
			echo '<tbody>';
			echo '<tr>';
				if ( $show_super_admin )
					echo '<td>&nbsp;</td>';
				echo '<td style="text-align:center"><img src="'.WPS_PLUGIN_URL.'/images/tick.png" /></td>';
				echo '<td>'.__('Core', WPS_TEXT_DOMAIN).'</td>';
				echo '<td>&nbsp;</td>';
				echo '<td style="text-align:center"><img src="'.get_option(WPS_OPTIONS_PREFIX.'_images').'/smilies/good.png" /></td>';
				if (current_user_can('update_core'))
					echo '<td class="symposium_url" style="background-color:#efefef">-</td>';
			echo '</tr>';

			// Get version numbers installed (if applicable)
			$mobile_ver = get_option(WPS_OPTIONS_PREFIX."_mobile_version");
			if ($mobile_ver != '') $mobile_ver = "v".$mobile_ver;

			__wps__install_row('profile', __('Profile', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-profile', '__wps__profile', get_option(WPS_OPTIONS_PREFIX.'_profile_url'), WPS_DIR.'/profile.php', 'admin.php?page=profile', '__wps__<a href="admin.php?page=symposium_profile">Options</a>');
			__wps__install_row('forum', __('Forum', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-forum', '__wps__forum', get_option(WPS_OPTIONS_PREFIX.'_forum_url'), WPS_DIR.'/forum.php', 'admin.php?page=forum', '__wps__<a href="admin.php?page=symposium_forum">Options</a>');
			__wps__install_row('members', __('Members', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-members', '__wps__members', get_option(WPS_OPTIONS_PREFIX.'_members_url'), WPS_DIR.'/members.php', 'admin.php?page=__wps__members_menu', '__wps__<a href="admin.php?page=__wps__members_menu">Options</a>');
			__wps__install_row('mail', __('Mail', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-mail', '__wps__mail', get_option(WPS_OPTIONS_PREFIX.'_mail_url'), WPS_DIR.'/mail.php', '', '__wps__<a href="admin.php?page=__wps__mail_menu">Options</a>');

			do_action('__wps__installation_hook');
			
			if ( is_super_admin() ) {

				$bronze = '';
				$bronze .= '<tr style="height:50px;">';
					$bronze .= '<td style="vertical-align:middle;padding-left:10px;" colspan='.$colspan.'>';
					$bronze .= '<input type="submit" class="button-primary" value="'.__('Update', WPS_TEXT_DOMAIN).'" />';
					$bronze .= '</td>';
				$bronze .= '</tr>';
							
				$bronze .= '<thead><tr>';
					$bronze .= '<th colspan='.$colspan.'>'.__('The following are Bronze+ member features', WPS_TEXT_DOMAIN).'</th>';
				$bronze .= '</tr></thead>';
			
				$bronze .= '<tr>';
				$bronze .= '<td colspan='.$colspan.'>';
	
					// Validation code		
					if (!WPS_HIDE_ACTIVATION) {
								
						if (!get_option(WPS_OPTIONS_PREFIX.'_activation_code')) {
							$bronze .= '<img style="float:right; margin:0 0 5px 10px;" src="'.WPS_PLUGIN_URL.'/images/bronze.png" />';
						} else {
							$bronze .= '<img style="width:70px; height:70px; float:right; margin:0 0 5px 10px;" src="'.WPS_PLUGIN_URL.'/images/bronze.png" />';
						}
						if (!get_option(WPS_OPTIONS_PREFIX.'_activation_code')) {
							
							$bronze .= '<p>';
								$bronze .= __('The following features are "Bronze+" member features. You can use them for free, but a polite notice will be shown at the top of your web pages.', WPS_TEXT_DOMAIN).' ';
								$bronze .= __('<strong>If you have purchased Bronze+ membership at www.wpsymposium.com</strong>, your activation code accessed via <a href="http://www.wpsymposium.com/membership" target="_new">http://www.wpsymposium.com/membership</a> (make sure you&apos;ve logged in!).', WPS_TEXT_DOMAIN);
							$bronze .= '</p>';					
						}
						
						$countdown = __wps__bronze_countdown();
						$days_left = $countdown[0];
						if ($has_bronze_plug_actived) {
							if (get_option(WPS_OPTIONS_PREFIX.'_activation_code'))
								$bronze .= $countdown[1];
						} else {
							$bronze .= __('You do not have any Bronze+ features activated on this site, and therefore the activation code is irrelevant.', WPS_TEXT_DOMAIN).'<br /><br />';
						}
		
						$bronze .= '<input type="text" name="symposium_validation_code" value="'.get_option(WPS_OPTIONS_PREFIX.'_activation_code').'" style="height:24px;margin-top:-2px;width:300px; background-color: #ff9; border:1px solid #333;">';
						$bronze .= ' <input type="submit" class="button-primary" value="'.__('Save', WPS_TEXT_DOMAIN).'" />';
						if ($code=get_option(WPS_OPTIONS_PREFIX.'_activation_code')) {
							if ($days_left < 366) {
								if (($code != 'wps') && (substr($code,0,3) != 'vip')) {
									$code =  preg_replace('#[^0-9]#','',$code);
									if ($code < time())
										$bronze .= '<br /><br /> <strong>'.__('This activation code has expired! <a href="http://www.wpsymposium.com/membership" target="_new">Get a new activation code</a> to extend the date.', WPS_TEXT_DOMAIN).'</strong>';
								}
							}
						} else {
							$bronze .= '<br />(no activation code entered)';
						}
						$bronze .= '</p>';
					}
						
				$bronze .= '</td>';
				$bronze .= '</tr>';
				$bronze = apply_filters( '__wps__code_filter', $bronze );
				echo $bronze;
				
			} else {
				echo '<input type="text" name="symposium_validation_code" value="'.get_option(WPS_OPTIONS_PREFIX.'_activation_code').'" style="display:none;">';
			}

			if ( $show_super_admin ) {
				echo '<thead>';
				echo '<tr>';
				echo '<th width="10px">'.__('Network&nbsp;Activated', WPS_TEXT_DOMAIN).'</th>';
				echo '<th>'.__('Activated', WPS_TEXT_DOMAIN).'</th>';
				echo '<th>'.__('Feature', WPS_TEXT_DOMAIN).'</th>';
				echo '<th>'.__('WordPress page/URL Found', WPS_TEXT_DOMAIN).'</th>';
				echo '<th style="text-align:center">'.__('Status', WPS_TEXT_DOMAIN);
				if (current_user_can('update_core'))
					echo '<th class="symposium_url">'.sprintf(__('%s Settings', WPS_TEXT_DOMAIN), WPS_WL_SHORT).'</th>';
				echo '</tr>';
				echo '</thead>';
			}
						
			__wps__install_row('panel', __('Panel/Chat', WPS_TEXT_DOMAIN), '', '__wps__add_notification_bar', '-', WPS_DIR.'/panel.php', 'admin.php?page=bar', '__wps__<a href="admin.php?page=symposium_bar">Options</a>');
			__wps__install_row('wysiwyg', __('Forum WYSIWYG editor', WPS_TEXT_DOMAIN), '', '__wps__wysiwyg', '-', '', WPS_DIR.'/forum.php', '__wps__bronze__<a href="admin.php?page=symposium_forum">Options</a>');
			__wps__install_row('profile_plus', __('Profile_Plus', WPS_TEXT_DOMAIN), '', '__wps__profile_plus', '-', 'wp-symposium/plus.php', 'admin.php?page='.WPS_DIR.'/plus_admin.php', '__wps__bronze__<a href="admin.php?page=wp-symposium/plus_admin.php">Options</a>');
			__wps__install_row('groups', __('Groups', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-groups', '__wps__groups', get_option(WPS_OPTIONS_PREFIX.'_groups_url'), WPS_DIR.'/groups.php', 'admin.php?page='.WPS_DIR.'/groups_admin.php', '__wps__bronze__<a href="admin.php?page=wp-symposium/groups_admin.php">Options</a>');
			__wps__install_row('group', __('Group', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-group', '__wps__group', get_option(WPS_OPTIONS_PREFIX.'_group_url'), WPS_DIR.'/groups.php', '', '__wps__bronze__');
			__wps__install_row('gallery', __('Gallery', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-galleries', '__wps__gallery', '/gallery/', WPS_DIR.'/gallery.php','admin.php?page='.WPS_DIR.'/gallery_admin.php', '__wps__bronze__<a href="admin.php?page=wp-symposium/gallery_admin.php">Options</a>');
			__wps__install_row('alerts', __('Alerts', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-alerts', '__wps__news_main', '-', WPS_DIR.'/news.php', 'admin.php?page='.WPS_DIR.'/news_admin.php', '__wps__bronze__<a href="admin.php?page=wp-symposium/news_admin.php">Options</a>');
			__wps__install_row('events', __('Events', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-events', '__wps__events_main', '-', WPS_DIR.'/events.php', 'admin.php?page='.WPS_DIR.'/events_admin.php', '__wps__bronze__<a href="admin.php?page=wp-symposium/events_admin.php">Options</a>');
			__wps__install_row('mobile', __('Mobile', WPS_TEXT_DOMAIN), '', '__wps__mobile', '-', WPS_DIR.'/mobile.php', 'admin.php?page=__wps__mobile_menu', '__wps__bronze__<a href="admin.php?page=__wps__mobile_menu">Options</a>');
			__wps__install_row('reply_by_email', 'Reply_by_Email', '', '__wps__mailinglist', '-', WPS_DIR.'/mailinglist.php', 'admin.php?page='.WPS_DIR.'/symposium_mailinglist_admin.php', '__wps__bronze__<a href="admin.php?page=wp-symposium/mailinglist_admin.php">Options</a>');
			__wps__install_row('the_lounge', __('The_Lounge', WPS_TEXT_DOMAIN), WPS_SHORTCODE_PREFIX.'-lounge', '__wps__lounge_main', '-', WPS_DIR.'/lounge.php', 'admin.php?page='.WPS_DIR.'/lounge_admin.php', '__wps__bronze__<a href="admin.php?page=wp-symposium/lounge_admin.php">Options</a>');
			__wps__install_row('rss_feed', __('RSS_Feed', WPS_TEXT_DOMAIN), '', '__wps__rss_main', '-', WPS_DIR.'/rss.php', '', '__wps__bronze__');
			__wps__install_row('facebook', __('Facebook', WPS_TEXT_DOMAIN), '', '__wps__facebook', '-', WPS_DIR.'/facebook.php', 'admin.php?page='.WPS_DIR.'/facebook_admin.php', '__wps__bronze__');
	

			echo '<tr style="height:50px">';
				echo '<td style="vertical-align:middle;padding-left:10px;" colspan='.$colspan.'>';
				echo '<input type="submit" class="button-primary" value="'.__('Update', WPS_TEXT_DOMAIN).'" />';
				echo '</td>';
			echo '</tr>';
			
			echo '</tbody>';
			echo '</table>';
			
			echo '</form>';
				
		echo "</div>";

		// Check for request in URL to go straight to site
		if (isset($_GET['gotosite']) && $_GET['gotosite'] == '1') {
			echo '<script>';
			echo 'window.location.replace("'.get_bloginfo('url').'?p='.$_GET['pid'].'");';
			echo '</script>';
			die();
		}
		
		// Only show following to admins and above
		if (current_user_can('update_core') && (!WPS_HIDE_INSTALL_INFO)) {
			
			if (isset($_POST['__wps__install_assist_action'])) {
				$action = $_POST['__wps__install_assist_action'];
				if ($action == 'hide') {
					update_option(WPS_OPTIONS_PREFIX."_install_assist", false);
				} else {
					update_option(WPS_OPTIONS_PREFIX."_install_assist", true);
				}
			}
			
			$show = get_option(WPS_OPTIONS_PREFIX."_install_assist");
			
			if (!$show) {

				echo '<form action="" method="POST">';
				echo '<input type="hidden" name="__wps__install_assist_action" value="show" />';
				echo "<input id='__wps__install_assist_button' type='submit' class='button-secondary' value='".__('Show installation help', WPS_TEXT_DOMAIN)."' />";
				echo '</form>';
				
			} else {
				
				echo '<form action="" method="POST">';
				echo '<input type="hidden" name="__wps__install_assist_action" value="hide" />';
				echo "<input id='__wps__install_assist_button' type='submit' class='button-secondary' value='".__('Hide installation help', WPS_TEXT_DOMAIN)."' />";
				echo '</form>';
				
				echo "<div id='__wps__install_assist' style='margin-top:15px'>";
				
					echo "<div style='width:49%; float:left;'>";
					
						echo '<table class="widefat"><tr><td style="padding:0 0 0 10px">';
							echo '<h2 style="margin-bottom:10px">'.__('Core Information', WPS_TEXT_DOMAIN).'</h2>';
				
							echo '<p>';
							echo __('Site domain name', WPS_TEXT_DOMAIN).': '.get_bloginfo('url').'<br />';
							echo '</p>';
				
							echo "<p>";
				
								global $blog_id;
								echo __("WordPress site ID:", WPS_TEXT_DOMAIN)." ".$blog_id.'<br />';
								echo __("WordPress site name:", WPS_TEXT_DOMAIN)." ".get_bloginfo('name').'<br />';
								echo '<br />';
								echo sprintf(__("%s internal code version:", WPS_TEXT_DOMAIN), WPS_WL)." ";
								$ver = get_option(WPS_OPTIONS_PREFIX."_version");
								if (!$ver) { 
									echo "<br /><span style='clear:both;color:red; font-weight:bold;'>Error!</span> ".__('No code version set. Try <a href="admin.php?page=symposium_debug&force_create_wps=yes">re-creating/modifying</a> the database tables.', WPS_TEXT_DOMAIN)."</span><br />"; 
								} else {
									echo $ver."<br />";
								}
						
							echo "</p>";
							
							// Curl / JSON
							$disabled_functions=explode(',', ini_get('disable_functions'));
							$ok=true;
							if (!is_callable('curl_init')) {
								echo $fail.__('CURL PHP extension is not installed, please contact your hosting company.', WPS_TEXT_DOMAIN).$fail2;
								$ok=false;
							} else {
								if (in_array('curl_init', $disabled_functions)) {
									echo $fail.__('CURL PHP extension is disabled in php.ini, please contact your hosting company.', WPS_TEXT_DOMAIN).$fail2;
									$ok=false;
								} else {
									echo '<p>'.__('CURL PHP extension is installed and enabled in php.ini.', WPS_TEXT_DOMAIN).'</p>';
								}
							}
							if (!is_callable('json_decode')) {
								echo $fail.__('JSON PHP extension is not installed, please contact your hosting company.', WPS_TEXT_DOMAIN).$fail2;
								$ok=false;
							} else {
								if (in_array('json_decode', $disabled_functions)) {
									echo $fail.__('JSON PHP extension is disabled in php.ini, please contact your hosting company.', WPS_TEXT_DOMAIN).$fail2;
									$ok=false;
								} else {
									echo "<p>".__('JSON PHP extension is installed and enabled in php.ini.', WPS_TEXT_DOMAIN)."</p>";
								}
							}
							if (!$ok)
								echo $fail.__('Please contact your hosting company to ask for the above to be installed/enabled.', WPS_TEXT_DOMAIN).$fail2;
							
							// Debug mode?
							if (WPS_DEBUG) {
								echo "<p style='font-weight:bold'>".__('Running in DEBUG mode.', WPS_TEXT_DOMAIN)."</p>";
							}
						echo '</td></tr></table>';
		
						// Integrity check
						echo '<table class="widefat" style="margin-top:10px"><tr><td style="padding:0 10px 0 10px">';
							echo '<a name="ric"></a>';
							echo '<h2 style="margin-bottom:10px">'.__('Integrity check', WPS_TEXT_DOMAIN).'</h2>';
							
							if (isset($_POST['symposium_ric'])) {
								$report = '';

								// Check that user meta matches user table and delete to synchronise
								if (isset($_POST['symposium_ric_syn'])) {
									
									if (!isset($_POST['symposium_ric_username'])) {
										$sql = "SELECT user_id
												FROM ".$wpdb->base_prefix."usermeta m 
												LEFT JOIN ".$wpdb->base_prefix."users u 
												ON m.user_id = u.ID 
												WHERE u.ID IS NULL;";
										$missing_users = $wpdb->get_results($sql); 
									} else {
										$sql = "SELECT user_id
												FROM ".$wpdb->base_prefix."usermeta m 
												LEFT JOIN ".$wpdb->base_prefix."users u 
												ON m.user_id = u.ID 
												WHERE u.ID IS NULL AND u.user_login = %s;";
										$missing_users = $wpdb->get_results($wpdb->prepare($sql, $_POST['symposium_ric_username'])); 
									}
											
									if ($missing_users) {
										foreach ($missing_users as $missing) {
											$sql = "DELETE FROM ".$wpdb->base_prefix."usermeta WHERE user_id = %d";
											$wpdb->query($wpdb->prepare($sql, $missing->uid)); 
											$sql = "DELETE FROM ".$wpdb->base_prefix."symposium_friends WHERE friend_from = %d or friend_to = %d";
											$wpdb->query($wpdb->prepare($sql, $missing->uid, $missing->uid)); 
											$sql = "DELETE FROM ".$wpdb->base_prefix."symposium_group_members WHERE member_id = %d";
											$wpdb->query($wpdb->prepare($sql, $missing->uid)); 			
										}
									}	
									$report .= __("User tables syncronized", WPS_TEXT_DOMAIN).".<br />";															
								}
								
								// Fix missing categories, where replies exist with a category
	  							$sql = "SELECT * from ".$wpdb->prefix."symposium_topics where topic_parent = 0 AND topic_category = 0 order by tid desc";
							  	$a = $wpdb->get_results($sql);
							  	$updated = 0;
							  	foreach ($a as $b) {
							  	    if ($b->topic_category == 0) {
										// Got no category, so check for a reply that has a category
							  	        $sql = "select * from ".$wpdb->prefix."symposium_topics where topic_category > 0 AND topic_parent = %d LIMIT 0,1";
							  	        $d = $wpdb->get_row($wpdb->prepare($sql, $b->tid));
							  	        if ($d) {
							  	            // Update the parent category from 0, to that of it's reply
											$sql = "UPDATE ".$wpdb->prefix."symposium_topics SET topic_category = %d WHERE tid = %d";
											$wpdb->query($wpdb->prepare($sql, $d->topic_category, $b->tid));
											$updated++;
							  	        }
							  	    }
							  	}
							  	if (count($a) > 0) 
									$report .= sprintf( __("%d topics had missing categories, %d were fixed by copying from one of its replies", WPS_TEXT_DOMAIN), count($a), $updated ).".<br />";
									if (count($a)-$updated > 0) 
										$report .= sprintf(__('Fix the remaining orphaned topics <a href="%s">here</a>.', WPS_TEXT_DOMAIN), 'admin.php?page=symposium_moderation&mod=orphaned').'<br />';
							  								    	
								// Update topic categories (if category missing and with a parent)
								$sql = "SELECT * FROM ".$wpdb->prefix."symposium_topics
										WHERE topic_category = 0 AND topic_parent > 0";
								$topics = $wpdb->get_results($sql);
								if ($topics) {
									foreach ($topics AS $topic) {
										// Get the category of the parent and update
										$sql = "SELECT topic_category FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d";
										$parent_cat = $wpdb->get_var($wpdb->prepare($sql, $topic->topic_parent));
										// Update this topic's category to it
										$sql = "UPDATE ".$wpdb->prefix."symposium_topics SET topic_category = %d WHERE tid = %d";
										$wpdb->query($wpdb->prepare($sql, $parent_cat, $topic->tid));
									}
									$report .= sprintf( __("%d replies had missing categories so copied from its parent", WPS_TEXT_DOMAIN), count($topics) )."<br />";
								}
								
								// If a members folder exists in wps-content, but user doesn't exist, report that it exists (can remove?)
								$path = get_option(WPS_OPTIONS_PREFIX.'_img_path').'/members';
								if(file_exists($path) && is_dir($path)) { 
									if ($handler = opendir($path)) {
										while (($sub = readdir($handler)) !== FALSE) {
											if ($sub != "." && $sub != ".." && $sub != "Thumb.db" && $sub != "Thumbs.db" && is_numeric($sub)) {
												if (is_dir($path."/".$sub)) {
													$id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM ".$wpdb->base_prefix."users WHERE ID = %d", $sub));
													if (!$id) {
														$report .= 'User ID ['.$sub.'] not found but '.$path."/".$sub.' exists<br />';
														//__wps__rrmdir($path."/".$sub);
													}
												}
											}
										}
									}
								} else {
									// Folder doesn't exist so create it
									if (!mkdir($path, 0777, true)) {
										$report .= sprintf(__("The %s images/media path could not be created (%s), check rights and re-run the Integrity Check", WPS_TEXT_DOMAIN), WPS_WL, $path);
									} else {
										$report .= sprintf(__("The %s images/media path (%s) was created", WPS_TEXT_DOMAIN), WPS_WL, $path);
									}
								}
								
								// Remove any users with user_id = Null
								$sql = "DELETE FROM ".$wpdb->base_prefix."usermeta WHERE user_id IS Null";
								$wpdb->query($sql);
			
								// Get a list of users that have duplicate keys in wp_usermeta
									$sql = "SELECT DISTINCT user_id FROM (
										SELECT user_id, meta_key, COUNT( user_id ) AS cnt
										FROM ".$wpdb->base_prefix."usermeta
										GROUP BY user_id, meta_key
										HAVING meta_key LIKE  '%symposium%'
										AND cnt > 1
										) AS results";
								$users = $wpdb->get_results($sql); 
			
								// Loop through each user
								if ($users) {
									foreach ($users AS $user) {
			
										if ($user->user_id != null) {
			
											$report .= '<strong>'.sprintf(__("Found duplicate meta_keys for user %d", WPS_TEXT_DOMAIN), $user->user_id).'</strong><br />';
			
											// Get list of meta keys that have duplicates
											$sql = "SELECT DISTINCT meta_key 
													FROM ".$wpdb->base_prefix."usermeta
													WHERE user_id = ".$user->user_id."
													AND meta_key LIKE '%symposium%'";
			
											$meta_keys = $wpdb->get_results($sql);
			
											// For each meta_key get latest, delete them all and re-add just one
											if ($meta_keys) {
												foreach ($meta_keys AS $meta) {
			
													$sql = "SELECT umeta_id, meta_key, meta_value 
															FROM ".$wpdb->base_prefix."usermeta
															WHERE user_id = %d
															AND meta_key =  %s
															ORDER BY umeta_id DESC 
															LIMIT 0 , 1";
			
													$single = $wpdb->get_row($wpdb->prepare($sql, $user->user_id, $meta->meta_key));
			
													// Don't include following as standard as may produce large HTML output
													// $report .= sprintf(__("Setting user %d meta_key '%s' as %s", WPS_TEXT_DOMAIN), $user->user_id, $single->meta_key, $single->meta_value).'<br />';
			
													// Do the clean up
													$sql = "DELETE FROM ".$wpdb->base_prefix."usermeta WHERE user_id = %d AND meta_key = %s";
													$wpdb->query($wpdb->prepare($sql, $user->user_id, $single->meta_key));
													update_user_meta( $user->user_id, $single->meta_key, $single->meta_value );
			
												}
											}
																							
										}
									}
								}
								
								// Update lat/long for distance calculation for all those users with a city and country
								if (function_exists('__wps__profile_plus')) {
									if (isset($_POST['symposium_ric_username']) && $_POST['symposium_ric_username'] != '') {
										$sql = "SELECT * FROM ".$wpdb->base_prefix."users WHERE user_login = %s OR display_name = %s";
										$users = $wpdb->get_results($wpdb->prepare($sql, $_POST['symposium_ric_username'], $_POST['symposium_ric_username']));
										$report .= sprintf(__("Geocoding for %s", WPS_TEXT_DOMAIN), $_POST['symposium_ric_username']).'<br />';
									} else {
										$sql = "SELECT * FROM ".$wpdb->base_prefix."users";
										$users = $wpdb->get_results($sql);
									}
									$not_reported_limit = false;
									
									if ($users) {

										foreach ($users as $user) {
											if (isset($_POST['symposium_ric_username']) && $_POST['symposium_ric_username'] != '')
												$report .= sprintf(__("Found %s", WPS_TEXT_DOMAIN), $_POST['symposium_ric_username']).'<br />';
											
											$lat = get_user_meta($user->ID, 'symposium_plus_lat', true);
											$lng = get_user_meta($user->ID, 'symposium_plus_long', true);
											
											if ( (!$lat || !$lng) || (isset($_POST['symposium_ric_username']) && $_POST['symposium_ric_username'] != '') ) {
												$city = get_user_meta($user->ID, 'symposium_extended_city', true);
												$country = get_user_meta($user->ID, 'symposium_extended_country', true);
		
												if ($city != '' && $country != '') {
													$city = str_replace(' ','%20',$city);
													$country = str_replace(' ','%20',$country);
									
													$fgc = 'http://maps.googleapis.com/maps/api/geocode/json?address='.$city.'+'.$country.'&sensor=false';
											
													if ($json = @file_get_contents($fgc) ) {
														if (WPS_DEBUG || (isset($_POST['symposium_ric_username']) && $_POST['symposium_ric_username'] != '')) $report .= "Connect URL to Google API with: ".$fgc."<br />";
														$json_output = json_decode($json, true);
														$json_output_array = __wps__displayArray($json_output);
														if (strpos($json_output_array, "OVER_QUERY_LIMIT") !== false) {
															if (!$not_reported_limit) {
																$report .= "<span style='color:red; font-weight:bold;'>".__("Google API limit reached, please repeat for remaining users, or enter a user login.", WPS_TEXT_DOMAIN).'</span><br />';														
																$not_reported_limit = true;
															}
														} else {
															$lat_new = $json_output['results'][0]['geometry']['location']['lat'];
															$lng_new = $json_output['results'][0]['geometry']['location']['lng'];														
															if (WPS_DEBUG || (isset($_POST['symposium_ric_username']) && $_POST['symposium_ric_username'] != ''))
																$report .= " - Google results: ".$lat_new."/".$lng_new."<br />";
			
															update_user_meta($user->ID, 'symposium_plus_lat', $lat_new);
															update_user_meta($user->ID, 'symposium_plus_long', $lng_new);
															
															if (!$not_reported_limit)
																$report .= sprintf(__("Updated %s [%d] geocode information for %s,%s from %s,%s to %s,%s", WPS_TEXT_DOMAIN), $user->display_name, $user->ID, $city, $country, $lat, $lng, $lat_new, $lng_new).'<br />';
														}
													} else {
														$report .= "<span style='color:red; font-weight:bold;'>".sprintf(__("Failed to connect to Google API<br>%s", WPS_TEXT_DOMAIN), $json).'</span><br />';
													}
												}
											}
										}
									} else {
										$report .= __("No users found.").'<br />';
									}
									
								} else {
									$report .= __("Not checking geocoding as Profile Plus not activated.").'<br />';
								}								
								
								// Remove dead friendships
								$del_count = 0;
								$sql = "SELECT fid from ".$wpdb->base_prefix."symposium_friends f
										left JOIN ".$wpdb->base_prefix."users u ON u.ID = f.friend_from
										WHERE u.ID is null";
								$orphaned = $wpdb->get_results($sql);
								foreach ($orphaned as $orphan) {
									$sql = "DELETE FROM ".$wpdb->base_prefix."symposium_friends WHERE fid = %d";
									$wpdb->query($wpdb->prepare($sql, $orphan->fid));
									$del_count++;
								}
								$sql = "SELECT fid from ".$wpdb->base_prefix."symposium_friends f
										left JOIN ".$wpdb->base_prefix."users u ON u.ID = f.friend_to
										WHERE u.ID is null";
								$orphaned = $wpdb->get_results($sql);
								foreach ($orphaned as $orphan) {
									$sql = "DELETE FROM ".$wpdb->base_prefix."symposium_friends WHERE fid = %d";
									$wpdb->query($wpdb->prepare($sql, $orphan->fid));
									$del_count++;
								}
								if ($del_count) $report .= sprintf(__("%d orphaned friendships removed.", WPS_TEXT_DOMAIN), $del_count).'<br />';
			
								// Filter
								$report = apply_filters( '__wps__integrity_check_hook', $report );						
			
								// Done
								echo "<div style='margin-top:15px;margin-right:15px; border:1px solid #060;background-color: #9f9; border-radius:5px;padding-left:8px; margin-bottom:10px;'>";
								if ($report == '') { $report = __('No problems found.', WPS_TEXT_DOMAIN); }
								echo "<strong>".__("Integrity check completed.", WPS_TEXT_DOMAIN)."</strong><br />".$report;
								echo "</div>";
								
							}
				
										
							echo "<p>".sprintf(__('<strong>Only click the button below once!<br />This can take a long while to complete if you have a lot of users - please wait for it to finish.<br />If your browser "times out" you can repeat until it completes.</strong><br />You should run the integrity check regularly, preferably daily. Before reporting a support request, please run the %s integrity check. This will remove potential inaccuracies within the database.', WPS_TEXT_DOMAIN), WPS_WL_SHORT)."</p>";
				
							echo '<form method="post" action="#ric">';
							echo '<input type="hidden" name="symposium_ric" value="Y">';
							echo __('Enter a user login/display name to restrict to one user.', WPS_TEXT_DOMAIN).'<br />';
							echo '<input type="text" name="symposium_ric_username" value=""><br />';
							echo '<input type="checkbox" name="symposium_ric_syn"> '.__('Syncronize WordPress user tables with WP Symposium', WPS_TEXT_DOMAIN);
							echo '<p></p><input type="submit" name="Submit" class="button-primary" value="'.__('Run integrity check', WPS_TEXT_DOMAIN).'" /></p>';
							echo '</form>';
		
						echo '</td></tr></table>';
		
						// ********** Reset database version
						echo '<table class="widefat" style="margin-top:10px"><tr><td style="padding:0 0 0 10px">';
							echo '<h2 style="margin-bottom:10px">'.sprintf(__('Refresh %s', WPS_TEXT_DOMAIN), WPS_WL).'</h2>';
							echo "<p>".__('To re-run the database table creation/modifications, <a href="admin.php?page=symposium_debug&force_create_wps=yes">click here</a>.<br /><strong>This will not destroy any existing tables or data</strong>.', WPS_TEXT_DOMAIN)."</p>";
							echo "<p>".sprintf(__('This will also display the %s <a href="%s">welcome page</a>.', WPS_TEXT_DOMAIN), WPS_WL, "admin.php?page=symposium_welcome")."</p>";
						echo '</td></tr></table>';
		
						// Purge chat
						echo '<table class="widefat" style="margin-top:10px"><tr><td style="padding:0 0 0 10px">';
							echo "<a name='purge'></a>";
							echo '<h2 style="margin-bottom:10px">'.__('Purge forum/chat', WPS_TEXT_DOMAIN).'</h2>';
			
							if (isset($_POST['purge_chat']) && $_POST['purge_chat'] != '' && is_numeric($_POST['purge_chat']) ) {
								
								$sql = "SELECT COUNT(id) FROM ".$wpdb->prefix."symposium_chat2 WHERE sent <= ".(time() - $_POST['purge_chat'] * 24 * 60 * 60);	
								$cnt = $wpdb->get_var( $sql );
								$sql = "DELETE FROM ".$wpdb->prefix."symposium_chat2 WHERE sent <= ".(time() - $_POST['purge_chat'] * 24 * 60 * 60);	
								$wpdb->query( $sql );
								
								echo "<div style='margin-top:10px; border:1px solid #060;background-color: #9f9; border-radius:5px;padding-left:8px; margin-bottom:10px;'>";
								echo "Chat purged: ".$cnt;
								echo "</div>";
							}
							
							// Purge topics
							if (isset($_POST['purge_topics']) && $_POST['purge_topics'] != '' && is_numeric($_POST['purge_topics']) ) {
								
								$sql = "SELECT tid FROM ".$wpdb->prefix."symposium_topics WHERE topic_started <= '".date("Y-m-d H:i:s",strtotime('-'.$_POST['purge_topics'].' days'))."'";	
								$topics = $wpdb->get_results( $sql );
								
								$cnt = 0;
								if ($topics) {
									foreach ($topics as $topic) {
										$cnt++;
										$wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."symposium_subs WHERE tid = %d", $topic->tid));
										$wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d", $topic->tid));
									}
								}
								
								echo "<div style='margin-top:10px; border:1px solid #060;background-color: #9f9; border-radius:5px;padding-left:8px; margin-bottom:10px;'>";
								echo "Topics purged: ".$cnt;
								echo "</div>";
							}
			
							echo '<p>'.__('Forum activity and chat purged are <strong>deleted</strong> - you cannot undo this. Take a backup first!', WPS_TEXT_DOMAIN).'</p>';
				
							echo '<form action="" method="post"><table style="margin-bottom:10px">';
							echo '<tr><td style="border:0">'.__('Chat older than', WPS_TEXT_DOMAIN);
								echo '</td><td style="border:0"><input type="text" size="3" name="purge_chat"> ';
								echo __('days', WPS_TEXT_DOMAIN)."</td></tr>";
							echo '<tr><td style="border:0">'.__('Forum topics older than', WPS_TEXT_DOMAIN);
								echo '</td><td style="border:0"><input type="text" size="3" name="purge_topics"> ';
								echo __('days', WPS_TEXT_DOMAIN)."</td></tr></table>";
							echo '<input type="submit" class="button-primary delete" value="'.__('Purge', WPS_TEXT_DOMAIN).'">';
							echo '</form><br />';
						echo '</td></tr></table>';
		
					echo "</div>";
					echo "<div style='width:50%; float:right; padding-bottom:15px;'>";
		
						// Permalinks
						echo '<table class="widefat" style="float:right;"><tr><td style="padding:0 0 0 10px">';
							echo '<a name="perma"></a>';
							echo '<h2 style="margin-bottom:10px">'.sprintf(__('%s Permalinks', WPS_TEXT_DOMAIN), WPS_WL_SHORT).'</h2>';
							echo '<p style="font-weight:bold">'.__('It is recommended that you test these before implementing.', WPS_TEXT_DOMAIN).'</p>';
							
							// Act on submit
							$just_switched_on = false;
							if (isset($_POST[ 'symposium_permalinks' ])) {
								if ( $_POST[ 'symposium_permalinks_enable' ] == 'on' ) {
									// If switching on, default categories to on
									if (!get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) {
										update_option(WPS_OPTIONS_PREFIX.'_permalinks_cats', 'on');	
										$just_switched_on = true;			   	    
									} else {
										// If already on, act on categories checkbox
										if (isset($_POST[ 'symposium_permalinks_cats' ])) {
											update_option(WPS_OPTIONS_PREFIX.'_permalinks_cats', 'on');
										} else {
											update_option(WPS_OPTIONS_PREFIX.'_permalinks_cats', '');
										}
									}
									update_option(WPS_OPTIONS_PREFIX.'_permalink_structure', 'on');				   	    
									
								} else {
			
									if (get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')) {
										echo '<p>'.__('The first time you enable permalinks, please be patient while your database is updated.', WPS_TEXT_DOMAIN).'</p>'; 
									}
									delete_option('symposium_permalink_structure');
									delete_option('symposium_permalinks_cats');
								}
							}
			
							if ( get_option('permalink_structure') != '' ) {
			
								echo '<form method="post" action="#perma">';
			
									if ( get_option(WPS_OPTIONS_PREFIX.'_permalink_structure')  ) {
										
										// Can't work with Forum in AJAX mode
										if (get_option(WPS_OPTIONS_PREFIX.'_forum_ajax')) {
											update_option(WPS_OPTIONS_PREFIX.'_forum_ajax', '');
											echo '<p style="color:green; font-weight:bold;">'.__('Forum "AJAX mode" has been disabled, as this is not compatible with permalinks.', WPS_TEXT_DOMAIN).'</p>'; 
										}
				
										// Do a check to ensure all forum categories have a slug
										$sql = "SELECT * FROM ".$wpdb->prefix."symposium_cats WHERE stub = ''";
										$cats = $wpdb->get_results($sql);
										if ($cats) {
											foreach ($cats as $cat) {
												$stub = __wps__create_stub($cat->title);
												$sql = "UPDATE ".$wpdb->prefix."symposium_cats SET stub = '".$stub."' WHERE cid = %d";
												$wpdb->query($wpdb->prepare($sql, $cat->cid));
												if (WPS_DEBUG) echo $wpdb->last_query.'<br>';
											}
										}
										// Do a check to ensure all forum topics have a slug
										$sql = "SELECT * FROM ".$wpdb->prefix."symposium_topics WHERE topic_parent = 0 AND stub = '' ORDER BY tid DESC";
										$topics = $wpdb->get_results($sql);
										if ($topics) {
											foreach ($topics as $topic) {
												$stub = __wps__create_stub($topic->topic_subject);
												$sql = "UPDATE ".$wpdb->prefix."symposium_topics SET stub = '".$stub."' WHERE tid = %d";
												$wpdb->query($wpdb->prepare($sql, $topic->tid));
												if (WPS_DEBUG) echo $wpdb->last_query.'<br>';
											}
										} 
			
										// update any POSTed values or update default values if necessary
										$reset = isset($_POST['symposium_permalinks_reset']) ? true : false;
			
										if ( (!$just_switched_on) && (!$reset) && ( get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single') || get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double') || get_option(WPS_OPTIONS_PREFIX.'_rewrite_members') ) )  {
												
												if (isset($_POST['symposium_permalinks']) && $_POST['symposium_permalinks'] == 'Y') {
													update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single', $_POST['symposium_rewrite_forum_single']);
													update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single_target', $_POST['symposium_rewrite_forum_single_target']);
													update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double', $_POST['symposium_rewrite_forum_double']);
													update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double_target', $_POST['symposium_rewrite_forum_double_target']);
													update_option(WPS_OPTIONS_PREFIX.'_rewrite_members', $_POST['symposium_rewrite_members']);
													update_option(WPS_OPTIONS_PREFIX.'_rewrite_members_target', $_POST['symposium_rewrite_members_target']);
												}
												flush_rewrite_rules();
												
										} else {
											
											// check that options exist if not put in defaults
			//								if ( ($reset) || ( !get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single') && !get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double')  && !get_option(WPS_OPTIONS_PREFIX.'_rewrite_members') ) ) {
			
												// get forum path and pagename
												$sql = "SELECT ID, post_title FROM ".$wpdb->prefix."posts WHERE post_content LIKE  '%[symposium-forum]%' AND post_status =  'publish' AND post_type =  'page'";
												$page = $wpdb->get_row($sql);
												$permalink = __wps__get_url('forum');
												$p = strtolower(trim(str_replace(get_bloginfo('url'), '', $permalink), '/'));
												$post_title = rawurlencode($page->post_title);
			
												// get profile path and pagename
												$sql = "SELECT ID, post_title FROM ".$wpdb->prefix."posts WHERE post_content LIKE  '%[symposium-profile]%' AND post_status =  'publish' AND post_type =  'page'";
												$page = $wpdb->get_row($sql);
												$permalink = __wps__get_url('profile');
												$m = strtolower(trim(str_replace(get_bloginfo('url'), '', $permalink), '/'));
												$members_title = rawurlencode($page->post_title);
												
												update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single', $p.'/([^/]+)/?');
												update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single_target', 'index.php?pagename='.$post_title.'&stub=/$matches[1]');
												update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double', $p.'/([^/]+)/([^/]+)/?');
												update_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double_target', 'index.php?pagename='.$post_title.'&stub=$matches[1]/$matches[2]');
												update_option(WPS_OPTIONS_PREFIX.'_rewrite_members', $m.'/([^/]+)/?');
												update_option(WPS_OPTIONS_PREFIX.'_rewrite_members_target', 'index.php?pagename='.$members_title.'&stub=$matches[1]');
			
												flush_rewrite_rules();
												echo '<p style="color:green; font-weight:bold;">'.__('Re-write rules saved as default suggested values.', WPS_TEXT_DOMAIN).'</p>'; 
												
												update_option(WPS_OPTIONS_PREFIX.'_permalinks_cats', 'on');
			
			//								}
										}
			
										// Flush WP permalinks to clean up
										global $wp_rewrite;				
										$wp_rewrite->flush_rules();
			
										// Display fields allowing them to be altered												
																
										echo '<strong>'.__('Forum', WPS_TEXT_DOMAIN).'</strong><br />';
										echo '<input type="text" name="symposium_rewrite_forum_single" style="width:150px" value="'.get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single').'" /> => ';
										echo '<input type="text" name="symposium_rewrite_forum_single_target" style="width:400px" value="'.get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_single_target').'" /><br />';
										echo '<input type="text" name="symposium_rewrite_forum_double" style="width:150px" value="'.get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double').'" /> => ';
										echo '<input type="text" name="symposium_rewrite_forum_double_target" style="width:400px" value="'.get_option(WPS_OPTIONS_PREFIX.'_rewrite_forum_double_target').'" /><br />';
										echo '<br /><strong>'.__('Member Profile', WPS_TEXT_DOMAIN).'</strong><br />';
										echo '<input type="text" name="symposium_rewrite_members" style="width:150px" value="'.get_option(WPS_OPTIONS_PREFIX.'_rewrite_members').'" /> => ';
										echo '<input type="text" name="symposium_rewrite_members_target" style="width:400px" value="'.get_option(WPS_OPTIONS_PREFIX.'_rewrite_members_target').'" /><br /><br />';
										
										echo '<input type="hidden" name="symposium_permalinks" value="Y">';
										echo '<input type="checkbox" name="symposium_permalinks_enable" CHECKED > '.sprintf(__('%s Permalinks enabled', WPS_TEXT_DOMAIN), WPS_WL_SHORT).'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
										echo '<input type="checkbox" name="symposium_permalinks_cats"';
											if (get_option(WPS_OPTIONS_PREFIX.'_permalinks_cats')) echo ' CHECKED';
											echo '> '.__('Include categories in forum hyperlinks', WPS_TEXT_DOMAIN).'<br /><br />';
										echo '<input type="checkbox" name="symposium_permalinks_reset" /> '.__('Reset to default suggested values (if you have altered page names for example)', WPS_TEXT_DOMAIN);
										echo '<p style="margin: 10px 0 10px 0"><input type="submit" class="button-primary" value="'.__('Update', WPS_TEXT_DOMAIN).'" />';
										
									} else {
										echo '<input type="hidden" name="symposium_permalinks" value="Y">';
										echo '<input type="checkbox" name="symposium_permalinks_enable"> '.sprintf(__('Check to enable %s Permalinks', WPS_TEXT_DOMAIN), WPS_WL_SHORT);
										echo '<p style="margin: 10px 0 10px 0"><input type="submit" class="button-primary" value="'.__('Update', WPS_TEXT_DOMAIN).'" />';
									}
			
			
								echo '</form>';
			
							} else {
								echo '<p>'.__('You cannot use Permalinks if your WordPress <a href="options-permalink.php">permalink setting</a> is default.', WPS_TEXT_DOMAIN).'</p>'; 
							}
							
						echo '</td></tr></table>';
		
						// ********** Test Email   	
						echo '<table class="widefat" style="margin-top:10px; float:right;"><tr><td style="padding:0 0 0 10px">';
						
							if( isset($_POST[ 'symposium_testemail' ]) && $_POST[ 'symposium_testemail' ] == 'Y' && $_POST['symposium_testemail_address'] != '' ) {
								$to = $_POST['symposium_testemail_address'];
								if (__wps__sendmail($to, sprintf("%s Test Email", WPS_WL), __("This is a test email sent from", WPS_TEXT_DOMAIN)." ".get_bloginfo('url'))) {
									echo "<div class='updated'><p>";
									$from = get_option(WPS_OPTIONS_PREFIX.'_from_email');
									echo sprintf(__('Email sent to %s from', WPS_TEXT_DOMAIN), $to);
									echo ' '.$from;
									echo "</p></div>";
								} else {
									echo "<div class='error'><p>".__("Email failed to send", WPS_TEXT_DOMAIN).".</p></div>";
								}
							}
							echo '<h2 style="margin-bottom:10px">'.__('Send a test email', WPS_TEXT_DOMAIN).'</h2>';
				
							echo '<p>'.__('Enter a valid email address to test sending an email from the server', WPS_TEXT_DOMAIN).'.</p>';
							echo '<form method="post" action="">';
							echo '<input type="hidden" name="symposium_testemail" value="Y">';
							echo '<p><input type="text" name="symposium_testemail_address" value="" style="margin-right:15px;height:24px;width:300px" class="regular-text">';
							echo '<input type="submit" name="Submit" class="button-primary" value="'.__('Send email', WPS_TEXT_DOMAIN).'" /></p';
							echo '</form>';
							
						echo '</td></tr></table>';
		
						// Image uploading
						echo '<table class="widefat" style="margin-top:10px; float:right;"><tr><td style="padding:0 0 0 10px">';
							echo '<a name="image"></a>';
							echo '<h2 style="margin-bottom:10px">'.__('Image Uploading', WPS_TEXT_DOMAIN).'</h2>';
						
							echo "<div>";
							echo "<div id='symposium_user_login' style='display:none'>".strtolower($current_user->user_login)."</div>";
							echo "<div id='symposium_user_email' style='display:none'>".strtolower($current_user->user_email)."</div>";
							if (get_option(WPS_OPTIONS_PREFIX.'_img_db') == "on") {
								echo __("<p>You are storing images in the database.</p>", WPS_TEXT_DOMAIN);
							} else {
								echo __("<p>You are storing images in the file system.</p>", WPS_TEXT_DOMAIN);			
					
								if (file_exists(get_option(WPS_OPTIONS_PREFIX.'_img_path'))) {
									echo "<p>".sprintf(__('The folder %s exists, where images uploaded will be placed.', WPS_TEXT_DOMAIN), get_option(WPS_OPTIONS_PREFIX.'_img_path'))."</p>";
								} else {
									echo "<p>".sprintf(__('The folder %s does not exist, where images uploaded will be placed, trying to create...', WPS_TEXT_DOMAIN), get_option(WPS_OPTIONS_PREFIX.'_img_path'))."</p>";
									if (!mkdir(get_option(WPS_OPTIONS_PREFIX.'_img_path'), 0755, true)) {
										echo '<p>Failed to create '.get_option(WPS_OPTIONS_PREFIX.'_img_path').'.</p>';
										$error = error_get_last();
									    echo '<p>'.$error['message'].'<br />';
									    echo sprintf(__('For info, this script is in %s.', WPS_TEXT_DOMAIN), __FILE__);
									} else {
										echo '<p>Created '.get_option(WPS_OPTIONS_PREFIX.'_img_path').'.</p>';
									}
								}
								
								if (get_option(WPS_OPTIONS_PREFIX.'_img_url') == '') {
									echo "<p>".$fail.__('You must update the URL for your images on the <a href="admin.php?page=symposium_settings">Settings</a>.', WPS_TEXT_DOMAIN).$fail2."</p>";
								} else {
									echo "<p>".__('The URL to your images folder is', WPS_TEXT_DOMAIN)." <a href='".get_option(WPS_OPTIONS_PREFIX.'_img_url')."'>".get_option(WPS_OPTIONS_PREFIX.'_img_url')."</a>.</p>";
								}
			
								$tmpDir = get_option(WPS_OPTIONS_PREFIX.'_img_path').'/tmp';
								$tmpFile = '.txt';
								$tmpFile = time().'.tmp';
								$targetTmpFile = $tmpDir.'/'.$tmpFile;
								
								// Does tmp folder exist?
								if (!file_exists($tmpDir)) {
									if (@mkdir($tmpDir)) {
										echo '<p>'.sprintf(__('The %s temporary image folder (%s) does not currently exist', WPS_TEXT_DOMAIN), WPS_WL_SHORT, $tmpDir);
										echo __(', and has been created.', WPS_TEXT_DOMAIN).'</p>';
									} else {
										echo '<p>'.$fail.sprintf(__('The %s temporary image folder (%s) does not currently exist', WPS_TEXT_DOMAIN), WPS_WL_SHORT, $tmpDir);
										echo __(', and could not be created - please check permissions of this path.', WPS_TEXT_DOMAIN).$fail2.'</p>';
									}
								} else {
									echo '<p>'.sprintf(__('The %s temporary image folder (%s) exists.', WPS_TEXT_DOMAIN), WPS_WL_SHORT, $tmpDir).'</p>';
									
									// Check creating a temporary file in tmp
									if (touch($targetTmpFile)) {
										@unlink($targetTmpFile);
										echo "<p>".sprintf(__('Temporary file (%s) created and removed successfully.', WPS_TEXT_DOMAIN), $tmpFile)."</p>";
									} else {
										echo '<p>'.$fail.sprintf(__('A temporary file (%s) could not be created (in %s), please check permissions.', WPS_TEXT_DOMAIN), $targetTmpFile, $tmpDir);
									}
								}
								
							}
							echo "</div>";
						echo '</td></tr></table>';

						// Link to licence
						echo '<table class="widefat" style="margin-top:10px; float:right;"><tr><td style="padding:0 0 0 10px">';
							echo '<a name="image"></a>';
							echo '<h2 style="margin-bottom:10px">'.__('End User Licence Agreement', WPS_TEXT_DOMAIN).'</h2>';
						
							echo "<p>".sprintf(__("If you do not accept the terms of the <a href='%s'>licence</a>, please remove this plugin", WPS_TEXT_DOMAIN), WPS_PLUGIN_URL."/licence.txt").".</p>";
							
						echo '</td></tr></table>';
								
						// ********** Daily Digest 
						echo '<table class="widefat" style="margin-top:10px; float:right;"><tr><td style="padding:0 0 0 10px">';
							echo '<h2 style="margin-bottom:10px">'.__('Daily Digest', WPS_TEXT_DOMAIN).'</h2>';
				
							if( isset($_POST[ 'symposium_dailydigest' ]) && $_POST[ 'symposium_dailydigest' ] == 'Y' ) {
								$to_users = isset($_POST['symposium_dailydigest_users']) ? $_POST['symposium_dailydigest_users'] : '';
								$to_admin = isset($_POST['symposium_dailydigest_admin']) ? $_POST['symposium_dailydigest_admin'] : '';
								if ($to_users == 'on' || $to_admin == 'on') {
									echo "<div style='border:1px solid #060;background-color: #9f9; border-radius:5px;padding-left:8px; margin-bottom:10px;'>Running...<br />";
									if ($to_users == "on") {
										echo "Sending summary report and to all users...<br />";
										$success = __wps__notification_do_jobs('send_admin_summary_and_to_users');
									}								
									if ($to_admin == "on") {
										echo "Sending summary report and daily digest to admin only... ";
										$success = __wps__notification_do_jobs('symposium_dailydigest_admin');
									}			
									echo $success;
									echo "Complete.<br />";
									if ($success == 'OK' && $to_admin == 'on') {
										echo "Summary report sent to ".get_bloginfo('admin_email').".<br />";
									}
									echo "</div>";
								}
							}
							echo '<p>'.__('The Daily Digest also performs some basic database cleanup operations, which can be run at any time', WPS_TEXT_DOMAIN).'.</p>';
							echo '<form method="post" action="">';
							echo '<input type="hidden" name="symposium_dailydigest" value="Y">';
							echo '<input type="checkbox" name="symposium_dailydigest_admin" > '.__('Send Daily Digest and summary to admin', WPS_TEXT_DOMAIN).' ('.get_bloginfo('admin_email').')<br />';
							echo '<input type="checkbox" name="symposium_dailydigest_users" > '.__('Send Daily Digest to users now (includes summary to admin)', WPS_TEXT_DOMAIN);
							echo '<p style="margin-top:10px"><input type="submit" name="Submit" class="button-primary" value="'.__('Send Daily Digest', WPS_TEXT_DOMAIN).'" /></p>';
							echo '</form>';
						echo '</td></tr></table>';
		
					echo "</div>";
					
					echo "<div style='clear:both;'></div>";
		
					// ********** Stylesheets	
					echo '<table class="widefat" style="margin-top:10px; float:right;"><tr><td style="padding:0 0 0 10px">';
					
						echo '<h2 style="margin-bottom:10px">'.__('Stylesheets', WPS_TEXT_DOMAIN).'</h2>';
				
						// CSS check
						$myStyleFile = WPS_PLUGIN_DIR . '/css/'.get_option(WPS_OPTIONS_PREFIX.'_wps_css_file');
						if ( !file_exists($myStyleFile) ) {
							echo $fail . sprintf(__('Stylesheet (%s) not found.', WPS_TEXT_DOMAIN), $myStyleFile) . $fail2;
						} else {
							echo "<p style='color:green; font-weight:bold;'>" . sprintf(__('Stylesheet (%s) found.', WPS_TEXT_DOMAIN), $myStyleFile) . "</p>";
						}
							
						// ********** Javascript			
						echo '<h2 style="margin-bottom:10px">'.__('Javascript', WPS_TEXT_DOMAIN).'</h2>';
				
						// JS check
						$myJSfile = WPS_PLUGIN_DIR . '/js/'.get_option(WPS_OPTIONS_PREFIX.'_wps_js_file');
						if ( !file_exists($myJSfile) ) {
							echo $fail . sprintf(__('Javascript file (%s) not found.', WPS_TEXT_DOMAIN), $myJSfile) . $fail2;
						} else {
							echo "<p style='color:green; font-weight:bold;'>" . sprintf(__("Javascript file (%s) found.", WPS_TEXT_DOMAIN), $myJSfile) . "</p>";
						}
						echo "<p>" . sprintf(__("If you find that certain %s things don't work, like buttons or uploading profile photos, it is probably because the %s Javascript file isn't loading and/or working. Usually, this is because of another WordPress plugin. Try deactivating all non-%s plugins and switching to the TwentyEleven theme. If %s then works, re-activate the plug-ins one at a time until the error re-occurs, this will help you locate the plugin that is clashing. Then switch your theme back. Also try using Firefox, with the Firebug add-in installed - this will show you where the Javascript error is occuring.", WPS_TEXT_DOMAIN), WPS_WL, WPS_WL, WPS_WL_SHORT, WPS_WL_SHORT)."</p>";
						echo "<p>".__("If you are experiencing problems, <a href='http://www.wpsymposium.com/trythisfirst' target='_blank'>try this first</a>.", WPS_TEXT_DOMAIN)."</p>";
								
						echo "<div id='jstest'>".$fail.sprintf(__( "You have problems with Javascript. This may be because a plugin is loading another version of jQuery or jQuery UI - try deactivating all plugins apart from %s plugins, and re-activate them one at a time until the error re-occurs, this will help you locate the plugin that is clashing. It might also be because there is an error in a JS file, either the symposium.js or another plugin script.", WPS_TEXT_DOMAIN), WPS_WL_SHORT).$fail2."</div>";
					echo '</td></tr></table>';
		
			
					// ********** bbPress migration
					echo '<table class="widefat" style="margin-top:10px; float:right;"><tr><td style="padding:0 0 0 10px">';
						echo '<a name="bbpress"></a>';
						echo '<h2 style="margin-bottom:10px">'.__('bbPress Migration', WPS_TEXT_DOMAIN).'</h2>';
				
						// migrate any chosen bbPress forums
						if( isset($_POST[ 'symposium_bbpress' ]) && $_POST[ 'symposium_bbpress' ] == 'Y' ) {
							$id = $_POST['bbPress_forum'];
							$cat_title = $_POST['bbPress_category'];
							
							$success = true;
							$success_message = "";
							
							if ($cat_title != '') {
								
								$sql = "SELECT * FROM ".$wpdb->prefix."posts WHERE post_type = 'forum' AND ID = %d";
								$forum = $wpdb->get_row($wpdb->prepare($sql, $id));
								$success_message .= "Creating &quot;".$cat_title."&quot; from &quot;".$forum->post_title."&quot;. ";

								$stub = trim(preg_replace("/[^A-Za-z0-9 ]/",'',$cat_title));
								$stub = strtolower(str_replace(' ', '-', $stub));
								$sql = "SELECT COUNT(*) FROM ".$wpdb->prefix."symposium_cats WHERE stub = '".$stub."'";
								$cnt = $wpdb->get_var($sql);
								if ($cnt > 0) $stub .= "-".$cnt;
								$stub = str_replace('--', '-', $stub);

								// Add new forum category
								if ( $wpdb->query( $wpdb->prepare( "
									INSERT INTO ".$wpdb->prefix.'symposium_cats'."
									( 	title, 
										cat_parent,
										listorder,
										cat_desc,
										allow_new,
										hide_breadcrumbs,
										hide_main,
										stub
									)
									VALUES ( %s, %d, %d, %s, %s, %s, %s, %s )", 
									array(
										$cat_title, 
										0,
										0,
										$forum->post_content,
										'on',
										'',
										'',
										$stub
										) 
									) )
								) {
									
									$success_message .= __("Forum created OK with stub ".$stub.".", WPS_TEXT_DOMAIN)."<br />";
									
									$new_forum_id = $wpdb->insert_id;
			
									$sql = "SELECT * FROM ".$wpdb->prefix."posts WHERE post_type = 'topic' AND post_parent = %d";
									$topics = $wpdb->get_results($wpdb->prepare($sql, $id));
									$success_message .= "Migrating topics to &quot;".$cat_title."&quot;.<br />";
									
									if ($topics) {
										
										$failed = 0;
										foreach ($topics AS $topic) {
											
											$stub = __wps__create_stub($topic->post_title);

											if ( $wpdb->query( $wpdb->prepare( "
												INSERT INTO ".$wpdb->prefix."symposium_topics 
												( 	topic_subject,
													topic_category, 
													topic_post, 
													topic_date, 
													topic_started, 
													topic_owner, 
													topic_parent, 
													topic_views,
													topic_approved,
													for_info,
													topic_group,
													stub
												)
												VALUES ( %s, %d, %s, %s, %s, %d, %d, %d, %s, %s, %d, %s )", 
												array(
													$topic->post_title, 
													$new_forum_id,
													$topic->post_content, 
													$topic->post_modified,
													$topic->post_date, 
													$topic->post_author, 
													0,
													0,
													'on',
													'',
													0, 
													$stub
													) 
												) ) ) {
			
													$success_message .= "Migrated &quot;".$topic->post_title."&quot; OK.<br />";	
													
													$new_topic_id = $wpdb->insert_id;
							
													$sql = "SELECT * FROM ".$wpdb->prefix."posts WHERE post_type = 'reply' AND post_parent = %d";
													$replies = $wpdb->get_results($wpdb->prepare($sql, $topic->ID));
													
													if ($replies) {
														$success_message .= "Migrating replies to &quot;".$topic->post_title."&quot; OK. ";	
													
														$failed_replies = 0;
														foreach ($replies AS $reply) {
			
															if ( $wpdb->query( $wpdb->prepare( "
															INSERT INTO ".$wpdb->prefix."symposium_topics
															( 	topic_subject, 
																topic_category,
																topic_post, 
																topic_date, 
																topic_started, 
																topic_owner, 
																topic_parent, 
																topic_views,
																topic_approved,
																topic_group,
																topic_answer
															)
															VALUES ( %s, %d, %s, %s, %s, %d, %d, %d, %s, %d, %s )", 
															array(
																'', 
																$new_forum_id,
																$reply->post_content, 
																$reply->post_modified,
																$reply->post_date, 
																$reply->post_author, 
																$new_topic_id,
																0,
																'on',
																0,
																''
																) 
															) ) ) {
															} else {
																$failed_replies++;
															}
															
														}
			
														if ($failed_replies == 0) {
								
															$success_message .= __("Replies migrated OK.", WPS_TEXT_DOMAIN)."<br />";
															
														} else {
															$success_message .= sprintf(__("Failed to migrate %d replies.", WPS_TEXT_DOMAIN), $failed_replies)."<br />";
															$success = false;
														}
			
													} else {
														$success_message .= __("No replies to migrate.", WPS_TEXT_DOMAIN)."<br />";
													}
											
											} else {
												$failed++;
											}
											   
										}
										
										if ($failed == 0) {
				
											$success_message .= __("Topics and replies migrated OK.", WPS_TEXT_DOMAIN)."<br />";
											
										} else {
											$success_message .= sprintf(__("Failed to migrate %d topics.", WPS_TEXT_DOMAIN), $failed)."<br />";
											$success = false;
										}
									} else {
											$success_message .= __("No topics to migrate.", WPS_TEXT_DOMAIN)."<br />";
									}
									
								} else {
									$success_message .= __("Forum failed to migrate", WPS_TEXT_DOMAIN)."<br />";
									$success_message .= $wpdb->last_query."<br />";
									$success = false;
								}
									
									
							} else {
								$success_message .= __('Please enter a new forum category title', WPS_TEXT_DOMAIN);
							}
							
							if ($success) {
								echo "<div style='margin-top:10px;border:1px solid #060;background-color: #9f9; border-radius:5px;padding-left:8px; margin-bottom:10px;'>";
								echo $success_message;
								echo "Complete.<br />";			
								echo "</div>";
							} else {
								echo "<div style='margin-top:10px;border:1px solid #600;background-color: #f99; border-radius:5px;padding-left:8px; margin-bottom:10px;'>";
								echo $success_message;
								echo "</div>";
							}
							
						}
				
						// check to see if any bbPress forums exist
						$sql = "SELECT * FROM ".$wpdb->prefix."posts WHERE post_type = 'forum'";
						$forums = $wpdb->get_results($sql);
						if ($forums) {
							echo '<p>'.sprintf(__('If you have bbPress v2 plugin forums, you can migrate them to your %s forum as a new category.', WPS_TEXT_DOMAIN), WPS_WL).'</p>';
							echo '<p>'.__('This migration works with the <a href="" target="_blank">WordPress bbPress plugin v2</a>. If you are running a previous or stand-alone version of bbPress, you should upgrade your installation first.', WPS_TEXT_DOMAIN).'</p>';
							echo '<p>'.__('You should take a backup of your database before migrating, just in case there is a problem.', WPS_TEXT_DOMAIN).'</p>';
							echo '<form method="post" action="#bbpress">';
							echo '<input type="hidden" name="symposium_bbpress" value="Y">';
							echo __('Select forum to migrate:', WPS_TEXT_DOMAIN).' ';
							echo '<select name="bbPress_forum">';
							foreach ($forums AS $forum) {
								echo '<option value="'.$forum->ID.'">'.$forum->post_title.'</option>';
							}
							echo '</select><br />';
							echo __('Enter new forum category title:', WPS_TEXT_DOMAIN).' ';
							echo '<input type="text" name="bbPress_category" />';
							echo '<p><em>' . __("Although your bbPress forum is not altered, and only new categories/topics/replies are added, it is recommended that you backup your database first.", WPS_TEXT_DOMAIN) . '</em></p>';
							echo '<p class="submit"><input type="submit" name="Submit" class="button-primary" value="'.__('Migrate bbPress', WPS_TEXT_DOMAIN).'" /></p>';
							echo '</form>';
						} else {
							echo '<p>'.__('No bbPress forums found', WPS_TEXT_DOMAIN).'.</p>';
						}
					echo '</td></tr></table>';
		
		
					// ********** Mingle migration
					echo '<table class="widefat" style="margin-top:10px; float:right;"><tr><td style="padding:0 0 0 10px">';			
						echo '<a name="mingle"></a>';
						echo '<h2 style="margin-bottom:10px">'.__('Mingle Migration', WPS_TEXT_DOMAIN).'</h2>';
			
						// migrate any chosen mingle forums
						if( isset($_POST[ 'symposium_mingle' ]) && $_POST[ 'symposium_mingle' ] == 'Y' ) {
							$id = $_POST['mingle_forum'];
							$cat_title = $_POST['mingle_category'];
							
							$success = true;
							$success_message = "";
							
							if ($cat_title != '') {
								
								$sql = "SELECT * FROM ".$wpdb->prefix."forum_forums WHERE id = %d";
								$forum = $wpdb->get_row($wpdb->prepare($sql, $id));
								$success_message .= "Creating &quot;".$cat_title."&quot; from &quot;".$forum->name."&quot;. ";
			
								// Add new forum category
								if ( $wpdb->query( $wpdb->prepare( "
									INSERT INTO ".$wpdb->prefix.'symposium_cats'."
									( 	title, 
										cat_parent,
										listorder,
										cat_desc,
										allow_new
									)
									VALUES ( %s, %d, %d, %s, %s )", 
									array(
										$cat_title, 
										0,
										0,
										$forum->description,
										'on'
										) 
									) )
								) {
									
									$success_message .= __("Forum created OK.", WPS_TEXT_DOMAIN)."<br />";
									
									$new_forum_id = $wpdb->insert_id;
									
									// Get Mingle threads	
									$sql = "SELECT * FROM ".$wpdb->prefix."forum_threads WHERE parent_id = %d";
									$topics = $wpdb->get_results($wpdb->prepare($sql, $id));
									$success_message .= "Migrating topics to &quot;".$cat_title."&quot;.<br />";
									
									if ($topics) {
										
										$failed = 0;								
										foreach ($topics AS $topic) {
											
											if ( $wpdb->query( $wpdb->prepare( "
												INSERT INTO ".$wpdb->prefix."symposium_topics 
												( 	topic_subject,
													topic_category, 
													topic_post, 
													topic_date, 
													topic_started, 
													topic_owner, 
													topic_parent, 
													topic_views,
													topic_approved,
													for_info,
													topic_group
												)
												VALUES ( %s, %d, %s, %s, %s, %d, %d, %d, %s, %s, %d )", 
												array(
													$topic->subject, 
													$new_forum_id,
													'nopost', 
													$topic->last_post,
													$topic->date, 
													$topic->starter, 
													0,
													0,
													'on',
													'',
													0
													) 
												) ) ) {
													
													// Set up topic, now add all the replies	
													$success_message .= "Migrated &quot;".$topic->subject."&quot; OK.<br />";	
													
													$new_topic_id = $wpdb->insert_id;
							
													$sql = "SELECT * FROM ".$wpdb->prefix."forum_posts WHERE parent_id = %d";
													$replies = $wpdb->get_results($wpdb->prepare($sql, $topic->id));
													
													if ($replies) {
														$success_message .= "Migrating replies to &quot;".$topic->subject."&quot;.<br />";	
													
														$failed_replies = 0;
														$done_first_reply = false;
														foreach ($replies AS $reply) {
															
															if ($done_first_reply) {
			
																if ( $wpdb->query( $wpdb->prepare( "
																INSERT INTO ".$wpdb->prefix."symposium_topics
																( 	topic_subject, 
																	topic_category,
																	topic_post, 
																	topic_date, 
																	topic_started, 
																	topic_owner, 
																	topic_parent, 
																	topic_views,
																	topic_approved,
																	topic_group,
																	topic_answer
																)
																VALUES ( %s, %d, %s, %s, %s, %d, %d, %d, %s, %d, %s )", 
																array(
																	'', 
																	$new_forum_id,
																	$reply->text, 
																	$reply->date,
																	$reply->date, 
																	$reply->author_id, 
																	$new_topic_id,
																	0,
																	'on',
																	0,
																	''
																	) 
																) ) ) {
																} else {
																	$failed_replies++;
																}
																
															} else {
																$done_first_reply = true;
																if ( $wpdb->query( $wpdb->prepare("UPDATE ".$wpdb->prefix."symposium_topics SET topic_post = '".$reply->text."' WHERE tid = %d", $new_topic_id) ) ) {
																	$success_message .= "Updated topic with intial post OK.<br />";
																} else {
																	$failed_replies++;
																}	
																
															}
															
														}
			
														if ($failed_replies == 0) {
								
															$success_message .= __("Replies migrated OK.", WPS_TEXT_DOMAIN)."<br />";
															
														} else {
															$success_message .= sprintf(__("Failed to migrate %d replies.", WPS_TEXT_DOMAIN), $failed_replies)."<br />";
															$success = false;
														}
			
													} else {
														$success_message .= __("No replies to migrate.", WPS_TEXT_DOMAIN)."<br />";
													}
																					
											} else {
												$failed++;
											}
											   
										}
										
										if ($failed == 0) {
				
											$success_message .= __("Topics and replies migrated OK.", WPS_TEXT_DOMAIN)."<br />";
											
										} else {
											$success_message .= sprintf(__("Failed to migrate %d topics.", WPS_TEXT_DOMAIN), $failed)."<br />";
											$success = false;
										}
									} else {
											$success_message .= __("No topics to migrate.", WPS_TEXT_DOMAIN)."<br />";
									}
									
								} else {
									$success_message .= __("Forum failed to migrate", WPS_TEXT_DOMAIN)."<br />";
									$success_message .= $wpdb->last_query."<br />";
									$success = false;
								}
									
									
							} else {
								$success_message .= __('Please enter a new forum category title', WPS_TEXT_DOMAIN);
							}
							
							if ($success) {
								echo "<div style='margin-top:10px;border:1px solid #060;background-color: #9f9; border-radius:5px;padding-left:8px; margin-bottom:10px;'>";
									echo 'Please now check the forum for your new migrated category. If you need to, you can move the position of the category (or delete it) in <a href="admin.php?page=symposium_categories">forum categories</a>.<br />';
									echo 'Migration complete. ';
									echo '<a href="javascript:void(0)" class="symposium_expand">View report</a>';
									echo '<div class="expand_this" style="display:none">';
										echo $success_message;
									echo "</div>";
								echo "</div>";
							} else {
								echo "<div style='margin-top:10px;border:1px solid #600;background-color: #f99; border-radius:5px;padding-left:8px; margin-bottom:10px;'>";
								echo $success_message;
								echo "</div>";
							}
							
						}
				
						// check to see if any Mingle forums exist
						if($wpdb->get_var("show tables like '%".$wpdb->prefix."forum_forums%'") == $wpdb->prefix."forum_forums") {
							$sql = "SELECT * FROM ".$wpdb->prefix."forum_forums";
							$forums = $wpdb->get_results($sql);
							if ($forums) {
								echo '<p>'.sprintf(__('If you have the Mingle v1.0.33 (or higher) plugin, you can migrate the forums to your %s forum as a new category.', WPS_TEXT_DOMAIN), WPS_WL).'</p>';
								echo '<p>'.__('This migration works with the <a href="" target="_blank">WordPress Mingle plugin</a>. If you are running a previous version of Mingle, you should upgrade your installation first.', WPS_TEXT_DOMAIN).'</p>';
								echo '<p>'.__('You should take a backup of your database before migrating, just in case there is a problem.', WPS_TEXT_DOMAIN).'</p>';
								echo '<form method="post" action="#mingle">';
								echo '<input type="hidden" name="symposium_mingle" value="Y">';
								echo __('Select forum to migrate:', WPS_TEXT_DOMAIN).' ';
								echo '<select name="mingle_forum">';
								foreach ($forums AS $forum) {
									echo '<option value="'.$forum->id.'">'.$forum->name.' ('.$forum->description.')</option>';
								}
								echo '</select><br />';
								echo __('Enter new forum category title:', WPS_TEXT_DOMAIN).' ';
								echo '<input type="text" name="mingle_category" />';
								echo '<p><em>' . __("Although your Mingle forum is not altered, and only new categories/topics/replies are added, it is recommended that you backup your database first.", WPS_TEXT_DOMAIN) . '</em></p>';
								echo '<p class="submit"><input type="submit" name="Submit" class="button-primary" value="'.__('Migrate Mingle', WPS_TEXT_DOMAIN).'" /></p>';
								echo '</form>';
							} else {
								echo '<p>'.__('No Mingle forums found', WPS_TEXT_DOMAIN).'.</p>';
							}
						} else {
								echo '<p>'.__('Mingle forum not installed', WPS_TEXT_DOMAIN).'.</p>';
						}
					echo '</td></tr></table>';
				
				echo '</div>'; 	
			
			}

	  	echo '</div>'; 	

	} // end admin check	
		
}