<html>

	<head>
		<title><?php print EDITOR_NAME; ?></title>
		<?php eval(include_namespace(HEAD_FILE)); ?>
		<script language="JavaScript">
		
			function view(ID) {
				popup("<?=$editor_index?>?page=content_view&ID=" + ID, 500, 450, "");
			}

			function rollback(ID) {
				location = "<?=$wrapper_page?>?page=content_edit&rollback=" + ID;
			}

			function apply_filters() {
				load_list();
			}
			
			function reset_filters() {
				for (i=0; i<filters.elements["filter_status[]"].length; i++) {
					document.filters.elements["filter_status[]"][i].checked = 0;
				}
				document.filters.filter_user.selectedIndex = 0;
				select_content("", "");
				document.filters.filter_text.value = "";
				document.filters.filter_date_start_year.selectedIndex = 0;
				document.filters.filter_date_start_month.selectedIndex = 0;
				document.filters.filter_date_start_day.selectedIndex = 0;
				document.filters.filter_date_end_year.selectedIndex = 0;
				document.filters.filter_date_end_month.selectedIndex = 0;
				document.filters.filter_date_end_day.selectedIndex = 0;
			}
			
			function serialize_filters() {
				data = new Object;
				filter_status = new Array();
				for (i=0; i<document.filters.elements["filter_status[]"].length; i++) {
					if (document.filters.elements["filter_status[]"][i].checked) {
						filter_status[filter_status.length] = document.filters.elements["filter_status[]"][i].value;
					}
				}
				filter_status = filter_status.join(",");
				data["filter_status"] = filter_status;
				data["filter_user"] = document.filters.filter_user.options[document.filters.filter_user.selectedIndex].value;
				data["filter_content"] = document.filters.filter_content.value;
				data["filter_content_name"] = document.filters.filter_content_name.value;
				data["filter_text"] = document.filters.filter_text.value;
				data["filter_date_start_year"] = document.filters.filter_date_start_year.options[document.filters.filter_date_start_year.selectedIndex].value;
				data["filter_date_start_month"] = document.filters.filter_date_start_month.options[document.filters.filter_date_start_month.selectedIndex].value;
				data["filter_date_start_day"] = document.filters.filter_date_start_day.options[document.filters.filter_date_start_day.selectedIndex].value;
				data["filter_date_end_year"] = document.filters.filter_date_end_year.options[document.filters.filter_date_end_year.selectedIndex].value;
				data["filter_date_end_month"] = document.filters.filter_date_end_month.options[document.filters.filter_date_end_month.selectedIndex].value;
				data["filter_date_end_day"] = document.filters.filter_date_end_day.options[document.filters.filter_date_end_day.selectedIndex].value;
				data["sort"] = document.filters.sort.value;
				data["start"] = document.filters.start.value;
				data["filters_submitted"] = document.filters.filters_submitted.value;
				data = ajax_serialize(data, 0);
				return data;
			}
			
			function sort(column) {
				document.filters.sort.value = column;
				load_list();
			}

			function click_pagination_link(start) {
				document.filters.start.value = start;
				load_list();
			}

			function load_list() {
				clear_feedback();
				ajax_URL = "<?=$editor_index?>?page=content_history_list&" + serialize_filters();
				success_code = "document.getElementById('list').innerHTML = ajax_response;";
				failure_code = "alert(\"There was an error loading the list.\");";
				ajax_request(ajax_URL, success_code, failure_code);
			}
			
			function select_user(user) {
				set_menu("filters", "filter_user", "value", user);
			}
			
			function select_content(ID, name) {
				if (name) {
					document.getElementById("filter_content_display").innerHTML = name + " <a href=\"JavaScript:select_content('', '');\">Clear<\/a>";
				} else {
					document.getElementById("filter_content_display").innerHTML = "(click a name to select)";
				}
				document.filters.filter_content.value = ID;
				document.filters.filter_content_name.value = name;
			}
			
			function show_feedback(message) {
				document.getElementById("feedback").innerHTML = message;
			}
			
			function clear_feedback() {
				document.getElementById('feedback').innerHTML = "";
			}
			
		</script>
	</head>
	
	<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
	
		<?php eval(include_namespace(HEADER_FILE)); ?>

		<p class="title">Edit history</p>
		
		<div id="feedback"></div>

		<div class="filters">
		<?php

			// get saved filter values from the database
			prepare_filters("user", $user, "content_history", "status,user,content,content_name,text,date_start,date_end");
			
			// look for filter override values passed in from another page
			// we will pass these to the list script via the load_list function and the list script will save them
			$filter_user_override = initialize("filter_user", "get", "integer");
			if ($filter_user_override) { $filter_user = $filter_user_override; }
			$filter_content_override = initialize("filter_content", "get", "text");
			if ($filter_content_override) {
				$filter_content = $filter_content_override;
				$filter_content_name = $filter_content_override;
			}

			// display the filter options
			print "<form name=\"filters\" onsubmit=\"return false;\">\n\n";
			
			print "<p class=\"body stack_left\">View edits of status...<br />\n";
			print make_checkboxes("status", "filter_status", "ID", "name", 0, 0, "&nbsp;", $filter_status);
			print "</p>\n\n";

			print "<p class=\"body stack_left\">View edits by user...<br />\n";
			print make_menu("User...", "user", "filter_user", "ID", "name", 0, 1, 0, "", $filter_user);
			print "<a href=\"JavaScript:select_user($user);\">me</a>\n";
			print "</p>\n\n";

			print "<p class=\"body stack_left\">to content...<br />\n";
			print "<span class=\"body\" id=\"filter_content_display\"></span></p>\n\n";
			print "<input type=\"hidden\" name=\"filter_content\" value=\"$filter_content\">\n";
			print "<input type=\"hidden\" name=\"filter_content_name\" value=\"$filter_content_name\">\n";
			print "<script language=\"JavaScript\"> select_content('$filter_content', '$filter_content_name'); </script>";
			print "<div class=\"reset\"></div>\n";
			
			print "<p class=\"body stack_left\">View edits containing the text...<br />\n";
			print "<input type=\"text\" size=\"24\" name=\"filter_text\" value=\"$filter_text\" class=\"body\"></p>\n\n";

			print "<p class=\"body stack_left\">\n";
			print make_date_menus("saved between...", "filters", "filter_date_start", $filter_date_start);
			print "</p>\n";
			print "<p class=\"body stack_left\">\n";
			print make_date_menus("and...", "filters", "filter_date_end", $filter_date_end);
			print "</p>\n";
			print "<div class=\"reset\"></div>\n\n";

			print "<input type=\"hidden\" name=\"sort\" value=\"\">\n";
			print "<input type=\"hidden\" name=\"start\" value=\"0\">\n";
			print "<input type=\"hidden\" name=\"filters_submitted\" value=\"1\">\n";
			print "<input type=\"submit\" value=\"View\" class=\"form\" onclick=\"apply_filters()\">\n";
			print "&nbsp;<input type=\"button\" value=\"Reset\" class=\"form\" onclick=\"reset_filters()\">\n\n";
			
			print "</form>\n\n";

		?>
		</div>
		
		<div id="list" class="body">
		</div>

		<script language="JavaScript">
			load_list();
		</script>
				
		<?php eval(include_namespace(FOOTER_FILE)); ?>

	</body>
	
</html>