<?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>Report</th>
                  <th>Phone</th>
                  <th>Date</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;
                      print("
                        <tr>
                            <td>".$serial_no."</td>
                            <td style=\"word-break:break-all;\">".$rep['reportName']."</td>
                            <td>".$rep['userPhone']."</td>
                            <td>".$rep['reportDateAdded']."</td>
                        </tr>
                      ");
                  }
                ?>

                </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="patientPhone">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="patientPhone">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 -->

