<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
include_once("adminfunctions.inc");

	if (isset($_POST['submit'])) {
		$halt = "no" ;
		if (($_POST["subject"] == "") || ($_POST["message"] == "")) {
			$halt = "yes" ;
			echo "Subject and/or Message not set" ;
		}
	
		
		if ($halt == "no") {
			switch($_POST["sendto"]) {
				case'activated':
					$db->query("SELECT email FROM member WHERE activationkey = '0'") ;	
				break;
				case'all':
					$db->query("SELECT email FROM member") ;	
				break;		
				case'noneact':
					$db->query("SELECT email FROM member WHERE activationkey <> '0'") ;	
				break;			
			}
			$mailadresses = array() ;	
			while ($res = $db->fetch()) {
				array_push($mailadresses, $res['email']) ;
			}
			$listadres = implode(',', $mailadresses) ;
			$mailheaders='';
			$mailheaders .= 'From: '.getSetting("default_from", $db).' <'.getSetting("contact_email", $db).'>' . "\r\n";
			$mailheaders .= 'Bcc: '.$listadres . "\r\n";
			mail(getSetting("contact_email", $db), $_POST["subject"], $_POST["message"], $mailheaders) ;
			unset($_POST);
			$x = count($mailadresses) ;
			
			$submitmsg =  "Mail Have been sent to $x of people" ;
		}
	}
?> 

<h2>Email all users</h2>


<div class="settings">

	<fieldset>
		<form action="" method="post" enctype="multipart/form-data">
		<table>
			<tr>
				<h3><?=$submitmsg?><h3>
			</tr>	
			<tr>
				<td>Send To:</td>
				<td>
					<select name="sendto" class="select">
						<option value="activated" selected>To all activated users</option>
						<option value="all">To all users</option>
						<option value="noneact" selected>To not activated users</option>
					</select>				
				</td>
			</tr>
			<tr>
				<td>Subject:</td>
				<td><input type="text" size="50" name="subject" value="<?= $_POST["subject"]?>"></td>
			</tr>
			<tr>
				<td>Message:</td>
				<td><textarea rows="10" name="message"><?= $_POST["message"]?></textarea></td>
			</tr>



			<tr>	
				<td><input class="submitbutton" type="submit" name="submit" value="Submit" /></td>
			</tr>
		</table>
		</form>

	</fieldset>
</div>	
