<div class="page-title">
    <h1><?php echo $this->user->lang("SQL Tool"); ?></h1>
    <p class="alert-content"><?php echo $this->user->lang("This tool allows you to query the database tables directly.  This is intended for experienced users who are familiar with SQL queries."); ?></p>
</div>

<div class="cm-holder settings-wrapper">
    <div class="sec-box">
<?php if ($this->parseDemoMode) { ?>
<div class="alert alert-danger">
  <?php echo $this->user->lang("This option does not work in demo mode"); ?>
</div>
<?php } ?>

<?php foreach ($this->parseExecutedQuery as $parseExecutedQuery) { ?>
<div class="card mb-3">
  <div class="card-body">
    <p class="fw-bold mb-1"><?php echo $this->user->lang("Query Run"); ?>:</p>
    <pre class="mb-0"><?php echo $this->escape($parseExecutedQuery['queryRun']) ?></pre>
  </div>
</div>

<?php if ($parseExecutedQuery['parseQueryFailed']) { ?>
<div class="alert alert-danger">
  <?php echo $this->user->lang("Query Failed"); ?>: <?php echo $parseExecutedQuery['failedError']; ?>
</div>
<?php } ?>

<?php if ($parseExecutedQuery['parseQueryResultStatus']) { ?>
<div class="alert alert-info">
  <?php echo $this->user->lang("Query Result"); ?>: <?php echo $parseExecutedQuery['queryStatus']; ?>
</div>
<?php } ?>

<?php if ($parseExecutedQuery['parseQueryResult']) { ?>
<div class="table-responsive mb-3">
  <table class="table table-bordered table-striped table-sm">
    <thead class="table-light">
      <tr>
        <?php foreach ($parseExecutedQuery['parseQueryResultHeader'] as $columnHeader) { ?>
        <th><?php echo $columnHeader; ?></th>
        <?php } ?>
      </tr>
    </thead>
    <tbody>
      <?php foreach ($parseExecutedQuery['parseQueryResultRow'] as $parseQueryResultRowData) { ?>
      <tr class="<?php echo $parseQueryResultRowData['rowClass']; ?>">
        <?php foreach ($parseQueryResultRowData['parseQueryResultRowData'] as $rowData) { ?>
        <td><?php echo $this->escape($rowData) ?></td>
        <?php } ?>
      </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
<?php } ?>
<?php } ?>

<form method="post" id="submitQueryForm"
      action="index.php?fuse=admin&amp;action=showdatabaseoptions&amp;controller=index">

  <div class="mb-3">
    <label for="sqlQueries" class="form-label">
      <?php echo $this->user->lang("SQL Query"); ?>:
    </label>
    <div class="form-text">
      <?php echo $this->user->lang("Enter the SQL queries in the text area. Each SQL query must end with a semi-colon."); ?>
    </div>
    <textarea id="sqlQueries" name="sqlQueries" class="form-control" rows="15"><?php echo $this->sqlQuery ?></textarea>
  </div>

  <button id="submitQueryButton" type="submit" class="btn btn-primary">
    <?php echo $this->user->lang("Submit Query"); ?>
  </button>
</form>

<script data-cfasync="false" type="text/javascript">
  $(document).ready(function() {
    $('#submitQueryButton').click(function(e) {
      e.preventDefault();
      $('#submitQueryForm').submit();
    });
  });
</script>



    </div>
</div>