Facebook
From cflpigskin, 2 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 162
  1. <?php
  2. include 'headerMain.php';
  3. ?>
  4. <style>
  5. @import url('https://fonts.googleapis.com/css?family=Ewert&display=swap');
  6. #theMagicNumber{
  7.         font-family: 'Ewert', cursive;
  8.         font-size: 40px;
  9.         color: maroon;
  10. }
  11. </style>
  12. <div id="main">
  13.  
  14. <?php
  15. require('dbConnect.php');
  16. $sql = 'SELECT * from homepage where line = 1';
  17.  
  18. if($result = mysqli_query($conn, $sql)){
  19.       if(mysqli_num_rows($result) > 0){
  20.                         while($row = mysqli_fetch_array($result)){
  21.                                 $openclosed = $row['openclosed'];
  22.                         }
  23.       } else {
  24.          echo "Could not load settings.";
  25.       }
  26.    } else {
  27.       echo "ERROR: Was not able to execute: " . mysqli_error($conn);
  28.    }
  29. mysqli_close($conn);
  30.  
  31. if ($openclosed == "open"){
  32.         //check for year
  33.         $selectedYear = date("Y");
  34.         //call the api
  35.         $jsonurl="https://api.cfl.ca/v1/games/2021?key=dRQCsdZJSxluvhh3cmPYaNKPxFry781k";
  36.         if (!$json = c($jsonurl)) {
  37.                   $error = error_get_last();
  38.                   //echo "HTTP request failed. Error was: " . $error['message'];
  39.                   echo "<h2>Connection to API failed - Please try again later.</h2>";
  40.         } else {
  41.                 $array = json_decode($json, true);
  42.  
  43.                 $picks = "";
  44.  
  45.                 //check for entry submit
  46.                 if (isset($_POST['sendEntry'])){
  47.                  if( isset( $_SESSION['captcha'] ) ) {
  48.                          
  49.                
  50.                  if ($_POST['captcha'] != $_SESSION['captcha']){
  51.                         echo "<h2>Robot check failed - Please try again later.</h2>";
  52.                         echo $_POST['captcha']." " . $_SESSION['captcha'];
  53.                  }else{
  54.                        
  55.                         require('dbConnect.php');
  56.                        
  57.                         $fullName = filter_var($_POST['fullName'], FILTER_SANITIZE_STRING);
  58.                         $city = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
  59.                         $phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING);
  60.                         $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  61.                         $tiebreaker = filter_var($_POST['tiebreaker'], FILTER_SANITIZE_STRING);
  62.                        
  63.                         foreach ($array["data"] as $data){
  64.                                 if ($data['event_type']['event_type_id'] == '1'){
  65.                                         $selected_radio = $_POST[$data["game_id"]];
  66.                                         $picks = $picks.",".$data["game_id"]."*".$selected_radio;
  67.                                 }
  68.                         }
  69.                                 //remove first "," from list
  70.                         $picks = substr($picks, 1);
  71.                         $sql = "INSERT INTO picks (pid,name,city,phone,email,picks,tiebreak, paid) VALUES(default,'".$fullName."','".$city."','".$phone."','".$email."','".$picks."','".$tiebreaker."','y')";
  72.                         if (mysqli_query($conn, $sql)) { //this line updates database
  73.                                 //make the picks look better in email
  74.                                 $picks = str_replace("," , "</td></tr><tr><td>" , $picks);
  75.                                 $picks = str_replace("*" , "</td><td>" , $picks);
  76.                                 $picks = '<table><tr><td>'.$picks;
  77.                                 $picks = $picks.'</table></td></tr>';
  78.                                 //send email to user and admin then got to success screen
  79.                                 $to = $email;
  80.                                 $subject = "CFL Pigskin Pickem 2021 Entry Recieved";
  81.                                 $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
  82. PLEASE SEND EMAIL TRANSFER TO [email protected]";
  83.                                 $headers = 'From: [email protected]' . "\r\n" .
  84.                                         'Reply-To: [email protected]' . "\r\n" .
  85.                                         'Content-type: text/html';
  86.                                 if (mail($to,$subject,$txt,$headers)){ //this sends to user with above details
  87.                                         $to = '[email protected]'; //admin email address
  88.                                         $subject = "CFL Pigskin Pickem 2020 - Entry for: ".$fullName;
  89.                                         $txt = "Name: ".$fullName."<br>City: ".$city."<br>Phone: ".$phone."<br>email: ".$email."<br>Picks: ".$picks."<br>Tiebreaker: ".$tiebreaker;
  90.                                         $headers = 'From: [email protected]' . "\r\n" .
  91.                                                 'Reply-To: [email protected]' . "\r\n" .
  92.                                                 'Content-type: text/html';
  93.                                        
  94.  
  95.                                         if (mail($to,$subject,$txt,$headers)){ //this sends to admin with above details
  96.                                                 header("Location: added.php?success=added_and_email_sent");
  97.                                         }else{
  98.                                                 header("Location: added.php?success=added_with_email_error");
  99.                                        
  100.                                         };
  101.                                        
  102.                                 }else{
  103.                                         header("Location: added.php?success=added_with_email_error");
  104.                                 };
  105.                                 //header('Location: added.php');
  106.                                
  107.                         } else {
  108.                                 header("Location: added.php?error=not_added");
  109.                         };
  110.                   }
  111.                  }else{
  112.                          echo "failed!!!!!!!";
  113.                  }
  114.                 };
  115.  
  116.  
  117.  
  118.                 //build the table
  119.                 echo '<div id="innerContent">';
  120.                 echo '<br><br><h1 id="topTitle">Thanks for playing! - Good luck</h1>';
  121.                 echo "<br>";
  122.                 echo '<h2>Please enter your details</h2>';
  123.                 echo '<form method = "post">';
  124.                 echo '<input name="fullName" type="text" autofocus required="required" placeholder="Full Name">';
  125.                 echo '<input name="city" type="text" required="required" placeholder="City">';
  126.                 echo '<input name="phone" type="tel" required="required" placeholder="Phone">';
  127.                 echo '<input name="email" type="email" required="required" placeholder="Email">';
  128.                 echo '<h2>Select your winners</h2>';
  129.                 echo "<table class='selectTable'>";
  130.                 echo "<tr><th>Game ID</th><th>Date Start</th><th>Away</th><th>Home</th><th>Venue</th></tr>";
  131.                 foreach ($array["data"] as $data){
  132.                        
  133.                         if ($data['event_type']['event_type_id'] == '1'){
  134.                                        
  135.  
  136.                                 echo "<tr><td>".$data["game_id"]."</td><td>".$data["date_start"]."</td>";
  137.                                 echo '<td class="mp'.$data["team_1"]["nickname"].'"><label class="container">';
  138.                                 //echo $data["team_1"]["nickname"];
  139.                                 echo '<input type="radio" required="required" name ="'.$data["game_id"].'" value="'.$data["team_1"]["nickname"].'">';
  140.                                 echo '<span class="checkmark"></span>';
  141.                                 echo '</label></td>';
  142.                                
  143.                                 echo '<td class="mp'.$data["team_2"]["nickname"].'"><label class="container">';
  144.                                 //echo $data["team_2"]["nickname"];
  145.                                 echo '<input type="radio" required="required" name ="'.$data["game_id"].'" value="'.$data["team_2"]["nickname"].'">';
  146.                                 echo '<span class="checkmark"></span>';
  147.                                 echo '</label></td>';  
  148.  
  149.                                        
  150.                                 echo "<td>".$data["venue"]["name"]."</td></tr>";
  151.                                
  152.  
  153.  
  154.                         }
  155.                 }
  156.                 echo "</table><br>";
  157.                 echo '<h2>Please pick a tiebreaker - the combined score of game #6196 Winnipeg @ Calgary</h2>';
  158.                 echo '<input name="tiebreaker" type="number" required="required" placeholder="Tiebreaker"><br><br>';
  159.                 $capture = mt_rand(1, 15);
  160.  
  161.                 $_SESSION['captcha'] = $capture;
  162.  
  163.                 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">';
  164.  
  165.                 echo '<input type="submit" value="Submit" name="sendEntry"></form><br><br><br>';
  166.                 echo '</div>';
  167.         }
  168. }else{
  169.                 echo '<br><br><h1 id="topTitle">Sorry - Picking is currently closed</h1>';
  170. }
  171. ?>
  172.  
  173. </div>
  174. <button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
  175.  
  176.  
  177. <script>
  178. // When the user scrolls down 20px from the top of the document, show the button
  179. window.onscroll = function() {scrollFunction()};
  180.  
  181. function scrollFunction() {
  182.   if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
  183.     document.getElementById("myBtn").style.display = "block";
  184.   } else {
  185.     document.getElementById("myBtn").style.display = "none";
  186.   }
  187. }
  188.  
  189. // When the user clicks on the button, scroll to the top of the document
  190. function topFunction() {
  191.   document.body.scrollTop = 0;
  192.   document.documentElement.scrollTop = 0;
  193. }
  194. </script>
  195.  
  196. <?php
  197. include 'footer.php';
  198. ?>
  199.