<?php
/**
 * Created by PhpStorm.
 * User: sunusi
 * Date: 2019-02-02
 * Time: 14:20
 */
if (isset($URL[1])) {
    $ack = $URL[1];
    if (!empty($ack)) {
        $acknowledge = '<div class="alert alert-success alert-dismissable">Your report has been successfully submitted.</div>';
    }
}
?>

<!-- Main Content -->
<div class="container">
  <div class="row">
    <div class="col-md-12">

      <div class="widget-area-2 proclinic-box-shadow">
        <h3 class="widget-title">Write a Report</h3>

        <div class="row justify-content-center">
          <div class="col-md-6">
            <table id="tableId" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th class="no-sort"></th>
                <th>Subject</th>
                <th>Phone</th>
                <th>Date</th>
                <th></th>

              </tr>
              </thead>
              <tbody>
              <?php
              $report = $query->getAll("
                    select udut_reports.*,
                           udut_users.*
                    from udut_reports
                    JOIN udut_users
                    ON udut_reports.userId = udut_users.userId
                    WHERE udut_users.userId = '" . $user["userId"] . "'
                    ORDER BY udut_reports.reportId DESC
                  ");
              $serial_no = 0;
              foreach ($report as $rep) {
                  $serial_no += 1;

                  $report = $rep['reportName'];
                  $subject = $rep['reportSubject'];

                  print("
                        <tr>
                            <td>" . $serial_no . "</td>
                            <td style=\"word-break:break-all;\">" . $rep['reportSubject'] . "</td>
                            <td>" . $rep['userPhone'] . "</td>
                            <td>" . $rep['reportDateAdded'] . "</td>
                            <td>
                              <a href='' class='btn btn-primary' data-toggle=\"modal\" data-target=\"#sync_enabled".$serial_no."\" aria-haspopup=\"true\"
                   aria-expanded=\"false\"><i class='ti-book'></i> Read</a>
                            </td>
                        </tr>
                        
                        <div class=\"modal fade\" id=\"sync_enabled".$serial_no."\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"exampleModalLabel\"
                     aria-hidden=\"true\">
                  <div class=\"modal-dialog\" role=\"document\">
                    <div class=\"modal-content\">
                      <div class=\"modal-header\">
                        <h5 class=\"modal-title\" id=\"exampleModalLabel\">${subject}</h5>
                        <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">
                          <span aria-hidden=\"true\">&times;</span>
                        </button>
                      </div>
                      <div class=\"modal-body\">
                        <div class=\"row justify-content-center\">
                          ${report}
                        </div>
                      </div>
                      <div class=\"modal-footer\">
                        <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Not at the moment</button>
                      </div>
                    </div>
                  </div>
                </div>
                      ");

              }
              ?>

              </tbody>
            </table>
          </div>
          <div class="col-md-6">
            <form name="add-patient-form" method="POST" action="<?php echo path(); ?>codes/report-form.php">
                  <?php if (isset($acknowledge)) {
                      echo $acknowledge;
                  } ?>
                <div class="form-group col-md-12">
                  <label for="userFullname">Reporter Name</label>
                  <input name="userFullname" type="text" value="<?php echo $user["userFullname"]; ?>"
                         readonly="readonly" class="form-control" id="userFullname">
                </div>
                <div class="form-group col-md-12">
                  <label for="reportSubject">Report Subject</label>
                  <input name="reportSubject" type="text"
                          class="form-control" id="reportSubject" placeholder="Report Subject">
                </div>
                <div class="form-group col-md-12">
                  <label for="reportName">Write a Report</label>
                  <textarea rows="8" name="reportName" type="text" required placeholder="Write a report"
                            class="form-control"
                            id="reportName"></textarea>
                </div>
                <div class="form-group col-md-6 mb-3">
                  <button type="submit" class="btn btn-primary btn-lg">Submit Report</button>
                </div>


            </form>
          </div>
        </div>

        <hr>
      </div>

    </div>
  </div>
</div>
<!-- /Main Content -->

