<?php
include('views/_header.tpl.php');
?>
<style>
	.updated { display:none; color:green; }
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
	
	<script type="text/javascript">
	$(document).ready(function() {		
		$(function() {
			$("#submittext").click(function() {
			//e.preventDefault();

			var chktext = $('#content').val();
			
			  $.ajax({
				type: "POST",
				url: "http://dev2.thinapp.co/admin/?editchk",
				//url: $(this).attr('action'),
				async: false,   // asynchronous request? (synchronous requests are discouraged...)
				cache: false,
				dataType: 'text',
				data: {chktext: content}
				//data: $("#idform").serialize(), // serializes the form's elements.
				//data: dataString,
				success: function(data){
					alert(data); // show response from the php script.
					$('.updated').fadeIn(200).show();
				}			
			  });
			return false;
			});
		});		
    });
	</script>

 <div class="home-feature-category" style="background:none; border:none;">
        <div class="container_12 clearfix">
        <div class="grid_12">

		<h1>Edit Checkout Page Content</h1>

		<?php 
		echo "<a href='?editchk'>Edit</a>
		<span class='updated'>| Updated!</span>
		<br /><br />";
		if($_POST['Submit']){ 
			$open = fopen("checkouttext.txt","w+"); 
			$text = $_POST['update']; 
			fwrite($open, $text); 
			fclose($open); 
			echo "File updated.<br />";  
			echo "File:<br />"; 
			$file = file("checkouttext.txt"); 
				foreach($file as $text) { 
					echo $text."<br />"; 
				} 
		}elseif($_POST['Edit']){
			$file = file("checkouttext.txt"); 
			echo "<form id='idform' action='http://dev2.thinapp.co/admin/?editchk' method='post'>"; 
			echo "<textarea id='content' name='update' cols='50' rows='10'>"; 
				foreach($file as $text) { 
					echo $text; 
				}  
			echo "</textarea><br /><br />"; 
			echo "<input id='submittext'  name='Submit' type='submit' value='Update' />\n 
			</form>"; 
		}else{ 
			$file = file("checkouttext.txt"); 
			echo "<form id='idform' action='http://dev2.thinapp.co/admin/?editchk' method='post'>"; 
			echo "<textarea id='content' name='update' cols='50' rows='10'>"; 
				foreach($file as $text) { 
					echo $text; 
				}  
			echo "</textarea><br /><br />"; 
			echo "<input id='submittext' name='Submit' type='submit' value='Update' />\n 
			</form>"; 
		} 
		?>		
		<br /><br />
		</div>
	</div>
</div>

<?php
include('views/_footer.tpl.php');
?>