<?php
function sm_intros_outros($campaign) {
  if (isset($_POST['smAddSet'])) {
    global $wpdb;
    $wpdb->show_errors();
    $table_name = $wpdb->prefix . "smintrosoutros";

    $title = $_POST['title'];
    if (!is_array($title)) {
      $title = [$title];
    }

    $wpdb->insert($table_name, array(
      'setname' => trim($_POST['setname']),
      'intro' => trim($_POST['intro']),
      'outro' => trim($_POST['outro']),
    ));
  }

  $formfields = '<tr><td style="width: 200px">Set Name:</td><td><input type="text" name="setname" maxlength="50"></td></tr>
      <tr><td style="width: 200px">Intro:</td><td><input type="text" name="intro" maxlength="1000" style="width: 400px" /></td></tr>
      <tr><td style="width: 200px">Outro:</td><td><input type="text" name="outro" maxlength="1000" style="width: 400px" /></td></tr>';

  echo '<div>
    <form method="post" action="">
    <table style="width: 100%">' . $formfields;

  echo '<tr><td></td><td><input name="smAddSet" type="submit" value="Save" class="button button-primary"></td></tr>
    </table>
    </form>
    </div>
    <form id="pagedata" method="post" action="">';

  $wp_list_table = new smIntrosOutros($campaign);
  $wp_list_table->prepare_items();
  $wp_list_table->display();

  echo '</form>';
  echo '<div id="inline-edit-ios" class="hidden" data-url="' . plugins_url('inline-edit.php', __FILE__) . '" />';

  echo '<div class="inline-edit-ios-form hidden">
    <input type="hidden" name="id" />
    <table style="width: 100%; border-top: 1px solid #cccccc; border-bottom: 1px solid #cccccc;">' . $formfields .
    '<tr><td></td><td><a href="#" class="button inline-edit-ios-update button-primary">Update</a> &nbsp; <a href="#" class="button inline-edit-cancel button-secondary">Cancel</a></td></tr>
    </table>
  </div>';
}
