#!/usr/bin/perl -w

# (c) CWZ, LLC

# End The Round

use strict;
use lib '.';
use Net::SMTP::SSL;
use CWZ;

my $subscribersRef = qDb_ar("SELECT email FROM Account WHERE subbed = 1");

# Iterate over the result set and send emails
foreach my $subscriber (@$subscribersRef) {
  my $email = $subscriber->{email};

my $sha = qDb_hr("SELECT SHA(email) AS enc, login FROM Account WHERE email = ?", $email);
my $enc = $sha->{enc};
my $login = $sha->{login};

# SMTP settings provided by Amazon SES
my $smtp_host = 'email-smtp.us-east-1.amazonaws.com';
my $smtp_port = 465;
my $smtp_username = 'AKIAWSVZAZU4RZLJZM6E';
my $smtp_password = 'BPuvCv4CrejV8P8C8plyWpnmKWMXguh5XIE1jI2AfAcu';

# Email details
my $to = $email;
my $from = 'Crypto Warz Team <support@crypto-warz.com>';
my $subject = 'Our First Trillionaire! September Crypto Warz Round Starts Now';
my $message = '<div style="width:100%;text-align:center;font-size:0px;">Win some real life crypto!</div>
		<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
		<html>
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
			<meta name="viewport" content="width=device-width, initial-scale=1">
		  	<meta http-equiv="X-UA-Compatible" content="IE=edge">
		  	<meta name="format-detection" content="telephone=no">
			<title>September Round Details</title>

		</head>
		<body bgcolor="#111;">
		<div align="center" style="background-color:#111;">


			<table id="email-header" width="660" align="center" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;background-color:#071e22;">
				<tr>
					<td>
						<table width="660" class="resp-full-table" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
							<tr>
								<td>
									<a href="https://crypto-warz.com?utm_source=subheader&utm_medium=email&utm_campaign=round-start"><img src="https://crypto-warz.com/images/email/header.jpg" alt="crypto warz banner" /></a>
								</td>
							</tr>
		                    </table>
					</td>

				</tr>
			</table>


		                    <!-- Begin Message -->
			<table id="content" width="570" align="center" style="background-color: #000418;padding:25px 45px;color: #fff;font-family: arial, sans-serif;font-size:16px;" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>
						<table width="570" class="resp-full-table" align="center" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="100%">
                                <h2 style="color:#fff">Round Begins September 2nd, 10AM EST</h2>
		                            <p style="color:#fff;margin:20px 0 10px;">We had our first trillionaire (nearly $14 trillion) in August. Setting the bar high for future rounds. Test yourself, break this record playing the market! The top 3 squads have been sent their prizes. You can check out the <a href="https://crypto-warz.com/cgi/hall-of-fame.cgi?start-date=August-2-2023&type=squads">Hall of Fame here</a></p>
                                    <img src="https://crypto-warz.com/images/email/august-hof.jpg" alt="top squads in august" />
		                            <p style="color:#fff;margin:20px 0 10px;">Log in today for the chance to win real crypto prizes. Prizes to be sent to wallets such as Metamask or Trust. The Founders of the top 3 global ranked squads win:</p>
          <ol style="color:#fff;">
            <li>First Place: $25</li>
            <li>Second Place: $15</li>
            <li>Third Place: $10</li>
          </ol>
                                    <a href="https://crypto-warz.com?utm_source=subimg&utm_medium=email&utm_campaign=round-start"><img src="https://www.crypto-warz.com/images/email/prize.jpg" width="400" height="325" alt="crypto prize" /></a>
                                    <h2 style="color:#fff">Recent Changes</h2>
                                    <p style="color:#fff"><strong>Avatars:</strong> Select an avatar at the beginning of the round.</p>
                                    <p style="color:#fff"><strong>Alliances:</strong> You may create or join an alliance. Join forces with other squads to look out for each other.</p>
                                    <p style="color:#fff"><strong>Top 25 Range:</strong> You may hit an enemy inside the top 25 ranks of your current location if you are also in the top 25.</p>
                                    <p style="color:#fff"><strong>Plus Mode:</strong> The first 5 days and last 5 days of the round will include one hour of Plus mode at 6PM EST. This means, you can attack anyone one or two positions below or above your rank regardless of value. Make some friends, you\'ll need it for this.</p>
                                    <p style="color:#fff"><strong>Retaliation:</strong> If a player has hit you, you are able to retaliate in the next 12 hours. Each hour that passes you lose a potential "out" on them.</p>
                                    <p style="color:#fff"><strong>Crypto Tracking:</strong> View crypto data and information inside the market page.</p>
                                    <p style="color:#fff">If you are looking for tutorials or need help logging in, join us on <a href="https://discord.gg/96pQdwfdky" style="color:#6dff5b">discord</a> or reply to this email for assistance!</p>

								</td>
							</tr>
						</table>
					</td>
				</tr>
		        <tr>
		        	<td>
		            <table style="width:100%;min-width:350px;color:#fff;" cellpadding="14" cellspacing="10">
						<tr style="background-color: #333;"><td style="width:25%"><strong>Username:</strong> </td><td>' . $login . '</td></tr>
		            </table>
		            </td>
		        </tr>
		        <tr>
		        	<td>
		                <a href="https://crypto-warz.com/?utm_source=subplay&utm_medium=email&utm_campaign=round-start" style="margin-top:20px;width: 100%;padding: 20px 0;display: block;background-color: #6dff5b;text-align: center;font-size: 24px;color: #111;text-decoration: none;font-weight: bold;text-transform: uppercase;">Play Now</a>
		            </td>
		        </tr>
		        <tr>
		        	<td style="text-align: center;padding-top: 50px;">
		                <h2>Learn More About Player Types</h2>
		                <p><a style="background-color: #0037ff;display: inline-block;width: 25%;margin: 5px;padding: 10px;text-align: center;color: #fff;text-decoration: none;" href="https://crypto-warz.com/guide/#investor">Investors</a> <a style="background-color: #008021;display: inline-block;width: 25%;margin: 5px;padding: 10px;text-align: center;color: #fff;text-decoration: none;" href="https://crypto-warz.com/guide/#influencer">Influencers</a> <a style="background-color: #830000;display: inline-block;width: 25%;margin: 5px;padding: 10px;text-align: center;color: #fff;text-decoration: none;" href="https://crypto-warz.com/guide/#doubter">Doubters</a></p>

		    <p><h2 style="margin-top: 50px;">Join the Community </h2></p><p><a href="https://discord.gg/96pQdwfdky"><img src="https://crypto-warz.com/images/email/discord-logo.jpg" alt="discord logo" width="200" height="55"></a></p>
		            </td>
		        </tr>
				</table>
				<table style="width:660px;background-color:#000;color:#fff;">
		        <tr>
		        	<td>
		        	<div style="padding:35px;text-align:center;font-size:12px;">Crypto Warz | Copyright 2023. All Rights Reserved.<br><br><a style="color:#6dff5b" href="https://crypto-warz.com/cgi/unsubscribe.cgi?pg=setting&action=0&token=' . $enc . '&email=' . $email . '">Unsubscribe</a></div>
		        	</td>
		        </tr>
			</table>
				<!-- End Message -->
		</div>
		</body>
		</html>';

		# Create the SMTP object
		my $smtp = Net::SMTP->new($smtp_host, Port => $smtp_port, SSL => 1, Debug => 1);

		# Authenticate
		$smtp->auth($smtp_username, $smtp_password) or die "Authentication failed: $!\n";

		# Compose and send the email
		$smtp->mail($from);
		$smtp->to($to);
		$smtp->data();
		$smtp->datasend("To: $to\n");
		$smtp->datasend("From: $from\n");
		$smtp->datasend("Subject: $subject\n");
		$smtp->datasend("Content-Type: text/html; charset=\"UTF-8\"\n");  # Set the content type to HTML
		$smtp->datasend("\n$message\n");
		$smtp->dataend();

		# Close the SMTP connection
		$smtp->quit;
  }
