<?php
function sm_custom($campaign) {
	$spintaxtut = plugin_dir_url(__FILE__) . 'spintax.html';

	if (isset($_POST['smAddCustom'])) {
		global $wpdb;

		$wpdb->show_errors();
		$table_name = $wpdb->prefix . "smcustom";
		$wpdb->insert($table_name, array(
      'headline'   => trim($_POST['headline']),
			'message'    => trim($_POST['message']),
			'url'        => trim($_POST['url']),
      'image'      => trim($_POST['image']),
			'campaign'   => $campaign,
		));
	}

	echo "<br />
      <br />
      <form method='post' action='' onsubmit= 'return validateVideoForm();'>";

  $formfields = '<tr><td>Headline</td><td><input type="text" name="headline" size="40"></td></tr>
      <tr><td>Message</td><td><input type="text" name="message" size="80"></td></tr>
      <tr><td>URL</td><td><input type="url" name="url" size="40"></td></tr>
      <tr><td>Image URL</td><td><input type="url" name="image" size="40"></td></tr>
      <tr>';

	echo "<p><a href ='" . $spintaxtut . "' target='_blank'>How Do I Use Spintax?</a></p>";
	echo '<div>
    <form method="post" action="">
    <table>' . $formfields;

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

	$wp_list_table = new smCustom($campaign);
	$wp_list_table->prepare_items();
	$wp_list_table->display();
	echo '</form>';

  echo '<div id="inline-edit-custom" class="hidden" data-url="' . plugins_url('inline-edit.php', __FILE__) . '" />';
  echo '<div class="inline-edit-custom-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-custom-update button-primary">Update</a> &nbsp; <a href="#" class="button inline-edit-cancel button-secondary">Cancel</a></td></tr>
    </table>
  </div>';
}
?>
