<?php
// Cancel out the default layout.
$t->assign("pgLayout", "don't use one");
echo "YAOUOU";
if (!$_REQUEST['historyId']) {
	die('No id specified.');
}
echo "MARINGE - meh";
echo "one more test.";
$Q = "	SELECT
		h.id, h.pageId, h.version, h.isActive, h.comment, h.dateModified, h.content, h.contentType,
		t.pageName AS name, t.title, t.id AS tocId,
		u.username
	FROM
		_page_history h
		LEFT JOIN _users u ON (h.userId = u.id)
		LEFT JOIN _pages p ON (p.id = h.pageId)
		LEFT JOIN _toc t ON (t.pageId = p.id)
	WHERE
		h.id = '".$_REQUEST['historyId']."'
	ORDER BY
		h.version DESC";

$thisHistory = $db->query($Q, DB_ROW);

if (!is_array($thisHistory)) {
	die ("Page history content not found.");
}

if (!($oAcm->checkAccess('edit', '_toc', $thisHistory['tocId']) && $oAcm->checkAccess('changeVersions', '_toc', $thisHistory['tocId']))) {
	die ('Access denied.');
}

$fileName = $aConstants['VANITY'].'\\'.$thisHistory['name'].'_v'.$thisHistory['version'].'.';
switch($thisHistory['contentType']) {
	case 'php' : $ext = 'php'; break;
	case 'file' :
	case 'smarty' : $ext = 'tpl'; break;
	case 'text' : $ext = 'txt'; break;
	case 'xml' : $ext = 'xml'; break;
	default: $ext = 'txt';
}
$fileName .= $ext;
echo $fileName;
exit();


header('Cache-Control: public'); // no-cache, must-revalidate');
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$fileName."\"");
//header("Content-length: ".(string)(filesize($completeFilePath)));
//$fd=fopen($completeFilePath,'r');
//fpassthru($fd);
echo $thisHistory['content'];

// Now send through the data...
exit();
?>
