<?php

	require_role($role, 2);
	
	// get the data sent in from the review list
	$ID = initialize("ID", "get", "text");

	// get the content details from the database
	$query = "
		SELECT
			path,
			field,
			content
		FROM content
		WHERE content.ID=$ID
	";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		set_feedback(0, "There is no content matching the requested ID.");
		print get_feedback();
		exit;
	} else {
		$row = db_get_row($result, 0);
		extract($row);
	}

	// since we're not submitting anything, we need to add slashes manually
	$content = addslashes($content);
	
	// set a default comment
	$comment = "Published from Review page";

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

	// save the content in the site format
	if ($result) {
		$content = stripslashes($content);
		$result = save_content($path, $field, $content);
	}
	
	// set feedback and return it to the calling page
	if ($result) {
		set_feedback(1, "The content has been published.");
	} else {
		set_feedback(0, "There was an error publishing the content.");
	}
	print get_feedback();
	
?>
