<?php
$this->load->view('partials/report_start', $this->data);
$report = isset($report) ? $report : array();
$publishers = isset($publishers) ? $publishers : array();
$publisher_name = isset($publisher_name) ? $publisher_name : '';
?>
<form method="post">
  <div class="row filter-row align-items-end mb-3">
    <div class="col-md-5">
      <div class="form-group mb-0">
        <label>Publisher</label>
        <select name="publisher_name" class="form-control js-select2" required>
          <option value="">Select publisher</option>
          <?php foreach ($publishers as $pub) {
              $name = is_object($pub)
                  ? (isset($pub->publishercode) ? $pub->publishercode : (isset($pub->publisher) ? $pub->publisher : ''))
                  : (isset($pub['publishercode']) ? $pub['publishercode'] : '');
              if ($name === '') {
                  continue;
              }
              ?>
            <option value="<?php echo htmlspecialchars($name); ?>" <?php echo ($publisher_name === $name) ? 'selected' : ''; ?>>
              <?php echo htmlspecialchars($name); ?>
            </option>
          <?php } ?>
        </select>
      </div>
    </div>
    <div class="col-md-4">
      <p class="mb-0 text-muted small mt-4">Items by publisher.</p>
    </div>
    <div class="col-md-3">
      <?php $this->load->view('partials/report_actions'); ?>
    </div>
  </div>
<?php if (!empty($searched)) { ?>
  <div class="report-results-toolbar">
  <p class="report-summary mb-0"><strong><?php echo count($report); ?></strong> item(s)</p>
  <?php $this->load->view('partials/report_exports'); ?>
</div>
  <?php
  $this->load->view('partials/report_datatable', array(
      'columns' => array(
          'Barcode' => 'barcode',
          'D.O.Entry' => 'Date_of_Entry',
          'Call No' => 'itemcallnumber',
          'Title' => 'title',
          'Author' => 'author',
          'Item Type' => 'itype',
          'Home Branch' => 'homebranch',
          'Publisher' => 'Publisher',
      ),
      'rows' => $report,
      'table_id' => 'publisherPersonTable',
  ));
  ?>
<?php } ?>
</form>
<?php $this->load->view('partials/report_end'); ?>
