<?php

	$page_data = $this->info("data");

	/* add the nomalized page info
		*/
	$page_data->editNode("data.page", null, "id=" . $this->info("id") . ";class=" . $this->info("class"));
	$page_data->editNode("data.page.title", $this->info("title"));

	/* add the children
		*/
	$show_captions_bool = $this->getTypedValue($page_data, "settings", "show_captions_bool");
	$images = Flatfile::getFileTable("image", $this->info("id"));
	$tracks = Flatfile::getFileTable("track", $this->info("id"));

	$xmlstr = "<data>";
	if (count($images)>0) {
		$xmlstr .= "<images>";
		foreach ($images as $key => $row) {
			$dim = explode("x", $row[2]);
			$caption = isset($row[5]) ? htmlspecialchars($row[5]) : "";
			$obj = array (
				"src" => SA_DIR_STORAGE . "/" . $this->info("id") . "/" . $row[0],
				"width" => $dim[0],
				"height" => $dim[1],
				"title" => htmlspecialchars($row[1]),
				"description" => ($show_captions_bool?$caption:"")
			);
			$xmlstr .= '<image width="' . $obj["width"] . '" height="' . $obj["height"] . '" src="' . $obj["src"] . '" title="' . $obj["title"] . '">' . $obj["description"] . "</image>\n";
		}
		$xmlstr .= "</images>";
	}
	if (count($tracks)>0) {
		$xmlstr .= "<tracks>";
		foreach ($tracks as $key => $row) {
			$dim = explode("x", $row[2]);
			$obj = array (
				"src" => SA_DIR_STORAGE . "/" . $this->info("id") . "/" . $row[0],
				"title" => htmlspecialchars($row[1])
			);
			$xmlstr .= '<track src="' . $obj["src"] . '" title="' . $obj["title"] . '"></track>'."\n";
		}
		$xmlstr .= "</tracks>";
	}
	$xmlstr .= "</data>";
	$xmlobj = new SimpleXML4($xmlstr);
	$page_data->merge($xmlobj);

	/* do a standard cleanout
		*/
	$this->cleanXmlOutput($page_data->xml_array);

	/* print away
		*/
	print $page_data->toString();

?>