<?php
function sm_viral_spiral($campaign) {
	if (isset($_POST['fbvaAddComment'])) {
		$fbvaComment = trim($_POST['fbvaComment']);

		global $wpdb;
		$wpdb->show_errors();
		$table_name = $wpdb->prefix . "smreplies";

		$wpdb->query($wpdb->prepare("INSERT INTO $table_name (Comment, campaign) VALUES (%s, %s)",
			$fbvaComment,
			$campaign
		));
	}

	// $setreply = plugins_url('smsetreply.php', __FILE__);
	// $spincomment = plugins_url('smspincomment.php', __FILE__);
	//
	// $spintaxtut = plugin_dir_url(__FILE__) . 'spintax.html';

	// echo '<script type="text/javascript">
	// 				function editReply(comment) {
	// 					var text = document.getElementById("editcomment"+comment).value;
	// 					request = jQuery.ajax({
	// 						type: "post",
	// 						  url: "' . $setreply . '",
	// 						  data: { id: comment, spintax: text , campaign: "' . $campaign . '"}
	// 						  })
	// 					.done(function( msg ) {
	// 					});
	// 				}
	//
	// 				function testreply() {
	// 						var text = document.getElementById("smComment").value;
	// 						request = jQuery.ajax({
	// 						type: "post",
	// 						  url: "' . $spincomment . '",
	// 						  data: { spintax: text, campaign:  "' . $campaign . '" }
	// 						})
	// 						.done(function( msg ) {
	// 							document.getElementById("testingspintax").innerHTML = msg;
	// 						});
	// 				}
	// 			</script>';

	echo "<div>
			<form method='post' action=''>
			<table>
			<tr>
			<td>Viral message <input type='text' value ='" . $fbvaComment . "' name='fbvaComment' id='smComment' size='100' /></td>
			<td><button type='button' class='button button-primary' onclick='testreply()'>Test</button><input name='fbvaAddComment' type='submit' value='Add Message' class = 'button button-primary'></td></tr></tr>
				</table>
				</form>
	</div>";
	echo "<div id ='testingspintax'></div>";
	echo "<p><a href ='" . $spintaxtut . "' target='_blank'>How Do I Use Spintax?</a></p>";
	echo '<form id="pagedata" method="post" action="">';

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

	echo '</form>';
}
