<?php
include 'headerMain.php';
?>
<style>
@import url('https://fonts.googleapis.com/css?family=Ewert&display=swap');
#theMagicNumber{
font-family: 'Ewert', cursive;
font-size: 40px;
color: maroon;
}
</style>
<div id="main">
<?php
require('dbConnect.php');
$sql = 'SELECT * from homepage where line = 1';
$openclosed = $row['openclosed'];
}
} else {
echo "Could not load settings.";
}
} else {
echo "ERROR: Was not able to execute: " . mysqli_error($conn);
}
if ($openclosed == "open"){
//check for year
$selectedYear = date("Y");
//call the api
$jsonurl="https://api.cfl.ca/v1/games/2021?key=dRQCsdZJSxluvhh3cmPYaNKPxFry781k";
if (!$json = c($jsonurl)) {
//echo "HTTP request failed. Error was: " . $error['message'];
echo "<h2>Connection to API failed - Please try again later.</h2>";
} else {
$picks = "";
//check for entry submit
if (isset($_POST['sendEntry'])){
if( isset( $_SESSION['captcha'] ) ) {
if ($_POST['captcha'] != $_SESSION['captcha']){
echo "<h2>Robot check failed - Please try again later.</h2>";
echo $_POST['captcha']." " . $_SESSION['captcha'];
}else{
require('dbConnect.php');
$fullName = filter_var($_POST['fullName'], FILTER_SANITIZE_STRING
);
$city = filter_var($_POST['city'], FILTER_SANITIZE_STRING
);
$phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING
);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL
);
$tiebreaker = filter_var($_POST['tiebreaker'], FILTER_SANITIZE_STRING
);
foreach ($array["data"] as $data){
if ($data['event_type']['event_type_id'] == '1'){
$selected_radio = $_POST[$data["game_id"]];
$picks = $picks.",".$data["game_id"]."*".$selected_radio;
}
}
//remove first "," from list
$sql = "INSERT INTO picks (pid,name,city,phone,email,picks,tiebreak, paid) VALUES(default,'".$fullName."','".$city."','".$phone."','".$email."','".$picks."','".$tiebreaker."','y')";
if (mysqli_query($conn, $sql)) { //this line updates database
//make the picks look better in email
$picks = str_replace("," , "</td></tr><tr><td>" , $picks);
$picks = '<table><tr><td>'.$picks;
$picks = $picks.'</table></td></tr>';
//send email to user and admin then got to success screen
$to = $email;
$subject = "CFL Pigskin Pickem 2021 Entry Recieved";
$txt = "Dear ".$fullName.", thank you for entering.<br><br>City: ".$city."<br>Phone: ".$phone."<br>email: ".$email."<br>Picks: ".$picks."<br>Tiebreaker: ".$tiebreaker."<br> UNLESS YOU MAKE OTHER ARRANGEMENTS TO PAY FOR PIG SKIN PICKEM
'Content-type: text/html';
if (mail($to,$subject,$txt,$headers)){ //this sends to user with above details
$subject = "CFL Pigskin Pickem 2020 - Entry for: ".$fullName;
$txt = "Name: ".$fullName."<br>City: ".$city."<br>Phone: ".$phone."<br>email: ".$email."<br>Picks: ".$picks."<br>Tiebreaker: ".$tiebreaker;
'Content-type: text/html';
if (mail($to,$subject,$txt,$headers)){ //this sends to admin with above details
header("Location: added.php?success=added_and_email_sent");
}else{
header("Location: added.php?success=added_with_email_error");
};
}else{
header("Location: added.php?success=added_with_email_error");
};
//header('Location: added.php');
} else {
header("Location: added.php?error=not_added");
};
}
}else{
echo "failed!!!!!!!";
}
};
//build the table
echo '<div id="innerContent">';
echo '<br><br><h1 id="topTitle">Thanks for playing! - Good luck</h1>';
echo "<br>";
echo '<h2>Please enter your details</h2>';
echo '<form method = "post">';
echo '<input name="fullName" type="text" autofocus required="required" placeholder="Full Name">';
echo '<input name="city" type="text" required="required" placeholder="City">';
echo '<input name="phone" type="tel" required="required" placeholder="Phone">';
echo '<input name="email" type="email" required="required" placeholder="Email">';
echo '<h2>Select your winners</h2>';
echo "<table class='selectTable'>";
echo "<tr><th>Game ID</th><th>Date Start</th><th>Away</th><th>Home</th><th>Venue</th></tr>";
foreach ($array["data"] as $data){
if ($data['event_type']['event_type_id'] == '1'){
echo "<tr><td>".$data["game_id"]."</td><td>".$data["date_start"]."</td>";
echo '<td class="mp'.$data["team_1"]["nickname"].'"><label class="container">';
//echo $data["team_1"]["nickname"];
echo '<input type="radio" required="required" name ="'.$data["game_id"].'" value="'.$data["team_1"]["nickname"].'">';
echo '<span class="checkmark"></span>';
echo '</label></td>';
echo '<td class="mp'.$data["team_2"]["nickname"].'"><label class="container">';
//echo $data["team_2"]["nickname"];
echo '<input type="radio" required="required" name ="'.$data["game_id"].'" value="'.$data["team_2"]["nickname"].'">';
echo '<span class="checkmark"></span>';
echo '</label></td>';
echo "<td>".$data["venue"]["name"]."</td></tr>";
}
}
echo "</table><br>";
echo '<h2>Please pick a tiebreaker - the combined score of game #6196 Winnipeg @ Calgary</h2>';
echo '<input name="tiebreaker" type="number" required="required" placeholder="Tiebreaker"><br><br>';
$_SESSION['captcha'] = $capture;
echo '<h2 id ="robot">Robot check - What number do you see?</h2><div id="theMagicNumber">'.$capture.'</div><br><input name="captcha" required="required" type ="number">';
echo '<input type="submit" value="Submit" name="sendEntry"></form><br><br><br>';
echo '</div>';
}
}else{
echo '<br><br><h1 id="topTitle">Sorry - Picking is currently closed</h1>';
}
?>
</div>
<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<script>
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
<?php
include 'footer.php';
?>