Location: PHPKode > projects > SiteX > admin/user_mail.php
<?PHP
ob_start();
session_start();

include("../includes/globals.php.inc");
include("../includes/functions.php");
include("../lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("../lang/".$sxSetup['Language'].".php");
include("../themes/$THEME_FOLDER/config.php.inc");
if((!userEditor())AND(!userAdmin()))  loginError($sxLang['LoginRequired']);
if((userEditor())AND(!$sxSetup['EditorRightsUsersEmail']))  loginError($sxLang['LoginRequired']);

if($SendMail)
{
	$address_list2 = explode(", ", $address_list);
	foreach($address_list2 as $k)
		$address_list2[$k] = trim($address_list2[$k]);
	
	if($sxAddBlog)
	{
		$query = "INSERT INTO $DB_Journal (title, entry, userid, timestamp, year, month, day) VALUES ('$email_subject', '".nl2br($email_message)."', '$THIS_USER', '$NOW', '".date("Y")."', '".date("n")."', '".date("j")."')";
		$result = mysql_query($query, $Link) or queryError("21", mysql_error());
		writeRSSXML();
	}
	
	$email_subject = stripslashes($email_subject);
	$email_message = stripslashes($email_message);

	$sxEmailHeaders = 'From: ' . $from_name . ' <' . $from_email . '>' . "\r\n" ;
	if ($sxSetup['HTMLEmail']) {
	$sxEmailHeaders .= 'Content-Type: text/html; charset="' . $sxSetupCharset . '"';
	}
	for($i = 0; $i < count($address_list2); $i++)
		mail($address_list2[$i], $email_subject, $email_message, $sxEmailHeaders);
	
	$message = $sxLang['MessageUserMailSent'];
}

$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function changeState(object){
	if(object.checked == true){
		<?PHP
		$query = "SELECT * FROM $DB_Users_Types ORDER BY name";
		$result = mysql_query($query, $Link) or queryError("200", mysql_error());
		while($ROW = mysql_fetch_object($result))
		{
			echo "document.all['users_$ROW->id'].disabled = true;"."\n";
			echo "document.all['users_$ROW->id'].checked = false;"."\n";
		}
		?>
	}else{
		<?PHP
		$query = "SELECT * FROM $DB_Users_Types ORDER BY name";
		$result = mysql_query($query, $Link) or queryError("205", mysql_error());
		while($ROW = mysql_fetch_object($result))
		{
			echo "document.all['users_$ROW->id'].disabled = false;"."\n";
		}
		?>
	}
}

function submitIt(myForm)
{
	if(myForm.from_name.value == ""){
		alert("<?PHP echo $sxLang['UserJSEmailFromName'] ?>");
		myForm.from_name.select();
		return false;
	}
	if(myForm.from_email.value == ""){
		alert("<?PHP echo $sxLang['UserJSEmailFromAddress'] ?>");
		myForm.from_email.select();
		return false;
	}
	if(emailCheck(myForm.from_email.value) == false){
		myForm.from_email.select();
		return false;
	}
}
function emailCheck (emailStr) {

	// Adapted from V1.1.3: Sandeep V. Tamhankar (hide@address.com)

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		alert("<?PHP echo $sxLang['UserJSEmail11']; ?>");
		return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("<?PHP echo $sxLang['UserJSEmail12']; ?>");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("<?PHP echo $sxLang['UserJSEmail13']; ?>");
			return false;
	   }
	}
	
	if (user.match(userPat)==null) {
		alert("<?PHP echo $sxLang['UserJSEmail14']; ?>");
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("<?PHP echo $sxLang['UserJSEmail15']; ?>");
				return false;
	   		}
		}
		return true;
	}
	
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("<?PHP echo $sxLang['UserJSEmail16']; ?>");
			return false;
	   }
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("<?PHP echo $sxLang['UserJSEmail17']; ?>");
		return false;
	}
	
	if (len<2) {
		alert("<?PHP echo $sxLang['UserJSEmail18']; ?>");
		return false;
	}
	
	return true;
}
//-->
</script>

