function add_reply($tid, $reply_text, $uid=0, $replybyemail=false) {
		
		if ($tid != '') {

			global $wpdb, $current_user;

			// Defaults for current state of class
			$topic_approved = 'on';
			$group_id = 0;
			$answered = '';
			
			// User ID?
			if ($uid == 0) { $uid = $current_user->ID; }

			// Get category for this topic ID
			$cat_id = $wpdb->get_var($wpdb->prepare("SELECT topic_category from ".$wpdb->prefix."symposium_topics where tid = %d", $tid));
			
			// Don't allow HTML in subject if not using WYSIWYG editor
			if (get_option(WPS_OPTIONS_PREFIX.'_use_wysiwyg') != 'on') {
				$reply_text = str_replace("<", "&lt;", $reply_text);
				$reply_text = str_replace(">", "&gt;", $reply_text);
			}

			// Check for banned words
			$chatroom_banned = get_option(WPS_OPTIONS_PREFIX.'_chatroom_banned');
			if ($chatroom_banned != '') {
				$badwords = $pieces = explode(",", $chatroom_banned);

				 for($i=0;$i < sizeof($badwords);$i++){
				 	if (strpos(' '.$reply_text.' ', $badwords[$i])) {
					 	$reply_text=eregi_replace($badwords[$i], "***", $reply_text);
				 	}
				 }
			}
			
			// First check for potential duplicate
			$sql = "SELECT tid FROM ".$wpdb->prefix."symposium_topics WHERE topic_parent = %d AND topic_post = %s";
			$duplicate = $wpdb->get_var($wpdb->prepare($sql, $tid, $reply_text));
						
			if (!$duplicate) {

				if (	
					
						// Store new reply in post					
						$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(
				        	'', 
				        	$cat_id,
				        	$reply_text, 
				        	date("Y-m-d H:i:s"), 
							date("Y-m-d H:i:s"), 
							$uid, 
							$tid,
							0,
							$topic_approved,
							$group_id,
							$answered
				        	) 
				        ) )

				) {

					// get new topic id (or response) for return
					$new_id = $wpdb->insert_id;
					
					// Now send out emails as appropriate				
	
					// Get forum URL worked out
					$forum_url = __wps__get_url('forum');
					if (strpos($forum_url, '?') !== FALSE) {
						$q = "&";
					} else {
						$q = "?";
					}
				
					// Get group URL worked out
					if ($group_id > 0) {
						$forum_url = __wps__get_url('group');
						if (strpos($forum_url, '?') !== FALSE) {
							$q = "&gid=".$group_id."&";
						} else {
							$q = "?gid=".$group_id."&";
						}
					}
	
					// Email people who want to know and prepare body
					$owner_name = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM ".$wpdb->base_prefix."users WHERE ID = %d", $uid));
					$parent = $wpdb->get_var($wpdb->prepare("SELECT topic_subject FROM ".$wpdb->prefix."symposium_topics WHERE tid = %d", $tid));
					
					$body = "<span style='font-size:24px'>".$parent."</span><br /><br />";
					$body .= "<p>".$owner_name." ".__('replied', WPS_TEXT_DOMAIN)."...</p>";
					$body .= "<p>".$reply_text."</p>";
					$url = $forum_url.$q."cid=".$cat_id."&show=".$tid;
					$body .= "<p><a href='".$url."'>".$url."</a></p>";
					$body = str_replace(chr(13), "<br />", $body);
					$body = str_replace("\\r\\n", "<br />", $body);
					$body = str_replace("\\", "", $body);
				
					$email_list = '0,';
					if ($topic_approved == "on") {
				
				
						$query = $wpdb->get_results($wpdb->prepare("
							SELECT user_email, ID
							FROM ".$wpdb->base_prefix."users u 
							RIGHT JOIN ".$wpdb->prefix."symposium_subs ON ".$wpdb->prefix."symposium_subs.uid = u.ID 
							WHERE u.ID != %d AND tid = %d", $uid, $tid));
							
						if ($query) {						
							foreach ($query as $user) {	
				
								// Filter to allow further actions to take place
								apply_filters ('__wps__forum_newreply_filter', $user->ID, $uid, $owner_name, $url);
						
								// Keep track of who sent to so far
								$email_list .= $user->ID.',';

								// Check for Reply-By-Email						
								if ($replybyemail || function_exists('__wps__mailinglist')) { 
									$subject_add = ' #TID='.$tid.' ['.__('do not edit', WPS_TEXT_DOMAIN).']'; 
									$body = get_option(WPS_OPTIONS_PREFIX.'_mailinglist_prompt').'<br />'.get_option(WPS_OPTIONS_PREFIX.'_mailinglist_divider').'<br /><br />'.get_option(WPS_OPTIONS_PREFIX.'_mailinglist_divider_bottom').'<br /><br />'.'<br /><br />'.$body;
								} else {
									$subject_add = '';
								}

								// Send mail
								if (strpos(get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'), '[topic]') !== FALSE) {
									$subject = str_replace("[topic]", $parent, get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'));
								} else {
									$subject = get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply');
								}
								__wps__sendmail($user->user_email, $subject.$subject_add, $body);							
							}
						}						
				
						// Now send to everyone who wants to know about all new topics and replies
						$email_list .= '0';
						$sql = "SELECT ID,user_email FROM ".$wpdb->base_prefix."users u 
							WHERE ID != %d AND 
							ID NOT IN (".$email_list.")";
						$list = $wpdb->get_results($wpdb->prepare($sql, $current_user->ID));

						if ($list) {
							
							$list_array = array();
							foreach ($list as $item) {
				
								if (__wps__get_meta($item->ID, 'forum_all') == 'on') {
									$add = array (	
										'ID' => $item->ID,
										'user_email' => $item->user_email
									);						
									array_push($list_array, $add);
								}
								
							}
							$query = __wps__sub_val_sort($list_array, 'last_activity');	
							
						} else {
						
							$query = false;
							
						}	
										
						// Get list of permitted roles for this topic category
						$sql = "SELECT level FROM ".$wpdb->prefix."symposium_cats WHERE cid = %d";
						$level = $wpdb->get_var($wpdb->prepare($sql, $cat_id));
						$cat_roles = unserialize($level);					
				
						if ($query) {						
							foreach ($query as $user) {	
								
								// If a group and a member of the group, or not a group forum...
								if ($group_id == 0 || __wps__member_of($group_id) == "yes") {
				
								// Get role of recipient user
									$the_user = get_userdata( $user->ID );
									$capabilities = $the_user->{$wpdb->prefix . 'capabilities'};
				
									if ( !isset( $wp_roles ) )
										$wp_roles = new WP_Roles();
										
									$user_role = 'NONE';
									if ($capabilities) {
										foreach ( $wp_roles->role_names as $role => $name ) {
										
											if ( array_key_exists( $role, $capabilities ) )
												$user_role = $role;
										}				
									}
									
									// Check in this topics category level
									if (strpos(strtolower($cat_roles), 'everyone,') !== FALSE || strpos(strtolower($cat_roles), $user_role.',') !== FALSE) {	 
				
										// Filter to allow further actions to take place
										apply_filters ('__wps__forum_newreply_filter', $user->ID, $uid, $owner_name, $url);
				
										// Send mail
										if (strpos(get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'), '[topic]') !== FALSE) {
											$subject = str_replace("[topic]", $parent, get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'));
										} else {
											$subject = get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply');
										}
										__wps__sendmail($user->user_email, $subject, $body);							
										
									}
									
								}
							}
						}	
						
					} else {
						// Email admin if post needs approval
						$body = "<span style='font-size:24px; font-style:italic;'>".__("Moderation required for a reply", WPS_TEXT_DOMAIN)."</span><br /><br />".$body;
						__wps__sendmail(get_bloginfo('admin_email'), __('Moderation required for a reply', WPS_TEXT_DOMAIN), $body);
					}	
										
					return $new_id;
					
				} else {
					
					//__wps__sendmail(get_bloginfo('admin_email'), __('POP3 insert failed', WPS_TEXT_DOMAIN), 'Query:'.$wpdb->last_query);
					return false;
					
				}
				
			} else {
				
				//__wps__sendmail(get_bloginfo('admin_email'), __('POP3 insert failed', WPS_TEXT_DOMAIN), 'Duplicate skipped: '.$wpdb->last_query);
				return false;
				
			} // End duplicate check
			
			
		} else {
			
			//__wps__sendmail(get_bloginfo('admin_email'), __('POP3 insert failed', WPS_TEXT_DOMAIN), 'No tid passed');
			return false;
			
		}
		
	}
	}
	exit;
}

// Warning report
if ($action == "sendReport") {
	
	global $wpdb, $current_user;

	$r = 'OK';

	$code = $_POST['code'];
	$report_text = $_POST['report_text'];
	$url = $_POST['url'];

	__wps__sendmail(get_bloginfo('admin_email'), __('Warning Report', WPS_TEXT_DOMAIN), __('From', WPS_TEXT_DOMAIN).': '.$current_user->display_name.'<br /><br />'.$report_text.'<br /><br />URL: '.$url.'<br /><br />Ref: '.$code);							

	exit;	
}

// Add new page
if ($action == "add_new_page") {
	
	global $wpdb, $current_user;

	if (current_user_can('edit_pages')) {

		$r = 'OK';
	
		$shortcode = strip_tags($_POST['shortcode']);
		$name = $_POST['name'];
				$body .= $message;
				$body .= "</p>";
				$body .= "<p><em>";
				$body .= $current_user->display_name;
				$body .= "</em></p>";
				$body .= $previous;
			
				$body = str_replace(chr(13), "<br />", $body);
				$body = str_replace("\\r\\n", "<br />", $body);
				$body = str_replace("\\", "", $body);

				$mail_subject = get_option(WPS_OPTIONS_PREFIX.'_subject_mail_new');
				if (strpos($mail_subject, '[subject]') !== FALSE) {
					$mail_subject = str_replace("[subject]", $subject, $mail_subject);
				}
				if ( __wps__sendmail($recipient->user_email, $mail_subject, $body) ) {
					// email sent ok.
				} else {
					$return .= '<p><strong>'.__('There was a problem sending an email notification to', WPS_TEXT_DOMAIN).' '.$recipient->user_email.'.</strong></p>';
				}
			}

		}
		
		echo $return;
	}
}

