<?php
include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . TEMPLATE_DIR . '/header.php');
include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . '/Auth/nav.php');
?>
<div class="container">
  <div class="row">
    <div class="col-sm-8">
      <h1>VVT - Textvorlagen</h1>
    </div>
    <div class="col-sm-4">
      <p class="text-right"><a href="create.php"><button type="button" class="btn btn-success">Neue VVT - Textvorlage <i class="fa fa-plus" aria-hidden="true"></i></button></a></p>
    </div>
  </div>
  <table class="table table-striped">
    <thead>
      <tr>
        <th>Nr</th>
        <th>Frage</th>
        <th></th>
        <th></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <?php
      foreach ($rows as $row) {
        
        $usedTexts                = $vvt->getNonusedVvtVorlagen($row['id']);
        $amountKunden             = $vvt->getAmountKunden();
        if ($usedTexts            == $amountKunden) {
          $showUsedTexts          = '<font color="#00AB34" size="+1"><i class="fas fa-thumbs-up"></i> alle Kunden</font>';
        } else {
          $showUsedTexts          = '<a href="set-text-to-client.php?id=' . $row['id'] . '"><button type="button" class="btn btn-info">Text Kunden zuweisen</button></a>';
        }
         
      ?>
      <tr>
        <td><?php echo $row['id']; ?></td>
        <td><?php echo showHtmlEntities(str_replace(chr(10), '<br>', $row['name'])); ?></td>
        <td><a href="edit.php?id=<?php echo $row['id']; ?>"><button type="button" class="btn btn-warning"><i class="fas fa-edit"></i></button></td>
        <td><?php echo $showUsedTexts; ?></td>
        <td><a href="delete.php?id=<?php echo $row['id']; ?>" onClick="return secquest(this);"><button type="button" class="btn btn-danger"><i class="fas fa-trash"></i></button></a></td>
      </tr>
      <?php
      }
      ?>
    </tbody>
  </table>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<?php
include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . TEMPLATE_DIR . '/footer.php');
?>
<script>
function secquest(Formular)
{
  if(confirm("Vorlage löschen?")) {
    return true;
  } else {
    return false;
  }
}
</script>
</body>
</html>
