<?php
// 9.php

// Database connection parameters
$servername = "localhost";
$username = "antenicenefather_anf";
$password = "363213119.363213119";
$dbname = "antenicenefather_anf";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// 1.) Locate all rows in the "longform" table where the "is_send" = 1 and the "gpt_response_8" is not null or blank
$sql = "UPDATE longform SET is_send = 2 WHERE is_send = 1 AND (gpt_response_8 IS NOT NULL AND gpt_response_8 != '')";

// 2.) Change all instances that match the conditions above to be "is_send" = 2
if ($conn->query($sql) === TRUE) {
    echo "Records updated successfully";
} else {
    echo "Error updating records: " . $conn->error;
}

$conn->close();
?>

<!-- HTML Code for Bootstrap Modal -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

<script>
$(document).ready(function() {
    // Show modal on page load
    $(".modal").modal('show');
    
    // Refresh the page when the 'Continue' button is clicked
    $(".btn-primary").click(function() {
        location.reload();
    });
});
</script>

<div class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Content Complete</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Your Longform Content has been completed. </p>
      </div>
      <div class="modal-footer">
       
        <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