<!-- // tinyMCE editor for html emails -->
<script type="text/javascript" src="../includes/tinymce/tiny_mce.js"></script>
<script type="text/javascript">
<!--
	tinyMCE.init({
		// General options
		mode : "textareas",
		editor_selector : 'mceEditor',
		language : "<?PHP echo $sxSetupTinyMCELanguage; ?>",
		theme : "advanced",
		relative_urls : false,
		convert_urls : false,
		plugins : "safari,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",

		// Theme options
		theme_advanced_buttons1 : "fullscreen,|,undo,redo,|,bold,italic,underline,strikethrough,|,forecolor,backcolor,|,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,blockquote,|,link,unlink,anchor,image,cleanup,help,code",
		theme_advanced_buttons3 : "tablecontrols,|,removeformat,visualaid,visualchars,|,sub,sup,|,charmap,iespell,media,advhr,|,emotions",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		//content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "",
			staffid : ""
		}
	});

//-->
</script>

<div class="bodyWrapper">
   <h1 class="sxAdminHeading"><?PHP echo $sxLang['UserHeadingEmail']; ?></h1>
   <div class="sxAdminBreadcrumbs"><?PHP if(userAdmin()) { ?><a href="index.php"><?PHP echo $sxLang['AdminBreadcrumb']; ?><?PHP }?><?PHP if(userEditor()) { ?><a href="editor_index.php"><?PHP echo $sxLang['EditorBreadcrumb']; ?><?PHP }?></a> > <a href="user_manager.php"><?PHP echo $sxLang['UserHeadingManager']; ?></a> > <?PHP echo $sxLang['UserHeadingEmail']; ?></div>
   <?PHP echoMessage($message); ?>
	<form name="sxFormEmailUsers" action="<?PHP echo $PHP_SELF; ?>" method="post" onsubmit="return submitIt(this)">
	<table border="0" cellspacing="2" cellpadding="5">
	  <tr>
		<td class="sxTdItem"><?PHP echo $sxLang['UserItemFrom']; ?></td>
		<td colspan="2"><input type="text" name="from_name" id="from_name"  value="<?PHP if($from_name) echo $from_name; else echo $_SESSION['firstname'] . ' ' . $_SESSION['lastname']; ?>" /> 
		                <input type="text" name="from_email" id="from_email" value="<?PHP if($from_email) echo $from_email; else echo $_SESSION['email']; ?>" /></td>
	  </tr>
	  <tr>
		<td class="sxTdItem"><?PHP echo $sxLang['UserItemTo']; ?></td>
		<td>
		<input type="checkbox" name="users_all" value="1"<?PHP if($users_all) echo ' checked'; ?> onclick="changeState(this)" /><?PHP echo $sxLang['UserOptionAllUsers']; ?><br />
		<input type="checkbox" name="users_all_newsletter" value="1"<?PHP if($users_all_newsletter) echo ' checked'; ?> onclick="changeState(this)" /><?PHP echo $sxLang['UserOptionSubscribed']; ?><br />
		<hr size="1" noshade="noshade" />
		<?PHP
		$query = "SELECT * FROM $DB_Users_Types ORDER BY name";
		$result = mysql_query($query, $Link) or queryError("204", mysql_error());
		while($ROW = mysql_fetch_object($result))
		{
			echo '<input type="checkbox" name="users_' . $ROW->id . '"';
			$temp_var = "users_".$ROW->id;
			if($$temp_var)
				echo ' checked';
			echo ' value="1" />' . $ROW->name . '<br />'."\n";
		}
		?>
		</select>
		<td valign="bottom" align="right"><input type="submit" name="update" value="<?PHP echo $sxLang['UserButtonUpdateAddresses']; ?>" class="sxButton" /></td>
	  </tr>
	  <tr>
		<td>&nbsp;</td>
		<td colspan="2">
		<textarea name="address_list" style="width:450px;height:200px;"><?PHP
		
		if($users_all)
		{
			$first = true;
			$query = "SELECT * FROM $DB_Users ORDER BY email";
			$result = mysql_query($query, $Link) or queryError("201", mysql_error());
			while($ROW = mysql_fetch_object($result))
			{
				if((!$first)AND($ROW->email))
					echo ', ';
				if($ROW->email)
				{
					echo $ROW->email;
					$first = false;
				}
			}
		}
		elseif($users_all_newsletter)
		{
			$first = true;
			$query = "SELECT * FROM $DB_Users WHERE newsletter='1' AND active='1' ORDER BY email";
			$result = mysql_query($query, $Link) or queryError("201", mysql_error());
			while($ROW = mysql_fetch_object($result))
			{
				if((!$first)AND($ROW->email))
					echo ', ';
				if($ROW->email)
				{
					echo $ROW->email;
					$first = false;
				}
			}
		}
		else
		{
			$counter = -1;
			$query = "SELECT * FROM $DB_Users_Types ORDER BY name";
			$result = mysql_query($query, $Link) or queryError("202", mysql_error());
			while($ROW = mysql_fetch_object($result))
			{
				$temp_var = "users_".$ROW->id;
				$temp_var2 = $$temp_var;
				
				if($temp_var2)
				{
					$query2 = "SELECT * FROM $DB_Users, $DB_Users_Assoc 
							   WHERE $DB_Users.id=$DB_Users_Assoc.userid AND
									 $DB_Users_Assoc.typeid=$ROW->id
							   ORDER BY $DB_Users.email";
					$result2 = mysql_query($query2, $Link) or queryError("203", mysql_error());
					while($ROW2 = mysql_fetch_object($result2))
					{
						$found = false;
						for($i = 0; $i < count($myAddresses); $i++)
						{
							if($myAddresses[$i] == $ROW2->email) $found = true;
						}
						if((!$found)AND($ROW2->email))
						{
							$counter = $counter + 1;
							$myAddresses[$counter] = $ROW2->email;
						}
					}
				}
			}
			$first = true;
			for($i = 0; $i < count($myAddresses); $i++)
			{
				if(!$first) echo ', ';
				echo $myAddresses[$i];
				$first = false;
			}
		}
	?></textarea></td>
	</tr>
	<tr>
	  <td class="sxTdItem"><?PHP echo $sxLang['UserItemSubject']; ?></td>
	  <td colspan="2"><input type="text" name="email_subject" style="width:450px;" <?PHP if($update) echo 'value="'.$email_subject.'"'; ?> /></td>
	</tr>