// Get mail messages
if ($_POST['action'] == 'getBox') {
function __wps__notification_do_jobs($mode) {
	
	global $wpdb;
	$summary_email = __("Website Title", WPS_TEXT_DOMAIN).": ".get_bloginfo('name')."<br />";
	$summary_email .= __("Website URL", WPS_TEXT_DOMAIN).": ".get_bloginfo('wpurl')."<br />";
	$summary_email .= __("Admin Email", WPS_TEXT_DOMAIN).": ".get_bloginfo('admin_email')."<br />";
	$summary_email .= __("WordPress version", WPS_TEXT_DOMAIN).": ".get_bloginfo('version')."<br />";
	$summary_email .= sprintf(__("%s version", WPS_TEXT_DOMAIN), WPS_WL).": ".WPS_VER."<br />";
	$summary_email .= __("Daily Digest mode", WPS_TEXT_DOMAIN).": ".$mode."<br /><br />";
	$topics_count = 0;
	$user_count = 0;
	$success = "INCOMPLETE. ";
		

	$users_sent_to_success = '';
	$users_sent_to_failed = '';
				
	// ******************************************* Daily Digest ******************************************
	$send_summary = get_option(WPS_OPTIONS_PREFIX.'_send_summary');
	if ($send_summary == "on" || $mode == 'cron' || $mode == 'symposium_dailydigest_admin' || $mode == 'send_admin_summary_and_to_users') {
		
		// Calculate yesterday			
		$startTime = mktime(0, 0, 0, date('m'), date('d')-1, date('Y'));
		$endTime = mktime(23, 59, 59, date('m'), date('d')-1, date('Y'));
		
		// Get all new topics from previous period
		$topics_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$wpdb->prefix.'symposium_topics'." WHERE topic_parent = %d AND UNIX_TIMESTAMP(topic_date) >= ".$startTime." AND UNIX_TIMESTAMP(topic_date) <= ".$endTime, 0));

		if ($topics_count > 0 || $mode == 'symposium_dailydigest_admin') {

			// Get Forum URL 
			$forum_url = __wps__get_url('forum');
			// Decide on query suffix on whether a permalink or not
			if (strpos($forum_url, '?') !== FALSE) {
				$q = "&";
			} else {
				$q = "?";
			}

			$body = "";
			
			$categories = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix.'symposium_cats'." ORDER BY listorder"); 
			if ($categories) {
				foreach ($categories as $category) {
					
					$shown_category = false;
					$topics = $wpdb->get_results("
						SELECT tid, topic_subject, topic_parent, topic_post, topic_date, display_name, topic_category 
						FROM ".$wpdb->prefix.'symposium_topics'." INNER JOIN ".$wpdb->base_prefix.'users'." ON ".$wpdb->prefix.'symposium_topics'.".topic_owner = ".$wpdb->base_prefix.'users'.".ID 
						WHERE topic_parent = 0 AND topic_category = ".$category->cid." AND UNIX_TIMESTAMP(topic_date) >= ".$startTime." AND UNIX_TIMESTAMP(topic_date) <= ".$endTime." 
						ORDER BY tid"); 
					if ($topics) {
						if (!$shown_category) {
							$shown_category = true;
							$body .= "<h1>".stripslashes($category->title)."</h1>";
						}
						$body .= "<h2>".__('New Topics', WPS_TEXT_DOMAIN)."</h2>";
						$body .= "<ol>";
						foreach ($topics as $topic) {
							$body .= "<li><strong><a href='".$forum_url.$q."cid=".$category->cid."&show=".$topic->tid."'>".stripslashes($topic->topic_subject)."</a></strong>";
							$body .= " started by ".$topic->display_name.":<br />";																
							$body .= stripslashes($topic->topic_post);
							$body .= "</li>";
						}
						$body .= "</ol>";
					}

					$replies = $wpdb->get_results("
						SELECT tid, topic_subject, topic_parent, topic_post, topic_date, display_name, topic_category 
						FROM ".$wpdb->prefix.'symposium_topics'." INNER JOIN ".$wpdb->base_prefix.'users'." ON ".$wpdb->prefix.'symposium_topics'.".topic_owner = ".$wpdb->base_prefix.'users'.".ID 
						WHERE topic_parent > 0 AND topic_category = ".$category->cid." AND UNIX_TIMESTAMP(topic_date) >= ".$startTime." AND UNIX_TIMESTAMP(topic_date) <= ".$endTime."
						ORDER BY topic_parent, tid"); 
					if ($replies) {
						if (!$shown_category) {
							$shown_category = true;
							$body .= "<h1>".$category->title."</h1>";
						}
						$body .= "<h2>".__('Replies in', WPS_TEXT_DOMAIN)." ".$category->title."</h2>";
						$current_parent = '';
						foreach ($replies as $reply) {
							$parent = $wpdb->get_var($wpdb->prepare("SELECT topic_subject FROM ".$wpdb->prefix.'symposium_topics'." WHERE tid = %d", $reply->topic_parent));
							if ($parent != $current_parent) {
								$body .= "<h3>".$parent."</h3>";
								$current_parent = $parent;
							}
							$body .= "<em>".$reply->display_name." wrote:</em> ";
							$post = __wps__clean_html(stripslashes($reply->topic_post));							
							if (strlen($post) > 100) { $post = substr($post, 0, 100)."..."; }
							if (strpos($reply->topic_post, '<iframe src=\"http://www.youtube.com') !== FALSE)
								$post .= " (".__('video', WPS_TEXT_DOMAIN).")";
							$body .= $post;
							$body .= " <a href='".$forum_url.$q."cid=".$category->cid."&show=".$topic->tid."'>".__('View topic', WPS_TEXT_DOMAIN)."...</a>";
							$body .= "<br />";
							$body .= "<br />";
						}						
					}	
				}
			}
			
			$body .= "<p>".__("You can stop receiving these emails at", WPS_TEXT_DOMAIN)." <a href='".$forum_url."'>".$forum_url."</a>.</p>";
			
			// Send the mail
			if (($mode == 'cron' && get_option(WPS_OPTIONS_PREFIX.'_send_summary') == "on") || $mode == 'send_admin_summary_and_to_users') {
				// send to all users
				$users = $wpdb->get_results("SELECT DISTINCT user_email 
				FROM ".$wpdb->base_prefix.'users'." u 
				INNER JOIN ".$wpdb->base_prefix."usermeta m ON u.ID = m.user_id 
				WHERE meta_key = 'symposium_forum_digest' and m.meta_value = 'on'"); 
				
				if ($users) {
					foreach ($users as $user) {
						$user_count++;
						$email = $user->user_email;
						if(__wps__sendmail($email, __('Daily Forum Digest', WPS_TEXT_DOMAIN), $body)) {
							$users_sent_to_success .= $user->user_email.'<br />';
							update_option(WPS_OPTIONS_PREFIX."_notification_triggercount",get_option(WPS_OPTIONS_PREFIX."_notification_triggercount")+1);
						} else {
							$users_sent_to_failed .= $user->user_email.'<br />';
						}						
					}
				} else {
					$users_sent_to_success = __('No users have selected to receive the digest.', WPS_TEXT_DOMAIN).'<br />';
				}
			}
			if ($mode == 'symposium_dailydigest_admin') {
				// send to admin only
				if(__wps__sendmail(get_bloginfo('admin_email'), __('Daily Forum Digest (admin only)', WPS_TEXT_DOMAIN), $body)) {
					$users_sent_to_success .= get_bloginfo('admin_email').'<br />';
				} else {
					$users_sent_to_failed .= get_bloginfo('admin_email').'<br />';
				}										
			}

		}
	}
	
	// Send admin summary
	$summary_email .= __("Forum topic count for previous day (midnight to midnight)", WPS_TEXT_DOMAIN).": ".$topics_count."<br />";
	$summary_email .= __("Daily Digest sent count", WPS_TEXT_DOMAIN).": ".$user_count."<br /><br />";
	$summary_email .= "<b>".__("List of recipients sent to:", WPS_TEXT_DOMAIN)."</b><br />";
	if ($users_sent_to_success != '') {
	$summary_email .= $users_sent_to_success;
	} else {
		$summary_email .= 'None.';
	}
	$summary_email .= "<br /><br /><b>List of sent failures:</b><br />";
	if ($users_sent_to_failed != '') {
		$summary_email .= $users_sent_to_failed;
	} else {
		$summary_email .= 'None.';
	}
	$email = get_bloginfo('admin_email');
	if (__wps__sendmail($email, __('Daily Digest Summary Report', WPS_TEXT_DOMAIN), $summary_email)) {
		$success = "OK<br />(summary sent to ".get_bloginfo('admin_email').")<br />";
	} else {
		$success = "FAILED sending to ".get_bloginfo('admin_email').". ";
	}
	
	return $success;
	
}
Beispiel #5
0
function __wps__mail_menu() {

	global $wpdb, $current_user;

	// See if the user has posted forum settings
	if( isset($_POST[ 'symposium_update' ]) && $_POST[ 'symposium_update' ] == '__wps__mail_menu' ) {
		$mail_all = (isset($_POST[ 'mail_all' ])) ? $_POST[ 'mail_all' ] : '';
		
		// Update database
		update_option(WPS_OPTIONS_PREFIX.'_mail_all', $mail_all);

	}
	
	if ( isset($_POST['bulk_message']) ) {

		$cnt = 0;

		$subject = $_POST['bulk_subject'];
		$message =$_POST['bulk_message'];
		
		if ($subject == '' || $message == '') {
			echo "<div class='error'><p>".__('Please fill in the subject and message fields.', WPS_TEXT_DOMAIN).".</p></div>";
		} else {

			if (isset($_POST['roles'])) {
		   		$range = array_keys($_POST['roles']);
		   		$include_roles = '';
	   			foreach ($range as $key) {
					  $include_roles .= $_POST['roles'][$key].',';
		   		}
					$include_roles = str_replace('', ' ', $include_roles);
			} else {
				$include_roles = '';
			}

			// Chosen at least one WordPress role?
			if ($include_roles != '') {

		  	$url = __wps__get_url('mail');	
	
				$sql = "SELECT * FROM ".$wpdb->base_prefix."users";
				$members = $wpdb->get_results($sql);
			
				foreach ($members as $member) {

					// Get this member's WP role and check in permitted list
					$the_user = get_userdata( $member->ID );
					$capabilities = $the_user->{$wpdb->prefix . 'capabilities'};
		
					$user_role = 'NONE';
					if ( !isset( $wp_roles ) )
						$wp_roles = new WP_Roles();

					if ($capabilities) {
						foreach ( $wp_roles->role_names as $role => $name ) {
							if ( array_key_exists( $role, $capabilities ) ) {
								$user_role = str_replace(' ', '', $role);
							}
						}
					}
								
					// Check in this topics category level
					if (strpos(strtolower($include_roles), 'everyone,') !== FALSE || strpos(strtolower($include_roles), $user_role.',') !== FALSE) {	
				
						// Send mail
						if ( $rows_affected = $wpdb->prepare( $wpdb->insert( $wpdb->base_prefix . "symposium_mail", array( 
						'mail_from' => $current_user->ID, 
						'mail_to' => $member->ID, 
						'mail_sent' => date("Y-m-d H:i:s"), 
						'mail_subject' => $subject,
						'mail_message' => $message
						 ) ), '' ) ) {
					 		$cnt++;
				 		}
		
						$mail_id = $wpdb->insert_id;
				
						// Filter to allow further actions to take place
						apply_filters ('__wps__sendmessage_filter', $member->ID, $current_user->ID, $current_user->display_name, $mail_id);
			
						// Send real email if chosen
						if ( __wps__get_meta($member->ID, 'notify_new_messages') ) {
		
							$body = "<h1>".$subject."</h1>";
							$body .= "<p><a href='".$url.__wps__string_query($url)."mid=".$mail_id."'>".__("Go to Mail", WPS_TEXT_DOMAIN)."...</a></p>";
							$body .= "<p>";
							$body .= $message;
							$body .= "</p>";
							$body .= "<p><em>";
							$body .= $current_user->display_name;
							$body .= "</em></p>";
				
							$body = str_replace(chr(13), "<br />", $body);
							$body = str_replace("\\r\\n", "<br />", $body);
							$body = str_replace("\\", "", $body);
		
							// Send real email
							if (isset($_POST['bulk_email'])) {
								__wps__sendmail($member->user_email, __('New Mail Message', WPS_TEXT_DOMAIN), $body);
							}
						}
					}		
				}
			
				echo "<div class='updated'><p>";
				if (isset($_POST['bulk_email'])) {
					echo sprintf(__('Bulk message sent to %d members, and to their email addresses.', WPS_TEXT_DOMAIN), $cnt);
				} else {
					echo sprintf(__('Bulk message sent to %d members (but not to their email addresses).', WPS_TEXT_DOMAIN), $cnt);
				}
				echo "</p></div>";	
				$subject = '';
				$message = '';			
			} else {

				echo "<div class='error'><p>".__('Please choose at least one WordPress role.', WPS_TEXT_DOMAIN).".</p></div>";

			}
		}
	} else {
		$subject = '';
		$message = '';
	}

	// Get config data to show
	$mail_all = get_option(WPS_OPTIONS_PREFIX.'_mail_all');
	
  	echo '<div class="wrap">';
  	
	  	echo '<div id="icon-themes" class="icon32"><br /></div>';
	  	echo '<h2>'.sprintf(__('%s Options', WPS_TEXT_DOMAIN), WPS_WL).'</h2><br />';
	
		__wps__show_tabs_header('mail');
		?>
			
			<form method="post" action=""> 
			<input type="hidden" name="symposium_update" value="__wps__mail_menu">
	
			<table class="form-table __wps__admin_table"> 
			
			<tr><td colspan="2"><h2><?php _e('Options', WPS_TEXT_DOMAIN) ?></h2></td></tr>

			<tr valign="top"> 
			<td scope="row"><label for="mail_all"><?php echo __('Mail to all', WPS_TEXT_DOMAIN); ?></label></td>
			<td>
			<input type="checkbox" name="mail_all" id="mail_all" <?php if ($mail_all == "on") { echo "CHECKED"; } ?>/>
			<span class="description"><?php echo __('Allow mail to all members, even if not a friend?', WPS_TEXT_DOMAIN); ?></span></td> 
			</tr> 
															
			</table> 	
		 
			<p class="submit" style='margin-left:6px;'> 
			<input type="submit" name="Submit" class="button-primary" value="<?php echo __('Save Changes', WPS_TEXT_DOMAIN); ?>" /> 
			</p> 
			</form> 

		
		<?php
		echo '<div style="margin-left:10px">';
		echo '<h2>'.__('Send bulk mail', WPS_TEXT_DOMAIN).'</h2>';
		echo '<p>'.sprintf(__('Send a message from you (%s) to all members of this website - if running WordPress MultiSite, this means all members on your site network.', WPS_TEXT_DOMAIN), $current_user->display_name).'</p>';
		echo '<form method="post" action="">';
		echo '<strong>'.__('Subject', WPS_TEXT_DOMAIN).'</strong><br />';
		echo '<textarea name="bulk_subject" style="width:500px; height:23px; margin-bottom:15px; overflow:hidden;">'.$subject.'</textarea><br />';
		echo '<strong>'.__('Select WordPress roles to include', WPS_TEXT_DOMAIN).'</strong><br />';
	  echo '<div style="margin:10px">';
				// Get list of roles
				global $wp_roles;
				$all_roles = $wp_roles->roles;
				echo '<input type="checkbox" name="roles[]" value="everyone"> '.__('All users', WPS_TEXT_DOMAIN).'<br />';
				foreach ($all_roles as $role) {
					echo '<input type="checkbox" name="roles[]" value="'.$role['name'].'"';
					echo '> '.$role['name'].'<br />';
				}			
		echo '</div>';
		echo '<strong>'.__('Message', WPS_TEXT_DOMAIN).'</strong><br />';
		echo '<textarea name="bulk_message" style="width:500px; height:200px;">'.$message.'</textarea><br />';
		echo '<p><em>'.__('You can include HTML.', WPS_TEXT_DOMAIN).'</em></p>';
		echo '<input type="checkbox" name="bulk_email" CHECKED> '.__('Internal mail will be sent, but also send out email notifications?', WPS_TEXT_DOMAIN);
		echo '<br /><em>'.__('Be wary of limitations from your hosting provider. Members who do not want email notifications will not be sent one.', WPS_TEXT_DOMAIN).'</em><br /><br />';
		echo '<input type="submit" name="Submit" class="button-primary" value="'.__('Send', WPS_TEXT_DOMAIN).'" />';
		echo '</form></div>';

		?>
		<table style="margin-left:10px; margin-top:10px;">						
			<tr><td colspan="2"><h2>Shortcodes</h2></td></tr>
			<tr><td width="165px">[<?php echo WPS_SHORTCODE_PREFIX; ?>-mail]</td>
				<td><?php echo __('Display the mail page.', WPS_TEXT_DOMAIN); ?></td></tr>
		</table>
		
		<?php		
		
		__wps__show_tabs_header_end();

	echo '</div>';
	

}
		        ) );

			// Filter to allow further actions to take place
			apply_filters ('__wps__friendaccepted_filter', $friend_to, $current_user->ID, $current_user->display_name);		

			// send email
			$friend_to_email = $wpdb->get_var($wpdb->prepare("SELECT user_email FROM ".$wpdb->base_prefix."users WHERE ID = %d", $friend_to));
			
			$body = "<h1>".sprintf(__("%s request accepted", WPS_TEXT_DOMAIN), get_option(WPS_OPTIONS_PREFIX.'_alt_friend'))."</h1>";
			$body .= "<p>".sprintf(__("Your %s request to %s has been accepted", WPS_TEXT_DOMAIN), get_option(WPS_OPTIONS_PREFIX.'_alt_friend'), $current_user->display_name)."</p>";
			
			$profile_url = __wps__get_url('profile');
			$profile_url .= __wps__string_query($profile_url)."uid=".$current_user->ID."&view=friends";
			$body .= "<p>".__("Go to", WPS_TEXT_DOMAIN)." <a href='".$profile_url."'>".get_bloginfo('name')."</a>...</p>";
			
			__wps__sendmail($friend_to_email, sprintf(__("%s request accepted", WPS_TEXT_DOMAIN), get_option(WPS_OPTIONS_PREFIX.'_alt_friend')), $body);
			
			// Tell friends
			if (!get_option(WPS_OPTIONS_PREFIX.'_wps_lite') && __wps__is_plus()) {
				$userdata = get_userdata($friend_to);
				$profile_url = __wps__get_url('profile');
				$profile_url .= __wps__string_query($profile_url);
				$post = __('Has made friends with', WPS_TEXT_DOMAIN).' <a href="'.$profile_url."uid=".$current_user->ID.'">'.$current_user->display_name.'</a>';
				$post = '<br /><div style="float:left;">'.get_avatar($current_user->ID, 32).'</div>'.$post;
				__wps__add_activity_comment($friend_to, $userdata->display_name, $friend_to, $post, 'friend');
			}

			// Hook for further actions
			do_action('symposium_friend_request_accepted_hook', $friend_to, $current_user->ID);	
			
		}
		if (WPS_DEBUG) echo $wpdb->last_query;			

		// Email the event owner that the event has been booked
		$sql = "SELECT * FROM ".$wpdb->base_prefix."symposium_events WHERE eid = %d";
		$event = $wpdb->get_row( $wpdb->prepare($sql, $eid) );
		if (WPS_DEBUG) echo '<p>'.$wpdb->last_query.'</p>';
		$sql = "SELECT user_email FROM ".$wpdb->base_prefix."users WHERE ID = %d";
		$event_owner_email = $wpdb->get_var( $wpdb->prepare($sql, $event->event_owner) );
		if (WPS_DEBUG) echo '<p>'.$wpdb->last_query.'</p>';
	
		// Inform the organiser
		$msg = '<p>'.$current_user->display_name.sprintf(__(' has booked %d ticket(s) for event (%s) ID:', WPS_TEXT_DOMAIN), $howmany, stripslashes($event->event_name)).$eid.'<br />';
		$msg .= __('If payment is required, please follow this up.', WPS_TEXT_DOMAIN).'</p>';
		$subject = sprintf(__('Attendee booking for Event (%s) ID:', WPS_TEXT_DOMAIN), $event->event_name).$eid;
		__wps__sendmail($event_owner_email, $subject, $msg);
		if (WPS_DEBUG) echo '<p>'.$subject.'<br />'.$event_owner_email.'<br />'.$msg.'</p>';
	
		if (!$event->event_confirmation && $event->event_send_email) {
			// Send confirmation email
			$from_email = trim(get_option(WPS_OPTIONS_PREFIX.'_from_email'));
			$from_name = html_entity_decode(trim(stripslashes(get_bloginfo('name'))), ENT_QUOTES, 'UTF-8');
			$crlf = PHP_EOL;
			$headers = "MIME-Version: 1.0" . $crlf;
			$headers .= "Content-type:text/html;charset=utf-8" . $crlf;
			$headers .= "From: " . $from_name . " <" . $from_email . ">" . $crlf;
			$event_email = __wps__events_confirm_email_fields($event->event_email, $eid, $new_bid, $current_user->ID);
			
			if (wp_mail($current_user->user_email, __('Booking confirmation', WPS_TEXT_DOMAIN), $event_email, $headers)) {
				$wpdb->query( $wpdb->prepare( "UPDATE ".$wpdb->base_prefix."symposium_events_bookings SET 
					email_sent = %s
	function sendmail($compose_recipient_id) {

		global $wpdb, $current_user;
		
		if (is_user_logged_in()) {
	
			$recipient = $wpdb->get_row("SELECT * FROM ".$wpdb->base_prefix."users WHERE ID = '".$compose_recipient_id."'");
			if (!$recipient) {
				$return = false;
			} else {

				// subject and message from wps_ui elements
				$subject = $_POST['wps-mail-subject'];
				$message = $_POST['wps-mail-message'];
				
				// Do some magic to the message
				$message = str_replace(chr(13), "<br />", $message);

				// Send mail
				if ( $rows_affected = $wpdb->prepare( $wpdb->insert( $wpdb->base_prefix . "symposium_mail", array( 
				'mail_from' => $current_user->ID, 
				'mail_to' => $recipient->ID, 
				'mail_sent' => date("Y-m-d H:i:s"), 
				'mail_subject' => $subject,
				'mail_message' => $message
				 ) ) ) ) {
					$return = true;
				 } else {
					$return = false;
				 }
	
				$mail_id = $wpdb->insert_id;
				// Filter to allow further actions to take place
				apply_filters ('__wps__sendmessage_filter', $recipient->ID, $current_user->ID, $current_user->display_name, $mail_id);
			
				// Send real email if chosen
				if ( __wps__get_meta($recipient->ID, 'notify_new_messages') ) {
	
					$url = __wps__get_url('mail');
	
					$body = "<h1>".$subject."</h1>";
					$body .= "<p><a href='".$url.__wps__string_query($url)."mid=".$mail_id."'>".sprintf(__("Go to %s Mail", WPS_TEXT_DOMAIN), __wps__get_url('mail'))."...</a></p>";
					$body .= "<p>";
					$body .= $message;
					$body .= "</p>";
					$body .= "<p><em>";
					$body .= $current_user->display_name;
					$body .= "</em></p>";
					$body .= $previous;
				
					$body = str_replace(chr(13), "<br />", $body);
					$body = str_replace("\\r\\n", "<br />", $body);
					$body = str_replace("\\", "", $body);
	
					$mail_subject = get_option(WPS_OPTIONS_PREFIX.'_subject_mail_new');
					if (strpos($mail_subject, '[subject]') !== FALSE) {
						$mail_subject = str_replace("[subject]", $subject, $mail_subject);
					}
					if ( __wps__sendmail($recipient->user_email, $mail_subject, $body) ) {
						$return = true;
					} else {
						$return = false;
					}
				}
	
			}
			
		} else {
			$return = false; // not logged in
		}

		return $return;

	}
									$subject = str_replace("[topic]", $parent, get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply'));
								} else {
									$subject = get_option(WPS_OPTIONS_PREFIX.'_subject_forum_reply');
								}
								__wps__sendmail($user_email, $subject.$subject_add, $body);							
								
							}
							
						}
					}
				}	
			}
		} else {
			// Email admin if post needs approval
			$body = "<span style='font-size:24px; font-style:italic;'>".__("Moderation required for a reply", WPS_TEXT_DOMAIN)."</span><br /><br />".$body;
			__wps__sendmail(get_bloginfo('admin_email'), __('Moderation required for a reply', WPS_TEXT_DOMAIN), $body);
		}		
		
	} else {
		
		echo 'NOT LOGGED IN';
		exit;
		
	}
}
	
