<?php
require_once '../includes/core.php';
require '../includes/connect.php';


$user_id = mysql_real_escape_string($_GET['userid']);

$result1 = mysql_query("SELECT * FROM users WHERE user_id = '$user_id' ");
$test1 = mysql_fetch_array($result1);

if (!$result1) 
		{
		die("Error: Data not found..");
		}
		
		$balance1  =$test1['balance']; 






$id =mysql_real_escape_string($_GET['id']);


$result = mysql_query("SELECT * FROM wallet WHERE id = '$id' ");
$test = mysql_fetch_array($result);

if (!$result) 
		{
		die("Error: Data not found..");
		}
		
		$amount  =$test['amount']; 




		 
		
		
		



if (loggedinadmin()){


$adminname = getfield1('name','admin','admin-id');
$admin_id = getfield1('admin-id','admin','admin-id');
$password = getfield1('password','admin','admin-id');

}else{ 
	header('Location:../loginexec.php');
}



?>





<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin  - Dashboard</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<link href="css/datepicker3.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">

<!--Icons-->
<script src="js/lumino.glyphs.js"></script>

<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->

</head>

<body>

    <?php include ('includes/header.php')  ?>

    <?php include ('includes/leftnav.php')  ?>
	
	
		
	<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main" style="margin-top: 20px">			
		<div class="row">
			<ol class="breadcrumb">
				<li><a href="#"><svg class="glyph stroked home"><use xlink:href="#stroked-home"></use></svg></a></li>
				<li class="active">home</li>
			</ol>
		</div><!--/.row-->
		
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header"></h1>
			</div>
		</div><!--/.row-->


		
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">Send Mail to all users</div>
					<div class="panel-body">
						<div class="col-md-6">

<form role="form" action="" method="POST">
							
								
																
							
								
								<div class="form-group">
									<label for="subject">Subject</label>

									<input type="text" name="subject" value="Enter Mail Subject" class="form-control">

									<label for="amount">Message</label>



									<textarea type="text" id="message" name="message" class="form-control">Message</textarea>


								</div>

								



								<button id="submit"  type="submit" class="btn btn-primary">Send Mails</button>
								
		
       
						</form>


					</div>
				</div>
			</div>
			</div>
			</div>




			<?php
					if (isset ($_POST['subject']) && isset ($_POST['message'])  )
					{
						$errors = array();
						
							$subject = mysql_real_escape_string($_POST['subject']);
							$message = mysql_real_escape_string($_POST['message']);

							
							
						
							

						if(!empty($message))
							{
								
								
								
									if(strlen($message) > 10000 ) {
										$errors[] = 'Message is too long';
									}

								}

									else
								{
									$errors[] = 'Please fill the form before submitting it!!!';
								}
							if(!empty($errors))
							{
								foreach($errors as $error) {
									
								echo 

								'<div class="alert bg-danger" role="alert">
					<svg class="glyph stroked success"><use xlink:href="#stroked-success"></use></svg>',$error, '  <a href="#" class="pull-right"><span class="glyphicon glyphicon-remove"></span></a>
				</div>'




								;
								
								}
							
							}

							else 		
								{
									
$query=mysql_query("SELECT email FROM users")or die(mysql_error());

while($row = mysql_fetch_array($query))
{
    $addresses[] = $row['email'];
    
}
$to = implode(", ", $addresses);
$headers = "From: info@solarmoney.com.ng\r\n";

mail($to, "$subject", "$message","$headers");



									
									$query1 = "INSERT INTO `message` (`subject`,`message`,`mdate`)VALUES('$subject','$message', NOW())";

									

								

									mysql_query($query1) or die(mysql_error());

echo '<script>
    setTimeout(function() {
        swal({
            title: "Congrats!",
            text: "Your Messages has been sent successfully to all Members",
            type: "success"
        }, function() {
            window.location.href = "sendmail.php";
        });
    }, 2000);
</script>';
									

								
								}		
					}

			
					
					


				?>
 
 





			
								
	
	</div>	<!--/.main-->

	<script src="js/jquery-1.11.1.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/sweetalert2@7.33.1/dist/sweetalert2.all.min.js"></script>
	<script src="js/chart.min.js"></script>
	<script src="js/chart-data.js"></script>
	<script src="js/easypiechart.js"></script>
	<script src="js/easypiechart-data.js"></script>
	<script src="js/bootstrap-datepicker.js"></script>
	<script>
		$('#calendar').datepicker({
		});

		!function ($) {
		    $(document).on("click","ul.nav li.parent > a > span.icon", function(){          
		        $(this).find('em:first').toggleClass("glyphicon-minus");      
		    }); 
		    $(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
		}(window.jQuery);

		$(window).on('resize', function () {
		  if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
		})
		$(window).on('resize', function () {
		  if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
		})
	</script>	
</body>

</html>
