<?php
    ob_start();
    require("db.php");
    $quoteId = $_GET['quoteid'];
?>
<!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 :: The biggest collection of money quotes on the planet</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>
      
      <?php 

        if (($quoteId == ".php") || ($quoteId == "noQuoteId")) { ?>
            
            <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>
              <h1 class="display-5 fw-bold"></h1>
              <div class="col-lg-6 mx-auto">
                <p class="lead mb-4">That quote was not found in the database.</p>
              </div>
            </div>
            
        <?php } else {
            $quote = getQuoteByQuoteId($conn,$quoteId);
            $quoterow = $quote->fetchAll();
      ?>

            <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>
            <?php foreach($quoterow as $row) { ?>
                <?php 
                    $aAttr = getAuthorAttributesByAuthor($conn,$row['author']);
                    $displayLink = "";
                    while ($rowAttr = $aAttr->fetch()) { 
                        $displayLink = 'Site: <a href="'.$rowAttr['link'].'" target="_blank">'.$rowAttr['link_name'].'</a>';
                    }
                ?>
                
                  <h1 class="display-5 fw-bold"><?php echo $row['quote']; ?></h1>
                  <div class="col-lg-6 mx-auto">
                    <p class="lead mb-4">
                        -- <a href="/search?authorExact=<?php echo $row['author']; ?>"><?php echo $row['author']; ?></a> <span style="color: #000;" class="badge rounded-pill bg-light"><?php echo $displayLink; ?></span>
                    </p>
                  </div>
            <?php } ?>
            </div>
            
            <div class="row g-5">
                <div class="col-md-12 text-start">
                    <h2>Related quotes (<a class="goback" onclick="goBack()">Go back</a>)</h2>
                    <br />
                    <?php $relatedQuotes = getRelatedQuotesByQuote($conn,$row['quote']); ?> 
                    
                    <?php while ($row = $relatedQuotes->fetch())
                    { displayQuoteRow($row); }
                    ?>
                </div>
            </div>
    
        <?php } ?>

    <?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>
