<?php 

include('../classes/database.class.php');
/**
 * Created by PhpStorm.
 * User: brycemoral
 * Date: 6/27/16
 * Time: 1:29 PM
 */
$db = new database();


$symbols = "EUR_USD";
$bidprice = "1.11850";
$alert_symbol = str_replace('_', '', $symbols);


$getalerts = $db->db->prepare("SELECT * FROM invataTracker WHERE symbol = '$alert_symbol'");
$getalerts->execute();
$get_alerts = $getalerts->fetchAll();

if (!empty($get_alerts)) {
	# code...

	foreach ($get_alerts as $alts) {
		# code...

			$alert_price = $alts['price'];

			$converttofloat = floatval($bidprice);

			$alert_email = $alts['email'];

			if ($converttofloat == $alert_price) {
				# code...

				$alert_id = $alts['id'];

				$uid = $alts['user_id'];

				$getuser = $db->db->prepare("SELECT * FROM users WHERE uid = '$uid'");
				$getuser->execute();
				$userinfo = $getuser->fetch();

				$getphone = $userinfo['phone'];
				$userEmail = $userinfo['email'];


				$alertDate = date('d M Y');

				$alertTime = date('H:i');

				$headers = "MIME-Version: 1.0" . "\r\n";
				$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
				$headers .= 'From: Invata<invata.io>' . "\r\n";


				$message = '<!DOCTYPE html>
				<html>
				<head>
					<title></title>
				</head>
				<body>
					<div style="border:1px solid #eee;padding:20px;">
					<div style="padding-top: 40px;padding-bottom: 40px;text-align: center;">
						<img src="https://trading.invata.io/images/invatalogo.png" style="width: 100px;">
					</div>
					<div style="text-align:center;">
						<p style="font-size:20px;">Alert Triggered - <span style="font-weight:700;">'.$alert_symbol.'</span></p>
						<p style="font-size:20px;">Alert Price - <span style="font-weight:700;">'.$alert_price.'</span></p>
						<p style="font-size:20px;">Alert Date - <span style="font-weight:700;">'.$alertDate.'</span></p>
						<p style="font-size:20px;">Alert Time - <span style="font-weight:700;">'.$alertTime.'</span></p>
						<a href="https://trading.invata.io/dashboard.php" target="_blank" style="background-color: #181818;color: #fff;text-align: center;padding: 10px 40px;text-decoration: none;margin-top:10px;">Move To Dashboard</a>
					</div>

					</div>
				</body>
				</html>';


				mail($alert_email,"Invata Alert", $message, $headers);


				/*$delAlert = $db->db->prepare("DELETE FROM invataTracker WHERE id = '$alert_id'");

				if ($delAlert->execute()) {
					# code...
					echo "Deleted";
				}*/


			}

	}




}

?>