<?php
    ob_start();
    require("db.php");
    $page = $_GET['page'];
    
    if ($page == "") {
        header("Location: /");
    }
    
    $page = explode(".",$page);
    $page = $page[0]; 
    
    $getBest = getBestQuoteBySlug($conn,$page);
    if ($getBest->rowCount() == 0) {
        header("Location: /");
    }
    
    $data = $getBest->fetch();
    $runQuery = runBestQueryBySlug($conn,$data['query']);
?>
<!doctype html>
<html lang="en">
  <head>
      <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async src="https://www.googletagmanager.com/gtag/js?id=G-9H2PTTEBRQ"></script>
        <script>
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
        
          gtag('config', 'G-9H2PTTEBRQ');
        </script>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <title>Today's Money Quote :: <?php echo $data['title']; ?></title>

    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link href="/css/styles.css" rel="stylesheet">

    <!-- Favicons -->
<link rel="apple-touch-icon" href="/img/moneyquoteslogo.png" sizes="180x180">
<link rel="icon" href="/img/moneyquoteslogo.png" sizes="32x32" type="image/png">
<link rel="mask-icon" href="/img/favicons/safari-pinned-tab.svg" color="#7952b3">
<meta name="theme-color" content="#7952b3">

<style>
      .bd-placeholder-img {
        font-size: 1.125rem;
        text-anchor: middle;
        -webkit-user-select: none;
        -moz-user-select: none;
        user-select: none;
      }

      @media (min-width: 768px) {
        .bd-placeholder-img-lg {
          font-size: 3.5rem;
        }
      }
      
      .goback:hover {
          cursor: pointer;
      }
    </style>
    
    <script>

        function copyToClipboard(el) {
          /* Get the text field */
          var text = el.getAttribute("quote");
          //copyText.setSelectionRange(0, 99999); /* For mobile devices */
          var dummy = document.createElement("textarea");
          document.body.appendChild(dummy);
          dummy.value = text;
          dummy.select();
          document.execCommand("copy");
          document.body.removeChild(dummy);

          /* Copy the text inside the text field */
          //document.execCommand("copy");

          /* Alert the copied text */
          alert("Copied quote to your clipboard.");
        }
        
        function goBack() {
          window.history.back();
        }

    </script>

  </head>
  <body>

            <div class="container-fluid text-center">
            <div class="px-4 py-5 my-5">
            <a href="/"><img class="d-block mx-auto mb-4" src="/img/moneyquoteslogo.png" alt="Today's Money Quote" width="52" height="52"></a>
                <h3><?php echo $data['description']; ?></h3>
                This is the largest searchable money quote database on the Internet. <a href="/search">Click here</a> to search.
            </div>
            
            <div class="row g-5">
                <div class="col-md-12 text-start">
                    <h2><?php echo $data['title']; ?></h2>
                    <br />
                    
                    <?php while ($row = $runQuery->fetch())
                    { 
                        displayQuoteRow($row);
                    }
                    ?>
                </div>
            </div>

    <?php include("inc.footer.php"); ?>

</div> <br />

<script src="/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
  </body>
</html>
