<?php

	// get the data sent in from the requesting page
	$path = initialize("path", "get", "filename");
	$field = initialize("field", "get", "filename");
	
	// get the last published content from the site storage; this is encoded for AJAX transmission
	$data = get_content($path, $field, 0, 1);
	$data = ajax_unserialize($data);
	$content = $data["content"];

	// since we're not submitting anything, we need to add slashes manually
	$content = addslashes($content);

	// set a default comment
	$comment = "Reverted from History page";

	// insert a new record into the database
	$query = "
		INSERT INTO content (
			path,
			field,
			content,
			user,
			status,
			comment,
			date
		) VALUES (
			'$path',
			'$field',
			'$content',
			 $user,
			 5,
			'$comment',
			 ".timestamp("SQL", 1)."
		)
	";
	$result = db_do_query($query);
	
	// see if we can remove the Dreamweaver lock file
	if ($result) {
		clear_dreamweaver_lock($path);
	}

	// set feedback and return it to the calling page
	if ($result) {
		set_feedback(1, "Your content has been reverted to the last published version.");
	} else {
		set_feedback(0, "There was an error in reverting your content.");
	}
	print get_feedback();
	
?>