// AJAX to fetch forum activity
if ($_POST['action'] == 'getActivity') {

	// Work out link to this page, dealing with permalinks or not
	$thispage = __wps__get_url('forum');
function __wps__inform_members($group_name, $gid, $new_member_emails) {
	
	
	global $wpdb, $current_user;

	$html = '';
	
	// First check that this group tells about new members
	if ($new_member_emails == 'on') {
		
		$body = "<h1>".stripslashes($group_name)."</h1>";
		$body .= '<p>'.__("New group member", WPS_TEXT_DOMAIN).': '.$current_user->display_name.'</p>';
	
		$url = __wps__get_url('group');
		$url .= __wps__string_query($url);
		$url .= "gid=".$gid;
		
		$body .= '<p><a href="'.$url.'">'.$url.'</a></p>';
		
	    $sql = "SELECT u.user_email 
				FROM ".$wpdb->base_prefix."users u 
				LEFT JOIN ".$wpdb->prefix."symposium_group_members m ON u.ID = m.member_id 
				WHERE m.group_id = %d";
				
		$recipients = $wpdb->get_results($wpdb->prepare($sql, $gid));	
	
		foreach ($recipients AS $recipient) {
			if (__wps__sendmail($recipient->user_email, __('New group member', WPS_TEXT_DOMAIN), $body)) {
				//$html .= 'Sent to '.$recipient->user_email.' ';
			} else {
				$html .= 'Failed to send email to '.$recipient->user_email.'<br />';
			}
		}

	} else {
		//$html .= 'Not sending emails for this group!';
	}
	
	return $html;
	
}
				if ($author->comment_parent == 0) {
					$type = 'post';
					$goto = $cid;
				} else {
					$type = 'reply';
					$goto = $author->comment_parent;
				}
				
				$body = "<p>".$current_user->display_name." ".sprintf(__('%s your %s', WPS_TEXT_DOMAIN), $verb, $type).":</p>";
				$comment = $author->comment;
				if ($author->type == 'gallery' && strpos($comment, "[]")) {
					$comment = substr($comment, 0, strpos($comment, "[]")); // strip off images
				}
				$body .= "<p>".$comment."</p>";
				$body .= "<p><a href='".__wps__get_url('profile')."?uid=".$author->author_uid."&post=".$goto."'>".__('Go to the post', WPS_TEXT_DOMAIN)."...</a></p>";
				__wps__sendmail($recipient->user_email, $current_user->display_name." ".sprintf(__('%s your %s', WPS_TEXT_DOMAIN), $verb, $type), $body);
				
				//echo $current_user->display_name." ".sprintf(__('%s your %s', WPS_TEXT_DOMAIN), $verb, $type);

			}
			
		}	
			
		echo 'OK';
		
	} else {
		
		echo "NOT LOGGED IN";
		
	}