<?PHP	if($sxSetup['HTMLEmail']){ ?>
  <tr>
    <td class="sxTdItem"><?PHP echo $sxLang['UserItemMessage']; ?></td>
		<td colspan="2"><textarea class="mceEditor" name="email_message" style="width:450px;height:300px;"><?PHP if($update) echo $email_message; ?></textarea></td>
	</tr>
<?PHP } 
else
{ ?>   	
	<tr>
	  <td class="sxTdItem"><?PHP echo $sxLang['UserItemMessage']; ?></td>
	  <td colspan="2"><textarea name="email_message" style="width:450px;height:300px;"><?PHP if($update) echo $email_message; ?></textarea></td>
	</tr>	
	<tr>
	  <td class="sxTdItem"><?PHP echo $sxLang['UserItemAddTo']; ?> <?PHP echo getComponentName("1"); ?></td>
	  <td colspan="2"><input type="checkbox" name="sxAddBlog" value="1" /></td>
	</tr>
<?PHP } ?>
	<tr>
	  <td colspan="3" align="right"><input type="submit" name="SendMail" value="<?PHP echo $sxLang['UserButtonSendMail']; ?>" class="sxButton" /></td>
	</tr>
  </table>
</form>
</div>
<script language="JavaScript" type="text/JavaScript">
<!--
if(document.all['users_all'].checked == true){
	<?PHP
	$query = "SELECT * FROM $DB_Users_Types ORDER BY name";
	$result = mysql_query($query, $Link) or queryError("200", mysql_error());
	while($ROW = mysql_fetch_object($result))
	{
		echo "document.all['users_$ROW->id'].disabled = true;"."\n";
		echo "document.all['users_$ROW->id'].checked = false;"."\n";
	}
	?>
}
//-->
</script>
 <!-- background refresh -->
<iframe src ="../includes/session_keepalive.php?interval=<?PHP echo $sxThemeConfig['AdminKeepAlive']; ?>&bgcolor=<?PHP echo urlencode($sxThemeConfig['SiteBaseColor']); ?>" scrolling="no" height="1" marginheight="0" marginwidth="0" frameborder="0" align="right" width="1"></iframe>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX