<?php
function sm_settings() {
	global $wpdb;

	require_once 'src/facebook.php';

	if (isset($_POST['smAuth'])) {

		$google = trim($_POST['google']);
		$email = trim($_POST['email']);
		$smtimezone = trim($_POST['smtimezone']);

		update_post_meta('111111113', 'smGoogle', $google);
		update_post_meta('111111113', 'smEmail', $email);
		update_post_meta('111111113', 'smtimezone', $smtimezone);

		$successmessage = "<strong>Settings Saved</strong>";
	}

	$google = get_post_meta(111111113, 'smGoogle', true);
	$email = get_post_meta(111111113, 'smEmail', true);
	$smtimezone = get_post_meta(111111113, 'smtimezone', true);

	echo '<div class = "wrap">
		<div class = "fbvahead">
		' . SOCIALTRAFFICBOT . ' </div>
		<h1> Settings</h1>
		<hr />
	';

	echo "<form method='post' action=''>
		<table>
			<tr><td>Google API Key</td><td><input type='text' name='google' value='" . $google . "'  size = '40'>
			<tr><td>Email</td><td><input type='text' name='email' value='" . $email . "' >";

	echo '
		<tr><td>Select Your Timezone: </td><td>
		<select name="smtimezone">';
	for ($i = 12; $i > 0; $i--) {
		if ($smtimezone == "-" . $i) {
			echo '<option value= -' . $i . ' selected = "selected">UTC -' . $i . ':00</option>';
		} else {
			echo '<option value= -' . $i . ' >UTC -' . $i . ':00</option>';
		}
	}
	for ($i = 0; $i < 13; $i++) {
		if ($smtimezone == "+" . $i) {
			echo '<option value= +' . $i . ' selected = "selected">UTC +' . $i . ':00</option>';
		} else {
			echo '<option value= +' . $i . ' >UTC +' . $i . ':00</option>';
		}
	}
	echo '</select></td></tr>';
	echo "<tr><td>";
	echo "</td><td><input name='smAuth' type='submit' value='Save' class = 'button button-primary'></td>";

	if (!empty($loginUrl)) {
		echo "<td><a href = '" . $loginUrl . "'>Auth Facebook</a></td>";
	}

	if (!empty($reddit_app_id)) {
		echo "<td><a href = '" . plugin_dir_url(__FILE__) . 'reddit-oauth.php' . "' target='_blank'>Auth Reddit</a></td>";
	}

	echo "</tr>";

	echo '<tr><td></td><td>' . $successmessage . '</td></tr>
		</table>
	</form>
	<hr />';

	$cron = plugin_dir_url(__FILE__) . 'wordpresspost.php';
	$facebook_cron = plugin_dir_url(__FILE__) . 'facebookcron.php';
	$twitter_cron = plugin_dir_url(__FILE__) . 'twittercron.php';
	$instagram_cron = plugin_dir_url(__FILE__) . 'instagramcron.php';
	$pinterest_cron = plugin_dir_url(__FILE__) . 'pinterestcron.php';
	$reddit_cron = plugin_dir_url(__FILE__) . 'redditcron.php';

	echo '<h2>Cron Info</h2>';
	echo "
	<table>
		<tr><td>WordPress Post: </td><td colspan = '2'>wget -O /dev/null " . $cron . "</td></tr>
		<tr><td>Facebook Cron: </td><td colspan = '2'>wget -O /dev/null " . $facebook_cron . "</td></tr>	
		<tr><td>Instagram Cron: </td><td colspan = '2'>wget -O /dev/null " . $instagram_cron . "</td></tr>
		<tr><td>Pinterest Cron: </td><td colspan = '2'>wget -O /dev/null " . $pinterest_cron . "</td></tr>
		<tr><td>Twitter Cron: </td><td colspan = '2'>wget -O /dev/null " . $twitter_cron . "</td></tr>
		<tr><td>Reddit Cron: </td><td colspan = '2'>wget -O /dev/null " . $reddit_cron . "</td></tr>
		
	</table>";

	echo '<h3>Alternative Cron Commands (Try these if the above dont work on your webhost) </h3>';

	echo "
	<table>
		<tr><td>WordPress Post: </td><td colspan = '2'>lynx -dump /dev/null " . $cron . "</td></tr>
		<tr><td>Facebook Cron: </td><td colspan = '2'>lynx -dump /dev/null " . $facebook_cron . "</td></tr>
		<tr><td>Twitter Cron: </td><td colspan = '2'>lynx -dump /dev/null " . $twitter_cron . "</td></tr>
		<tr><td>Instagram Cron: </td><td colspan = '2'>lynx -dump /dev/null " . $instagram_cron . "</td></tr>
		<tr><td>Pinterest Cron: </td><td colspan = '2'>lynx -dump /dev/null" . $pinterest_cron . "</td></tr>
		<tr><td>Reddit Cron: </td><td colspan = '2'>lynx -dump /dev/null " . $reddit_cron . "</td></tr>
	
	</table>";

	echo "</div>";
}
