<?php 
include 'check.php';
include '../db.inc.php';
include 'check_msg.php';
$number=$_GET['user'];

if(isset($_POST['submit'])) {
	$subject=addslashes($_POST['subject']);
	$message=addslashes($_POST['message']);
	
	if(strlen($subject) == 0 || strlen($message) == 0) {
		$error_msg="<font color=red>Required field is blank</font>";
	}
	else {
		if(!mysqli_query($connectionString,"INSERT INTO `alerts` (`number` ,`date` ,`subject` ,`message` ,`status`)VALUES ( '$number', NOW( ) , '$subject', '$message', '0')")) {
      echo("Error description: " . mysqli_error($connectionString));exit;
    }

$user=mysqli_fetch_array(mysqli_query($connectionString,"SELECT * FROM users WHERE $number=number LIMIT 1"),MYSQLI_ASSOC);

             $recipient=$user['email'];
		$mob_tel=$user['phone'];
		$first_name=$user['firstname'];
		$last_name=$user['lastname'];
                date_default_timezone_set("Europe/Gateshead");

                $time = date("h:i:sa");

                $date = date('d/m/Y');
                $senderName = "AnB Credit Union";

$fromEmailAddress = "no-reply-accountdept@anbcreditunion.com";

$emailSubject = "Message From Service Center";

$comments = "\n Hello $first_name $last_name \n \n The below message was sent to you from our service center. \n\n MESSAGE SUBJECT: $subject \n\n MESSAGE \n\n $message \n\n\n This message was sent on $date at exactly $time (GMT/UTC) \n\n To respond to this message, please log into your online account and click on the Alerts menu link. Once you are in the Alerts section, simply click on the message subject to read and reply to the message.  \n \n \n \n Best regards, \n Account Support Team \n For AnB Credit Union.";


mail($recipient, $emailSubject, $comments, "From: $senderName <$fromEmailAddress>\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 8bit");


		$error_msg="Alert Successfully Sent";
	}
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Administrator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="96%" height="421" border="0" cellspacing="5">
  <tr>
    <td width="14%" height="274" valign="top" style="border:#003399 1px solid;"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="21" bgcolor="#004500" class="headers">Navigation</td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="1">
          <tr>
            <td bgcolor="#E8FFF8"><p><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="./">Home</a></strong></font></p></td>
          </tr>
           <tr>
            <td bgcolor="#E8FFF8"><p><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="smssender.php">SMS 
              Sender</a></strong></font></p></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><p><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="add.php">Add 
              User</a></strong></font></p></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="addact.php">Add Activity </a></strong></font></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><a href="viewact.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>View Activities </strong></font></a></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><a href="messages.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>View Messages (<?php echo $umsg; ?>)</strong></font></a></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><a href="alerts.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>View Alerts</strong></font></a></td>
          </tr>
          <tr>
            <td bgcolor="#E8FFF8"><a href="sql.php"><font size="2" face="Arial, Helvetica, sans-serif"><strong>SQL</strong></font></a></td>
          </tr>
		  
          <tr>
            <td bgcolor="#E8FFF8"><font size="2" face="Arial, Helvetica, sans-serif"><strong><a href="logout.php">Log 
              Out</a></strong></font></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>      
      <p>&nbsp;</p>
    </td>
    <td width="86%" valign="top" style="border:#003399 1px solid;"><form name="form1" method="post" action="">
      <table width="100%" border="0">
	  <tr>
	  <td>&nbsp;</td><td><?php echo $error_msg; ?></td>
	  </tr>
        <tr>
          <td width="9%">Subject</td>
          <td width="91%"><input name="subject" type="text" id="subject" size="50" <?php if (isset($_GET['subject'])) { ?>value="RE: <?php echo $_GET['subject']; ?>"<?php }?>></td>
        </tr>
        <tr>
          <td valign="top">Message</td>
          <td><textarea name="message" cols="70" rows="20" id="message"></textarea></td>
        </tr>
        <tr>
          <td valign="top">&nbsp;</td>
          <td><input name="submit" type="submit" id="submit" value="Send"></td>
        </tr>
      </table>
    </form>
    </td>
  </tr>
</table>


</body>
</html>
